Search in sources :

Example 1 with ResidueNumber

use of org.biojava.bio.structure.ResidueNumber in project ffx by mjschnie.

the class PDBFileMatcher method getMatchingAtom.

/**
 * Finds atom1's match in structure2; uses atom1's residue number, atom
 * type, and PDB serial number as a guess; if robustMatch is set true, will
 * search all Atoms in structure2.
 *
 * @param atom1 An Atom
 * @param structure2 A Structure to search
 * @param searchAll Whether to search all Atoms in structure2.
 * @return atom1's match in structure2
 * @throws IllegalArgumentException If no match can be found.
 */
private Atom getMatchingAtom(Atom atom1, Structure structure2, boolean searchAll) throws IllegalArgumentException {
    ResidueNumber res1 = atom1.getGroup().getResidueNumber();
    String chainID = res1.getChainId();
    Atom atom2 = null;
    try {
        Chain chain2 = structure2.getChainByPDB(chainID);
        Group group2 = chain2.getGroupByPDB(res1);
        try {
            atom2 = group2.getAtom(atom1.getName());
        } catch (StructureException ex) {
            if (atom1.getName().equalsIgnoreCase("H")) {
                atom2 = group2.getAtom("H1");
            } else if (atom1.getName().equalsIgnoreCase("H1")) {
                atom2 = group2.getAtom("H");
            }
            atom2 = group2.getAtom(atom1.getPDBserial());
        }
    } catch (StructureException ex) {
        if (!searchAll) {
            throw new IllegalArgumentException("Matching atom not found.");
        }
        for (Chain chain : structure2.getChains()) {
            for (Group group : chain.getAtomGroups()) {
                for (Atom atom : group.getAtoms()) {
                    if (compareAtoms(atom1, atom)) {
                        return atom2;
                    }
                }
            }
        }
    }
    if (atom2 != null && compareAtoms(atom1, atom2)) {
        return atom2;
    }
    throw new IllegalArgumentException("Matching atom not found.");
}
Also used : Chain(org.biojava.bio.structure.Chain) Group(org.biojava.bio.structure.Group) StructureException(org.biojava.bio.structure.StructureException) ResidueNumber(org.biojava.bio.structure.ResidueNumber) Atom(org.biojava.bio.structure.Atom)

Example 2 with ResidueNumber

use of org.biojava.bio.structure.ResidueNumber in project ffx by mjschnie.

the class BiojavaFilter method convert.

/**
 * {@inheritDoc}
 *
 * Parse the Biojava Structure
 *
 * @return true if the structure is successfully converted
 */
