Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2805 Saving of 3:3 reaction to SDF v2000 causes exception: Convert error! core: <reaction> is not a base molecule #2842

Merged
merged 7 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/tests/integration/ref/formats/ket_to_sdf.py.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
*** KET to SDF ***
acd2d_err3.sdf:SUCCEED
multi.sdf:SUCCEED
pathway1.sdf:SUCCEED
pathway2.sdf:SUCCEED
pathway3.sdf:SUCCEED
qreaction.sdf:SUCCEED
14 changes: 14 additions & 0 deletions api/tests/integration/ref/formats/reactions_to_cdxml.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*** KET to CDXML ***
multi.cdxml:SUCCEED
pathway1.cdxml:SUCCEED
pathway10.cdxml:SUCCEED
pathway11.cdxml:SUCCEED
pathway12.cdxml:SUCCEED
pathway2.cdxml:SUCCEED
pathway3.cdxml:SUCCEED
pathway4.cdxml:SUCCEED
pathway5.cdxml:SUCCEED
pathway6.cdxml:SUCCEED
pathway7.cdxml:SUCCEED
pathway8.cdxml:SUCCEED
pathway9.cdxml:SUCCEED
37 changes: 37 additions & 0 deletions api/tests/integration/tests/formats/ket_to_sdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,40 @@ def find_diff(a, b):
else:
print(filename + ".sdf:FAILED")
print(diff)

root = joinPathPy("reactions/", __file__)
ref_path = joinPathPy("ref/", __file__)

files = ["pathway1", "pathway2", "pathway3", "multi", "qreaction"]

files.sort()
for filename in files:
try:
ket = indigo.loadReactionFromFile(
os.path.join(root, filename + ".ket")
)
except:
try:
ket = indigo.loadQueryReactionFromFile(
os.path.join(root, filename + ".ket")
)
except IndigoException as e:
print(" %s" % (getIndigoExceptionText(e)))

buffer = indigo.writeBuffer()
sdfSaver = indigo.createSaver(buffer, "sdf")
for mol in ket.iterateMolecules():
sdfSaver.append(mol.clone())
sdfSaver.close()
sdf = buffer.toString()
# with open(os.path.join(ref_path, filename) + ".sdf", "w") as file:
# file.write(sdf)

