Example usage for org.apache.commons.configuration CompositeConfiguration getDouble

List of usage examples for org.apache.commons.configuration CompositeConfiguration getDouble

Introduction

In this page you can find the example usage for org.apache.commons.configuration CompositeConfiguration getDouble.

Prototype

public double getDouble(String key, double defaultValue) 

Source Link

Usage

From source file:ffx.crystal.Resolution.java

/**
 * <p>//from   w  w  w  .  ja  v  a2s .c  om
 * checkProperties</p>
 *
 * @param properties a
 * {@link org.apache.commons.configuration.CompositeConfiguration} object.
 * @return a {@link ffx.crystal.Resolution} object.
 */
public static Resolution checkProperties(CompositeConfiguration properties) {
    double resolution = properties.getDouble("resolution", -1.0);
    double sampling = properties.getDouble("sampling", 0.6);

    if (resolution < 0.0) {
        return null;
    }

    return new Resolution(resolution, sampling);
}

From source file:ffx.crystal.Crystal.java

/**
 * <p>//from  w w  w .  j a v  a 2  s.c  o m
 * checkProperties</p>
 *
 * @param properties a
 * {@link org.apache.commons.configuration.CompositeConfiguration} object.
 * @return a {@link ffx.crystal.Crystal} object.
 */
public static Crystal checkProperties(CompositeConfiguration properties) {
    double a = properties.getDouble("a-axis", -1.0);
    double b = properties.getDouble("b-axis", -1.0);
    double c = properties.getDouble("c-axis", -1.0);
    double alpha = properties.getDouble("alpha", -1.0);
    double beta = properties.getDouble("beta", -1.0);
    double gamma = properties.getDouble("gamma", -1.0);
    String sg = properties.getString("spacegroup", null);

    sg = SpaceGroup.pdb2ShortName(sg);

    if (a < 0.0 || b < 0.0 || c < 0.0 || alpha < 0.0 || beta < 0.0 || gamma < 0.0 || sg == null) {
        return null;
    }

    // check the space group name is valid
    SpaceGroup spaceGroup = SpaceGroup.spaceGroupFactory(sg);
    if (spaceGroup == null) {
        sg = sg.replaceAll(" ", "");
        spaceGroup = SpaceGroup.spaceGroupFactory(sg);
        if (spaceGroup == null) {
            return null;
        }
    }

    return new Crystal(a, b, c, alpha, beta, gamma, sg);
}

From source file:ffx.xray.RealSpaceData.java

/**
 * construct a real space data assembly/* w w w .j a  v  a  2s  .com*/
 *
 * @param assembly
 * {@link ffx.potential.MolecularAssembly molecular assembly} object array
 * (typically containing alternate conformer assemblies), used as the atomic
 * model for comparison against the data
 * @param properties system properties file
 * @param datafile one or more {@link RealSpaceFile} to be refined against
 */
public RealSpaceData(MolecularAssembly assembly[], CompositeConfiguration properties,
        RealSpaceFile... datafile) {

    this.assembly = assembly;
    this.modelname = assembly[0].getFile().getName();
    this.dataname = datafile;
    this.n = datafile.length;
    crystal = new Crystal[n];
    refinementdata = new RealSpaceRefinementData[n];

    xweight = properties.getDouble("xweight", 1.0);

    for (int i = 0; i < n; i++) {
        crystal[i] = datafile[i].realspacefilter.getCrystal(datafile[i].filename, properties);

        if (crystal[i] == null) {
            logger.severe("CCP4 map file does not contain full crystal information!");
        }
    }

    for (int i = 0; i < n; i++) {
        refinementdata[i] = new RealSpaceRefinementData();
        datafile[i].realspacefilter.readFile(datafile[i].filename, refinementdata[i], properties);

        if (refinementdata[i].ori[0] == 0 && refinementdata[i].ori[1] == 0 && refinementdata[i].ori[2] == 0
                && refinementdata[i].ext[0] == refinementdata[i].ni[0]
                && refinementdata[i].ext[1] == refinementdata[i].ni[1]
                && refinementdata[i].ext[2] == refinementdata[i].ni[2]) {
            refinementdata[i].periodic = true;
        }
    }

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(" Refinement Settings\n");
        sb.append("  Real space refinement weight (xweight): " + xweight + "\n");
        logger.info(sb.toString());
    }

    // now set up the refinement model
    refinementmodel = new RefinementModel(assembly);
}

