From bb6d7be0563845aba3bf0cc25fc2a6bab7c69625 Mon Sep 17 00:00:00 2001 From: Aliaksandr Dziarkach <18146690+AliaksandrDziarkach@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:29:50 +0300 Subject: [PATCH] #1917 Changed hydrogens layout in WASM Fix lyaout constructor. Add UT. --- .../indigo-ketcher/test/failed_unfold.ket | 69 +++++++++++++++++++ .../indigo-ketcher/test/failed_unfold_ref.ket | 1 + api/wasm/indigo-ketcher/test/test.js | 19 +++++ .../layout/src/molecule_layout_graph.cpp | 12 +--- 4 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 api/wasm/indigo-ketcher/test/failed_unfold.ket create mode 100644 api/wasm/indigo-ketcher/test/failed_unfold_ref.ket diff --git a/api/wasm/indigo-ketcher/test/failed_unfold.ket b/api/wasm/indigo-ketcher/test/failed_unfold.ket new file mode 100644 index 0000000000..ee5a599044 --- /dev/null +++ b/api/wasm/indigo-ketcher/test/failed_unfold.ket @@ -0,0 +1,69 @@ +{ + "root": { + "nodes": [ + { + "$ref": "mol0" + } + ], + "connections": [], + "templates": [] + }, + "mol0": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 15.249374214363929, + -11.282470415521408, + 0 + ], + "explicitValence": 8 + }, + { + "label": "C", + "location": [ + 16.25062578563607, + -11.282470415521408, + 0 + ], + "explicitValence": 8 + }, + { + "label": "C", + "location": [ + 15.750050188048686, + -10.417529584478597, + 0 + ], + "explicitValence": 8 + } + ], + "bonds": [ + { + "type": 4, + "atoms": [ + 0, + 1 + ], + "topology": 1 + }, + { + "type": 4, + "atoms": [ + 1, + 2 + ], + "topology": 1 + }, + { + "type": 4, + "atoms": [ + 2, + 0 + ], + "topology": 1 + } + ] + } +} diff --git a/api/wasm/indigo-ketcher/test/failed_unfold_ref.ket b/api/wasm/indigo-ketcher/test/failed_unfold_ref.ket new file mode 100644 index 0000000000..02c9effdcd --- /dev/null +++ b/api/wasm/indigo-ketcher/test/failed_unfold_ref.ket @@ -0,0 +1 @@ +{"root":{"nodes":[{"$ref":"mol0"}]},"mol0":{"type":"molecule","atoms":[{"label":"C","location":[15.249374389648438,-11.282470703125,0.0],"explicitValence":8},{"label":"C","location":[16.250625610351564,-11.282470703125,0.0],"explicitValence":8},{"label":"C","location":[15.75005054473877,-10.417530059814454,0.0],"explicitValence":8},{"label":"H","location":[15.60797119140625,-12.048626899719239,0.0]},{"label":"H","location":[14.30993938446045,-10.939743995666504,0.0]},{"label":"H","location":[14.38306713104248,-11.781982421875,0.0]},{"label":"H","location":[14.76511001586914,-10.590422630310059,0.0]},{"label":"H","location":[15.075355529785157,-12.267212867736817,0.0]},{"label":"H","location":[16.734975814819337,-10.590508460998536,0.0]},{"label":"H","location":[17.190080642700197,-10.939798355102539,0.0]},{"label":"H","location":[16.42461585998535,-12.267218589782715,0.0]},{"label":"H","location":[15.892024040222168,-12.048624992370606,0.0]},{"label":"H","location":[17.116910934448243,-11.78201961517334,0.0]},{"label":"H","location":[14.908734321594239,-10.342500686645508,0.0]},{"label":"H","location":[16.59134864807129,-10.342525482177735,0.0]},{"label":"H","location":[16.51589012145996,-9.77449893951416,0.0]},{"label":"H","location":[15.750094413757325,-9.417530059814454,0.0]},{"label":"H","location":[14.98426628112793,-9.774432182312012,0.0]}],"bonds":[{"type":4,"topology":1,"atoms":[0,1]},{"type":4,"topology":1,"atoms":[1,2]},{"type":4,"topology":1,"atoms":[2,0]},{"type":1,"atoms":[0,3]},{"type":1,"atoms":[0,4]},{"type":1,"atoms":[0,5]},{"type":1,"atoms":[0,6]},{"type":1,"atoms":[0,7]},{"type":1,"atoms":[1,8]},{"type":1,"atoms":[1,9]},{"type":1,"atoms":[1,10]},{"type":1,"atoms":[1,11]},{"type":1,"atoms":[1,12]},{"type":1,"atoms":[2,13]},{"type":1,"atoms":[2,14]},{"type":1,"atoms":[2,15]},{"type":1,"atoms":[2,16]},{"type":1,"atoms":[2,17]}]}} \ No newline at end of file diff --git a/api/wasm/indigo-ketcher/test/test.js b/api/wasm/indigo-ketcher/test/test.js index 54e77138c4..f8327eee0d 100644 --- a/api/wasm/indigo-ketcher/test/test.js +++ b/api/wasm/indigo-ketcher/test/test.js @@ -968,6 +968,25 @@ M END }); } + { + test("unfold-ci-error", "basic", () => { + var fs = require('fs'); + let options = new indigo.MapStringString(); + options.set("output-content-type", "application/json"); + options.set("input-format", "chemical/x-indigo-ket"); + const ket = fs.readFileSync("failed_unfold.ket"); + const ket_unfold = JSON.parse(indigo.convert_explicit_hydrogens(ket, "unfold", "ket", options)).struct; + + // fs.writeFileSync("failed_unfold_ref.ket", ket_unfold); + + const ket_unfold_ref = fs.readFileSync("failed_unfold_ref.ket").toString(); + + assert.equal(ket_unfold, ket_unfold_ref); + + options.delete(); + }); + } + // Run tests run(); }); diff --git a/core/indigo-core/layout/src/molecule_layout_graph.cpp b/core/indigo-core/layout/src/molecule_layout_graph.cpp index 5c4e16c02a..45046ca541 100644 --- a/core/indigo-core/layout/src/molecule_layout_graph.cpp +++ b/core/indigo-core/layout/src/molecule_layout_graph.cpp @@ -26,16 +26,10 @@ using namespace indigo; IMPL_ERROR(MoleculeLayoutGraph, "layout_graph"); -MoleculeLayoutGraph::MoleculeLayoutGraph() : Graph() +MoleculeLayoutGraph::MoleculeLayoutGraph() + : Graph(), _flipped(false), max_iterations(-1), layout_orientation(UNCPECIFIED), preserve_existing_layout(false), cancellation(nullptr), + _total_morgan_code(0), _first_vertex_idx(-1), _n_fixed(0), _molecule(nullptr), _molecule_edge_mapping(nullptr) { - _total_morgan_code = 0; - _first_vertex_idx = -1; - _n_fixed = 0; - _molecule = 0; - _molecule_edge_mapping = 0; - cancellation = 0; - _flipped = false; - preserve_existing_layout = false; } MoleculeLayoutGraph::~MoleculeLayoutGraph()