<commit_before>package etomica.models.oneDHardRods;

import etomica.api.IBox;
import etomica.api.IPotentialMaster;
import etomica.api.IRandom;
import etomica.api.IVector;
import etomica.atom.iterator.AtomIterator;
import etomica.atom.iterator.AtomIteratorAllMolecules;
import etomica.data.meter.MeterPotentialEnergy;
import etomica.integrator.mcmove.MCMoveBoxStep;
import etomica.normalmode.CoordinateDefinition;
import etomica.normalmode.CoordinateDefinition.BasisCell;

/**
 * A Monte Carlo move which selects a wave vector, and an eigenvector allowed 
 * by that wave vector.
 * 
 * @author cribbin
 *
 */
public class MCMoveChangeMode extends MCMoveBoxStep{

    private static final long serialVersionUID = 1L;
    protected CoordinateDefinition coordinateDefinition;
    private final AtomIteratorAllMolecules iterator;
    protected double[][] uOld;
    protected double[] deltaU;
    protected final IRandom random;
    protected double energyOld, energyNew /*, latticeEnergy*/;
    protected final MeterPotentialEnergy energyMeter;
    private double[][][] eigenVectors;
    private IVector[] waveVectors;
    int changedWV, changedEV;
    
    int countFlag;
    
    public MCMoveChangeMode(IPotentialMaster potentialMaster, IRandom random) {
        super(potentialMaster);
        
        this.random = random;
        iterator = new AtomIteratorAllMolecules();
        energyMeter = new MeterPotentialEnergy(potentialMaster);
        countFlag = 0;
    }

    public void setCoordinateDefinition(CoordinateDefinition newCoordinateDefinition) {
        coordinateDefinition = newCoordinateDefinition;
        deltaU = new double[coordinateDefinition.getCoordinateDim()];
        uOld = null;         //
    }
    
    public CoordinateDefinition getCoordinateDefinition() {
        return coordinateDefinition;
    }

    /**
     * Set the wave vectors used by the move.
     * 
     * @param wv
     */
    public void setWaveVectors(IVector[] wv){
        waveVectors = new IVector[wv.length];
        waveVectors = wv;
    }
    /**
     * Informs the move of the eigenvectors for the selected wave vector.  The
     * actual eigenvectors used will be those specified via setModes
     */
    public void setEigenVectors(double[][][] newEigenVectors) {
        eigenVectors = newEigenVectors;
    }
    
    public void setBox(IBox newBox) {
        super.setBox(newBox);
        iterator.setBox(newBox);
        energyMeter.setBox(newBox);
    }

    public AtomIterator affectedAtoms() {
        return iterator;
    }

//    public void setWaveVectorAndEigenVectorsChanged(int wv, int[] evectors){
//        //we will need some flag to indicate that these were set, and not
          //randomly assign them.
//    }
//    
    public boolean doTrial() {
//    	System.out.println("called");
        energyOld = energyMeter.getDataAsScalar();
        int coordinateDim = coordinateDefinition.getCoordinateDim();
        BasisCell[] cells = coordinateDefinition.getBasisCells();
        
        //nan These lines make it a single atom-per-molecule class, and
        // assumes that the first cell is the same as every other cell.
//        BasisCell cell = cells[0];
        double sqrtCells = Math.sqrt(cells.length);
//        double[] calcedU = coordinateDefinition.calcU(cell.molecules);
        uOld = new double[cells.length][coordinateDim];
        
        // Select the wave vector whose eigenvectors will be changed.
        changedWV = random.nextInt(waveVectors.length);
        
        //calculate the new positions of the atoms.
        //loop over cells
        double delta1 = (2*random.nextDouble()-1) * stepSize;
        double delta2 = (2*random.nextDouble()-1) * stepSize;
        for(int iCell = 0; iCell < cells.length; iCell++){
            //store old positions.
            double[] uNow = coordinateDefinition.calcU(cells[iCell].molecules);
            System.arraycopy(uNow, 0, uOld[iCell], 0, coordinateDim);
            BasisCell cell = cells[iCell];
//            for(int i = 0; i< coordinateDim; i++){
////            	System.out.println("Old  " +u[i]);
//                u[i] = 0;
//            }
            
            //loop over the wavevectors, and sum contribution of each to the
            //generalized coordinates.  Change the selected wavevector's eigen-
            //vectors at the same time!
//            for(int iVector = ; iVector <= waveVectors.length; iVector++){
            int iVector = changedWV;    
            double kR = waveVectors[iVector].dot(cell.cellPosition);
                double coskR = Math.cos(kR);
                double sinkR = Math.sin(kR);
                for(int i = 0; i < coordinateDim; i++){
                    for(int j = 0; j < coordinateDim; j++){
//                        delta1 = 5.0; delta2 = 1.0;
                        deltaU[j] += eigenVectors[iVector][i][j]*2.0*(delta1*coskR - delta2*sinkR);
//                        System.out.println("iCell: "+ iCell+" i: "+i+ " j: "+j+" u: "+u[j]+ " ev: "+ eigenVectors[iVector][i][j]);
                    }
                }
//            }
            double normalization = 1/Math.sqrt(cells.length);
//                System.out.println("norm  " +normalization);
            for(int i = 0; i < coordinateDim; i++){
//                System.out.println("prenormal " + u[i]);
                deltaU[i] *= normalization;
            }
            
            coordinateDefinition.setToU(cells[iCell].molecules, deltaU);
            
            
//            for(int i = 0; i < coordinateDim; i++){
//                System.out.println("Postnormal " +u[i]);
//            }
        }
        
        energyNew = energyMeter.getDataAsScalar();
        return true;
    }
    