From source file:ffx.xray.RealSpaceData.java

/**
 * construct a real space data assembly, assumes a real space map with a
 * weight of 1.0 using the same name as the molecular assembly
 *
 * @param assembly/*from  w  w w  .j  a  v  a  2  s .  co m*/
 * {@link ffx.potential.MolecularAssembly molecular assembly} object, used
 * as the atomic model for comparison against the data
 * @param properties system properties file
 * @param diffractiondata {@link ffx.xray.DiffractionData diffraction data}
 */
public RealSpaceData(MolecularAssembly assembly[], CompositeConfiguration properties,
        DiffractionData diffractiondata) {
    this.assembly = assembly;
    this.modelname = assembly[0].getFile().getName();
    this.dataname = null;
    this.n = 1;
    crystal = new Crystal[n];
    crystal[0] = diffractiondata.crystal[0];
    refinementdata = new RealSpaceRefinementData[n];
    refinementdata[0] = new RealSpaceRefinementData();
    refinementdata[0].periodic = true;

    xweight = properties.getDouble("xweight", 1.0);

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(" Refinement Settings\n");
        sb.append("  Real space refinement weight (xweight): " + xweight + "\n");
        logger.info(sb.toString());
    }

    if (!diffractiondata.scaled[0]) {
        diffractiondata.scaleBulkFit();
        diffractiondata.printStats();
        // energy();
    }

    // get Fo-Fc difference density
    diffractiondata.crs_fc[0].computeAtomicGradients(diffractiondata.refinementData[0].fofc1,
            diffractiondata.refinementData[0].freer, diffractiondata.refinementData[0].rfreeflag,
            RefinementMode.COORDINATES);

    refinementdata[0].ori[0] = 0;
    refinementdata[0].ori[1] = 0;
    refinementdata[0].ori[2] = 0;
    int extx = (int) diffractiondata.crs_fc[0].getXDim();
    int exty = (int) diffractiondata.crs_fc[0].getYDim();
    int extz = (int) diffractiondata.crs_fc[0].getZDim();
    refinementdata[0].ext[0] = extx;
    refinementdata[0].ext[1] = exty;
    refinementdata[0].ext[2] = extz;
    refinementdata[0].ni[0] = extx;
    refinementdata[0].ni[1] = exty;
    refinementdata[0].ni[2] = extz;
    refinementdata[0].data = new double[extx * exty * extz];
    for (int k = 0; k < extz; k++) {
        for (int j = 0; j < exty; j++) {
            for (int i = 0; i < extx; i++) {
                int index1 = (i + extx * (j + exty * k));
                int index2 = 2 * (i + extx * (j + exty * k));
                refinementdata[0].data[index1] = diffractiondata.crs_fc[0].densityGrid[index2];
            }
        }
    }

    // now set up the refinement model
    refinementmodel = new RefinementModel(assembly);
}

From source file:ffx.xray.DiffractionRefinementData.java

/**
 * allocate data given a {@link ReflectionList}
 *
 * @param properties configuration properties
 * @param reflectionlist {@link ReflectionList} to use to allocate data
 *//*from  w w  w  .  j  a  v  a 2 s  .  co m*/
