private void trimBondLists() { for (int modelInd=0; modelInd<structure.nrModels(); modelInd++){ for (Chain chain : structure.getChains(modelInd)) { for (Group group : chain.getAtomGroups()) { for (Atom atom : group.getAtoms()) { if (atom.getBonds()!=null && atom.getBonds().size() > 0) { ((ArrayList<Bond>) atom.getBonds()).trimToSize(); } } } } } }
/** * Find the number of bonds in a group * @param atomsInGroup the list of atoms in the group * @return the number of atoms in the group */ public static int getNumBondsInGroup(List<Atom> atomsInGroup) { int bondCounter = 0; for(Atom atom : atomsInGroup) { if(atom.getBonds()==null){ continue; } for(Bond bond : atom.getBonds()) { // Now set the bonding information. Atom other = bond.getOther(atom); // If both atoms are in the group if (atomsInGroup.indexOf(other)!=-1){ Integer firstBondIndex = atomsInGroup.indexOf(atom); Integer secondBondIndex = atomsInGroup.indexOf(other); // Don't add the same bond twice if (firstBondIndex<secondBondIndex){ bondCounter++; } } } } return bondCounter; }
/** * Prints the connections in PDB style * * Rewritten since 5.0 to use {@link Bond}s * Will produce strictly one CONECT record per bond (won't group several bonds in one line) */ private String printPDBConnections(){ StringBuilder str = new StringBuilder(); for (Chain c:structure.getChains()) { for (Group g:c.getAtomGroups()) { for (Atom a:g.getAtoms()) { if (a.getBonds()!=null) { for (Bond b:a.getBonds()) { //7890123456789012345678901234567890123456789012345678901234567890 str.append(String.format("CONECT%5d%5d "+newline, b.getAtomA().getPDBserial(), b.getAtomB().getPDBserial())); } } } } } return str.toString(); }
/** * Adds this Bond to its atoms bond lists. If this method is not called, * then the list returned from calling {@link Atom#getBonds()} will not * include this bond. * <p> * If you created your Bond with the constructor * {@link #Bond(Atom, Atom, int)}, this method has already been called for * you and should not be called again. */ // TODO first check if those bonds haven't been made already private void addSelfToAtoms() { List<Bond> bonds = atomA.getBonds(); if (bonds==null) { bonds = new ArrayList<Bond>(AtomImpl.BONDS_INITIAL_CAPACITY); atomA.setBonds(bonds); } boolean exists = false; for (Bond bond : bonds) { // TODO is it equals() what we want here, or is it == ? - JD 2016-03-02 if (bond.getOther(atomA).equals(atomB)) { exists = true; break; } } if (!exists) { atomA.addBond(this); atomB.addBond(this); } }
String spaceEle = getSpace(4, a.getElement().toString()); atomList.append(spaceX+df.format(a.getX())+spaceY+df.format(a.getY())+spaceZ+df.format(a.getZ())+" "+a.getElement().toString()+spaceEle+"0 0 0 0 0 0 0 0 0 0 0 0\n"); for(Bond b: a.getBonds()){ Atom otherAtom = b.getOther(a); if(atoms.indexOf(otherAtom)>=atoms.indexOf(a)){
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); } } } }