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); } } } }
public static void main(String[] args){ Chain c = new ChainImpl(); c.setId("X"); Group g = new AminoAcidImpl(); g.setResidueNumber(ResidueNumber.fromString("1A")); try { g.setPDBName("ALA"); } catch (Exception e){} Atom a = new AtomImpl(); a.setName("CA"); g.addAtom(a); c.addGroup(g); System.out.println(getPdbInfo(a)); }
/** * 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); } } } } } } } } }
g1.addAtom(a); c1.addGroup(g1);