Skip to content

Commit dbdb0d0

Browse files
#3640 Escaped characters in SGroup labels in CXSMILES not properly handled (#3675)
Co-authored-by: Aliaksandr Dziarkach <18146690+AliaksandrDziarkach@users.noreply.github.com>
1 parent 0123210 commit dbdb0d0

8 files changed

Lines changed: 367 additions & 23 deletions

File tree

api/tests/integration/ref/formats/smiles.py.out

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ default smiles:
5555
CCCCC |Sg:n:1,2,3::hh|
5656
canonical smiles:
5757
canonical SMILES saver: can not canonicalize a polymer
58+
default smiles:
59+
CCCC%91.[*:1]%91 |$;;;;_AP1$,Sg:n:2:2&#44;6-7:ht|
60+
canonical smiles:
61+
canonical SMILES saver: can not canonicalize a polymer
62+
default smiles:
63+
CCCCC |SgD:1,2,3:a&#44;b:c&#44;d::: :|
64+
canonical smiles:
65+
CCCCC
66+
default smiles:
67+
CCCCC |SgD:1,2,3:name&#44;&#59;&#58;&#124;&#123;&#125;&#36;field:data&#44;&#59;&#58;&#124;&#123;&#125;&#36;value:query&#44;&#59;&#58;&#124;&#123;&#125;&#36;op:unit&#44;&#59;&#58;&#124;&#123;&#125;&#36;text: :|
68+
canonical smiles:
69+
CCCCC
70+
default smiles:
71+
CCCCC |Sg:n:1,2,3:sub&#44;&#59;&#58;&#124;&#123;&#125;&#36;script:hh|
72+
canonical smiles:
73+
canonical SMILES saver: can not canonicalize a polymer
5874
daylight:
5975
CCCC
6076
daylight:
@@ -63,6 +79,14 @@ daylight:
6379
SMILES saver: repeating units must have exactly two outgoing bonds, has 1
6480
daylight:
6581
CC{-}CC{+n}C
82+
daylight:
83+
CCC{-}{+n}C%91.[*:1]%91
84+
daylight:
85+
CCCCC
86+
daylight:
87+
CCCCC
88+
daylight:
89+
CC{-}CC{+n}C
6690
chemaxon:
6791
CCCC |Sg:gen:0,1,2:|
6892
chemaxon:
@@ -71,6 +95,19 @@ chemaxon:
7195
CCCC |Sg:n:0,1,2::ht|
7296
chemaxon:
7397
CCCCC |Sg:n:1,2,3::hh|
98+
chemaxon:
99+
CCCC%91.[*:1]%91 |$;;;;_AP1$,Sg:n:2:2&#44;6-7:ht|
100+
chemaxon:
101+
CCCCC |SgD:1,2,3:a&#44;b:c&#44;d::: :|
102+
chemaxon:
103+
CCCCC |SgD:1,2,3:name&#44;&#59;&#58;&#124;&#123;&#125;&#36;field:data&#44;&#59;&#58;&#124;&#123;&#125;&#36;value:query&#44;&#59;&#58;&#124;&#123;&#125;&#36;op:unit&#44;&#59;&#58;&#124;&#123;&#125;&#36;text: :|
104+
chemaxon:
105+
CCCCC |Sg:n:1,2,3:sub&#44;&#59;&#58;&#124;&#123;&#125;&#36;script:hh|
106+
*** S-Group AP closure roundtrip ***
107+
chemaxon roundtrip:
108+
CCCC%91.[*:1]%91 |$;;;;_AP1$,Sg:n:2:2&#44;6-7:ht|
109+
daylight closure:
110+
CCC{-}{+n}C%91.[*:1]%91
74111
*** Atropisomers ***
75112
atropisomer:
76113
C1=CC=C(C)C(C2=C(N)C=C(C)C=C2)=C1O |o1:5,r,wU:5.4|
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*** SMILES to KET ***
2+
sgroup_data_all_fields.ket:SUCCEED
3+
sgroup_sru_subscript.ket:SUCCEED
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"root": {
3+
"nodes": [
4+
{
5+
"$ref": "mol0"
6+
}
7+
]
8+
},
9+
"mol0": {
10+
"type": "molecule",
11+
"atoms": [
12+
{
13+
"label": "C",
14+
"location": [
15+
-1.7320506572723389,
16+
-5.960464477539063e-8,
17+
0.0
18+
]
19+
},
20+
{
21+
"label": "C",
22+
"location": [
23+
-0.8660253882408142,
24+
0.5,
25+
0.0
26+
]
27+
},
28+
{
29+
"label": "C",
30+
"location": [
31+
0.0,
32+
0.0,
33+
0.0
34+
]
35+
},
36+
{
37+
"label": "C",
38+
"location": [
39+
0.866025447845459,
40+
0.4999999701976776,
41+
0.0
42+
]
43+
},
44+
{
45+
"label": "C",
46+
"location": [
47+
1.7320506572723389,
48+
-2.980232238769531e-7,
49+
0.0
50+
]
51+
}
52+
],
53+
"bonds": [
54+
{
55+
"type": 1,
56+
"atoms": [
57+
0,
58+
1
59+
]
60+
},
61+
{
62+
"type": 1,
63+
"atoms": [
64+
1,
65+
2
66+
]
67+
},
68+
{
69+
"type": 1,
70+
"atoms": [
71+
2,
72+
3
73+
]
74+
},
75+
{
76+
"type": 1,
77+
"atoms": [
78+
3,
79+
4
80+
]
81+
}
82+
],
83+
"sgroups": [
84+
{
85+
"type": "DAT",
86+
"atoms": [
87+
1,
88+
2,
89+
3
90+
],
91+
"fieldName": "name,;:|{}$field",
92+
"fieldData": "data,;:|{}$value",
93+
"fieldType": "unit,;:|{}$text",
94+
"queryOp": "query,;:|{}$op",
95+
"dataDetached": false
96+
}
97+
]
98+
}
99+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"root": {
3+
"nodes": [
4+
{
5+
"$ref": "mol0"
6+
}
7+
]
8+
},
9+
"mol0": {
10+
"type": "molecule",
11+
"atoms": [
12+
{
13+
"label": "C",
14+
"location": [
15+
-1.7320506572723389,
16+
-5.960464477539063e-8,
17+
0.0
18+
]
19+
},
20+
{
21+
"label": "C",
22+
"location": [
23+
-0.8660253882408142,
24+
0.5,
25+
0.0
26+
]
27+
},
28+
{
29+
"label": "C",
30+
"location": [
31+
0.0,
32+
0.0,
33+
0.0
34+
]
35+
},
36+
{
37+
"label": "C",
38+
"location": [
39+
0.866025447845459,
40+
0.4999999701976776,
41+
0.0
42+
]
43+
},
44+
{
45+
"label": "C",
46+
"location": [
47+
1.7320506572723389,
48+
-2.980232238769531e-7,
49+
0.0
50+
]
51+
}
52+
],
53+
"bonds": [
54+
{
55+
"type": 1,
56+
"atoms": [
57+
0,
58+
1
59+
]
60+
},
61+
{
62+
"type": 1,
63+
"atoms": [
64+
1,
65+
2
66+
]
67+
},
68+
{
69+
"type": 1,
70+
"atoms": [
71+
2,
72+
3
73+
]
74+
},
75+
{
76+
"type": 1,
77+
"atoms": [
78+
3,
79+
4
80+
]
81+
}
82+
],
83+
"sgroups": [
84+
{
85+
"type": "SRU",
86+
"atoms": [
87+
1,
88+
2,
89+
3
90+
],
91+
"subscript": "sub,;:|{}$script",
92+
"connectivity": "HH"
93+
}
94+
]
95+
}
96+
}

