<commit_before>package etomica.virial.paralleltempering;

import etomica.atom.AtomLeaf;
import etomica.atom.iterator.AtomIterator;
import etomica.atom.iterator.AtomIteratorAllMolecules;
import etomica.atom.iterator.AtomIteratorLeafAtoms;
import etomica.atom.iterator.AtomIteratorNull;
import etomica.integrator.IntegratorMC;
import etomica.integrator.IntegratorPT;
import etomica.integrator.IntegratorPhase;
import etomica.integrator.mcmove.MCMove;
import etomica.phase.Phase;
import etomica.potential.PotentialMaster;
import etomica.space.Vector;
import etomica.virial.PhaseCluster;

/**
 * Swaps configurations and pairSet between phases for a virial clustering simulation. 
 */
public class MCMoveSwapCluster extends MCMove implements IntegratorPT.MCMoveSwap {

    private IntegratorMC integrator1, integrator2;	
    private AtomIteratorLeafAtoms iterator1 = new AtomIteratorLeafAtoms();
    private AtomIteratorLeafAtoms iterator2 = new AtomIteratorLeafAtoms();
    private AtomIteratorAllMolecules affectedAtomIterator = new AtomIteratorAllMolecules();
    private Vector r;
    private PhaseCluster phase1, phase2;
    private double weightOld1, weightOld2;
    private double weightNew1, weightNew2;
    private final Phase[] swappedPhases = new Phase[2];

    public MCMoveSwapCluster(PotentialMaster potentialMaster, 
                             IntegratorMC integrator1, IntegratorMC integrator2) {
        super(potentialMaster,2);
        r = potentialMaster.getSpace().makeVector();
        this.integrator1 = integrator1;
        this.integrator2 = integrator2;		
    }

    public boolean doTrial() {
        if(phase1 == null || phase2 == null) {
            phase1 = (PhaseCluster)integrator1.getPhase();
            phase2 = (PhaseCluster)integrator2.getPhase();
            iterator1.setPhase(phase1);
            iterator2.setPhase(phase2);
        }

        weightOld1 = phase1.getSampleCluster().value(phase1.getCPairSet(), phase1.getAPairSet());
        weightOld2 = phase2.getSampleCluster().value(phase2.getCPairSet(), phase2.getAPairSet());
        
//        System.out.println("in trial "+integrator2.getWeight()+" "+weightOld2);
//        System.out.println("in trial "+integrator1.getWeight()+" "+weightOld1);
        iterator1.reset();
        iterator2.reset();

        while(iterator1.hasNext()) {
            AtomLeaf a1 = (AtomLeaf)iterator1.nextAtom();
            AtomLeaf a2 = (AtomLeaf)iterator2.nextAtom();

            //swap coordinates
            r.E(a1.coord.position());
            
            a1.coord.position().E(a2.coord.position());
            a2.coord.position().E(r);
        }

        //assumes energy will be determined using only pairSets in phases
        phase1.trialNotify(null);
        phase2.trialNotify(null);
		
        weightNew1 = weightNew2 = Double.NaN;
        return true;
    }
    
    public double getB() {return 0.0;}
    
    public double getA() {
        weightNew1 = phase1.getSampleCluster().value(phase1.getCPairSet(), phase1.getAPairSet());
        weightNew2 = phase2.getSampleCluster().value(phase2.getCPairSet(), phase2.getAPairSet());
//        System.out.println(weightOld1+" "+weightOld2+" "+weightNew1+" "+weightNew2);
        return  (weightNew1 * weightNew2) / (weightOld1 * weightOld2);
    }
	
    /**
     * Swaps positions of molecules in two phases.
     */
    public void acceptNotify() {
//        System.out.println("accepted");
		
        phase1.acceptNotify();
        phase2.acceptNotify();
    }
	
