private Atom getAtom(String atomId, Group group) { Atom a = group.getAtom(atomId); // Check for deuteration if(a==null && atomId.startsWith("H")) { a = group.getAtom(atomId.replaceFirst("H", "D")); // Check it is actually deuterated if(a!=null){ if(!a.getElement().equals(Element.D)){ a=null; } } } return a; }
@Override public Group getAltLocGroup(Character altLoc) { Atom a = getAtom(0); if ( a == null) { return null; } // maybe the alt loc group in question is myself if (a.getAltLoc().equals(altLoc)) { return this; } if (altLocs == null || altLocs.isEmpty()) return null; for (Group group : altLocs) { if (group.getAtoms().isEmpty()) continue; // determine this group's alt-loc character code by looking // at its first atom's alt-loc character Atom b = group.getAtom(0); if ( b == null) continue; if (b.getAltLoc().equals(altLoc)) { return group; } } return null; }
/** * 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()]); }
/** * Returns the first atom for each group * @param ca * @param hetatms * @return * @throws StructureException */ public static final Atom[] getAtomArray(Atom[] ca,List<Group> hetatms ) throws StructureException{ List<Atom> atoms = new ArrayList<Atom>(); Collections.addAll(atoms, ca); logger.debug("got {} hetatoms", hetatms.size()); // we only add atom nr 1, since the getAlignedStructure method actually adds the parent group, and not the atoms... for (Group g : hetatms){ if (g.size() < 1) continue; //if (debug) // System.out.println("adding group " + g); Atom a = g.getAtom(0); //if (debug) // System.out.println(a); a.setGroup(g); atoms.add(a); } Atom[] arr = atoms.toArray(new Atom[atoms.size()]); return arr; }
/** * 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()]); }
/** * 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()]); }
private Atom getCBeta(Group g1) { Atom cb = null; cb = g1.getAtom("CB"); if ( cb == null) { if ( g1 instanceof AminoAcid) { AminoAcid aa = (AminoAcid) g1; try { cb = Calc.createVirtualCBAtom(aa); } catch (StructureException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } return cb; }
/** * 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++; }
protected void cloneAtomsAndBonds(Group newGroup) { // copy the atoms for (Atom atom1 : atoms) { Atom atom = (Atom) atom1.clone(); newGroup.addAtom(atom); atom.setGroup(newGroup); } // copy the bonds for (int i=0;i<atoms.size();i++) { Atom atom1 = atoms.get(i); List<Bond> bonds1 = atom1.getBonds(); if (bonds1 != null) { for (Bond b : bonds1) { int atomAIndex = atoms.indexOf(b.getAtomA()); int atomBIndex = atoms.indexOf(b.getAtomB()); // The order of the atoms are the same on the original and the cloned object, which we use here. Bond newBond = new BondImpl(newGroup.getAtom(atomAIndex), newGroup.getAtom(atomBIndex), b.getBondOrder(), false); newGroup.getAtom(i).addBond(newBond); } } } }
/** 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++; }
private Map<Integer,Atom> getAtomFromRecord(String name, String altLoc, String resName, String chainID, String resSeq, String iCode) throws StructureException { if (iCode==null || iCode.isEmpty()) { iCode = " "; // an insertion code of ' ' is ignored } Map<Integer, Atom> outMap = new HashMap<>(); ResidueNumber resNum = new ResidueNumber(chainID, Integer.parseInt(resSeq), iCode.charAt(0)); for (int i=0; i<structure.nrModels(); i++){ Chain chain = structure.getChain(chainID,i); Group group = chain.getGroupByPDB(resNum); Group g = group; // there is an alternate location if (!altLoc.isEmpty()) { g = group.getAltLocGroup(altLoc.charAt(0)); if (g==null) throw new StructureException("Could not find altLoc code "+altLoc+" in group "+resSeq+iCode+" of chain "+ chainID); } Atom a = g.getAtom(name); if (a!=null){ outMap.put(i,a); } } return outMap; } }
/** Return next atom. * * @return the next Atom * @throws NoSuchElementException if there is no atom after the current one */ @Override public Atom next() throws NoSuchElementException { current_atom_pos++ ; if ( current_atom_pos >= group.size() ) { if ( groupiter == null ) { throw new NoSuchElementException("no more atoms found in group!"); } if ( groupiter.hasNext() ) { group = groupiter.next() ; current_atom_pos = -1 ; return next(); } else { throw new NoSuchElementException("no more atoms found in structure!"); } } Atom a ; a = group.getAtom(current_atom_pos); if ( a == null) { logger.error("current_atom_pos {} group {} size: {}", current_atom_pos, group, group.size()); throw new NoSuchElementException("error wile trying to retrieve atom"); } return a ; }
Atom a = g.getAtom(atompos); if ( a == null) continue ;
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()); } }
if ( g.size() < 1) continue; Atom a = g.getAtom(0); twistedAs.add(a);
private static void toPDB(Group g, StringBuffer str) { // iterate over all atoms ... // format output ... int groupsize = g.size(); for ( int atompos = 0 ; atompos < groupsize; atompos++) { Atom a = null ; a = g.getAtom(atompos); if ( a == null) continue ; toPDB(a, str); //line = record + serial + " " + fullname +altLoc //+ leftResName + " " + chainID + resseq //+ " " + x+y+z //+ occupancy + tempfactor; //str.append(line + newline); //System.out.println(line); } if ( g.hasAltLoc()){ for (Group alt : g.getAltLocs() ) { toPDB(alt,str); } } }
/** Note: ca2, hetatoms2 and nucleotides2 should not be rotated. This will be done here... * */ public static final StructureAlignmentJmol display(AFPChain afpChain,Group[] twistedGroups, Atom[] ca1, Atom[] ca2,List<Group> hetatms1, List<Group> hetatms2 ) throws StructureException { 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 = twistedAs.toArray(new Atom[twistedAs.size()]); twistedAtoms = StructureTools.cloneAtomArray(twistedAtoms); Atom[] arr1 = getAtomArray(ca1, hetatms1); Atom[] arr2 = getAtomArray(twistedAtoms, hetatms2); // //if ( hetatms2.size() > 0) // System.out.println("atom after:" + hetatms2.get(0).getAtom(0)); //if ( hetatms2.size() > 0) // System.out.println("atom after:" + hetatms2.get(0).getAtom(0)); String title = afpChain.getAlgorithmName() + " V." +afpChain.getVersion() + " : " + afpChain.getName1() + " vs. " + afpChain.getName2(); //System.out.println(artificial.toPDB()); StructureAlignmentJmol jmol = new StructureAlignmentJmol(afpChain,arr1,arr2); //jmol.setStructure(artificial); System.out.format("CA2[0]=(%.2f,%.2f,%.2f)%n", arr2[0].getX(), arr2[0].getY(), arr2[0].getZ()); //jmol.setTitle("Structure Alignment: " + afpChain.getName1() + " vs. " + afpChain.getName2()); jmol.setTitle(title); return jmol; }