/** * Gets the van der Waals radius of the given atom following the values defined by Chothia (1976) * J.Mol.Biol.105,1-14 NOTE: the vdw values defined by the paper assume no Hydrogens and thus * "inflates" slightly the heavy atoms to account for Hydrogens. Thus this method cannot be used * in a structure that contains Hydrogens! * * <p>If atom is neither part of a nucleotide nor of a standard aminoacid, the default vdw radius * for the element is returned. If atom is of unknown type (element) the vdw radius of {@link * #Element().N} is returned * * @param atom * @return */ public static double getRadius(Atom atom) { if (atom.getElement() == null) { System.err.println( "Warning: unrecognised atom " + atom.getName() + " with serial " + atom.getPDBserial() + ", assigning the default vdw radius (Nitrogen vdw radius)."); return Element.N.getVDWRadius(); } Group res = atom.getGroup(); if (res == null) { System.err.println( "Warning: unknown parent residue for atom " + atom.getName() + " with serial " + atom.getPDBserial() + ", assigning its default vdw radius"); return atom.getElement().getVDWRadius(); } String type = res.getType(); if (type.equals(GroupType.AMINOACID)) return getRadiusForAmino(((AminoAcid) res), atom); if (type.equals(GroupType.NUCLEOTIDE)) return getRadiusForNucl((NucleotideImpl) res, atom); return atom.getElement().getVDWRadius(); }
private void checkRange(Structure s, String range) { GroupIterator iter = new GroupIterator(s); Group g1 = iter.next(); Group g2 = null; while (iter.hasNext()) { g2 = iter.next(); } assertNotNull(g1); assertNotNull(g2); String chainId = g1.getChain().getChainID(); String rangeTest = chainId + ":" + g1.getResidueNumber().toString() + "-" + g2.getResidueNumber().toString(); assertEquals("The expected range and the detected range don;t match!", rangeTest, range); }
private void recordUnidentifiableModifiedResidues(List<ModifiedCompound> modComps) { Set<StructureGroup> identifiedComps = new HashSet<StructureGroup>(); for (ModifiedCompound mc : modComps) { identifiedComps.addAll(mc.getGroups(true)); } // TODO: use the ModifiedAminoAcid after Andreas add that. for (Group group : residues) { if (group.getType().equals(GroupType.HETATM)) { StructureGroup strucGroup = StructureUtil.getStructureGroup(group, true); if (!identifiedComps.contains(strucGroup)) { unidentifiableModifiedResidues.add(strucGroup); } } } }
/** * Record unidentifiable atom linkages in a chain. Only linkages between two residues or one * residue and one ligand will be recorded. */ private void recordUnidentifiableAtomLinkages( List<ModifiedCompound> modComps, List<Group> ligands) { // first put identified linkages in a map for fast query Set<StructureAtomLinkage> identifiedLinkages = new HashSet<StructureAtomLinkage>(); for (ModifiedCompound mc : modComps) { identifiedLinkages.addAll(mc.getAtomLinkages()); } // record // cross link int nRes = residues.size(); for (int i = 0; i < nRes - 1; i++) { Group group1 = residues.get(i); for (int j = i + 1; j < nRes; j++) { Group group2 = residues.get(j); List<Atom[]> linkages = StructureUtil.findAtomLinkages(group1, group2, true, bondLengthTolerance); for (Atom[] atoms : linkages) { StructureAtomLinkage link = StructureUtil.getStructureAtomLinkage(atoms[0], true, atoms[1], true); unidentifiableAtomLinkages.add(link); } } } // attachment int nLig = ligands.size(); for (int i = 0; i < nRes; i++) { Group group1 = residues.get(i); for (int j = 0; j < nLig; j++) { Group group2 = ligands.get(j); if (group1.equals(group2)) { // overlap between residues and ligands continue; } List<Atom[]> linkages = StructureUtil.findAtomLinkages(group1, group2, false, bondLengthTolerance); for (Atom[] atoms : linkages) { StructureAtomLinkage link = StructureUtil.getStructureAtomLinkage(atoms[0], true, atoms[1], false); unidentifiableAtomLinkages.add(link); } } } }
private static char getOneLetter(Group g) { try { Character c = StructureTools.get1LetterCode(g.getPDBName()); return c; } catch (Exception e) { return 'X'; } }
/** * Calculates ASA for all atoms and return them as a GroupAsa array (one element per residue in * structure) containing ASAs per residue and per atom. The sorting of Groups in returned array is * as specified by {@link org.biojava.bio.structure.ResidueNumber} * * @return */ public GroupAsa[] getGroupAsas() { TreeMap<ResidueNumber, GroupAsa> asas = new TreeMap<ResidueNumber, GroupAsa>(); double[] asasPerAtom = calculateAsas(); for (int i = 0; i < atoms.length; i++) { Group g = atoms[i].getGroup(); if (!asas.containsKey(g.getResidueNumber())) { GroupAsa groupAsa = new GroupAsa(g); groupAsa.addAtomAsaU(asasPerAtom[i]); asas.put(g.getResidueNumber(), groupAsa); } else { GroupAsa groupAsa = asas.get(g.getResidueNumber()); groupAsa.addAtomAsaU(asasPerAtom[i]); } } return (GroupAsa[]) asas.values().toArray(new GroupAsa[asas.size()]); }
public static void main(String[] args) { try { FileParsingParameters params = new FileParsingParameters(); params.setParseSecStruc(true); AtomCache cache = new AtomCache(); cache.setFileParsingParams(params); Structure s = cache.getStructure("4hhb"); for (Chain c : s.getChains()) { for (Group g : c.getAtomGroups()) { if (g instanceof AminoAcid) { AminoAcid aa = (AminoAcid) g; Map<String, String> sec = aa.getSecStruc(); System.out.println( c.getChainID() + " " + g.getResidueNumber() + " " + g.getPDBName() + " " + " " + sec); } } } } catch (Exception e) { e.printStackTrace(); } }
public static Structure createArtificalStructure(AFPChain afpChain, Atom[] ca1, Atom[] ca2) throws Exception { if (afpChain.getNrEQR() < 1) { return GuiWrapper.getAlignedStructure(ca1, ca2); } Group[] twistedGroups = GuiWrapper.prepareGroupsForDisplay(afpChain, ca1, ca2); List<Atom> twistedAs = new ArrayList<Atom>(); for (Group g : twistedGroups) { if (g == null) continue; if (g.size() < 1) continue; Atom a = g.getAtom(0); twistedAs.add(a); } Atom[] twistedAtoms = (Atom[]) twistedAs.toArray(new Atom[twistedAs.size()]); List<Group> hetatms = new ArrayList<Group>(); List<Group> nucs1 = new ArrayList<Group>(); Group g1 = ca1[0].getParent(); Chain c1 = null; if (g1 != null) { c1 = g1.getParent(); if (c1 != null) { hetatms = c1.getAtomGroups("hetatm"); ; nucs1 = c1.getAtomGroups("nucleotide"); } } List<Group> hetatms2 = new ArrayList<Group>(); List<Group> nucs2 = new ArrayList<Group>(); Group g2 = ca2[0].getParent(); Chain c2 = null; if (g2 != null) { c2 = g2.getParent(); if (c2 != null) { hetatms2 = c2.getAtomGroups("hetatm"); nucs2 = c2.getAtomGroups("nucleotide"); } } Atom[] arr1 = GuiWrapper.getAtomArray(ca1, hetatms, nucs1); Atom[] arr2 = GuiWrapper.getAtomArray(twistedAtoms, hetatms2, nucs2); Structure artificial = GuiWrapper.getAlignedStructure(arr1, arr2); return artificial; }
/** Get matched atoms for all linkages. */ private List<List<Atom[]>> getMatchedAtomsOfLinkages( ModificationCondition condition, Map<Component, Set<Group>> mapCompGroups) { List<ModificationLinkage> linkages = condition.getLinkages(); int nLink = linkages.size(); List<List<Atom[]>> matchedAtomsOfLinkages = new ArrayList<List<Atom[]>>(nLink); for (int iLink = 0; iLink < nLink; iLink++) { ModificationLinkage linkage = linkages.get(iLink); Component comp1 = linkage.getComponent1(); Component comp2 = linkage.getComponent2(); // boolean isAA1 = comp1.; // boolean isAA2 = comp2.getType()==true; Set<Group> groups1 = mapCompGroups.get(comp1); Set<Group> groups2 = mapCompGroups.get(comp2); List<Atom[]> list = new ArrayList<Atom[]>(); List<String> potentialNamesOfAtomOnGroup1 = linkage.getPDBNameOfPotentialAtomsOnComponent1(); for (String name : potentialNamesOfAtomOnGroup1) { if (name.equals("*")) { // wildcard potentialNamesOfAtomOnGroup1 = null; // search all atoms break; } } List<String> potentialNamesOfAtomOnGroup2 = linkage.getPDBNameOfPotentialAtomsOnComponent2(); for (String name : potentialNamesOfAtomOnGroup2) { if (name.equals("*")) { // wildcard potentialNamesOfAtomOnGroup2 = null; // search all atoms break; } } for (Group g1 : groups1) { for (Group g2 : groups2) { if (g1.equals(g2)) { continue; } // only for wildcard match of two residues boolean ignoreNCLinkage = potentialNamesOfAtomOnGroup1 == null && potentialNamesOfAtomOnGroup2 == null && residues.contains(g1) && residues.contains(g2); Atom[] atoms = StructureUtil.findNearestAtomLinkage( g1, g2, potentialNamesOfAtomOnGroup1, potentialNamesOfAtomOnGroup2, ignoreNCLinkage, bondLengthTolerance); if (atoms != null) { list.add(atoms); } } } if (list.isEmpty()) { // broken linkage break; } matchedAtomsOfLinkages.add(list); } return matchedAtomsOfLinkages; }
/** * @param modifications a set of {@link ProteinModification}s. * @param residues * @param ligands * @param saveTo save result to * @return map from component to list of corresponding residues in the chain. */ private void addModificationGroups( final Set<ProteinModification> modifications, final List<Group> residues, final List<Group> ligands, final Map<Component, Set<Group>> saveTo) { if (residues == null || ligands == null || modifications == null) { throw new IllegalArgumentException("Null argument(s)."); } Map<Component, Set<Component>> mapSingleMultiComps = new HashMap<Component, Set<Component>>(); for (ProteinModification mod : modifications) { ModificationCondition condition = mod.getCondition(); for (Component comp : condition.getComponents()) { for (String pdbccId : comp.getPdbccIds()) { Component single = Component.of(Collections.singleton(pdbccId), comp.isNTerminal(), comp.isCTerminal()); Set<Component> mult = mapSingleMultiComps.get(single); if (mult == null) { mult = new HashSet<Component>(); mapSingleMultiComps.put(single, mult); } mult.add(comp); } } } { // ligands Set<Component> ligandsWildCard = mapSingleMultiComps.get(Component.of("*")); for (Group group : ligands) { String pdbccId = group.getPDBName().trim(); Set<Component> comps = mapSingleMultiComps.get(Component.of(pdbccId)); for (Component comp : unionComponentSet(ligandsWildCard, comps)) { Set<Group> gs = saveTo.get(comp); if (gs == null) { gs = new LinkedHashSet<Group>(); saveTo.put(comp, gs); } gs.add(group); } } } { // residues if (residues.isEmpty()) { return; } Set<Component> residuesWildCard = mapSingleMultiComps.get(Component.of("*")); // for all residues for (Group group : residues) { String pdbccId = group.getPDBName().trim(); Set<Component> comps = mapSingleMultiComps.get(Component.of(pdbccId)); for (Component comp : unionComponentSet(residuesWildCard, comps)) { Set<Group> gs = saveTo.get(comp); if (gs == null) { gs = new LinkedHashSet<Group>(); saveTo.put(comp, gs); } gs.add(group); } } // for N-terminal int nRes = residues.size(); int iRes = 0; Group res; do { // for all ligands on N terminal and the first residue res = residues.get(iRes++); Set<Component> nTermWildCard = mapSingleMultiComps.get(Component.of("*", true, false)); Set<Component> comps = mapSingleMultiComps.get(Component.of(res.getPDBName(), true, false)); for (Component comp : unionComponentSet(nTermWildCard, comps)) { Set<Group> gs = saveTo.get(comp); if (gs == null) { gs = new LinkedHashSet<Group>(); saveTo.put(comp, gs); } gs.add(res); } } while (iRes < nRes && ligands.contains(res)); // for C-terminal iRes = residues.size() - 1; do { // for all ligands on C terminal and the last residue res = residues.get(iRes--); Set<Component> cTermWildCard = mapSingleMultiComps.get(Component.of("*", false, true)); Set<Component> comps = mapSingleMultiComps.get(Component.of(res.getPDBName(), false, true)); for (Component comp : unionComponentSet(cTermWildCard, comps)) { Set<Group> gs = saveTo.get(comp); if (gs == null) { gs = new LinkedHashSet<Group>(); saveTo.put(comp, gs); } gs.add(res); } } while (iRes >= 0 && ligands.contains(res)); } }