diff --git a/api/tests/integration/ref/formats/ket_retrosynthetic_arrow.py.out b/api/tests/integration/ref/formats/ket_retrosynthetic_arrow.py.out index 85801f5313..661b7d29cd 100644 --- a/api/tests/integration/ref/formats/ket_retrosynthetic_arrow.py.out +++ b/api/tests/integration/ref/formats/ket_retrosynthetic_arrow.py.out @@ -76,4 +76,6 @@ ket_simple_arrow_retro_arrow_sum_of_products.smarts:SUCCEED output format: CML ket_simple_arrow_retro_arrow_sum_of_products.cml:SUCCEED issue 2318 -ket_simple_arrow_retro_arrow_sum_of_products.cml:SUCCEED +ket_retro_arrow.ket:SUCCEED +issue 2417 +ket_retro_arrow.ket:SUCCEED diff --git a/api/tests/integration/tests/formats/ket_retrosynthetic_arrow.py b/api/tests/integration/tests/formats/ket_retrosynthetic_arrow.py index be4d14fa14..fa32564ec7 100644 --- a/api/tests/integration/tests/formats/ket_retrosynthetic_arrow.py +++ b/api/tests/integration/tests/formats/ket_retrosynthetic_arrow.py @@ -85,6 +85,8 @@ def getCML(reaction): print("output format: " + format_name) + # with open(os.path.join(ref_path, filename), "w") as file: + # file.write(parsed_format) with open(os.path.join(ref_path, filename), "r") as file: format_ref = file.read() diff = find_diff(format_ref, parsed_format) @@ -96,7 +98,8 @@ def getCML(reaction): print("issue 2318") indigo.setOption("json-use-native-precision", "1") -fname = os.path.join(root_rea, "ket_retro_arrow.ket") +filename = "ket_retro_arrow.ket" +fname = os.path.join(root_rea, filename) rxn = indigo.loadReactionFromFile(fname) # with open(fname, "w") as file: # file.write(rxn.json()) @@ -108,3 +111,13 @@ def getCML(reaction): else: print(filename + ":FAILED") print(diff) +print("issue 2417") +rxn.layout() +# with open(fname, "w") as file: +# file.write(rxn.json()) +diff = find_diff(ref_json, rxn.json()) +if not diff: + print(filename + ":SUCCEED") +else: + print(filename + ":FAILED") + print(diff) diff --git a/api/tests/integration/tests/formats/reactions/ket_retro_arrow.ket b/api/tests/integration/tests/formats/reactions/ket_retro_arrow.ket index 5464fb3676..42019ac0d1 100644 --- a/api/tests/integration/tests/formats/reactions/ket_retro_arrow.ket +++ b/api/tests/integration/tests/formats/reactions/ket_retro_arrow.ket @@ -13,13 +13,13 @@ "mode": "retrosynthetic", "pos": [ { - "x": 17.023752, - "y": -8.175, + "x": 5.071281, + "y": 0.0, "z": 0.0 }, { - "x": 18.750181, - "y": -8.175, + "x": 9.271282, + "y": 0.0, "z": 0.0 } ] @@ -33,32 +33,32 @@ { "label": "C", "location": [ - 15.246468, - -9.074999, + 2.685641, + -1.2, 0.0 ] }, { "label": "C", "location": [ - 15.246468, - -8.075001, + 2.685641, + 0.4, 0.0 ] }, { "label": "C", "location": [ - 14.380445, - -7.575001, + 1.3, + 1.2, 0.0 ] }, { "label": "N", "location": [ - 16.112492, - -7.575001, + 4.071281, + 1.2, 0.0 ] } @@ -93,24 +93,24 @@ { "label": "O", "location": [ - 19.987497, - -8.075001, + 10.271282, + 0.4, 0.0 ] }, { "label": "C", "location": [ - 20.853495, - -8.575, + 11.656923, + -0.4, 0.0 ] }, { "label": "O", "location": [ - 21.719555, - -8.075001, + 13.042563, + 0.4, 0.0 ] } diff --git a/api/tests/integration/tests/formats/ref/ket_retro_arrow.b64cdx b/api/tests/integration/tests/formats/ref/ket_retro_arrow.b64cdx index e5330eb247..a4c99f9c0f 100644 --- a/api/tests/integration/tests/formats/ref/ket_retro_arrow.b64cdx +++ b/api/tests/integration/tests/formats/ref/ket_retro_arrow.b64cdx @@ -1 +1 @@ -VmpDRDAxMDAEAwIBAAAAAAAAAAAAAAAAAAAAAAUIBAAAAB4AGggCAAMAGwgCAAQAAAEkAAAAAgACAOn9BQBBcmlhbAMA6f0PAFRpbWVzIE5ldyBSb21hbgADMgAIAP///////wAAAAAAAP//AAAAAP////8AAAAA//8AAAAA/////wAAAAD/////AAD//wGAAAAAABAIAgABAA8IAgABAAOABAAAAASABQAAAAACCAD+PxAB4GTJAQAABIAGAAAAAAIIAAJA8gDgZMkBAAAEgAcAAAAAAggAAkDjANBprwEAAASACAAAAAIEAgAHACsEAgACAAACCAACQOMA8F/jAQaAAAAAAAACCAACQOMA8F/jASMIAQAAAAcZAAIAAAADAGAAyAAAAAIAAwAgAMgAAABOSDIAAAAABYAQAAAABAYEAAUAAAAFBgQABgAAAAAABYARAAAABAYEAAYAAAAFBgQABwAAAAAABYASAAAABAYEAAYAAAAFBgQACAAAAAAAAAADgAkAAAAEgAoAAAACBAIACAArBAIAAQAAAggAAkDyAPyfVwIGgAAAAAAAAggAAkDyAPyfVwIjCAEAAAAHDgABAAAAAwBgAMgAAABPSAAAAAAEgAsAAAAAAggAAEABAdiacQIAAASADAAAAAIEAgAIACsEAgABAAACCAACQPIAMJaLAgaAAAAAAAACCAACQPIAMJaLAiMIAQAAAAcOAAEAAAADAGAAyAAAAE9IAAAAAAWAEwAAAAQGBAAKAAAABQYEAAsAAAAAAAWAFAAAAAQGBAALAAAABQYEAAwAAAAAAAAAIYANAAAABAIQAABA9QBkgTICAED1AGq2/gE3CgIAAAA1CgIAAgAvCgIAAwAgCgIAWAIwCgIAWAIxCgIAlgAzCgIAWAIHAgwAZAEyAgBA9QAAAAAACAIMAGo2/wEAQPUAAAAAAAAAB4AVAAAAEwAEAA0AAAAACgIAAQACCgIAIAAgCgIAWAIEAhAAAED1AGQBMgIAQPUAajb/AQAADYAAAAAADoAAAAAAAQwEAAQAAAACDAQACQAAAAQMBAAVAAAAAAAAAAAAAAAAAA== \ No newline at end of file +VmpDRDAxMDAEAwIBAAAAAAAAAAAAAAAAAAAAAAUIBAAAAB4AGggCAAMAGwgCAAQAAAEkAAAAAgACAOn9BQBBcmlhbAMA6f0PAFRpbWVzIE5ldyBSb21hbgADMgAIAP///////wAAAAAAAP//AAAAAP////8AAAAA//8AAAAA/////wAAAAD/////AAD//wGAAAAAABAIAgABAA8IAgABAAOABAAAAASABQAAAAACCAAAACQAuZFQAAAABIAGAAAAAAIIAAAA9P+5kVAAAAAEgAcAAAAAAggAAADc/wAAJwAAAASACAAAAAIEAgAHACsEAgACAAACCAAAANz/cCN6AAaAAAAAAAACCAAAANz/cCN6ACMIAQAAAAcZAAIAAAADAGAAyAAAAAIAAwAgAMgAAABOSDIAAAAABYAQAAAABAYEAAUAAAAFBgQABgAAAAAABYARAAAABAYEAAYAAAAFBgQABwAAAAAABYASAAAABAYEAAYAAAAFBgQACAAAAAAAAAADgAkAAAAEgAoAAAACBAIACAArBAIAAQAAAggAAAD0/3IjNAEGgAAAAAAAAggAAAD0/3IjNAEjCAEAAAAHDgABAAAAAwBgAMgAAABPSAAAAAAEgAsAAAAAAggAAAAMACy1XQEAAASADAAAAAIEAgAIACsEAgABAAACCAAAAPT/5EaHAQaAAAAAAAACCAAAAPT/5EaHASMIAQAAAAcOAAEAAAADAGAAyAAAAE9IAAAAAAWAEwAAAAQGBAAKAAAABQYEAAsAAAAAAAWAFAAAAAQGBAALAAAABQYEAAwAAAAAAAAAIYANAAAABAIQAAAAAAByIxYBAAAAAHAjmAA3CgIAAAA1CgIAAgAvCgIAAwAgCgIAWAIwCgIAWAIxCgIAlgAzCgIAWAIHAgwAcqMVAQAAAAAAAAAACAIMAHCjmAAAAAAAAAAAAAAAB4AVAAAAEwAEAA0AAAAACgIAAQACCgIAIAAgCgIAWAIEAhAAAAAAAHKjFQEAAAAAcKOYAAAADYAAAAAADoAAAAAAAQwEAAQAAAACDAQACQAAAAQMBAAVAAAAAAAAAAAAAAAAAA== \ No newline at end of file diff --git a/api/tests/integration/tests/formats/ref/ket_retro_arrow.cdxml b/api/tests/integration/tests/formats/ref/ket_retro_arrow.cdxml index 784d363149..0a9be3c219 100644 --- a/api/tests/integration/tests/formats/ref/ket_retro_arrow.cdxml +++ b/api/tests/integration/tests/formats/ref/ket_retro_arrow.cdxml @@ -18,11 +18,11 @@ - - - - - + + + + + NH 2 @@ -32,22 +32,22 @@ - - + + OH - - - + + + OH - - + + diff --git a/api/tests/integration/tests/formats/ref/ket_retro_arrow.cml b/api/tests/integration/tests/formats/ref/ket_retro_arrow.cml index 354e718394..fdd6393ff0 100644 --- a/api/tests/integration/tests/formats/ref/ket_retro_arrow.cml +++ b/api/tests/integration/tests/formats/ref/ket_retro_arrow.cml @@ -4,9 +4,9 @@ - - - + + + @@ -17,10 +17,10 @@ - - - - + + + + diff --git a/api/tests/integration/tests/formats/ref/ket_retro_arrow_2000.rxn b/api/tests/integration/tests/formats/ref/ket_retro_arrow_2000.rxn index c29e36ea27..b5839a9cd3 100644 --- a/api/tests/integration/tests/formats/ref/ket_retro_arrow_2000.rxn +++ b/api/tests/integration/tests/formats/ref/ket_retro_arrow_2000.rxn @@ -8,9 +8,9 @@ $MOL -INDIGO-01000000002D 3 2 0 0 0 0 0 0 0 0999 V2000 - 19.9875 -8.0750 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 - 20.8535 -8.5750 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 21.7196 -8.0750 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 10.2713 0.4000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 11.6569 -0.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 13.0426 0.4000 0.0000 O 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 M END @@ -19,10 +19,10 @@ $MOL -INDIGO-01000000002D 4 3 0 0 0 0 0 0 0 0999 V2000 - 15.2465 -9.0750 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 15.2465 -8.0750 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 14.3804 -7.5750 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 - 16.1125 -7.5750 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 + 2.6856 -1.2000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 2.6856 0.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 1.3000 1.2000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 4.0713 1.2000 0.0000 N 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 2 4 1 0 0 0 0 diff --git a/api/tests/integration/tests/formats/ref/ket_retro_arrow_3000.rxn b/api/tests/integration/tests/formats/ref/ket_retro_arrow_3000.rxn index 7e11303d38..ce6f4b7e44 100644 --- a/api/tests/integration/tests/formats/ref/ket_retro_arrow_3000.rxn +++ b/api/tests/integration/tests/formats/ref/ket_retro_arrow_3000.rxn @@ -7,9 +7,9 @@ M V30 BEGIN REACTANT M V30 BEGIN CTAB M V30 COUNTS 3 2 0 0 0 M V30 BEGIN ATOM -M V30 1 O 19.9875 -8.075 0.0 0 -M V30 2 C 20.8535 -8.575 0.0 0 -M V30 3 O 21.7196 -8.075 0.0 0 +M V30 1 O 10.2713 0.4 0.0 0 +M V30 2 C 11.6569 -0.4 0.0 0 +M V30 3 O 13.0426 0.4 0.0 0 M V30 END ATOM M V30 BEGIN BOND M V30 1 1 1 2 @@ -21,10 +21,10 @@ M V30 BEGIN PRODUCT M V30 BEGIN CTAB M V30 COUNTS 4 3 0 0 0 M V30 BEGIN ATOM -M V30 1 C 15.2465 -9.075 0.0 0 -M V30 2 C 15.2465 -8.075 0.0 0 -M V30 3 C 14.3804 -7.575 0.0 0 -M V30 4 N 16.1125 -7.575 0.0 0 +M V30 1 C 2.68564 -1.2 0.0 0 +M V30 2 C 2.68564 0.4 0.0 0 +M V30 3 C 1.3 1.2 0.0 0 +M V30 4 N 4.07128 1.2 0.0 0 M V30 END ATOM M V30 BEGIN BOND M V30 1 1 1 2 diff --git a/core/indigo-core/layout/src/reaction_layout.cpp b/core/indigo-core/layout/src/reaction_layout.cpp index 7b81e1c58d..d82dd944f2 100644 --- a/core/indigo-core/layout/src/reaction_layout.cpp +++ b/core/indigo-core/layout/src/reaction_layout.cpp @@ -103,17 +103,35 @@ void ReactionLayout::_updateMetadata() Rect2f react_box, product_box, catalyst_box; bool last_single_reactant = false; bool first_single_product = false; + bool is_retrosyntetic = _r.isRetrosyntetic(); if (_r.reactantsCount() > 0) { - processSideBoxes(pluses, react_box, BaseReaction::REACTANT); - for (int i = _r.reactantBegin(); i != _r.reactantEnd(); i = _r.reactantNext(i)) - last_single_reactant = _r.getBaseMolecule(i).vertexCount() == 1; + if (is_retrosyntetic) + { + processSideBoxes(pluses, react_box, BaseReaction::PRODUCT); + for (int i = _r.productBegin(); i != _r.productEnd(); i = _r.productNext(i)) + last_single_reactant = _r.getBaseMolecule(i).vertexCount() == 1; + } + else + { + processSideBoxes(pluses, react_box, BaseReaction::REACTANT); + for (int i = _r.reactantBegin(); i != _r.reactantEnd(); i = _r.reactantNext(i)) + last_single_reactant = _r.getBaseMolecule(i).vertexCount() == 1; + } } if (_r.productsCount() > 0) { - processSideBoxes(pluses, product_box, BaseReaction::PRODUCT); - first_single_product = _r.getBaseMolecule(_r.productBegin()).vertexCount() == 1; + if (is_retrosyntetic) + { + processSideBoxes(pluses, product_box, BaseReaction::REACTANT); + first_single_product = _r.getBaseMolecule(_r.reactantBegin()).vertexCount() == 1; + } + else + { + processSideBoxes(pluses, product_box, BaseReaction::PRODUCT); + first_single_product = _r.getBaseMolecule(_r.productBegin()).vertexCount() == 1; + } } if (_r.catalystCount() > 0) @@ -126,14 +144,16 @@ void ReactionLayout::_updateMetadata() Vec2f arrow_tail(0, 0); constexpr float shift = 1.0f; - if (_r.productsCount() == 0) + int prod_count = is_retrosyntetic ? _r.reactantsCount() : _r.productsCount(); + int react_count = is_retrosyntetic ? _r.productsCount() : _r.reactantsCount(); + if (prod_count == 0) { arrow_tail.x = react_box.right() + shift; arrow_tail.y = react_box.middleY(); arrow_head.x = arrow_tail.x + shift; arrow_head.y = arrow_tail.y; } - else if (_r.reactantsCount() == 0) + else if (react_count == 0) { arrow_head.x = product_box.left() - shift; arrow_head.y = product_box.middleY(); @@ -216,13 +236,19 @@ void ReactionLayout::make() // layout molecules in a row with the intervals specified Metalayout::LayoutLine& line = _ml.newLine(); - for (int i = _r.reactantBegin(); i < _r.reactantEnd(); i = _r.reactantNext(i)) - { - bool single_atom = _getMol(i).vertexCount() == 1; - if (i != _r.reactantBegin()) - _pushSpace(line, plus_interval_factor); - _pushMol(line, i); - } + auto processReactionElements = [this, &line](int begin, int end, std::function next) { + for (int i = begin; i < end; i = next(_r, i)) + { + if (i != begin) + _pushSpace(line, plus_interval_factor); + _pushMol(line, i); + } + }; + + if (_r.isRetrosyntetic()) + processReactionElements(_r.productBegin(), _r.productEnd(), &BaseReaction::productNext); + else + processReactionElements(_r.reactantBegin(), _r.reactantEnd(), &BaseReaction::reactantNext); if (_r.catalystCount()) { @@ -241,13 +267,10 @@ void ReactionLayout::make() _pushSpace(line, bond_length); - for (int i = _r.productBegin(); i < _r.productEnd(); i = _r.productNext(i)) - { - bool single_atom = _getMol(i).vertexCount() == 1; - if (i != _r.productBegin()) - _pushSpace(line, plus_interval_factor); - _pushMol(line, i); - } + if (_r.isRetrosyntetic()) + processReactionElements(_r.reactantBegin(), _r.reactantEnd(), &BaseReaction::reactantNext); + else + processReactionElements(_r.productBegin(), _r.productEnd(), &BaseReaction::productNext); _ml.bondLength = bond_length; _ml.horizontalIntervalFactor = horizontal_interval_factor;