def ch(x, y): x = _convert(x) y = _convert(y) return g.CritAnd(c, mg.HasNeighbors(h, x, y))
def ipr(atom): at = _convert(atom) return g.CritAnd(c, mg.HasNeighbors(me(c), me(c), h, at))
# Dirty trick to silence warnings of confliciting # modules on the HPC cluster and to silence NumPy # warnings. with warnings.catch_warnings(): warnings.simplefilter('ignore') import molmod.graphs as g import molmod.molecular_graphs as mg h = mg.HasAtomNumber(1) c = mg.HasAtomNumber(6) n = mg.HasAtomNumber(7) o = mg.HasAtomNumber(8) s = mg.HasAtomNumber(16) p = mg.HasAtomNumber(15) csp3 = g.CritAnd(c, mg.HasNumNeighbors(4)) csp2 = g.CritAnd(c, mg.HasNumNeighbors(3)) csp = g.CritAnd(c, mg.HasNumNeighbors(2)) def _convert(atom): try: return mg.HasAtomNumber(utils.anum(atom)) except: return atom def me(atom): ''' at can be 'C', 'c', 6 or a pattern '''
def me(atom): ''' at can be 'C', 'c', 6 or a pattern ''' at = _convert(atom) return g.CritAnd(mg.HasNeighbors(h, h, h, at), c)
def _classify(self): p = OrderedDict() self.geometry.initiate_match() p['ph'] = gr.CritAnd(c, g.HasNeighbors(c, c, c)) self.geometry.set_matches(p) if self.nucleophile == 'OPh': # find the O just to check which ph was parsed self.geometry.set_match('o', o) # wrong phenyl group selected, select the other one if self.geometry.dist(self.geometry.ph.n, self.geometry.o.n) < 3.0: self.geometry.set_match('ph', gr.CritAnd(c, g.HasNeighbors(c, c, c))) # remove phenyl group to speed up pattern searching phgroup = self.geometry.closest(6, self.geometry.ph.n, n=2) phgroup += [ self.geometry.closest(6, i, exclude=[self.geometry.ph.n]) for i in phgroup ] phgroup += [self.geometry.closest(6, phgroup[-1], exclude=phgroup)] logging.debug('SixThreeBicyclic._classify(): phenyl group %s' % (phgroup + [self.geometry.ph.n])) for i in phgroup: self.geometry.unparsed.remove(i) self.geometry.set_match( 'c7', self.geometry.closest(6, self.geometry.ph.n, only=self.geometry.unparsed)) self.geometry.set_match( 'me', self.geometry.closest(6, self.geometry.c7.n, only=self.geometry.unparsed)) self.geometry.set_match( 'nplus', self.geometry.closest(7, self.geometry.c7.n, only=self.geometry.unparsed)) nplus = gr.CritAnd( n, gr.CritOr(g.HasNeighbors(c, c, c, c), g.HasNeighbors(c, c, c))) c_nextto_nplus = g.HasNeighbors(nplus, h, h, c) p['c2'] = g.HasNeighbors(c_nextto_nplus, h, h, c) p['c3'] = g.HasNeighbors(p['c2'], h, h, c) p['c4'] = g.HasNeighbors(p['c3'], h, h, c) p['c1'] = g.HasNeighbors(nplus, h, h, p['c2']) self.geometry.set_matches(p) self.geometry.set_match( 'c5', self.geometry.closest(6, self.geometry.c4.n, only=self.geometry.unparsed)) self.geometry.set_match( 'c6', self.geometry.closest(6, self.geometry.nplus.n, only=self.geometry.unparsed)) if self.attacking_atom: self.geometry.set_match( 'nu', self.geometry.closest(self.attacking_atom, self.geometry.c5.n, only=self.geometry.unparsed)) else: logging.debug( 'SixThreeBicyclic._classify(): nu not parsed, since no nucleophile was found.' )