def removeNeighbors(self, atDict): #filter out at-itself and at-bondedat up to 1:4 #NB keys could be hydrogens OR donors for at in atDict.keys(): closeAts = atDict[at] bondedAts = AtomSet([]) for b in at.bonds: ###at2 = b.neighborAtom(at) at2 = b.atom1 if id(at2) == id(at): at2 = b.atom2 bondedAts.append(at2) #9/13 remove this: ##also remove 1-3 for b2 in at2.bonds: at3 = b2.atom1 if id(at3) == id(at2): at3 = b.atom2 #at3 = b2.neighborAtom(at2) if id(at3) != id(at): bondedAts.append(at3) #for b3 in at3.bonds: #at4 = b2.neighborAtom(at3) #if at4!=at and at4!=at2: #bondedAts.append(at4) bondedAts = bondedAts.uniq() goodAts = [] for i in range(len(closeAts)): cAt = closeAts[i] if cAt not in bondedAts: goodAts.append(cAt) if len(goodAts): atDict[at] = goodAts else: del atDict[at] return atDict
def removeNeighbors(self, atDict): #filter out at-itself and at-bondedat up to 1:4 #NB keys could be hydrogens OR donors for at in atDict.keys(): closeAts = atDict[at] bondedAts = AtomSet([]) for b in at.bonds: ###at2 = b.neighborAtom(at) at2 = b.atom1 if id(at2)==id(at): at2 = b.atom2 bondedAts.append(at2) #9/13 remove this: ##also remove 1-3 for b2 in at2.bonds: at3 = b2.atom1 if id(at3)==id(at2): at3 = b.atom2 #at3 = b2.neighborAtom(at2) if id(at3)!=id(at): bondedAts.append(at3) #for b3 in at3.bonds: #at4 = b2.neighborAtom(at3) #if at4!=at and at4!=at2: #bondedAts.append(at4) bondedAts = bondedAts.uniq() goodAts = [] for i in range(len(closeAts)): cAt = closeAts[i] if cAt not in bondedAts: goodAts.append(cAt) if len(goodAts): atDict[at] = goodAts else: del atDict[at] return atDict
def setAromaticCarbons(self, molecule, cutoff=None, debug=False): assert len(molecule.allAtoms.bonds[0]) if cutoff: if cutoff != self.cutoff: old_aromCs = molecule.allAtoms.get(lambda x:\ (x.element=='C' and x.autodock_element=='A')) if old_aromCs is not None and len(old_aromCs) != 0: if debug: print "resetting ", len(old_aromCs), " prior aromCs" self.set_carbon_names(old_aromCs, 'C') self.cutoff = cutoff typed_atoms = molecule.allAtoms.get( lambda x: hasattr(x, 'autodock_element')) currentAromCs = AtomSet() if typed_atoms is not None and len(typed_atoms) == len( molecule.allAtoms): currentAromCs = molecule.allAtoms.get( lambda x: (x.element == 'C' and x.autodock_element == 'A')) if debug: if currentAromCs is not None and len(currentAromCs): print "now: ", len(currentAromCs) else: print "now: no aromCs" aromBnds = self.aromBndSel.select(molecule.allAtoms.bonds[0], self.cutoff) aromBndAts = self.aromBndSel.getAtoms(aromBnds) result = AtomSet() changed = AtomSet() if len(aromBndAts): aromCs = AtomSet(filter(lambda x: x.element=='C', \ aromBndAts)) aromCs = aromCs.uniq() if len(aromCs) > len(result): result = aromCs if debug: print "len(aromCs)=", len(aromCs) changed = self.set_carbon_names(aromCs, 'A') #if len(changed)>len(result): # result = changed #return result return changed
def setAromaticCarbons(self, molecule, cutoff=None, debug=False): assert len(molecule.allAtoms.bonds[0]) if cutoff: if cutoff!=self.cutoff: old_aromCs = molecule.allAtoms.get(lambda x:\ (x.element=='C' and x.autodock_element=='A')) if old_aromCs is not None and len(old_aromCs)!=0: if debug: print "resetting ", len(old_aromCs), " prior aromCs" self.set_carbon_names(old_aromCs, 'C') self.cutoff = cutoff typed_atoms = molecule.allAtoms.get(lambda x: hasattr(x, 'autodock_element')) currentAromCs = AtomSet() if typed_atoms is not None and len(typed_atoms)==len(molecule.allAtoms): currentAromCs = molecule.allAtoms.get(lambda x: (x.element=='C' and x.autodock_element=='A')) if debug: if currentAromCs is not None and len(currentAromCs): print "now: ", len(currentAromCs) else: print "now: no aromCs" aromBnds = self.aromBndSel.select(molecule.allAtoms.bonds[0], self.cutoff) aromBndAts = self.aromBndSel.getAtoms(aromBnds) result = AtomSet() changed = AtomSet() if len(aromBndAts): aromCs = AtomSet(filter(lambda x: x.element=='C', \ aromBndAts)) aromCs = aromCs.uniq() if len(aromCs)>len(result): result = aromCs if debug: print "len(aromCs)=", len(aromCs) changed = self.set_carbon_names(aromCs, 'A') #if len(changed)>len(result): # result = changed #return result return changed