Search in sources :

Example 51 with Rotamer

use of ffx.potential.bonded.Rotamer in project ffx by mjschnie.

the class RotamerOptimization method deeRotamerElimination.

/**
 * Elimination of rotamers via the original Dead End Elimination algorithm.
 *
 * @param residues Array of residues under consideration.
 * @return True if any rotamers were eliminated.
 */
private boolean deeRotamerElimination(Residue[] residues) {
    int nres = residues.length;
    // A flag to indicate if any more rotamers or rotamer pairs were eliminated.
    boolean eliminated = false;
    // Loop over residues.
    double[] minMax = new double[2];
    double[] minEnergySingles = null;
    double[] maxEnergySingles = null;
    for (int i = 0; i < nres; i++) {
        Residue residuei = residues[i];
        Rotamer[] rotamersi = residuei.getRotamers(library);
        int lenri = rotamersi.length;
        if (minEnergySingles == null || minEnergySingles.length < lenri) {
            minEnergySingles = new double[lenri];
            maxEnergySingles = new double[lenri];
        }
        // Loop over the set of rotamers for residue i.
        for (int ri = 0; ri < lenri; ri++) {
            // Check for an eliminated single.
            if (check(i, ri)) {
                continue;
            }
            // Start the min/max summation with the self-energy.
            minEnergySingles[ri] = getSelf(i, ri);
            maxEnergySingles[ri] = minEnergySingles[ri];
            for (int j = 0; j < nres; j++) {
                if (j == i) {
                    continue;
                }
                if (minMaxPairEnergy(residues, minMax, i, ri, j)) {
                    if (Double.isFinite(minMax[0]) && Double.isFinite(minEnergySingles[ri])) {
                        minEnergySingles[ri] += minMax[0];
                    } else {
                        // There is a possibility that ri conflicts with every possible rotamer of some residue j.
                        // In that event, its minimum energy is set NaN and should be easy to eliminate.
                        minEnergySingles[ri] = Double.NaN;
                    }
                    if (Double.isFinite(minMax[0]) && Double.isFinite(maxEnergySingles[ri])) {
                        maxEnergySingles[ri] += minMax[1];
                    } else {
                        // In this branch, ri conflicts with some j,rj and cannot be practically used for elimination.
                        maxEnergySingles[ri] = Double.NaN;
                    }
                } else {
                    Residue residuej = residues[j];
                    logger.info(format(" Inconsistent Pair: %8s %2d, %8s.", residuei.toFormattedString(false, true), ri, residuej.toFormattedString(false, true)));
                // eliminateRotamer(residues, i, ri, print);
                }
            }
        }
        /**
         * Apply the singles elimination criteria to rotamers of residue i
         * by determining the most favorable maximum energy.
         */
        double eliminationEnergy = Double.MAX_VALUE;
        int eliminatingRotamer = 0;
        for (int ri = 0; ri < lenri; ri++) {
            if (check(i, ri)) {
                continue;
            }
            if (Double.isFinite(maxEnergySingles[ri]) && maxEnergySingles[ri] < eliminationEnergy) {
                eliminationEnergy = maxEnergySingles[ri];
                eliminatingRotamer = ri;
            }
        }
        if (eliminationEnergy == Double.MAX_VALUE) {
            // This branch is taken if every ri conflicts with at least one j,rj. In that case, nothing can be eliminated yet!
            logIfMaster(" Could not eliminate any i,ri because eliminationEnergy was never set!", Level.FINE);
        } else {
            /**
             * Eliminate rotamers whose minimum energy is greater than the
             * worst case for another rotamer.
             */
            for (int ri = 0; ri < lenri; ri++) {
                if (check(i, ri)) {
                    continue;
                }
                // If i,ri has a clash with all of phase space, it can be eliminated by something that doesn't clash with all phase space.
                if (!Double.isFinite(minEnergySingles[ri])) {
                    if (eliminateRotamer(residues, i, ri, print)) {
                        logIfMaster(format("  Rotamer elimination of (%8s,%2d) that always clashes.", residuei.toFormattedString(false, true), ri));
                        eliminated = true;
                    }
                }
                // Otherwise, can eliminate if its best possible energy is still worse than something else's worst possible energy.
                if (minEnergySingles[ri] > eliminationEnergy + ensembleBuffer) {
                    if (eliminateRotamer(residues, i, ri, print)) {
                        logIfMaster(format("  Rotamer elimination of (%8s,%2d) by (%8s,%2d): %12.4f > %6.4f.", residuei.toFormattedString(false, true), ri, residuei.toFormattedString(false, true), eliminatingRotamer, minEnergySingles[ri], eliminationEnergy + ensembleBuffer));
                        eliminated = true;
                    }
                }
            }
        }
    }
    return eliminated;
}
Also used : Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue) RotamerLibrary.applyRotamer(ffx.potential.bonded.RotamerLibrary.applyRotamer) Rotamer(ffx.potential.bonded.Rotamer)

