Search in sources :

Example 1 with BondedUtils.findAtomType

use of ffx.potential.bonded.BondedUtils.findAtomType in project ffx by mjschnie.

the class AminoAcidUtils method assignAminoAcidAtomTypes.

public static void assignAminoAcidAtomTypes(Residue residue, Residue previousResidue, Residue nextResidue, ForceField forceField, ArrayList<Bond> bondList) throws MissingHeavyAtomException, MissingAtomTypeException {
    String residueName = residue.getName().toUpperCase();
    int j = 1;
    ResiduePosition position = MIDDLE_RESIDUE;
    if (previousResidue == null) {
        j = 0;
        position = FIRST_RESIDUE;
    } else if (nextResidue == null) {
        j = 2;
        position = LAST_RESIDUE;
        /**
         * If the last residue only contains a nitrogen turn it into an NH2
         * group.
         */
        Atom N = (Atom) residue.getAtomNode("N");
        if (residue.getAtomNodeList().size() == 1 && N != null) {
            residueName = "NH2".intern();
            residue.setName(residueName);
        }
    }
    AminoAcid3 aminoAcid = getAminoAcid(residueName);
    int aminoAcidNumber = getAminoAcidNumber(residueName);
    /**
     * Non-standard Amino Acid; use ALA backbone types.
     */
    boolean nonStandard = false;
    if (aminoAcid == AminoAcid3.UNK) {
        aminoAcidNumber = getAminoAcidNumber("ALA");
        nonStandard = true;
    }
    /**
     * Only the last residue in a chain should have an OXT/OT2 atom.
     */
    if (nextResidue != null) {
        removeOXT_OT2(residue);
    }
    /**
     * Only the first nitrogen should have H1, H2 and H3 atoms, unless it's
     * an NME cap.
     */
    if (previousResidue != null) {
        removeH1_H2_H3(aminoAcid, residue);
    }
    /**
     * Check for missing heavy atoms. This check ignores special terminating
     * groups like FOR, NH2, etc.
     */
    if (!nonStandard) {
        try {
            checkForMissingHeavyAtoms(aminoAcidNumber, aminoAcid, position, residue);
        } catch (BondedUtils.MissingHeavyAtomException e) {
            logger.log(Level.INFO, " {0} could not be parsed.", residue.toString());
            logger.warning("MissingHeavyAtomException incoming from 194.");
            throw e;
        }
    }
    Atom pC = null;
    Atom pCA = null;
    if (previousResidue != null) {
        pC = (Atom) previousResidue.getAtomNode("C");
        pCA = (Atom) previousResidue.getAtomNode("CA");
    }
    /**
     * Backbone heavy atoms.
     */
    Atom N = (Atom) residue.getAtomNode("N");
    if (N != null) {
        N.setAtomType(BondedUtils.findAtomType(AA_N[j][aminoAcidNumber], forceField));
        if (position != FIRST_RESIDUE) {
            buildBond(pC, N, forceField, bondList);
        }
    }
    Atom CA = null;
    Atom C = null;
    Atom O = null;
    if (!(position == LAST_RESIDUE && aminoAcid == AminoAcid3.NH2)) {
        if (aminoAcid == AminoAcid3.ACE || aminoAcid == AminoAcid3.NME) {
            CA = buildHeavy(residue, "CH3", N, AA_CA[j][aminoAcidNumber], forceField, bondList);
        } else {
            CA = buildHeavy(residue, "CA", N, AA_CA[j][aminoAcidNumber], forceField, bondList);
        }
        if (!(position == LAST_RESIDUE && aminoAcid == AminoAcid3.NME)) {
            C = buildHeavy(residue, "C", CA, AA_C[j][aminoAcidNumber], forceField, bondList);
            O = (Atom) residue.getAtomNode("O");
            if (O == null) {
                O = (Atom) residue.getAtomNode("OT1");
            }
            AtomType atomType = findAtomType(AA_O[j][aminoAcidNumber], forceField);
            if (O == null) {
                MissingHeavyAtomException missingHeavyAtom = new MissingHeavyAtomException("O", atomType, C);
                logger.warning(" MissingHeavyAtomException incoming from 234.");
                throw missingHeavyAtom;
            }
            O.setAtomType(atomType);
            buildBond(C, O, forceField, bondList);
        }
    }
    /**
     * Nitrogen hydrogen atoms.
     */
    AtomType atomType = findAtomType(AA_HN[j][aminoAcidNumber], forceField);
    switch(position) {
        case FIRST_RESIDUE:
            switch(aminoAcid) {
                case PRO:
                    buildHydrogenAtom(residue, "H2", N, 1.02, CA, 109.5, C, 0.0, 0, atomType, forceField, bondList);
                    buildHydrogenAtom(residue, "H3", N, 1.02, CA, 109.5, C, -120.0, 0, atomType, forceField, bondList);
                    break;
                case PCA:
                    buildHydrogenAtom(residue, "H", N, 1.02, CA, 109.5, C, -60.0, 0, atomType, forceField, bondList);
                    break;
                case ACE:
                    break;
                default:
                    buildHydrogenAtom(residue, "H1", N, 1.02, CA, 109.5, C, 180.0, 0, atomType, forceField, bondList);
                    buildHydrogenAtom(residue, "H2", N, 1.02, CA, 109.5, C, 60.0, 0, atomType, forceField, bondList);
                    buildHydrogenAtom(residue, "H3", N, 1.02, CA, 109.5, C, -60.0, 0, atomType, forceField, bondList);
            }
            break;
        case LAST_RESIDUE:
            switch(aminoAcid) {
                case NH2:
                    buildHydrogenAtom(residue, "H1", N, 1.02, pC, 119.0, pCA, 0.0, 0, atomType, forceField, bondList);
                    buildHydrogenAtom(residue, "H2", N, 1.02, pC, 119.0, pCA, 180.0, 0, atomType, forceField, bondList);
                    break;
                case NME:
                    buildHydrogenAtom(residue, "H", N, 1.02, pC, 118.0, CA, 121.0, 1, atomType, forceField, bondList);
                    break;
                default:
                    buildHydrogenAtom(residue, "H", N, 1.02, pC, 119.0, CA, 119.0, 1, atomType, forceField, bondList);
            }
            break;
        default:
            // Mid-chain nitrogen hydrogen.
            buildHydrogenAtom(residue, "H", N, 1.02, pC, 119.0, CA, 119.0, 1, atomType, forceField, bondList);
    }
    /**
     * C-alpha hydrogen atoms.
     */
    String haName = "HA";
    if (aminoAcid == AminoAcid3.GLY) {
        haName = "HA2";
    }
    atomType = findAtomType(AA_HA[j][aminoAcidNumber], forceField);
    switch(position) {
        case FIRST_RESIDUE:
            switch(aminoAcid) {
                case FOR:
                    buildHydrogenAtom(residue, "H", C, 1.12, O, 0.0, null, 0.0, 0, atomType, forceField, bondList);
                    break;
                case ACE:
                    buildHydrogenAtom(residue, "H1", CA, 1.10, C, 109.5, O, 180.0, 0, atomType, forceField, bondList);
                    buildHydrogenAtom(residue, "H2", CA, 1.10, C, 109.5, O, 60.0, 0, atomType, forceField, bondList);
                    buildHydrogenAtom(residue, "H3", CA, 1.10, C, 109.5, O, -60.0, 0, atomType, forceField, bondList);
                    break;
                default:
                    buildHydrogenAtom(residue, haName, CA, 1.10, N, 109.5, C, 109.5, -1, atomType, forceField, bondList);
                    break;
            }
            break;
        case LAST_RESIDUE:
            switch(aminoAcid) {
                case NME:
                    buildHydrogenAtom(residue, "H1", CA, 1.10, N, 109.5, pC, 180.0, 0, atomType, forceField, bondList);
                    buildHydrogenAtom(residue, "H2", CA, 1.10, N, 109.5, pC, 60.0, 0, atomType, forceField, bondList);
                    buildHydrogenAtom(residue, "H3", CA, 1.10, N, 109.5, pC, -60.0, 0, atomType, forceField, bondList);
                    break;
                default:
                    buildHydrogenAtom(residue, haName, CA, 1.10, N, 109.5, C, 109.5, -1, atomType, forceField, bondList);
            }
            break;
        default:
            buildHydrogenAtom(residue, haName, CA, 1.10, N, 109.5, C, 109.0, -1, atomType, forceField, bondList);
    }
    /**
     * Build the amino acid side chain.
     */
    assignAminoAcidSideChain(position, aminoAcid, residue, CA, N, C, forceField, bondList);
    /**
     * Build the terminal oxygen if the residue is not NH2 or NME.
     */
    if (position == LAST_RESIDUE && !(aminoAcid == AminoAcid3.NH2 || aminoAcid == AminoAcid3.NME)) {
        atomType = findAtomType(AA_O[2][aminoAcidNumber], forceField);
        Atom OXT = (Atom) residue.getAtomNode("OXT");
        if (OXT == null) {
            OXT = (Atom) residue.getAtomNode("OT2");
            if (OXT != null) {
                OXT.setName("OXT");
            }
        }
        if (OXT == null) {
            String resName = C.getResidueName();
            int resSeq = C.getResidueNumber();
            Character chainID = C.getChainID();
            Character altLoc = C.getAltLoc();
            String segID = C.getSegID();
            double occupancy = C.getOccupancy();
            double tempFactor = C.getTempFactor();
            OXT = new Atom(0, "OXT", altLoc, new double[3], resName, resSeq, chainID, occupancy, tempFactor, segID);
            OXT.setAtomType(atomType);
            residue.addMSNode(OXT);
            intxyz(OXT, C, 1.25, CA, 117.0, O, 126.0, 1);
        } else {
            OXT.setAtomType(atomType);
        }
        buildBond(C, OXT, forceField, bondList);
    }
    /**
     * Do some checks on the current residue to make sure all atoms have
     * been assigned an atom type.
     */
    List<Atom> resAtoms = residue.getAtomList();
    for (Atom atom : resAtoms) {
        atomType = atom.getAtomType();
        if (atomType == null) {
            /**
             * Sometimes, with deuterons, a proton has been constructed in
             * its place, so we have a "dummy" deuteron still hanging
             * around.
             */
            String protonEq = atom.getName().replaceFirst("D", "H");
            Atom correspH = (Atom) residue.getAtomNode(protonEq);
            if (correspH == null || correspH.getAtomType() == null) {
                MissingAtomTypeException missingAtomTypeException = new MissingAtomTypeException(residue, atom);
                logger.warning("MissingAtomTypeException incoming from 393.");
                throw missingAtomTypeException;
            } else {
                correspH.setName(atom.getName());
                atom.removeFromParent();
                atom = correspH;
                atomType = atom.getAtomType();
            }
        }
        int numberOfBonds = atom.getNumBonds();
        if (numberOfBonds != atomType.valence) {
            if (atom == C && numberOfBonds == atomType.valence - 1 && position != LAST_RESIDUE) {
                continue;
            }
            logger.warning(format(" An atom for residue %s has the wrong number of bonds:\n %s", residueName, atom.toString()));
            logger.warning(format(" Expected: %d Actual: %d.", atomType.valence, numberOfBonds));
        }
    }
}
Also used : ResiduePosition(ffx.potential.bonded.Residue.ResiduePosition) AminoAcid3(ffx.potential.bonded.ResidueEnumerations.AminoAcid3) MissingHeavyAtomException(ffx.potential.bonded.BondedUtils.MissingHeavyAtomException) MissingHeavyAtomException(ffx.potential.bonded.BondedUtils.MissingHeavyAtomException) BondedUtils.buildHydrogenAtom(ffx.potential.bonded.BondedUtils.buildHydrogenAtom) MissingAtomTypeException(ffx.potential.bonded.BondedUtils.MissingAtomTypeException) AtomType(ffx.potential.parameters.AtomType) BondedUtils.findAtomType(ffx.potential.bonded.BondedUtils.findAtomType)

Aggregations

MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)1 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)1 BondedUtils.buildHydrogenAtom (ffx.potential.bonded.BondedUtils.buildHydrogenAtom)1 BondedUtils.findAtomType (ffx.potential.bonded.BondedUtils.findAtomType)1 ResiduePosition (ffx.potential.bonded.Residue.ResiduePosition)1 AminoAcid3 (ffx.potential.bonded.ResidueEnumerations.AminoAcid3)1 AtomType (ffx.potential.parameters.AtomType)1