Search in sources :

Example 51 with Residue

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

the class MolecularAssembly method addMSNode.

/**
 * {@inheritDoc}
 */
@Override
public MSNode addMSNode(MSNode o) {
    ArrayList<MSNode> Polymers = getAtomNodeList();
    if (o instanceof Atom) {
        Atom atom = (Atom) o;
        if (atom.isModRes()) {
            return getResidue(atom, true, Residue.ResidueType.AA);
        } else if (!atom.isHetero()) {
            return getResidue(atom, true);
        } else {
            return getMolecule(atom, true);
        }
    } else if (o instanceof Residue) {
        Residue residue = (Residue) o;
        Character chainID = residue.getChainID();
        String segID = residue.getSegID();
        int index = Polymers.indexOf(new Polymer(chainID, segID));
        /**
         * See if the polymer already exists.
         */
        if (index != -1) {
            Polymer c = (Polymer) Polymers.get(index);
            setFinalized(false);
            return c.addMSNode(residue);
        } else {
            Polymer newc = new Polymer(chainID, segID);
            getAtomNode().add(newc);
            setFinalized(false);
            return newc.addMSNode(residue);
        }
    } else if (o instanceof Polymer) {
        Polymer c = (Polymer) o;
        int index = Polymers.indexOf(c);
        if (index == -1) {
            getAtomNode().add(c);
            setFinalized(false);
            return c;
        } else {
            return (Polymer) Polymers.get(index);
        }
    } else if (o instanceof Molecule) {
        Molecule m = (Molecule) o;
        if (m.getAtomNode().getChildCount() == 1) {
            ions.add(m);
            return m;
        } else if (Utilities.isWaterOxygen((Atom) m.getAtomNode().getChildAt(0))) {
            water.add(m);
            return m;
        } else {
            molecules.add(m);
            return m;
        }
    } else {
        String message = "Programming error in MolecularAssembly addNode";
        logger.log(Level.SEVERE, message);
        return o;
    }
}
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 52 with Residue

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

the class MolecularAssembly method getResiduePosition.

public ResiduePosition getResiduePosition(int residueNumber) {
    ResiduePosition position;
    int numberOfResidues = 0;
    Polymer[] polymers = getChains();
    int nPolymers = polymers.length;
    for (int i = 0; i < nPolymers; i++) {
        Polymer polymer = polymers[i];
        ArrayList<Residue> residues = polymer.getResidues();
        numberOfResidues += residues.size();
    }
    if (residueNumber == 0) {
        position = FIRST_RESIDUE;
    } else if (residueNumber == numberOfResidues - 1) {
        position = LAST_RESIDUE;
    } else {
        position = MIDDLE_RESIDUE;
    }
    return position;
}
Also used : ResiduePosition(ffx.potential.bonded.Residue.ResiduePosition) Residue(ffx.potential.bonded.Residue) Polymer(ffx.potential.bonded.Polymer)

Example 53 with Residue

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

the class MolecularAssembly method getBackBoneAtoms.

/**
 * <p>
 * getBackBoneAtoms</p>
 *
 * @return a {@link java.util.ArrayList} object.
 */
public ArrayList<Atom> getBackBoneAtoms() {
    ArrayList<Atom> backbone = new ArrayList<>();
    List<Residue> residues = getResidueList();
    for (Residue residue : residues) {
        backbone.addAll(residue.getBackboneAtoms());
    }
    /*Atom ca = new Atom("CA");
        ArrayList<ROLS> atoms = this.getList(Atom.class, new ArrayList<ROLS>());
        for (ROLS m : atoms) {
            Atom atom = (Atom) m;
            if (atom.equals(ca)) {
                backbone.add(atom);
                // else if (a.equals(new Atom("C"))) backbone.add(a);
                // else if (a.equals(new Atom("N"))) backbone.add(a);
            }
        }*/
    return backbone;
}
Also used : Residue(ffx.potential.bonded.Residue) ArrayList(java.util.ArrayList) Atom(ffx.potential.bonded.Atom)

Example 54 with Residue

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

the class Utilities method divideBackbone.

