Search in sources :

Example 1 with DYNFilter

use of ffx.potential.parsers.DYNFilter in project ffx by mjschnie.

the class MolecularDynamics method init.

/**
 * <p>
 * init</p>
 *
 * @param nSteps           a int.
 * @param timeStep         a double.
 * @param printInterval    a double.
 * @param saveInterval     a double.
 * @param fileType         a String.
 * @param restartFrequency the number of steps between writing restart
 *                         files.
 * @param temperature      a double.
 * @param initVelocities   a boolean.
 * @param dyn              a {@link java.io.File} object.
 */
public void init(final int nSteps, final double timeStep, final double printInterval, final double saveInterval, final String fileType, final double restartFrequency, final double temperature, final boolean initVelocities, final File dyn) {
    /**
     * Return if already running.
     */
    if (!done) {
        logger.warning(" Programming error - attempt to modify parameters of a running MolecularDynamics instance.");
        return;
    }
    this.nSteps = nSteps;
    totalSimTime = 0.0;
    /**
     * Convert the time step from femtoseconds to picoseconds.
     */
    dt = timeStep * 1.0e-3;
    /**
     * Convert the print interval to a print frequency.
     */
    printFrequency = 100;
    if (printInterval >= this.dt) {
        printFrequency = (int) (printInterval / this.dt);
    }
    /**
     * Convert the save interval to a save frequency.
     */
    saveSnapshotFrequency = 1000;
    if (saveInterval >= this.dt) {
        saveSnapshotFrequency = (int) (saveInterval / this.dt);
    }
    /**
     * Set snapshot file type.
     */
    saveSnapshotAsPDB = true;
    if (fileType.equalsIgnoreCase("XYZ")) {
        saveSnapshotAsPDB = false;
    } else if (!fileType.equalsIgnoreCase("PDB")) {
        logger.warning("Snapshot file type unrecognized; saving snaphshots as PDB.\n");
    }
    /**
     * Convert restart frequency to steps.
     */
    saveRestartFileFrequency = 1000;
    if (restartFrequency >= this.dt) {
        saveRestartFileFrequency = (int) (restartFrequency / this.dt);
    }
    assemblyInfo();
    String firstFileName = FilenameUtils.removeExtension(molecularAssembly.getFile().getAbsolutePath());
    if (dyn == null) {
        this.restartFile = new File(firstFileName + ".dyn");
        loadRestart = false;
    } else {
        this.restartFile = dyn;
        loadRestart = true;
    }
    if (dynFilter == null) {
        dynFilter = new DYNFilter(molecularAssembly.getName());
    }
    this.targetTemperature = temperature;
    this.initVelocities = initVelocities;
}
Also used : DYNFilter(ffx.potential.parsers.DYNFilter) File(java.io.File)

Example 2 with DYNFilter

use of ffx.potential.parsers.DYNFilter in project ffx by mjschnie.

the class MolecularDynamicsOpenMM method init.

@Override
public void init(int numSteps, double timeStep, double printInterval, double saveInterval, String fileType, double restartFrequency, double temperature, boolean initVelocities, File dyn) {
    this.targetTemperature = temperature;
    this.dt = timeStep;
    this.printFrequency = (int) printInterval;
    this.restartFile = dyn;
    this.initVelocities = initVelocities;
    switch(thermostatType) {
        case BUSSI:
        case BERENDSEN:
            logger.info(String.format(" Replacing thermostat %s with OpenMM's Andersen thermostat", thermostatType));
            forceFieldEnergyOpenMM.addAndersenThermostat(temperature);
            break;
        default:
    }
    /**
     * Convert the print interval to a print frequency.
     */
    printFrequency = 100;
    // Time step is in fsec, so convert printInterval to fsec.
    printInterval *= 1000;
    if (printInterval >= dt) {
        printFrequency = (int) (printInterval / dt);
    }
    /**
     * Convert save interval to a save frequency.
     */
    saveSnapshotFrequency = 1000;
    if (saveInterval >= this.dt) {
        saveSnapshotFrequency = (int) (saveInterval / this.dt);
    }
    done = false;
    assemblyInfo();
    String firstFileName = FilenameUtils.removeExtension(molecularAssembly.getFile().getAbsolutePath());
    if (dyn == null) {
        restartFile = new File(firstFileName + ".dyn");
        loadRestart = false;
    } else {
        restartFile = dyn;
        loadRestart = true;
    }
    if (dynFilter == null) {
        dynFilter = new DYNFilter(molecularAssembly.getName());
    }
    dof = forceFieldEnergyOpenMM.calculateDegreesOfFreedom();
    if (!initialized) {
        if (loadRestart) {
            Crystal crystal = molecularAssembly.getCrystal();
            // possibly add check to see if OpenMM supports this space group.
            if (!dynFilter.readDYN(restartFile, crystal, x, v, a, aPrevious)) {
                String message = " Could not load the restart file - dynamics terminated.";
                logger.log(Level.WARNING, message);
                done = true;
            } else {
                forceFieldEnergyOpenMM.setCrystal(crystal);
                // Load positions into the main FFX data structure, move into primary unit cell, then load to OpenMM.
                Atom[] atoms = molecularAssembly.getAtomArray();
                double[] xyz = new double[3];
                double[] vel = new double[3];
                double[] acc = new double[3];
                double[] accPrev = new double[3];
                for (int i = 0; i < atoms.length; i++) {
                    Atom atom = atoms[i];
                    int i3 = i * 3;
                    for (int j = 0; j < 3; j++) {
                        xyz[j] = x[i3 + j];
                        vel[j] = v[i3 + j];
                        acc[j] = a[i3 + j];
                        accPrev[j] = aPrevious[i3 + j];
                    }
                    atom.setXYZ(xyz);
                    atom.setVelocity(vel);
                    atom.setAcceleration(acc);
                    atom.setPreviousAcceleration(accPrev);
                }
                molecularAssembly.moveAllIntoUnitCell();
            }
        } else {
            if (initVelocities) {
                getThermostat().setQuiet(true);
                getThermostat().maxwell(targetTemperature);
                forceFieldEnergyOpenMM.setOpenMMVelocities(v, numberOfVariables);
                Atom[] atoms = molecularAssembly.getAtomArray();
                double[] vel = new double[3];
                for (int i = 0; i < atoms.length; i++) {
                    Atom atom = atoms[i];
                    int i3 = i * 3;
                    for (int j = 0; j < 3; j++) {
                        vel[j] = v[i3 + j];
                    }
                    atom.setVelocity(vel);
                }
            }
        }
        setOpenMMState();
    }
    saveSnapshotAsPDB = true;
    if (fileType.equalsIgnoreCase("XYZ")) {
        saveSnapshotAsPDB = false;
        logger.info("Snapshots will be saved as XYZ");
    } else if (!fileType.equalsIgnoreCase("PDB")) {
        logger.warning("Snapshot file type unrecognized; saving snaphshots as PDB.\n");
    }
    Atom[] atoms = molecularAssembly.getAtomArray();
    natoms = atoms.length;
    int i = 0;
    running = false;
    // logger.info(" Calling OpenMM Update from MD Init.");
    updateFromOpenMM(i, running);
}
Also used : DYNFilter(ffx.potential.parsers.DYNFilter) File(java.io.File) Atom(ffx.potential.bonded.Atom) Crystal(ffx.crystal.Crystal)

Aggregations

DYNFilter (ffx.potential.parsers.DYNFilter)2 File (java.io.File)2 Crystal (ffx.crystal.Crystal)1 Atom (ffx.potential.bonded.Atom)1