diff --git a/api/tests/integration/ref/reaction/save_ket_layout_1205.py.out b/api/tests/integration/ref/reaction/save_ket_layout_1205.py.out new file mode 100644 index 0000000000..b15a278249 --- /dev/null +++ b/api/tests/integration/ref/reaction/save_ket_layout_1205.py.out @@ -0,0 +1 @@ +Test passed \ No newline at end of file diff --git a/api/tests/integration/tests/reaction/reactions/issue_1205.ket b/api/tests/integration/tests/reaction/reactions/issue_1205.ket new file mode 100644 index 0000000000..ad99a57f5e --- /dev/null +++ b/api/tests/integration/tests/reaction/reactions/issue_1205.ket @@ -0,0 +1 @@ +{"root":{"nodes":[{"$ref":"mol0"},{"$ref":"mol1"},{"$ref":"mol2"},{"$ref":"mol3"},{"type":"arrow","data":{"mode":"open-angle","pos":[{"x":10.515000343322754,"y":-8.324899673461914,"z":0.0},{"x":15.034599304199219,"y":-8.274900436401368,"z":0.0}]}}]},"mol0":{"type":"molecule","atoms":[{"label":"C","location":[7.7846999168396,-7.824999809265137,0.0]},{"label":"C","location":[9.515000343322754,-7.82450008392334,0.0]},{"label":"C","location":[8.65149974822998,-7.324900150299072,0.0]},{"label":"C","location":[9.515000343322754,-8.825400352478028,0.0]},{"label":"C","location":[7.7846999168396,-8.829899787902832,0.0]},{"label":"C","location":[8.65369987487793,-9.324899673461914,0.0]}],"bonds":[{"type":2,"atoms":[2,0]},{"type":2,"atoms":[3,1]},{"type":1,"atoms":[0,4]},{"type":1,"atoms":[1,2]},{"type":2,"atoms":[4,5]},{"type":1,"atoms":[5,3]}]},"mol1":{"type":"molecule","atoms":[{"label":"C","location":[16.03459930419922,-7.775000095367432,0.0]},{"label":"C","location":[17.76499938964844,-7.774499893188477,0.0]},{"label":"C","location":[16.90139961242676,-7.274899959564209,0.0]},{"label":"C","location":[17.76499938964844,-8.775400161743164,0.0]},{"label":"C","location":[16.03459930419922,-8.779899597167969,0.0]},{"label":"C","location":[16.903600692749025,-9.274900436401368,0.0]}],"bonds":[{"type":2,"atoms":[2,0]},{"type":2,"atoms":[3,1]},{"type":1,"atoms":[0,4]},{"type":1,"atoms":[1,2]},{"type":2,"atoms":[4,5]},{"type":1,"atoms":[5,3]}]},"mol2":{"type":"molecule","atoms":[{"label":"Cl","location":[12.974800109863282,-8.824899673461914,0.0]}],"bonds":[]},"mol3":{"type":"molecule","atoms":[{"label":"N","location":[12.549799919128418,-7.724899768829346,0.0]}],"bonds":[]}} diff --git a/api/tests/integration/tests/reaction/reactions/issue_1205.rxn b/api/tests/integration/tests/reaction/reactions/issue_1205.rxn new file mode 100644 index 0000000000..51360a94ae --- /dev/null +++ b/api/tests/integration/tests/reaction/reactions/issue_1205.rxn @@ -0,0 +1,55 @@ +$RXN + + -INDIGO- 0808231408 + + 1 1 2 +$MOL + + -INDIGO-08082314082D + + 6 6 0 0 0 0 0 0 0 0999 V2000 + 7.7847 -7.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 9.5150 -7.8245 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 8.6515 -7.3249 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 9.5150 -8.8254 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 7.7847 -8.8299 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 8.6537 -9.3249 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 +$MOL + + -INDIGO-08082314082D + + 6 6 0 0 0 0 0 0 0 0999 V2000 + 16.0346 -7.7750 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 17.7650 -7.7745 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 16.9014 -7.2749 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 17.7650 -8.7754 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 16.0346 -8.7799 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 16.9036 -9.2749 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 +$MOL + + -INDIGO-08082314082D + + 1 0 0 0 0 0 0 0 0 0999 V2000 + 12.9748 -8.8249 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0 +M END +$MOL + + -INDIGO-08082314082D + + 1 0 0 0 0 0 0 0 0 0999 V2000 + 12.5498 -7.7249 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 +M END diff --git a/api/tests/integration/tests/reaction/save_ket_layout_1205.py b/api/tests/integration/tests/reaction/save_ket_layout_1205.py new file mode 100644 index 0000000000..a6faeb815b --- /dev/null +++ b/api/tests/integration/tests/reaction/save_ket_layout_1205.py @@ -0,0 +1,28 @@ +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 * + +indigo = Indigo() +r1 = indigo.loadReactionFromFile( + joinPathPy("reactions/issue_1205.rxn", __file__) +) +with open(joinPathPy("reactions/issue_1205.ket", __file__), "r") as file: + ket_ref = file.read() +ket_out = r1.json() +diff = find_diff(ket_ref, ket_out) +if diff: + print("Difference found:\n", diff) +else: + print("Test passed") diff --git a/core/indigo-core/common/math/algebra.h b/core/indigo-core/common/math/algebra.h index 310e5d05e5..c59b7db90c 100644 --- a/core/indigo-core/common/math/algebra.h +++ b/core/indigo-core/common/math/algebra.h @@ -21,6 +21,7 @@ #include #include +#include #include "base_c/defs.h" #include "base_cpp/exception.h" @@ -59,6 +60,16 @@ namespace indigo float x, y; + static constexpr auto min_coord() + { + return std::numeric_limits::min(); + } + + static constexpr auto max_coord() + { + return std::numeric_limits::max(); + } + inline void set(float xx, float yy) { x = xx; diff --git a/core/indigo-core/reaction/src/reaction_json_saver.cpp b/core/indigo-core/reaction/src/reaction_json_saver.cpp index 406c84ddc3..c225032349 100644 --- a/core/indigo-core/reaction/src/reaction_json_saver.cpp +++ b/core/indigo-core/reaction/src/reaction_json_saver.cpp @@ -36,20 +36,23 @@ IMPL_ERROR(ReactionJsonSaver, "reaction KET saver"); void ReactionJsonSaver::_fixLayout(BaseReaction& rxn) { - Vec2f rmax, pmin; + 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 = rxn.reactantBegin(); i != rxn.reactantEnd(); i = rxn.reactantNext(i)) { rxn.getBaseMolecule(i).getBoundingBox(bb); rmax.max(bb.rightTop()); } + // Calculate leftBottom of product bounding box for (int i = rxn.productBegin(); i != rxn.productEnd(); i = rxn.productNext(i)) { rxn.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) { ReactionLayout rl(rxn, true);