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

#1205 Fix reaction json saver layout calculation #1216

Merged
merged 2 commits into from
Aug 9, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test passed
Original file line number Diff line number Diff line change
@@ -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":[]}}
55 changes: 55 additions & 0 deletions api/tests/integration/tests/reaction/reactions/issue_1205.rxn
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions api/tests/integration/tests/reaction/save_ket_layout_1205.py
Original file line number Diff line number Diff line change
@@ -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")
11 changes: 11 additions & 0 deletions core/indigo-core/common/math/algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <algorithm>
#include <cmath>
#include <limits>

#include "base_c/defs.h"
#include "base_cpp/exception.h"
Expand Down Expand Up @@ -59,6 +60,16 @@ namespace indigo

float x, y;

static constexpr auto min_coord()
{
return std::numeric_limits<decltype(x)>::min();
}

static constexpr auto max_coord()
{
return std::numeric_limits<decltype(x)>::max();
}

inline void set(float xx, float yy)
{
x = xx;
Expand Down
5 changes: 4 additions & 1 deletion core/indigo-core/reaction/src/reaction_json_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down