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

import etomica.atom.IAtom;

/**
 * Pair criterion that judges whether two atoms are or are not in the same 
 * molecule.  Intermolecular pairs are always accepted.  An optional 
 * intramolecular may be used to filter out intramolecular pairs.
 */
public class CriterionInterMolecular extends CriterionAdapter {

    /**
     * Constructs criterion in default state such that intramolecular pairs are rejected,
     * and intermolecular pairs are accepted.
     */
    public CriterionInterMolecular(NeighborCriterion criterion) {
        super(criterion);
    }
   
    /**
     * Configures to use the given criterion for intramolecular pairs.
     */
    public void setIntraMolecularCriterion(NeighborCriterion criterion) {
        intraCriterion = criterion;
    }

    /**
     * Returns the intramolecular criterion, or null if none is in use.
     */
    public NeighborCriterion getIntraMolecularCriterion() {
        return intraCriterion;
    }
    
    public boolean accept(IAtom atom1, IAtom atom2) {
        // Only ask the intracriterion if it exists and the pair is intramolecular. 
        if ((atom1.getParentGroup() == atom2.getParentGroup()) && (intraCriterion == null ||
                !intraCriterion.accept(atom1, atom2))) {
            return false;
        }
        return subCriterion.accept(atom1, atom2);
    }
    
    private static final long serialVersionUID = 1L;
    private NeighborCriterion intraCriterion;
}

@@ -992,16 +992,145 @@
 %0A    %7D%0A%0A
+    public void setIntraMolecularOnly(boolean intraMolecularOnly) %7B%0A        this.intraMolecularOnly = intraMolecularOnly;%0A    %7D%0A%0A
     /**%0A
@@ -1361,24 +1361,211 @@
 om atom2) %7B%0A
+        boolean atomsIntraMolecular = atom1.getParentGroup() == atom2.getParentGroup();%0A        if (this.intraMolecularOnly && !atomsIntraMolecular) %7B%0A            return false;%0A        %7D%0A
         // O
@@ -1652,59 +1652,28 @@
  if 
-(
 (atom
-1.getParentGroup() == atom2.getParentGroup())
+sIntraMolecular
  && 
@@ -1952,10 +1952,50 @@
 terion;%0A
+    private boolean intraMolecularOnly;%0A
 %7D%0A

Add intraMolecularOnly flag to CriterionInterMolecular