Search in sources :

Example 6 with RotamerLibrary.applyRotamer

use of ffx.potential.bonded.RotamerLibrary.applyRotamer in project ffx by mjschnie.

the class RotamerOptimization method assignResiduesToCells.

/**
 * Constructs the cells for box optimization and assigns them residues,
 * presently based on C alpha fractional coordinates; by default, cells are
 * sorted by global index. Presently, specifying approxBoxLength over-rides
 * numXYZBoxes, and always rounds the number of boxes down (to ensure boxes
 * are always at least the specified size).
 *
 * @param crystal Crystal group.
 * @param residues List of residues to be optimized.
 * @return Array of filled Cells
 */
private void assignResiduesToCells(Crystal crystal, Residue[] residues, BoxOptCell[] cells) {
    // Search through residues, add them to all boxes containing their
    // fractional coordinates.
    int numCells = cells.length;
    int nResidues = residues.length;
    for (int i = 0; i < nResidues; i++) {
        Residue residuei = residues[i];
        double[] atomFracCoords = new double[3];
        boolean[] contained;
        double[][] originalCoordinates;
        switch(boxInclusionCriterion) {
            // As case 1 is default, test other cases first.
            case 2:
                // Residue coordinates defined by any original atomic coordinate.
                originalCoordinates = residuei.storeCoordinateArray();
                contained = new boolean[numCells];
                fill(contained, false);
                // Loop over atomic coordinates in originalCoordinates.
                for (int ai = 0; ai < originalCoordinates.length; ai++) {
                    crystal.toFractionalCoordinates(originalCoordinates[ai], atomFracCoords);
                    NeighborList.moveValuesBetweenZeroAndOne(atomFracCoords);
                    for (int j = 0; j < numCells; j++) {
                        if (!contained[j] && cells[j].checkIfContained(atomFracCoords)) {
                            cells[j].addResidue(residuei);
                            contained[j] = true;
                        }
                    }
                }
                break;
            case 3:
                // Residue coordinates defined by any atomic coordinate in any rotamer.
                // originalCoordinates = storeSingleCoordinates(residuei, true);
                ResidueState origState = residuei.storeState();
                contained = new boolean[numCells];
                fill(contained, false);
                Rotamer[] rotamersi = residuei.getRotamers(library);
                for (Rotamer rotamer : rotamersi) {
                    RotamerLibrary.applyRotamer(residuei, rotamer);
                    double[][] currentCoordinates = residuei.storeCoordinateArray();
                    for (int ai = 0; ai < currentCoordinates.length; ai++) {
                        crystal.toFractionalCoordinates(currentCoordinates[ai], atomFracCoords);
                        NeighborList.moveValuesBetweenZeroAndOne(atomFracCoords);
                        for (int j = 0; j < numCells; j++) {
                            if (!contained[j] && cells[j].checkIfContained(atomFracCoords)) {
                                cells[j].addResidue(residuei);
                                contained[j] = true;
                            }
                        }
                    }
                }
                residuei.revertState(origState);
                // revertSingleResidueCoordinates(residuei, originalCoordinates, true);
                break;
            case 1:
            default:
                // Residue coordinates defined by C alpha (protein) or N1/9
                // (nucleic acids).
                double[] cAlphaCoords = new double[3];
                residuei.getReferenceAtom().getXYZ(cAlphaCoords);
                crystal.toFractionalCoordinates(cAlphaCoords, atomFracCoords);
                NeighborList.moveValuesBetweenZeroAndOne(atomFracCoords);
                for (int j = 0; j < numCells; j++) {
                    if (cells[j].checkIfContained(atomFracCoords)) {
                        cells[j].addResidue(residuei);
                    }
                }
                break;
        }
    }
}
Also used : 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)

Example 7 with RotamerLibrary.applyRotamer

use of ffx.potential.bonded.RotamerLibrary.applyRotamer in project ffx by mjschnie.

the class RotamerOptimization method eliminateNABackboneRotamers.

/**
 * Eliminates NA backbone rotamers with corrections greater than threshold.
 * The int[] parameter allows the method to know how many Rotamers for each
 * residue have previously been pruned; currently, this means any Rotamer
 * pruned by reconcileNARotamersWithPriorResidues.
 * <p>
 * A nucleic correction threshold of 0 skips the entire method; this check
 * is presently being performed inside the method in case it is called again
 * at some point.
 *
 * @param residues Residues to eliminate bad backbone rotamers over.
 * @param numEliminatedRotamers Number of previously eliminated rotamers per
 * residue.
 */