public DiffractionRefinementData(CompositeConfiguration properties, ReflectionList reflectionlist) {

    int rflag = -1;
    if (properties != null) {
        rflag = properties.getInt("rfreeflag", -1);
        fsigfcutoff = properties.getDouble("fsigfcutoff", -1.0);
    } else {
        fsigfcutoff = -1.0;
    }

    this.n = reflectionlist.hkllist.size();
    this.scale_n = reflectionlist.crystal.scale_n;
    this.rfreeflag = rflag;
    this.nbins = reflectionlist.nbins;
    fsigf = new double[n][2];
    freer = new int[n];
    fc = new double[n][2];
    fs = new double[n][2];
    fctot = new double[n][2];
    fomphi = new double[n][2];
    fofc2 = new double[n][2];
    fofc1 = new double[n][2];
    dfc = new double[n][2];
    dfs = new double[n][2];

    for (int i = 0; i < n; i++) {
        fsigf[i][0] = fsigf[i][1] = Double.NaN;
        fctot[i][0] = fctot[i][1] = Double.NaN;
    }

    spline = new double[nbins * 2];
    sigmaa = new double[nbins];
    sigmaw = new double[nbins];
    fcesq = new double[nbins];
    foesq = new double[nbins];
    for (int i = 0; i < nbins; i++) {
        spline[i] = spline[i + nbins] = sigmaa[i] = fcesq[i] = foesq[i] = 1.0;
        sigmaw[i] = 0.05;
    }

    // initial guess for scaling/bulk solvent correction
    solvent_k = 0.33;
    solvent_ueq = 50.0 / (8.0 * PI * PI);
    model_k = 0.0;
}

From source file:ffx.realspace.RealSpaceData.java

/**
 * Construct a real space data molecularAssemblies.
 *
 * @param molecularAssemblies//w  w  w .  j  av  a  2  s  .co m
 * {@link ffx.potential.MolecularAssembly molecular molecularAssemblies}
 * object array (typically containing alternate conformer assemblies), used
 * as the atomic model for comparison against the data
 * @param properties system properties file
 * @param parallelTeam
 * @param dataFile one or more {@link RealSpaceFile} to be refined against
 */
public RealSpaceData(MolecularAssembly molecularAssemblies[], CompositeConfiguration properties,
        ParallelTeam parallelTeam, RealSpaceFile... dataFile) {

    this.molecularAssemblies = molecularAssemblies;
    this.modelName = molecularAssemblies[0].getFile().getName();
    this.parallelTeam = parallelTeam;
    this.realSpaceFile = dataFile;
    this.nRealSpaceData = dataFile.length;
    crystal = new Crystal[nRealSpaceData];
    refinementData = new RealSpaceRefinementData[nRealSpaceData];

    xweight = properties.getDouble("xweight", 1.0);
    lambdaTerm = properties.getBoolean("lambdaterm", false);

    for (int i = 0; i < nRealSpaceData; i++) {
        crystal[i] = dataFile[i].getRealSpaceFileFilter().getCrystal(dataFile[i].getFilename(), properties);

        if (crystal[i] == null) {
            logger.severe("CCP4 map file does not contain full crystal information!");
        }
    }

    for (int i = 0; i < nRealSpaceData; i++) {
        refinementData[i] = new RealSpaceRefinementData();
        dataFile[i].getRealSpaceFileFilter().readFile(dataFile[i].getFilename(), refinementData[i], properties);

        if (refinementData[i].getOrigin()[0] == 0 && refinementData[i].getOrigin()[1] == 0
                && refinementData[i].getOrigin()[2] == 0
                && refinementData[i].getExtent()[0] == refinementData[i].getNi()[0]
                && refinementData[i].getExtent()[1] == refinementData[i].getNi()[1]
                && refinementData[i].getExtent()[2] == refinementData[i].getNi()[2]) {
            refinementData[i].setPeriodic(true);
        }
    }

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(" Real Space Refinement Settings\n");
        sb.append(format("  Refinement weight (xweight): %5.3f", xweight));
        logger.info(sb.toString());
    }

    // now set up the refinement model
    refinementModel = new RefinementModel(molecularAssemblies);

    /**
     * Initialize the RealSpaceRegion.
     */
    int nAtoms = refinementModel.getTotalAtomArray().length;
    realSpaceRegion = new RealSpaceRegion(parallelTeam.getThreadCount(), nAtoms, refinementData.length);

}

From source file:ffx.realspace.RealSpaceData.java