/**
 * <p>
 * divideBackbone</p>
 *
 * @param backbone a {@link java.util.List} object.
 * @param c a {@link ffx.potential.bonded.Polymer} object.
 * @return a boolean.
 */
public static boolean divideBackbone(List<Atom> backbone, Polymer c) {
    int length = backbone.size();
    // Try to find a Phosphorus or Nitrogen in the backbone
    int n, p;
    n = p = 0;
    for (Atom match : backbone) {
        int an = match.getAtomicNumber();
        if (an == 15) {
            p++;
        } else if (an == 7) {
            n++;
        }
    }
    PolymerType type;
    if (p >= n && p > 1) {
        type = PolymerType.NUCLEICACID;
    } else if (n > p && n > 2) {
        type = PolymerType.AMINOACID;
    } else {
        return false;
    }
    int start = -1;
    for (int i = 0; i < length; i++) {
        Residue res = patternMatch(i, backbone, type);
        if (res != null) {
            for (Atom a : res.getAtomList()) {
                a.setParent(null);
            }
            if (!(res.getName().equals("Unknown"))) {
                start = i;
                // Want 5' to 3'
                if (type == PolymerType.NUCLEICACID) {
                    Atom carbon5 = backbone.get(start + 1);
                    if (numberOfBondsWith(carbon5, 6) != 1) {
                        start = -1;
                    }
                }
                break;
            }
        }
    }
    if (start == -1) {
        backbone = reverseAtomList(backbone);
        for (int i = 0; i < length; i++) {
            Residue res = patternMatch(i, backbone, type);
            if (res != null) {
                for (Atom a : res.getAtomList()) {
                    a.setParent(null);
                }
                if (!(res.getName().equals("Unknown"))) {
                    start = i;
                    break;
                }
            }
        }
    }
    if (start == -1) {
        return false;
    }
    // Potential Polypeptide
    if (type == PolymerType.AMINOACID) {
        Atom nitrogen, alpha, carbonyl = null;
        Atom nitrogen2, carbonyl2;
        Residue aa = null;
        int lastRes = 0;
        int firstRes = -1;
        List<Residue> aaArray = new ArrayList<Residue>();
        while (start < length) {
            aa = patternMatch(start, backbone, PolymerType.AMINOACID);
            if (aa != null) {
                if (firstRes == -1) {
                    firstRes = start;
                    carbonyl = findCarbonyl(backbone.get(start));
                }
                aaArray.add(aa);
                lastRes = start;
            }
            start += 3;
        }
        // Make sure the fisrt residue is found
        aa = null;
        if (carbonyl != null) {
            alpha = findAlphaCarbon(carbonyl);
            if (alpha != null) {
                nitrogen = findBondWith(alpha, 7);
                if (nitrogen != null) {
                    nitrogen2 = findBondWith(carbonyl, 7);
                    List<Atom> firstAtoms = getAtomListFromPool();
                    firstAtoms.add(nitrogen);
                    firstAtoms.add(alpha);
                    firstAtoms.add(carbonyl);
                    firstAtoms.add(nitrogen2);
                    aa = patternMatch(0, firstAtoms, PolymerType.AMINOACID);
                    addAtomListToPool(firstAtoms);
                    if (aa != null) {
                        addCap(alpha, nitrogen, aa);
                        aaArray.add(0, aa);
                    }
                }
            }
        }
        // Add the remaining atoms to the end of the Polymer
        if (aa == null) {
            nitrogen = backbone.get(firstRes);
            alpha = backbone.get(firstRes + 1);
            addCap(alpha, nitrogen, aaArray.get(0));
        }
        // Make sure the last residue is found
        aa = null;
        carbonyl = findCarbonyl(backbone.get(lastRes + 1));
        if (carbonyl != null) {
            nitrogen = findBondWith(carbonyl, 7);
            if (nitrogen != null) {
                alpha = findAlphaCarbon(nitrogen);
                if (alpha != null) {
                    carbonyl2 = findCarbonyl(alpha);
                    if (carbonyl2 != null) {
                        List<Atom> lastAtoms = getAtomListFromPool();
                        lastAtoms.add(carbonyl);
                        lastAtoms.add(nitrogen);
                        lastAtoms.add(alpha);
                        lastAtoms.add(carbonyl2);
                        aa = patternMatch(1, lastAtoms, PolymerType.AMINOACID);
                        addAtomListToPool(lastAtoms);
                        if (aa != null) {
                            addCap(alpha, carbonyl2, aa);
                            aaArray.add(aa);
                        }
                    }
                }
            }
        }
        if (aa == null) {
            carbonyl = backbone.get(lastRes + 2);
            alpha = backbone.get(lastRes + 1);
            addCap(alpha, carbonyl, aaArray.get(aaArray.size() - 1));
        }
        int index = 1;
        for (Residue r : aaArray) {
            r.setNumber(index++);
            c.addMSNode(r);
        }
    // Potential DNA/RNA
    } else if (type == PolymerType.NUCLEICACID) {
        Residue base;
        int lastRes = 0;
        boolean firstBase = true;
        Atom phos = null;
        Atom oxygen1 = null;
        Atom phosphate1 = null;
        List<Residue> na = new ArrayList<Residue>();
        while (start < length) {
            base = patternMatch(start, backbone, PolymerType.NUCLEICACID);
            if (base != null) {
                phos = backbone.get(start - 1);
                if (phos != null && phos.getAtomicNumber() == 15) {
                    addPhosphate(phos, base);
                }
                na.add(base);
                if (firstBase) {
                    firstBase = false;
                    phosphate1 = backbone.get(start - 1);
                    oxygen1 = backbone.get(start);
                }
                lastRes = start;
            }
            start += 6;
        }
        // Make sure the fisrt base is found
        Atom o2, o3;
        Atom c1, c2, c3;
        if (phosphate1 != null && oxygen1 != null) {
            o2 = findOtherOxygen(phosphate1, oxygen1);
            if (o2 != null) {
                c1 = findBondWith(o2, 6);
                if (c1 != null) {
                    c2 = findCO(c1);
                    if (c2 != null) {
                        c3 = findC5(c2);
                        if (c3 != null) {
                            o3 = findBondWith(c3, 8);
                            if (o3 != null) {
                                List<Atom> firstAtoms = getAtomListFromPool();
                                firstAtoms.add(o3);
                                firstAtoms.add(c3);
                                firstAtoms.add(c2);
                                firstAtoms.add(c1);
                                firstAtoms.add(o2);
                                firstAtoms.add(phosphate1);
                                base = patternMatch(0, firstAtoms, type);
                                if (base != null) {
                                    addCap(c3, o3, base);
                                    na.add(0, base);
                                }
                            }
                        }
                    }
                }
            }
        }
        // Make sure the last base is found
        oxygen1 = backbone.get(lastRes + 4);
        phosphate1 = backbone.get(lastRes + 5);
        if (phosphate1 != null && oxygen1 != null) {
            o2 = findOtherOxygen(phosphate1, oxygen1);
            if (o2 != null) {
                c1 = findBondWith(o2, 6);
                if (c1 != null) {
                    c2 = findBondWith(c1, 6);
                    if (c2 != null) {
                        c3 = findCCO(c2);
                        if (c3 != null) {
                            o3 = findBondWith(c3, 8);
                            if (o3 != null) {
                                List<Atom> lastAtoms = getAtomListFromPool();
                                lastAtoms.add(phosphate1);
                                lastAtoms.add(o2);
                                lastAtoms.add(c1);
                                lastAtoms.add(c2);
                                lastAtoms.add(c3);
                                lastAtoms.add(o3);
                                base = patternMatch(1, lastAtoms, type);
                                if (base != null) {
                                    addPhosphate(phosphate1, base);
                                    addCap(c3, o3, base);
                                    na.add(base);
                                }
                            }
                        }
                    }
                }
            }
        }
        int index = 1;
        for (Residue r : na) {
            r.setNumber(index++);
            c.addMSNode(r);
        }
    } else {
        return false;
    }
    return true;
}
Also used : Residue(ffx.potential.bonded.Residue) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Atom(ffx.potential.bonded.Atom)

