<commit_before>package etomica.spin.heisenberg_interacting.heisenberg;

import etomica.atom.AtomLeafAgentManager;
import etomica.atom.IAtom;
import etomica.atom.IAtomList;
import etomica.atom.IAtomOriented;
import etomica.box.Box;
import etomica.potential.IPotentialAtomic;
import etomica.potential.PotentialCalculation;
import etomica.space.Space;
import etomica.space.Vector;


/**
 * Potential Calculation for mean field
 */

public class PotentialCalculationMeanField implements PotentialCalculation, AtomLeafAgentManager.AgentSource<Vector> {
    protected AtomLeafAgentManager.AgentIterator leafAgentIterator;
    protected final double J2;
    protected final Space space;

    protected AtomLeafAgentManager<Vector> leafAgentManager;

    public PotentialCalculationMeanField(Space space, double J, Box box) {
        this.J2 = 0.5 * J;
        this.space = space;
        this.leafAgentManager = new AtomLeafAgentManager<>(this, box, Vector.class);

        leafAgentIterator = leafAgentManager.makeIterator();

    }


    public void doCalculation(IAtomList atoms, IPotentialAtomic potential) {
        IAtomOriented atom1 = (IAtomOriented) atoms.getAtom(0);
        IAtomOriented atom2 = (IAtomOriented) atoms.getAtom(1);
        Vector ei = atom1.getOrientation().getDirection();
        Vector ej = atom2.getOrientation().getDirection();
        Vector hi = leafAgentManager.getAgent(atom1);
        Vector hj = leafAgentManager.getAgent(atom2);

        hi.PEa1Tv1(J2, ej);
        hj.PEa1Tv1(J2, ei);
    }


    public void reset() {
        AtomLeafAgentManager.AgentIterator<Vector> it = leafAgentManager.makeIterator();
        it.reset();
        for (Vector h = it.next(); it.hasNext(); h = it.next()) {
            h.E(0);
        }
    }

    public AtomLeafAgentManager<Vector> getAgentManager() {
        return leafAgentManager;
    }

    @Override
    public Vector makeAgent(IAtom a, Box agentBox) {
        return space.makeVector();
    }

    @Override
    public void releaseAgent(Vector agent, IAtom atom, Box agentBox) {

    }
}<commit_msg>Use iterator properly<commit_after>package etomica.spin.heisenberg_interacting.heisenberg;

import etomica.atom.AtomLeafAgentManager;
import etomica.atom.IAtom;
import etomica.atom.IAtomList;
import etomica.atom.IAtomOriented;
import etomica.box.Box;
import etomica.potential.IPotentialAtomic;
import etomica.potential.PotentialCalculation;
import etomica.space.Space;
import etomica.space.Vector;


/**
 * Potential Calculation for mean field
 */

public class PotentialCalculationMeanField implements PotentialCalculation, AtomLeafAgentManager.AgentSource<Vector> {
    protected AtomLeafAgentManager.AgentIterator leafAgentIterator;
    protected final double J2;
    protected final Space space;

    protected AtomLeafAgentManager<Vector> leafAgentManager;

    public PotentialCalculationMeanField(Space space, double J, Box box) {
        this.J2 = 0.5 * J;
        this.space = space;
        this.leafAgentManager = new AtomLeafAgentManager<>(this, box, Vector.class);

        leafAgentIterator = leafAgentManager.makeIterator();

    }


    public void doCalculation(IAtomList atoms, IPotentialAtomic potential) {
        IAtomOriented atom1 = (IAtomOriented) atoms.getAtom(0);
        IAtomOriented atom2 = (IAtomOriented) atoms.getAtom(1);
        Vector ei = atom1.getOrientation().getDirection();
        Vector ej = atom2.getOrientation().getDirection();
        Vector hi = leafAgentManager.getAgent(atom1);
        Vector hj = leafAgentManager.getAgent(atom2);

        hi.PEa1Tv1(J2, ej);
        hj.PEa1Tv1(J2, ei);
    }


    public void reset() {
        AtomLeafAgentManager.AgentIterator<Vector> it = leafAgentManager.makeIterator();
        it.reset();
        while (it.hasNext()) it.next().E(0);
    }

    public AtomLeafAgentManager<Vector> getAgentManager() {
        return leafAgentManager;
    }

    @Override
    public Vector makeAgent(IAtom a, Box agentBox) {
        return space.makeVector();
    }

    @Override
    public void releaseAgent(Vector agent, IAtom atom, Box agentBox) {

    }
}
{'fraction_non_alphanumeric': 0.09413767939674045, 'fraction_numerical': 0.009243493067380199, 'mean_word_length': 3.604703247480403, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6653460', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1256, 'n_words': 261}