Search in sources :

Example 16 with Residue

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

the class RotamerOptimization method eliminateRotamerPairs.

private int eliminateRotamerPairs(Residue[] residues, int i, int ri, boolean verbose) {
    int nres = residues.length;
    int eliminatedPairs = 0;
    for (int j = 0; j < nres; j++) {
        if (j == i) {
            continue;
        }
        Residue residuej = residues[j];
        Rotamer[] rotamersj = residuej.getRotamers(library);
        int lenrj = rotamersj.length;
        for (int rj = 0; rj < lenrj; rj++) {
            if (eliminateRotamerPair(residues, i, ri, j, rj, verbose)) {
                eliminatedPairs++;
            }
        }
    }
    return eliminatedPairs;
}
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 17 with Residue

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

the class RotamerOptimization method testSelfEnergyElimination.

/**
 * Test the self-energy elimination by setting 2-body and 3-body
 * interactions to zero.
 */
public void testSelfEnergyElimination(Residue[] residues) {
    int nRes = residues.length;
    for (int i = 0; i < nRes; i++) {
        Residue resI = residues[i];
        Rotamer[] rotI = resI.getRotamers(library);
        int nI = rotI.length;
        for (int ri = 0; ri < nI; ri++) {
            for (int j = i + 1; j < nRes; j++) {
                Residue resJ = residues[j];
                Rotamer[] rotJ = resJ.getRotamers(library);
                int nJ = rotJ.length;
                for (int rj = 0; rj < nJ; rj++) {
                    try {
                        twoBodyEnergy[i][ri][j][rj] = 0.0;
                    } catch (Exception e) {
                    // catch NPE.
                    }
                    if (threeBodyTerm) {
                        for (int k = j + 1; k < nRes; k++) {
                            Residue resK = residues[k];
                            Rotamer[] rotK = resK.getRotamers(library);
                            int nK = rotK.length;
                            for (int rk = 0; rk < nK; rk++) {
                                try {
                                    threeBodyEnergy[i][ri][j][rj][k][rk] = 0.0;
                                } catch (Exception e) {
                                // catch NPE.
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue) RotamerLibrary.applyRotamer(ffx.potential.bonded.RotamerLibrary.applyRotamer) Rotamer(ffx.potential.bonded.Rotamer) IOException(java.io.IOException) NACorrectionException(ffx.potential.bonded.NACorrectionException)

Example 18 with Residue

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

the class RotamerOptimization method goldsteinDriver.

private boolean goldsteinDriver(Residue[] residues) {
    int nres = residues.length;
    // A flag to indicate if a rotamer is eliminated.
    boolean eliminated = false;
    // Loop over residue i.
    for (int i = 0; i < nres; i++) {
        Residue resi = residues[i];
        Rotamer[] roti = resi.getRotamers(library);
        int nri = roti.length;
        // Loop over the set of rotamers for residue i.
        for (int riA = 0; riA < nri; riA++) {
            // Continue if rotamer (i, riA) is not valid.
            if (check(i, riA)) {
                continue;
            }
            for (int riB = 0; riB < nri; riB++) {
                // The eliminating rotamer cannot be riA and must be a valid.
                if (riA == riB || check(i, riB)) {
                    continue;
                }
                if (goldsteinElimination(residues, i, riA, riB)) {
                    eliminated = true;
                    break;
                }
            }
        }
    }
    if (eliminated == false) {
        logIfMaster(" No more single rotamers to eliminate.");
    }
    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 19 with Residue

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

the class RotamerOptimization method independent.

private double independent(List<Residue> residues) {
    if (x == null) {
        Atom[] atoms = molecularAssembly.getAtomArray();
        int nAtoms = atoms.length;
        x = new double[nAtoms * 3];
    }
    double e = Double.MAX_VALUE;
    List<Residue> rList = new ArrayList<>(Collections.nCopies(1, null));
    for (Residue residue : residues) {
        rList.set(0, residue);
        logger.info(format(" Optimizing %s side-chain.", residue));
        Rotamer[] rotamers = residue.getRotamers(library);
        potential.getCoordinates(x);
        e = Double.MAX_VALUE;
        int bestRotamer = -1;
        for (int j = 0; j < rotamers.length; j++) {
            Rotamer rotamer = rotamers[j];
            RotamerLibrary.applyRotamer(residue, rotamer);
            if (algorithmListener != null) {
                algorithmListener.algorithmUpdate(molecularAssembly);
            }
            double newE = Double.NaN;
            try {
                newE = currentEnergy(rList);
            } catch (ArithmeticException ex) {
                logger.fine(String.format(" Exception %s in energy calculations during independent for %s-%d", ex.toString(), residue, j));
            }
            if (newE < e) {
                bestRotamer = j;
            }
        }
        if (bestRotamer > -1) {
            Rotamer rotamer = rotamers[bestRotamer];
            RotamerLibrary.applyRotamer(residue, rotamer);
        }
        if (algorithmListener != null) {
            algorithmListener.algorithmUpdate(molecularAssembly);
        }
        if (terminate) {
            logger.info(format("\n Terminating after residue %s.\n", residue));
            break;
        }
    }
    return e;
}
Also used : Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue) ArrayList(java.util.ArrayList) RotamerLibrary.applyRotamer(ffx.potential.bonded.RotamerLibrary.applyRotamer) Rotamer(ffx.potential.bonded.Rotamer) Atom(ffx.potential.bonded.Atom)

Example 20 with Residue

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

the class RotamerOptimization method evaluateDistance.

/**
 * Evaluates the pairwise distance between two residues' rotamers under any
 * symmetry operator; does "lazy loading" for the distance matrix.
 *
 * @param i Residue i
 * @param ri Rotamer for i
 * @param j Residue j
 * @param rj Rotamer for j
 * @return Shortest distance
 */
private double evaluateDistance(int i, int ri, int j, int rj) {
    Residue resi = allResiduesArray[i];
    Rotamer[] rotamersI = resi.getRotamers(library);
    Rotamer roti = rotamersI[ri];
    double[][] xi;
    if (roti.equals(resi.getRotamer())) {
        xi = resi.storeCoordinateArray();
    } else {
        ResidueState origI = resi.storeState();
        RotamerLibrary.applyRotamer(resi, roti);
        xi = resi.storeCoordinateArray();
        resi.revertState(origI);
    }
    Residue resj = allResiduesArray[j];
    Rotamer[] rotamersJ = resj.getRotamers(library);
    Rotamer rotj = rotamersJ[rj];
    double[][] xj;
    if (rotj.equals(resj.getRotamer())) {
        xj = resj.storeCoordinateArray();
    } else {
        ResidueState origJ = resj.storeState();
        RotamerLibrary.applyRotamer(resj, rotj);
        xj = resj.storeCoordinateArray();
        resj.revertState(origJ);
    }
    Crystal crystal = molecularAssembly.getCrystal();
    int nSymm = crystal.spaceGroup.getNumberOfSymOps();
    double minDist = Double.MAX_VALUE;
    for (int iSymOp = 0; iSymOp < nSymm; iSymOp++) {
        SymOp symOp = crystal.spaceGroup.getSymOp(iSymOp);
        double dist = interResidueDistance(xi, xj, symOp);
        minDist = dist < minDist ? dist : minDist;
    }
    return minDist;
}
Also used : SymOp(ffx.crystal.SymOp) Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue) ResidueState(ffx.potential.bonded.ResidueState) RotamerLibrary.applyRotamer(ffx.potential.bonded.RotamerLibrary.applyRotamer) Rotamer(ffx.potential.bonded.Rotamer) Crystal(ffx.crystal.Crystal)

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