api/tests/integration/tests/formats/smiles.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
77
)
88
)
9-
from env_indigo import *
9+
from env_indigo import Indigo, IndigoException, getIndigoExceptionText
1010

1111
indigo = Indigo()
1212

@@ -92,11 +92,25 @@
9292
print(getIndigoExceptionText(e))
9393

9494
print("*** S-Groups ***")
95+
sgroup_data_all_fields = (
96+
"CCCCC |SgD:1,2,3:"
97+
"name&#44;&#59;&#58;&#124;&#123;&#125;&#36;field:"
98+
"data&#44;&#59;&#58;&#124;&#123;&#125;&#36;value:"
99+
"query&#44;&#59;&#58;&#124;&#123;&#125;&#36;op:"
100+
"unit&#44;&#59;&#58;&#124;&#123;&#125;&#36;text: :|"
101+
)
102+
sgroup_sru_subscript = (
103+
"CCCCC |Sg:n:1,2,3:sub&#44;&#59;&#58;&#124;&#123;&#125;&#36;script:hh|"
104+
)
95105
mols_smiles = [
96106
"CCCC |Sg:gen:0,1,2:|",
97107
"CCCC |Sg:n:0,1,2:3-6:eu|",
98108
"CCCC |Sg:n:0,1,2::ht|",
99109
"CCCCC |Sg:n:1,2,3::hh|",
110+
"CCCC* |$;;;;_AP1$,Sg:n:2:2&#44;6-7:ht|",
111+
"CCCCC |SgD:1,2,3:a&#44;b:c&#44;d::: :|",
112+
sgroup_data_all_fields,
113+
sgroup_sru_subscript,
100114
]
101115
for sm in mols_smiles:
102116
print("default smiles:")
@@ -120,6 +134,16 @@
120134
print("chemaxon:")
121135
print(indigo.loadMolecule(sm).smiles())
122136

