parameters: (mol, allNodes=None, minFragmentSize=0, onlyUseReactions=None)
return_statement: return res
docstring: returns the recap decomposition for a molecule
docstring_summary: returns the recap decomposition for a molecule
docstring_tokens: returns the recap decomposition for a molecule
function: def RecapDecompose(mol, allNodes=None, minFragmentSize=0, onlyUseReactions=None):
      """ returns the recap decomposition for a molecule """
      mSmi = Chem.MolToSmiles(mol, 1)
  
      if allNodes is None:
          allNodes = {}
      if mSmi in allNodes:
          return allNodes[mSmi]
  
      res = RecapHierarchyNode(mol)
      res.smiles = mSmi
      activePool = {mSmi: res}
      allNodes[mSmi] = res
      while activePool:
          nSmi = next(iter(activePool))
          node = activePool.pop(nSmi)
          if not node.mol:
              continue
          for rxnIdx, reaction in enumerate(reactions):
              if onlyUseReactions and rxnIdx not in onlyUseReactions:
                  continue
              # print '  .',nSmi
              # print '         !!!!',rxnIdx,nSmi,reactionDefs[rxnIdx]
              ps = reaction.RunReactants((node.mol, ))
              # print '    ',len(ps)
              if ps:
                  for prodSeq in ps:
                      seqOk = True
                      # we want to disqualify small fragments, so sort the product sequence by size
                      # and then look for "forbidden" fragments
                      tSeq = [(prod.GetNumAtoms(onlyExplicit=True), idx)
                              for idx, prod in enumerate(prodSeq)]
                      tSeq.sort()
                      ts = [(x, prodSeq[y]) for x, y in tSeq]
                      prodSeq = ts
                      for nats, prod in prodSeq:
                          try:
                              Chem.SanitizeMol(prod)
                          except Exception:
                              continue
                          pSmi = Chem.MolToSmiles(prod, 1)
                          if minFragmentSize > 0:
                              nDummies = pSmi.count('*')
                              if nats - nDummies < minFragmentSize:
                                  seqOk = False
                                  break
                          # don't forget after replacing dummy atoms to remove any empty
                          # branches:
                          elif pSmi.replace('*', '').replace('()', '') in ('', 'C', 'CC', 'CCC'):
                              seqOk = False
                              break
                          prod.pSmi = pSmi
                      if seqOk:
                          for nats, prod in prodSeq:
                              pSmi = prod.pSmi
                              # print '\t',nats,pSmi
                              if not pSmi in allNodes:
                                  pNode = RecapHierarchyNode(prod)
                                  pNode.smiles = pSmi
                                  pNode.parents[nSmi] = weakref.proxy(node)
                                  node.children[pSmi] = pNode
                                  activePool[pSmi] = pNode
                                  allNodes[pSmi] = pNode
                              else:
                                  pNode = allNodes[pSmi]
                                  pNode.parents[nSmi] = weakref.proxy(node)
                                  node.children[pSmi] = pNode
                          # print '                >>an:',allNodes.keys()
      return res
function_tokens: def RecapDecompose ( mol , allNodes = None , minFragmentSize = 0 , onlyUseReactions = None ) : mSmi = Chem . MolToSmiles ( mol , 1 ) if allNodes is None : allNodes = { } if mSmi in allNodes : return allNodes [ mSmi ] res = RecapHierarchyNode ( mol ) res . smiles = mSmi activePool = { mSmi : res } allNodes [ mSmi ] = res while activePool : nSmi = next ( iter ( activePool ) ) node = activePool . pop ( nSmi ) if not node . mol : continue for rxnIdx , reaction in enumerate ( reactions ) : if onlyUseReactions and rxnIdx not in onlyUseReactions : continue # print '  .',nSmi # print '         !!!!',rxnIdx,nSmi,reactionDefs[rxnIdx] ps = reaction . RunReactants ( ( node . mol , ) ) # print '    ',len(ps) if ps : for prodSeq in ps : seqOk = True # we want to disqualify small fragments, so sort the product sequence by size # and then look for "forbidden" fragments tSeq = [ ( prod . GetNumAtoms ( onlyExplicit = True ) , idx ) for idx , prod in enumerate ( prodSeq ) ] tSeq . sort ( ) ts = [ ( x , prodSeq [ y ] ) for x , y in tSeq ] prodSeq = ts for nats , prod in prodSeq : try : Chem . SanitizeMol ( prod ) except Exception : continue pSmi = Chem . MolToSmiles ( prod , 1 ) if minFragmentSize > 0 : nDummies = pSmi . count ( '*' ) if nats - nDummies < minFragmentSize : seqOk = False break # don't forget after replacing dummy atoms to remove any empty # branches: elif pSmi . replace ( '*' , '' ) . replace ( '()' , '' ) in ( '' , 'C' , 'CC' , 'CCC' ) : seqOk = False break prod . pSmi = pSmi if seqOk : for nats , prod in prodSeq : pSmi = prod . pSmi # print '\t',nats,pSmi if not pSmi in allNodes : pNode = RecapHierarchyNode ( prod ) pNode . smiles = pSmi pNode . parents [ nSmi ] = weakref . proxy ( node ) node . children [ pSmi ] = pNode activePool [ pSmi ] = pNode allNodes [ pSmi ] = pNode else : pNode = allNodes [ pSmi ] pNode . parents [ nSmi ] = weakref . proxy ( node ) node . children [ pSmi ] = pNode # print '                >>an:',allNodes.keys() return res