Example 52 with Rotamer

use of ffx.potential.bonded.Rotamer in project ffx by mjschnie.

the class GenerateRotamers method applyLibRotamer.

/**
 * Applies a library rotamer, filling in the end with 0s as necessary. For
 * example, PTR requires more torsions than TYR, so one cannot simply apply
 * a TYR rotamer to a PTR residue.
 * @param rotamer
 */
private void applyLibRotamer(Rotamer rotamer) {
    double[] rotValues = new double[nChi * 2];
    Arrays.fill(rotValues, 0.0);
    Arrays.fill(currentChi, 0.0);
    int fillTo = Math.min(startDepth, (rotamer.length - 1));
    for (int i = 0; i < fillTo; i++) {
        int ii = 2 * i;
        rotValues[ii] = rotamer.angles[i];
        currentChi[i] = rotamer.angles[i];
        rotValues[ii + 1] = rotamer.sigmas[i];
    }
    Rotamer newRot = generateRotamer(rotValues);
    RotamerLibrary.applyRotamer(residue, newRot);
}
Also used : Rotamer(ffx.potential.bonded.Rotamer)

Example 53 with Rotamer

use of ffx.potential.bonded.Rotamer in project ffx by mjschnie.

the class GenerateRotamers method tryRotamers.

/**
 * Main driver method; spins torsions, evaluates energy, and prints to file.
 */
public void tryRotamers() {
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(outFile))) {
        if (aroundLibrary) {
            for (Rotamer rotamer : baselineRotamers) {
                applyLibRotamer(rotamer);
                turnChi(startDepth, bw);
            }
        } else {
            RotamerLibrary.measureRotamer(residue, currentChi, false);
            turnChi(startDepth, bw);
        }
    } catch (IOException ex) {
        logger.warning(String.format(" IO exception in rotamer generation: %s", ex.toString()));
    }
}
Also used : FileWriter(java.io.FileWriter) Rotamer(ffx.potential.bonded.Rotamer) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 54 with Rotamer

use of ffx.potential.bonded.Rotamer in project ffx by mjschnie.

the class RosenbluthChiAllMove method engage_control.

/**
 * For validation. Performs Monte Carlo chi moves WITHOUT biasing. Randomly
 * select one chi, give it a random theta. Accept on the vanilla Metropolis
 * criterion.
 */
private boolean engage_control() {
    report.append(String.format(" Rosenbluth Control Move: %4d  %s\n", moveNumber, target));
    double origEnergy = totalEnergy();
    double[] origChi = RotamerLibrary.measureRotamer(target, false);
    int chiIndex = rand.nextInt(origChi.length);
    double theta = rand.nextDouble(360.0) - 180;
    double[] newChi = new double[origChi.length];
    System.arraycopy(origChi, 0, newChi, 0, origChi.length);
    newChi[chiIndex] = theta;
    Rotamer newState = createRotamer(target, newChi);
    RotamerLibrary.applyRotamer(target, newState);
    double finalEnergy = totalEnergy();
    double dU = finalEnergy - origEnergy;
    double criterion = FastMath.exp(-beta * dU);
    double rng = rand.nextDouble();
    report.append(String.format("    move (chi,theta): %d %5.1f\n", chiIndex, theta));
    report.append(String.format("    orig, final, dU:  %.2g %.2g %.2g\n", origEnergy, finalEnergy, dU));
    report.append(String.format("    crit, rng:        %.2g %.2g\n", criterion, rng));
    if (rng < criterion) {
        accepted = true;
        report.append(String.format("    Accepted!\n"));
        PDBFilter writer = new PDBFilter(mola.getFile(), mola, null, null);
        String filename = FilenameUtils.removeExtension(mola.getFile().toString());
        filename = mola.getFile().getAbsolutePath();
        if (!filename.contains("_mc")) {
            filename = FilenameUtils.removeExtension(filename) + "_mc.pdb";
        }
        File file = new File(filename);
        writer.writeFile(file, false);
    } else {
        accepted = false;
        report.append(String.format("    Denied.\n"));
        target.revertState(origState);
    }
    updateAll();
    if (verbose) {
        logger.info(report.toString());
    }
    return (rng < criterion);
}
Also used : Rotamer(ffx.potential.bonded.Rotamer) PDBFilter(ffx.potential.parsers.PDBFilter) File(java.io.File)

