use of ffx.potential.bonded.Polymer in project ffx by mjschnie.
the class RotamerOptimization method optimize.
/**
* Execute the rotamer optimization.
*
* @return The lowest energy found.
*/
public double optimize() {
boolean ignoreNA = false;
String ignoreNAProp = System.getProperty("ignoreNA");
if (ignoreNAProp != null && ignoreNAProp.equalsIgnoreCase("true")) {
logger.info("(Key) Ignoring nucleic acids.");
ignoreNA = true;
}
logger.info(format("\n Rotamer Library: %s", library.getLibrary()));
logger.info(format(" Algorithm: %s", algorithm));
logger.info(format(" Goldstein Criteria: %b", useGoldstein));
logger.info(format(" Three-Body Energies: %b\n", threeBodyTerm));
/*
* Collect all residues in the MolecularAssembly. Use all Residues with
* Rotamers and all forced residues if using sliding window and forced
* residues. Forced residues is meaningless for other algorithms, and
* will be reverted to false.
*/
allResiduesList = new ArrayList<>();
polymers = molecularAssembly.getChains();
for (Polymer polymer : polymers) {
ArrayList<Residue> current = polymer.getResidues();
for (Residue residuej : current) {
if (useForcedResidues) {
switch(algorithm) {
case WINDOW:
if (residuej == null) {
// Do nothing.
} else if (residuej.getRotamers(library) != null) {
allResiduesList.add(residuej);
} else {
int indexJ = residuej.getResidueNumber();
if (checkIfForced(indexJ)) {
allResiduesList.add(residuej);
}
}
break;
default:
// Should only trigger once before resetting useForcedResidues to false.
logIfMaster(" Forced residues only applicable to sliding window.", Level.WARNING);
useForcedResidues = false;
if (residuej != null && (residuej.getRotamers(library) != null)) {
if (!(ignoreNA && residuej.getResidueType() == Residue.ResidueType.NA)) {
allResiduesList.add(residuej);
}
}
break;
}
} else if (residuej != null && (residuej.getRotamers(library) != null)) {
if (!(ignoreNA && residuej.getResidueType() == Residue.ResidueType.NA)) {
allResiduesList.add(residuej);
}
}
}
}
sortResidues(allResiduesList);
sortResidues(residueList);
// If -DignoreNA=true, then remove nucleic acids from residue list.
if (ignoreNA) {
for (int i = 0; i < residueList.size(); i++) {
Residue res = residueList.get(i);
if (res.getResidueType() == Residue.ResidueType.NA) {
residueList.remove(i);
}
}
}
// for NA only
RotamerLibrary.initializeDefaultAtomicCoordinates(molecularAssembly.getChains());
numResidues = allResiduesList.size();
allResiduesArray = allResiduesList.toArray(new Residue[numResidues]);
/*
* Distance matrix is used to add residues to the sliding window
* based on distance cutoff, and to automatically set some 3-body terms
* to 0 at > 10 angstroms.
*
* The memory and compute overhead can be a problem for some very large
* structures.
*/
if (distance > 0) {
distanceMatrix();
}
double e = 0.0;
if (residueList != null) {
done = false;
terminate = false;
switch(algorithm) {
case INDEPENDENT:
e = independent(residueList);
break;
case BRUTE_FORCE:
e = bruteForce(residueList);
break;
case ALL:
e = globalOptimization(residueList);
break;
case WINDOW:
e = slidingWindowOptimization(residueList, windowSize, increment, revert, distance, direction);
break;
case BOX:
e = boxOptimization(residueList);
break;
default:
break;
}
terminate = false;
done = true;
}
return e;
}
use of ffx.potential.bonded.Polymer in project ffx by mjschnie.
the class PDBFilter method numberAtoms.
/**
* <p>
* numberAtoms</p>
*/
private void numberAtoms() {
int index = 1;
for (Atom a : activeMolecularAssembly.getAtomArray()) {
a.setXyzIndex(index++);
}
index--;
if (logger.isLoggable(Level.INFO)) {
logger.info(String.format(" Total number of atoms: %d\n", index));
}
Polymer[] polymers = activeMolecularAssembly.getChains();
if (polymers != null) {
for (Polymer p : polymers) {
List<Residue> residues = p.getResidues();
for (Residue r : residues) {
r.reOrderAtoms();
}
}
}
List<Molecule> molecules = activeMolecularAssembly.getMolecules();
for (Molecule n : molecules) {
n.reOrderAtoms();
}
List<MSNode> waters = activeMolecularAssembly.getWaters();
for (MSNode n : waters) {
MSGroup m = (MSGroup) n;
m.reOrderAtoms();
}
List<MSNode> ions = activeMolecularAssembly.getIons();
for (MSNode n : ions) {
MSGroup m = (MSGroup) n;
m.reOrderAtoms();
}
}
use of ffx.potential.bonded.Polymer in project ffx by mjschnie.
the class PDBFilter method buildMissingResidues.
/**
* Currently builds missing internal loops based on information in DBREF and
* SEQRES records.
*
* Known limitations include: 1) No building n- and c-terminal loops. 2) No
* support for DBREF1 or DBREF2 records. 3) Incomplete optimization scheme
* to position the loops.
*
* @param xyzIndex
*
* @return xyzIndex updated based on built atoms.
*/
private int buildMissingResidues(int xyzIndex) {
/**
* Only build loops if the buildLoops flag is true.
*/
if (!properties.getBoolean("buildLoops", false)) {
return xyzIndex;
}
Polymer[] polymers = activeMolecularAssembly.getChains();
for (Polymer polymer : polymers) {
Character chainID = polymer.getChainID();
String[] resNames = seqres.get(chainID);
int[] seqRange = dbref.get(chainID);
if (resNames == null || seqRange == null) {
continue;
}
int seqBegin = seqRange[0];
int seqEnd = seqRange[1];
logger.info(format("\n Checking for missing residues in chain %s between residues %d and %d.", polymer.toString(), seqBegin, seqEnd));
int firstResID = polymer.getFirstResidue().getResidueNumber();
for (int i = 0; i < resNames.length; i++) {
int currentID = seqBegin + i;
Residue currentResidue = polymer.getResidue(currentID);
if (currentResidue != null) {
continue;
}
if (currentID <= firstResID) {
logger.info(format(" Residue %d is missing, but is at the beginning of the chain.", currentID));
continue;
}
Residue previousResidue = polymer.getResidue(currentID - 1);
if (previousResidue == null) {
logger.info(format(" Residue %d is missing, but could not be build (previous residue missing).", currentID));
continue;
}
Residue nextResidue = null;
for (int j = currentID + 1; j <= seqEnd; j++) {
nextResidue = polymer.getResidue(j);
if (nextResidue != null) {
break;
}
}
/**
* Residues at the end of the chain are not currently built.
*/
if (nextResidue == null) {
logger.info(format(" Residue %d is missing, but is at the end of the chain.", currentID));
break;
}
/**
* Find the previous carbonyl carbon and next nitrogen.
*/
Atom C = (Atom) previousResidue.getAtomNode("C");
Atom N = (Atom) nextResidue.getAtomNode("N");
if (C == null || N == null) {
logger.info(format(" Residue %d is missing, but bonding atoms are missing (C or N).", currentID));
continue;
}
/**
* Build the missing residue.
*/
currentResidue = polymer.getResidue(resNames[i], currentID, true);
double[] vector = new double[3];
int count = 3 * (nextResidue.getResidueNumber() - previousResidue.getResidueNumber());
VectorMath.diff(N.getXYZ(null), C.getXYZ(null), vector);
VectorMath.scalar(vector, 1.0 / count, vector);
double[] nXYZ = new double[3];
VectorMath.sum(C.getXYZ(null), vector, nXYZ);
nXYZ[0] += Math.random() - 0.5;
nXYZ[1] += Math.random() - 0.5;
nXYZ[2] += Math.random() - 0.5;
Atom newN = new Atom(xyzIndex++, "N", C.getAltLoc(), nXYZ, resNames[i], currentID, chainID, 1.0, C.getTempFactor(), C.getSegID(), true);
currentResidue.addMSNode(newN);
double[] caXYZ = new double[3];
VectorMath.scalar(vector, 2.0, vector);
VectorMath.sum(C.getXYZ(null), vector, caXYZ);
caXYZ[0] += Math.random() - 0.5;
caXYZ[1] += Math.random() - 0.5;
caXYZ[2] += Math.random() - 0.5;
Atom newCA = new Atom(xyzIndex++, "CA", C.getAltLoc(), caXYZ, resNames[i], currentID, chainID, 1.0, C.getTempFactor(), C.getSegID(), true);
currentResidue.addMSNode(newCA);
double[] cXYZ = new double[3];
VectorMath.scalar(vector, 1.5, vector);
VectorMath.sum(C.getXYZ(null), vector, cXYZ);
cXYZ[0] += Math.random() - 0.5;
cXYZ[1] += Math.random() - 0.5;
cXYZ[2] += Math.random() - 0.5;
Atom newC = new Atom(xyzIndex++, "C", C.getAltLoc(), cXYZ, resNames[i], currentID, chainID, 1.0, C.getTempFactor(), C.getSegID(), true);
currentResidue.addMSNode(newC);
double[] oXYZ = new double[3];
vector[0] = Math.random() - 0.5;
vector[1] = Math.random() - 0.5;
vector[2] = Math.random() - 0.5;
VectorMath.sum(cXYZ, vector, oXYZ);
Atom newO = new Atom(xyzIndex++, "O", C.getAltLoc(), oXYZ, resNames[i], currentID, chainID, 1.0, C.getTempFactor(), C.getSegID(), true);
currentResidue.addMSNode(newO);
logger.info(String.format(" Building residue %8s.", currentResidue.toString()));
}
}
return xyzIndex;
}
use of ffx.potential.bonded.Polymer in project ffx by mjschnie.
the class PDBFilter method buildDisulfideBonds.
/**
* Assign parameters to disulfide bonds.
*
* @param ssBondList
*/
private void buildDisulfideBonds(List<Bond> ssBondList) {
StringBuilder sb = new StringBuilder(" Disulfide Bonds:");
for (Bond bond : ssBondList) {
Atom a1 = bond.getAtom(0);
Atom a2 = bond.getAtom(1);
int[] c = new int[2];
c[0] = a1.getAtomType().atomClass;
c[1] = a2.getAtomType().atomClass;
String key = BondType.sortKey(c);
BondType bondType = forceField.getBondType(key);
if (bondType == null) {
logger.severe(format("No BondType for key: %s\n %s\n %s", key, a1, a2));
} else {
bond.setBondType(bondType);
}
double d = VectorMath.dist(a1.getXYZ(null), a2.getXYZ(null));
Polymer c1 = activeMolecularAssembly.getChain(a1.getSegID());
Polymer c2 = activeMolecularAssembly.getChain(a2.getSegID());
Residue r1 = c1.getResidue(a1.getResidueNumber());
Residue r2 = c2.getResidue(a2.getResidueNumber());
sb.append(format("\n S-S distance of %6.2f for %s and %s.", d, r1.toString(), r2.toString()));
bondList.add(bond);
}
if (ssBondList.size() > 0) {
logger.info(sb.toString());
}
}
use of ffx.potential.bonded.Polymer in project ffx by mjschnie.
the class PDBFilter method locateDisulfideBonds.
/**
* Locate disulfide bonds based on SSBOND records.
*
* @param ssbonds
*
* @return An ArrayList of Bond instances for SS-Bonds.
*/
private List<Bond> locateDisulfideBonds(List<String> ssbonds) {
List<Bond> ssBondList = new ArrayList<>();
for (String ssbond : ssbonds) {
// =============================================================================
try {
char c1ch = ssbond.charAt(15);
char c2ch = ssbond.charAt(29);
Polymer c1 = activeMolecularAssembly.getChain(String.format("%c", c1ch));
Polymer c2 = activeMolecularAssembly.getChain(String.format("%c", c2ch));
String origResNum1 = ssbond.substring(17, 21).trim();
char insChar1 = ssbond.charAt(21);
String origResNum2 = ssbond.substring(31, 35).trim();
char insChar2 = ssbond.charAt(35);
String pdbResNum1 = String.format("%c%s%c", c1ch, origResNum1, insChar1);
String pdbResNum2 = String.format("%c%s%c", c2ch, origResNum2, insChar2);
String resnum1 = pdbToNewResMap.get(pdbResNum1);
String resnum2 = pdbToNewResMap.get(pdbResNum2);
if (resnum1 == null) {
logger.warning(String.format(" Could not find residue %s for SS-bond %s", pdbResNum1, ssbond));
continue;
}
if (resnum2 == null) {
logger.warning(String.format(" Could not find residue %s for SS-bond %s", pdbResNum2, ssbond));
continue;
}
Residue r1 = c1.getResidue(Integer.parseInt(resnum1.substring(1)));
Residue r2 = c2.getResidue(Integer.parseInt(resnum2.substring(1)));
/*Residue r1 = c1.getResidue(Hybrid36.decode(4, ssbond.substring(17, 21)));
Residue r2 = c2.getResidue(Hybrid36.decode(4, ssbond.substring(31, 35)));*/
List<Atom> atoms1 = r1.getAtomList();
List<Atom> atoms2 = r2.getAtomList();
Atom SG1 = null;
Atom SG2 = null;
for (Atom atom : atoms1) {
if (atom.getName().equalsIgnoreCase("SG")) {
SG1 = atom;
break;
}
}
for (Atom atom : atoms2) {
if (atom.getName().equalsIgnoreCase("SG")) {
SG2 = atom;
break;
}
}
if (SG1 == null) {
logger.warning(String.format(" SG atom 1 of SS-bond %s is null", ssbond));
}
if (SG2 == null) {
logger.warning(String.format(" SG atom 2 of SS-bond %s is null", ssbond));
}
if (SG1 == null || SG2 == null) {
continue;
}
double d = VectorMath.dist(SG1.getXYZ(null), SG2.getXYZ(null));
if (d < 3.0) {
r1.setName("CYX");
r2.setName("CYX");
for (Atom atom : atoms1) {
atom.setResName("CYX");
}
for (Atom atom : atoms2) {
atom.setResName("CYX");
}
Bond bond = new Bond(SG1, SG2);
ssBondList.add(bond);
} else {
String message = format("Ignoring [%s]\n due to distance %8.3f A.", ssbond, d);
logger.log(Level.WARNING, message);
}
} catch (Exception e) {
String message = format("Ignoring [%s]", ssbond);
logger.log(Level.WARNING, message, e);
}
}
return ssBondList;
}
Aggregations