/** * {@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; } }
private static Atom[] getAtoms(Atom[] ca, int[] positions, int length, boolean clone) { List<Atom> atoms = new ArrayList<Atom>(); for (int i = 0; i < length; i++) { int p = positions[i]; Atom a; if (clone) { a = (Atom) ca[p].clone(); a.setGroup((Group) ca[p].getGroup().clone()); } else { a = ca[p]; } atoms.add(a); } 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; }
/** * {@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."); } } };
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); } } } }