Skip to content

Commit

Permalink
#2665, #2664, #2662 - SMILES/SMARTS reaction layout issues (#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
even1024 authored Dec 2, 2024
1 parent d62efc0 commit dfa8f2f
Show file tree
Hide file tree
Showing 15 changed files with 917 additions and 133 deletions.
4 changes: 4 additions & 0 deletions api/tests/integration/ref/formats/reactions_to_ket.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*** SMARTS to KET ***
2662-arrow-size.ket:SUCCEED
2664-catalyst-margin.ket:SUCCEED
2665-incomplete-reaction.ket:SUCCEED
70 changes: 35 additions & 35 deletions api/tests/integration/ref/formats/rxn_no_layout.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,39 @@
{
"type": "plus",
"location": [
12.252167,
12.278682,
0.0,
0.0
]
},
{
"type": "plus",
"location": [
14.752167,
15.358227,
0.0,
0.0
]
},
{
"type": "plus",
"location": [
17.252167,
18.437771,
0.0,
0.0
]
},
{
"type": "plus",
"location": [
20.752186,
21.964306,
0.0,
0.0
]
},
{
"type": "plus",
"location": [
30.755943,
31.968063,
0.0,
0.0
]
Expand All @@ -80,12 +80,12 @@
"mode": "open-angle",
"pos": [
{
"x": 24.002205,
"x": 25.214325,
"y": 0.0,
"z": 0.0
},
{
"x": 25.002205,
"x": 26.214325,
"y": 0.0,
"z": 0.0
}
Expand Down Expand Up @@ -414,7 +414,7 @@
{
"label": "O",
"location": [
13.502167,
13.805197,
0.0,
0.0
]
Expand All @@ -428,7 +428,7 @@
{
"label": "O",
"location": [
16.002167,
16.911257,
0.0,
0.0
]
Expand All @@ -442,7 +442,7 @@
{
"label": "O",
"location": [
18.502167,
19.714287,
0.0,
0.0
],
Expand All @@ -451,7 +451,7 @@
{
"label": "O",
"location": [
19.502186,
20.714306,
0.0,
0.0
]
Expand All @@ -473,15 +473,15 @@
{
"label": "O",
"location": [
22.002186,
23.214306,
0.0,
0.0
]
},
{
"label": "O",
"location": [
23.002205,
24.214325,
0.0,
0.0
]
Expand All @@ -503,87 +503,87 @@
{
"label": "C",
"location": [
28.007244,
29.219364,
0.867686,
0.0
]
},
{
"label": "C",
"location": [
29.505945,
30.718065,
0.003001,
0.0
]
},
{
"label": "C",
"location": [
29.007935,
30.220055,
0.867352,
0.0
]
},
{
"label": "C",
"location": [
29.0056,
30.21772,
-0.864017,
0.0
]
},
{
"label": "C",
"location": [
27.504906,
28.717026,
-0.002667,
0.0
]
},
{
"label": "C",
"location": [
28.009914,
29.222034,
-0.865684,
0.0
]
},
{
"label": "C",
"location": [
27.513239,
28.725359,
-1.733703,
0.0
]
},
{
"label": "C",
"location": [
26.504883,
27.717003,
-0.005332,
0.0
]
},
{
"label": "O",
"location": [
26.002205,
27.214325,
0.859018,
0.0
]
},
{
"label": "O",
"location": [
26.007204,
27.219324,
-0.873017,
0.0
]
},
{
"label": "C",
"location": [
27.507238,
28.719358,
1.733703,
0.0
]
Expand Down Expand Up @@ -675,87 +675,87 @@
{
"label": "C",
"location": [
34.010983,
35.223103,
0.867686,
0.0
]
},
{
"label": "C",
"location": [
35.509682,
36.721802,
0.003001,
0.0
]
},
{
"label": "C",
"location": [
35.011673,
36.223793,
0.867352,
0.0
]
},
{
"label": "C",
"location": [
35.009338,
36.221458,
-0.864017,
0.0
]
},
{
"label": "C",
"location": [
33.508644,
34.720764,
-0.002667,
0.0
]
},
{
"label": "C",
"location": [
34.013653,
35.225773,
-0.865684,
0.0
]
},
{
"label": "C",
"location": [
33.516975,
34.729095,
-1.733703,
0.0
]
},
{
"label": "C",
"location": [
32.508621,
33.720741,
-0.005332,
0.0
]
},
{
"label": "O",
"location": [
32.005943,
33.218063,
0.859018,
0.0
]
},
{
"label": "O",
"location": [
32.010941,
33.223061,
-0.873017,
0.0
]
},
{
"label": "C",
"location": [
33.510975,
34.723095,
1.733703,
0.0
]
Expand Down
55 changes: 55 additions & 0 deletions api/tests/integration/tests/formats/reactions_to_ket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import difflib
import os
import sys


def find_diff(a, b):
return "\n".join(difflib.unified_diff(a.splitlines(), b.splitlines()))


sys.path.append(
os.path.normpath(
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
)
)
from env_indigo import * # noqa

indigo = Indigo()
indigo.setOption("json-saving-pretty", True)
indigo.setOption("ignore-stereochemistry-errors", True)

print("*** SMARTS to KET ***")

ref_path = joinPathPy("ref/", __file__)

tests = [
(
"[#6]1(-[#6])-[#6](-[#8])=[#6]-[#6](-[#16])=[#6](-[#7])-[#6]=1>>[#6]1(-Br)-[#6](-[#6])=[#6]-[#6](-I)=[#6](-[#8])-[#6]=1",
"2662-arrow-size",
),
("[#15]1-[#6]=[#6]-[#6]=[#6]-1>Br.Br>[#8]", "2664-catalyst-margin"),
("C1=OC=CC=C1>C1N=CC=C1>", "2665-incomplete-reaction"),
]

for test in tests:
try:
reaction = indigo.loadReaction(test[0])
except:
try:
reaction = indigo.loadQueryReaction(test[0])
except:
print("bad reaction data")

# with open(os.path.join(ref_path, test[1]) + ".ket", "w") as file:
# file.write(reaction.json())

with open(os.path.join(ref_path, test[1]) + ".ket", "r") as file:
ket_ref = file.read()

ket = reaction.json()
diff = find_diff(ket_ref, ket)
if not diff:
print(test[1] + ".ket:SUCCEED")
else:
print(test[1] + ".ket:FAILED")
print(diff)
Loading

0 comments on commit dfa8f2f

Please sign in to comment.