Example 55 with Rotamer

use of ffx.potential.bonded.Rotamer in project ffx by mjschnie.

the class RosenbluthChiAllMove method cheapTorsionSet.

/**
 * This version foregoes doing a full energy eval (uExt) on each member of
 * each chi test set. Instead, each member of the test set is a full set of
 * chi angles, the COMBINATION of which is drawn from the Boltzmann.
 */
private TrialSet cheapTorsionSet(List<Torsion> allTors, int setSize, String snapSuffix) {
    if (printTestSets) {
        report.append(String.format("    TrialSet_Cheap (uDep uExt)\n"));
    }
    TrialSet trialSet = new TrialSet(setSize);
    double[] origChi = RotamerLibrary.measureRotamer(target, false);
    int i = 0;
    while (i < setSize) {
        double[] newChi = new double[origChi.length];
        System.arraycopy(origChi, 0, newChi, 0, origChi.length);
        for (int k = 0; k < origChi.length; k++) {
            if (doChi[k]) {
                if (randInts) {
                    newChi[k] = rand.nextInt(360) - 180;
                } else {
                    newChi[k] = rand.nextDouble(360.0) - 180;
                }
            }
        }
        // report.append(String.format(" newChi:"));
        // for (int k = 0; k < origChi.length; k++) {
        // report.append(String.format(" %.2f", newChi[k]));
        // }
        // report.append("\n");
        Rotamer newState = createRotamer(target, newChi);
        RotamerLibrary.applyRotamer(target, newState);
        double uTors = 0;
        for (int j = 0; j < allTors.size(); j++) {
            if (doChi[j]) {
                uTors += allTors.get(j).energy(false);
                double offset = 0;
                try {
                    offset = TORSION_OFFSET_AMPRO13.valueOf(target.getName() + j).offset;
                } catch (IllegalArgumentException ex) {
                    logger.warning(ex.getMessage());
                }
                uTors += offset;
            }
        }
        double criterion = FastMath.exp(-beta * uTors);
        double rng = rand.nextDouble();
        if (rng < criterion) {
            // this cheap version does all thetas at once
            trialSet.theta[i] = 0.0;
            trialSet.rotamer[i] = newState;
            trialSet.uDep[i] = uTors;
            trialSet.uExt[i] = totalEnergy() - uTors;
            i++;
            writeSnapshot(snapSuffix, true);
            if (printTestSets) {
                if (i < 5 || i > setSize - 1) {
                    report.append(String.format("       %3s %d:      %5.2f\t%5.2f\n", snapSuffix, i, trialSet.uDep[i - 1], trialSet.uExt[i - 1]));
                } else if (i == 5) {
                    report.append(String.format("       ...\n"));
                }
            }
        }
    }
    target.revertState(origState);
    updateAll();
    return trialSet;
}
Also used : Rotamer(ffx.potential.bonded.Rotamer)

Aggregations

Rotamer (ffx.potential.bonded.Rotamer)56 Residue (ffx.potential.bonded.Residue)44 MultiResidue (ffx.potential.bonded.MultiResidue)42 RotamerLibrary.applyRotamer (ffx.potential.bonded.RotamerLibrary.applyRotamer)40 IOException (java.io.IOException)12 NACorrectionException (ffx.potential.bonded.NACorrectionException)10 Atom (ffx.potential.bonded.Atom)8 ResidueState (ffx.potential.bonded.ResidueState)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 PDBFilter (ffx.potential.parsers.PDBFilter)4 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 Polymer (ffx.potential.bonded.Polymer)3 TitrationUtils.inactivateResidue (ffx.potential.extended.TitrationUtils.inactivateResidue)3 AminoAcid3 (ffx.potential.bonded.ResidueEnumerations.AminoAcid3)2 RotamerLibrary (ffx.potential.bonded.RotamerLibrary)2 Torsion (ffx.potential.bonded.Torsion)2 Test (org.junit.Test)2 BooleanBuf (edu.rit.mp.BooleanBuf)1