package etomica.virial.cluster;

import static etomica.graph.model.Metadata.COLOR_CODE_0;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import etomica.graph.iterators.IteratorWrapper;
import etomica.graph.iterators.StoredIterator;
import etomica.graph.iterators.filters.IdenticalGraphFilter;
import etomica.graph.iterators.filters.PropertyFilter;
import etomica.graph.model.BitmapFactory;
import etomica.graph.model.Edge;
import etomica.graph.model.Graph;
import etomica.graph.model.GraphFactory;
import etomica.graph.model.GraphIterator;
import etomica.graph.model.GraphList;
import etomica.graph.model.Metadata;
import etomica.graph.model.Node;
import etomica.graph.model.comparators.ComparatorBiConnected;
import etomica.graph.model.comparators.ComparatorChain;
import etomica.graph.model.comparators.ComparatorNumEdges;
import etomica.graph.model.comparators.ComparatorNumFieldNodes;
import etomica.graph.model.comparators.ComparatorNumNodes;
import etomica.graph.model.impl.CoefficientImpl;
import etomica.graph.model.impl.MetadataImpl;
import etomica.graph.operations.Decorate;
import etomica.graph.operations.Decorate.DecorateParameters;
import etomica.graph.operations.DeleteEdge;
import etomica.graph.operations.DeleteEdgeParameters;
import etomica.graph.operations.DifByNode;
import etomica.graph.operations.DifParameters;
import etomica.graph.operations.Factor;
import etomica.graph.operations.FactorOnce;
import etomica.graph.operations.FactorOnce.FactorOnceParameters;
import etomica.graph.operations.IsoFree;
import etomica.graph.operations.MaxIsomorph;
import etomica.graph.operations.MulFlexible;
import etomica.graph.operations.MulFlexible.MulFlexibleParameters;
import etomica.graph.operations.MulScalar;
import etomica.graph.operations.MulScalarParameters;
import etomica.graph.operations.PCopy;
import etomica.graph.operations.ReeHoover;
import etomica.graph.operations.ReeHoover.ReeHooverParameters;
import etomica.graph.operations.Relabel;
import etomica.graph.operations.RelabelParameters;
import etomica.graph.operations.Split;
import etomica.graph.operations.SplitGraph;
import etomica.graph.operations.SplitOne;
import etomica.graph.operations.SplitOne.SplitOneParameters;
import etomica.graph.operations.SplitParameters;
import etomica.graph.property.HasSimpleArticulationPoint;
import etomica.graph.property.IsBiconnected;
import etomica.graph.property.IsConnected;
import etomica.graph.viewer.ClusterViewer;
import etomica.math.SpecialFunctions;
import etomica.virial.ClusterBonds;
import etomica.virial.ClusterSum;
import etomica.virial.ClusterSumEF;
import etomica.virial.ClusterSumExternalField;
import etomica.virial.ClusterSumShell;
import etomica.virial.MayerFunction;

public class ExternalVirialDiagrams extends VirialDiagrams{

	public ExternalVirialDiagrams(int n, boolean multibody, boolean flex) {
		super(n, multibody, flex);
		// TODO Auto-generated constructor stub
	}
	 public ClusterSum makeRhoCluster(MayerFunction f, boolean useExternalField) {
	       if (rho == null) {
	           makeRhoDiagrams();
	       }
	        ArrayList<ClusterBonds> allBonds = new ArrayList<ClusterBonds>();
	        ArrayList<Double> weights = new ArrayList<Double>();
	        Set<Graph> rhon = getMSMCGraphsEX(false);
	        for (Graph g : rhon) {
	            populateEFBonds(g, allBonds, false);
	            
	            double w = ((double)g.coefficient().getNumerator())/g.coefficient().getDenominator();
	           
	            weights.add(w);
	            
	        }
	        double[] w = new double[weights.size()];
	        for (int i=0; i<w.length; i++) {
	            w[i] = weights.get(i);
	        }
	        if (useExternalField) {
		           return new ClusterSumExternalField(allBonds.toArray(new ClusterBonds[0]), w, new MayerFunction[]{f});
		       }
		       else {
		           return new ClusterSum(allBonds.toArray(new ClusterBonds[0]), w, new MayerFunction[]{f});
		       }
	        
	    }
	 public Set<Graph> getMSMCGraphsEX(boolean connectedOnly) {
	        if (rho == null) {
	            makeRhoDiagrams();
	        }
	        GraphList<Graph> rhon = makeGraphList();
	       
	        for (Graph g : rho) {
	            
	            
	            if (g.nodeCount()==n) {
	                rhon.add(g);
	            }
	        }
	        return rhon;
	    }

}      

