File: UnitTestSubstruct.py

package info (click to toggle)
rdkit 202503.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 578; xml: 229; fortran: 183; sh: 105
file content (101 lines) | stat: -rwxr-xr-x 2,714 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright (C) 2001 greg Landrum and Rational Discovery LLC
"""basic unit testing code for the substructure matching

"""
import os
import sys
import unittest

import RDConfig


class TestCase(unittest.TestCase):

  def setUp(self):
    #print '\n%s: '%self.shortDescription(),
    # decipher the name of the executable
    if (sys.platform == 'win32'):
      exe = 'SubstructTest2___Win32_Debug/SubstructTest2.exe'
    else:
      exe = 'test2'
    # update to use the full path
    self.basePath = '%s/Code/GraphMol/Substruct' % (RDConfig.RDBaseDir)
    self.exe = '%s/%s' % (self.basePath, exe)

    self.passStr = 'Got a match: \n'
    self.failStr = 'No match\n'

  def testAtomListPass(self):
    """ testing atom list matches which should pass """
    smis = [
      'C1=CC=CC=C1',
      'C1C=CC=CC=1',
      'N1=CC=CC=C1',
      'C1=NC=CC=C1',
      'C1=CN=CC=C1',
      'C1=CC=NC=C1',
      'C1=CC=CN=C1',
      'C1=CC=CC=N1',
      'P1=CC=CC=C1',
      'C1=PC=CC=C1',
      'C1=CP=CC=C1',
      'C1=CC=PC=C1',
      'C1=CC=CP=C1',
      'C1=CC=CC=P1',
      'C1=C(C)C=CC=C1',
      'C1C=C(CC)C=C(C)C=1',
    ]
    cdxFile = '%s/list-query.cdxml' % (self.basePath)
    for smi in smis:
      p = os.popen('%s %s "%s"' % (self.exe, cdxFile, smi), 'r')
      l = p.read()
      assert l.find(self.passStr) != -1, 'no match for (%s): %s' % (smi, l)

  def testAtomListFail(self):
    """ testing atom list matches which should fail """
    smis = [
      'C1CC=CC=C1',
      'c1ccccc1',
      'O1=CC=CC=C1',
      'C1=NC=CN=C1',
      'C1=CP=CO=C1',
    ]
    cdxFile = '%s/list-query.cdxml' % (self.basePath)
    for smi in smis:
      p = os.popen('%s %s "%s"' % (self.exe, cdxFile, smi), 'r')
      l = p.read()
      assert l.find(self.failStr) != -1, 'invalid match for (%s): %s' % (smi, l)

  def testBondListPass(self):
    """ testing bond list matches which should pass """
    smis = [
      'CCCC=C',
      'C=CCCC',
      'CC=CC=C',
      'C=CC=CC',
      'C1CCC=CC1',
      'C1CC=CC=C1'
      'C=CC=CCCCO',
      'CC=C(C=C)COC',
    ]
    cdxFile = '%s/bond-query.cdxml' % (self.basePath)
    for smi in smis:
      p = os.popen('%s %s "%s"' % (self.exe, cdxFile, smi), 'r')
      l = p.read()
      assert l.find(self.passStr) != -1, 'no match for (%s): %s' % (smi, l)

  def testBondListFail(self):
    """ testing bond list matches which should fail """
    smis = [
      'CCCCC',
      'C=COCC',
    ]
    cdxFile = '%s/bond-query.cdxml' % (self.basePath)
    for smi in smis:
      p = os.popen('%s %s "%s"' % (self.exe, cdxFile, smi), 'r')
      l = p.read()
      assert l.find(self.failStr) != -1, 'invalid match for (%s): %s' % (smi, l)


if __name__ == '__main__':
  unittest.main()