@Override
public boolean convert() {
    // First atom is #1, to match xyz file format
    int xyzIndex = 1;
    setConverted(false);
    systems.add(activeMolecularAssembly);
    if (mutate) {
        List<Character> chainIDs = new ArrayList<>();
        for (Chain chain : structure.getChains()) {
            chainIDs.add(chain.getChainID().charAt(0));
        }
        if (!chainIDs.contains(mutateChainID)) {
            if (chainIDs.size() == 1) {
                logger.warning(String.format(" Chain ID %c for " + "mutation not found: only one chain %c " + "found.", mutateChainID, chainIDs.get(0)));
                mutateChainID = chainIDs.get(0);
            } else {
                logger.warning(String.format(" Chain ID %c for " + "mutation not found: mutation will not " + "proceed.", mutateChainID));
            }
        }
    }
    /**
     * Echo the alternate location being parsed.
     */
    if (currentAltLoc == 'A') {
        logger.info(String.format(" Reading %s", structure.getName()));
    } else {
        logger.info(String.format(" Reading %s alternate location %s", structure.getName(), currentAltLoc));
    }
    org.biojava.bio.structure.Atom[] bjAtoms = StructureTools.getAllAtomArray(structure);
    int nAtoms = bjAtoms.length;
    Atom[] ffxAtoms = new Atom[nAtoms];
    /**
     * Reset the current chain and segID.
     */
    currentChainID = null;
    currentSegID = null;
    PDBCrystallographicInfo cInfo = structure.getCrystallographicInfo();
    if (cInfo.isCrystallographic()) {
        // I do not think we need to check if it already has these properties,
        // but it can be done.
        properties.addProperty("a-axis", cInfo.getA());
        properties.addProperty("b-axis", cInfo.getB());
        properties.addProperty("c-axis", cInfo.getC());
        properties.addProperty("alpha", cInfo.getAlpha());
        properties.addProperty("beta", cInfo.getBeta());
        properties.addProperty("gamma", cInfo.getGamma());
        properties.addProperty("spacegroup", SpaceGroup.pdb2ShortName(cInfo.getSpaceGroup()));
    }
    for (org.biojava.bio.structure.Atom atom : bjAtoms) {
        String name = atom.getName().toUpperCase().trim();
        double[] xyz = new double[3];
        xyz[0] = atom.getX();
        xyz[1] = atom.getY();
        xyz[2] = atom.getZ();
        char altLoc = atom.getAltLoc();
        if (!altLocs.contains(altLoc)) {
            altLocs.add(altLoc);
        }
        if (altLoc != ' ' && altLoc != 'A' && altLoc != currentAltLoc) {
            break;
        }
        if (name.contains("1H") || name.toUpperCase().contains("2H") || name.toUpperCase().contains("3H")) {
            // VERSION3_2 is presently just a placeholder for "anything non-standard".
            fileStandard = VERSION3_2;
        }
        Group group = atom.getGroup();
        ResidueNumber resnum = group.getResidueNumber();
        int resSeq = resnum.getSeqNum();
        String resName = group.getPDBName().trim().toUpperCase();
        Chain chain = group.getChain();
        char chainID = chain.getChainID().charAt(0);
        String segID = getSegID(chainID);
        boolean printAtom = false;
        if (mutate && chainID == mutateChainID && mutateResID == resSeq) {
            if (name.equals("N") || name.equals("C") || name.equals("O") || name.equals("CA")) {
                printAtom = true;
                name = mutateToResname;
            } else {
                logger.info(String.format(" Deleting atom %s of %s %d", name, resName, resSeq));
                break;
            }
        }
        Atom newAtom = new Atom(0, name, altLoc, xyz, resName, resSeq, chainID, atom.getOccupancy(), atom.getTempFactor(), segID);
        /* Biojava sets at least some capping groups, and possibly nonstandard
             amino acids to be heteroatoms. */
        boolean hetatm = true;
        for (AminoAcid3 aa3Name : AminoAcid3.values()) {
            if (aa3Name.name().equals(resName)) {
                hetatm = false;
                break;
            }
        }
        newAtom.setHetero(hetatm);
        // Look Ma, Biojava doesn't care about anisou!
        Atom returnedAtom = (Atom) activeMolecularAssembly.addMSNode(newAtom);
        if (returnedAtom != newAtom) {
            atoms.put(atom.getPDBserial(), returnedAtom);
            if (logger.isLoggable(Level.FINE)) {
                logger.fine(String.format("%s has been retained over\n%s", returnedAtom.toString(), newAtom.toString()));
            }
        } else {
            atoms.put(atom.getPDBserial(), newAtom);
            if (newAtom.getIndex() == 0) {
                newAtom.setXyzIndex(xyzIndex++);
            }
            if (printAtom) {
                logger.info(newAtom.toString());
            }
        }
    }
    List<Bond> ssBondList = new ArrayList<>();
    for (SSBond ssBond : structure.getSSBonds()) {
        Polymer c1 = activeMolecularAssembly.getChain(ssBond.getChainID1());
        Polymer c2 = activeMolecularAssembly.getChain(ssBond.getChainID2());
        int rn1;
        int rn2;
        try {
            rn1 = Integer.parseInt(ssBond.getResnum1());
            rn2 = Integer.parseInt(ssBond.getResnum1());
        } catch (NumberFormatException ex) {
            logger.warning(String.format(" Could not parse SSbond %d", ssBond.getSerNum()));
            continue;
        }
        Residue r1 = c1.getResidue(rn1);
        Residue r2 = c2.getResidue(rn2);
        List<Atom> atoms1 = r1.getAtomList();
        List<Atom> atoms2 = r2.getAtomList();
        Atom SG1 = null;
        Atom SG2 = null;
        for (Atom atom : atoms1) {
            if (atom.getName().equalsIgnoreCase("SG")) {
                SG1 = atom;
                break;
            }
        }
        for (Atom atom : atoms2) {
            if (atom.getName().equalsIgnoreCase("SG")) {
                SG2 = atom;
                break;
            }
        }
        if (SG1 == null) {
            logger.warning(String.format(" SG atom 1 of SS-bond %s is null", ssBond.toString()));
        }
        if (SG2 == null) {
            logger.warning(String.format(" SG atom 2 of SS-bond %s is null", ssBond.toString()));
        }
        if (SG1 == null || SG2 == null) {
            continue;
        }
        double d = VectorMath.dist(SG1.getXYZ(null), SG2.getXYZ(null));
        if (d < 3.0) {
            r1.setName("CYX");
            r2.setName("CYX");
            for (Atom atom : atoms1) {
                atom.setResName("CYX");
            }
            for (Atom atom : atoms2) {
                atom.setResName("CYX");
            }
            Bond bond = new Bond(SG1, SG2);
            ssBondList.add(bond);
        } else {
            String message = String.format("Ignoring [%s]\n due to distance %8.3f A.", ssBond.toString(), d);
            logger.log(Level.WARNING, message);
        }
    }
    int pdbAtoms = activeMolecularAssembly.getAtomArray().length;
    assignAtomTypes();
    StringBuilder sb = new StringBuilder(" Disulfide Bonds:");
    for (Bond bond : ssBondList) {
        Atom a1 = bond.getAtom(0);
        Atom a2 = bond.getAtom(1);
        int[] c = new int[2];
        c[0] = a1.getAtomType().atomClass;
        c[1] = a2.getAtomType().atomClass;
        String key = ffx.potential.parameters.BondType.sortKey(c);
        ffx.potential.parameters.BondType bondType = forceField.getBondType(key);
        if (bondType == null) {
            logger.severe(String.format("No BondType for key: %s\n %s\n %s", key, a1, a2));
        } else {
            bond.setBondType(bondType);
        }
        double d = VectorMath.dist(a1.getXYZ(null), a2.getXYZ(null));
        Polymer c1 = activeMolecularAssembly.getChain(a1.getSegID());
        Polymer c2 = activeMolecularAssembly.getChain(a2.getSegID());
        Residue r1 = c1.getResidue(a1.getResidueNumber());
        Residue r2 = c2.getResidue(a2.getResidueNumber());
        sb.append(String.format("\n S-S distance of %6.2f for %s and %s.", d, r1.toString(), r2.toString()));
        bondList.add(bond);
    }
    if (ssBondList.size() > 0) {
        logger.info(sb.toString());
    }
    /**
     * Finally, re-number the atoms if missing atoms were created.
     */
    if (pdbAtoms != activeMolecularAssembly.getAtomArray().length) {
        numberAtoms();
    }
    return true;
}
Also used : Chain(org.biojava.bio.structure.Chain) Group(org.biojava.bio.structure.Group) MSGroup(ffx.potential.bonded.MSGroup) SpaceGroup(ffx.crystal.SpaceGroup) ArrayList(java.util.ArrayList) PDBCrystallographicInfo(org.biojava.bio.structure.PDBCrystallographicInfo) SSBond(org.biojava.bio.structure.SSBond) AminoAcid3(ffx.potential.bonded.ResidueEnumerations.AminoAcid3) Polymer(ffx.potential.bonded.Polymer) Atom(ffx.potential.bonded.Atom) Residue(ffx.potential.bonded.Residue) ResidueNumber(org.biojava.bio.structure.ResidueNumber) Bond(ffx.potential.bonded.Bond) SSBond(org.biojava.bio.structure.SSBond)

Aggregations

Chain (org.biojava.bio.structure.Chain)2 Group (org.biojava.bio.structure.Group)2 ResidueNumber (org.biojava.bio.structure.ResidueNumber)2 SpaceGroup (ffx.crystal.SpaceGroup)1 Atom (ffx.potential.bonded.Atom)1 Bond (ffx.potential.bonded.Bond)1 MSGroup (ffx.potential.bonded.MSGroup)1 Polymer (ffx.potential.bonded.Polymer)1 Residue (ffx.potential.bonded.Residue)1 AminoAcid3 (ffx.potential.bonded.ResidueEnumerations.AminoAcid3)1 ArrayList (java.util.ArrayList)1 Atom (org.biojava.bio.structure.Atom)1 PDBCrystallographicInfo (org.biojava.bio.structure.PDBCrystallographicInfo)1 SSBond (org.biojava.bio.structure.SSBond)1 StructureException (org.biojava.bio.structure.StructureException)1