<commit_before>package etomica.meta.wrappers;

import etomica.integrator.Integrator;
import etomica.integrator.IntegratorBox;
import etomica.integrator.IntegratorManagerMC;
import etomica.meta.SimulationModel;
import etomica.meta.properties.InstanceProperty;
import etomica.potential.PotentialMaster;
import etomica.simulation.Simulation;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Specialized wrapper for Simulations.
 *
 * When a wrapper is created it collects the PotentialMasters in a simulation,
 * which are associated with Integrators internally but conceptually are children of the simulation,
 * and adds a "synthetic" method to return them to the list of the simulation's properties.
 */
public class SimulationWrapper extends ObjectWrapper<Simulation> {

    public SimulationWrapper(Simulation wrapped, SimulationModel simModel, boolean doSerialize) {
        super(wrapped, simModel, doSerialize);

        try {
            PropertyDescriptor descriptor = new PropertyDescriptor(
                    "potentialMasters",
                    SimulationWrapper.class.getDeclaredMethod("getPotentialMasters"),
                    null
            );

            this.childProps.add(new InstanceProperty(this, descriptor));
        } catch (IntrospectionException | NoSuchMethodException e) {
            e.printStackTrace();
        }

    }

    public List<PotentialMaster> getPotentialMasters() {
        Set<PotentialMaster> set = new HashSet<>();
        getPotentialMasters(wrapped.getIntegrator(), set);
        return new ArrayList<>(set);
    }

    private static void getPotentialMasters(Integrator integrator, Set<PotentialMaster> set) {
        if(integrator instanceof IntegratorManagerMC) {
            for(Integrator i : ((IntegratorManagerMC) integrator).getIntegrators()) {
                getPotentialMasters(i, set);
            }
        } else if(integrator instanceof IntegratorBox) {
            set.add(((IntegratorBox) integrator).getPotentialMaster());
        }
    }


}<commit_msg>Provide a method to obtain coordinates of all atoms in wrapped Simulation<commit_after>package etomica.meta.wrappers;

import etomica.atom.IAtomList;
import etomica.box.Box;
import etomica.integrator.Integrator;
import etomica.integrator.IntegratorBox;
import etomica.integrator.IntegratorManagerMC;
import etomica.meta.SimulationModel;
import etomica.meta.properties.InstanceProperty;
import etomica.potential.PotentialMaster;
import etomica.simulation.Simulation;
import etomica.simulation.prototypes.HSMD2D;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Specialized wrapper for Simulations.
 *
 * When a wrapper is created it collects the PotentialMasters in a simulation,
 * which are associated with Integrators internally but conceptually are children of the simulation,
 * and adds a "synthetic" method to return them to the list of the simulation's properties.
 */
public class SimulationWrapper extends ObjectWrapper<Simulation> {

    protected double allCoords[][][] = new double[0][][];

    public SimulationWrapper(Simulation wrapped, SimulationModel simModel, boolean doSerialize) {
        super(wrapped, simModel, doSerialize);

        try {
            PropertyDescriptor descriptor = new PropertyDescriptor(
                    "potentialMasters",
                    SimulationWrapper.class.getDeclaredMethod("getPotentialMasters"),
                    null
            );

            this.childProps.add(new InstanceProperty(this, descriptor));
        } catch (IntrospectionException | NoSuchMethodException e) {
            e.printStackTrace();
        }

    }

    public List<PotentialMaster> getPotentialMasters() {
        Set<PotentialMaster> set = new HashSet<>();
        getPotentialMasters(wrapped.getIntegrator(), set);
        return new ArrayList<>(set);
    }

    private static void getPotentialMasters(Integrator integrator, Set<PotentialMaster> set) {
        if(integrator instanceof IntegratorManagerMC) {
            for(Integrator i : ((IntegratorManagerMC) integrator).getIntegrators()) {
                getPotentialMasters(i, set);
            }
        } else if(integrator instanceof IntegratorBox) {
            set.add(((IntegratorBox) integrator).getPotentialMaster());
        }
    }

    /**
     * Array of coordinates of all atoms in all boxes in the wrapped Simulation.
     * @return 3-dimensional array of coordinates. First index indicates the box; second index
     * indicates the leaf atom in the box; third index indicates the coordinate (i.e., x, y, z)
     */
    public double[][][] getAllCoordinates() {
        Simulation sim = simModel.getSimulation();
        if(allCoords.length != sim.getBoxCount()) {
            allCoords = new double[sim.getBoxCount()][0][];
            for(int i=0; i< sim.getBoxCount(); i++) {
                IAtomList leafList = sim.getBox(i).getLeafList();
                if(allCoords[i].length != leafList.getAtomCount()) {
                    allCoords[i] = new double[leafList.getAtomCount()][sim.getSpace().D()];
                }
                for(int j=0; j<leafList.getAtomCount(); j++) {
                    leafList.getAtom(j).getPosition().assignTo(allCoords[i][j]);
                }
            }
        }
        return allCoords;
    }


/*
    public static void main(String[] args) {
        Simulation sim = new HSMD2D();
        SimulationWrapper wrapper = new SimulationWrapper(sim, new SimulationModel(sim), true);
        double[][][] coords = wrapper.getAllCoordinates();
        System.out.println("done");

    }
*/
}
{'fraction_non_alphanumeric': 0.09511612021857924, 'fraction_numerical': 0.0011953551912568306, 'mean_word_length': 3.113061797752809, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '534588', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1554, 'n_words': 388}