    public double getA() {
        return 1;
    }

    public double getB() {
        return -(energyNew - energyOld);
    }
    
    public void acceptNotify() {
        System.out.println("accept");
    }

    public double energyChange() {
        return energyNew - energyOld;
    }

    public void rejectNotify() {
//        System.out.println("reject");<commit_msg>ease of access from home<commit_after>package etomica.models.oneDHardRods;

import etomica.api.IBox;
import etomica.api.IPotentialMaster;
import etomica.api.IRandom;
import etomica.api.IVector;
import etomica.atom.iterator.AtomIterator;
import etomica.atom.iterator.AtomIteratorAllMolecules;
import etomica.data.meter.MeterPotentialEnergy;
import etomica.integrator.mcmove.MCMoveBoxStep;
import etomica.normalmode.CoordinateDefinition;
import etomica.normalmode.CoordinateDefinition.BasisCell;

/**
 * A Monte Carlo move which selects a wave vector, and an eigenvector allowed 
 * by that wave vector.
 * 
 * @author cribbin
 *
 */
public class MCMoveChangeMode extends MCMoveBoxStep{

    private static final long serialVersionUID = 1L;
    protected CoordinateDefinition coordinateDefinition;
    private final AtomIteratorAllMolecules iterator;
    protected double[][] uOld;
    protected double[] deltaU;
    protected final IRandom random;
    protected double energyOld, energyNew /*, latticeEnergy*/;
    protected final MeterPotentialEnergy energyMeter;
    private double[][][] eigenVectors;
    private IVector[] waveVectors;
    int changedWV, changedEV;
    
    int countFlag;
    
    public MCMoveChangeMode(IPotentialMaster potentialMaster, IRandom random) {
        super(potentialMaster);
        
        this.random = random;
        iterator = new AtomIteratorAllMolecules();
        energyMeter = new MeterPotentialEnergy(potentialMaster);
        countFlag = 0;
    }

    public void setCoordinateDefinition(CoordinateDefinition newCoordinateDefinition) {
        coordinateDefinition = newCoordinateDefinition;
        deltaU = new double[coordinateDefinition.getCoordinateDim()];
        uOld = null;
    }
    
    public CoordinateDefinition getCoordinateDefinition() {
        return coordinateDefinition;
    }

    /**
     * Set the wave vectors used by the move.
     * 
     * @param wv
     */
    public void setWaveVectors(IVector[] wv){
        waveVectors = new IVector[wv.length];
        waveVectors = wv;
    }
    /**
     * Informs the move of the eigenvectors for the selected wave vector.  The
     * actual eigenvectors used will be those specified via setModes
     */
    public void setEigenVectors(double[][][] newEigenVectors) {
        eigenVectors = newEigenVectors;
    }
    
    public void setBox(IBox newBox) {
        super.setBox(newBox);
        iterator.setBox(newBox);
        energyMeter.setBox(newBox);
    }

    public AtomIterator affectedAtoms() {
        return iterator;
    }

//    public void setWaveVectorAndEigenVectorsChanged(int wv, int[] evectors){
//        //we will need some flag to indicate that these were set, and not
          //randomly assign them.
//    }
//    
    public boolean doTrial() {
//    	System.out.println("called");
        energyOld = energyMeter.getDataAsScalar();
        int coordinateDim = coordinateDefinition.getCoordinateDim();
        BasisCell[] cells = coordinateDefinition.getBasisCells();
        
        //nan These lines make it a single atom-per-molecule class, and
        // assumes that the first cell is the same as every other cell.
//        BasisCell cell = cells[0];
        double sqrtCells = Math.sqrt(cells.length);
//        double[] calcedU = coordinateDefinition.calcU(cell.molecules);
        uOld = new double[cells.length][coordinateDim];
        
        // Select the wave vector whose eigenvectors will be changed.
        changedWV = random.nextInt(waveVectors.length);
        
        //calculate the new positions of the atoms.
        //loop over cells
        double delta1 = (2*random.nextDouble()-1) * stepSize;
        double delta2 = (2*random.nextDouble()-1) * stepSize;
        for(int iCell = 0; iCell < cells.length; iCell++){
            //store old positions.
            double[] uNow = coordinateDefinition.calcU(cells[iCell].molecules);
            System.arraycopy(uNow, 0, uOld[iCell], 0, coordinateDim);
            BasisCell cell = cells[iCell];
            for(int i = 0; i< coordinateDim; i++){
                  deltaU[i] = 0;
            }
            
            //loop over the wavevectors, and sum contribution of each to the
            //generalized coordinates.  Change the selected wavevector's eigen-
            //vectors at the same time!
//            for(int iVector = ; iVector <= waveVectors.length; iVector++){
            int iVector = changedWV;    
            double kR = waveVectors[iVector].dot(cell.cellPosition);
                double coskR = Math.cos(kR);
                double sinkR = Math.sin(kR);
                for(int i = 0; i < coordinateDim; i++){
                    for(int j = 0; j < coordinateDim; j++){
//                        delta1 = 5.0; delta2 = 1.0;
                        deltaU[j] += eigenVectors[iVector][i][j]*2.0*(delta1*coskR - delta2*sinkR);
//                        System.out.println("iCell: "+ iCell+" i: "+i+ " j: "+j+" u: "+deltaU[j]+ " ev: "+ eigenVectors[iVector][i][j]);
                    }
                }
//            }
            double normalization = 1/Math.sqrt(cells.length);
//                System.out.println("norm  " +normalization);
            for(int i = 0; i < coordinateDim; i++){
//                System.out.println("prenormal " + deltaU[i]);
                deltaU[i] *= normalization;
            }
            
            for(int i = 0; i < coordinateDim; i++) {
                uNow[i] += deltaU[i];
//            	System.out.println("uNow:  " + uNow[i]);
            }
            coordinateDefinition.setToU(cells[iCell].molecules, uNow);
            
            
//            for(int i = 0; i < coordinateDim; i++){
//                System.out.println("Postnormal " +deltaU[i]);
//            }
        }
        
        energyNew = energyMeter.getDataAsScalar();
        return true;
    }
    
    public double getA() {
        return 1;
    }

    public double getB() {
        return -(energyNew - energyOld);
    }
    
    public void acceptNotify() {
//        System.out.println("accept");
    }

    public double energyChange() {
        return energyNew - energyOld;
    }

    public void rejectNotify() {
//        System.out.println("reject");
{'fraction_non_alphanumeric': 0.10616743658319151, 'fraction_numerical': 0.004943674527919604, 'mean_word_length': 2.175501801338137, 'pattern_counts': {'":': 0, '<': 18, '<?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': '6344789', 'n_tokens_mistral': 3626, 'n_tokens_neox': 3461, 'n_words': 869}