Search in sources :

Example 21 with Residue

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

the class RotamerOptimization method pairsToSingleElimination.

/**
 * Method to check if pairs elimination for some residue pair has enabled a
 * singles rotamer elimination by eliminating all ri-rj for some ri or some
 * rj.
 *
 * @param residues Residues under consideration.
 * @param i A residue index.
 * @param j A residue index j!=i
 * @return If any singletons were eliminated.
 */
private boolean pairsToSingleElimination(Residue[] residues, int i, int j) {
    assert i != j;
    assert i < residues.length;
    assert j < residues.length;
    Residue residuei = residues[i];
    Residue residuej = residues[j];
    Rotamer[] rotsi = residuei.getRotamers(library);
    Rotamer[] rotsj = residuej.getRotamers(library);
    int lenri = rotsi.length;
    int lenrj = rotsj.length;
    boolean eliminated = false;
    // Now check ris with no remaining pairs to j.
    for (int ri = 0; ri < lenri; ri++) {
        if (check(i, ri)) {
            continue;
        }
        boolean pairRemaining = false;
        for (int rj = 0; rj < lenrj; rj++) {
            if (!check(j, rj) && !check(i, ri, j, rj)) {
                pairRemaining = true;
                break;
            }
        }
        if (!pairRemaining) {
            if (eliminateRotamer(residues, i, ri, print)) {
                eliminated = true;
                logIfMaster(format(" Eliminating rotamer %s-%d with no remaining pairs to residue %s.", residuei.toFormattedString(false, true), ri, residuej));
            } else {
                logIfMaster(format(" Already eliminated rotamer %s-%d with no remaining pairs to residue %s.", residuei.toFormattedString(false, true), ri, residuej), Level.WARNING);
            }
        }
    }
    // Check rjs with no remaining pairs to i.
    for (int rj = 0; rj < lenrj; rj++) {
        if (check(j, rj)) {
            continue;
        }
        boolean pairRemaining = false;
        for (int ri = 0; ri < lenri; ri++) {
            if (!check(i, ri) && !check(i, ri, j, rj)) {
                pairRemaining = true;
                break;
            }
        }
        if (!pairRemaining) {
            if (eliminateRotamer(residues, j, rj, print)) {
                eliminated = true;
                logIfMaster(format(" Eliminating rotamer %s-%d with no remaining pairs to residue %s.", residuej.toFormattedString(false, true), rj, residuei));
            } else {
                logIfMaster(format(" Already eliminated rotamer J %s-%d with no remaining pairs to residue %s.", residuej.toFormattedString(false, true), rj, residuei), Level.WARNING);
            }
        }
    }
    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 22 with Residue

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

the class RotamerOptimization method goldsteinPairElimination.

/**
 * Attempt to eliminate rotamer pair (ResI-RotA, ResJ-RotC) using
 * (ResI-RotB, ResJ-RotD).
 *
 * @param residues
 * @param i Index of the first residue.
 * @param riA Index of the first residue's rotamer to eliminate.
 * @param riB Index of the first residue's rotamer to use for elimination.
 * @param j Index of the 2nd residue.
 * @param rjC Index of the 2nd residue's rotamer to eliminate.
 * @param rjD Index of the 2nd residue's rotamer to use for elimination.
 * @return Return true if eliminated.
 */
private boolean goldsteinPairElimination(Residue[] residues, int i, int riA, int riB, int j, int rjC, int rjD) {
    ArrayList<Residue> missedResidues = null;
    // Initialize the Goldstein energy.
    double goldsteinEnergy = getSelf(i, riA) + getSelf(j, rjC) + get2Body(i, riA, j, rjC) - getSelf(i, riB) - getSelf(j, rjD) - get2Body(i, riB, j, rjD);
    try {
        if (parallelTeam == null) {
            parallelTeam = new ParallelTeam();
        }
        if (goldsteinPairRegion == null) {
            goldsteinPairRegion = new GoldsteinPairRegion(parallelTeam.getThreadCount());
        }
        goldsteinPairRegion.init(residues, i, riA, riB, j, rjC, rjD);
        parallelTeam.execute(goldsteinPairRegion);
        goldsteinEnergy += goldsteinPairRegion.getSumOverK();
        missedResidues = goldsteinPairRegion.getMissedResidues();
    } catch (Exception e) {
        logger.log(Level.WARNING, " Exception in GoldsteinPairRegion.", e);
    }
    // goldsteinEnergy += goldsteinPairSumOverK(residues, 0, nres-1, i, riA, riB, j, rjC, rjD);
    if (missedResidues != null && !missedResidues.isEmpty()) {
        logIfMaster(format(" Skipping energy comparison due to a missed residue: i %d riA %d riB %d j %d rjC %d rjD %d", i, riA, riB, j, rjC, rjD), Level.FINE);
        return false;
    }
    if (goldsteinEnergy > ensembleBuffer) {
        if (missedResidues.isEmpty()) {
            if (eliminateRotamerPair(residues, i, riA, j, rjC, print)) {
                logIfMaster(format("  Pair elimination of [(%8s,%2d),(%8s,%2d)] by [(%8s,%2d),(%8s,%2d)]: %12.4f > %6.4f", residues[i].toFormattedString(false, true), riA, residues[j].toFormattedString(false, true), rjC, residues[i].toFormattedString(false, true), riB, residues[j].toFormattedString(false, true), rjD, goldsteinEnergy, ensembleBuffer));
                return true;
            }
        } else {
            logIfMaster(format("  No Pair elimination of [(%8s,%2d),(%8s,%2d)] by [(%8s,%2d),(%8s,%2d)]: %12.4f > %6.4f", residues[i].toFormattedString(false, true), riA, residues[j].toFormattedString(false, true), rjC, residues[i].toFormattedString(false, true), riB, residues[j].toFormattedString(false, true), rjD, goldsteinEnergy, ensembleBuffer));
            StringBuffer sb = new StringBuffer();
            for (int m = 0; m < missedResidues.size(); m++) {
                Residue residueM = missedResidues.get(m);
                sb.append(residueM);
            }
            logIfMaster(format("   due to %s.", sb));
        }
    }
    return false;
}
Also used : ParallelTeam(edu.rit.pj.ParallelTeam) Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue) IOException(java.io.IOException) NACorrectionException(ffx.potential.bonded.NACorrectionException)

