package etomica.potential;

import etomica.atom.AtomSet;
import etomica.atom.iterator.AtomsetIterator;

/**
 * Evaluates the energy summed over all iterated atoms. Each call to doCalculate
 * accumulates the energy of the given potential applied to the atoms produced
 * by the given iterator. Each such call accumulates a single sum, which can
 * be accessed via the getSum() method.  Sum is re-zeroed only upon a call to the
 * zeroSum() method. 
 *
 * @author David Kofke
 */
public final class PotentialCalculationEnergySum extends PotentialCalculation {

    /**
	 * Adds to the energy sum the energy values obtained from application of the given potential to the
	 * atoms produced by the given iterator.  Iterator is reset by method before beginning calculation.
	 */
	protected void doCalculation(AtomsetIterator iterator, Potential potential) {
		iterator.reset();
		while(iterator.hasNext()) {
            AtomSet atoms = iterator.next();
            System.out.println(atoms);
			sum += potential.energy(atoms);
            if(Double.isInfinite(potential.energy(atoms))){
//                System.out.println(atoms + "  are overlapped!!!!!!");
            }
		}
	}
	
	/**
	 * Sets the energy sum to zero, typically to begin a new energy-sum calculation.
	 * @return this instance, so the method can be called in-line as the instance is
	 * passed to the PotentialMaster.
	 */
	public PotentialCalculationEnergySum zeroSum() {
		sum = 0.0;
		return this;
	}

	/**
	 * Returns the current value of the energy sum.
	 */
	public double getSum() {
        return sum;
    }
	
    private static final long serialVersionUID = 1L;
	private  double sum = 0.0;
}

@@ -946,227 +946,42 @@
 ();%0A
-            System.out.println(atoms);%0A%09%09%09sum += potential.energy(atoms);%0A            if(Double.isInfinite(potential.energy(atoms)))%7B%0A//                System.out.println(atoms + %22  are overlapped!!!!!!%22);%0A            %7D
+%09%09%09sum += potential.energy(atoms);
 %0A%09%09%7D

revert previous change