Search in sources :

Example 46 with Atom

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

the class Utilities method biochemistry.

/**
 * This routine sub-divides a system into groups of ions, water, hetero
 * molecules, and polynucleotides/polypeptides.
 *
 * @param molecularAssembly a {@link ffx.potential.MolecularAssembly}
 * object.
 * @param atoms a {@link java.util.List} object.
 */
public static void biochemistry(MolecularAssembly molecularAssembly, List<Atom> atoms) {
    Atom atom, seed = null;
    int num = 0;
    int waterNum = 0;
    int ionNum = 0;
    int moleculeNum = 0;
    List<String> segIDs = new ArrayList<>();
    while (atoms.size() > 0) {
        /**
         * Nitrogen is used to "seed" a backbone search because carbon can
         * be separated from the backbone by a sulfur (ie. MET).
         */
        for (Atom a : atoms) {
            seed = a;
            if (seed.getAtomicNumber() == 7) {
                break;
            }
        }
        /**
         * If no nitrogen atoms remain, there are no nucleic or amino acids.
         */
        if (seed.getAtomicNumber() != 7) {
            List<Atom> moleculeAtoms;
            while (atoms.size() > 0) {
                atom = atoms.get(0);
                // Check for a metal ion or noble gas
                if (atom.getNumBonds() == 0) {
                    ionNum++;
                    Molecule ion = new Molecule(atom.getName() + "-" + ionNum);
                    ion.addMSNode(atom);
                    atoms.remove(0);
                    molecularAssembly.addMSNode(ion);
                    continue;
                } else // Check for water
                if (atom.getAtomicNumber() == 8 && isWaterOxygen(atom)) {
                    waterNum++;
                    Molecule water = new Molecule("Water-" + waterNum);
                    water.addMSNode(atom);
                    atoms.remove(0);
                    List<Bond> bonds = atom.getBonds();
                    for (Bond b : bonds) {
                        Atom hydrogen = b.get1_2(atom);
                        water.addMSNode(hydrogen);
                        atoms.remove(hydrogen);
                    }
                    molecularAssembly.addMSNode(water);
                    continue;
                }
                // Otherwise classify the molecule as a hetero
                moleculeNum++;
                Molecule molecule = new Molecule("Molecule-" + moleculeNum);
                moleculeAtoms = getAtomListFromPool();
                collectAtoms(atoms.get(0), moleculeAtoms);
                while (moleculeAtoms.size() > 0) {
                    atom = moleculeAtoms.get(0);
                    moleculeAtoms.remove(0);
                    molecule.addMSNode(atom);
                    atoms.remove(atom);
                }
                molecularAssembly.addMSNode(molecule);
            }
            seed = null;
            break;
        }
        List<Atom> backbone = findPolymer(atoms, seed, null);
        if (backbone.size() > 0) {
            for (ListIterator li = backbone.listIterator(backbone.size()); li.hasPrevious(); ) {
                seed = (Atom) li.previous();
                if (seed.getAtomicNumber() == 7) {
                    break;
                }
            }
            backbone = findPolymer(atoms, seed, null);
        }
        Character chainID = getChainID(num);
        String segID = getSegID(chainID, segIDs);
        Polymer c = new Polymer(chainID, segID, true);
        if (backbone.size() > 2 && divideBackbone(backbone, c)) {
            for (Atom a : c.getAtomList()) {
                atoms.remove(a);
            }
            logger.fine(" Sequenced chain: " + c.getName());
            molecularAssembly.addMSNode(c);
            num++;
        } else {
            moleculeNum++;
            Molecule hetero = new Molecule("" + moleculeNum + "-Hetero");
            atom = backbone.get(0);
            List<Atom> heteroAtomList = getAtomListFromPool();
            collectAtoms(atom, heteroAtomList);
            for (Atom a : heteroAtomList) {
                hetero.addMSNode(a);
            }
            for (Atom a : hetero.getAtomList()) {
                atoms.remove(a);
            }
            molecularAssembly.addMSNode(hetero);
        }
    }
}
Also used : Molecule(ffx.potential.bonded.Molecule) ArrayList(java.util.ArrayList) Polymer(ffx.potential.bonded.Polymer) List(java.util.List) ArrayList(java.util.ArrayList) Bond(ffx.potential.bonded.Bond) ListIterator(java.util.ListIterator) Atom(ffx.potential.bonded.Atom)

Example 47 with Atom

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

the class Utilities method patternMatch.

