package etomica.nbr.site;

import etomica.atom.IAtom;
import etomica.box.Box;
import etomica.lattice.CellLattice;
import etomica.lattice.RectangularLatticeNbrIteratorAdjacent;
import etomica.nbr.NeighborIterator;
import etomica.potential.IteratorDirective;

public class NeighborIteratorSite implements NeighborIterator {
    private final NeighborSiteManager siteManager;
    private final CellLattice lattice;
    private final RectangularLatticeNbrIteratorAdjacent realIterator;

    public NeighborIteratorSite(NeighborSiteManager siteManager, Box box) {
        this.siteManager = siteManager;
        this.lattice = siteManager.getLattice();
        this.realIterator = new RectangularLatticeNbrIteratorAdjacent(lattice.D());
        realIterator.setLattice(lattice);
        realIterator.setPeriodicity(box.getBoundary().getPeriodicity());
    }

    @Override
    public void forEachNeighbor(IAtom targetAtom, IteratorDirective.Direction direction, AtomPairConsumer upAction, AtomPairConsumer downAction) {
        // TODO
    }
}

@@ -474,16 +474,54 @@
 terator;
+%0A    private final int%5B%5D latticeIndex;
 %0A%0A    pu
@@ -874,24 +874,84 @@
 odicity());%0A
+        this.latticeIndex = new int%5Bbox.getSpace().getD()%5D;%0A
     %7D%0A%0A    @
@@ -1118,15 +1118,884 @@
     
-// TODO
+lattice.latticeIndex(siteManager.getSite(targetAtom).latticeArrayIndex, latticeIndex);%0A        realIterator.setSite(this.latticeIndex);%0A%0A        if (direction != IteratorDirective.Direction.DOWN) %7B%0A            realIterator.setDirection(IteratorDirective.Direction.UP);%0A            realIterator.reset();%0A%0A            while (this.realIterator.hasNext()) %7B%0A                AtomSite site = ((AtomSite) realIterator.next());%0A                upAction.accept(targetAtom, site.getAtom());%0A            %7D%0A        %7D%0A%0A        if (direction != IteratorDirective.Direction.UP) %7B%0A            realIterator.setDirection(IteratorDirective.Direction.DOWN);%0A            realIterator.reset();%0A%0A            while (this.realIterator.hasNext()) %7B%0A                AtomSite site = ((AtomSite) realIterator.next());%0A                downAction.accept(site.getAtom(), targetAtom);%0A            %7D%0A%0A        %7D
 %0A   

Implement NeighborIteratorSite