use of ffx.potential.bonded.MSNode 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.MSNode 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.MSNode 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;
}
}
}
use of ffx.potential.bonded.MSNode in project ffx by mjschnie.
the class MolecularAssembly method getChainNames.
/**
* <p>
* getChainNames</p>
*
* @return an array of {@link java.lang.String} objects.
*/
public String[] getChainNames() {
ArrayList<String> temp = new ArrayList<>();
for (ListIterator<MSNode> li = getAtomNodeList().listIterator(); li.hasNext(); ) {
MSNode node = li.next();
if (node instanceof Polymer) {
temp.add(((Polymer) node).getName());
}
}
if (temp.isEmpty()) {
return null;
}
String[] names = new String[temp.size()];
for (int i = 0; i < temp.size(); i++) {
names[i] = temp.get(i);
}
return names;
}
use of ffx.potential.bonded.MSNode in project ffx by mjschnie.
the class MolecularAssembly method getMolecule.
private Atom getMolecule(Atom atom, boolean create) {
String resName = atom.getResidueName();
int resNum = atom.getResidueNumber();
Character chainID = atom.getChainID();
String segID = atom.getSegID();
ArrayList<MSNode> list = ions.getChildList();
for (MSNode node : list) {
Molecule m = (Molecule) node;
if (m.getSegID().equalsIgnoreCase(segID) && m.getResidueName().equalsIgnoreCase(resName) && m.getResidueNumber() == resNum) {
return (Atom) m.addMSNode(atom);
}
}
list = water.getChildList();
for (MSNode node : list) {
Molecule m = (Molecule) node;
if (m.getSegID().equalsIgnoreCase(segID) && m.getResidueName().equalsIgnoreCase(resName) && m.getResidueNumber() == resNum) {
return (Atom) m.addMSNode(atom);
}
}
list = molecules.getChildList();
for (MSNode node : list) {
Molecule m = (Molecule) node;
if (m.getSegID().equalsIgnoreCase(segID) && m.getResidueName().equalsIgnoreCase(resName) && m.getResidueNumber() == resNum) {
return (Atom) m.addMSNode(atom);
}
}
if (create) {
Molecule m = new Molecule(resName, resNum, chainID, segID);
m.addMSNode(atom);
if (resName.equalsIgnoreCase("DOD") || resName.equalsIgnoreCase("HOH") || resName.equalsIgnoreCase("WAT")) {
water.add(m);
// NA, K, MG, MG2, CA, CA2, CL
} else if (resName.equalsIgnoreCase("NA") || resName.equalsIgnoreCase("K") || resName.equalsIgnoreCase("MG") || resName.equalsIgnoreCase("MG2") || resName.equalsIgnoreCase("CA") || resName.equalsIgnoreCase("CA2") || resName.equalsIgnoreCase("CL") || resName.equalsIgnoreCase("BR") || resName.equalsIgnoreCase("ZN") || resName.equalsIgnoreCase("ZN2")) {
ions.add(m);
} else {
molecules.add(m);
}
return atom;
} else {
return null;
}
}
Aggregations