    public void rejectNotify() {<commit_msg>oops... update for CoordinatePairSet change<commit_after>package etomica.virial.paralleltempering;

import etomica.atom.AtomLeaf;
import etomica.atom.iterator.AtomIterator;
import etomica.atom.iterator.AtomIteratorAllMolecules;
import etomica.atom.iterator.AtomIteratorLeafAtoms;
import etomica.atom.iterator.AtomIteratorNull;
import etomica.integrator.IntegratorMC;
import etomica.integrator.IntegratorPT;
import etomica.integrator.IntegratorPhase;
import etomica.integrator.mcmove.MCMove;
import etomica.phase.Phase;
import etomica.potential.PotentialMaster;
import etomica.space.Vector;
import etomica.virial.PhaseCluster;

/**
 * Swaps configurations and pairSet between phases for a virial clustering simulation. 
 */
public class MCMoveSwapCluster extends MCMove implements IntegratorPT.MCMoveSwap {

    private IntegratorMC integrator1, integrator2;	
    private AtomIteratorLeafAtoms iterator1 = new AtomIteratorLeafAtoms();
    private AtomIteratorLeafAtoms iterator2 = new AtomIteratorLeafAtoms();
    private AtomIteratorAllMolecules affectedAtomIterator = new AtomIteratorAllMolecules();
    private Vector r;
    private PhaseCluster phase1, phase2;
    private double weightOld1, weightOld2;
    private double weightNew1, weightNew2;
    private final Phase[] swappedPhases = new Phase[2];

    public MCMoveSwapCluster(PotentialMaster potentialMaster, 
                             IntegratorMC integrator1, IntegratorMC integrator2) {
        super(potentialMaster,2);
        r = potentialMaster.getSpace().makeVector();
        this.integrator1 = integrator1;
        this.integrator2 = integrator2;		
    }

    public boolean doTrial() {
        if(phase1 == null || phase2 == null) {
            phase1 = (PhaseCluster)integrator1.getPhase();
            phase2 = (PhaseCluster)integrator2.getPhase();
            iterator1.setPhase(phase1);
            iterator2.setPhase(phase2);
        }

        weightOld1 = phase1.getSampleCluster().value(phase1.getCPairSet(), phase1.getAPairSet());
        weightOld2 = phase2.getSampleCluster().value(phase2.getCPairSet(), phase2.getAPairSet());
        
//        System.out.println("in trial "+integrator2.getWeight()+" "+weightOld2);
//        System.out.println("in trial "+integrator1.getWeight()+" "+weightOld1);
        iterator1.reset();
        iterator2.reset();

        while(iterator1.hasNext()) {
            AtomLeaf a1 = (AtomLeaf)iterator1.nextAtom();
            AtomLeaf a2 = (AtomLeaf)iterator2.nextAtom();

            //swap coordinates
            r.E(a1.coord.position());
            
            a1.coord.position().E(a2.coord.position());
            a2.coord.position().E(r);
        }

        //assumes energy will be determined using only pairSets in phases
        phase1.trialNotify();
        phase2.trialNotify();
		
        weightNew1 = weightNew2 = Double.NaN;
        return true;
    }
    
    public double getB() {return 0.0;}
    
    public double getA() {
        weightNew1 = phase1.getSampleCluster().value(phase1.getCPairSet(), phase1.getAPairSet());
        weightNew2 = phase2.getSampleCluster().value(phase2.getCPairSet(), phase2.getAPairSet());
//        System.out.println(weightOld1+" "+weightOld2+" "+weightNew1+" "+weightNew2);
        return  (weightNew1 * weightNew2) / (weightOld1 * weightOld2);
    }
	
    /**
     * Swaps positions of molecules in two phases.
     */
    public void acceptNotify() {
//        System.out.println("accepted");
		
        phase1.acceptNotify();
        phase2.acceptNotify();
    }
	
    public void rejectNotify() {
{'fraction_non_alphanumeric': 0.10757363253856943, 'fraction_numerical': 0.021037868162692847, 'mean_word_length': 3.1555944055944054, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6541766', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2101, 'n_words': 398}