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;
}
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.
}
}
}
}
}
}
}
}
}
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;
}
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;
}
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;
}
Aggregations