VLib.NodeLib.demo

Package VLib :: Package NodeLib :: Module demo |
[hide private]
[frames] | no frames]

# Source Code for Module VLib.NodeLib.demo

     1  #  $Id: demo.py 2 2006-05-06 22:54:39Z glandrum $
     2  #
     3  #  Copyright (C) 2003 Rational Discovery LLC
     4  #     All Rights Reserved
     5  #
     6  import RDConfig
     7  import Chem,os.path
     8
     9  from VLib.NodeLib import *
    10  from VLib import Supply,Filter
    11
    12  # this would be a real input, from an sd file:
    13  #fName = os.path.join(RDConfig.RDCodeDir,'VLib','NodeLib','test_data','NCI_aids.10.dupes.sdf')
    14  #supplier = SDSupply.SDSupplyNode(fName)
    15  # instead though, we want a simpler input:
    16  smis = ['CCOC','CCO.Cl','CC(=O)[O-].[Na+]','CC[Cu]CC','OCC','C[N+](C)(C)C.[Cl-]',
    17          '[Na+].[Cl-]']
    18  mols = [Chem.MolFromSmiles(x) for x in smis]
    19  # name the molecules (only needed because we built them from smiles):
    20  for i in range(len(mols)):
    21    mols[i].SetProp('Name','Mol-%d'%(i+1))
    22  supplier = Supply.SupplyNode(contents=mols)
    23  # should be 7 here
    24  print 'initial:',len([x for x in supplier])
    25
    26  # filter out anything with a transition metal or lanthanide:
    27  metals = '[#21,#22,#23,#24,#25,#26,#27,#28,#29,#39,#40,#41,#42,#43,#44,#45,#46,#47,#57,#58,#59,#60,#61,#62,#63,#64,#65,#66,#67,#68,#69,#70,#71,#72,#73,#74,#75,#76,#77,#78,#79]'
    28  smaFilter= SmartsMolFilter.SmartsFilter(patterns=[metals],counts=[1])
    29  smaFilter.SetNegate(1)
    30  smaFilter.AddParent(supplier)
    31  # should be 6 here
    32  print 'post-smaFilter:',len([x for x in smaFilter])
    33
    34  salts = ['[Cl;H1&X1,-]','[Na+]','[O;H2,H1&-,X0&-2]']
    35  remover = SmartsRemover.SmartsRemover(patterns=salts)
    36  remover.AddParent(smaFilter)
    37  atsFilter = Filter.FilterNode(func=lambda x:x.GetNumAtoms()>1)
    38  atsFilter.AddParent(remover)
    39  # should be 5 here
    40  print 'post-remover:',len([x for x in atsFilter])
    41
    42  dupeFilter = SmilesDupeFilter.DupeFilter()
    43  dupeFilter.AddParent(atsFilter)
    44  # should be 4 here
    45  print 'post-dupes:',len([x for x in dupeFilter])
    46
    47
    48  import StringIO
    49  # a StringIO object acts like a file:
    50  io = StringIO.StringIO()
    51  output = SmilesOutput.OutputNode(dest=io,delim=', ',idField='Name')
    52  output.AddParent(dupeFilter)
    53  print 'post-output:',len([x for x in output])
    54  print 'OUTPUT:'
    55  print io.getvalue()
    56