137+
print("*** S-Group AP closure roundtrip ***")
138+
sgroup_ap_closure = "CCCC* |$;;;;_AP1$,Sg:n:2:2&#44;6-7:ht|"
139+
indigo.setOption("smiles-saving-format", "chemaxon")
140+
print("chemaxon roundtrip:")
141+
print(indigo.loadMolecule(sgroup_ap_closure).smiles())
142+
indigo.setOption("smiles-saving-format", "daylight")
143+
print("daylight closure:")
144+
print(indigo.loadMolecule(sgroup_ap_closure).smiles())
145+
indigo.setOption("smiles-saving-format", "chemaxon")
146+
123147
print("*** Atropisomers ***")
124148
mols_smiles = [
125149
"C1C(O)=C(C2C=CC(C)=CC=2N)C(C)=CC=1 |o1:3,r,wU:3.12|",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
import sys
3+
4+
sys.path.append(
5+
os.path.normpath(
6+
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
7+
)
8+
)
9+
from common.util import compare_diff
10+
from env_indigo import Indigo, joinPathPy # noqa
11+
12+
indigo = Indigo()
13+
indigo.setOption("json-saving-pretty", True)
14+
15+
print("*** SMILES to KET ***")
16+
17+
ref_path = joinPathPy("ref/", __file__)
18+
19+
tests = [
20+
(
21+
"sgroup_data_all_fields",
22+
"CCCCC |SgD:1,2,3:"
23+
"name&#44;&#59;&#58;&#124;&#123;&#125;&#36;field:"
24+
"data&#44;&#59;&#58;&#124;&#123;&#125;&#36;value:"
25+
"query&#44;&#59;&#58;&#124;&#123;&#125;&#36;op:"
26+
"unit&#44;&#59;&#58;&#124;&#123;&#125;&#36;text: :|",
27+
),
28+
(
29+
"sgroup_sru_subscript",
30+
"CCCCC |Sg:n:1,2,3:sub&#44;&#59;&#58;&#124;&#123;&#125;&#36;script:hh|",
31+
),
32+
]
33+
34+
for filename, smiles in tests:
35+
ket = indigo.loadMolecule(smiles).json()
36+
compare_diff(ref_path, filename + ".ket", ket)

0 commit comments

Comments
 (0)