Search in sources :

Example 1 with Molecule

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;
}
Also used : Molecule(ffx.potential.bonded.Molecule) Residue(ffx.potential.bonded.Residue) Atom(ffx.potential.bonded.Atom)

Example 2 with Molecule

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++;
        }
    }
}
Also used : Molecule(ffx.potential.bonded.Molecule) Residue(ffx.potential.bonded.Residue) Atom(ffx.potential.bonded.Atom)

Example 3 with Molecule

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);
        }
    }
}
Also used : Molecule(ffx.potential.bonded.Molecule) MSNode(ffx.potential.bonded.MSNode) Polymer(ffx.potential.bonded.Polymer) Atom(ffx.potential.bonded.Atom)

Example 4 with Molecule

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++]);
    }
}
Also used : Molecule(ffx.potential.bonded.Molecule) MSNode(ffx.potential.bonded.MSNode) Polymer(ffx.potential.bonded.Polymer) Atom(ffx.potential.bonded.Atom)

Example 5 with Molecule

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;
        }
    }
}
Also used : Molecule(ffx.potential.bonded.Molecule) MSNode(ffx.potential.bonded.MSNode)

Aggregations

Molecule (ffx.potential.bonded.Molecule)20 Atom (ffx.potential.bonded.Atom)18 MSNode (ffx.potential.bonded.MSNode)15 Polymer (ffx.potential.bonded.Polymer)13 Residue (ffx.potential.bonded.Residue)13 Bond (ffx.potential.bonded.Bond)7 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)6 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)6 IOException (java.io.IOException)6 Crystal (ffx.crystal.Crystal)4 MolecularAssembly (ffx.potential.MolecularAssembly)4 BufferedWriter (java.io.BufferedWriter)4 File (java.io.File)4 FileWriter (java.io.FileWriter)4 MSGroup (ffx.potential.bonded.MSGroup)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SSBond (org.biojava.bio.structure.SSBond)3 AminoAcid3 (ffx.potential.bonded.ResidueEnumerations.AminoAcid3)2 NucleicAcid3 (ffx.potential.bonded.ResidueEnumerations.NucleicAcid3)2