Skip to content

Commit a98ec0d

Browse files
authored
#2462 Can't save a reaction with Multi-Tailed Arrow to Daylight SMARTS format (#2885)
1 parent c75308f commit a98ec0d

6 files changed

Lines changed: 664 additions & 10 deletions

File tree

api/wasm/indigo-ketcher/indigo-ketcher.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,8 @@ namespace indigo
428428
return IndigoKetcherObject(objectId, IndigoKetcherObject::EKETDocument);
429429
}
430430
}
431-
bool query = false;
432431
auto i = options.find("query");
433-
if (i != options.end() and i->second == "true")
434-
{
435-
query = true;
436-
}
437-
if (!query)
432+
if (i == options.end() || i->second == "false")
438433
{
439434
// Let's try a simple molecule
440435
print_js("try as molecule");
@@ -529,6 +524,24 @@ namespace indigo
529524
{
530525
return IndigoKetcherObject(objectId, IndigoKetcherObject::EKETReactionQuery);
531526
}
527+
528+
// Let's try a simple molecule
529+
print_js("try as molecule");
530+
objectId = indigoLoadMoleculeFromBuffer(data.c_str(), data.size());
531+
if (objectId >= 0)
532+
{
533+
return IndigoKetcherObject(objectId, IndigoKetcherObject::EKETMolecule);
534+
}
535+
exceptionMessages.emplace_back(indigoGetLastError());
536+
537+
// Let's try reaction
538+
print_js("try as reaction");
539+
objectId = indigoLoadReactionFromBuffer(data.c_str(), data.size());
540+
if (objectId >= 0)
541+
{
542+
return IndigoKetcherObject(objectId, IndigoKetcherObject::EKETReaction);
543+
}
544+
exceptionMessages.emplace_back(indigoGetLastError());
532545
}
533546
// It's not anything we can load, let's throw an exception
534547
std::stringstream ss;
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
{
2+
"root": {
3+
"nodes": [
4+
{
5+
"$ref": "mol0"
6+
},
7+
{
8+
"$ref": "mol1"
9+
},
10+
{
11+
"$ref": "mol2"
12+
},
13+
{
14+
"type": "multi-tailed-arrow",
15+
"data": {
16+
"head": {
17+
"position": {
18+
"x": 34.82349,
19+
"y": -15.38089,
20+
"z": 0
21+
}
22+
},
23+
"spine": {
24+
"pos": [
25+
{
26+
"x": 28.32349,
27+
"y": -13.22968,
28+
"z": 0
29+
},
30+
{
31+
"x": 28.32349,
32+
"y": -17.5321,
33+
"z": 0
34+
}
35+
]
36+
},
37+
"tails": {
38+
"pos": [
39+
{
40+
"x": 27.82349,
41+
"y": -13.22968,
42+
"z": 0
43+
},
44+
{
45+
"x": 27.82349,
46+
"y": -17.5321,
47+
"z": 0
48+
}
49+
]
50+
},
51+
"zOrder": 0
52+
}
53+
}
54+
],
55+
"connections": [],
56+
"templates": []
57+
},
58+
"mol0": {
59+
"type": "molecule",
60+
"atoms": [
61+
{
62+
"label": "C",
63+
"location": [
64+
36.10126780234289,
65+
-14.947879824075631,
66+
0
67+
]
68+
},
69+
{
70+
"label": "C",
71+
"location": [
72+
35.60126777147982,
73+
-15.813905086958911,
74+
0
75+
]
76+
},
77+
{
78+
"label": "C",
79+
"location": [
80+
36.601267833205966,
81+
-15.813905086958911,
82+
0
83+
]
84+
}
85+
],
86+
"bonds": [
87+
{
88+
"type": 1,
89+
"atoms": [
90+
0,
91+
1
92+
]
93+
},
94+
{
95+
"type": 1,
96+
"atoms": [
97+
1,
98+
2
99+
]
100+
},
101+
{
102+
"type": 1,
103+
"atoms": [
104+
2,
105+
0
106+
]
107+
}
108+
],
109+
"stereoFlagPosition": {
110+
"x": 36.601267833205966,
111+
"y": 13.947879824075631,
112+
"z": 0
113+
}
114+
},
115+
"mol1": {
116+
"type": "molecule",
117+
"atoms": [
118+
{
119+
"label": "C",
120+
"location": [
121+
25.922221973681747,
122+
-12.522571446831636,
123+
0
124+
]
125+
},
126+
{
127+
"label": "C",
128+
"location": [
129+
25.21511516094984,
130+
-13.229678319168192,
131+
0
132+
]
133+
},
134+
{
135+
"label": "C",
136+
"location": [
137+
26.629328846018304,
138+
-13.229678319168192,
139+
0
140+
]
141+
},
142+
{
143+
"label": "C",
144+
"location": [
145+
25.922222092891044,
146+
-13.936784953086153,
147+
0
148+
]
149+
}
150+
],
151+
"bonds": [
152+
{
153+
"type": 1,
154+
"atoms": [
155+
0,
156+
1
157+
]
158+
},
159+
{
160+
"type": 1,
161+
"atoms": [
162+
1,
163+
3
164+
]
165+
},
166+
{
167+
"type": 1,
168+
"atoms": [
169+
3,
170+
2
171+
]
172+
},
173+
{
174+
"type": 1,
175+
"atoms": [
176+
2,
177+
0
178+
]
179+
}
180+
],
181+
"stereoFlagPosition": {
182+
"x": 26.629328846018304,
183+
"y": 11.522571446831636,
184+
"z": 0
185+
}
186+
},
187+
"mol2": {
188+
"type": "molecule",
189+
"atoms": [
190+
{
191+
"label": "C",
192+
"location": [
193+
25.922221973681747,
194+
-16.436785107401523,
195+
0
196+
]
197+
},
198+
{
199+
"label": "C",
200+
"location": [
201+
25.021253068409443,
202+
-16.870668801175675,
203+
0
204+
]
205+
},
206+
{
207+
"label": "C",
208+
"location": [
209+
24.798732166822372,
210+
-17.845596763575898,
211+
0
212+
]
213+
},
214+
{
215+
"label": "C",
216+
"location": [
217+
25.422222181237267,
218+
-18.627428553168368,
219+
0
220+
]
221+
},
222+
{
223+
"label": "C",
224+
"location": [
225+
26.823190580930806,
226+
-16.870668801175675,
227+
0
228+
]
229+
},
230+
{
231+
"label": "C",
232+
"location": [
233+
26.42222200454482,
234+
-18.62742807633118,
235+
0
236+
]
237+
},
238+
{
239+
"label": "C",
240+
"location": [
241+
27.04571189975042,
242+
-17.845596763575898,
243+
0
244+
]
245+
}
246+
],
247+
"bonds": [
248+
{
249+
"type": 1,
250+
"atoms": [
251+
1,
252+
0
253+
]
254+
},
255+
{
256+
"type": 1,
257+
"atoms": [
258+
0,
259+
4
260+
]
261+
},
262+
{
263+
"type": 1,
264+
"atoms": [
265+
4,
266+
6
267+
]
268+
},
269+
{
270+
"type": 1,
271+
"atoms": [
272+
6,
273+
5
274+
]
275+
},
276+
{
277+
"type": 1,
278+
"atoms": [
279+
5,
280+
3
281+
]
282+
},
283+
{
284+
"type": 1,
285+
"atoms": [
286+
3,
287+
2
288+
]
289+
},
290+
{
291+
"type": 1,
292+
"atoms": [
293+
2,
294+
1
295+
]
296+
}
297+
],
298+
"stereoFlagPosition": {
299+
"x": 27.04571189975042,
300+
"y": 15.436785107401523,
301+
"z": 0
302+
}
303+
}
304+
}