Example 55 with Residue

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

the class TitrationUtils method performTitration.

/**
 * Perform the requested titration on the given MultiResidue. Remember to
 * call reInit() on affected ForceFieldEnergy and MolecularDynamics objects!
 *
 * @param multiRes
 * @param titration
 */
public static TitrationType performTitration(MultiResidue multiRes, Titration titration, boolean inactivateBackground) {
    AminoAcid3 current = multiRes.getActive().getAminoAcid3();
    final TitrationType type;
    final AminoAcid3 target;
    if (current == titration.protForm) {
        type = TitrationType.DEPROT;
        target = titration.deprotForm;
    } else if (current == titration.deprotForm) {
        type = TitrationType.PROT;
        target = titration.protForm;
    } else {
        throw new IllegalStateException();
    }
    boolean success = multiRes.requestSetActiveResidue(target);
    if (!success) {
        logger.severe(String.format("Couldn't perform requested titration for MultiRes: %s", multiRes.toString()));
    }
    List<Atom> oldAtoms = multiRes.getActive().getAtomList();
    List<Atom> newAtoms = multiRes.getActive().getAtomList();
    // identify which atoms were actually inserted/removed
    List<Atom> removedAtoms = new ArrayList<>();
    List<Atom> insertedAtoms = new ArrayList<>();
    for (Atom oldAtom : oldAtoms) {
        boolean found = false;
        for (Atom newAtom : newAtoms) {
            if (newAtom == oldAtom || (newAtom.getResidueNumber() == oldAtom.getResidueNumber() && newAtom.getName().equals(oldAtom.getName()))) {
                found = true;
                break;
            }
        }
        if (!found) {
            removedAtoms.add(oldAtom);
        }
    }
    for (Atom newAtom : newAtoms) {
        boolean found = false;
        for (Atom oldAtom : oldAtoms) {
            if (newAtom == oldAtom || (newAtom.getResidueNumber() == oldAtom.getResidueNumber() && newAtom.getName().equals(oldAtom.getName()))) {
                found = true;
                break;
            }
        }
        if (!found) {
            insertedAtoms.add(newAtom);
        }
    }
    if (insertedAtoms.size() + removedAtoms.size() > 1) {
        logger.warning("Protonate: removed + inserted atom count > 1.");
    }
    if (inactivateBackground) {
        activateResidue(multiRes.getActive());
        for (Residue res : multiRes.getInactive()) {
            inactivateResidue(res);
        }
    }
    return type;
}
Also used : MultiResidue(ffx.potential.bonded.MultiResidue) Residue(ffx.potential.bonded.Residue) AminoAcid3(ffx.potential.bonded.ResidueEnumerations.AminoAcid3) ArrayList(java.util.ArrayList) Atom(ffx.potential.bonded.Atom)

Aggregations

Residue (ffx.potential.bonded.Residue)102 MultiResidue (ffx.potential.bonded.MultiResidue)66 Rotamer (ffx.potential.bonded.Rotamer)44 Atom (ffx.potential.bonded.Atom)41 RotamerLibrary.applyRotamer (ffx.potential.bonded.RotamerLibrary.applyRotamer)39 ArrayList (java.util.ArrayList)30 Polymer (ffx.potential.bonded.Polymer)29 IOException (java.io.IOException)20 Molecule (ffx.potential.bonded.Molecule)13 NACorrectionException (ffx.potential.bonded.NACorrectionException)13 MSNode (ffx.potential.bonded.MSNode)12 ResidueState (ffx.potential.bonded.ResidueState)11 Bond (ffx.potential.bonded.Bond)10 Crystal (ffx.crystal.Crystal)8 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)8 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)8 File (java.io.File)8 AminoAcid3 (ffx.potential.bonded.ResidueEnumerations.AminoAcid3)7 TitrationUtils.inactivateResidue (ffx.potential.extended.TitrationUtils.inactivateResidue)6 BufferedWriter (java.io.BufferedWriter)6