use of ffx.potential.bonded.Molecule 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.Molecule 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.Molecule in project ffx by mjschnie.
the class Barostat method moveToFractionalCOM.
private void moveToFractionalCOM() {
int iMolecule = 0;
double[] com = new double[3];
Polymer[] polymers = molecularAssembly.getChains();
if (polymers != null && polymers.length > 0) {
// Find the center of mass
for (Polymer polymer : polymers) {
List<Atom> list = polymer.getAtomList();
double totalMass = 0.9;
com[0] = 0.0;
com[1] = 0.0;
com[2] = 0.0;
for (Atom atom : list) {
double m = atom.getMass();
com[0] += atom.getX() * m;
com[1] += atom.getY() * m;
com[2] += atom.getZ() * m;
totalMass += m;
}
com[0] /= totalMass;
com[1] /= totalMass;
com[2] /= totalMass;
// Find the new center of mass in fractional coordinates.
unitCell.toFractionalCoordinates(com, com);
// Find the reciprocal translation vector.
double[] frac = fractionalCOM[iMolecule++];
com[0] = frac[0] - com[0];
com[1] = frac[1] - com[1];
com[2] = frac[2] - com[2];
// Convert the fractional translation vector to Cartesian coordinates.
unitCell.toCartesianCoordinates(com, com);
// List<Atom> list = polymer.getAtomList();
for (Atom atom : list) {
atom.move(com);
}
}
}
// Loop over each molecule
List<Molecule> molecules = molecularAssembly.getMolecules();
for (MSNode molecule : molecules) {
List<Atom> list = molecule.getAtomList();
// Find the center of mass
com[0] = 0.0;
com[1] = 0.0;
com[2] = 0.0;
double totalMass = 0.0;
for (Atom atom : list) {
double m = atom.getMass();
com[0] += atom.getX() * m;
com[1] += atom.getY() * m;
com[2] += atom.getZ() * m;
totalMass += m;
}
com[0] /= totalMass;
com[1] /= totalMass;
com[2] /= totalMass;
// Find the new center of mass in fractional coordinates.
unitCell.toFractionalCoordinates(com, com);
// Find the reciprocal translation vector to the previous COM.
double[] frac = fractionalCOM[iMolecule++];
com[0] = frac[0] - com[0];
com[1] = frac[1] - com[1];
com[2] = frac[2] - com[2];
// Convert the fractional translation vector to Cartesian coordinates.
unitCell.toCartesianCoordinates(com, com);
// Move all atoms.
for (Atom atom : list) {
atom.move(com);
}
}
// Loop over each water
List<MSNode> waters = molecularAssembly.getWaters();
for (MSNode water : waters) {
List<Atom> list = water.getAtomList();
// Find the center of mass
com[0] = 0.0;
com[1] = 0.0;
com[2] = 0.0;
double totalMass = 0.0;
for (Atom atom : list) {
double m = atom.getMass();
com[0] += atom.getX() * m;
com[1] += atom.getY() * m;
com[2] += atom.getZ() * m;
totalMass += m;
}
com[0] /= totalMass;
com[1] /= totalMass;
com[2] /= totalMass;
// Find the new center of mass in fractional coordinates.
unitCell.toFractionalCoordinates(com, com);
// Find the reciprocal translation vector to the previous COM.
double[] frac = fractionalCOM[iMolecule++];
com[0] = frac[0] - com[0];
com[1] = frac[1] - com[1];
com[2] = frac[2] - com[2];
// Convert the fractional translation vector to Cartesian coordinates.
unitCell.toCartesianCoordinates(com, com);
double r = ffx.numerics.VectorMath.r(com);
/**
* Warn if an atom is moved more than 1 Angstrom.
*/
if (r > 1.0) {
int i = iMolecule - 1;
logger.info(String.format(" %d R: %16.8f", i, r));
logger.info(String.format(" %d FRAC %16.8f %16.8f %16.8f", i, frac[0], frac[1], frac[2]));
logger.info(String.format(" %d COM %16.8f %16.8f %16.8f", i, com[0], com[1], com[2]));
}
// Move all atoms.
for (Atom atom : list) {
atom.move(com);
}
}
// Loop over each ion
List<MSNode> ions = molecularAssembly.getIons();
for (MSNode ion : ions) {
List<Atom> list = ion.getAtomList();
// Find the center of mass
com[0] = 0.0;
com[1] = 0.0;
com[2] = 0.0;
double totalMass = 0.0;
for (Atom atom : list) {
double m = atom.getMass();
com[0] += atom.getX() * m;
com[1] += atom.getY() * m;
com[2] += atom.getZ() * m;
totalMass += m;
}
com[0] /= totalMass;
com[1] /= totalMass;
com[2] /= totalMass;
// Find the new center of mass in fractional coordinates.
unitCell.toFractionalCoordinates(com, com);
// Find the reciprocal translation vector to the previous COM.
double[] frac = fractionalCOM[iMolecule++];
com[0] = frac[0] - com[0];
com[1] = frac[1] - com[1];
com[2] = frac[2] - com[2];
// Convert the fractional translation vector to Cartesian coordinates.
unitCell.toCartesianCoordinates(com, com);
// Move all atoms.
for (Atom atom : list) {
atom.move(com);
}
}
}
use of ffx.potential.bonded.Molecule in project ffx by mjschnie.
the class Barostat method computeFractionalCOM.
private void computeFractionalCOM() {
int iMolecule = 0;
double[] com = new double[3];
Polymer[] polymers = molecularAssembly.getChains();
if (polymers != null && polymers.length > 0) {
// Find the center of mass
for (Polymer polymer : polymers) {
List<Atom> list = polymer.getAtomList();
com[0] = 0.0;
com[1] = 0.0;
com[2] = 0.0;
double totalMass = 0.0;
for (Atom atom : list) {
double m = atom.getMass();
com[0] += atom.getX() * m;
com[1] += atom.getY() * m;
com[2] += atom.getZ() * m;
totalMass += m;
}
com[0] /= totalMass;
com[1] /= totalMass;
com[2] /= totalMass;
unitCell.toFractionalCoordinates(com, fractionalCOM[iMolecule++]);
}
}
// Loop over each molecule
List<Molecule> molecules = molecularAssembly.getMolecules();
for (MSNode molecule : molecules) {
List<Atom> list = molecule.getAtomList();
// Find the center of mass
com[0] = 0.0;
com[1] = 0.0;
com[2] = 0.0;
double totalMass = 0.0;
for (Atom atom : list) {
double m = atom.getMass();
com[0] += atom.getX() * m;
com[1] += atom.getY() * m;
com[2] += atom.getZ() * m;
totalMass += m;
}
com[0] /= totalMass;
com[1] /= totalMass;
com[2] /= totalMass;
unitCell.toFractionalCoordinates(com, fractionalCOM[iMolecule++]);
}
// Loop over each water
List<MSNode> waters = molecularAssembly.getWaters();
for (MSNode water : waters) {
List<Atom> list = water.getAtomList();
// Find the center of mass
com[0] = 0.0;
com[1] = 0.0;
com[2] = 0.0;
double totalMass = 0.0;
for (Atom atom : list) {
double m = atom.getMass();
com[0] += atom.getX() * m;
com[1] += atom.getY() * m;
com[2] += atom.getZ() * m;
totalMass += m;
}
com[0] /= totalMass;
com[1] /= totalMass;
com[2] /= totalMass;
unitCell.toFractionalCoordinates(com, fractionalCOM[iMolecule++]);
}
// Loop over each ion
List<MSNode> ions = molecularAssembly.getIons();
for (MSNode ion : ions) {
List<Atom> list = ion.getAtomList();
// Find the center of mass
com[0] = 0.0;
com[1] = 0.0;
com[2] = 0.0;
double totalMass = 0.0;
for (Atom atom : list) {
double m = atom.getMass();
com[0] += atom.getX() * m;
com[1] += atom.getY() * m;
com[2] += atom.getZ() * m;
totalMass += m;
}
com[0] /= totalMass;
com[1] /= totalMass;
com[2] /= totalMass;
unitCell.toFractionalCoordinates(com, fractionalCOM[iMolecule++]);
}
}
use of ffx.potential.bonded.Molecule in project ffx by mjschnie.
the class MolecularAssembly method deleteMolecule.
/**
* <p>
* deleteMolecule</p>
*
* @param molecule a {@link ffx.potential.bonded.Molecule} object.
*/
public void deleteMolecule(Molecule molecule) {
ArrayList<MSNode> list = ions.getChildList();
for (MSNode node : list) {
Molecule m = (Molecule) node;
if (molecule == m) {
ions.remove(m);
return;
}
}
list = water.getChildList();
for (MSNode node : list) {
Molecule m = (Molecule) node;
if (molecule == m) {
water.remove(m);
return;
}
}
list = molecules.getChildList();
for (MSNode node : list) {
Molecule m = (Molecule) node;
if (molecule == m) {
molecules.remove(m);
return;
}
}
}
Aggregations