/** * Get all AAs in a chain */ List<AminoAcid> aminoAcids(Chain chain) { ArrayList<AminoAcid> aas = new ArrayList<AminoAcid>(); for (Group group : chain.getAtomGroups()) if (group instanceof AminoAcid) aas.add((AminoAcid) group); return aas; }
/** * Translates a chain object, given a Vector3d (i.e. the vecmath library * double-precision 3-d vector) * * @param chain * @param v */ public static final void translate (Chain chain, Vector3d v) { for (Group g:chain.getAtomGroups()) { translate(g, v); } }
private int getMaxSequenceLength(){ int l1 = panel1.getChain().getAtomGroups(GroupType.AMINOACID).size(); int l2 = panel2.getChain().getAtomGroups(GroupType.AMINOACID).size(); if ( l1 > l2) return l1; else return l2; }
/** * Transforms a chain object, given a Matrix4d (i.e. the vecmath library * double-precision 4x4 rotation+translation matrix). The transformation * Matrix must be a post-multiplication Matrix. * * @param chain * @param m */ public static final void transform (Chain chain, Matrix4d m) { for (Group g : chain.getAtomGroups()) { transform(g, m); } }
/** * Get all amino acids in a chain. * @param chain * @return */ public static List<Group> getAminoAcids(Chain chain) { List<Group> gs = new ArrayList<>(); for ( Group g : chain.getAtomGroups()){ if ( g.isAminoAcid()) gs.add(g); } return gs; }
private void alignNucleotideChains(Chain seqRes, Chain atomRes) { if ( atomRes.getAtomGroups(GroupType.NUCLEOTIDE).size() < 1) { logger.debug("ATOM chain {} does not contain nucleotides, ignoring...", atomRes.getId()); return; } logger.debug("Alignment for chain {}", atomRes.getId() ); List<Group> seqResGroups = seqRes.getAtomGroups(); boolean noMatchFound = alignNucleotideGroups(seqResGroups,atomRes.getAtomGroups()); if ( ! noMatchFound){ atomRes.setSeqResGroups(seqResGroups); } }
/** * Count the total number of groups in the structure * @param structure the input structure * @return the total number of groups */ public static int getNumGroups(Structure structure) { int count = 0; for(int i=0; i<structure.nrModels(); i++) { for(Chain chain : structure.getChains(i)){ count+= chain.getAtomGroups().size(); } } return count; }
/** * Returns and array of all atoms of the chain, including * Hydrogens (if present) and all HETATOMs. Waters are not included. * * @param c * input chain * @return all atom array */ public static final Atom[] getAllAtomArray(Chain c) { List<Atom> atoms = new ArrayList<Atom>(); for (Group g : c.getAtomGroups()) { if (g.isWater()) continue; for (Atom a : g.getAtoms()) { atoms.add(a); } } return atoms.toArray(new Atom[atoms.size()]); }
import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureIO; public class StackOverflowIssue { public static void main(String[] args) throws Exception { Structure s = StructureIO.getStructure("2a65"); Chain c = s.getChainByPDB("A"); for (Group gr : c.getSeqResGroups()) { System.out.println(gr.getResidueNumber()+" "+gr.getPDBName()); } for (Group gr : c.getAtomGroups()) { if (!gr.isWater()) System.out.println(gr.getResidueNumber()+" "+gr.getPDBName()); } } }
/** * Returns an Atom array of the C-alpha atoms. Any atom that is a carbon and * has CA name will be returned. * * @param c * the structure object * @return an Atom[] array * @see #getRepresentativeAtomArray(Chain) */ public static final Atom[] getAtomCAArray(Chain c) { List<Atom> atoms = new ArrayList<Atom>(); for (Group g : c.getAtomGroups()) { if (g.hasAtom(CA_ATOM_NAME) && g.getAtom(CA_ATOM_NAME).getElement() == Element.C) { atoms.add(g.getAtom(CA_ATOM_NAME)); } } return atoms.toArray(new Atom[atoms.size()]); }
/** * Add the missing groups to the SeqResGroups. * @param modelChain the chain to add the information for * @param sequence the sequence of the construct */ public static void addSeqRes(Chain modelChain, String sequence) { List<Group> seqResGroups = modelChain.getSeqResGroups(); GroupType chainType = getChainType(modelChain.getAtomGroups()); for(int i=0; i<sequence.length(); i++){ char singleLetterCode = sequence.charAt(i); Group group = null; if(seqResGroups.size()<=i){ } else{ group=seqResGroups.get(i); } if(group!=null){ continue; } group = getSeqResGroup(modelChain, singleLetterCode, chainType); addGroupAtId(seqResGroups, group, i); seqResGroups.set(i, group); } }
/** * Return an Atom array of the C-alpha atoms. Any atom that is a carbon and * has CA name will be returned. * * @param s * the structure object * @return an Atom[] array * @see #getRepresentativeAtomArray(Structure) */ public static Atom[] getAtomCAArray(Structure s) { List<Atom> atoms = new ArrayList<Atom>(); for (Chain c : s.getChains()) { for (Group g : c.getAtomGroups()) { if (g.hasAtom(CA_ATOM_NAME) && g.getAtom(CA_ATOM_NAME).getElement() == Element.C) { atoms.add(g.getAtom(CA_ATOM_NAME)); } } } return atoms.toArray(new Atom[atoms.size()]); }
/** * Returns and array of all non-Hydrogen atoms in the given Chain, * optionally including HET atoms or not Waters are not included. * * @param c * @param hetAtoms * if true HET atoms are included in array, if false they are not * @return */ public static final Atom[] getAllNonHAtomArray(Chain c, boolean hetAtoms) { List<Atom> atoms = new ArrayList<Atom>(); for (Group g : c.getAtomGroups()) { if (g.isWater()) continue; for (Atom a : g.getAtoms()) { if (a.getElement() == Element.H) continue; if (!hetAtoms && g.getType().equals(GroupType.HETATM)) continue; atoms.add(a); } } return atoms.toArray(new Atom[atoms.size()]); }
private void trimBondLists() { for (int modelInd=0; modelInd<structure.nrModels(); modelInd++){ for (Chain chain : structure.getChains(modelInd)) { for (Group group : chain.getAtomGroups()) { for (Atom atom : group.getAtoms()) { if (atom.getBonds()!=null && atom.getBonds().size() > 0) { ((ArrayList<Bond>) atom.getBonds()).trimToSize(); } } } } } }
/** * Returns and array of all non-Hydrogen atoms coordinates in the given Chain, * optionally including HET atoms or not Waters are not included. * * @param c * @param hetAtoms * if true HET atoms are included in array, if false they are not * @return */ public static final Point3d[] getAllNonHCoordsArray(Chain c, boolean hetAtoms) { List<Point3d> atoms = new ArrayList<Point3d>(); for (Group g : c.getAtomGroups()) { if (g.isWater()) continue; for (Atom a : g.getAtoms()) { if (a.getElement() == Element.H) continue; if (!hetAtoms && g.getType().equals(GroupType.HETATM)) continue; atoms.add(a.getCoordsAsPoint3d()); } } return atoms.toArray(new Point3d[atoms.size()]); }
/** * * @return */ private Group getGroupWithSameResNumButDiffPDBName() { // If this chain already has this group number for (Group g : chain.getAtomGroups() ) { if (g.getResidueNumber().equals(group.getResidueNumber())) { if( ! g.getPDBName().equals(group.getPDBName() )){ return g; } } } return null; }
/** * Prints the connections in PDB style * * Rewritten since 5.0 to use {@link Bond}s * Will produce strictly one CONECT record per bond (won't group several bonds in one line) */ private String printPDBConnections(){ StringBuilder str = new StringBuilder(); for (Chain c:structure.getChains()) { for (Group g:c.getAtomGroups()) { for (Atom a:g.getAtoms()) { if (a.getBonds()!=null) { for (Bond b:a.getBonds()) { //7890123456789012345678901234567890123456789012345678901234567890 str.append(String.format("CONECT%5d%5d "+newline, b.getAtomA().getPDBserial(), b.getAtomB().getPDBserial())); } } } } } return str.toString(); }
public synchronized void setChain(Chain c){ List<Group> a = c.getAtomGroups(GroupType.AMINOACID); seqArr = new Character[a.size()]; chain = new ChainImpl(); Iterator<Group> iter = a.iterator(); int i = 0; while (iter.hasNext()){ AminoAcid aa = (AminoAcid) iter.next(); // preserver original hierarchy ... for highlighting in Jmol Chain old = aa.getChain(); chain.addGroup(aa); aa.setChain(old); seqArr[i] = aa.getAminoType(); i++; } chainLength = i; coordManager.setLength(chainLength); setPrefSize(); this.repaint(); }
/** * Returns a {@link Structure} corresponding to the CATH identifier supplied in {@code structureName}, using the specified {@link CathDatabase}. */ public Structure getStructureForCathDomain(StructureName structureName, CathDatabase cathInstall) throws IOException, StructureException { CathDomain cathDomain = cathInstall.getDomainByCathId(structureName.getIdentifier()); Structure s = getStructureForPdbId(cathDomain.getIdentifier()); Structure n = cathDomain.reduce(s); // add the ligands of the chain... Chain newChain = n.getPolyChainByPDB(structureName.getChainId()); List<Chain> origChains = s.getNonPolyChainsByPDB(structureName.getChainId()); for ( Chain origChain : origChains) { List<Group> ligands = origChain.getAtomGroups(); for (Group g : ligands) { if (!newChain.getAtomGroups().contains(g)) { newChain.addGroup(g); } } } return n; }
/** * Auxiliary method to reset chain ids of residue numbers in a chain. * Used when cloning chains and resetting their ids: one needs to take care of * resetting the ids within residue numbers too. * @param c * @param newChainName */ private static void setChainIdsInResidueNumbers(Chain c, String newChainName) { for (Group g:c.getAtomGroups()) { g.setResidueNumber(newChainName, g.getResidueNumber().getSeqNum(), g.getResidueNumber().getInsCode()); } for (Group g:c.getSeqResGroups()) { if (g.getResidueNumber()==null) continue; g.setResidueNumber(newChainName, g.getResidueNumber().getSeqNum(), g.getResidueNumber().getInsCode()); } }