Search in sources :

Example 26 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class RefinementMinimize method optimizationUpdate.

/**
 * {@inheritDoc}
 */
@Override
public boolean optimizationUpdate(int iter, int nfun, double grms, double xrms, double f, double df, double angle, LineSearchResult info) {
    long currentTime = System.nanoTime();
    Double seconds = (currentTime - time) * 1.0e-9;
    time = currentTime;
    this.grms = grms;
    this.nSteps = iter;
    // update display
    if (listener != null) {
        MolecularAssembly[] molecularAssembly;
        molecularAssembly = dataContainer.getMolecularAssemblies();
        for (MolecularAssembly ma : molecularAssembly) {
            listener.algorithmUpdate(ma);
        }
    }
    if (iter == 0) {
        logger.info("\n Limited Memory BFGS Quasi-Newton Optimization: \n");
        logger.info(" Cycle       Energy      G RMS    Delta E   Delta X    Angle  Evals     Time      " + dataContainer.printOptimizationHeader());
    }
    if (info == null) {
        logger.info(String.format("%6d %12.3f %10.3f", iter, f, grms));
    } else if (info == LineSearchResult.Success) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("%6d %12.3f %10.3f %10.3f %9.4f %8.2f %6d %8.3f ", iter, f, grms, df, xrms, angle, nfun, seconds));
        sb.append(dataContainer.printOptimizationUpdate());
        logger.info(sb.toString());
    } else {
        logger.info(String.format("%6d %12.3g %10.3f %10.3f %9.4f %8.2f %6d %8s", iter, f, grms, df, xrms, angle, nfun, info.toString()));
    }
    if (terminate) {
        logger.info(" The optimization recieved a termination request.");
        // Tell the L-BFGS optimizer to terminate.
        return false;
    }
    return true;
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly)

Example 27 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class Rescore method rescoreSingle.

private File rescoreSingle(File modelFile, RescoreStrategy rscType, DoubleIndexPair[] energies, int i) {
    Path filepath = generatePath(modelFile);
    if (filepath == null) {
        logger.warning(String.format(" Could not generate path to file %s", modelFile.toPath()));
        return null;
    }
    String filename = pwdPath.relativize(filepath).toString();
    File retFile = modelFile;
    try {
        MolecularAssembly assembly = utils.open(filename);
        switch(rscType) {
            case NO_RESCORE:
                logger.warning(" Rescore is being called with rscType = NO_RESCORE");
                break;
            case ENERGY_EVAL:
                break;
            case MINIMIZE:
                logger.info(String.format("\n Running minimize on %s", filename));
                logger.info(String.format(" RMS gradient convergence criteria: %f", eps));
                utils.energy(assembly);
                utils.minimize(assembly, eps);
                String ext = FilenameUtils.getExtension(filename);
                ext = ".".concat(ext);
                if (resultDir != null) {
                    filename = FilenameUtils.getBaseName(filename);
                    filename = FilenameUtils.concat(resultPath.toString(), filename);
                } else {
                    filename = FilenameUtils.removeExtension(filename);
                }
                filename = filename.concat(fileSuffix).concat(ext);
                retFile = new File(filename);
                if (ext.toUpperCase().contains("XYZ")) {
                    utils.saveAsXYZ(assembly, retFile);
                } else {
                    utils.saveAsPDB(assembly, retFile);
                }
                break;
            case XRAY_MIN:
                logger.info(String.format("\n Running x-ray minimize on %s", filename));
                DiffractionFile diffractionFile = null;
                if (diffractionFiles.isEmpty()) {
                    diffractionFile = new DiffractionFile(assembly, 1.0, false);
                    diffractionFiles.add(diffractionFile);
                }
                CompositeConfiguration properties = Keyword.loadProperties(modelFile);
                DiffractionData diffractionData = new DiffractionData(assembly, properties, SolventModel.POLYNOMIAL, diffractionFiles.toArray(new DiffractionFile[diffractionFiles.size()]));
                diffractionData.scaleBulkFit();
                diffractionData.printStats();
                utils.energy(assembly);
                RefinementMinimize refinementMinimize = new RefinementMinimize(diffractionData, refinementMode);
                if (eps < 0.0) {
                    eps = refinementMinimize.getEps();
                }
                logger.info(String.format("\n RMS gradient convergence criteria: %8.5f max number of iterations %d", eps, maxiter));
                refinementMinimize.minimize(eps, maxiter);
                diffractionData.scaleBulkFit();
                diffractionData.printStats();
                ext = FilenameUtils.getExtension(filename);
                ext = ".".concat(ext);
                if (resultDir != null) {
                    filename = FilenameUtils.getBaseName(filename);
                    filename = FilenameUtils.concat(resultPath.toString(), filename);
                } else {
                    filename = FilenameUtils.removeExtension(filename);
                }
                filename = filename.concat(fileSuffix);
                diffractionData.writeData(filename + ".mtz");
                filename = filename.concat(ext);
                diffractionData.writeModel(filename);
                retFile = new File(filename);
                if (diffractionFile != null) {
                    try {
                        diffractionFiles.remove(diffractionFile);
                    } catch (UnsupportedOperationException ex) {
                        // This should never occur, because diffractionFiles should be of a List type supporting remove(object).
                        diffractionFiles = new ArrayList<>();
                    }
                }
                break;
            case RS_MIN:
                logger.info(String.format("\n Running real-space minimize on %s", filename));
                RealSpaceFile realspaceFile = null;
                if (mapFiles.isEmpty()) {
                    realspaceFile = new RealSpaceFile(assembly);
                    mapFiles.add(realspaceFile);
                }
                properties = Keyword.loadProperties(modelFile);
                RealSpaceData realspaceData = new RealSpaceData(assembly, properties, new ParallelTeam(), mapFiles.toArray(new RealSpaceFile[mapFiles.size()]));
                utils.energy(assembly);
                refinementMinimize = new RefinementMinimize(realspaceData, refinementMode);
                if (eps < 0.0) {
                    eps = 1.0;
                }
                logger.info(String.format("\n RMS gradient convergence criteria: %8.5f max number of iterations %d", eps, maxiter));
                refinementMinimize.minimize(eps, maxiter);
                ext = FilenameUtils.getExtension(filename);
                ext = ".".concat(ext);
                if (resultDir != null) {
                    filename = FilenameUtils.getBaseName(filename);
                    filename = FilenameUtils.concat(resultPath.toString(), filename);
                } else {
                    filename = FilenameUtils.removeExtension(filename);
                }
                filename = filename.concat(fileSuffix).concat(ext);
                retFile = new File(filename);
                if (ext.toUpperCase().contains("XYZ")) {
                    utils.saveAsXYZ(assembly, retFile);
                } else {
                    utils.saveAsPDB(assembly, retFile);
                }
                if (realspaceFile != null) {
                    try {
                        mapFiles.remove(realspaceFile);
                    } catch (UnsupportedOperationException ex) {
                        // This should never occur, because diffractionFiles should be of a List type supporting remove(object).
                        mapFiles = new ArrayList<>();
                    }
                }
                break;
            default:
                logger.severe(" No valid rescore type: FFX will not continue.");
        }
        double e = utils.returnEnergy(assembly);
        energies[i] = new DoubleIndexPair(i, e);
        utils.close(assembly);
    } catch (Exception ex) {
        logger.warning(String.format(" Exception rescoring on file %s", filename));
        logger.info(ex.toString());
    }
    return retFile;
}
Also used : Path(java.nio.file.Path) ClusterStructures.generatePath(ffx.algorithms.ClusterStructures.generatePath) DoubleIndexPair(ffx.utilities.DoubleIndexPair) ParallelTeam(edu.rit.pj.ParallelTeam) RealSpaceFile(ffx.realspace.RealSpaceFile) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DiffractionFile(ffx.xray.parsers.DiffractionFile) MolecularAssembly(ffx.potential.MolecularAssembly) RealSpaceData(ffx.realspace.RealSpaceData) DiffractionFile(ffx.xray.parsers.DiffractionFile) File(java.io.File) RealSpaceFile(ffx.realspace.RealSpaceFile)

