Skip to content

Commit

Permalink
#1230 Unable to save file if the canvas has a reaction arrow and a Fu…
Browse files Browse the repository at this point in the history
…nctional Group (#1237)
  • Loading branch information
even1024 authored Aug 21, 2023
1 parent 36719d3 commit bdb26d4
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 15 deletions.
1 change: 1 addition & 0 deletions api/tests/integration/ref/formats/ket_to_mol.py.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*** KET to MOL ***
suplabel.ket:SUCCEED
empty_apid.ket:SUCCEED
ket-reaction-arrow.ket:SUCCEED
13 changes: 6 additions & 7 deletions api/tests/integration/tests/formats/ket_to_mol.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def find_diff(a, b):
ref_path = joinPathPy("ref/", __file__)
root_rea = joinPathPy("reactions/", __file__)

files = [
"suplabel",
]
files = ["suplabel"]

files.sort()
for filename in files:
Expand All @@ -41,16 +39,17 @@ def find_diff(a, b):
print(filename + ".ket:FAILED")
print(diff)

files = [
"ket-reaction-arrow",
]
files = ["ket-reaction-arrow", "empty_apid"]

files.sort()
for filename in files:
rc = indigo.loadReactionFromFile(os.path.join(root_rea, filename + ".ket"))
ket = rc.rxnfile()
# with open(os.path.join(ref_path, filename) + ".mol", "w") as file:
# file.write(ket)

with open(os.path.join(ref_path, filename) + ".mol", "r") as file:
ket_ref = file.read()
ket = rc.rxnfile()
diff = find_diff(ket_ref, ket)
if not diff:
print(filename + ".ket:SUCCEED")
Expand Down
154 changes: 154 additions & 0 deletions api/tests/integration/tests/formats/reactions/empty_apid.ket
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"root": {
"nodes": [
{
"$ref": "mol0"
},
{
"type": "arrow",
"data": {
"mode": "open-angle",
"pos": [
{
"x": 3.1,
"y": -4.575,
"z": 0
},
{
"x": 7.804253394535632,
"y": -4.575,
"z": 0
}
]
}
}
]
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
9.325000000000001,
-3.875,
0
]
},
{
"label": "O",
"location": [
9.825003666733892,
-3.008993649216902,
0
]
},
{
"label": "O",
"location": [
9.825003666733892,
-4.741006350783098,
0
]
},
{
"label": "C",
"location": [
10.825011000201673,
-3.008993649216902,
0
]
},
{
"label": "C",
"location": [
11.825018333669453,
-3.008993649216902,
0
]
},
{
"label": "C",
"location": [
10.825011000201673,
-2.008986315749121,
0
]
},
{
"label": "C",
"location": [
10.825011000201673,
-4.009000982684682,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
},
{
"type": 2,
"atoms": [
0,
2
]
},
{
"type": 1,
"atoms": [
1,
3
]
},
{
"type": 1,
"atoms": [
3,
4
]
},
{
"type": 1,
"atoms": [
3,
5
]
},
{
"type": 1,
"atoms": [
3,
6
]
}
],
"sgroups": [
{
"type": "SUP",
"atoms": [
0,
1,
2,
3,
4,
5,
6
],
"name": "Boc",
"id": 0,
"attachmentPoints": [
{
"attachmentAtom": 0,
"attachmentId": ""
}
]
}
]
}
}
31 changes: 31 additions & 0 deletions api/tests/integration/tests/formats/ref/empty_apid.mol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$RXN

-INDIGO- 0100000000

0 1
$MOL

-INDIGO-01000000002D

7 6 0 0 0 0 0 0 0 0999 V2000
9.3250 -3.8750 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
9.8250 -3.0090 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
9.8250 -4.7410 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
10.8250 -3.0090 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
11.8250 -3.0090 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
10.8250 -2.0090 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
10.8250 -4.0090 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 3 2 0 0 0 0
2 4 1 0 0 0 0
4 5 1 0 0 0 0
4 6 1 0 0 0 0
4 7 1 0 0 0 0
M STY 1 1 SUP
M SLB 1 1 1
M SAL 1 7 1 2 3 4 5 6 7
M SMT 1 Boc
M SAP 1 1 1 0
M SDI 1 4 0.0000 0.0000 0.0000 0.0000
M SDI 1 4 0.0000 0.0000 0.0000 0.0000
M END
7 changes: 5 additions & 2 deletions core/indigo-core/molecule/src/molfile_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,8 +1667,11 @@ void MolfileSaver::_writeCtab2000(Output& output, BaseMolecule& mol, bool query)
int leave_idx = 0;
if (superatom.attachment_points[j].lvidx > -1)
leave_idx = _atom_mapping[superatom.attachment_points[j].lvidx];
output.printf(" %3d %3d %c%c", _atom_mapping[superatom.attachment_points[j].aidx], leave_idx, superatom.attachment_points[j].apid[0],
superatom.attachment_points[j].apid[1]);
const int KApIdNumPlaces = 2;
std::string apid_str = superatom.attachment_points[j].apid.ptr();
if (apid_str.size() < KApIdNumPlaces)
apid_str = std::string(KApIdNumPlaces - apid_str.size(), ' ') + apid_str;
output.printf(" %3d %3d %.*s", _atom_mapping[superatom.attachment_points[j].aidx], leave_idx, KApIdNumPlaces, apid_str.c_str());
k++;
nrem--;
if ((k == 6) || (nrem == 0))
Expand Down
8 changes: 2 additions & 6 deletions utils/indigo-service/backend/service/v2/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class InputFormatSchema(Schema):
"chemical/x-daylight-smiles",
"chemical/x-cml",
"chemical/x-inchi",
"chemical/x-inchi-key",
"chemical/x-iupac",
"chemical/x-daylight-smarts",
"chemical/x-inchi-aux",
Expand Down Expand Up @@ -228,12 +229,7 @@ def sim_min_range(self, data, **kwargs):

@validates_schema
def sim_max_range(self, data, **kwargs):
print(
data,
data.get("type"),
data.get("max_sim"),
data.get("min_sim"),
)
print(data, data.get("type"), data.get("max_sim"), data.get("min_sim"))
if (
data.get("type")
and "sim" in data.get("type")
Expand Down

0 comments on commit bdb26d4

Please sign in to comment.