use of ffx.potential.bonded.Atom in project ffx by mjschnie.
the class XRayEnergy method getMass.
/**
* {@inheritDoc}
*/
@Override
public double[] getMass() {
double[] mass = new double[nXYZ + nB + nOCC];
int i = 0;
if (refineXYZ) {
for (Atom a : activeAtomArray) {
double m = a.getMass();
mass[i++] = m;
mass[i++] = m;
mass[i++] = m;
}
}
if (refineB) {
for (int j = i; j < nXYZ + nB; i++, j++) {
mass[j] = bMass;
}
}
if (refineOCC) {
for (int j = i; j < nXYZ + nB + nOCC; i++, j++) {
mass[j] = occMass;
}
}
return mass;
}
use of ffx.potential.bonded.Atom in project ffx by mjschnie.
the class XRayEnergy method energyAndGradient.
/**
* {@inheritDoc}
*/
@Override
public double energyAndGradient(double[] x, double[] g) {
double e = 0.0;
/**
* Unscale the coordinates.
*/
if (optimizationScaling != null) {
int len = x.length;
for (int i = 0; i < len; i++) {
x[i] /= optimizationScaling[i];
}
}
if (refineXYZ) {
for (Atom a : activeAtomArray) {
a.setXYZGradient(0.0, 0.0, 0.0);
a.setLambdaXYZGradient(0.0, 0.0, 0.0);
}
// update coordinates
diffractionData.setFFTCoordinates(x);
}
if (refineB) {
for (Atom a : activeAtomArray) {
a.setTempFactorGradient(0.0);
if (a.getAnisou(null) != null) {
if (a.getAnisouGradient(null) == null) {
double[] ganisou = new double[6];
a.setAnisouGradient(ganisou);
} else {
double[] ganisou = a.getAnisouGradient(null);
ganisou[0] = ganisou[1] = ganisou[2] = 0.0;
ganisou[3] = ganisou[4] = ganisou[5] = 0.0;
a.setAnisouGradient(ganisou);
}
}
}
// update B factors
setBFactors(x);
}
if (refineOCC) {
for (Atom a : activeAtomArray) {
a.setOccupancyGradient(0.0);
}
// update occupancies
setOccupancies(x);
}
if (xrayTerms) {
if (lambdaTerm) {
diffractionData.setLambdaTerm(false);
}
// compute new structure factors
diffractionData.computeAtomicDensity();
// compute crystal likelihood
e = diffractionData.computeLikelihood();
// compute the crystal gradients
diffractionData.computeAtomicGradients(refinementMode);
if (refineXYZ) {
// pack gradients into gradient array
getXYZGradients(g);
}
if (lambdaTerm) {
int n = dUdXdL.length;
System.arraycopy(g, 0, dUdXdL, 0, n);
for (Atom a : activeAtomArray) {
a.setXYZGradient(0.0, 0.0, 0.0);
a.setLambdaXYZGradient(0.0, 0.0, 0.0);
}
// Turn off all atoms scaled by lambda.
diffractionData.setLambdaTerm(true);
// Compute new structure factors.
diffractionData.computeAtomicDensity();
// Compute crystal likelihood.
double e2 = diffractionData.computeLikelihood();
// compute the crystal gradients
diffractionData.computeAtomicGradients(refinementMode);
dEdL = e - e2;
e = lambda * e + (1.0 - lambda) * e2;
getXYZGradients(g2);
for (int i = 0; i < g.length; i++) {
dUdXdL[i] -= g2[i];
g[i] = lambda * g[i] + (1.0 - lambda) * g2[i];
}
diffractionData.setLambdaTerm(false);
}
}
if (restraintTerms) {
if (refineB) {
// add B restraints
e += getBFactorRestraints();
// pack gradients into gradient array
getBFactorGradients(g);
}
if (refineOCC) {
// pack gradients into gradient array
getOccupancyGradients(g);
}
}
/**
* Scale the coordinates and gradients.
*/
if (optimizationScaling != null) {
int len = x.length;
for (int i = 0; i < len; i++) {
x[i] *= optimizationScaling[i];
g[i] /= optimizationScaling[i];
}
}
totalEnergy = e;
return e;
}
use of ffx.potential.bonded.Atom in project ffx by mjschnie.
the class XRayEnergy method getCoordinates.
/**
* {@inheritDoc}
*/
@Override
public double[] getCoordinates(double[] x) {
assert (x != null);
double[] xyz = new double[3];
int index = 0;
fill(x, 0.0);
if (refineXYZ) {
for (Atom a : activeAtomArray) {
a.getXYZ(xyz);
x[index++] = xyz[0];
x[index++] = xyz[1];
x[index++] = xyz[2];
}
}
if (refineB) {
double[] anisou = null;
int resnum = -1;
int nat = 0;
int nres = diffractionData.getnResidueBFactor() + 1;
for (Atom a : activeAtomArray) {
// ignore hydrogens!!!
if (a.getAtomicNumber() == 1) {
continue;
}
if (a.getAnisou(null) != null) {
anisou = a.getAnisou(anisou);
x[index++] = anisou[0];
x[index++] = anisou[1];
x[index++] = anisou[2];
x[index++] = anisou[3];
x[index++] = anisou[4];
x[index++] = anisou[5];
} else if (diffractionData.isResidueBFactor()) {
if (resnum != a.getResidueNumber()) {
if (nres >= diffractionData.getnResidueBFactor()) {
if (resnum > -1 && index < nXYZ + nB - 1) {
x[index] /= nat;
index++;
}
nat = 1;
nres = 1;
} else {
nres++;
nat++;
}
x[index] += a.getTempFactor();
resnum = a.getResidueNumber();
} else {
x[index] += a.getTempFactor();
nat++;
}
} else {
x[index++] = a.getTempFactor();
}
}
if (diffractionData.isResidueBFactor()) {
if (nat > 1) {
x[index] /= nat;
}
}
}
if (refineOCC) {
for (ArrayList<Residue> list : refinementModel.getAltResidues()) {
for (Residue r : list) {
for (Atom a : r.getAtomList()) {
if (a.getOccupancy() < 1.0) {
x[index++] = a.getOccupancy();
break;
}
}
}
}
for (ArrayList<Molecule> list : refinementModel.getAltMolecules()) {
for (Molecule m : list) {
for (Atom a : m.getAtomList()) {
if (a.getOccupancy() < 1.0) {
x[index++] = a.getOccupancy();
break;
}
}
}
}
}
return x;
}
use of ffx.potential.bonded.Atom in project ffx by mjschnie.
the class XRayEnergy method getOccupancyGradients.
/**
* Fill gradient array with occupancy gradients.
* Note: this also acts to constrain the occupancies
* by moving the gradient vector COM to zero
*
* @param g array to add gradients to
*/
public void getOccupancyGradients(double[] g) {
double ave;
int index = nXYZ + nB;
// First: Alternate Residues
for (ArrayList<Residue> list : refinementModel.getAltResidues()) {
ave = 0.0;
for (Residue r : list) {
for (Atom a : r.getAtomList()) {
if (a.getOccupancy() < 1.0) {
ave += a.getOccupancyGradient();
}
}
}
/*
* should this be normalized with respect
* to number of atoms in residue in addition
* to the number of conformers?
*/
ave /= list.size();
for (Residue r : list) {
for (Atom a : r.getAtomList()) {
if (a.getOccupancy() < 1.0) {
g[index] += a.getOccupancyGradient();
}
}
if (list.size() > 1) {
// subtract average to move COM to zero
g[index] -= ave;
}
index++;
}
}
// Now the molecules (HETATMs).
for (ArrayList<Molecule> list : refinementModel.getAltMolecules()) {
ave = 0.0;
for (Molecule m : list) {
for (Atom a : m.getAtomList()) {
if (a.getOccupancy() < 1.0) {
ave += a.getOccupancyGradient();
}
}
}
ave /= list.size();
for (Molecule m : list) {
for (Atom a : m.getAtomList()) {
if (a.getOccupancy() < 1.0) {
g[index] += a.getOccupancyGradient();
}
}
if (list.size() > 1) {
g[index] -= ave;
}
index++;
}
}
}
use of ffx.potential.bonded.Atom in project ffx by mjschnie.
the class GraphicsPicking method measure.
/**
* @param measureLevel
* @param atoms
*/
private void measure() {
String measurement = null;
double value = 0.0;
Atom a1, a2, a3, a4;
switch(pickLevel) {
case MEASUREDISTANCE:
if (atomCache.size() < 2) {
return;
}
a1 = atomCache.get(0);
a2 = atomCache.get(1);
distance(a1, a);
distance(a2, b);
value = ffx.numerics.VectorMath.dist(a, b);
measurement = "\nDistance\t" + a1.getIndex() + ", " + a2.getIndex() + ": \t" + String.format("%10.5f", value);
break;
case MEASUREANGLE:
if (atomCache.size() < 3) {
return;
}
a1 = atomCache.get(0);
a2 = atomCache.get(1);
a3 = atomCache.get(2);
distance(a1, a);
distance(a2, b);
distance(a3, c);
value = ffx.numerics.VectorMath.bondAngle(a, b, c);
value = Math.toDegrees(value);
measurement = "\nAngle\t" + a1.getIndex() + ", " + a2.getIndex() + ", " + a3.getIndex() + ": \t" + String.format("%10.5f", value);
break;
case MEASUREDIHEDRAL:
if (atomCache.size() < 4) {
return;
}
a1 = atomCache.get(0);
a2 = atomCache.get(1);
a3 = atomCache.get(2);
a4 = atomCache.get(3);
distance(a1, a);
distance(a2, b);
distance(a3, c);
distance(a4, d);
value = ffx.numerics.VectorMath.dihedralAngle(a, b, c, d);
value = Math.toDegrees(value);
measurement = "\nDihedral\t" + a1.getIndex() + ", " + a2.getIndex() + ", " + a3.getIndex() + ", " + a4.getIndex() + ":\t" + String.format("%10.5f", value);
break;
default:
return;
}
logger.info(measurement);
ModelingShell modelingShell = mainPanel.getModelingShell();
modelingShell.setMeasurement(measurement, value);
count = 0;
}
Aggregations