<commit_before>package etomica.virial.simulations;



import etomica.data.AccumulatorAverage;
import etomica.data.AccumulatorRatioAverage;
import etomica.data.types.DataDoubleArray;
import etomica.data.types.DataGroup;
import etomica.models.water.PotentialWaterGCPM3forB5;
import etomica.simulation.Simulation;
import etomica.space.Space;
import etomica.space3d.Space3D;
import etomica.units.Kelvin;
import etomica.virial.ClusterAbstract;
import etomica.virial.ClusterWeight;
import etomica.virial.ClusterWeightAbs;
import etomica.virial.ClusterCoupledFlipped;
import etomica.virial.ClusterSumPolarizable;
import etomica.virial.MayerEGeneral;
import etomica.virial.MayerEHardSphere;
import etomica.virial.MayerGeneral;
import etomica.virial.MayerHardSphere;
import etomica.virial.SpeciesFactoryWaterGCPM;
import etomica.virial.cluster.Standard;



/**

 * Generic simulation using Mayer sampling to evaluate cluster integrals

 */

public class VirialWaterOverlapClusterCoupled extends Simulation {





    public static void main(String[] args) {

        int nPoints = 2;

        double temperature = Kelvin.UNIT.toSim(350);

        long steps = 1000l;

        if (args.length > 0) nPoints = Integer.parseInt(args[0]);

        if (args.length > 1) temperature = Kelvin.UNIT.toSim(Double.parseDouble(args[1]));

        if (args.length > 2) steps = Long.parseLong(args[2]);

        double sigmaHSRef = 3.2;

        double[] HSB = new double[7];

        HSB[2] = Standard.B2HS(sigmaHSRef);

        HSB[3] = Standard.B3HS(sigmaHSRef);

        HSB[4] = Standard.B4HS(sigmaHSRef);

        HSB[5] = Standard.B5HS(sigmaHSRef);

        HSB[6] = Standard.B6HS(sigmaHSRef);

        System.out.println("sigmaHSRef: "+sigmaHSRef);

        System.out.println("B2HS: "+HSB[2]);

        System.out.println("B3HS: "+HSB[3]+" = "+(HSB[3]/(HSB[2]*HSB[2]))+" B2HS^2");

        System.out.println("B4HS: "+HSB[4]+" = "+(HSB[4]/(HSB[2]*HSB[2]*HSB[2]))+" B2HS^3");

        System.out.println("B5HS: "+HSB[5]+" = 0.110252 B2HS^4");

        System.out.println("B6HS: "+HSB[6]+" = 0.03881 B2HS^5");

        System.out.println("Water Direct sampling B"+nPoints+" at T="+Kelvin.UNIT.fromSim(temperature));

		

        Space space = Space3D.getInstance();

        

        MayerHardSphere fRef = new MayerHardSphere(space,sigmaHSRef);

        MayerEHardSphere eRef = new MayerEHardSphere(space,sigmaHSRef);

//        P2WaterSPCE pTarget = new P2WaterSPCE(space);
	//P2WaterTIP4P pTarget = new P2WaterTIP4P(space);
//        PotentialWaterPPC2 pTarget = new PotentialWaterPPC2(space);
//        PotentialWaterPPC9forB3 pTarget = new PotentialWaterPPC9forB3(space);
        //PotentialWaterGCPMforB3 pTarget = new PotentialWaterGCPMforB3(space);
        PotentialWaterGCPM3forB5 pTarget = new PotentialWaterGCPM3forB5(space);
  
        
        // kmb added the code below; 9/23/05
        ClusterWeight sampleCluster1 = null;
     
	    MayerGeneral fTarget = new MayerGeneral(pTarget);
	    MayerEGeneral eTarget = new MayerEGeneral(pTarget);
	    ClusterSumPolarizable targetCluster = Standard.virialClusterPolarizable(nPoints, fTarget, nPoints>3, eTarget, false);
	    //	ClusterCoupled targetClusterCoupled = new ClusterCoupled(targetCluster);

// old "trunc" code before flipping molecules; KMB and AJS, 7/25/07
/*	    if (args.length > 3 && args[3].equals("trunc")) {
            Potential2Transformed pSample = new Potential2Transformed(space,pTarget);
            pSample.setAtomPositionDefinition(new AtomPositionFirstAtom());
            MayerGeneral fSample = new MayerGeneral(pSample);
            MayerEGeneral eSample = new MayerEGeneral(pSample);
            ClusterAbstract sampleCluster2 = Standard.virialCluster(nPoints, fSample, true, eSample, temperature); //, true);
            sampleCluster1 = ClusterWeightAbs.makeWeightCluster(sampleCluster2);
        }
        else {
*/        	    sampleCluster1 = ClusterWeightAbs.makeWeightCluster(targetCluster.makeCopy());
  //      	    sampleCluster1 = ClusterWeightAbs.makeWeightCluster(targetClusterCoupled.makeCopy());
                             
//        }

        

        


        ClusterAbstract refCluster = Standard.virialCluster(nPoints, fRef, nPoints>3, eRef, false, false);
        ClusterWeight refSample = ClusterWeightAbs.makeWeightCluster(refCluster.makeCopy());

       
        targetCluster.setTemperature(temperature);
        refCluster.setTemperature(temperature);
        sampleCluster1.setTemperature(temperature);
        refCluster.setTemperature(temperature);


//        System.out.println(steps+" steps of size "+defaults.blockSize);

		

//		while (true) {

            SimulationVirialOverlap sim = new SimulationVirialOverlap(space,new SpeciesFactoryWaterGCPM(), temperature, new ClusterAbstract[]{refCluster,targetCluster},new ClusterWeight[]{refSample,sampleCluster1});
//            SimulationVirialOverlap sim = new SimulationVirialOverlap(space,defaults,new SpeciesFactoryWater(), temperature,refCluster,targetCluster);

/*            AtomTreeNodeWater secondWater = (AtomTreeNodeWaterGCPM)((Phase)sim.getPhaseList().get(1)).molecule(1).node;
            secondWater.H1.coord.position().PE(20);
            secondWater.H2.coord.position().PE(20);
            secondWater.M.coord.position().PE(20);
            secondWater.O.coord.position().PE(20);
            ((PhaseCluster)sim.getPhaseList().get(1)).trialNotify();
            ((PhaseCluster)sim.getPhaseList().get(1)).acceptNotify();
*/            
            
//            sim.integratorOS.setStepFreq0(0);
//            sim.integratorOS.setAdjustStepFreq(false);
            
            for (int i=0; i<2; i++) {

                sim.integrators[i].getMoveManager().setEquilibrating(true);

                sim.mcMoveTranslate[i].setStepSize(1.0);

//                sim.mcMoveTranslate[i].setAcceptanceTarget(0.20);

//                sim.mcMoveTranslate[i].setAdjustInterval(sim.mcMoveTranslate[i].getAdjustInterval()*100);

                sim.mcMoveRotate[i].setStepSize(1.5);

  //              sim.mcMoveRotate[i].setAdjustInterval(sim.mcMoveRotate[i].getAdjustInterval()*100);

//                sim.mcMoveRotate[i].setAcceptanceTarget(0.20);

               /* if (sim.mcMoveMulti != null) {

                    sim.mcMoveMulti[i].setStepSize(0.5);

                    sim.mcMoveMulti[i].setAdjustInterval(sim.mcMoveMulti[i].getAdjustInterval()*100);

                    sim.mcMoveMulti[i].setAcceptanceTarget(0.20);

                }*/

            }
            


//            sim.mcMoveAtom1.setNoisyAdjustment(true);

//            sim.mcMoveRotate.setNoisyAdjustment(true);

//            sim.mcMoveMulti.setNoisyAdjustment(true);

            // if running interactively, set filename to null so that it doens't read
            // (or write) to a refpref file
            String refFileName = args.length > 0 ? "refpref"+nPoints+"_"+temperature : null;
            sim.initRefPref(refFileName,steps/100);
            sim.equilibrate(refFileName,steps/40);

/*            try { 

                fileReader = new FileReader("refpref");

                BufferedReader bufReader = new BufferedReader(fileReader);

                String refPrefString = bufReader.readLine();

                refPref = Double.parseDouble(refPrefString);

                bufReader.close();

                fileReader.close();<commit_msg>replace targetCluster with the flipped version<commit_after>package etomica.virial.simulations;



import etomica.data.AccumulatorAverage;
import etomica.data.AccumulatorRatioAverage;
import etomica.data.types.DataDoubleArray;
import etomica.data.types.DataGroup;
import etomica.models.water.PotentialWaterGCPM3forB5;
import etomica.simulation.Simulation;
import etomica.space.Space;
import etomica.space3d.Space3D;
import etomica.units.Kelvin;
import etomica.virial.ClusterAbstract;
import etomica.virial.ClusterWeight;
import etomica.virial.ClusterWeightAbs;
import etomica.virial.ClusterCoupledFlipped;
import etomica.virial.ClusterSumPolarizable;
import etomica.virial.MayerEGeneral;
import etomica.virial.MayerEHardSphere;
import etomica.virial.MayerGeneral;
import etomica.virial.MayerHardSphere;
import etomica.virial.SpeciesFactoryWaterGCPM;
import etomica.virial.cluster.Standard;



/**

 * Generic simulation using Mayer sampling to evaluate cluster integrals

 */

public class VirialWaterOverlapClusterCoupled extends Simulation {





    public static void main(String[] args) {

        int nPoints = 2;

        double temperature = Kelvin.UNIT.toSim(350);

        long steps = 1000l;

        if (args.length > 0) nPoints = Integer.parseInt(args[0]);

        if (args.length > 1) temperature = Kelvin.UNIT.toSim(Double.parseDouble(args[1]));

        if (args.length > 2) steps = Long.parseLong(args[2]);

        double sigmaHSRef = 3.2;

        double[] HSB = new double[7];

        HSB[2] = Standard.B2HS(sigmaHSRef);

        HSB[3] = Standard.B3HS(sigmaHSRef);

        HSB[4] = Standard.B4HS(sigmaHSRef);

        HSB[5] = Standard.B5HS(sigmaHSRef);

        HSB[6] = Standard.B6HS(sigmaHSRef);

        System.out.println("sigmaHSRef: "+sigmaHSRef);

        System.out.println("B2HS: "+HSB[2]);

        System.out.println("B3HS: "+HSB[3]+" = "+(HSB[3]/(HSB[2]*HSB[2]))+" B2HS^2");

        System.out.println("B4HS: "+HSB[4]+" = "+(HSB[4]/(HSB[2]*HSB[2]*HSB[2]))+" B2HS^3");

        System.out.println("B5HS: "+HSB[5]+" = 0.110252 B2HS^4");

        System.out.println("B6HS: "+HSB[6]+" = 0.03881 B2HS^5");

        System.out.println("Water Direct sampling B"+nPoints+" at T="+Kelvin.UNIT.fromSim(temperature));

		

        Space space = Space3D.getInstance();

        

        MayerHardSphere fRef = new MayerHardSphere(space,sigmaHSRef);

        MayerEHardSphere eRef = new MayerEHardSphere(space,sigmaHSRef);

//        P2WaterSPCE pTarget = new P2WaterSPCE(space);
	//P2WaterTIP4P pTarget = new P2WaterTIP4P(space);
//        PotentialWaterPPC2 pTarget = new PotentialWaterPPC2(space);
//        PotentialWaterPPC9forB3 pTarget = new PotentialWaterPPC9forB3(space);
        //PotentialWaterGCPMforB3 pTarget = new PotentialWaterGCPMforB3(space);
        PotentialWaterGCPM3forB5 pTarget = new PotentialWaterGCPM3forB5(space);
  
        
        // kmb added the code below; 9/23/05
        ClusterWeight sampleCluster1 = null;
     
	    MayerGeneral fTarget = new MayerGeneral(pTarget);
	    MayerEGeneral eTarget = new MayerEGeneral(pTarget);
	    ClusterAbstract targetCluster = Standard.virialClusterPolarizable(nPoints, fTarget, nPoints>3, eTarget, false);
	    targetCluster = new ClusterCoupledFlipped(targetCluster);

// old "trunc" code before flipping molecules; KMB and AJS, 7/25/07
/*	    if (args.length > 3 && args[3].equals("trunc")) {
            Potential2Transformed pSample = new Potential2Transformed(space,pTarget);
            pSample.setAtomPositionDefinition(new AtomPositionFirstAtom());
            MayerGeneral fSample = new MayerGeneral(pSample);
            MayerEGeneral eSample = new MayerEGeneral(pSample);
            ClusterAbstract sampleCluster2 = Standard.virialCluster(nPoints, fSample, true, eSample, temperature); //, true);
            sampleCluster1 = ClusterWeightAbs.makeWeightCluster(sampleCluster2);
        }
        else {
*/        	    sampleCluster1 = ClusterWeightAbs.makeWeightCluster(targetCluster.makeCopy());
                             
//        }

        

        


        ClusterAbstract refCluster = Standard.virialCluster(nPoints, fRef, nPoints>3, eRef, false, false);
        ClusterWeight refSample = ClusterWeightAbs.makeWeightCluster(refCluster.makeCopy());

       
        targetCluster.setTemperature(temperature);
        refCluster.setTemperature(temperature);
        sampleCluster1.setTemperature(temperature);
        refSample.setTemperature(temperature);


//        System.out.println(steps+" steps of size "+defaults.blockSize);

		

//		while (true) {

            SimulationVirialOverlap sim = new SimulationVirialOverlap(space,new SpeciesFactoryWaterGCPM(), temperature, new ClusterAbstract[]{refCluster,targetCluster},new ClusterWeight[]{refSample,sampleCluster1});
//            SimulationVirialOverlap sim = new SimulationVirialOverlap(space,defaults,new SpeciesFactoryWater(), temperature,refCluster,targetCluster);

/*            AtomTreeNodeWater secondWater = (AtomTreeNodeWaterGCPM)((Phase)sim.getPhaseList().get(1)).molecule(1).node;
            secondWater.H1.coord.position().PE(20);
            secondWater.H2.coord.position().PE(20);
            secondWater.M.coord.position().PE(20);
            secondWater.O.coord.position().PE(20);
            ((PhaseCluster)sim.getPhaseList().get(1)).trialNotify();
            ((PhaseCluster)sim.getPhaseList().get(1)).acceptNotify();
*/            
            
//            sim.integratorOS.setStepFreq0(0);
//            sim.integratorOS.setAdjustStepFreq(false);
            
            for (int i=0; i<2; i++) {

                sim.integrators[i].getMoveManager().setEquilibrating(true);

                sim.mcMoveTranslate[i].setStepSize(1.0);

//                sim.mcMoveTranslate[i].setAcceptanceTarget(0.20);

//                sim.mcMoveTranslate[i].setAdjustInterval(sim.mcMoveTranslate[i].getAdjustInterval()*100);

                sim.mcMoveRotate[i].setStepSize(1.5);

  //              sim.mcMoveRotate[i].setAdjustInterval(sim.mcMoveRotate[i].getAdjustInterval()*100);

//                sim.mcMoveRotate[i].setAcceptanceTarget(0.20);

               /* if (sim.mcMoveMulti != null) {

                    sim.mcMoveMulti[i].setStepSize(0.5);

                    sim.mcMoveMulti[i].setAdjustInterval(sim.mcMoveMulti[i].getAdjustInterval()*100);

                    sim.mcMoveMulti[i].setAcceptanceTarget(0.20);

                }*/

            }
            


//            sim.mcMoveAtom1.setNoisyAdjustment(true);

//            sim.mcMoveRotate.setNoisyAdjustment(true);

//            sim.mcMoveMulti.setNoisyAdjustment(true);

            // if running interactively, set filename to null so that it doens't read
            // (or write) to a refpref file
            String refFileName = args.length > 0 ? "refpref"+nPoints+"_"+temperature : null;
            sim.initRefPref(refFileName,steps/100);
            sim.equilibrate(refFileName,steps/40);
            sim.setRefPref(19.325574333497855);

/*            try { 

                fileReader = new FileReader("refpref");

                BufferedReader bufReader = new BufferedReader(fileReader);

                String refPrefString = bufReader.readLine();

                refPref = Double.parseDouble(refPrefString);

                bufReader.close();

                fileReader.close();
{'fraction_non_alphanumeric': 0.11827229029855799, 'fraction_numerical': 0.022882675512829194, 'mean_word_length': 2.8883916820215845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6650229', 'n_tokens_mistral': 4825, 'n_tokens_neox': 4485, 'n_words': 690}