<commit_before>package etomica.data;

import java.io.Serializable;

import etomica.api.IAtom;
import etomica.atom.IAtomKinetic;
import etomica.atom.iterator.AtomIterator;
import etomica.data.types.DataDouble;
import etomica.data.types.DataDoubleArray;
import etomica.data.types.DataFunction;
import etomica.data.types.DataDouble.DataInfoDouble;
import etomica.data.types.DataDoubleArray.DataInfoDoubleArray;
import etomica.data.types.DataFunction.DataInfoFunction;
import etomica.units.DimensionRatio;
import etomica.units.Length;
import etomica.units.Null;
import etomica.units.Time;
import etomica.util.Histogram;
import etomica.util.HistogramCollapsing;

/**
 * Meter for the root-mean-square velocity of a set of atoms. Useful to obtain
 * histograms of atom speeds.
 * 
 * @author <NAME>
 */

public class DataSourceRmsVelocity implements DataSourceAtomic, DataSourceIndependent, Serializable {

    public DataSourceRmsVelocity() {
        this(new HistogramCollapsing());
    }
    
	public DataSourceRmsVelocity(Histogram histogram) {
        setIterator(null);
        atomDataInfo = new DataInfoDouble("RMS Velocity", new DimensionRatio(Length.DIMENSION, Time.DIMENSION));
        atomData = new DataDouble();
        this.histogramRMS = histogram;
        tag = new DataTag();
        atomDataInfo.addTag(tag);
        setupData();
    }
    
    public IDataInfo getDataInfo() {
        return dataInfo;
    }
    
    public DataTag getTag() {
        return tag;
    }

    public IDataInfo getAtomDataInfo() {
        return atomDataInfo;
    }

	/**
	 * Returns the rms velocity of the atoms given by the iterator. Value is
	 * given in the first element of the array, which is always of dimension 1.
	 */
	public Data getData() {
		iterator.reset();
        histogramRMS.reset();
		for (IAtomKinetic atom = (IAtomKinetic)iterator.nextAtom(); atom != null;
             atom = (IAtomKinetic)iterator.nextAtom()) {
			histogramRMS.addValue(Math.sqrt(atom.getVelocity().squared()));
		}

        //covertly invoke getHistogram, which actually calculates the histogram
        // our DataFunction wraps the histogram array
        if (data.getData() != histogramRMS.getHistogram() ||
                xData.getData() != histogramRMS.xValues()) {
            // we wrap the histogram inner array instances in the DataFunction.
            // if they change, we need a new instance of the DataFunction
            setupData();
        }
        
		return data;
	}
    
    /**
     * Creates the data object (a DataFunction) to be returned by getData().  
     * data wraps the histogram's double[] so copying is not needed.
     */
    protected void setupData() {
        int nBins = histogramRMS.getNBins();
        xData = new DataDoubleArray(new int[]{nBins},histogramRMS.xValues());
        xDataInfo = new DataInfoDoubleArray(atomDataInfo.getLabel(),atomDataInfo.getDimension(), new int[]{nBins});
        data = new DataFunction(new int[]{nBins}, histogramRMS.getHistogram());
        dataInfo = new DataInfoFunction("RMS Velocity Histogram",Null.DIMENSION, this);
        dataInfo.addTag(tag);
    }
    
    public Data getData(IAtom a) {
        atomData.x = Math.sqrt(((IAtomKinetic)a).getVelocity().squared());
        return atomData;
    }
    
    public DataDoubleArray getIndependentData(int i) {
        return xData;
    }
    
    public DataInfoDoubleArray getIndependentDataInfo(int i) {
        return xDataInfo;
    }
    
    public int getIndependentArrayDimension() {
        return 1;
    }
    
	/**
	 * Sets the iterator defining the atoms for which the RMS velocity is
	 * calculated.
	 * 
	 * @param iterator
	 */
	public void setIterator(AtomIterator newIterator) {
	    iterator = newIterator;
	}

	/**
	 * @return The iterator defining the atoms used for the RMS velocity
	 *         calculation
	 */
	public AtomIterator getIterator() {
		return iterator;
	}

    private static final long serialVersionUID = 1L;
	private AtomIterator iterator;
    private final DataDouble atomData;
    private final IDataInfo atomDataInfo;
    private IDataInfo dataInfo;
    protected DataDoubleArray xData;
    protected DataInfoDoubleArray xDataInfo;
    private final Histogram histogramRMS;
    private DataFunction data;
    protected final DataTag tag;
}
<commit_msg>DataSourceAtomic is no longer a DataSource, so implement it explicitly<commit_after>package etomica.data;

import java.io.Serializable;

