From a409c114270ba37c253cc6c8809ed798cd40f68d Mon Sep 17 00:00:00 2001 From: Aliaksandr Dziarkach <18146690+AliaksandrDziarkach@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:55:27 +0300 Subject: [PATCH] #2539 - Export of unknown monomer to HELM doesn't work Fix code. Add UTs. --- .../ref/formats/ket_to_helm.py.out | 1 + .../integration/tests/formats/ket_to_helm.py | 1 + .../tests/formats/ref/helm_unknown.ket | 128 ++++++++++++++++++ .../molecule/src/sequence_saver.cpp | 10 +- 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 api/tests/integration/tests/formats/ref/helm_unknown.ket diff --git a/api/tests/integration/ref/formats/ket_to_helm.py.out b/api/tests/integration/ref/formats/ket_to_helm.py.out index 5970164d51..112b0dee40 100644 --- a/api/tests/integration/ref/formats/ket_to_helm.py.out +++ b/api/tests/integration/ref/formats/ket_to_helm.py.out @@ -19,4 +19,5 @@ helm_rna_without_base.ket:SUCCEED helm_simple_rna.ket:SUCCEED helm_smiles.ket:SUCCEED helm_smiles_sugar.ket:SUCCEED +helm_unknown.ket:SUCCEED rna_variants.ket:SUCCEED diff --git a/api/tests/integration/tests/formats/ket_to_helm.py b/api/tests/integration/tests/formats/ket_to_helm.py index e3e69cd297..84e5553911 100644 --- a/api/tests/integration/tests/formats/ket_to_helm.py +++ b/api/tests/integration/tests/formats/ket_to_helm.py @@ -54,6 +54,7 @@ def find_diff(a, b): "helm_molecule_2418": "PEPTIDE1{A}|CHEM1{[C1C=CC=CC=1[*:1] |$;;;;;;_R1$|]}$PEPTIDE1,CHEM1,1:R1-1:R1$$$V2.0", "helm_chem_rna_hydro": "CHEM1{[MCC]}|RNA1{R(U)P}$CHEM1,RNA1,1:pair-3:pair$$$V2.0", "helm_monomer_molecule_direct": "PEPTIDE1{A}|CHEM1{[C(=C)N[*:1] |$;;;_R1$|]}$PEPTIDE1,CHEM1,1:R2-1:R1$$$V2.0", + "helm_unknown": "CHEM1{[C1([*:1])C([*:4])C([*:3])C1[*:2] |$;_R1;;_R4;;_R3;;_R2$|]}$$$$V2.0", } for filename in sorted(helm_data.keys()): diff --git a/api/tests/integration/tests/formats/ref/helm_unknown.ket b/api/tests/integration/tests/formats/ref/helm_unknown.ket new file mode 100644 index 0000000000..ce49b5ffa5 --- /dev/null +++ b/api/tests/integration/tests/formats/ref/helm_unknown.ket @@ -0,0 +1,128 @@ +{ + "root": { + "nodes": [ + { + "$ref": "monomer489" + } + ], + "connections": [], + "templates": [ + { + "$ref": "monomerTemplate-unknown_monomer_with_idt_alias_Unknown" + } + ] + }, + "monomer489": { + "type": "monomer", + "id": "489", + "position": { + "x": 13.213368034362787, + "y": -10.06310758590698 + }, + "alias": "Unknown", + "templateId": "unknown_monomer_with_idt_alias_Unknown", + "seqid": 0 + }, + "monomerTemplate-unknown_monomer_with_idt_alias_Unknown": { + "type": "monomerTemplate", + "atoms": [ + { + "label": "C", + "location": [ + 0, + 0, + 0 + ] + }, + { + "label": "C", + "location": [ + 1, + 1, + 1 + ] + }, + { + "label": "C", + "location": [ + 2, + 2, + 2 + ] + }, + { + "label": "C", + "location": [ + 3, + 3, + 3 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 3 + ] + }, + { + "type": 1, + "atoms": [ + 0, + 3 + ] + } + ], + "class": "CHEM", + "id": "unknown_monomer_with_idt_alias_Unknown", + "fullName": "Unknown", + "alias": "Unknown", + "attachmentPoints": [ + { + "attachmentAtom": 0, + "leavingGroup": { + "atoms": [] + } + }, + { + "attachmentAtom": 1, + "leavingGroup": { + "atoms": [] + } + }, + { + "attachmentAtom": 2, + "leavingGroup": { + "atoms": [] + } + }, + { + "attachmentAtom": 3, + "leavingGroup": { + "atoms": [] + } + } + ], + "idtAliases": { + "base": "Unknown" + }, + "unresolved": true, + "naturalAnalogShort": "" + } +} \ No newline at end of file diff --git a/core/indigo-core/molecule/src/sequence_saver.cpp b/core/indigo-core/molecule/src/sequence_saver.cpp index a7c50ab03d..acb4c01cd0 100644 --- a/core/indigo-core/molecule/src/sequence_saver.cpp +++ b/core/indigo-core/molecule/src/sequence_saver.cpp @@ -1206,7 +1206,15 @@ void SequenceSaver::add_monomer(KetDocument& document, const std::unique_ptrresetAtom(leaving_atom, ELEM_RSITE); + if (leaving_atom >= 0) + { + pmol->resetAtom(leaving_atom, ELEM_RSITE); + } + else + { + leaving_atom = pmol->addAtom(ELEM_RSITE); + pmol->addBond(ap.aidx, leaving_atom, BOND_SINGLE); + } pmol->allowRGroupOnRSite(leaving_atom, ap_idx); } sgroups.remove(i);