// Check to see if a portion of the backbone matches that of a
// biological polymer, and if so determine the respective residue
private static Residue patternMatch(int start, List<Atom> backbone, PolymerType type) {
    int[] pattern;
    // Initialization
    if (type == PolymerType.AMINOACID) {
        pattern = AAPATTERN;
        if (backbone.size() < start + pattern.length) {
            return null;
        }
        // Check for correct Carbonyl placement
        Atom a = backbone.get(start + 1);
        if (formsBondsWith(a, 8)) {
            return null;
        }
        a = backbone.get(start + 2);
        if (!formsBondsWith(a, 8)) {
            return null;
        }
    } else if (type == PolymerType.NUCLEICACID) {
        pattern = NAPATTERN;
        if (backbone.size() < start + pattern.length) {
            return null;
        }
    } else {
        return null;
    }
    int length = pattern.length;
    List<Atom> atoms = getAtomListFromPool();
    List<Atom> sidePolymer = getAtomListFromPool();
    for (int i = 0; i < length; i++) {
        Atom a = backbone.get(start + i);
        // add backbone atoms to terminate sidePolymer search
        sidePolymer.add(a);
        if (a.getAtomicNumber() != pattern[i]) {
            return null;
        }
    }
    // terminate the search, then remove them
    if (start > 0) {
        atoms.add(backbone.get(start - 1));
    }
    if (start + length < backbone.size()) {
        atoms.add(backbone.get(start + length));
    }
    collectAtoms(backbone.get(start), atoms);
    if (start > 0) {
        atoms.remove(0);
    }
    if (start + length < backbone.size()) {
        atoms.remove(0);
    // Collect Just Side chain atoms, then remove backbone termination
    }
    if (type == PolymerType.AMINOACID) {
        collectAtoms(sidePolymer.get(1), sidePolymer);
    } else if (type == PolymerType.NUCLEICACID) {
        Atom seed = null;
        for (Atom a : atoms) {
            if (a.getAtomicNumber() == 7) {
                seed = a;
                break;
            }
        }
        if (seed != null && seed.getAtomicNumber() == 7) {
            sidePolymer.add(seed);
            collectAtoms(seed, sidePolymer);
        } else {
            return null;
        }
    }
    for (int i = 0; i <= length; i++) {
        sidePolymer.remove(0);
    }
    Residue res = assignResidue(backbone, start, atoms, sidePolymer);
    return res;
}
Also used : Residue(ffx.potential.bonded.Residue) Atom(ffx.potential.bonded.Atom)

Example 48 with Atom

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

the class Utilities method assignResidue.

private static Residue assignResidue(List<Atom> backbone, int start, List<Atom> atoms, List<Atom> sidePolymer) {
    Atom a;
    int atomicnum;
    // 0 = S, 1 = P, 2 = O, 3 = N, 4 = C
    int[] bins = new int[5];
    char[] chars = { 'S', 'P', 'O', 'N', 'C' };
    for (ListIterator li = sidePolymer.listIterator(); li.hasNext(); ) {
        a = (Atom) li.next();
        atomicnum = a.getAtomicNumber();
        switch(atomicnum) {
            case 1:
                // ignore hydrogens
                break;
            case 6:
                // Carbon
                bins[4]++;
                break;
            case 7:
                // Nitrogen
                bins[3]++;
                break;
            case 8:
                // Oxygen
                bins[2]++;
                break;
            case 15:
                // Phosphorus
                bins[1]++;
                break;
            case 16:
                // Sulfur
                bins[0]++;
                break;
            default:
                return null;
        }
    }
    StringBuilder key = new StringBuilder();
    int atomCount = 0;
    for (int i = 0; i < 5; i++) {
        if (bins[i] != 0) {
            atomCount += bins[i];
            key.append(chars[i]);
            key.append(Integer.toString(bins[i]));
        }
    }
    if (atomCount == 0) {
        // Glycine
        key.append("H");
    }
    String resname = sidechainStoichiometry.get(key.toString());
    if (resname == null) {
        resname = "Unknown";
    } else {
        resname = resname.intern();
    }
    if (resname.equals("1") || resname.equals("2")) {
        // Special case where atom string keys aren't unique
        Atom alpha = backbone.get(start + 1);
        Atom carbonyl = backbone.get(start + 2);
        Atom beta = null;
        List alphabonds = alpha.getBonds();
        Bond abond;
        for (ListIterator li = alphabonds.listIterator(); li.hasNext(); ) {
            abond = (Bond) li.next();
            beta = abond.get1_2(alpha);
            // carbon
            if (beta.getAtomicNumber() != 7 && beta.getAtomicNumber() != 1 && beta != carbonyl) {
                break;
            }
            beta = null;
        }
        if (beta == null) {
            return null;
        }
        List<Bond> betabonds = beta.getBonds();
        Atom gamma;
        int carboncount = 0;
        for (ListIterator<Bond> li = betabonds.listIterator(); li.hasNext(); ) {
            abond = li.next();
            gamma = abond.get1_2(beta);
            if (gamma.getAtomicNumber() == 6) {
                carboncount++;
            }
        }
        if (resname.equals("1")) {
            if (carboncount == 2) {
                resname = "PRO";
            } else {
                resname = "VAL";
            }
        } else {
            if (carboncount == 2) {
                resname = "LEU";
            } else {
                resname = "ILE";
            }
        }
    } else if (resname.equals("3")) {
        Atom c3 = backbone.get(start + 3);
        int num = countCO(c3);
        if (num == 2) {
            resname = "A";
        } else {
            resname = "DG";
        }
    }
    Residue residue = null;
    try {
        Residue.NA3.valueOf(resname.toUpperCase());
        residue = new Residue(resname, Residue.ResidueType.NA);
    } catch (Exception e) {
    }
    if (residue == null) {
        try {
            Residue.AA3.valueOf(resname.toUpperCase());
            residue = new Residue(resname, Residue.ResidueType.AA);
        } catch (Exception e) {
        }
    }
    if (residue == null) {
        residue = new Residue(resname, Residue.ResidueType.UNK);
    }
    // Create the Residue group
    for (ListIterator li = atoms.listIterator(); li.hasNext(); ) {
        a = (Atom) li.next();
        residue.addMSNode(a);
    }
    return residue;
}
Also used : ListIterator(java.util.ListIterator) Atom(ffx.potential.bonded.Atom) Residue(ffx.potential.bonded.Residue) List(java.util.List) ArrayList(java.util.ArrayList) Bond(ffx.potential.bonded.Bond)