api/wasm/indigo-ketcher/test/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ M END
542542
assert.equal(rsmiles, '{"struct":"C1C=CC=CC=1.N>>C1N=CC=CC=1.[CH3-]","format":"smiles","original_format":"chemical/x-daylight-smarts"}');
543543
options.delete();
544544
});
545+
test("convert", "pathway-smarts", () => {
546+
var fs = require('fs');
547+
const ket = fs.readFileSync("pathway_2642.ket");
548+
let options = new indigo.MapStringString();
549+
const smarts = indigo.convert(ket, "smarts", options);
550+
assert.equal(smarts, '[#6]1-[#6]-[#6]-[#6]-1.[#6]1-[#6]-[#6]-[#6]-[#6]-[#6]-[#6]-1>>[#6]1-[#6]-[#6]-1')
551+
options.delete();
552+
});
545553
}
546554

547555
// Convert explicit hydrogens

utils/indigo-service/backend/service/tests/api/indigo_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,27 @@ def test_convert_smarts(self):
714714

715715
self.assertEqual(smarts, results)
716716
# self.assertEqual(smarts, results_get)
717+
with open(
718+
os.path.join(
719+
joinPathPy("structures/", __file__), "pathway_2642.ket"
720+
),
721+
"r",
722+
) as file:
723+
pw_ket = file.read()
724+
params = {
725+
"struct": pw_ket,
726+
"output_format": "chemical/x-daylight-smarts",
727+
}
728+
headers, data = self.get_headers(params)
729+
result = requests.post(
730+
self.url_prefix + "/convert", headers=headers, data=data
731+
)
732+
self.assertEqual(200, result.status_code)
733+
result_data = json.loads(result.text)
734+
self.assertEqual(
735+
result_data["struct"],
736+
"[#6]1-[#6]-[#6]-[#6]-1.[#6]1-[#6]-[#6]-[#6]-[#6]-[#6]-[#6]-1>>[#6]1-[#6]-[#6]-1",
737+
)
717738

718739
def test_convert_name_to_structure(self):
719740
names = [

0 commit comments

Comments
 (0)