import etomica.api.IAtom;
import etomica.atom.IAtomKinetic;
import etomica.atom.iterator.AtomIterator;
import etomica.data.types.DataDouble;
import etomica.data.types.DataDoubleArray;
import etomica.data.types.DataFunction;
import etomica.data.types.DataDouble.DataInfoDouble;
import etomica.data.types.DataDoubleArray.DataInfoDoubleArray;
import etomica.data.types.DataFunction.DataInfoFunction;
import etomica.units.DimensionRatio;
import etomica.units.Length;
import etomica.units.Null;
import etomica.units.Time;
import etomica.util.Histogram;
import etomica.util.HistogramCollapsing;

/**
 * Meter for the root-mean-square velocity of a set of atoms. Useful to obtain
 * histograms of atom speeds.
 * 
 * @author <NAME>
 */

public class DataSourceRmsVelocity implements DataSource, DataSourceAtomic, DataSourceIndependent, Serializable {

    public DataSourceRmsVelocity() {
        this(new HistogramCollapsing());
    }
    
	public DataSourceRmsVelocity(Histogram histogram) {
        setIterator(null);
        atomDataInfo = new DataInfoDouble("RMS Velocity", new DimensionRatio(Length.DIMENSION, Time.DIMENSION));
        atomData = new DataDouble();
        this.histogramRMS = histogram;
        tag = new DataTag();
        atomDataInfo.addTag(tag);
        setupData();
    }
    
    public IDataInfo getDataInfo() {
        return dataInfo;
    }
    
    public DataTag getTag() {
        return tag;
    }

    public IDataInfo getAtomDataInfo() {
        return atomDataInfo;
    }

	/**
	 * Returns the rms velocity of the atoms given by the iterator. Value is
	 * given in the first element of the array, which is always of dimension 1.
	 */
	public Data getData() {
		iterator.reset();
        histogramRMS.reset();
		for (IAtomKinetic atom = (IAtomKinetic)iterator.nextAtom(); atom != null;
             atom = (IAtomKinetic)iterator.nextAtom()) {
			histogramRMS.addValue(Math.sqrt(atom.getVelocity().squared()));
		}

        //covertly invoke getHistogram, which actually calculates the histogram
        // our DataFunction wraps the histogram array
        if (data.getData() != histogramRMS.getHistogram() ||
                xData.getData() != histogramRMS.xValues()) {
            // we wrap the histogram inner array instances in the DataFunction.
            // if they change, we need a new instance of the DataFunction
            setupData();
        }
        
		return data;
	}
    
    /**
     * Creates the data object (a DataFunction) to be returned by getData().  
     * data wraps the histogram's double[] so copying is not needed.
     */
    protected void setupData() {
        int nBins = histogramRMS.getNBins();
        xData = new DataDoubleArray(new int[]{nBins},histogramRMS.xValues());
        xDataInfo = new DataInfoDoubleArray(atomDataInfo.getLabel(),atomDataInfo.getDimension(), new int[]{nBins});
        data = new DataFunction(new int[]{nBins}, histogramRMS.getHistogram());
        dataInfo = new DataInfoFunction("RMS Velocity Histogram",Null.DIMENSION, this);
        dataInfo.addTag(tag);
    }
    
    public Data getData(IAtom a) {
        atomData.x = Math.sqrt(((IAtomKinetic)a).getVelocity().squared());
        return atomData;
    }
    
    public DataDoubleArray getIndependentData(int i) {
        return xData;
    }
    
    public DataInfoDoubleArray getIndependentDataInfo(int i) {
        return xDataInfo;
    }
    
    public int getIndependentArrayDimension() {
        return 1;
    }
    
	/**
	 * Sets the iterator defining the atoms for which the RMS velocity is
	 * calculated.
	 * 
	 * @param iterator
	 */
	public void setIterator(AtomIterator newIterator) {
	    iterator = newIterator;
	}

	/**
	 * @return The iterator defining the atoms used for the RMS velocity
	 *         calculation
	 */
	public AtomIterator getIterator() {
		return iterator;
	}

    private static final long serialVersionUID = 1L;
	private AtomIterator iterator;
    private final DataDouble atomData;
    private final IDataInfo atomDataInfo;
    private IDataInfo dataInfo;
    protected DataDoubleArray xData;
    protected DataInfoDoubleArray xDataInfo;
    private final Histogram histogramRMS;
    private DataFunction data;
    protected final DataTag tag;
}

{'fraction_non_alphanumeric': 0.09029137394909593, 'fraction_numerical': 0.0006910054128757342, 'mean_word_length': 3.1097964978703265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3505403', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2498, 'n_words': 674}