File: testSCSR.py

package info (click to toggle)
rdkit 202503.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 222,000 kB
  • sloc: cpp: 411,111; python: 78,482; ansic: 26,181; java: 8,285; javascript: 4,404; sql: 2,393; yacc: 1,626; lex: 1,267; cs: 1,090; makefile: 581; xml: 229; fortran: 183; sh: 121
file content (121 lines) | stat: -rw-r--r-- 4,071 bytes parent folder | download | duplicates (2)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#
#  Copyright (C) 2024 Tad Hurst
#         All Rights Reserved
#
#  This file is part of the RDKit.
#  The contents are covered by the terms of the BSD license
#  which is included in the file license.txt, found at the root
#  of the RDKit source tree.
#

#
import os
import sys
import unittest

from rdkit import Chem
from rdkit.Chem import RDConfig


class TestCase(unittest.TestCase):

  def setUp(self):
    pass

  def testSCSR(self):
    """Test the SCSR system"""

    ofile = os.path.join(RDConfig.RDBaseDir, 'Code', 'GraphMol', 'FileParsers', 'test_data',
                         'macromols', 'Triplet.mol')
    with open(ofile) as inf:
      scsrBlock = inf.read()

    molFromSCSRParams = Chem.MolFromSCSRParams()
    molFromSCSRParams.includeLeavingGroups = True
    molFromSCSRParams.scsrTemplateNames = Chem.SCSRTemplateNames.AsEntered
    molFromSCSRParams.scsrBaseHbondOptions = Chem.SCSRBaseHbondOptions.Ignore

    for mol in (Chem.MolFromSCSRBlock(scsrBlock, False, False, molFromSCSRParams),
                Chem.MolFromSCSRFile(ofile, False, False, molFromSCSRParams)):

      self.assertTrue(mol.GetNumAtoms() == 30)
      sgs = Chem.GetMolSubstanceGroups(mol)
      self.assertEqual(len(sgs), 6)

    # check defaults:
    for mol in (Chem.MolFromSCSRBlock(scsrBlock), Chem.MolFromSCSRFile(ofile)):
      self.assertTrue(mol.GetNumAtoms() == 30)
      sgs = Chem.GetMolSubstanceGroups(mol)
      self.assertEqual(len(sgs), 6)

  def testSCSRRna(self):
    """Test the SCSR system with and RNA double strand"""

    ofile = os.path.join(RDConfig.RDBaseDir, 'Code', 'GraphMol', 'FileParsers', 'test_data',
                         'macromols', 'DnaTest.mol')
    with open(ofile) as inf:
      scsrBlock = inf.read()

    molFromSCSRParams = Chem.MolFromSCSRParams()
    molFromSCSRParams.includeLeavingGroups = True
    molFromSCSRParams.scsrTemplateNames = Chem.SCSRTemplateNames.AsEntered
    molFromSCSRParams.scsrBaseHbondOptions = Chem.SCSRBaseHbondOptions.Auto

    mol = Chem.MolFromSCSRBlock(scsrBlock, False, False, molFromSCSRParams)

    self.assertTrue(mol.GetNumAtoms() == 254)
    self.assertTrue(mol.GetNumBonds() == 300)
    sgs = Chem.GetMolSubstanceGroups(mol)
    self.assertTrue(len(sgs) == 38)

    molFromSCSRParams.scsrBaseHbondOptions = Chem.SCSRBaseHbondOptions.Ignore
    mol = Chem.MolFromSCSRBlock(scsrBlock, False, False, molFromSCSRParams)

    self.assertTrue(mol.GetNumAtoms() == 254)
    self.assertTrue(mol.GetNumBonds() == 282)
    sgs = Chem.GetMolSubstanceGroups(mol)
    self.assertTrue(len(sgs) == 38)

  def testThreeLetterCodes(self):
    """Test the SCSR system with three letter codes"""

    ofile = os.path.join(RDConfig.RDBaseDir, 'Code', 'GraphMol', 'FileParsers', 'test_data',
                         'macromols', 'PepTla.mol')
    with open(ofile) as inf:
      scsrBlock = inf.read()

    molFromSCSRParams = Chem.MolFromSCSRParams()
    molFromSCSRParams.includeLeavingGroups = True
    molFromSCSRParams.scsrTemplateNames = Chem.SCSRTemplateNames.AsEntered

    mol = Chem.MolFromSCSRBlock(scsrBlock, False, False, molFromSCSRParams)

    self.assertEqual(mol.GetNumAtoms(), 26)
    self.assertEqual(mol.GetNumBonds(), 25)
    sgs = Chem.GetMolSubstanceGroups(mol)
    self.assertTrue(len(sgs) == 7)
    sgs[0].GetProp('LABEL')
    self.assertEqual(sgs[0].GetProp('LABEL'), 'Ala_4')

    molFromSCSRParams.scsrTemplateNames = Chem.SCSRTemplateNames.UseFirstName

    mol = Chem.MolFromSCSRBlock(scsrBlock, False, False, molFromSCSRParams)

    self.assertEqual(mol.GetNumAtoms(), 26)
    sgs = Chem.GetMolSubstanceGroups(mol)
    self.assertEqual(len(sgs), 7)

    self.assertEqual(sgs[0].GetProp('LABEL'), 'Ala_4')

    molFromSCSRParams.scsrTemplateNames = Chem.SCSRTemplateNames.UseSecondName
    mol = Chem.MolFromSCSRBlock(scsrBlock, False, False, molFromSCSRParams)

    self.assertEqual(mol.GetNumAtoms(), 26)
    sgs = Chem.GetMolSubstanceGroups(mol)
    self.assertEqual(len(sgs), 7)

    self.assertEqual(sgs[0].GetProp('LABEL'), 'A_4')


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