Example 23 with Residue

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

the class RotamerOptimization method setResidues.

/**
 * Set a contiguous block of residues to optimize.
 *
 * @param startResID
 * @param finalResID
 */
public void setResidues(int startResID, int finalResID) {
    Polymer polymer;
    if (chain != null) {
        polymer = molecularAssembly.getChain(chain);
    } else {
        polymers = molecularAssembly.getChains();
        polymer = polymers[0];
    }
    residueList = new ArrayList<>();
    for (int i = startResID; i <= finalResID; i++) {
        Residue residue = polymer.getResidue(i);
        if (residue != null) {
            Rotamer[] rotamers = residue.getRotamers(library);
            if (rotamers != null) {
                if (rotamers.length == 1) {
                    switch(residue.getResidueType()) {
                        case NA:
                            residue.initializeDefaultAtomicCoordinates();
                            break;
                        case AA:
                        default:
                            RotamerLibrary.applyRotamer(residue, rotamers[0]);
                            break;
                    }
                    if (addOrigRot) {
                        residueList.add(residue);
                    }
                } else {
                    residueList.add(residue);
                }
            } else if (useForcedResidues && checkIfForced(i)) {
                residueList.add(residue);
            }
        }
    }
}
Also used : Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue) Polymer(ffx.potential.bonded.Polymer) RotamerLibrary.applyRotamer(ffx.potential.bonded.RotamerLibrary.applyRotamer) Rotamer(ffx.potential.bonded.Rotamer)

Example 24 with Residue

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

the class RotamerOptimization method setResiduesIgnoreNull.

/**
 * Accepts a list of residues but throws out null residues. Used by the -lR
 * flag.
 *
 * @param residueList
 * @return Added residues.
 */
public List<Residue> setResiduesIgnoreNull(ArrayList<Residue> residueList) {
    this.residueList = new ArrayList<>();
    logger.info(" Optimizing these residues: ");
    for (Residue r : residueList) {
        if (r.getRotamers(library) != null) {
            this.residueList.add(r);
            logger.info(format("\t%s", r.toString()));
        } else {
            logger.info(format(" not \t%s", r.toString()));
        }
    }
    return new ArrayList<>(residueList);
}
Also used : Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue) ArrayList(java.util.ArrayList)