/**
 * Construct a real space data molecularAssemblies, assumes a real space map
 * with a weight of 1.0 using the same name as the molecularAssemblies.
 *
 * @param molecularAssemblies//from   ww  w. jav a2s  . co  m
 * {@link ffx.potential.MolecularAssembly molecular molecularAssemblies}
 * object, used as the atomic model for comparison against the data
 * @param properties system properties file
 * @param parallelTeam
 * @param diffractionData {@link ffx.xray.DiffractionData diffraction data}
 */
public RealSpaceData(MolecularAssembly molecularAssemblies[], CompositeConfiguration properties,
        ParallelTeam parallelTeam, DiffractionData diffractionData) {
    this.molecularAssemblies = molecularAssemblies;
    this.parallelTeam = parallelTeam;
    this.modelName = molecularAssemblies[0].getFile().getName();
    this.realSpaceFile = null;
    this.nRealSpaceData = 1;
    crystal = new Crystal[nRealSpaceData];
    crystal[0] = diffractionData.getCrystal()[0];
    refinementData = new RealSpaceRefinementData[nRealSpaceData];
    refinementData[0] = new RealSpaceRefinementData();
    refinementData[0].setPeriodic(true);

    xweight = properties.getDouble("xweight", 1.0);
    lambdaTerm = properties.getBoolean("lambdaterm", false);

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(" Real Space Refinement Settings\n");
        sb.append(format("  Refinement weight (xweight): %5.3f", xweight));
        logger.info(sb.toString());
    }

    if (!diffractionData.getScaled()[0]) {
        diffractionData.scaleBulkFit();
        diffractionData.printStats();
    }

    // get Fo-Fc difference density
    diffractionData.getCrs_fc()[0].computeAtomicGradients(diffractionData.getRefinementData()[0].fofc1,
            diffractionData.getRefinementData()[0].freer, diffractionData.getRefinementData()[0].rfreeflag,
            RefinementMode.COORDINATES);

    refinementData[0].setOrigin(0, 0, 0);
    int extx = (int) diffractionData.getCrs_fc()[0].getXDim();
    int exty = (int) diffractionData.getCrs_fc()[0].getYDim();
    int extz = (int) diffractionData.getCrs_fc()[0].getZDim();
    refinementData[0].setExtent(extx, exty, extz);
    refinementData[0].setNI(extx, exty, extz);
    refinementData[0].setData(new double[extx * exty * extz]);
    for (int k = 0; k < extz; k++) {
        for (int j = 0; j < exty; j++) {
            for (int i = 0; i < extx; i++) {
                int index1 = (i + extx * (j + exty * k));
                int index2 = 2 * (i + extx * (j + exty * k));
                refinementData[0].getData()[index1] = diffractionData.getCrs_fc()[0].getDensityGrid()[index2];
            }
        }
    }

    /**
     * Initialize the refinement model.
     */
    refinementModel = new RefinementModel(molecularAssemblies);

    /**
     * Initialize the RealSpaceRegion.
     */
    int nAtoms = refinementModel.getTotalAtomArray().length;
    realSpaceRegion = new RealSpaceRegion(parallelTeam.getThreadCount(), nAtoms, refinementData.length);

}

From source file:ffx.xray.DiffractionData.java

/**
 * construct a diffraction data assembly
 *
 * @param assembly//from w ww .  j  a  v a  2 s  .  co  m
 * {@link ffx.potential.MolecularAssembly molecular assembly} object array
 * (typically containing alternate conformer assemblies), used as the atomic
 * model for comparison against the data
 * @param properties system properties file
 * @param solventmodel the type of solvent model desired - see
 * {@link CrystalReciprocalSpace.SolventModel bulk solvent model} selections
 * @param datafile one or more {@link DiffractionFile} to be refined against
 */
