/** * Count how many Atoms are contained within a Structure object. * * @param s * the structure object * @return the number of Atoms in this Structure */ public static final int getNrAtoms(Structure s) { int nrAtoms = 0; Iterator<Group> iter = new GroupIterator(s); while (iter.hasNext()) { Group g = iter.next(); nrAtoms += g.size(); } return nrAtoms; }
/** * 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 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 ; }
/** Is there a next atom ? * @return true if there is an atom after the current one * */ @Override public boolean hasNext() { // trying to iterate over an empty structure... if ( group == null) return false; // if there is another group ... if ( current_atom_pos < group.size()-1 ) { return true ; } else { // search through the next groups if they contain an atom if (groupiter != null) { GroupIterator tmp = (GroupIterator) groupiter.clone() ; while (tmp.hasNext()) { Group tmpg = tmp.next() ; if ( tmpg.size() > 0 ) { return true ; } } } else { // just an iterator over one group ... return false ; } } return false ; }
int groupsize = g.size();
if ( g.size() == 1 ) {
if ( g == null ) continue; if ( g.size() < 1) continue; Atom a = g.getAtom(0);
/** 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; }
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); } } }
if ( g == null ) continue; if ( g.size() < 1) continue; Atom a = g.getAtom(0);