with open(os.path.join(ref_path, filename) + ".sdf", "r") as file:
sdf_ref = file.read()
diff = find_diff(sdf_ref, sdf)
if not diff:
print(filename + ".sdf:SUCCEED")
else:
print(filename + ".sdf:FAILED")
print(diff)
200 changes: 200 additions & 0 deletions api/tests/integration/tests/formats/reactions/qreaction.ket
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"root": {
"nodes": [
{
"$ref": "mol0"
},
{
"$ref": "mol1"
},
{
"type": "arrow",
"data": {
"mode": "open-angle",
"pos": [
{
"x": 13.15,
"y": -8.3,
"z": 0
},
{
"x": 15.725121356363621,
"y": -8.3,
"z": 0
}
]
}
}
],
"connections": [],
"templates": []
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
12.08220745473898,
-8.79754874346472,
0
]
},
{
"label": "C",
"location": [
12.078504114664911,
-7.8024512565352815,
0
]
},
{
"label": "C",
"location": [
11.070294802067824,
-8.784637098341616,
0
]
},
{
"label": "A",
"location": [
11.067792545261023,
-7.8024512565352815,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
},
{
"type": 1,
"atoms": [
1,
3
]
},
{
"type": 1,
"atoms": [
3,
2
]
},
{
"type": 1,
"atoms": [
2,
0
]
}
]
},
"mol1": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
16.758987298340656,
-7.82499266647844,
0
]
},
{
"label": "C",
"location": [
16.758987298340656,
-8.825007333521562,
0
]
},
{
"label": "A",
"location": [
17.625,
-9.325014667043124,
0
]
},
{
"label": "C",
"location": [
18.491012701659344,
-8.825007333521562,
0
]
},
{
"label": "C",
"location": [
18.491012701659344,
-7.82499266647844,
0
]
},
{
"type": "atom-list",
"elements": [
"C"
],
"notList": true,
"location": [
17.625,
-7.324985332956879,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
5,
0
]
},
{
"type": 1,
"atoms": [
0,
1
]
},
{
"type": 1,
"atoms": [
1,
2
]
},
{
"type": 1,
"atoms": [
2,
3
]
},
{
"type": 1,
"atoms": [
3,
4
]
},
{
"type": 1,
"atoms": [
4,
5
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def find_diff(a, b):
indigo = Indigo()
indigo.setOption("ignore-stereochemistry-errors", True)

print("*** RDF to CDXML ***")
print("*** KET to CDXML ***")

root = joinPathPy("reactions/rdf/", __file__)
root = joinPathPy("reactions/", __file__)
ref_path = joinPathPy("ref/", __file__)

files = [
Expand All @@ -35,20 +35,21 @@ def find_diff(a, b):
"pathway10",
"pathway11",
"pathway12",
"multi",
]

files.sort()
for filename in files:
try:
ket = indigo.loadReactionFromFile(
os.path.join(root, filename + ".rdf")
os.path.join(root, filename + ".ket")
)
except IndigoException as e:
print(" %s" % (getIndigoExceptionText(e)))

cdxml_text = ket.cdxml()
# with open(os.path.join(ref_path, filename + ".cdxml"), "w") as file:
# file.write(cdxml_text)
with open(os.path.join(ref_path, filename + ".cdxml"), "w") as file:
file.write(cdxml_text)

with open(os.path.join(ref_path, filename) + ".cdxml", "r") as file:
cdxml_ref = file.read()
Expand Down
93 changes: 93 additions & 0 deletions api/tests/integration/tests/formats/ref/multi.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

-INDIGO-01000000002D

4 4 0 0 0 0 0 0 0 0999 V2000
3.5322 -4.1225 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.5285 -3.1275 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.5203 -4.1096 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.5178 -3.1275 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 3 1 0 0 0 0
2 4 1 0 0 0 0
3 4 1 0 0 0 0
M END
$$$$

-INDIGO-01000000002D

3 3 0 0 0 0 0 0 0 0999 V2000
5.2744 -4.0825 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
6.2756 -4.0825 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
5.7751 -3.2175 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 3 1 0 0 0 0
2 3 1 0 0 0 0
M END
$$$$

-INDIGO-01000000002D

3 2 0 0 0 0 0 0 0 0999 V2000
0.4000 -2.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.1000 -3.5660 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.4000 -4.4321 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
2 3 1 0 0 0 0
M END
$$$$

-INDIGO-01000000002D

7 7 0 0 0 0 0 0 0 0999 V2000
10.8545 -3.1186 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
11.6384 -2.5010 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
12.6114 -2.7236 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
13.0455 -3.6194 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
10.8600 -4.1258 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
12.6121 -4.5264 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
11.6384 -4.7490 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
2 3 1 0 0 0 0
3 4 1 0 0 0 0
4 6 1 0 0 0 0
1 5 1 0 0 0 0
5 7 1 0 0 0 0
6 7 1 0 0 0 0
M END
$$$$

-INDIGO-01000000002D

6 6 0 0 0 0 0 0 0 0999 V2000
15.5090 -2.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
15.5090 -3.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
16.3750 -4.3250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
17.2410 -3.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
17.2410 -2.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
16.3750 -2.3250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 6 1 0 0 0 0
1 2 1 0 0 0 0
2 3 1 0 0 0 0
3 4 1 0 0 0 0
4 5 1 0 0 0 0
5 6 1 0 0 0 0
M END
$$$$

-INDIGO-01000000002D

6 6 0 0 0 0 0 0 0 0999 V2000
22.5598 -3.0501 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
24.2902 -3.0496 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
23.4266 -2.5500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
24.2902 -4.0505 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
22.5598 -4.0550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
23.4288 -4.5500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3 1 2 0 0 0 0
4 2 2 0 0 0 0
1 5 1 0 0 0 0
2 3 1 0 0 0 0
5 6 2 0 0 0 0
6 4 1 0 0 0 0
M END
$$$$
Loading