public DiffractionData(MolecularAssembly assembly[], CompositeConfiguration properties,
        SolventModel solventmodel, DiffractionFile... datafile) {

    this.assembly = assembly;
    this.solventModel = solventmodel;
    this.modelName = assembly[0].getFile().getName();
    this.dataFiles = datafile;
    this.n = datafile.length;

    int rflag = properties.getInt("rfreeflag", -1);
    fsigfCutoff = properties.getDouble("fsigfcutoff", -1.0);
    gridSearch = properties.getBoolean("gridsearch", false);
    splineFit = properties.getBoolean("splinefit", true);
    use_3g = properties.getBoolean("use_3g", true);
    aRadBuff = properties.getDouble("aradbuff", 0.75);
    double sampling = properties.getDouble("sampling", 0.6);
    xrayScaleTol = properties.getDouble("xrayscaletol", 1e-4);
    sigmaATol = properties.getDouble("sigmaatol", 0.05);
    xWeight = properties.getDouble("xweight", 1.0);
    bSimWeight = properties.getDouble("bsimweight", 1.0);
    bNonZeroWeight = properties.getDouble("bnonzeroweight", 1.0);
    bMass = properties.getDouble("bmass", 5.0);
    residueBFactor = properties.getBoolean("residuebfactor", false);
    nResidueBFactor = properties.getInt("nresiduebfactor", 1);
    addAnisou = properties.getBoolean("addanisou", false);
    refineMolOcc = properties.getBoolean("refinemolocc", false);
    occMass = properties.getDouble("occmass", 10.0);

    crystal = new Crystal[n];
    resolution = new Resolution[n];
    reflectionList = new ReflectionList[n];
    refinementData = new DiffractionRefinementData[n];
    scaleBulkMinimize = new ScaleBulkMinimize[n];
    sigmaAMinimize = new SigmaAMinimize[n];
    splineMinimize = new SplineMinimize[n];
    crystalStats = new CrystalStats[n];

    // read in Fo/sigFo/FreeR
    File tmp;
    Crystal crystalinit = Crystal.checkProperties(properties);
    Resolution resolutioninit = Resolution.checkProperties(properties);
    if (crystalinit == null || resolutioninit == null) {
        for (int i = 0; i < n; i++) {
            tmp = new File(datafile[i].getFilename());
            reflectionList[i] = datafile[i].getDiffractionfilter().getReflectionList(tmp, properties);

            if (reflectionList[i] == null) {
                logger.info(" Crystal information from the PDB or property file will be used.");
                crystalinit = assembly[i].getCrystal().getUnitCell();
                double res = datafile[i].getDiffractionfilter().getResolution(tmp, crystalinit);
                if (res < 0.0) {
                    logger.severe("MTZ/CIF/CNS file does not contain full crystal information!");
                } else {
                    resolutioninit = new Resolution(res, sampling);
                    reflectionList[i] = new ReflectionList(crystalinit, resolutioninit, properties);
                }
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            reflectionList[i] = new ReflectionList(crystalinit, resolutioninit, properties);
        }
    }

    for (int i = 0; i < n; i++) {
        crystal[i] = reflectionList[i].crystal;
        resolution[i] = reflectionList[i].resolution;
        refinementData[i] = new DiffractionRefinementData(properties, reflectionList[i]);
        tmp = new File(datafile[i].getFilename());
        datafile[i].getDiffractionfilter().readFile(tmp, reflectionList[i], refinementData[i], properties);
    }

    if (!crystal[0].equals(assembly[0].getCrystal().getUnitCell())) {
        logger.severe("PDB and reflection file crystal information do not match! (check CRYST1 record?)");
    }

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(" X-ray Refinement Settings\n\n");
        sb.append("  Target Function\n");
        sb.append("  X-ray refinement weight (xweight): ").append(xWeight).append("\n");
        sb.append("  Use cctbx 3 Gaussians (use_3g): ").append(use_3g).append("\n");
        sb.append("  Atomic form factor radius buffer (aradbuff): ").append(aRadBuff).append("\n");
        sb.append("  Reciprocal space sampling rate (sampling): ").append(sampling).append("\n");
        sb.append("  Resolution dependent spline scale (splinefit): ").append(splineFit).append("\n");
        sb.append("  Solvent grid search (gridsearch): ").append(gridSearch).append("\n");
        sb.append("  X-ray scale fit tolerance (xrayscaletol): ").append(xrayScaleTol).append("\n");
        sb.append("  Sigma A fit tolerance (sigmaatol): ").append(sigmaATol).append("\n\n");
        sb.append("  Reflections\n");
        sb.append("  F/sigF cutoff (fsigfcutoff): ").append(fsigfCutoff).append("\n");
        sb.append("  R Free flag (rfreeflag) (if -1, value will be updated when data is read in): ")
                .append(rflag).append("\n");
        sb.append("  Number of bins (nbins): ").append(reflectionList[0].nbins).append("\n\n");
        sb.append("  B-Factors\n");
        sb.append("  Similarity weight (bsimweight): ").append(bSimWeight).append("\n");
        sb.append("  Non-zero weight (bnonzeroweight): ").append(bNonZeroWeight).append("\n");
        sb.append("  Lagrangian mass (bmass): ").append(bMass).append("\n");
        sb.append("  Refined by residue (residuebfactor): ").append(residueBFactor).append("\n");
        sb.append("    (if true, num. residues per B (nresiduebfactor): ").append(nResidueBFactor)
                .append(")\n");
        sb.append("  Add ANISOU for refinement (addanisou): ").append(addAnisou).append("\n\n");
        sb.append("  Occupancies\n");
        sb.append("  Refine on molecules (HETATMs - refinemolocc): ").append(refineMolOcc).append("\n");
        sb.append("  Lagrangian mass (occmass): ").append(occMass).append("\n");

        logger.info(sb.toString());
    }

    // now set up the refinement model
    refinementModel = new RefinementModel(assembly, refineMolOcc);

    // initialize atomic form factors
    for (Atom a : refinementModel.getTotalAtomArray()) {
        a.setFormFactorIndex(-1);
        XRayFormFactor atomff = new XRayFormFactor(a, use_3g, 2.0);
        a.setFormFactorIndex(atomff.ffIndex);

        if (a.getOccupancy() == 0.0) {
            a.setFormFactorWidth(1.0);
            continue;
        }

        double arad = a.getVDWType().radius * 0.5;
        double xyz[] = new double[3];
        xyz[0] = a.getX() + arad;
        xyz[1] = a.getY();
        xyz[2] = a.getZ();
        double rho = atomff.rho(0.0, 1.0, xyz);
        while (rho > 0.001) {
            arad += 0.1;
            xyz[0] = a.getX() + arad;
            rho = atomff.rho(0.0, 1.0, xyz);
        }
        arad += aRadBuff;
        a.setFormFactorWidth(arad);
    }

    // set up FFT and run it
    crs_fc = new CrystalReciprocalSpace[n];
    crs_fs = new CrystalReciprocalSpace[n];

    parallelTeam = assembly[0].getParallelTeam();

    parallelTeam = new ParallelTeam();
    for (int i = 0; i < n; i++) {
        crs_fc[i] = new CrystalReciprocalSpace(reflectionList[i], refinementModel.getTotalAtomArray(),
                parallelTeam, parallelTeam, false, dataFiles[i].isNeutron());
        refinementData[i].setCrystalReciprocalSpace_fc(crs_fc[i]);
        crs_fc[i].setUse3G(use_3g);
        crs_fc[i].setWeight(dataFiles[i].getWeight());
        crs_fc[i].lambdaTerm = false;
        crs_fs[i] = new CrystalReciprocalSpace(reflectionList[i], refinementModel.getTotalAtomArray(),
                parallelTeam, parallelTeam, true, dataFiles[i].isNeutron(), solventmodel);
        refinementData[i].setCrystalReciprocalSpace_fs(crs_fs[i]);
        crs_fs[i].setUse3G(use_3g);
        crs_fs[i].setWeight(dataFiles[i].getWeight());
        crs_fs[i].lambdaTerm = false;

        crystalStats[i] = new CrystalStats(reflectionList[i], refinementData[i]);
    }

    scaled = new boolean[n];
    fill(scaled, false);
}

