Skip to content

Commit

Permalink
Backmerge: #2318 - The reaction with retrosynthetic arrow is displaye…
Browse files Browse the repository at this point in the history
…d not correct after clicking on Aromatize (#2394)
  • Loading branch information
AliaksandrDziarkach authored Sep 17, 2024
1 parent 04356f1 commit 2772c0c
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 78 deletions.
2 changes: 2 additions & 0 deletions api/c/indigo/src/indigo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ void Indigo::initReactionJsonSaver(ReactionJsonSaver& saver)
{
saver.add_stereo_desc = json_saving_add_stereo_desc;
saver.pretty_json = json_saving_pretty;
saver.use_native_precision = json_use_native_precision;
}

void Indigo::initReactionJsonSaver(PathwayReactionJsonSaver& saver)
{
saver.add_stereo_desc = json_saving_add_stereo_desc;
saver.pretty_json = json_saving_pretty;
saver.use_native_precision = json_use_native_precision;
}

void Indigo::initRxnfileSaver(RxnfileSaver& saver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ ket_simple_arrow_retro_arrow_sum_of_products.smi:SUCCEED
output format: SMARTS
ket_simple_arrow_retro_arrow_sum_of_products.smarts:SUCCEED
output format: CML
ket_simple_arrow_retro_arrow_sum_of_products.cml:SUCCEED
ket_simple_arrow_retro_arrow_sum_of_products.cml:SUCCEED
issue 2318
ket_simple_arrow_retro_arrow_sum_of_products.cml:SUCCEED
6 changes: 3 additions & 3 deletions api/tests/integration/tests/basic/ref/issue_1576.ket
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@
}
],
"stereoFlagPosition": {
"x": 3.0,
"y": 1.0,
"z": 0.0
"x": 3.000000,
"y": 1.000000,
"z": 0.000000
}
}
}
15 changes: 15 additions & 0 deletions api/tests/integration/tests/formats/ket_retrosynthetic_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,18 @@ def getCML(reaction):
else:
print(filename + ":FAILED")
print(diff)

print("issue 2318")
indigo.setOption("json-use-native-precision", "1")
fname = os.path.join(root_rea, "ket_retro_arrow.ket")
rxn = indigo.loadReactionFromFile(fname)
# with open(fname, "w") as file:
# file.write(rxn.json())
with open(fname, "r") as file:
ref_json = file.read()
diff = find_diff(ref_json, rxn.json())
if not diff:
print(filename + ":SUCCEED")
else:
print(filename + ":FAILED")
print(diff)
54 changes: 26 additions & 28 deletions api/tests/integration/tests/formats/reactions/ket_retro_arrow.ket
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,53 @@
"mode": "retrosynthetic",
"pos": [
{
"x": 17.023752881253245,
"x": 17.023752,
"y": -8.175,
"z": 0
"z": 0.0
},
{
"x": 18.750181019051478,
"x": 18.750181,
"y": -8.175,
"z": 0
"z": 0.0
}
]
}
}
],
"connections": [],
"templates": []
]
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
15.246467820890256,
-9.074998653426483,
0
15.246468,
-9.074999,
0.0
]
},
{
"label": "C",
"location": [
15.246467820890256,
-8.075000455066647,
0
15.246468,
-8.075001,
0.0
]
},
{
"label": "C",
"location": [
14.38044431997395,
-7.5750013465735195,
0
14.380445,
-7.575001,
0.0
]
},
{
"label": "N",
"location": [
16.11249117279522,
-7.5750013465735195,
0
16.112492,
-7.575001,
0.0
]
}
],
Expand Down Expand Up @@ -95,25 +93,25 @@
{
"label": "O",
"location": [
19.987496757286365,
-8.075000455066647,
0
19.987497,
-8.075001,
0.0
]
},
{
"label": "C",
"location": [
20.853495224297802,
-8.574999544933355,
0
20.853495,
-8.575,
0.0
]
},
{
"label": "O",
"location": [
21.71955568002605,
-8.075000455066647,
0
21.719555,
-8.075001,
0.0
]
}
],
Expand Down
39 changes: 28 additions & 11 deletions core/indigo-core/layout/src/reaction_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,38 @@ void ReactionLayout::fixLayout()

Vec2f rmax{Vec2f::min_coord(), Vec2f::min_coord()}, pmin{Vec2f::max_coord(), Vec2f::max_coord()};
Rect2f bb;
// Calculate rightTop of reactant bounding box

for (int i = _r.reactantBegin(); i != _r.reactantEnd(); i = _r.reactantNext(i))
if (_r.isRetrosyntetic())
{
_r.getBaseMolecule(i).getBoundingBox(bb);
rmax.max(bb.rightTop());
}
// Calculate rightTop of product bounding box
for (int i = _r.productBegin(); i != _r.productEnd(); i = _r.productNext(i))
{
_r.getBaseMolecule(i).getBoundingBox(bb);
rmax.max(bb.rightTop());
}

// Calculate leftBottom of product bounding box
for (int i = _r.productBegin(); i != _r.productEnd(); i = _r.productNext(i))
{
_r.getBaseMolecule(i).getBoundingBox(bb);
pmin.min(bb.leftBottom());
// Calculate leftBottom of reactant bounding box
for (int i = _r.reactantBegin(); i != _r.reactantEnd(); i = _r.reactantNext(i))
{
_r.getBaseMolecule(i).getBoundingBox(bb);
pmin.min(bb.leftBottom());
}
}
else
{
// Calculate rightTop of reactant bounding box
for (int i = _r.reactantBegin(); i != _r.reactantEnd(); i = _r.reactantNext(i))
{
_r.getBaseMolecule(i).getBoundingBox(bb);
rmax.max(bb.rightTop());
}

// Calculate leftBottom of product bounding box
for (int i = _r.productBegin(); i != _r.productEnd(); i = _r.productNext(i))
{
_r.getBaseMolecule(i).getBoundingBox(bb);
pmin.min(bb.leftBottom());
}
}
// if left side of product bb at left of right side of reactant bb - fix layout
if (rmax.x > pmin.x)
{
Expand Down
2 changes: 1 addition & 1 deletion core/indigo-core/molecule/molecule_json_saver.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace indigo
void saveMolecule(BaseMolecule& bmol);
void saveMolecule(BaseMolecule& bmol, JsonWriter& writer);

static void saveMetaData(JsonWriter& writer, MetaDataStorage& meta);
void saveMetaData(JsonWriter& writer, MetaDataStorage& meta);
static std::string monomerId(const TGroup& tg);
static std::string monomerKETClass(const std::string& class_name);
static std::string monomerHELMClass(const std::string& class_name);
Expand Down
Loading

0 comments on commit 2772c0c

Please sign in to comment.