From edb4134edfa1fc4d93eccd97e83ef46f7f91f1a9 Mon Sep 17 00:00:00 2001 From: even1024 Date: Tue, 18 Jul 2023 19:18:38 +0200 Subject: [PATCH] #1113 RXN 3000 import: When importing, the structure becomes unreadable (#1178) --- .../ref/formats/rxn_no_layout.py.out | 844 ++++++++++++++++++ .../tests/basic/ref/crazystereo.ket | 108 +-- .../formats/reactions/1113-no-layout.rxn | 154 ++++ ...r_atom_attachment_point_w_leav_pnt_out.mol | 2 +- ..._atom_attachment_point_wo_leav_pnt_out.mol | 2 +- .../tests/formats/rxn_no_layout.py | 18 + .../tests/layout/ref/932-agents.ket | 142 +-- .../tests/layout/ref/reaction_layout.rdf | 40 +- .../layout/src/reaction_layout.cpp | 19 +- core/indigo-core/molecule/base_molecule.h | 1 + core/indigo-core/molecule/ket_commons.h | 1 + .../molecule/src/base_molecule.cpp | 13 + .../reaction/reaction_json_loader.h | 1 - .../reaction/reaction_json_saver.h | 2 + .../reaction/src/reaction_json_loader.cpp | 11 +- .../reaction/src/reaction_json_saver.cpp | 82 +- 16 files changed, 1249 insertions(+), 191 deletions(-) create mode 100644 api/tests/integration/ref/formats/rxn_no_layout.py.out create mode 100644 api/tests/integration/tests/formats/reactions/1113-no-layout.rxn create mode 100644 api/tests/integration/tests/formats/rxn_no_layout.py diff --git a/api/tests/integration/ref/formats/rxn_no_layout.py.out b/api/tests/integration/ref/formats/rxn_no_layout.py.out new file mode 100644 index 0000000000..8419bece36 --- /dev/null +++ b/api/tests/integration/ref/formats/rxn_no_layout.py.out @@ -0,0 +1,844 @@ +1113-no-layout.rxn +{ + "root": { + "nodes": [ + { + "$ref": "mol0" + }, + { + "$ref": "mol1" + }, + { + "$ref": "mol2" + }, + { + "$ref": "mol3" + }, + { + "$ref": "mol4" + }, + { + "$ref": "mol5" + }, + { + "$ref": "mol6" + }, + { + "$ref": "mol7" + }, + { + "type": "plus", + "location": [ + 5.2510833740234379, + 0.0, + 0.0 + ] + }, + { + "type": "plus", + "location": [ + 12.91125774383545, + 0.0, + 0.0 + ] + }, + { + "type": "plus", + "location": [ + 18.638530731201173, + 0.0, + 0.0 + ] + }, + { + "type": "plus", + "location": [ + 24.1688289642334, + 0.0, + 0.0 + ] + }, + { + "type": "plus", + "location": [ + 28.737014770507814, + 0.0, + 0.0 + ] + }, + { + "type": "plus", + "location": [ + 38.702880859375, + 0.0, + 0.0 + ] + }, + { + "type": "arrow", + "data": { + "mode": "open-angle", + "pos": [ + { + "x": 32.09308624267578, + "y": 0.0, + "z": 0.0 + }, + { + "x": 33.19913864135742, + "y": 0.0, + "z": 0.0 + } + ] + } + } + ] + }, + "mol0": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 1.5023635625839234, + 0.8676860332489014, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 3.0010616779327394, + 0.0030012130737304689, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 2.5030517578125, + 0.8673515319824219, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 2.500718593597412, + -0.8640168309211731, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 1.0000206232070926, + -0.002666711807250977, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 1.50503146648407, + -0.8656835556030273, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 1.0023539066314698, + 1.7337028980255128, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 1.0083551406860352, + -1.7337028980255128, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 0.0, + -0.005331993103027344, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 4.0010833740234379, + 0.002666711807250977, + 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 + ] + }, + { + "type": 1, + "atoms": [ + 0, + 6 + ] + }, + { + "type": 1, + "atoms": [ + 5, + 7 + ] + }, + { + "type": 1, + "atoms": [ + 4, + 8 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 9 + ] + } + ] + }, + "mol1": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 8.003446578979493, + 0.8676860332489014, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 9.502144813537598, + 0.0030012130737304689, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 9.004135131835938, + 0.8673515319824219, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 9.001802444458008, + -0.8640168309211731, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 7.50110387802124, + -0.002666711807250977, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 8.006114959716797, + -0.8656835556030273, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 7.503437042236328, + 1.7337028980255128, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 7.509438514709473, + -1.7337028980255128, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 6.5010833740234379, + -0.005331993103027344, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 10.502166748046877, + 0.002666711807250977, + 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 + ] + }, + { + "type": 1, + "atoms": [ + 0, + 6 + ] + }, + { + "type": 1, + "atoms": [ + 5, + 7 + ] + }, + { + "type": 1, + "atoms": [ + 4, + 8 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 9 + ] + } + ] + }, + "mol2": { + "type": "molecule", + "atoms": [ + { + "label": "O", + "location": [ + 15.320348739624024, + 0.0, + 0.0 + ] + } + ], + "bonds": [] + }, + "mol3": { + "type": "molecule", + "atoms": [ + { + "label": "O", + "location": [ + 21.95671272277832, + 0.0, + 0.0 + ] + } + ], + "bonds": [] + }, + "mol4": { + "type": "molecule", + "atoms": [ + { + "label": "O", + "location": [ + 26.38094520568848, + 0.0, + 0.0 + ], + "charge": 2 + }, + { + "label": "O", + "location": [ + 27.38096427917481, + 0.0, + 0.0 + ] + } + ], + "bonds": [ + { + "type": 2, + "atoms": [ + 0, + 1 + ] + } + ] + }, + "mol5": { + "type": "molecule", + "atoms": [ + { + "label": "O", + "location": [ + 30.093067169189458, + 0.0, + 0.0 + ] + }, + { + "label": "O", + "location": [ + 31.09308624267578, + 0.0, + 0.0 + ] + } + ], + "bonds": [ + { + "type": 2, + "atoms": [ + 0, + 1 + ] + } + ] + }, + "mol6": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 36.20417785644531, + 0.8676860332489014, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 37.702880859375, + 0.0030012130737304689, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 37.20486831665039, + 0.8673515319824219, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 37.20253372192383, + -0.8640168309211731, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 35.70183944702149, + -0.002666711807250977, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 36.20684814453125, + -0.8656835556030273, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 35.71017074584961, + -1.7337028980255128, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 34.70181655883789, + -0.005331993103027344, + 0.0 + ] + }, + { + "label": "O", + "location": [ + 34.19913864135742, + 0.859018087387085, + 0.0 + ] + }, + { + "label": "O", + "location": [ + 34.20413589477539, + -0.873016893863678, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 35.70417022705078, + 1.7337028980255128, + 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 + ] + }, + { + "type": 1, + "atoms": [ + 5, + 6 + ] + }, + { + "type": 1, + "atoms": [ + 4, + 7 + ] + }, + { + "type": 2, + "atoms": [ + 7, + 8 + ] + }, + { + "type": 1, + "atoms": [ + 7, + 9 + ] + }, + { + "type": 1, + "atoms": [ + 0, + 10 + ] + } + ] + }, + "mol7": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 41.70792007446289, + 0.8676860332489014, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 43.20661926269531, + 0.0030012130737304689, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 42.70861053466797, + 0.8673515319824219, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 42.706275939941409, + -0.8640168309211731, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 41.20558166503906, + -0.002666711807250977, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 41.71059036254883, + -0.8656835556030273, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 41.21391296386719, + -1.7337028980255128, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 40.20555877685547, + -0.005331993103027344, + 0.0 + ] + }, + { + "label": "O", + "location": [ + 39.702880859375, + 0.859018087387085, + 0.0 + ] + }, + { + "label": "O", + "location": [ + 39.70787811279297, + -0.873016893863678, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 41.20791244506836, + 1.7337028980255128, + 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 + ] + }, + { + "type": 1, + "atoms": [ + 5, + 6 + ] + }, + { + "type": 1, + "atoms": [ + 4, + 7 + ] + }, + { + "type": 2, + "atoms": [ + 7, + 8 + ] + }, + { + "type": 1, + "atoms": [ + 7, + 9 + ] + }, + { + "type": 1, + "atoms": [ + 0, + 10 + ] + } + ] + } +} diff --git a/api/tests/integration/tests/basic/ref/crazystereo.ket b/api/tests/integration/tests/basic/ref/crazystereo.ket index c3093810b8..fe4a79bc83 100644 --- a/api/tests/integration/tests/basic/ref/crazystereo.ket +++ b/api/tests/integration/tests/basic/ref/crazystereo.ket @@ -13,13 +13,13 @@ "mode": "open-angle", "pos": [ { - "x": -5.879899978637695, - "y": 0.5597999691963196, + "x": 4.464198589324951, + "y": 0.0, "z": 0.0 }, { - "x": -3.7695000171661379, - "y": 0.8544500470161438, + "x": 5.464198589324951, + "y": 0.0, "z": 0.0 } ] @@ -33,80 +33,80 @@ { "label": "C", "location": [ - -8.308899879455567, - 0.9722999930381776, + 1.7320992946624756, + 0.49999362230300906, 0.0 ] }, { "label": "C", "location": [ - -9.02340030670166, - 1.3847999572753909, + 0.8660491108894348, + 0.9999874234199524, 0.0 ] }, { "label": "C", "location": [ - -9.737899780273438, - 0.9722999930381776, + 0.0, + 0.49999362230300906, 0.0 ] }, { "label": "C", "location": [ - -9.737899780273438, - 0.14730000495910645, + 0.0, + -0.4999937117099762, 0.0 ] }, { "label": "C", "location": [ - -9.02340030670166, - -0.2651999890804291, + 0.8660491108894348, + -0.9999874234199524, 0.0 ] }, { "label": "C", "location": [ - -8.308899879455567, - 0.14730000495910645, + 1.7320992946624756, + -0.4999937117099762, 0.0 ] }, { "label": "C", "location": [ - -7.594500064849854, - -0.2651999890804291, + 2.5980277061462404, + -0.9999874234199524, 0.0 ] }, { "label": "C", "location": [ - -6.879899978637695, - 0.14730000495910645, + 3.464198589324951, + -0.4999937117099762, 0.0 ] }, { "label": "C", "location": [ - -6.879899978637695, - 0.9722999930381776, + 3.464198589324951, + 0.49999362230300906, 0.0 ] }, { "label": "C", "location": [ - -7.594500064849854, - 1.3847999572753909, + 2.5980277061462404, + 0.9999874234199524, 0.0 ] } @@ -197,56 +197,56 @@ { "label": "C", "location": [ - 0.08839999884366989, - 2.710700035095215, + 9.92827606201172, + 2.249971866607666, 0.0 ] }, { "label": "C", "location": [ - -0.6261000037193298, - 2.2981998920440676, + 9.062226295471192, + 1.7499775886535645, 0.0 ] }, { "label": "C", "location": [ - -0.6261000037193298, - 1.4731999635696412, + 9.062226295471192, + 0.7499902248382568, 0.0 ] }, { "label": "C", "location": [ - 0.08839999884366989, - 1.0607000589370728, + 9.92827606201172, + 0.2499966621398926, 0.0 ] }, { "label": "C", "location": [ - 0.8029000163078308, - 1.4731999635696412, + 10.794326782226565, + 0.7499902248382568, 0.0 ] }, { "label": "C", "location": [ - 0.8029000163078308, - 2.2981998920440676, + 10.794326782226565, + 1.7499775886535645, 0.0 ] }, { "label": "C", "location": [ - -1.340499997138977, - 1.0607000589370728, + 8.196298599243164, + 0.2499966621398926, 0.0 ], "stereoLabel": "&1" @@ -254,64 +254,64 @@ { "label": "C", "location": [ - -2.055000066757202, - 1.4731999635696412, + 7.3302483558654789, + 0.7499902248382568, 0.0 ] }, { "label": "C", "location": [ - -2.769500017166138, - 1.0607000589370728, + 6.464198589324951, + 0.2499966621398926, 0.0 ] }, { "label": "C", "location": [ - -2.769500017166138, - 0.23569999635219578, + 6.464198589324951, + -0.7499908208847046, 0.0 ] }, { "label": "C", "location": [ - -2.055000066757202, - -0.1767999976873398, + 7.3302483558654789, + -1.2499845027923585, 0.0 ] }, { "label": "C", "location": [ - -1.340499997138977, - 0.23569999635219578, + 8.196298599243164, + -0.7499908208847046, 0.0 ] }, { "label": "P", "location": [ - -0.6261000037193298, - -0.1767999976873398, + 9.062226295471192, + -1.2499845027923585, 0.0 ] }, { "label": "C", "location": [ - 0.1988999992609024, - -0.1767999976873398, + 10.06221389770508, + -1.2499845027923585, 0.0 ] }, { "label": "C", "location": [ - -0.6261000037193298, - -1.0017999410629273, + 9.062226295471192, + -2.249971866607666, 0.0 ] } diff --git a/api/tests/integration/tests/formats/reactions/1113-no-layout.rxn b/api/tests/integration/tests/formats/reactions/1113-no-layout.rxn new file mode 100644 index 0000000000..58f2035cf9 --- /dev/null +++ b/api/tests/integration/tests/formats/reactions/1113-no-layout.rxn @@ -0,0 +1,154 @@ +$RXN V3000 + + ChemDraw12232218102D + +M V30 COUNTS 6 2 +M V30 BEGIN REACTANT +M V30 BEGIN CTAB +M V30 COUNTS 10 10 0 0 0 +M V30 BEGIN ATOM +M V30 1 C -0.410997 0.715841 0.000000 0 +M V30 2 C 0.825429 0.002476 0.000000 0 +M V30 3 C 0.414571 0.715565 0.000000 0 +M V30 4 C 0.412646 -0.712814 0.000000 0 +M V30 5 C -0.825430 -0.002200 0.000000 0 +M V30 6 C -0.408796 -0.714189 0.000000 0 +M V30 7 C -0.823505 1.430305 0.000000 0 +M V30 8 C -0.818554 -1.430305 0.000000 0 +M V30 9 C -1.650447 -0.004399 0.000000 0 +M V30 10 C 1.650447 0.002200 0.000000 0 +M V30 END ATOM +M V30 BEGIN BOND +M V30 1 2 3 1 +M V30 2 2 4 2 +M V30 3 1 1 5 +M V30 4 1 2 3 +M V30 5 2 5 6 +M V30 6 1 6 4 +M V30 7 1 1 7 +M V30 8 1 6 8 +M V30 9 1 5 9 +M V30 10 1 2 10 +M V30 END BOND +M V30 END CTAB +M V30 BEGIN CTAB +M V30 COUNTS 10 10 0 0 0 +M V30 BEGIN ATOM +M V30 1 C -0.410997 0.715841 0.000000 0 +M V30 2 C 0.825429 0.002476 0.000000 0 +M V30 3 C 0.414571 0.715565 0.000000 0 +M V30 4 C 0.412646 -0.712814 0.000000 0 +M V30 5 C -0.825430 -0.002200 0.000000 0 +M V30 6 C -0.408796 -0.714189 0.000000 0 +M V30 7 C -0.823505 1.430305 0.000000 0 +M V30 8 C -0.818554 -1.430305 0.000000 0 +M V30 9 C -1.650447 -0.004399 0.000000 0 +M V30 10 C 1.650447 0.002200 0.000000 0 +M V30 END ATOM +M V30 BEGIN BOND +M V30 1 2 3 1 +M V30 2 2 4 2 +M V30 3 1 1 5 +M V30 4 1 2 3 +M V30 5 2 5 6 +M V30 6 1 6 4 +M V30 7 1 1 7 +M V30 8 1 6 8 +M V30 9 1 5 9 +M V30 10 1 2 10 +M V30 END BOND +M V30 END CTAB +M V30 BEGIN CTAB +M V30 COUNTS 1 0 0 0 0 +M V30 BEGIN ATOM +M V30 1 O 0.000000 0.000000 0.000000 0 +M V30 END ATOM +M V30 END CTAB +M V30 BEGIN CTAB +M V30 COUNTS 1 0 0 0 0 +M V30 BEGIN ATOM +M V30 1 O 0.000000 0.000000 0.000000 0 +M V30 END ATOM +M V30 END CTAB +M V30 BEGIN CTAB +M V30 COUNTS 2 1 0 0 0 +M V30 BEGIN ATOM +M V30 1 O -0.412508 0.000000 0.000000 0 CHG=2 +M V30 2 O 0.412508 0.000000 0.000000 0 +M V30 END ATOM +M V30 BEGIN BOND +M V30 1 2 1 2 +M V30 END BOND +M V30 END CTAB +M V30 BEGIN CTAB +M V30 COUNTS 2 1 0 0 0 +M V30 BEGIN ATOM +M V30 1 O -0.412508 0.000000 0.000000 0 +M V30 2 O 0.412508 0.000000 0.000000 0 +M V30 END ATOM +M V30 BEGIN BOND +M V30 1 2 1 2 +M V30 END BOND +M V30 END CTAB +M V30 END REACTANT +M V30 BEGIN PRODUCT +M V30 BEGIN CTAB +M V30 COUNTS 11 11 0 0 0 +M V30 BEGIN ATOM +M V30 1 C 0.208865 0.715841 0.000000 0 +M V30 2 C 1.445293 0.002476 0.000000 0 +M V30 3 C 1.034434 0.715565 0.000000 0 +M V30 4 C 1.032509 -0.712814 0.000000 0 +M V30 5 C -0.205565 -0.002200 0.000000 0 +M V30 6 C 0.211067 -0.714189 0.000000 0 +M V30 7 C -0.198690 -1.430305 0.000000 0 +M V30 8 C -1.030584 -0.004399 0.000000 0 +M V30 9 O -1.445293 0.708690 0.000000 0 +M V30 10 O -1.441169 -0.720239 0.000000 0 +M V30 11 C -0.203641 1.430305 0.000000 0 +M V30 END ATOM +M V30 BEGIN BOND +M V30 1 2 3 1 +M V30 2 2 4 2 +M V30 3 1 1 5 +M V30 4 1 2 3 +M V30 5 2 5 6 +M V30 6 1 6 4 +M V30 7 1 6 7 +M V30 8 1 5 8 +M V30 9 2 8 9 +M V30 10 1 8 10 +M V30 11 1 1 11 +M V30 END BOND +M V30 END CTAB +M V30 BEGIN CTAB +M V30 COUNTS 11 11 0 0 0 +M V30 BEGIN ATOM +M V30 1 C 0.208865 0.715841 0.000000 0 +M V30 2 C 1.445293 0.002476 0.000000 0 +M V30 3 C 1.034434 0.715565 0.000000 0 +M V30 4 C 1.032509 -0.712814 0.000000 0 +M V30 5 C -0.205565 -0.002200 0.000000 0 +M V30 6 C 0.211067 -0.714189 0.000000 0 +M V30 7 C -0.198690 -1.430305 0.000000 0 +M V30 8 C -1.030584 -0.004399 0.000000 0 +M V30 9 O -1.445293 0.708690 0.000000 0 +M V30 10 O -1.441169 -0.720239 0.000000 0 +M V30 11 C -0.203641 1.430305 0.000000 0 +M V30 END ATOM +M V30 BEGIN BOND +M V30 1 2 3 1 +M V30 2 2 4 2 +M V30 3 1 1 5 +M V30 4 1 2 3 +M V30 5 2 5 6 +M V30 6 1 6 4 +M V30 7 1 6 7 +M V30 8 1 5 8 +M V30 9 2 8 9 +M V30 10 1 8 10 +M V30 11 1 1 11 +M V30 END BOND +M V30 END CTAB +M V30 END PRODUCT +M END diff --git a/api/tests/integration/tests/formats/ref/super_atom_attachment_point_w_leav_pnt_out.mol b/api/tests/integration/tests/formats/ref/super_atom_attachment_point_w_leav_pnt_out.mol index a2b6a3c03f..23b62649df 100644 --- a/api/tests/integration/tests/formats/ref/super_atom_attachment_point_w_leav_pnt_out.mol +++ b/api/tests/integration/tests/formats/ref/super_atom_attachment_point_w_leav_pnt_out.mol @@ -1,5 +1,5 @@ - -INDIGO-06302312372D + -INDIGO-07182314162D 0 0 0 0 0 0 0 0 0 0 0 V3000 M V30 BEGIN CTAB diff --git a/api/tests/integration/tests/formats/ref/super_atom_attachment_point_wo_leav_pnt_out.mol b/api/tests/integration/tests/formats/ref/super_atom_attachment_point_wo_leav_pnt_out.mol index 0255dd3805..d38a251b7e 100644 --- a/api/tests/integration/tests/formats/ref/super_atom_attachment_point_wo_leav_pnt_out.mol +++ b/api/tests/integration/tests/formats/ref/super_atom_attachment_point_wo_leav_pnt_out.mol @@ -1,5 +1,5 @@ - -INDIGO-06302312372D + -INDIGO-07182314162D 0 0 0 0 0 0 0 0 0 0 0 V3000 M V30 BEGIN CTAB diff --git a/api/tests/integration/tests/formats/rxn_no_layout.py b/api/tests/integration/tests/formats/rxn_no_layout.py new file mode 100644 index 0000000000..4a013d4629 --- /dev/null +++ b/api/tests/integration/tests/formats/rxn_no_layout.py @@ -0,0 +1,18 @@ +import os +import sys + +sys.path.append( + os.path.normpath( + os.path.join(os.path.abspath(__file__), "..", "..", "..", "common") + ) +) + +from env_indigo import * # noqa + +indigo = Indigo() +indigo.setOption("json-saving-pretty", True) +root_rxn = joinPathPy("reactions/", __file__) +filename = "1113-no-layout.rxn" +print(filename) +rxn = indigo.loadReactionFromFile(os.path.join(root_rxn, filename)) +print(rxn.json()) diff --git a/api/tests/integration/tests/layout/ref/932-agents.ket b/api/tests/integration/tests/layout/ref/932-agents.ket index f5d13d6f83..132c9aa080 100644 --- a/api/tests/integration/tests/layout/ref/932-agents.ket +++ b/api/tests/integration/tests/layout/ref/932-agents.ket @@ -43,31 +43,31 @@ { "type": "plus", "location": [ - 3.3999998569488527, - -0.10717970132827759, + 2.96875, + -0.06698718667030335, 0.0 ] }, { "type": "plus", "location": [ - 6.199999809265137, - -0.10000000149011612, + 6.65625, + 0.0, 0.0 ] }, { "type": "plus", "location": [ - 34.913841247558597, - -0.10000000149011612, + 32.26663589477539, + 0.0, 0.0 ] }, { "type": "plus", "location": [ - 41.57658004760742, + 38.11834716796875, 0.0, 0.0 ] @@ -78,12 +78,12 @@ "mode": "open-angle", "pos": [ { - "x": 9.799999237060547, - "y": -1.1920928955078126e-7, + "x": 10.375, + "y": 0.0, "z": 0.0 }, { - "x": 31.913841247558595, + "x": 28.79788589477539, "y": 0.0, "z": 0.0 } @@ -99,23 +99,23 @@ "label": "C", "location": [ 0.0, - 0.5856406092643738, + 0.3660256266593933, 0.0 ] }, { "label": "C", "location": [ - 1.5999997854232789, - 0.5856406092643738, + 1.0000001192092896, + 0.3660256266593933, 0.0 ] }, { "label": "C", "location": [ - 0.7999998927116394, - -0.800000011920929, + 0.5000000596046448, + -0.5, 0.0 ] } @@ -150,8 +150,8 @@ { "label": "S", "location": [ - 5.199999809265137, - -0.10000000149011612, + 4.9375, + 0.0, 0.0 ] } @@ -164,32 +164,32 @@ { "label": "C", "location": [ - 7.199999809265137, - 0.7999997735023499, + 8.375, + 0.5000000596046448, 0.0 ] }, { "label": "C", "location": [ - 8.799999237060547, - 0.7999997735023499, + 9.375, + 0.5000000596046448, 0.0 ] }, { "label": "C", "location": [ - 8.799999237060547, - -0.800000011920929, + 9.375, + -0.5000000596046448, 0.0 ] }, { "label": "C", "location": [ - 7.199999809265137, - -0.800000011920929, + 8.375, + -0.5000000596046448, 0.0 ] } @@ -231,8 +231,8 @@ { "label": "S", "location": [ - 33.913841247558597, - -0.10000000149011612, + 30.79788589477539, + 0.0, 0.0 ] } @@ -245,64 +245,64 @@ { "label": "C", "location": [ - 38.64521026611328, - 1.931370735168457, + 35.4424934387207, + 1.2071070671081544, 0.0 ] }, { "label": "C", "location": [ - 37.04521179199219, - 1.931370735168457, + 34.4424934387207, + 1.2071070671081544, 0.0 ] }, { "label": "C", "location": [ - 35.913841247558597, - 0.7999999523162842, + 33.73538589477539, + 0.5000001192092896, 0.0 ] }, { "label": "C", "location": [ - 35.913841247558597, - -0.7999998331069946, + 33.73538589477539, + -0.5000000596046448, 0.0 ] }, { "label": "C", "location": [ - 37.04521179199219, - -1.931370735168457, + 34.4424934387207, + -1.2071070671081544, 0.0 ] }, { "label": "C", "location": [ - 38.64521026611328, - -1.931370735168457, + 35.4424934387207, + -1.2071070671081544, 0.0 ] }, { "label": "C", "location": [ - 39.77658081054688, - -0.7999998331069946, + 36.14959716796875, + -0.5000000596046448, 0.0 ] }, { "label": "C", "location": [ - 39.77658081054688, - 0.7999999523162842, + 36.14959716796875, + 0.5000001192092896, 0.0 ] } @@ -372,8 +372,8 @@ { "label": "O", "location": [ - 43.37657928466797, - -0.10000000149011612, + 40.08709716796875, + 0.0, 0.0 ] } @@ -386,24 +386,24 @@ { "label": "C", "location": [ - 11.785640716552737, - 1.5999999046325684, + 10.760640144348145, + 1.062500238418579, 0.0 ] }, { "label": "C", "location": [ - 13.17128086090088, - 0.800000011920929, + 11.626666069030762, + 0.5625, 0.0 ] }, { "label": "C", "location": [ - 14.55692195892334, - 1.5999999046325684, + 12.492690086364746, + 1.0625, 0.0 ] } @@ -431,8 +431,8 @@ { "label": "C", "location": [ - 16.15692138671875, - 1.5, + 14.43018913269043, + 1.0, 0.0 ] } @@ -445,8 +445,8 @@ { "label": "P", "location": [ - 17.756921768188478, - 1.5, + 17.30518913269043, + 1.0, 0.0 ] } @@ -459,24 +459,24 @@ { "label": "C", "location": [ - 20.74256134033203, - 1.5999999046325684, + 19.628332138061525, + 1.062500238418579, 0.0 ] }, { "label": "C", "location": [ - 22.128202438354493, - 0.800000011920929, + 20.494356155395509, + 0.5625, 0.0 ] }, { "label": "C", "location": [ - 23.51384162902832, - 1.5999999046325684, + 21.36038398742676, + 1.0625, 0.0 ] } @@ -504,24 +504,24 @@ { "label": "C", "location": [ - 25.913841247558599, - 2.185640573501587, + 22.36038589477539, + 1.366025686264038, 0.0 ] }, { "label": "C", "location": [ - 27.51384162902832, - 2.185640573501587, + 23.36038589477539, + 1.366025686264038, 0.0 ] }, { "label": "C", "location": [ - 26.71384048461914, - 0.800000011920929, + 22.86038589477539, + 0.5, 0.0 ] } @@ -556,8 +556,8 @@ { "label": "F", "location": [ - 29.113842010498048, - 1.5, + 24.98538589477539, + 1.0, 0.0 ] } @@ -570,8 +570,8 @@ { "label": "I", "location": [ - 30.713842391967778, - 1.5, + 27.23538589477539, + 1.0, 0.0 ] } diff --git a/api/tests/integration/tests/layout/ref/reaction_layout.rdf b/api/tests/integration/tests/layout/ref/reaction_layout.rdf index 7e5db1dc40..b1bbfeebe5 100644 --- a/api/tests/integration/tests/layout/ref/reaction_layout.rdf +++ b/api/tests/integration/tests/layout/ref/reaction_layout.rdf @@ -30,12 +30,12 @@ $MOL -INDIGO-01000000002D 6 6 0 0 0 0 0 0 0 0999 V2000 - 11.6995 1.6000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 10.3138 0.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 10.3138 -0.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 11.6995 -1.6000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 13.0851 -0.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 13.0851 0.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 12.4995 1.6000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 11.1138 0.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 11.1138 -0.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 12.4995 -1.6000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 13.8851 -0.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 13.8851 0.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 2 3 2 0 0 0 0 3 4 1 0 0 0 0 @@ -48,13 +48,13 @@ $MOL -INDIGO-01000000002D 7 6 0 0 0 0 0 0 0 0999 V2000 - 16.6851 0.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 18.0708 1.2000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 19.4564 0.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 20.8420 1.2000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 22.2277 0.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 23.6133 1.2000 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0 - 19.4564 -1.2000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 17.4851 0.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 18.8708 1.2000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 20.2564 0.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 21.6420 1.2000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 23.0277 0.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 24.4133 1.2000 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0 + 20.2564 -1.2000 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 @@ -67,13 +67,13 @@ $MOL -INDIGO-01000000002D 7 7 0 0 0 0 0 0 0 0999 V2000 - 25.6133 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 26.4133 1.3856 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 28.0133 1.3856 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 28.8133 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 28.0133 -1.3856 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 26.4133 -1.3856 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 30.4133 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 26.4133 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 27.2133 1.3856 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 28.8133 1.3856 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 29.6133 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 28.8133 -1.3856 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 27.2133 -1.3856 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 31.2133 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 2 3 2 0 0 0 0 3 4 1 0 0 0 0 diff --git a/core/indigo-core/layout/src/reaction_layout.cpp b/core/indigo-core/layout/src/reaction_layout.cpp index 7a6ebcffe1..0578f0a9ef 100644 --- a/core/indigo-core/layout/src/reaction_layout.cpp +++ b/core/indigo-core/layout/src/reaction_layout.cpp @@ -32,6 +32,8 @@ ReactionLayout::ReactionLayout(BaseReaction& r, bool smart_layout) void ReactionLayout::make() { + const auto kHalfBondLength = bond_length / 2; + const auto kDoubleBondLength = bond_length * 2; // update layout of molecules, if needed if (!preserve_molecule_layout) { @@ -51,9 +53,7 @@ void ReactionLayout::make() { bool single_atom = _getMol(i).vertexCount() == 1; if (i != _r.reactantBegin()) - { - _pushSpace(line, plus_interval_factor + (single_atom ? bond_length : 0)); - } + _pushSpace(line, plus_interval_factor + (single_atom ? bond_length : kHalfBondLength)); _pushMol(line, i); } @@ -63,8 +63,8 @@ void ReactionLayout::make() { auto& mol = _getMol(i); Rect2f bbox; - mol.getBoundingBox(bbox); - _pushSpace(line, bond_length + bbox.width() / 2); + mol.getBoundingBox(bbox, Vec2f(kDoubleBondLength, kDoubleBondLength)); + _pushSpace(line, bbox.width() / 2); _pushMol(line, i, true); } _pushSpace(line, bond_length); @@ -102,12 +102,12 @@ Metalayout::LayoutItem& ReactionLayout::_pushMol(Metalayout::LayoutLine& line, i item.fragment = true; item.id = id; auto& mol = _getMol(id); - Metalayout::getBoundRect(item.min, item.max, mol); if (is_agent) { item.verticalAlign = Metalayout::LayoutItem::ItemVerticalAlign::ETop; } + Rect2f bbox; if (mol.vertexCount() == 1) { int max_h = mol.getAtomMaxH(0); @@ -115,10 +115,15 @@ Metalayout::LayoutItem& ReactionLayout::_pushMol(Metalayout::LayoutLine& line, i if (mult > kMaxSymbols) mult = kMaxSymbols; item.minScaledSize.set(0, kMinHeight); + mol.getBoundingBox(bbox, Vec2f(bond_length * mult, bond_length)); } else + { + mol.getBoundingBox(bbox, Vec2f(bond_length, bond_length)); item.minScaledSize.set(bond_length, bond_length); - + } + item.min.copy(bbox.leftBottom()); + item.max.copy(bbox.rightTop()); return item; } diff --git a/core/indigo-core/molecule/base_molecule.h b/core/indigo-core/molecule/base_molecule.h index 974e9e02ec..94d47d109d 100644 --- a/core/indigo-core/molecule/base_molecule.h +++ b/core/indigo-core/molecule/base_molecule.h @@ -443,6 +443,7 @@ namespace indigo // calc bounding box void getBoundingBox(Rect2f& bbox) const; + void getBoundingBox(Rect2f& bbox, const Vec2f& minbox) const; void getBoundingBox(Vec2f& a, Vec2f& b) const; // aliases diff --git a/core/indigo-core/molecule/ket_commons.h b/core/indigo-core/molecule/ket_commons.h index 71c5fb6e72..31e789dd4d 100644 --- a/core/indigo-core/molecule/ket_commons.h +++ b/core/indigo-core/molecule/ket_commons.h @@ -42,6 +42,7 @@ namespace indigo const uint8_t KETReagentUpArea = 1; const uint8_t KETReagentDownArea = 2; const uint8_t KETProductArea = 3; + const Vec2f MIN_MOL_SIZE = {0.5, 0.5}; const std::unordered_map KStringToCIP = {{"R", CIPDesc::R}, {"S", CIPDesc::S}, {"r", CIPDesc::r}, {"s", CIPDesc::s}, {"E", CIPDesc::E}, {"Z", CIPDesc::Z}}; diff --git a/core/indigo-core/molecule/src/base_molecule.cpp b/core/indigo-core/molecule/src/base_molecule.cpp index 9e31c83b2e..a50e2d6ed6 100644 --- a/core/indigo-core/molecule/src/base_molecule.cpp +++ b/core/indigo-core/molecule/src/base_molecule.cpp @@ -4360,6 +4360,19 @@ void BaseMolecule::getBoundingBox(Vec2f& a, Vec2f& b) const } } +void BaseMolecule::getBoundingBox(Rect2f& bbox, const Vec2f& minbox) const +{ + getBoundingBox(bbox); + if (bbox.width() < minbox.x || bbox.height() < minbox.y) + { + Vec2f center(bbox.center()); + const auto half_width = std::max(bbox.width() / 2, minbox.x / 2); + const auto half_height = std::max(bbox.height() / 2, minbox.y / 2); + Rect2f new_bbox(Vec2f(center.x - half_width, center.y - half_height), Vec2f(center.x + half_width, center.y + half_height)); + bbox.copy(new_bbox); + } +} + void BaseMolecule::getBoundingBox(Rect2f& bbox) const { Vec2f a, b; diff --git a/core/indigo-core/reaction/reaction_json_loader.h b/core/indigo-core/reaction/reaction_json_loader.h index bd4cb4c226..87df4f06d2 100644 --- a/core/indigo-core/reaction/reaction_json_loader.h +++ b/core/indigo-core/reaction/reaction_json_loader.h @@ -68,7 +68,6 @@ namespace indigo bool ignore_no_chiral_flag; const Vec2f PLUS_BBOX_SHIFT = {0.9, 0.9}; - const Vec2f MIN_MOL_SIZE = {0.5, 0.5}; const Vec2f ARROW_BBOX_SHIFT = {0.0, 0.9}; private: diff --git a/core/indigo-core/reaction/reaction_json_saver.h b/core/indigo-core/reaction/reaction_json_saver.h index 730b38588a..86221d83da 100644 --- a/core/indigo-core/reaction/reaction_json_saver.h +++ b/core/indigo-core/reaction/reaction_json_saver.h @@ -53,6 +53,8 @@ namespace indigo private: ReactionJsonSaver(const ReactionJsonSaver&); // no implicit copy static void _getBounds(BaseMolecule& mol, Vec2f& min_vec, Vec2f& max_vec, float scale); + void _fixLayout(BaseReaction& rxn); + std::unordered_map _arrow_type2string = { {ReactionComponent::ARROW_BASIC, "open-angle"}, {ReactionComponent::ARROW_FILLED_TRIANGLE, "filled-triangle"}, diff --git a/core/indigo-core/reaction/src/reaction_json_loader.cpp b/core/indigo-core/reaction/src/reaction_json_loader.cpp index ad132fe59c..a8c479ea46 100644 --- a/core/indigo-core/reaction/src/reaction_json_loader.cpp +++ b/core/indigo-core/reaction/src/reaction_json_loader.cpp @@ -232,16 +232,7 @@ void ReactionJsonLoader::parseMultipleArrowReaction(BaseReaction& rxn) BaseMolecule& mol = *component; mol.makeSubmolecule(*_pmol, filter, 0, 0); Rect2f bbox; - mol.getBoundingBox(bbox); - - if (bbox.width() < MIN_MOL_SIZE.x || bbox.height() < MIN_MOL_SIZE.y) - { - Vec2f center(bbox.center()); - const auto hw = std::max(bbox.width() / 2, MIN_MOL_SIZE.x / 2); - const auto hh = std::max(bbox.height() / 2, MIN_MOL_SIZE.y / 2); - Rect2f new_bbox(Vec2f(center.x - hw, center.y - hh), Vec2f(center.x + hw, center.y + hh)); - bbox.copy(new_bbox); - } + mol.getBoundingBox(bbox, MIN_MOL_SIZE); mol_tops.emplace_back(bbox.top(), i); mol_bottoms.emplace_back(bbox.bottom(), i); diff --git a/core/indigo-core/reaction/src/reaction_json_saver.cpp b/core/indigo-core/reaction/src/reaction_json_saver.cpp index a5eb9c9dcc..406c84ddc3 100644 --- a/core/indigo-core/reaction/src/reaction_json_saver.cpp +++ b/core/indigo-core/reaction/src/reaction_json_saver.cpp @@ -22,6 +22,7 @@ #include #include "base_cpp/output.h" +#include "layout/reaction_layout.h" #include "molecule/molecule_json_saver.h" #include "molecule/query_molecule.h" #include "reaction/reaction.h" @@ -33,9 +34,36 @@ using namespace rapidjson; IMPL_ERROR(ReactionJsonSaver, "reaction KET saver"); +void ReactionJsonSaver::_fixLayout(BaseReaction& rxn) +{ + Vec2f rmax, pmin; + Rect2f bb; + for (int i = rxn.reactantBegin(); i != rxn.reactantEnd(); i = rxn.reactantNext(i)) + { + rxn.getBaseMolecule(i).getBoundingBox(bb); + rmax.max(bb.rightTop()); + } + + for (int i = rxn.productBegin(); i != rxn.productEnd(); i = rxn.productNext(i)) + { + rxn.getBaseMolecule(i).getBoundingBox(bb); + pmin.min(bb.leftBottom()); + } + + if (rmax.x > pmin.x) + { + ReactionLayout rl(rxn, true); + rl.preserve_molecule_layout = true; + rl.make(); + } +} + void ReactionJsonSaver::_getBounds(BaseMolecule& mol, Vec2f& min_vec, Vec2f& max_vec, float scale) { - mol.getBoundingBox(min_vec, max_vec); + Rect2f bbox; + mol.getBoundingBox(bbox); + min_vec.copy(bbox.leftBottom()); + max_vec.copy(bbox.rightTop()); min_vec.scale(scale); max_vec.scale(scale); } @@ -67,17 +95,19 @@ void ReactionJsonSaver::saveReaction(BaseReaction& rxn, BaseMolecule& merged, Mo Vec2f rmin(0, 0), rmax(0, 0), pmin(0, 0), pmax(0, 0), cmin(0, 0), cmax(0, 0); bool last_single_reactant = false; bool first_single_product = false; - - if (rxn.reactantsCount() > 0) + std::unique_ptr reaction(rxn.neu()); + reaction->clone(rxn); + _fixLayout(*reaction); + if (reaction->reactantsCount() > 0) { int rcount = 1; - for (int i = rxn.reactantBegin(); i != rxn.reactantEnd(); i = rxn.reactantNext(i)) + for (int i = reaction->reactantBegin(); i != reaction->reactantEnd(); i = reaction->reactantNext(i)) { Vec2f min1, max1; - _getBounds(rxn.getBaseMolecule(i), min1, max1, 1.0); - merged.mergeWithMolecule(rxn.getBaseMolecule(i), 0, 0); + _getBounds(reaction->getBaseMolecule(i), min1, max1, 1.0); + merged.mergeWithMolecule(reaction->getBaseMolecule(i), 0, 0); - if (i == rxn.reactantBegin()) + if (i == reaction->reactantBegin()) { rmin = min1; rmax = max1; @@ -88,33 +118,33 @@ void ReactionJsonSaver::saveReaction(BaseReaction& rxn, BaseMolecule& merged, Mo rmax.max(max1); } - if (rcount < rxn.reactantsCount()) + if (rcount < reaction->reactantsCount()) { Vec2f min2, max2; - _getBounds(rxn.getBaseMolecule(rxn.reactantNext(i)), min2, max2, 1.0); + _getBounds(reaction->getBaseMolecule(reaction->reactantNext(i)), min2, max2, 1.0); pluses.emplace_back((max1.x + min2.x) / 2, (min1.y + max1.y) / 2); rcount++; } - last_single_reactant = rxn.getBaseMolecule(i).vertexCount() == 1; + last_single_reactant = reaction->getBaseMolecule(i).vertexCount() == 1; } } - if (rxn.productsCount() > 0) + if (reaction->productsCount() > 0) { int rcount = 1; Vec2f min1, max1; - for (int i = rxn.productBegin(); i != rxn.productEnd(); i = rxn.productNext(i)) + for (int i = reaction->productBegin(); i != reaction->productEnd(); i = reaction->productNext(i)) { Vec2f min1, max1; - _getBounds(rxn.getBaseMolecule(i), min1, max1, 1.0); - merged.mergeWithMolecule(rxn.getBaseMolecule(i), 0, 0); + _getBounds(reaction->getBaseMolecule(i), min1, max1, 1.0); + merged.mergeWithMolecule(reaction->getBaseMolecule(i), 0, 0); - if (i == rxn.productBegin()) + if (i == reaction->productBegin()) { pmin = min1; pmax = max1; - first_single_product = rxn.getBaseMolecule(i).vertexCount() == 1; + first_single_product = reaction->getBaseMolecule(i).vertexCount() == 1; } else { @@ -122,24 +152,24 @@ void ReactionJsonSaver::saveReaction(BaseReaction& rxn, BaseMolecule& merged, Mo pmax.max(max1); } - if (rcount < rxn.productsCount()) + if (rcount < reaction->productsCount()) { Vec2f min2, max2; - _getBounds(rxn.getBaseMolecule(rxn.productNext(i)), min2, max2, 1.0); + _getBounds(reaction->getBaseMolecule(reaction->productNext(i)), min2, max2, 1.0); pluses.emplace_back((max1.x + min2.x) / 2, (min1.y + max1.y) / 2); rcount++; } } } - if (rxn.catalystCount() > 0) + if (reaction->catalystCount() > 0) { - for (int i = rxn.catalystBegin(); i != rxn.catalystEnd(); i = rxn.catalystNext(i)) + for (int i = reaction->catalystBegin(); i != reaction->catalystEnd(); i = reaction->catalystNext(i)) { Vec2f min1, max1; - _getBounds(rxn.getBaseMolecule(i), min1, max1, 1.0); - merged.mergeWithMolecule(rxn.getBaseMolecule(i), 0, 0); - if (i == rxn.catalystBegin()) + _getBounds(reaction->getBaseMolecule(i), min1, max1, 1.0); + merged.mergeWithMolecule(reaction->getBaseMolecule(i), 0, 0); + if (i == reaction->catalystBegin()) { cmin = min1; cmax = max1; @@ -180,16 +210,16 @@ void ReactionJsonSaver::saveReaction(BaseReaction& rxn, BaseMolecule& merged, Mo // calculate arrow Vec2f arrow_head(0, 0); Vec2f arrow_tail(0, 0); - if (rxn.reactantsCount() || rxn.productsCount()) + if (reaction->reactantsCount() || reaction->productsCount()) { - if (rxn.productsCount() == 0) + if (reaction->productsCount() == 0) { arrow_tail.x = rmax.x + 1.0f; arrow_tail.y = (rmin.y + rmax.y) / 2; arrow_head.x = arrow_tail.x + 1.0f; arrow_head.y = arrow_tail.y; } - else if (rxn.reactantsCount() == 0) + else if (reaction->reactantsCount() == 0) { arrow_head.x = pmin.x - 1.0f; arrow_head.y = (pmin.y + pmax.y) / 2;