chython 2.4__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. chython/__init__.py +31 -0
  2. chython/_functions.py +69 -0
  3. chython/algorithms/__init__.py +18 -0
  4. chython/algorithms/_isomorphism.cp312-win_amd64.pyd +0 -0
  5. chython/algorithms/_isomorphism.pyx +189 -0
  6. chython/algorithms/aromatics/__init__.py +27 -0
  7. chython/algorithms/aromatics/_rules.py +124 -0
  8. chython/algorithms/aromatics/kekule.py +530 -0
  9. chython/algorithms/aromatics/test/__init__.py +18 -0
  10. chython/algorithms/aromatics/test/test_kekule.py +160 -0
  11. chython/algorithms/aromatics/test/test_thiele.py +263 -0
  12. chython/algorithms/aromatics/thiele.py +226 -0
  13. chython/algorithms/calculate2d/__init__.py +23 -0
  14. chython/algorithms/calculate2d/clean2d.js +1 -0
  15. chython/algorithms/calculate2d/molecule.py +149 -0
  16. chython/algorithms/calculate2d/reaction.py +80 -0
  17. chython/algorithms/depict.py +523 -0
  18. chython/algorithms/fingerprints/__init__.py +48 -0
  19. chython/algorithms/fingerprints/linear.py +208 -0
  20. chython/algorithms/fingerprints/morgan.py +137 -0
  21. chython/algorithms/fingerprints/test/__init__.py +18 -0
  22. chython/algorithms/fingerprints/test/test_linear.py +127 -0
  23. chython/algorithms/fingerprints/test/test_morgan.py +79 -0
  24. chython/algorithms/isomorphism.py +667 -0
  25. chython/algorithms/mapping/__init__.py +28 -0
  26. chython/algorithms/mapping/_groups.py +94 -0
  27. chython/algorithms/mapping/_reactions.py +72 -0
  28. chython/algorithms/mapping/attention.py +216 -0
  29. chython/algorithms/mapping/fixmapper.py +84 -0
  30. chython/algorithms/mapping/groups.py +137 -0
  31. chython/algorithms/mcs.py +202 -0
  32. chython/algorithms/morgan.py +82 -0
  33. chython/algorithms/rings.py +551 -0
  34. chython/algorithms/smiles.py +556 -0
  35. chython/algorithms/standardize/__init__.py +30 -0
  36. chython/algorithms/standardize/_charged.py +115 -0
  37. chython/algorithms/standardize/_groups.py +926 -0
  38. chython/algorithms/standardize/_metal_organics.py +189 -0
  39. chython/algorithms/standardize/_reagents.py +44 -0
  40. chython/algorithms/standardize/_salts.py +68 -0
  41. chython/algorithms/standardize/molecule.py +479 -0
  42. chython/algorithms/standardize/reaction.py +429 -0
  43. chython/algorithms/standardize/resonance.py +196 -0
  44. chython/algorithms/standardize/salts.py +128 -0
  45. chython/algorithms/standardize/saturation.py +378 -0
  46. chython/algorithms/standardize/test/__init__.py +18 -0
  47. chython/algorithms/standardize/test/test_groups.py +118 -0
  48. chython/algorithms/stereo.py +1222 -0
  49. chython/algorithms/tautomers/__init__.py +171 -0
  50. chython/algorithms/tautomers/_acid.py +59 -0
  51. chython/algorithms/tautomers/_base.py +116 -0
  52. chython/algorithms/tautomers/_keto_enol.py +107 -0
  53. chython/algorithms/tautomers/acid_base.py +214 -0
  54. chython/algorithms/tautomers/heteroarenes.py +108 -0
  55. chython/algorithms/tautomers/keto_enol.py +148 -0
  56. chython/algorithms/tautomers/test/__init__.py +18 -0
  57. chython/algorithms/tautomers/test/test_tautomers.py +80 -0
  58. chython/algorithms/test/__init__.py +18 -0
  59. chython/algorithms/test/test_isomorphism.py +58 -0
  60. chython/algorithms/test/test_smiles.py +76 -0
  61. chython/algorithms/x3dom.py +355 -0
  62. chython/containers/__init__.py +43 -0
  63. chython/containers/_pack_v2.cp312-win_amd64.pyd +0 -0
  64. chython/containers/_pack_v2.pyx +271 -0
  65. chython/containers/_unpack_v0v2.cp312-win_amd64.pyd +0 -0
  66. chython/containers/_unpack_v0v2.pyx +300 -0
  67. chython/containers/bonds.py +255 -0
  68. chython/containers/cgr.py +115 -0
  69. chython/containers/graph.py +200 -0
  70. chython/containers/molecule.py +695 -0
  71. chython/containers/query.py +66 -0
  72. chython/containers/reaction.py +324 -0
  73. chython/exceptions.py +114 -0
  74. chython/files/MRVrw.py +523 -0
  75. chython/files/PDBrw.py +257 -0
  76. chython/files/RDFrw.py +298 -0
  77. chython/files/SDFrw.py +221 -0
  78. chython/files/__init__.py +29 -0
  79. chython/files/_convert.py +207 -0
  80. chython/files/_mapping.py +117 -0
  81. chython/files/_xyz.cp312-win_amd64.pyd +0 -0
  82. chython/files/_xyz.pyx +74 -0
  83. chython/files/daylight/__init__.py +24 -0
  84. chython/files/daylight/parser.py +157 -0
  85. chython/files/daylight/smarts.py +107 -0
  86. chython/files/daylight/smiles.py +245 -0
  87. chython/files/daylight/test/__init__.py +18 -0
  88. chython/files/daylight/test/test_daylight_smarts.py +289 -0
  89. chython/files/daylight/test/test_daylight_smiles.py +101 -0
  90. chython/files/daylight/test/test_parser.py +118 -0
  91. chython/files/daylight/test/test_tokenize.py +77 -0
  92. chython/files/daylight/tokenize.py +376 -0
  93. chython/files/libinchi/__init__.py +22 -0
  94. chython/files/libinchi/libinchi.dll +0 -0
  95. chython/files/libinchi/wrapper.py +555 -0
  96. chython/files/mdl/__init__.py +25 -0
  97. chython/files/mdl/emol.py +209 -0
  98. chython/files/mdl/erxn.py +67 -0
  99. chython/files/mdl/mol.py +144 -0
  100. chython/files/mdl/read.py +225 -0
  101. chython/files/mdl/rxn.py +67 -0
  102. chython/files/mdl/stereo.py +63 -0
  103. chython/files/mdl/write.py +165 -0
  104. chython/files/xyz.py +78 -0
  105. chython/periodictable/__init__.py +69 -0
  106. chython/periodictable/base/__init__.py +25 -0
  107. chython/periodictable/base/dynamic.py +149 -0
  108. chython/periodictable/base/element.py +452 -0
  109. chython/periodictable/base/groups.py +90 -0
  110. chython/periodictable/base/periods.py +46 -0
  111. chython/periodictable/base/query.py +473 -0
  112. chython/periodictable/base/vector.py +119 -0
  113. chython/periodictable/groupI.py +252 -0
  114. chython/periodictable/groupII.py +223 -0
  115. chython/periodictable/groupIII.py +1154 -0
  116. chython/periodictable/groupIV.py +210 -0
  117. chython/periodictable/groupIX.py +196 -0
  118. chython/periodictable/groupV.py +192 -0
  119. chython/periodictable/groupVI.py +183 -0
  120. chython/periodictable/groupVII.py +162 -0
  121. chython/periodictable/groupVIII.py +161 -0
  122. chython/periodictable/groupX.py +166 -0
  123. chython/periodictable/groupXI.py +164 -0
  124. chython/periodictable/groupXII.py +158 -0
  125. chython/periodictable/groupXIII.py +239 -0
  126. chython/periodictable/groupXIV.py +262 -0
  127. chython/periodictable/groupXV.py +276 -0
  128. chython/periodictable/groupXVI.py +457 -0
  129. chython/periodictable/groupXVII.py +324 -0
  130. chython/periodictable/groupXVIII.py +260 -0
  131. chython/reactor/__init__.py +24 -0
  132. chython/reactor/base.py +212 -0
  133. chython/reactor/deprotection.py +565 -0
  134. chython/reactor/groups.py +128 -0
  135. chython/reactor/reactions/__init__.py +157 -0
  136. chython/reactor/reactions/_amidation.py +58 -0
  137. chython/reactor/reactions/_amine_isocyanate.py +52 -0
  138. chython/reactor/reactions/_buchwald_hartwig.py +50 -0
  139. chython/reactor/reactions/_esterification.py +49 -0
  140. chython/reactor/reactions/_macmillan.py +43 -0
  141. chython/reactor/reactions/_reductive_amination.py +50 -0
  142. chython/reactor/reactions/_sonogashira.py +49 -0
  143. chython/reactor/reactions/_sulfonamidation.py +52 -0
  144. chython/reactor/reactions/_suzuki_miyaura.py +88 -0
  145. chython/reactor/reactions/ufe.py +99 -0
  146. chython/reactor/reactor.py +170 -0
  147. chython/reactor/retro/__init__.py +77 -0
  148. chython/reactor/retro/_amidation.py +39 -0
  149. chython/reactor/retro/_aryl_amination.py +32 -0
  150. chython/reactor/retro/_mitsunobu.py +49 -0
  151. chython/reactor/retro/_sonogashira.py +49 -0
  152. chython/reactor/retro/_suzuki_miyaura.py +54 -0
  153. chython/reactor/scaffold.py +122 -0
  154. chython/reactor/test/__init__.py +18 -0
  155. chython/reactor/test/test_deprotection.py +57 -0
  156. chython/reactor/test/test_reactor.py +40 -0
  157. chython/reactor/test/test_scaffold.py +57 -0
  158. chython/reactor/test/test_transformer.py +40 -0
  159. chython/reactor/transformer.py +62 -0
  160. chython/utils/__init__.py +57 -0
  161. chython/utils/free_wilson.py +114 -0
  162. chython/utils/grid.py +130 -0
  163. chython/utils/rdkit.py +165 -0
  164. chython/utils/retro.py +139 -0
  165. chython/utils/svg.py +57 -0
  166. chython/utils/test/__init__.py +18 -0
  167. chython/utils/test/test_rdkit.py +71 -0
  168. chython-2.4.dist-info/LICENSE +165 -0
  169. chython-2.4.dist-info/METADATA +101 -0
  170. chython-2.4.dist-info/RECORD +171 -0
  171. chython-2.4.dist-info/WHEEL +4 -0