Example 25 with Residue

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

the class RotamerOptimization method rotamerOptimization.

/**
 * A brute-force global optimization over side-chain rotamers using a
 * recursive algorithm.
 *
 * @param molecularAssembly
 * @param residues
 * @param i
 * @param lowEnergy
 * @param optimum
 * @return the current energy.
 */
public double rotamerOptimization(MolecularAssembly molecularAssembly, Residue[] residues, int i, double lowEnergy, int[] optimum) {
    // This is the initialization condition.
    if (i == 0) {
        evaluatedPermutations = 0;
    }
    int nResidues = residues.length;
    Residue current = residues[i];
    Rotamer[] rotamers = current.getRotamers(library);
    int lenri = rotamers.length;
    double currentEnergy = Double.MAX_VALUE;
    List<Residue> resList = Arrays.asList(residues);
    if (i < nResidues - 1) {
        /**
         * As long as there are more residues, continue the recursion for
         * each rotamer of the current residue.
         */
        int minRot = -1;
        for (int ri = 0; ri < lenri; ri++) {
            applyRotamer(current, rotamers[ri]);
            double rotEnergy = rotamerOptimization(molecularAssembly, residues, i + 1, lowEnergy, optimum);
            if (rotEnergy < currentEnergy) {
                currentEnergy = rotEnergy;
            }
            if (rotEnergy < lowEnergy) {
                minRot = ri;
                lowEnergy = rotEnergy;
            }
        }
        if (minRot > -1) {
            optimum[i] = minRot;
        }
    } else {
        /**
         * At the end of the recursion, compute the potential energy for
         * each rotamer of the final residue. If a lower potential energy is
         * discovered, the rotamers of each residue will be collected as the
         * recursion returns up the chain.
         */
        for (int ri = 0; ri < lenri; ri++) {
            applyRotamer(current, rotamers[ri]);
            double rotEnergy = Double.NaN;
            try {
                rotEnergy = currentEnergy(resList);
                logger.info(format(" %d Energy: %s", ++evaluatedPermutations, formatEnergy(rotEnergy)));
            } catch (ArithmeticException ex) {
                logger.info(String.format(" %d Energy set to NaN (unreasonable conformation)", ++evaluatedPermutations));
            }
            if (algorithmListener != null) {
                algorithmListener.algorithmUpdate(molecularAssembly);
            }
            if (rotEnergy < currentEnergy) {
                currentEnergy = rotEnergy;
            }
            if (rotEnergy < lowEnergy) {
                lowEnergy = rotEnergy;
                optimum[nResidues - 1] = ri;
            }
        }
    }
    return currentEnergy;
}
Also used : Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue) RotamerLibrary.applyRotamer(ffx.potential.bonded.RotamerLibrary.applyRotamer) Rotamer(ffx.potential.bonded.Rotamer)

Aggregations

Residue (ffx.potential.bonded.Residue)102 MultiResidue (ffx.potential.bonded.MultiResidue)66 Rotamer (ffx.potential.bonded.Rotamer)44 Atom (ffx.potential.bonded.Atom)41 RotamerLibrary.applyRotamer (ffx.potential.bonded.RotamerLibrary.applyRotamer)39 ArrayList (java.util.ArrayList)30 Polymer (ffx.potential.bonded.Polymer)29 IOException (java.io.IOException)20 Molecule (ffx.potential.bonded.Molecule)13 NACorrectionException (ffx.potential.bonded.NACorrectionException)13 MSNode (ffx.potential.bonded.MSNode)12 ResidueState (ffx.potential.bonded.ResidueState)11 Bond (ffx.potential.bonded.Bond)10 Crystal (ffx.crystal.Crystal)8 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)8 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)8 File (java.io.File)8 AminoAcid3 (ffx.potential.bonded.ResidueEnumerations.AminoAcid3)7 TitrationUtils.inactivateResidue (ffx.potential.extended.TitrationUtils.inactivateResidue)6 BufferedWriter (java.io.BufferedWriter)6