From source file:ffx.algorithms.AbstractOSRW.java

/**
 * OSRW Asynchronous MultiWalker Constructor.
 *
 * @param lambdaInterface defines Lambda and dU/dL.
 * @param potential defines the Potential energy.
 * @param lambdaFile contains the current Lambda particle position and
 * velocity./*  ww w.j  av  a2  s.c o m*/
 * @param histogramFile contains the Lambda and dU/dL histogram.
 * @param properties defines System properties.
 * @param temperature the simulation temperature.
 * @param dt the time step.
 * @param printInterval number of steps between logging updates.
 * @param saveInterval number of steps between restart file updates.
 * @param asynchronous set to true if walkers run asynchronously.
 * @param resetNumSteps whether to reset energy counts to 0
 * @param algorithmListener the AlgorithmListener to be notified of
 * progress.
 */
public AbstractOSRW(LambdaInterface lambdaInterface, Potential potential, File lambdaFile, File histogramFile,
        CompositeConfiguration properties, double temperature, double dt, double printInterval,
        double saveInterval, boolean asynchronous, boolean resetNumSteps, AlgorithmListener algorithmListener) {
    this.lambdaInterface = lambdaInterface;
    this.potential = potential;
    this.lambdaFile = lambdaFile;
    this.histogramFile = histogramFile;
    this.temperature = temperature;
    this.asynchronous = asynchronous;
    this.algorithmListener = algorithmListener;

    nVariables = potential.getNumberOfVariables();
    lowEnergyCoordsZero = new double[nVariables];
    lowEnergyCoordsOne = new double[nVariables];

    /**
     * Convert the time step to picoseconds.
     */
    this.dt = dt * 0.001;

    /**
     * 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.
     */
    saveFrequency = 1000;
    if (saveInterval >= this.dt) {
        saveFrequency = (int) (saveInterval / this.dt);
    }

    biasCutoff = properties.getInt("lambda-bias-cutoff", 5);
    biasMag = properties.getDouble("bias-gaussian-mag", 0.002);
    dL = properties.getDouble("lambda-bin-width", 0.005);
    dFL = properties.getDouble("flambda-bin-width", 2.0);

    /**
     * Require modest sampling of the lambda path.
     */
    if (dL > 0.1) {
        dL = 0.1;
    }

    /**
     * Many lambda bin widths do not evenly divide into 1.0; here we correct
     * for this by computing an integer number of bins, then re-setting the
     * lambda variable appropriately. Note that we also choose to have an
     * odd number of lambda bins, so that the centers of the first and last
     * bin are at 0 and 1.
     */
    lambdaBins = (int) (1.0 / dL);
    if (lambdaBins % 2 == 0) {
        lambdaBins++;
    }

    /**
     * The initial number of FLambda bins does not really matter, since a
     * larger number is automatically allocated as needed. The center of the
     * central bin is at 0.
     */
    FLambdaBins = 401;
    minFLambda = -(dFL * FLambdaBins) / 2.0;

    energyCount = -1;

    dL = 1.0 / (lambdaBins - 1);
    dL_2 = dL / 2.0;
    minLambda = -dL_2;
    dFL_2 = dFL / 2.0;
    maxFLambda = minFLambda + FLambdaBins * dFL;
    FLambda = new double[lambdaBins];
    dUdXdL = new double[nVariables];
    stochasticRandom = new Random(0);

    /**
     * Set up the multi-walker communication variables for Parallel Java
     * communication between nodes.
     */
    world = Comm.world();
    numProc = world.size();
    rank = world.rank();
    jobBackend = JobBackend.getJobBackend();

    /**
     * Log OSRW parameters.
     */
    logger.info(" Orthogonal Space Random Walk Parameters");
    logger.info(String.format(" Gaussian Bias Magnitude:        %6.5f (kcal/mole)", biasMag));
    logger.info(String.format(" Gaussian Bias Cutoff:           %6d bins", biasCutoff));
}

