/** * {@inheritDoc} */ @Override public Atom getAtom(String name) { if ( atomNameLookup != null) return atomNameLookup.get(name); else { /** This is the performance penalty we pay for NOT using the atomnameLookup in PerformanceBehaviour.LESS_MEMORY_SLOWER_PERFORMANCE */ for (Atom a : atoms) { if (a.getName().equals(name)) { return a; } } return null; } }
/** * {@inheritDoc} */ @Override public boolean hasAtom(String fullName) { if ( atomNameLookup != null) { Atom a = atomNameLookup.get(fullName.trim()); return a != null; } else { /** This is the performance penalty we pay for NOT using the atomnameLookup in PerformanceBehaviour.LESS_MEMORY_SLOWER_PERFORMANCE */ for (Atom a : atoms) { if (a.getName().equals(fullName)) { return true; } } return false; } }
/** * {@inheritDoc} */ @Override public void setAtoms(List<Atom> atoms) { // important we are resetting atoms to a new list, we need to reset the lookup too! if ( atomNameLookup != null) atomNameLookup.clear(); for (Atom a: atoms){ a.setGroup(this); if ( atomNameLookup != null) atomNameLookup.put(a.getName(),a); } this.atoms = atoms; if (!atoms.isEmpty()) { pdb_flag = true; } }
/** * * @param group a {@link Group}. * @return all atom names of the group. */ public static List<String> getAtomNames(Group group) { List<Atom> atoms = group.getAtoms(); if (atoms == null) { return Collections.emptyList(); } int n = atoms.size(); List<String> ret = new ArrayList<String>(n); for (int i=0; i<n; i++) { ret.add(atoms.get(i).getName()); } return ret; }
private static String formatAtomName(Atom a) { String fullName = null; String name = a.getName(); Element element = a.getElement(); // RULES FOR ATOM NAME PADDING: 4 columns in total: 13, 14, 15, 16 // if length 4: nothing to do if (name.length()==4) fullName = name; // if length 3: they stay at 14 else if (name.length()==3) fullName = " "+name; // for length 2 it depends: // carbon, oxygens, nitrogens, phosphorous stay at column 14 // elements with 2 letters (e.g. NA, FE) will go to column 13 else if (name.length()==2) { if (element == Element.C || element == Element.N || element == Element.O || element == Element.P || element == Element.S) fullName = " "+name+" "; else fullName = name+" "; } // for length 1 (e.g. K but also C, O) they stay in column 14 else if (name.length()==1) fullName = " "+name+" "; //if (fullName.length()!=4) // logger.warn("Atom name "+fullName+"to be written in PDB format does not have length 4. Formatting will be incorrect"); return fullName; }
/** * Copies the first length atoms from the input array * @param ca The array to copy * @param length the number of atoms to copy * @param clone If true, preform a deep copy, cloning the underlying Groups * @return An array with the first length items of ca, possibly cloning the Atoms. * @throws StructureException */ private Atom[] getAtoms(Atom[] ca, int length, boolean clone) throws StructureException{ List<Atom> atoms = new ArrayList<Atom>(); for ( int i = 0 ; i < length ; i++){ Atom a; if ( clone ){ Group g = (Group)ca[i].getGroup().clone(); a = g.getAtom(ca[i].getName()); } else { a = ca[i]; } atoms.add(a); } return atoms.toArray(new Atom[atoms.size()]); }
/** * Copies the first length atoms from the input array * @param ca The array to copy * @param length the number of atoms to copy * @param clone If true, preform a deep copy, cloning the underlying Groups * @return An array with the first length items of ca, possibly cloning the Atoms. * @throws StructureException */ private Atom[] getAtoms(Atom[] ca, int length, boolean clone) throws StructureException{ List<Atom> atoms = new ArrayList<Atom>(); for ( int i = 0 ; i < length ; i++){ Atom a; if ( clone ){ Group g = (Group)ca[i].getGroup().clone(); a = g.getAtom(ca[i].getName()); } else { a = ca[i]; } atoms.add(a); } return atoms.toArray(new Atom[atoms.size()]); }
/** set the Atoms for a particular residue position. * Requires that atom.getParent returns the correct group! * take care during cloning of atoms. Best to use StructureTools.cloneCaAtoms(); * * @param strBuf * @param i * @param ca * @param j */ private void setStrBuf(Atom[] strBuf, int i, Atom[] ca, int j) { // TODO Auto-generated method stub //TODO Group parent = ca[j].getGroup(); int pos = 0; String atomName = ca[j].getName(); Atom a = null; a= parent.getAtom(atomName); if ( a != null){ strBuf[i]=a; } else { // probably a GLY and no CB was found... //e.printStackTrace(); } strBuf[i+pos] = a; pos++; }
/** * {@inheritDoc} */ @Override public void addAtom(Atom atom){ atom.setGroup(this); atoms.add(atom); // TODO this check is useless, coords are always !=null since they are initialized to 0,0,0 in AtomImpl constructor. We need to review this - JD 2016-09-14 if (atom.getCoordsAsPoint3d() != null){ // we have got coordinates! setPDBFlag(true); } if (atomNameLookup != null){ Atom existingAtom = atomNameLookup.put(atom.getName(), atom); // if an atom with same name is added to the group that has to be some kind of problem, // we need to warn properly if (existingAtom != null) { String altLocStr = ""; char altLoc = atom.getAltLoc(); if (altLoc != ' ') altLocStr = "(alt loc '" + altLoc + "')"; logger.warn("An atom with name " + atom.getName() + " " + altLocStr + " is already present in group: " + this.toString() + ". The atom with serial " + atom.getPDBserial() + " will be ignored in look-ups."); } } };
/** set the Atoms for a particular residue position. * Requires that atom.getParent returns the correct group! * take care during cloning of atoms. Best to use StructureTools.cloneCaAtoms(); * * @param strBuf * @param i * @param ca * @param j */ private void setStrBuf(Atom[] strBuf, int i, Atom[] ca, int j) { // TODO Auto-generated method stub //TODO Group parent = ca[j].getGroup(); int pos = 0; String atomName = ca[j].getName(); Atom a = null; a= parent.getAtom(atomName); if ( a != null){ strBuf[i]=a; } else { // probably a GLY and no CB was found... //e.printStackTrace(); } strBuf[i+pos] = a; pos++; }
/** * Check to see if a Hydrogen has a Deuterated brother in the group. * @param atom the input atom that is putatively hydorgen * @param currentGroup the group the atom is in * @return true if the atom is hydrogen and it's Deuterium equiv exists. */ public static boolean hasDeuteratedEquiv(Atom atom, Group currentGroup) { if(atom.getElement()==Element.H && currentGroup.hasAtom(replaceFirstChar(atom.getName(),'H', 'D'))) { // If it's hydrogen and has a deuterated brother return true; } return false; }
/** * Check to see if an Deuterated atom has a non deuterated brother in the group. * @param atom the input atom that is putatively deuterium * @param currentGroup the group the atom is in * @return true if the atom is deuterated and it's hydrogen equive exists. */ public static boolean hasNonDeuteratedEquiv(Atom atom, Group currentGroup) { if(atom.getElement()==Element.D && currentGroup.hasAtom(replaceFirstChar(atom.getName(),'D', 'H'))) { // If it's deuterated and has a non-deuterated brother return true; } return false; }
try{ PDBFileReader read=new PDBFileReader(); Structure pdb=read.getStructure(filename); System.out.println("PDB code :"+pdb.getPDBCode()); List chains=Collections.synchronizedList(new ArrayList()); chains=pdb.getChains(); for(Iterator iter=chains.iterator();iter.hasNext();){ Chain c=(Chain)(iter.next()); System.out.println("Chain :"+c.getName()+"\n"+"Seq aa :"+c.getAtomSequence()); for(int j=0;j<c.getAtomLength();j++){ for (int k=0; k < c.getAtomGroup(j).size(); k++ ){ Atom a=c.getAtomGroup(j).getAtom(k); System.out.println("Name : "+a.getName()+" X : "+a.getX()+" Y : "+a.getY()+" Z : "+a.getZ()); } }
private void rot_mol(Atom[] caA, Atom[] caB, int nse2, Matrix m , Atom shift) throws StructureException{ for(int l=0; l<nse2; l++) { Atom a = caA[l]; Group g = (Group)a.getGroup().clone(); //Group g = (Group)a.getParent(); Calc.rotate( g, m); Calc.shift( g, shift); caB[l] = g.getAtom(a.getName()); } }
private void rot_mol(Atom[] caA, Atom[] caB, int nse2, Matrix m , Atom shift) throws StructureException{ for(int l=0; l<nse2; l++) { Atom a = caA[l]; Group g = (Group)a.getGroup().clone(); //Group g = (Group)a.getParent(); Calc.rotate( g, m); Calc.shift( g, shift); caB[l] = g.getAtom(a.getName()); } }
/** * * @param atom a {@link Atom} in structure. * @param isParentAminoAcid true if the containing group is an amino acid. * @return the {@link StructureAtom} of the atom. */ public static StructureAtom getStructureAtom(Atom atom, boolean isParentAminoAcid) { Group g = atom.getGroup(); String chainId = g.getChainId(); StructureGroup strucGroup = getStructureGroup(g, isParentAminoAcid); strucGroup.setChainId(chainId); return new StructureAtom(strucGroup, atom.getName()); }
logger.warn("Unrecognised atom "+atom.getName()+" with serial "+atom.getPDBserial()+ ", assigning the default vdw radius (Nitrogen vdw radius)."); return Element.N.getVDWRadius(); logger.warn("Unknown parent residue for atom "+atom.getName()+" with serial "+ atom.getPDBserial()+", assigning its default vdw radius"); return atom.getElement().getVDWRadius();
/** create a new residue which is of the new type. * Only the atoms N, Ca, C, O, Cb will be considered. * @param oldAmino * @param newType * @return a new, mutated, residue * @throws PDBParseException */ public AminoAcid mutateResidue(AminoAcid oldAmino, String newType) throws PDBParseException { AminoAcid newgroup = new AminoAcidImpl(); newgroup.setResidueNumber(oldAmino.getResidueNumber()); newgroup.setPDBName(newType); AtomIterator aiter =new AtomIterator(oldAmino); while (aiter.hasNext()){ Atom a = aiter.next(); if ( supportedAtoms.contains(a.getName())){ newgroup.addAtom(a); } } return newgroup; }
/** * Gets the radius for given nucleotide atom * @param atom * @return */ private static double getRadiusForNucl(NucleotideImpl nuc, Atom atom) { if (atom.getElement().equals(Element.H)) return Element.H.getVDWRadius(); if (atom.getElement().equals(Element.D)) return Element.D.getVDWRadius(); if (atom.getElement()==Element.C) return NUC_CARBON_VDW; if (atom.getElement()==Element.N) return NUC_NITROGEN_VDW; if (atom.getElement()==Element.P) return PHOSPHOROUS_VDW; if (atom.getElement()==Element.O) return OXIGEN_VDW; logger.info("Unexpected atom "+atom.getName()+" for nucleotide "+nuc.getPDBName()+", assigning its standard vdw radius"); return atom.getElement().getVDWRadius(); }
/** * Cleans up the structure's alternate location (altloc) groups. All alternate location groups should have all atoms (except * in the case of microheterogenity) or when a deuterium exists. * Ensure that all the alt loc groups have all the atoms in the main group. * @param structure The Structure to be cleaned up */ public static void cleanUpAltLocs(Structure structure) { for (int i =0; i< structure.nrModels() ; i++){ for (Chain chain : structure.getModel(i)) { for (Group group : chain.getAtomGroups()) { for (Group altLocGroup : group.getAltLocs()) { for ( Atom groupAtom : group.getAtoms()) { // If this alt loc doesn't have this atom if (! altLocGroup.hasAtom(groupAtom.getName())) { // Fix for microheterogenity if (altLocGroup.getPDBName().equals(group.getPDBName())) { // If it's a Hydrogen then we check for it's Deuterated brother if(!hasDeuteratedEquiv(groupAtom, altLocGroup)){ altLocGroup.addAtom(groupAtom); } } } } } } } } }