<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
 * History
 * Created on Aug 30, 2004 by kofke
 */
package etomica.nbr.site;

import etomica.atom.AtomPair;
import etomica.atom.IAtom;
import etomica.atom.IAtomList;
import etomica.atom.iterator.AtomsetIteratorPDT;
import etomica.box.Box;
import etomica.box.BoxAgentManager;
import etomica.lattice.CellLattice;
import etomica.lattice.RectangularLatticeNbrIterator;
import etomica.lattice.RectangularLatticeNbrIteratorAdjacent;
import etomica.potential.IteratorDirective;
import etomica.potential.IteratorDirective.Direction;

/**
 * Iteration is performed using site lists.
 * Direction is related to ordering of sites.
 */
public class Api1ASite implements AtomsetIteratorPDT, java.io.Serializable {
    
    /**
	 * Constructor makes iterator that must have box specified and then be 
	 * reset() before iteration.
     * 
     * @param D the dimension of the space of the simulation (used to construct cell iterators)
     */
	public Api1ASite(int D, BoxAgentManager agentManager) {
        neighborIterator = new RectangularLatticeNbrIteratorAdjacent(D);
        
        latticeIndex = new int[D];
        periodicity = new boolean[D];
        
        neighborIterator.setDirection(null);
        boxAgentManager = agentManager;
	}

	public void setBox(Box box) {
        neighborSiteManager = (NeighborSiteManager)boxAgentManager.getAgent(box);
        lattice = neighborSiteManager.getLattice();
        neighborIterator.setLattice(lattice);
        for (int i=0; i<periodicity.length; i++) {
            periodicity[i] = box.getBoundary().getPeriodicity(i);
        }
        neighborIterator.setPeriodicity(periodicity);
	}
    
	/**
	 * Returns the number of atom pairs the iterator will return if
	 * reset and iterated in its present state.
	 */
	public int size() {
        int count = 0;
        reset();
        for (Object a = next(); a != null; a = next()) {
            count++;
        }
        return count;
	}
	
    public IAtomList next() {
        if (upListNow) {
            if (neighborIterator.hasNext()) {
                pair.atom1 = ((AtomSite)neighborIterator.next()).getAtom();
                return pair;
            }
            else if (!doGoDown) {
                return null;
            }
            upListNow = false;
            neighborIterator.setDirection(IteratorDirective.Direction.DOWN);
            neighborIterator.reset();
            pair.atom1 = ((AtomSite)neighborIterator.next()).getAtom();
            return pair;
        }
        if (!neighborIterator.hasNext()) {
            return null;
        }
        pair.atom0 = ((AtomSite)neighborIterator.next()).getAtom();
        return pair;
    }<commit_msg>Don't overwrite central atom with neighbor when iterating down site list<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
 * History
 * Created on Aug 30, 2004 by kofke
 */
package etomica.nbr.site;

import etomica.atom.AtomPair;
import etomica.atom.IAtom;
import etomica.atom.IAtomList;
import etomica.atom.iterator.AtomsetIteratorPDT;
import etomica.box.Box;
import etomica.box.BoxAgentManager;
import etomica.lattice.CellLattice;
import etomica.lattice.RectangularLatticeNbrIterator;
import etomica.lattice.RectangularLatticeNbrIteratorAdjacent;
import etomica.potential.IteratorDirective;
import etomica.potential.IteratorDirective.Direction;

/**
 * Iteration is performed using site lists.
 * Direction is related to ordering of sites.
 */
public class Api1ASite implements AtomsetIteratorPDT, java.io.Serializable {
    
    /**
	 * Constructor makes iterator that must have box specified and then be 
	 * reset() before iteration.
     * 
     * @param D the dimension of the space of the simulation (used to construct cell iterators)
     */
	public Api1ASite(int D, BoxAgentManager agentManager) {
        neighborIterator = new RectangularLatticeNbrIteratorAdjacent(D);
        
        latticeIndex = new int[D];
        periodicity = new boolean[D];
        
        neighborIterator.setDirection(null);
        boxAgentManager = agentManager;
	}

	public void setBox(Box box) {
        neighborSiteManager = (NeighborSiteManager)boxAgentManager.getAgent(box);
        lattice = neighborSiteManager.getLattice();
        neighborIterator.setLattice(lattice);
        for (int i=0; i<periodicity.length; i++) {
            periodicity[i] = box.getBoundary().getPeriodicity(i);
        }
        neighborIterator.setPeriodicity(periodicity);
	}
    
	/**
	 * Returns the number of atom pairs the iterator will return if
	 * reset and iterated in its present state.
	 */
	public int size() {
        int count = 0;
        reset();
        for (Object a = next(); a != null; a = next()) {
            count++;
        }
        return count;
	}
	
    public IAtomList next() {
        if (upListNow) {
            if (neighborIterator.hasNext()) {
                pair.atom1 = ((AtomSite)neighborIterator.next()).getAtom();
                return pair;
            }
            else if (!doGoDown) {
                return null;
            }
            upListNow = false;
            neighborIterator.setDirection(IteratorDirective.Direction.DOWN);
            neighborIterator.reset();
            pair.atom1 = ((AtomSite)neighborIterator.next()).getAtom();
            return pair;
        }
        if (!neighborIterator.hasNext()) {
            return null;
        }
        pair.atom1 = ((AtomSite)neighborIterator.next()).getAtom();
        return pair;
    }
{'fraction_non_alphanumeric': 0.09700598802395209, 'fraction_numerical': 0.005816937553464499, 'mean_word_length': 2.6064157927205427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1369393', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1673, 'n_words': 444}