use of ffx.potential.bonded.Rotamer in project ffx by mjschnie.
the class RotamerOptimization method goldsteinPairSumOverK.
private double goldsteinPairSumOverK(Residue[] residues, int lb, int ub, int i, int riA, int riB, int j, int rjC, int rjD, ArrayList<Residue> blockedResidues) {
double sumOverK = 0.0;
int nres = residues.length;
for (int k = lb; k <= ub; k++) {
if (k == j || k == i) {
continue;
}
double minForResK = Double.MAX_VALUE;
Residue resk = residues[k];
Rotamer[] rotk = resk.getRotamers(library);
int nrk = rotk.length;
int rkEvals = 0;
// Loop over residue k's rotamers.
for (int rk = 0; rk < nrk; rk++) {
if (check(k, rk)) {
continue;
}
// Continue if k,rk invalid for riA/rjC.
if (check(i, riA, k, rk) || check(j, rjC, k, rk)) {
// Not implemented: check(i, riA, j, rjC, k, rk).
continue;
}
// Return false if k,rk invalid for riB/rjD.
if (check(i, riB, k, rk) || check(j, rjD, k, rk)) {
blockedResidues.add(resk);
return Double.NaN;
}
rkEvals++;
double currentResK = get2Body(i, riA, k, rk) - get2Body(i, riB, k, rk) + get2Body(j, rjC, k, rk) - get2Body(j, rjD, k, rk);
// Include 3-body effects.
if (threeBodyTerm) {
double sumOverL = (get3Body(i, riA, j, rjC, k, rk) - get3Body(i, riB, j, rjD, k, rk));
// Loop over a 4th residue l.
for (int l = 0; l < nres; l++) {
if (l == k || l == i || l == j) {
continue;
}
Residue residuel = residues[l];
Rotamer[] rotamersl = residuel.getRotamers(library);
int nrl = rotamersl.length;
int rlEvaluations = 0;
double minForResL = Double.MAX_VALUE;
// Loop over rotamers for residue l.
for (int rl = 0; rl < nrl; rl++) {
// If not a part of valid phase space for riA/rjC, continue.
if (check(l, rl) || check(k, rk, l, rl) || check(i, riA, l, rl) || check(j, rjC, l, rl)) {
// Not implemented: check(i, riA, j, rjC, l, rl) || check(i, riA, k, rk, l, rl) || check(j, rjC, k, rk, l, rl) || check(i, riA, j, rjC, k, rk, l, rl)
continue;
}
if (check(i, riB, l, rl) || check(j, rjD, l, rl)) {
// Not implemented: check(i, riB, j, rjD, l, rl) || check(i, riB, k, rk, l, rl) || check(j, rjD, k, rk, l, rl) || check(i, riB, j, rjD, k, rk, l, rl)
blockedResidues.add(residuel);
return Double.NaN;
}
rlEvaluations++;
double e = get3Body(i, riA, k, rk, l, rl) - get3Body(i, riB, k, rk, l, rl) + get3Body(j, rjC, k, rk, l, rl) - get3Body(j, rjD, k, rk, l, rl);
if (e < minForResL) {
minForResL = e;
}
}
if (rlEvaluations == 0) {
minForResL = 0.0;
}
sumOverL += minForResL;
}
currentResK += sumOverL;
}
if (currentResK < minForResK) {
minForResK = currentResK;
}
}
if (rkEvals == 0) {
minForResK = 0.0;
blockedResidues.add(resk);
}
sumOverK += minForResK;
}
return sumOverK;
}
use of ffx.potential.bonded.Rotamer 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.Rotamer 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.Rotamer 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.Rotamer 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;
}
Aggregations