private void eliminateNABackboneRotamers(Residue[] residues, int[] numEliminatedRotamers) {
    /* Atom atoms[] = molecularAssembly.getAtomArray();
         int nAtoms = atoms.length;
         String begin[] = new String[nAtoms];
         for (int i = 0; i < nAtoms; i++) {
         begin[i] = atoms[i].toString();
         } */
    if (nucleicCorrectionThreshold != 0) {
        logIfMaster(format(" Eliminating nucleic acid rotamers with correction vectors larger than %5.3f A", nucleicCorrectionThreshold));
        logIfMaster(format(" A minimum of %d rotamers per NA residue will carry through to energy calculations.", minNumberAcceptedNARotamers));
        ArrayList<Residue> resList = new ArrayList<>();
        resList.addAll(Arrays.asList(residues));
        ResidueState[] origCoordinates = ResidueState.storeAllCoordinates(resList);
        for (int j = 0; j < residues.length; j++) {
            Residue nucleicResidue = residues[j];
            Rotamer[] rotamers = nucleicResidue.getRotamers(library);
            if (nucleicResidue.getResidueType() == NA && rotamers != null) {
                int nrotamers = rotamers.length;
                // Default to all rotamers that have not previously been
                // eliminated; subtract as rotamers are rejected.
                int numAcceptedRotamers = nrotamers - numEliminatedRotamers[j];
                if (minNumberAcceptedNARotamers >= numAcceptedRotamers) {
                    continue;
                }
                ArrayList<DoubleIndexPair> rejectedRotamers = new ArrayList<>();
                for (int i = 0; i < nrotamers; i++) {
                    if (!check(j, i)) {
                        try {
                            RotamerLibrary.applyRotamer(nucleicResidue, rotamers[i], nucleicCorrectionThreshold);
                        } catch (NACorrectionException error) {
                            double rejectedCorrection = error.getCorrection();
                            numAcceptedRotamers--;
                            DoubleIndexPair rejected = new DoubleIndexPair(i, rejectedCorrection);
                            rejectedRotamers.add(rejected);
                        }
                    }
                }
                int numAdditionalRotamersToAccept = minNumberAcceptedNARotamers - numAcceptedRotamers;
                if (numAdditionalRotamersToAccept > 0) {
                    DoubleIndexPair[] rejectedArray = new DoubleIndexPair[rejectedRotamers.size()];
                    for (int i = 0; i < rejectedArray.length; i++) {
                        rejectedArray[i] = rejectedRotamers.get(i);
                    }
                    Arrays.sort(rejectedArray);
                    rejectedRotamers = new ArrayList<>();
                    rejectedRotamers.addAll(Arrays.asList(rejectedArray));
                    for (int i = 0; i < numAdditionalRotamersToAccept; i++) {
                        rejectedRotamers.remove(0);
                    }
                }
                for (DoubleIndexPair rotToReject : rejectedRotamers) {
                    eliminateRotamer(residues, j, rotToReject.getIndex(), print);
                    logIfMaster(format(" Correction magnitude was %6.4f A > %5.3f A", rotToReject.getDoubleValue(), nucleicCorrectionThreshold));
                }
            }
            nucleicResidue.revertState(origCoordinates[j]);
        // revertSingleResidueCoordinates(nucleicResidue, originalCoordinates[j]);
        }
    }
}
Also used : DoubleIndexPair(ffx.utilities.DoubleIndexPair) ResidueState(ffx.potential.bonded.ResidueState) ArrayList(java.util.ArrayList) RotamerLibrary.applyRotamer(ffx.potential.bonded.RotamerLibrary.applyRotamer) Rotamer(ffx.potential.bonded.Rotamer) NACorrectionException(ffx.potential.bonded.NACorrectionException) Residue(ffx.potential.bonded.Residue) MultiResidue(ffx.potential.bonded.MultiResidue)

Aggregations

MultiResidue (ffx.potential.bonded.MultiResidue)7 Residue (ffx.potential.bonded.Residue)7 Rotamer (ffx.potential.bonded.Rotamer)7 RotamerLibrary.applyRotamer (ffx.potential.bonded.RotamerLibrary.applyRotamer)7 ResidueState (ffx.potential.bonded.ResidueState)4 Atom (ffx.potential.bonded.Atom)3 NACorrectionException (ffx.potential.bonded.NACorrectionException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Crystal (ffx.crystal.Crystal)1 SymOp (ffx.crystal.SymOp)1 Polymer (ffx.potential.bonded.Polymer)1 PDBFilter (ffx.potential.parsers.PDBFilter)1 DoubleIndexPair (ffx.utilities.DoubleIndexPair)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1