Skip to content

Commit

Permalink
Backmerge: #2257 - Unable to save CHEM SS3 to IDT format (#2502)
Browse files Browse the repository at this point in the history
  • Loading branch information
AliaksandrDziarkach authored Oct 4, 2024
1 parent d4233f9 commit 98beb22
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 13 deletions.
1 change: 1 addition & 0 deletions api/tests/integration/ref/formats/ket_to_idt.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ idt_i2moera_32moera.ket:SUCCEED
idt_i2moera_sp.ket:SUCCEED
idt_i2moera_sp_32moera.ket:SUCCEED
idt_i2moera_t.ket:SUCCEED
idt_issue_2257.ket:SUCCEED
idt_many_molecules.ket:SUCCEED
idt_mixed.ket:SUCCEED
idt_mixed_custom.ket:SUCCEED
Expand Down
1 change: 1 addition & 0 deletions api/tests/integration/tests/formats/ket_to_idt.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def find_diff(a, b):
"idt_mixed_custom": "(N1:10203050)(N1)N",
"idt_rna_dna_mixed_custom": "r(R1:50003000)(R1)",
"idt_mixed_ketcher": "KrK(K1:00003070)r(K2:00003070)",
"idt_issue_2257": "/3ThioMC3-D/",
}

for filename in sorted(idt_data.keys()):
Expand Down
236 changes: 236 additions & 0 deletions api/tests/integration/tests/formats/ref/idt_issue_2257.ket
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
{
"root": {
"nodes": [
{
"$ref": "monomer0"
}
],
"connections": [],
"templates": [
{
"$ref": "monomerTemplate-SS3___Dipropanol-disulfide"
}
]
},
"monomer0": {
"type": "monomer",
"id": "0",
"position": {
"x": 14.424999999999997,
"y": -5.899999999999998
},
"alias": "SS3",
"templateId": "SS3___Dipropanol-disulfide"
},
"monomerTemplate-SS3___Dipropanol-disulfide": {
"type": "monomerTemplate",
"atoms": [
{
"label": "H",
"location": [
-6.8609,
-0.665,
0
]
},
{
"label": "O",
"location": [
-5.862,
0,
0
]
},
{
"label": "C",
"location": [
-4.5166,
-0.6653,
0
]
},
{
"label": "C",
"location": [
-3.2673,
0.1663,
0
]
},
{
"label": "C",
"location": [
-1.922,
-0.499,
0
]
},
{
"label": "S",
"location": [
-0.6726,
0.3327,
0
]
},
{
"label": "S",
"location": [
0.6726,
-0.3327,
0
]
},
{
"label": "C",
"location": [
1.922,
0.499,
0
]
},
{
"label": "C",
"location": [
3.2673,
-0.1663,
0
]
},
{
"label": "C",
"location": [
4.5166,
0.6653,
0
]
},
{
"label": "O",
"location": [
5.862,
0,
0
]
},
{
"label": "H",
"location": [
6.8609,
0.665,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
5,
6
]
},
{
"type": 1,
"atoms": [
1,
2
]
},
{
"type": 1,
"atoms": [
6,
7
]
},
{
"type": 1,
"atoms": [
7,
8
]
},
{
"type": 1,
"atoms": [
2,
3
]
},
{
"type": 1,
"atoms": [
8,
9
]
},
{
"type": 1,
"atoms": [
9,
10
]
},
{
"type": 1,
"atoms": [
3,
4
]
},
{
"type": 1,
"atoms": [
10,
11
]
},
{
"type": 1,
"atoms": [
0,
1
]
},
{
"type": 1,
"atoms": [
4,
5
]
}
],
"class": "CHEM",
"classHELM": "CHEM",
"id": "SS3___Dipropanol-disulfide",
"fullName": "Dipropanol-disulfide",
"alias": "SS3",
"attachmentPoints": [
{
"attachmentAtom": 1,
"leavingGroup": {
"atoms": [
0
]
},
"type": "left"
},
{
"attachmentAtom": 10,
"leavingGroup": {
"atoms": [
11
]
},
"type": "right"
}
],
"idtAliases": {
"base": "ThioMC3-D",
"modifications": {
"endpoint3": "3ThioMC3-D"
}
}
}
}
6 changes: 6 additions & 0 deletions api/tests/integration/tests/formats/ref/monomer_library.ket
Original file line number Diff line number Diff line change
Expand Up @@ -45012,6 +45012,12 @@
"id": "SS3___Dipropanol-disulfide",
"fullName": "Dipropanol-disulfide",
"alias": "SS3",
"idtAliases": {
"base": "ThioMC3-D",
"modifications": {
"endpoint3": "3ThioMC3-D"
}
},
"attachmentPoints": [
{
"attachmentAtom": 1,
Expand Down
34 changes: 21 additions & 13 deletions core/indigo-core/molecule/src/sequence_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,12 @@ void SequenceSaver::saveIdt(KetDocument& doc, std::vector<std::deque<std::string
std::string sugar;
std::string base;
std::string phosphate;
if (seq_string.size() > 0 && sequence.size() == 0)
modification = IdtModification::THREE_PRIME_END;
IdtModification possible_modification = modification;
if (sequence.size() == 0) // last monomer
if (seq_string.size() > 0)
modification = IdtModification::THREE_PRIME_END;
else // corner case - only one monomer
possible_modification = IdtModification::THREE_PRIME_END;

if (monomer_class == MonomerClass::Phosphate)
{
Expand Down Expand Up @@ -898,17 +902,25 @@ void SequenceSaver::saveIdt(KetDocument& doc, std::vector<std::deque<std::string
}
else if (monomer_class == MonomerClass::CHEM || monomer_class == MonomerClass::DNA || monomer_class == MonomerClass::RNA)
{
auto write_name = [&](const IdtAlias& idtAlias) -> bool {
bool has_modification = idtAlias.hasModification(modification);
if (has_modification || (possible_modification != modification && idtAlias.hasModification(possible_modification)))
{
const std::string& idt_alias =
has_modification ? idtAlias.getModification(modification) : idtAlias.getModification(possible_modification);
seq_string += '/';
seq_string += idt_alias;
seq_string += '/';
return true;
}
return false;
};
// Try to find in library
const std::string& lib_monomer_id = _library.getMonomerTemplateIdByAlias(monomer_class, monomer);
if (lib_monomer_id.size()) // Monomer in library
{
const MonomerTemplate& templ = _library.getMonomerTemplateById(lib_monomer_id);
if (templ.idtAlias().hasModification(modification))
if (write_name(_library.getMonomerTemplateById(lib_monomer_id).idtAlias()))
{
const std::string& idt_alias = templ.idtAlias().getModification(modification);
seq_string += '/';
seq_string += idt_alias;
seq_string += '/';
if (modification == IdtModification::FIVE_PRIME_END)
modification = IdtModification::INTERNAL;
continue;
Expand All @@ -917,12 +929,8 @@ void SequenceSaver::saveIdt(KetDocument& doc, std::vector<std::deque<std::string

// Check template for IdtAlias
auto& monomer_template = doc.getMonomerTemplate(monomers.at(monomer_id)->templateId());

if (monomer_template.idtAlias().hasModification(modification))
if (write_name(monomer_template.idtAlias()))
{
seq_string.push_back('/');
seq_string.append(monomer_template.idtAlias().getModification(modification));
seq_string.push_back('/');
modification = IdtModification::INTERNAL;
continue;
}
Expand Down

0 comments on commit 98beb22

Please sign in to comment.