@@ -0,0 +1,108 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2022-2024 Ramil Nugmanov <nougmanoff@protonmail.com>
4
+ # This file is part of chython.
5
+ #
6
+ # chython is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation; either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with this program; if not, see <https://www.gnu.org/licenses/>.
18
+ #
19
+ from collections import deque, defaultdict
20
+ from itertools import product
21
+ from typing import TYPE_CHECKING
22
+ from ..aromatics.kekule import _kekule_component
23
+ from ...exceptions import InvalidAromaticRing
24
+
25
+
26
+ if TYPE_CHECKING:
27
+ from chython import MoleculeContainer
28
+
29
+
30
+ # atomic number constants
31
+ B = 5
32
+ C = 6
33
+ N = 7
34
+ P = 15
35
+
36
+
37
+ class HeteroArenes:
38
+ __slots__ = ()
39
+
40
+ def _enumerate_hetero_arene_tautomers(self: 'MoleculeContainer'):
41
+ atoms = self._atoms
42
+ bonds = self._bonds
43
+
44
+ rings = defaultdict(list) # aromatic skeleton
45
+ for n, m_bond in bonds.items():
46
+ for m, bond in m_bond.items():
47
+ if bond == 4:
48
+ rings[n].append(m)
49
+ if not rings:
50
+ return
51
+
52
+ acceptors = set()
53
+ donors = set()
54
+ single_bonded = set()
55
+ for n, ms in rings.items():
56
+ a = atoms[n]
57
+ if len(ms) == 2:
58
+ if a in (B, N, P):
59
+ if not a.charge and not a.is_radical:
60
+ # only neutral B, N, P
61
+ if a.implicit_hydrogens: # pyrrole
62
+ donors.add(n)
63
+ elif len(bonds[n]) == 2: # pyridine
64
+ acceptors.add(n)
65
+ else:
66
+ single_bonded.add(n)
67
+ elif a.charge == -1 and a == C: # ferrocene
68
+ single_bonded.add(n)
69
+ elif len(ms) == 3 and a in (B, N, P) and not a.charge and not a.is_radical:
70
+ single_bonded.add(n)
71
+ if not donors or not acceptors:
72
+ return
73
+
74
+ atoms = set(rings)
75
+ components = []
76
+ while atoms:
77
+ start = atoms.pop()
78
+ component = {start: rings[start]}
79
+ queue = deque([start])
80
+ while queue:
81
+ current = queue.popleft()
82
+ for n in rings[current]:
83
+ if n not in component:
84
+ queue.append(n)
85
+ component[n] = rings[n]
86
+
87
+ atoms.difference_update(component)
88
+ if donors.isdisjoint(component) or acceptors.isdisjoint(component):
89
+ continue
90
+ components.append(component)
91
+
92
+ if not components:
93
+ return
94
+ for component in components:
95
+ for d, a in product(component.keys() & donors, component.keys() & acceptors):
96
+ sb = component.keys() & single_bonded
97
+ sb.add(a) # now pyrrole
98
+ try:
99
+ next(_kekule_component(component, sb, (), 0))
100
+ except InvalidAromaticRing:
101
+ continue
102
+ mol = self.copy(keep_sssr=True, keep_components=True)
103
+ mol._atoms[d]._implicit_hydrogens = 0
104
+ mol._atoms[a]._implicit_hydrogens = 1
105
+ yield mol
106
+
107
+
108
+ __all__ = ['HeteroArenes']
@@ -0,0 +1,148 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2022-2024 Ramil Nugmanov <nougmanoff@protonmail.com>
4
+ # This file is part of chython.
5
+ #
6
+ # chython is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation; either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with this program; if not, see <https://www.gnu.org/licenses/>.
18
+ #
19
+ from collections import defaultdict
20
+ from functools import cached_property
21
+ from itertools import chain, repeat
22
+ from typing import TYPE_CHECKING, Union
23
+ from ._keto_enol import *
24
+
25
+
26
+ if TYPE_CHECKING:
27
+ from chython import MoleculeContainer
28
+
29
+
30
+ # atomic number constants
31
+ C = 6
32
+
33
+
34
+ class KetoEnol:
35
+ __slots__ = ()
36
+
37
+ def _enumerate_keto_enol_tautomers(self: Union['MoleculeContainer', 'KetoEnol'], partial=False):
38
+ for fix, ket in self.__enumerate_bonds(partial):
39
+ if ket:
40
+ a = fix[-1][1]
41
+ d = fix[0][0]
42
+ else:
43
+ a = fix[0][0]
44
+ d = fix[-1][1]
45
+
46
+ mol = self.copy(keep_sssr=True, keep_components=True)
47
+ m_bonds = mol._bonds
48
+ for n, m, b in fix:
49
+ m_bonds[n][m]._order = b
50
+
51
+ a = mol._atoms[a]
52
+ d = mol._atoms[d]
53
+ a._implicit_hydrogens += 1
54
+ d._implicit_hydrogens -= 1
55
+ a._hybridization -= 1 # -C=X>=C-X or -C=C=X>=C-C=X
56
+ d._hybridization += 1
57
+ yield mol, ket
58
+
59
+ @cached_property
60
+ def _sugar_groups(self):
61
+ ek = []
62
+ for mapping in sugar_group.get_mapping(self, automorphism_filter=False):
63
+ e, k = mapping[1], mapping[2]
64
+ ek.append((e, k))
65
+ return ek
66
+
67
+ def __enumerate_bonds(self: 'MoleculeContainer', partial):
68
+ atoms = self._atoms
69
+ bonds = self._bonds
70
+ rings = self.atoms_rings_sizes
71
+
72
+ # search neutral oxygen and nitrogen
73
+ donors = defaultdict(set)
74
+ acceptors = defaultdict(set)
75
+ for q in enol_rules:
76
+ for mapping in q.get_mapping(self, automorphism_filter=False):
77
+ donors[mapping[1]].add(mapping[2])
78
+ for q in keto_rules:
79
+ for mapping in q.get_mapping(self, automorphism_filter=False):
80
+ acceptors[mapping[1]].add(mapping[2])
81
+
82
+ for (atom, dirs), hydrogen, anti in chain(zip(donors.items(), repeat(True), repeat(acceptors)),
83
+ zip(acceptors.items(), repeat(False), repeat(donors))):
84
+ path = []
85
+ seen = {atom}
86
+ stack = [(atom, n, 2 if hydrogen else 1, 0) for n in dirs]
87
+ while stack:
88
+ last, current, bond, depth = stack.pop()
89
+
90
+ if partial and path and not len(path) % 2 and \
91
+ (hydrogen or # enol > ketone
92
+ atoms[(x := path[-1][1])].implicit_hydrogens and
93
+ (x not in rings or all(x > 7 for x in rings[x]))): # ketone>
94
+ # return partial hops. ignore allenes in small rings.
95
+ yield path, hydrogen
96
+ if len(path) > depth: # fork found
97
+ if not partial and not len(path) % 2 and (hydrogen or atoms[path[-1][1]].implicit_hydrogens):
98
+ # end of path found. return it and start new one.
99
+ yield path, hydrogen
100
+ seen.difference_update(x for _, x, _ in path[depth:])
101
+ path = path[:depth]
102
+
103
+ path.append((last, current, bond))
104
+
105
+ # adding neighbors
106
+ depth += 1
107
+ seen.add(current)
108
+ if bond == 2:
109
+ next_bond = 1
110
+ else:
111
+ next_bond = 2
112
+
113
+ for n, b in bonds[current].items():
114
+ if n == last:
115
+ continue
116
+ elif n in seen: # aromatic ring destruction. pyridine double bonds shift
117
+ continue
118
+ elif n in anti: # enol-ketone switch
119
+ if current in anti[n]: # keton or enol bond
120
+ if hydrogen:
121
+ cp = path.copy()
122
+ cp.append((current, n, 1)) # double to single in keton end
123
+ yield cp, True
124
+ else:
125
+ cp = path.copy()
126
+ cp.append((current, n, 2)) # single to double in enol end
127
+ yield cp, False
128
+ elif b == bond and (a := atoms[n]) == C: # classic keto-enol route
129
+ if a.hybridization == 2: # grow up
130
+ stack.append((current, n, next_bond, depth))
131
+ elif hydrogen:
132
+ if a.hybridization == 3: # OC=CC=C=C case
133
+ cp = path.copy()
134
+ cp.append((current, n, 1))
135
+ yield cp, True # ketone found
136
+ elif a.hybridization == 1 and a.implicit_hydrogens: # ketone >> enol
137
+ cp = path.copy()
138
+ cp.append((current, n, 2))
139
+ yield cp, False
140
+
141
+ if path and not len(path) % 2 and \
142
+ (hydrogen or # enol > ketone
143
+ atoms[(x := path[-1][1])].implicit_hydrogens and
144
+ (x not in rings or all(x > 7 for x in rings[x]))):
145
+ yield path, hydrogen
146
+
147
+
148
+ __all__ = ['KetoEnol']
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2021 Ramil Nugmanov <nougmanoff@protonmail.com>
4
+ # This file is part of chython.
5
+ #
6
+ # chython is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation; either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with this program; if not, see <https://www.gnu.org/licenses/>.
18
+ #
@@ -0,0 +1,80 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2021 Ramil Nugmanov <nougmanoff@protonmail.com>
4
+ # This file is part of chython.
5
+ #
6
+ # chython is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation; either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with this program; if not, see <https://www.gnu.org/licenses/>.
18
+ #
19
+ from chython import smiles
20
+ from itertools import zip_longest
21
+
22
+
23
+ def test_keto_enol_2h_pyrrole():
24
+ """
25
+ 2H‐pyrrole. [N:1]=1[C:2][C:3]=,:[C:4][C:5]=1
26
+ """
27
+ for t, v in zip(['C1C=CC=N1', 'C1N=CC2=C1C=CC=C2'], ['C=1C=CNC=1', 'N1C=C2C=CC=CC2=C1']):
28
+ s = smiles(t)
29
+ t = set(s.enumerate_tautomers())
30
+ v = smiles(v)
31
+ s.thiele()
32
+ v.thiele()
33
+ assert len(t) == 2, ' '.join(str(x) for x in t)
34
+ assert t == {s, v}, f'{", ".join(str(x) for x in t)} != {s}, {v}'
35
+
36
+
37
+ def test_acid_protonated_nitrogen():
38
+ """
39
+ Ammonia, H-imine,guanidine,amidine. [H][N+]=,-,:
40
+ """
41
+ for t, v in zip_longest(['C=[NH2+].[Cl-]', 'C=[NH+]C.[Cl-]', 'C[NH3+].[Cl-]', 'C[NH2+]C.[Cl-]', 'C[NH1+](C)C.[Cl-]',
42
+ '[NH4+].[Cl-]', 'C=[N+](C)C.[Cl-]', 'C[N+](C)(C)C.[Cl-]'],
43
+ ['C=N.Cl', 'C=NC.Cl', 'CN.Cl', 'CNC.Cl', 'CN(C)C.Cl', 'N.Cl']):
44
+ s = smiles(t)
45
+ t = set(s.enumerate_tautomers())
46
+ if v:
47
+ assert len(t) == 2, ' '.join(str(x) for x in t)
48
+ assert t == {s, smiles(v)}
49
+ else:
50
+ assert len(t) == 1
51
+
52
+
53
+ def test_base_nitrogen():
54
+ for t, v in zip_longest(['N1C=CN=N1.Cl', 'NC(N)=N.Cl', 'CN(C)C(=NO)N(C)C.Cl', 'CN(C)C(=NC)N(C)C.Cl',
55
+ 'CN(C)C(=NN)N(C)C.Cl', 'COC(N)=N.Cl', 'CSC(N)=N.Cl', 'COC(OC)=N.Cl', 'COC(C)=N.Cl',
56
+ 'CNN.Cl', 'CN.Cl',
57
+ 'N.Cl', 'N1C=CC=C1.Cl'],
58
+ [('N1N=NC=C1.Cl', 'N1=CC=NN1.Cl', '[NH+]=1NC=CN=1.[Cl-]', 'N1=[NH+]C=CN1.[Cl-]',
59
+ 'N1=CC=[NH+]N1.[Cl-]'),
60
+ ('NC(N)=N.Cl', 'NC(N)=[NH2+].[Cl-]'),
61
+ ('CN(C)C(=NO)N(C)C.Cl', 'CN(C)C(N(C)C)=[NH+]O.[Cl-]'),
62
+ ('CN(C)C(=NC)N(C)C.Cl', 'CN(C)C(N(C)C)=[NH+]C.[Cl-]'),
63
+ ('CN(C)C(=NN)N(C)C.Cl', 'CN(C)C(N(C)C)=[NH+]N.[Cl-]'),
64
+ ('Cl.NC(=N)OC', '[NH2+]=C(N)OC.[Cl-]'), ('Cl.NC(=N)SC', '[NH2+]=C(N)SC.[Cl-]'),
65
+ ('COC(OC)=N.Cl', 'COC(OC)=[NH2+].[Cl-]'),
66
+ ('COC(C)=N.Cl', 'COC(C)=[NH2+].[Cl-]'),
67
+ ('CNN.Cl', 'CN[NH3+].[Cl-]', 'C[NH2+]N.[Cl-]'),
68
+ ('CN.Cl', 'C[NH3+].[Cl-]')]):
69
+ s = smiles(t)
70
+ t = set(s.enumerate_tautomers(zwitter=True))
71
+ if v:
72
+ assert len(t) == len(v), ' '.join(str(x) for x in t)
73
+ vs = set()
74
+ for x in v:
75
+ x = smiles(x)
76
+ x.thiele(fix_tautomers=False)
77
+ vs.add(x)
78
+ assert t == vs, ' '.join(str(x) for x in t) + ' != ' + ' '.join(str(x) for x in vs)
79
+ else:
80
+ assert len(t) == 1, ' '.join(str(x) for x in t)
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2025 Ramil Nugmanov <nougmanoff@protonmail.com>
4
+ # This file is part of chython.
5
+ #
6
+ # chython is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation; either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with this program; if not, see <https://www.gnu.org/licenses/>.
18
+ #
@@ -0,0 +1,58 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2025 Ramil Nugmanov <nougmanoff@protonmail.com>
4
+ # Copyright 2025 Tagir Akhmetshin <tagirshin@gmail.com>
5
+ # This file is part of chython.
6
+ #
7
+ # chython is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation; either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program; if not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+ from chython import smiles
21
+
22
+
23
+ def test_basic():
24
+ # Test basic atom mapping in simple molecules
25
+ mol1 = smiles('CC(=O)O') # acetic acid
26
+ mol2 = smiles('CC(O)=O') # acetic acid
27
+
28
+ assert mol1 <= mol2
29
+ assert mol2 <= mol1
30
+
31
+ mappings = list(mol1.get_mapping(mol2))
32
+ assert len(mappings) == 1
33
+ assert mappings[0] == {1: 1, 2: 2, 3: 4, 4: 3}
34
+ assert not smiles('CC(O)O') <= mol1
35
+ assert smiles('C[O-]') <= smiles('CC[O-]')
36
+ assert not smiles('C[O-]') <= smiles('CCO')
37
+
38
+
39
+ def test_substructure_mapping():
40
+ # Test mapping of a substructure
41
+ mol = smiles('CCC(=O)OC')
42
+ substructure = smiles('CC(=O)O')
43
+
44
+ assert substructure < mol
45
+ mappings = list(substructure.get_mapping(mol))
46
+ assert len(mappings) == 1
47
+ assert mappings[0] == {1: 2, 2: 3, 3: 4, 4: 5}
48
+
49
+
50
+ def test_multiple_mappings():
51
+ # Test cases where multiple valid mappings exist
52
+ mol = smiles('CC(=O)OC(=O)C')
53
+ pattern = smiles('CC(=O)O') # acetone pattern
54
+
55
+ mappings = list(pattern.get_mapping(mol))
56
+ assert len(mappings) == 2 # should find multiple matches
57
+ assert {1: 1, 2: 2, 3: 3, 4: 4} in mappings
58
+ assert {1: 7, 2: 5, 3: 6, 4: 4} in mappings
@@ -0,0 +1,76 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2025 Ramil Nugmanov <nougmanoff@protonmail.com>
4
+ # Copyright 2025 Tagir Akhmetshin <tagirshin@gmail.com>
5
+ # This file is part of chython.
6
+ #
7
+ # chython is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation; either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program; if not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+ from chython import smiles
21
+
22
+
23
+ def test_basic_smiles():
24
+ # Test basic SMILES generation
25
+ mol = smiles('CO') # methanol
26
+ assert str(mol) in ('CO', 'OC')
27
+
28
+ mol = smiles('c1ccccc1') # benzene
29
+ assert str(mol) == 'c1ccccc1'
30
+
31
+
32
+ def test_format_options():
33
+ # Test different format options
34
+ mol = smiles('C=1C=CC=CC=1')
35
+
36
+ # Test asymmetric closures
37
+ assert str(mol) == 'C=1C=CC=CC=1'
38
+ assert format(mol, 'a') == 'C=1C=CC=CC1'
39
+
40
+ assert format(mol, '!b') == 'C1CCCCC1'
41
+
42
+ # Test disable stereo
43
+ mol = smiles('C[C@H](O)CC')
44
+ assert '@' in str(mol)
45
+ assert '@' not in format(mol, '!s')
46
+
47
+ mol = smiles('c1ccccc1')
48
+ assert format(mol, 'A') == 'C:1:C:C:C:C:C:1'
49
+ assert format(mol, 'Aa') == 'C:1:C:C:C:C:C1'
50
+ assert format(mol, 'm') == '[cH:1]1[cH:2][cH:3][cH:4][cH:5][cH:6]1'
51
+ assert format(mol, 'h') == '[cH]1[cH][cH][cH][cH][cH]1'
52
+
53
+ assert format(mol, 'Ah') == '[CH]:1:[CH]:[CH]:[CH]:[CH]:[CH]:1'
54
+ assert format(mol, 'Ah!b') == '[CH]1[CH][CH][CH][CH][CH]1'
55
+
56
+ mol = smiles('[K+]')
57
+ assert str(mol) == '[K+]'
58
+ assert format(mol, '!z') == '[K]'
59
+
60
+ mol = smiles('[CH3]')
61
+ assert str(mol) == '[CH3] |^1:0|'
62
+ assert format(mol, '!x') == '[CH3]'
63
+
64
+ mol = smiles('CCO')
65
+ assert len({format(mol, 'r') for _ in range(50)}) == 4
66
+
67
+
68
+ def test_smiles_comparison():
69
+ # Test SMILES comparison functionality
70
+ mol1 = smiles('CCO')
71
+ mol2 = smiles('OCC')
72
+ mol3 = smiles('CCC')
73
+
74
+ assert mol1 == mol2 # same molecules
75
+ assert mol1 != mol3 # different molecules
76
+ assert hash(mol1) == hash(mol2) # same hash for same molecules