Example 28 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class TimerTest method main.

public static void main(String[] args) {
    // Parameters collection from original Timer script
    String pdbname = System.getProperty("pdbFile", "1N7S.pdb");
    String mtzname = System.getProperty("mtzFile", null);
    String cifname = System.getProperty("cifFile", null);
    final boolean ciOnly = false;
    final String info = "SNARE complex";
    final double r = 19.412671496011;
    final double rfree = 21.555930987573;
    final double sigmaA = 0.9336853524690557;
    final double sigmaW = 0.13192537249786418;
    boolean ci = System.getProperty("ffx.ci", "false").equalsIgnoreCase("true");
    if (!ci && ciOnly) {
        crystalStats = null;
        return;
    }
    int index = pdbname.lastIndexOf(".");
    String name = pdbname.substring(0, index);
    // load the structure
    MolecularAssembly molecularAssembly;
    File structure, mtzFile, cifFile;
    structure = new File(pdbname);
    PotentialsFileOpener opener = new PotentialsFileOpener(structure);
    opener.run();
    molecularAssembly = opener.getAssembly();
    mtzFile = new File(mtzname);
    cifFile = new File(cifname);
    // load any properties associated with it
    CompositeConfiguration properties = Keyword.loadProperties(structure);
    // read in Fo/sigFo/FreeR
    MTZFilter mtzFilter = new MTZFilter();
    CIFFilter cifFilter = new CIFFilter();
    Crystal crystal = Crystal.checkProperties(properties);
    Resolution resolution = Resolution.checkProperties(properties);
    if (crystal == null || resolution == null) {
        if (mtzname != null) {
            reflectionList = mtzFilter.getReflectionList(mtzFile);
        } else {
            reflectionList = cifFilter.getReflectionList(cifFile);
        }
    } else {
        reflectionList = new ReflectionList(crystal, resolution);
    }
    refinementData = new DiffractionRefinementData(properties, reflectionList);
    if (mtzname != null) {
    // assertTrue(info + " mtz file should be read in without errors",
    // mtzFilter.readFile(mtzFile, reflectionList, refinementData,
    // properties));
    } else {
    // assertTrue(info + " cif file should be read in without errors",
    // cifFilter.readFile(cifFile, reflectionList, refinementData,
    // properties));
    }
    ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    // associate molecular assembly with the structure, set up forcefield
    molecularAssembly.setForceField(forceField);
    PDBFilter pdbFile = new PDBFilter(structure, molecularAssembly, forceField, properties);
    pdbFile.readFile();
    pdbFile.applyAtomProperties();
    molecularAssembly.finalize(true, forceField);
    ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(molecularAssembly, pdbFile.getCoordRestraints());
    List<Atom> atomList = molecularAssembly.getAtomList();
    Atom[] atomArray = atomList.toArray(new Atom[atomList.size()]);
    // set up FFT and run it
    parallelTeam = new ParallelTeam();
    CrystalReciprocalSpace crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam, false);
    crs.computeDensity(refinementData.fc);
    refinementData.setCrystalReciprocalSpace_fc(crs);
    crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam, true);
    crs.computeDensity(refinementData.fs);
    refinementData.setCrystalReciprocalSpace_fs(crs);
    ScaleBulkMinimize scaleBulkMinimize = new ScaleBulkMinimize(reflectionList, refinementData, crs, parallelTeam);
    scaleBulkMinimize.minimize(6, 1.0e-4);
    SigmaAMinimize sigmaAMinimize = new SigmaAMinimize(reflectionList, refinementData, parallelTeam);
    sigmaAMinimize.minimize(7, 2.0e-2);
    SplineMinimize splineMinimize = new SplineMinimize(reflectionList, refinementData, refinementData.spline, SplineEnergy.Type.FOFC);
    splineMinimize.minimize(7, 1e-5);
    crystalStats = new CrystalStats(reflectionList, refinementData);
    scaleBulkMinimize = new ScaleBulkMinimize(reflectionList, refinementData, refinementData.crs_fs, parallelTeam);
    ScaleBulkEnergy scaleBulkEnergy = scaleBulkMinimize.getScaleBulkEnergy();
    int n = scaleBulkMinimize.getNumberOfVariables();
    double[] x = new double[n];
    double[] g = new double[n];
    scaleBulkMinimize.getCoordinates(x);
    scaleBulkEnergy.energyAndGradient(x, g);
    double delta = 1.0e-4;
    double tolerance = 1.0e-4;
    logger.info(String.format("SCATTER TEST"));
    for (int i = 0; i < 30; i++) {
        long time = -System.nanoTime();
        scaleBulkEnergy.energyAndGradient(x, g);
        time += System.nanoTime();
        logger.info(String.format(" Time %12.8f", time * 1.0e-9));
    }
}
Also used : ParallelTeam(edu.rit.pj.ParallelTeam) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) ReflectionList(ffx.crystal.ReflectionList) ForceField(ffx.potential.parameters.ForceField) PDBFilter(ffx.potential.parsers.PDBFilter) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Atom(ffx.potential.bonded.Atom) PotentialsFileOpener(ffx.potential.utils.PotentialsFileOpener) MolecularAssembly(ffx.potential.MolecularAssembly) CIFFilter(ffx.xray.parsers.CIFFilter) File(java.io.File) MTZFilter(ffx.xray.parsers.MTZFilter) Crystal(ffx.crystal.Crystal) Resolution(ffx.crystal.Resolution)

