diff --git a/api/tests/integration/ref/formats/helm_to_ket.py.out b/api/tests/integration/ref/formats/helm_to_ket.py.out index 1000fca796..28512961d8 100644 --- a/api/tests/integration/ref/formats/helm_to_ket.py.out +++ b/api/tests/integration/ref/formats/helm_to_ket.py.out @@ -6,4 +6,7 @@ helm_multi_char_rna.ket:SUCCEED helm_peptide.ket:SUCCEED helm_rna_without_base.ket:SUCCEED helm_simple_rna.ket:SUCCEED +Test 'CHEM1{[A6OH]}|PEPTIDE1{A}$CHEM1,PEPTIDE1,1:R2-3:R1$$$V2.0': got expected error 'Polymer 'PEPTIDE1' does not contains monomer with number 3.' +Test 'CHEM1{[A6OH]}|PEPTIDE1{A}$CHEM10,PEPTIDE1,1:R2-1:R1$$$V2.0': got expected error 'Polymer 'CHEM10' not found.' +Test 'CHEM1{[MCC]}|RNA1{R(A)P.R(C)P.R(G)P.R(T)P.R(U)P}$RNA1,PEPTIDE1,15:R2-1:R1$$$V2.0': got expected error 'Polymer 'PEPTIDE1' not found.' Test 'PEPTIDE1{A'2'}$$$$V2.0': got expected error 'Repeating do not supported now.' diff --git a/api/tests/integration/tests/formats/helm_to_ket.py b/api/tests/integration/tests/formats/helm_to_ket.py index 67979d9d98..f3c9564053 100644 --- a/api/tests/integration/tests/formats/helm_to_ket.py +++ b/api/tests/integration/tests/formats/helm_to_ket.py @@ -56,7 +56,12 @@ def find_diff(a, b): print(filename + ".ket:FAILED") print(diff) -helm_errors = {"PEPTIDE1{A'2'}$$$$V2.0": "Repeating do not supported now."} +helm_errors = { + "PEPTIDE1{A'2'}$$$$V2.0": "Repeating do not supported now.", + "CHEM1{[MCC]}|RNA1{R(A)P.R(C)P.R(G)P.R(T)P.R(U)P}$RNA1,PEPTIDE1,15:R2-1:R1$$$V2.0": "Polymer 'PEPTIDE1' not found.", + "CHEM1{[A6OH]}|PEPTIDE1{A}$CHEM10,PEPTIDE1,1:R2-1:R1$$$V2.0": "Polymer 'CHEM10' not found.", + "CHEM1{[A6OH]}|PEPTIDE1{A}$CHEM1,PEPTIDE1,1:R2-3:R1$$$V2.0": "Polymer 'PEPTIDE1' does not contains monomer with number 3.", +} for helm_seq in sorted(helm_errors.keys()): error = helm_errors[helm_seq] try: diff --git a/core/indigo-core/molecule/src/sequence_loader.cpp b/core/indigo-core/molecule/src/sequence_loader.cpp index 8f563b6b20..ad6ed1108c 100644 --- a/core/indigo-core/molecule/src/sequence_loader.cpp +++ b/core/indigo-core/molecule/src/sequence_loader.cpp @@ -1059,11 +1059,17 @@ void SequenceLoader::loadHELM(BaseMolecule& mol) // CHEM1,RNA1,32:R1-12:R2"annotation"|..... std::string left_polymer, right_polymer; std::ignore = readHelmSimplePolymerName(left_polymer); + auto left_polymer_nums = used_polymer_nums.find(left_polymer); + if (left_polymer_nums == used_polymer_nums.end()) + throw Error("Polymer '%s' not found.", left_polymer.c_str()); ch = _scanner.lookNext(); if (ch != ',') throw Error("Unexpected symbol. Expected ',' but found '%c'.", _scanner.lookNext()); _scanner.skip(1); std::ignore = readHelmSimplePolymerName(right_polymer); + auto right_polymer_nums = used_polymer_nums.find(right_polymer); + if (right_polymer_nums == used_polymer_nums.end()) + throw Error("Polymer '%s' not found.", right_polymer.c_str()); ch = _scanner.lookNext(); if (ch != ',') throw Error("Unexpected symbol. Expected ',' but found '%c'.", _scanner.lookNext()); @@ -1087,8 +1093,14 @@ void SequenceLoader::loadHELM(BaseMolecule& mol) if (error_pos != position.size() - 1) // arrray contains 0 at the end throw Error("Only direct connections supported now."); _scanner.readWord(right_ap, "\"|$"); - int left_templ_atom_idx = used_polymer_nums[left_polymer][left_monomer_idx]; - int right_templ_atom_idx = used_polymer_nums[right_polymer][right_monomer_idx]; + auto left_mon_it = left_polymer_nums->second.find(left_monomer_idx); + if (left_mon_it == left_polymer_nums->second.end()) + throw Error("Polymer '%s' does not contains monomer with number %d.", left_polymer.c_str(), left_monomer_idx); + int left_templ_atom_idx = left_mon_it->second; + auto right_mon_it = right_polymer_nums->second.find(right_monomer_idx); + if (right_mon_it == right_polymer_nums->second.end()) + throw Error("Polymer '%s' does not contains monomer with number %d.", right_polymer.c_str(), right_monomer_idx); + int right_templ_atom_idx = right_mon_it->second; mol.asMolecule().addBond_Silent(left_templ_atom_idx, right_templ_atom_idx, BOND_SINGLE); mol.setTemplateAtomAttachmentOrder(left_templ_atom_idx, right_templ_atom_idx, convertAPFromHELM(left_ap.ptr()).c_str()); mol.setTemplateAtomAttachmentOrder(right_templ_atom_idx, left_templ_atom_idx, convertAPFromHELM(right_ap.ptr()).c_str());