Example 49 with Atom

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

the class XtalEnergy method getCoordinates.

@Override
public double[] getCoordinates(double[] x) {
    int n = getNumberOfVariables();
    if (x == null || x.length < n) {
        x = new double[n];
    }
    int index = 0;
    for (int i = 0; i < nActive; i++) {
        Atom a = activeAtoms[i];
        x[index] = a.getX();
        index++;
        x[index] = a.getY();
        index++;
        x[index] = a.getZ();
        index++;
    }
    x[index] = unitCell.a;
    index++;
    x[index] = unitCell.b;
    index++;
    x[index] = unitCell.c;
    index++;
    x[index] = unitCell.alpha;
    index++;
    x[index] = unitCell.beta;
    index++;
    x[index] = unitCell.gamma;
    return x;
}
Also used : Atom(ffx.potential.bonded.Atom)

Example 50 with Atom

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

the class DualTopologyEnergy method getAcceleration.

@Override
public double[] getAcceleration(double[] acceleration) {
    if (acceleration == null || acceleration.length < nVariables) {
        acceleration = new double[nVariables];
    }
    int indexCommon = 0;
    int indexUnique = nShared * 3;
    double[] accel = new double[3];
    for (int i = 0; i < nActive1; i++) {
        Atom atom = activeAtoms1[i];
        atom.getAcceleration(accel);
        if (!doUnpin.test(atom)) {
            acceleration[indexCommon++] = accel[0];
            acceleration[indexCommon++] = accel[1];
            acceleration[indexCommon++] = accel[2];
        } else {
            acceleration[indexUnique++] = accel[0];
            acceleration[indexUnique++] = accel[1];
            acceleration[indexUnique++] = accel[2];
        }
    }
    for (int i = 0; i < nActive2; i++) {
        Atom atom = activeAtoms2[i];
        if (doUnpin.test(atom)) {
            atom.getAcceleration(accel);
            acceleration[indexUnique++] = accel[0];
            acceleration[indexUnique++] = accel[1];
            acceleration[indexUnique++] = accel[2];
        }
    }
    return acceleration;
}
Also used : Atom(ffx.potential.bonded.Atom)

Aggregations

Atom (ffx.potential.bonded.Atom)206 Residue (ffx.potential.bonded.Residue)42 Bond (ffx.potential.bonded.Bond)37 CoordRestraint (ffx.potential.nonbonded.CoordRestraint)34 ArrayList (java.util.ArrayList)33 OpenMM_System_addConstraint (simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint)23 Polymer (ffx.potential.bonded.Polymer)22 IOException (java.io.IOException)22 MSNode (ffx.potential.bonded.MSNode)21 Crystal (ffx.crystal.Crystal)20 Molecule (ffx.potential.bonded.Molecule)19 File (java.io.File)19 MultiResidue (ffx.potential.bonded.MultiResidue)17 MultipoleType (ffx.potential.parameters.MultipoleType)13 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)12 PointerByReference (com.sun.jna.ptr.PointerByReference)11 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)11 AtomType (ffx.potential.parameters.AtomType)11 List (java.util.List)11 MolecularAssembly (ffx.potential.MolecularAssembly)10