def doit(self, ats): """ Function to delete all the references to each atom of a AtomSet.""" # Remove the atoms of the molecule you are deleting from the # the AtomSet self.vf.allAtoms self.vf.allAtoms = self.vf.allAtoms - ats # If the current selection atmsInSel = self.vf.selection.findType(Atom)[:] atmsInSel.sort() ats.sort() # Call the updateGeoms function for all the command having an # updateGeom function molecules, atomSets = self.vf.getNodesByMolecule(ats) done = 0 event = DeleteAtomsEvent(objects=ats) self.vf.dispatchEvent(event) allAtoms = AtomSet([]) for mol, atSet in map(None, molecules, atomSets): if len(atSet)==len(mol.allAtoms): #have to add atoms back to allAtoms for deleteMol to work self.vf.allAtoms = self.vf.allAtoms + atSet self.vf.deleteMol.deleteMol(mol) #if this is the last atom, quit the loop if mol==molecules[-1]: done=1 break continue mol.allAtoms = mol.allAtoms - atSet allAtoms = allAtoms + atSet #FIRST remove any possible hbonds hbondAts = atSet.get(lambda x: hasattr(x, 'hbonds')) if hbondAts is not None: #for each atom with hbonds for at in hbondAts: if not hasattr(at, 'hbonds'): continue #remove each of its hbonds for b in at.hbonds: self.removeHBond(b) for at in atSet: for b in at.bonds: at2 = b.atom1 if at2 == at: at2 = b.atom2 at2.bonds.remove(b) at.parent.remove(at, cleanup=1) if len(atmsInSel): if atmsInSel == ats: # the current selection was deleted self.vf.clearSelection(topCommand=0) else: nodes = self.vf.selection lenSel = len(nodes) setClass = nodes.__class__ elementClass = nodes.elementType if lenSel>0: # this breaks if selectionlevel is Molecule, for instance # setClass = nodes.__class__ # newSel = setClass(nodes.findType(Atom) - ats) # newSel2 = setClass([]) newSel = atmsInSel-ats newSel2 = AtomSet([]) # may have ats which have been deleted everywhere else for at in newSel: if at in at.top.allAtoms: newSel2.append(at) if len(newSel2)!=lenSel: self.vf.clearSelection(topCommand=0) if len(newSel2): newSel2 = newSel2.findType(elementClass).uniq() self.vf.select(newSel2, topCommand=0) #this fixed a bug which occurred when only 1 molecule present #and cmd invoked with mv.deleteAtomSet(mv.Mols[0].allAtoms) if not done: for at in ats: del at self.vf.resetUndo(topCommand=0)
def doit(self, ats): """ Function to delete all the references to each atom of a AtomSet.""" # Remove the atoms of the molecule you are deleting from the # the AtomSet self.vf.allAtoms self.vf.allAtoms = self.vf.allAtoms - ats # If the current selection atmsInSel = self.vf.selection.findType(Atom)[:] atmsInSel.sort() ats.sort() # Call the updateGeoms function for all the command having an # updateGeom function molecules, atomSets = self.vf.getNodesByMolecule(ats) done = 0 event = DeleteAtomsEvent(objects=ats) self.vf.dispatchEvent(event) allAtoms = AtomSet([]) for mol, atSet in map(None, molecules, atomSets): if len(atSet) == len(mol.allAtoms): #have to add atoms back to allAtoms for deleteMol to work self.vf.allAtoms = self.vf.allAtoms + atSet self.vf.deleteMol.deleteMol(mol) #if this is the last atom, quit the loop if mol == molecules[-1]: done = 1 break continue mol.allAtoms = mol.allAtoms - atSet allAtoms = allAtoms + atSet #FIRST remove any possible hbonds hbondAts = atSet.get(lambda x: hasattr(x, 'hbonds')) if hbondAts is not None: #for each atom with hbonds for at in hbondAts: if not hasattr(at, 'hbonds'): continue #remove each of its hbonds for b in at.hbonds: self.removeHBond(b) atSetCopy = atSet.copy() #fixed bug#: 1143 for at in atSetCopy: for b in at.bonds: at2 = b.atom1 if at2 == at: at2 = b.atom2 at2.bonds.remove(b) if at.parent.children: at.parent.remove(at, cleanup=1) if len(atmsInSel): if atmsInSel == ats: # the current selection was deleted self.vf.clearSelection(topCommand=0, createEvents=False) else: nodes = self.vf.selection lenSel = len(nodes) setClass = nodes.__class__ elementClass = nodes.elementType if lenSel > 0: # this breaks if selectionlevel is Molecule, for instance # setClass = nodes.__class__ # newSel = setClass(nodes.findType(Atom) - ats) # newSel2 = setClass([]) newSel = atmsInSel - ats newSel2 = AtomSet([]) # may have ats which have been deleted everywhere else for at in newSel: if at in at.top.allAtoms: newSel2.append(at) if len(newSel2) != lenSel: self.vf.clearSelection(topCommand=0) if len(newSel2): newSel2 = newSel2.findType(elementClass).uniq() self.vf.select(newSel2, topCommand=0) # this fixes an exception that occured when the last chain was split # out of a ptrotein if not done: event = AfterDeleteAtomsEvent(objects=ats) self.vf.dispatchEvent(event) #this fixed a bug which occured when only 1 molecule present #and cmd invoked with mv.deleteAtomSet(mv.Mols[0].allAtoms) if not done: for at in ats: del at self.vf.resetUndo(topCommand=0)