/* 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/. */

package etomica.potential;

import etomica.molecule.IMoleculeList;

/**
 * Molecular potential class that simply sums up contributions from multiple
 * (molecular) potentials.
 * 
 * @author Andrew Schultz
 */
public class PotentialMolecularSum implements IPotentialMolecular {

    protected final IPotentialMolecular[] p;
    
    public PotentialMolecularSum(IPotentialMolecular[] p) {
        this.p = p;
    }

    public double energy(IMoleculeList molecules) {
        double sum = 0;
        for (int i=0; i<p.length; i++) {
            sum += p[i].energy(molecules);
        }
        return sum;
    }

}

@@ -519,24 +519,51 @@
 ecular%5B%5D p;%0A
+    protected double umax;%0A
     %0A    pub
@@ -631,14 +631,163 @@
 this
-.p = p
+(p, Double.POSITIVE_INFINITY);%0A    %7D%0A%0A    public PotentialMolecularSum(IPotentialMolecular%5B%5D p, double umax) %7B%0A        this.p = p;%0A        this.umax = umax
 ;%0A  
@@ -951,16 +951,78 @@
 cules);%0A
+            if (sum %3E= umax) return Double.POSITIVE_INFINITY;%0A
         

add a parameter to cause sum to bail if we reach it