From source file:ffx.algorithms.MolecularDynamics.java

/**
 * <p>/*from  w ww.  j  av  a 2s .c o m*/
 * Constructor for MolecularDynamics.</p>
 *
 * @param assembly a {@link ffx.potential.MolecularAssembly} object.
 * @param potentialEnergy a {@link ffx.numerics.Potential} object.
 * @param properties a
 * {@link org.apache.commons.configuration.CompositeConfiguration} object.
 * @param listener a {@link ffx.algorithms.AlgorithmListener} object.
 * @param requestedThermostat a
 * {@link ffx.algorithms.Thermostat.Thermostats} object.
 * @param requestedIntegrator a
 * {@link ffx.algorithms.Integrator.Integrators} object.
 */
public MolecularDynamics(MolecularAssembly assembly, Potential potentialEnergy,
        CompositeConfiguration properties, AlgorithmListener listener, Thermostats requestedThermostat,
        Integrators requestedIntegrator) {
    this.molecularAssembly = assembly;
    assemblies = new ArrayList<>();
    assemblies.add(new AssemblyInfo(assembly));
    this.algorithmListener = listener;
    this.potential = potentialEnergy;

    assemblies.get(0).props = properties;
    mass = potentialEnergy.getMass();
    numberOfVariables = potentialEnergy.getNumberOfVariables();
    x = new double[numberOfVariables];
    v = new double[numberOfVariables];
    a = new double[numberOfVariables];
    aPrevious = new double[numberOfVariables];
    grad = new double[numberOfVariables];

    /**
     * If an Integrator wasn't passed to the MD constructor, check for one
     * specified as a property.
     */
    if (requestedIntegrator == null) {
        String integrate = properties.getString("integrate", "beeman").trim();
        try {
            requestedIntegrator = Integrators.valueOf(integrate);
        } catch (Exception e) {
            requestedIntegrator = Integrators.BEEMAN;
        }
    }
    switch (requestedIntegrator) {
    case RESPA:
        integrator = new Respa(numberOfVariables, x, v, a, aPrevious, mass);
        break;
    case STOCHASTIC:
        double friction = properties.getDouble("friction", 91.0);
        Stochastic stochastic = new Stochastic(friction, numberOfVariables, x, v, a, mass);
        if (properties.containsKey("randomseed")) {
            stochastic.setRandomSeed(properties.getInt("randomseed", 0));
        }
        integrator = stochastic;
        /**
         * The stochastic dynamics integration procedure will thermostat
         * the system. The ADIABTIC thermostat just serves to report the
         * temperature and initialize velocities if necessary.
         */
        requestedThermostat = Thermostats.ADIABATIC;
        break;
    case VELOCITYVERLET:
        integrator = new VelocityVerlet(numberOfVariables, x, v, a, mass);
        break;
    case BEEMAN:
    default:
        integrator = new BetterBeeman(numberOfVariables, x, v, a, aPrevious, mass);
    }

    /**
     * If a Thermostat wasn't passed to the MD constructor, check for one
     * specified as a property.
     */
    if (requestedThermostat == null) {
        String thermo = properties.getString("thermostat", "Berendsen").trim();
        try {
            requestedThermostat = Thermostats.valueOf(thermo);
        } catch (Exception e) {
            requestedThermostat = Thermostats.BERENDSEN;
        }
    }

    switch (requestedThermostat) {
    case BERENDSEN:
        double tau = properties.getDouble("tau-temperature", 0.2);
        thermostat = new Berendsen(numberOfVariables, x, v, mass, potentialEnergy.getVariableTypes(), 300.0,
                tau);
        break;
    case BUSSI:
        tau = properties.getDouble("tau-temperature", 0.2);
        thermostat = new Bussi(numberOfVariables, x, v, mass, potentialEnergy.getVariableTypes(), 300.0, tau);
        break;
    case ADIABATIC:
    default:
        thermostat = new Adiabatic(numberOfVariables, x, v, mass, potentialEnergy.getVariableTypes());
    }

    if (properties.containsKey("randomseed")) {
        thermostat.setRandomSeed(properties.getInt("randomseed", 0));
    }

    /**
     * For StochasticDynamics, center of mass motion will not be removed.
     */
    if (integrator instanceof Stochastic) {
        thermostat.setRemoveCenterOfMassMotion(false);
    }

    done = true;
}