Search in sources :

Example 1 with Polymer

use of ffx.potential.bonded.Polymer 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 2 with Polymer

use of ffx.potential.bonded.Polymer 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 3 with Polymer

use of ffx.potential.bonded.Polymer 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;
}
Also used : MSNode(ffx.potential.bonded.MSNode) ArrayList(java.util.ArrayList) Polymer(ffx.potential.bonded.Polymer)

Example 4 with Polymer

use of ffx.potential.bonded.Polymer in project ffx by mjschnie.

the class MolecularAssembly method findAtom.

/**
 * <p>
 * findAtom</p>
 *
 * @param atom a {@link ffx.potential.bonded.Atom} object.
 * @return a {@link ffx.potential.bonded.Atom} object.
 */
public Atom findAtom(Atom atom) {
    if (!atom.isHetero() || atom.isModRes()) {
        Polymer polymer = getPolymer(atom.getChainID(), atom.getSegID(), false);
        if (polymer != null) {
            Residue res = polymer.getResidue(atom.getResidueName(), atom.getResidueNumber(), false);
            if (res != null) {
                MSNode node = res.getAtomNode();
                Atom root = (Atom) node.contains(atom);
                return root;
            }
        }
        return null;
    } else {
        ArrayList<Molecule> list = getMolecules();
        for (MSNode node : list) {
            Molecule m = (Molecule) node;
            if (m.getSegID().equalsIgnoreCase(atom.getSegID()) && m.getResidueName().equalsIgnoreCase(atom.getResidueName()) && m.getResidueNumber() == atom.getResidueNumber()) {
                Atom root = (Atom) node.contains(atom);
                return root;
            }
        }
        ArrayList<MSNode> ionList = getIons();
        for (MSNode node : ionList) {
            Molecule m = (Molecule) node;
            if (m.getSegID().equalsIgnoreCase(atom.getSegID()) && m.getResidueName().equalsIgnoreCase(atom.getResidueName()) && m.getResidueNumber() == atom.getResidueNumber()) {
                Atom root = (Atom) node.contains(atom);
                return root;
            }
        }
        ArrayList<MSNode> waterList = getWaters();
        for (MSNode node : waterList) {
            Molecule m = (Molecule) node;
            if (m.getSegID().equalsIgnoreCase(atom.getSegID()) && m.getResidueName().equalsIgnoreCase(atom.getResidueName()) && m.getResidueNumber() == atom.getResidueNumber()) {
                Atom root = (Atom) node.contains(atom);
                return root;
            }
        }
        return null;
    }
}
Also used : Molecule(ffx.potential.bonded.Molecule) MSNode(ffx.potential.bonded.MSNode) Residue(ffx.potential.bonded.Residue) Polymer(ffx.potential.bonded.Polymer) Atom(ffx.potential.bonded.Atom)

Example 5 with Polymer

use of ffx.potential.bonded.Polymer in project ffx by mjschnie.

the class MolecularAssembly method getResidueList.

/**
 * <p>
 * getResidueList</p>
 *
 * @return a {@link java.util.ArrayList} object.
 */
public ArrayList<Residue> getResidueList() {
    ArrayList<Residue> residues = new ArrayList<>();
    ListIterator<MSNode> li, lj;
    MSNode o;
    Polymer c;
    for (li = getAtomNodeList().listIterator(); li.hasNext(); ) {
        o = li.next();
        if (o instanceof Polymer) {
            c = (Polymer) o;
            for (lj = c.getAtomNodeList().listIterator(); lj.hasNext(); ) {
                o = lj.next();
                if (o instanceof Residue) {
                    residues.add((Residue) o);
                }
            }
        }
    }
    return residues;
}
Also used : MSNode(ffx.potential.bonded.MSNode) Residue(ffx.potential.bonded.Residue) ArrayList(java.util.ArrayList) Polymer(ffx.potential.bonded.Polymer)

Aggregations

Polymer (ffx.potential.bonded.Polymer)38 Residue (ffx.potential.bonded.Residue)29 Atom (ffx.potential.bonded.Atom)21 MSNode (ffx.potential.bonded.MSNode)19 ArrayList (java.util.ArrayList)14 Molecule (ffx.potential.bonded.Molecule)13 Bond (ffx.potential.bonded.Bond)10 MultiResidue (ffx.potential.bonded.MultiResidue)9 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)7 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)7 IOException (java.io.IOException)7 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 SSBond (org.biojava.bio.structure.SSBond)4 MSGroup (ffx.potential.bonded.MSGroup)3 AminoAcid3 (ffx.potential.bonded.ResidueEnumerations.AminoAcid3)3 Rotamer (ffx.potential.bonded.Rotamer)3