コード例 #1
0
ファイル: UnitTestVLib.py プロジェクト: yinxx/rdkit
 def test_FilterNode(self):
   filt = Filter.FilterNode(func=lambda a, b: a + b < 5)
   suppl1 = Supply.SupplyNode(contents=[1, 2, 3, 3])
   suppl2 = Supply.SupplyNode(contents=[1, 2, 3, 1])
   filt.AddParent(suppl1)
   filt.AddParent(suppl2)
   self.assertEqual([x for x in filt], [(1, 1), (2, 2), (3, 1)])
   filt.reset()
   self.assertEqual(filt.Negate(), False)
   filt.SetNegate(True)
   self.assertEqual(filt.Negate(), True)
   self.assertEqual([x for x in filt], [(3, 3), ])
   filt.Destroy()
コード例 #2
0
ファイル: UnitTestVLib.py プロジェクト: yinxx/rdkit
  def test_OutputNode(self):
    supplier1 = Supply.SupplyNode(contents=[1, 2, 3])
    supplier2 = Supply.SupplyNode(contents=['a', 'b', 'c'])

    sio = StringIO()
    node = Output.OutputNode(dest=sio, strFunc=lambda x: '{0[0]}-{0[1]} '.format(x))
    node.AddParent(supplier1)
    node.AddParent(supplier2)
    result = list(s for s in node)
    self.assertEqual(result, [(1, 'a'), (2, 'b'), (3, 'c')])
    self.assertEqual(sio.getvalue(), '1-a 2-b 3-c ')

    sio = StringIO()
    node = Output.OutputNode(dest=sio)
    node.AddParent(supplier1)
    result = list(s for s in node)
    self.assertEqual(result, [1, 2, 3])
    self.assertEqual(sio.getvalue(), '123')
コード例 #3
0
ファイル: UnitTestVLib.py プロジェクト: yinxx/rdkit
  def test_SupplyNode(self):
    supplier = Supply.SupplyNode()
    self.assertEqual(supplier._contents, [])

    supplier = Supply.SupplyNode(contents=[1, 2, 3])
    self.assertRaises(ValueError, supplier.AddParent, None)
コード例 #4
0
ファイル: demo.py プロジェクト: yinxx/rdkit
from rdkit.VLib.NodeLib import *
from rdkit.VLib import Supply, Filter

# this would be a real input, from an sd file:
#fName = os.path.join(RDConfig.RDCodeDir,'VLib','NodeLib','test_data','NCI_aids.10.dupes.sdf')
#supplier = SDSupply.SDSupplyNode(fName)
# instead though, we want a simpler input:
smis = [
    'CCOC', 'CCO.Cl', 'CC(=O)[O-].[Na+]', 'CC[Cu]CC', 'OCC',
    'C[N+](C)(C)C.[Cl-]', '[Na+].[Cl-]'
]
mols = [Chem.MolFromSmiles(x) for x in smis]
# name the molecules (only needed because we built them from smiles):
for i in range(len(mols)):
    mols[i].SetProp('Name', 'Mol-%d' % (i + 1))
supplier = Supply.SupplyNode(contents=mols)
# should be 7 here
print('initial:', len([x for x in supplier]))

# filter out anything with a transition metal or lanthanide:
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]'
smaFilter = SmartsMolFilter.SmartsFilter(patterns=[metals], counts=[1])
smaFilter.SetNegate(1)
smaFilter.AddParent(supplier)
# should be 6 here
print('post-smaFilter:', len([x for x in smaFilter]))

salts = ['[Cl;H1&X1,-]', '[Na+]', '[O;H2,H1&-,X0&-2]']
remover = SmartsRemover.SmartsRemover(patterns=salts)
remover.AddParent(smaFilter)
atsFilter = Filter.FilterNode(func=lambda x: x.GetNumAtoms() > 1)