@@ -37,2550 +37,122 @@
 ort 
-static etomica.graph.model.Metadata.COLOR_CODE_0;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Comparator;%0Aimport java.util.HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A%0Aimport etomica.graph.iterators.IteratorWrapper;%0Aimport etomica.graph.iterators.StoredIterator;%0Aimport etomica.graph.iterators.filters.IdenticalGraphFilter;%0Aimport etomica.graph.iterators.filters.PropertyFilter;%0Aimport etomica.graph.model.BitmapFactory;%0Aimport etomica.graph.model.Edge;%0Aimport etomica.graph.model.Graph;%0Aimport etomica.graph.model.GraphFactory;%0Aimport etomica.graph.model.GraphIterator;%0Aimport etomica.graph.model.GraphList;%0Aimport etomica.graph.model.Metadata;%0Aimport etomica.graph.model.Node;%0Aimport etomica.graph.model.comparators.ComparatorBiConnected;%0Aimport etomica.graph.model.comparators.ComparatorChain;%0Aimport etomica.graph.model.comparators.ComparatorNumEdges;%0Aimport etomica.graph.model.comparators.ComparatorNumFieldNodes;%0Aimport etomica.graph.model.comparators.ComparatorNumNodes;%0Aimport etomica.graph.model.impl.CoefficientImpl;%0Aimport etomica.graph.model.impl.MetadataImpl;%0Aimport etomica.graph.operations.Decorate;%0Aimport etomica.graph.operations.Decorate.DecorateParameters;%0Aimport etomica.graph.operations.DeleteEdge;%0Aimport etomica.graph.operations.DeleteEdgeParameters;%0Aimport etomica.graph.operations.DifByNode;%0Aimport etomica.graph.operations.DifParameters;%0Aimport etomica.graph.operations.Factor;%0Aimport etomica.graph.operations.FactorOnce;%0Aimport etomica.graph.operations.FactorOnce.FactorOnceParameters;%0Aimport etomica.graph.operations.IsoFree;%0Aimport etomica.graph.operations.MaxIsomorph;%0Aimport etomica.graph.operations.MulFlexible;%0Aimport etomica.graph.operations.MulFlexible.MulFlexibleParameters;%0Aimport etomica.graph.operations.MulScalar;%0Aimport etomica.graph.operations.MulScalarParameters;%0Aimport etomica.graph.operations.PCopy;%0Aimport etomica.graph.operations.ReeHoover;%0Aimport etomica.graph.operations.ReeHoover.ReeHooverParameters;%0Aimport etomica.graph.operations.Relabel;%0Aimport etomica.graph.operations.RelabelParameters;%0Aimport etomica.graph.operations.Split;%0Aimport etomica.graph.operations.SplitGraph;%0Aimport etomica.graph.operations.SplitOne;%0Aimport etomica.graph.operations.SplitOne.SplitOneParameters;%0Aimport etomica.graph.operations.SplitParameters;%0Aimport etomica.graph.property.HasSimpleArticulationPoint;%0Aimport etomica.graph.property.IsBiconnected;%0Aimport etomica.graph.property.IsConnected;%0Aimport etomica.graph.viewer.ClusterViewer;%0Aimport etomica.math.SpecialFunctions
+java.util.ArrayList;%0Aimport java.util.Set;%0A%0Aimport etomica.graph.model.Graph;%0Aimport etomica.graph.model.GraphList
 ;%0Aim
@@ -223,44 +223,8 @@
 um;%0A
-import etomica.virial.ClusterSumEF;%0A
 impo
@@ -270,47 +270,8 @@
 ld;%0A
-import etomica.virial.ClusterSumShell;%0A
 impo
@@ -923,24 +923,30 @@
 Bonds, false
+, true
 );%0A%09        
@@ -1290,35 +1290,32 @@
 ld) %7B%0A%09%09        
-   
 return new Clust
@@ -1410,19 +1410,16 @@
     
-   
 %7D%0A%09%09    
    e
@@ -1414,19 +1414,16 @@
 %7D%0A%09%09    
-  
- 
 else %7B%0A%09
@@ -1427,27 +1427,24 @@
 %7B%0A%09%09        
-   
 return new C
@@ -1522,27 +1522,24 @@
 %7Bf%7D);%0A%09%09    
-   
 %7D%0A%09        %0A

update VirialDiagrams to better handle multibody graphs, including identification of graphs that need to be evaluated together for a finite result and construction of Cluster objects