Example 29 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class PotentialsUtils method openQuietly.

/**
 * Open one File object without printing all the header material.
 *
 * @param file
 * @return
 */
public MolecularAssembly openQuietly(File file) {
    setSilentPotential(true);
    MolecularAssembly mola = open(file);
    setSilentPotential(false);
    return mola;
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly)

Example 30 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class PotentialsUtils method openQuietly.

/**
 * Open one filename string without printing all the header material.
 *
 * @param filename
 * @return
 */
public MolecularAssembly openQuietly(String filename) {
    setSilentPotential(true);
    MolecularAssembly mola = open(filename);
    setSilentPotential(false);
    return mola;
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly)

Aggregations

MolecularAssembly (ffx.potential.MolecularAssembly)34 File (java.io.File)13 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)11 Atom (ffx.potential.bonded.Atom)10 Crystal (ffx.crystal.Crystal)7 MSNode (ffx.potential.bonded.MSNode)7 IOException (java.io.IOException)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)5 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)5 Molecule (ffx.potential.bonded.Molecule)5 Polymer (ffx.potential.bonded.Polymer)5 Residue (ffx.potential.bonded.Residue)5 PDBFilter (ffx.potential.parsers.PDBFilter)5 ParallelTeam (edu.rit.pj.ParallelTeam)4 Bond (ffx.potential.bonded.Bond)4 ExtendedSystem (ffx.potential.extended.ExtendedSystem)4 ForceField (ffx.potential.parameters.ForceField)4 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)4 BufferedWriter (java.io.BufferedWriter)4