<commit_before>package etomica.virial;

import etomica.Atom;
import etomica.Default;
import etomica.Phase;
import etomica.PotentialMaster;
import etomica.integrator.mcmove.MCMoveAtom;
import etomica.space.Vector;

/**
 * @author kofke
 *
 * Extension of MCMoveAtom that does trial in which several atom positions are
 * perturbed.  However, position of first atom is never altered.  
 */
public class MCMoveClusterAtomMulti extends MCMoveAtom implements MCMoveCluster {

    public MCMoveClusterAtomMulti(PotentialMaster potentialMaster, int nAtoms) {
        super(potentialMaster);
        this.nAtoms = nAtoms;
        selectedAtoms = new Atom[nAtoms];
        translationVectors = new Vector[nAtoms];
        for (int i=0; i<nAtoms; i++) {
            translationVectors[i] = potential.getSpace().makeVector();
        }
        weightMeter = new MeterClusterWeight(potential);
        setStepSize(Default.ATOM_SIZE*1.2);
	}
	
    public void setPhase(Phase[] p) {
        super.setPhase(p);
        weightMeter.setPhase(p[0]);
    }
    
	//note that total energy is calculated
	public boolean doTrial() {
		if (selectedAtoms[0] == null) selectAtoms();
        uOld = weightMeter.getDataAsScalar();
        for(int i=0; i<selectedAtoms.length; i++) {
            translationVectors[i].setRandomCube();
            translationVectors[i].TE(stepSize);
            selectedAtoms[i].coord.position().PE(translationVectors[i]);
        }
		((PhaseCluster)phases[0]).trialNotify();
		uNew = Double.NaN;
		return true;
	}
	
    public double lnProbabilityRatio() {
    	return Math.log(probabilityRatio());
    }
    
    public double probabilityRatio() {
        uNew = weightMeter.getDataAsScalar();
        return (uOld==0.0) ? Double.POSITIVE_INFINITY : uNew/uOld;
    }

    public double trialRatio() {
    	return 1.0;
    }
    
    public void selectAtoms() {
    	int total=phases[0].getSpeciesMaster().atomList.size();
    	for(int i=total-1; i>total-nAtoms-1; i--) {
    		selectedAtoms[total-1-i] = phases[0].getSpeciesMaster().atomList.get(i);
    	}
    }

    public void rejectNotify() {
        for(int i=0; i<selectedAtoms.length; i++) {
            selectedAtoms[i].coord.position().ME(translationVectors[i]);
        }
    	((PhaseCluster)phases[0]).rejectNotify();
    }
    
    public void acceptNotify() {
    	super.acceptNotify();
    	((PhaseCluster)phases[0]).acceptNotify();
    }

    private MeterClusterWeight weightMeter;
    private final int nAtoms;
    private final Atom[] selectedAtoms;
    private final Vector[] translationVectors;
}<commit_msg>super.acceptNotify doesn't do anything we're interested in<commit_after>package etomica.virial;

import etomica.Atom;
import etomica.Default;
import etomica.Phase;
import etomica.PotentialMaster;
import etomica.integrator.mcmove.MCMoveAtom;
import etomica.space.Vector;

/**
 * @author kofke
 *
 * Extension of MCMoveAtom that does trial in which several atom positions are
 * perturbed.  However, position of first atom is never altered.  
 */
public class MCMoveClusterAtomMulti extends MCMoveAtom implements MCMoveCluster {

    public MCMoveClusterAtomMulti(PotentialMaster potentialMaster, int nAtoms) {
        super(potentialMaster);
        this.nAtoms = nAtoms;
        selectedAtoms = new Atom[nAtoms];
        translationVectors = new Vector[nAtoms];
        for (int i=0; i<nAtoms; i++) {
            translationVectors[i] = potential.getSpace().makeVector();
        }
        weightMeter = new MeterClusterWeight(potential);
        setStepSize(Default.ATOM_SIZE*1.2);
	}
	
    public void setPhase(Phase[] p) {
        super.setPhase(p);
        weightMeter.setPhase(p[0]);
    }
    
	//note that total energy is calculated
	public boolean doTrial() {
		if (selectedAtoms[0] == null) selectAtoms();
        uOld = weightMeter.getDataAsScalar();
        for(int i=0; i<selectedAtoms.length; i++) {
            translationVectors[i].setRandomCube();
            translationVectors[i].TE(stepSize);
            selectedAtoms[i].coord.position().PE(translationVectors[i]);
        }
		((PhaseCluster)phases[0]).trialNotify();
		uNew = Double.NaN;
		return true;
	}
	
    public double lnProbabilityRatio() {
    	return Math.log(probabilityRatio());
    }
    
    public double probabilityRatio() {
        uNew = weightMeter.getDataAsScalar();
        return (uOld==0.0) ? Double.POSITIVE_INFINITY : uNew/uOld;
    }

    public double trialRatio() {
    	return 1.0;
    }
    
    public void selectAtoms() {
    	int total=phases[0].getSpeciesMaster().atomList.size();
    	for(int i=total-1; i>total-nAtoms-1; i--) {
    		selectedAtoms[total-1-i] = phases[0].getSpeciesMaster().atomList.get(i);
    	}
    }

    public void rejectNotify() {
        for(int i=0; i<selectedAtoms.length; i++) {
            selectedAtoms[i].coord.position().ME(translationVectors[i]);
        }
    	((PhaseCluster)phases[0]).rejectNotify();
    }
    
    public void acceptNotify() {
    	((PhaseCluster)phases[0]).acceptNotify();
    }

    private MeterClusterWeight weightMeter;
    private final int nAtoms;
    private final Atom[] selectedAtoms;
    private final Vector[] translationVectors;
}
{'fraction_non_alphanumeric': 0.11931380107941403, 'fraction_numerical': 0.007324595219737857, 'mean_word_length': 3.10197628458498, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '4039905', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1660, 'n_words': 327}