Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2575 - Saving atom to monomer connections to Mol and HELM #2592

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/tests/integration/ref/formats/ket_to_helm.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ helm_mixed_base.ket:SUCCEED
helm_mixed_custom.ket:SUCCEED
helm_molecule_2418.ket:SUCCEED
helm_monomer_molecule.ket:SUCCEED
helm_monomer_molecule_direct.ket:SUCCEED
helm_multi_char_rna.ket:SUCCEED
helm_peptide.ket:SUCCEED
helm_rna_without_base.ket:SUCCEED
Expand Down
1 change: 1 addition & 0 deletions api/tests/integration/tests/formats/ket_to_helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def find_diff(a, b):
"helm_smiles_sugar": "RNA1{[C(C(CO[*:1])O[*:2])[*:3] |$;;;;_R1;;_R2;_R3$|](A)P}$$$$V2.0",
"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",
}

for filename in sorted(helm_data.keys()):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
{
"root": {
"nodes": [
{
"$ref": "monomer5635"
},
{
"$ref": "mol0"
}
],
"connections": [
{
"connectionType": "single",
"endpoint1": {
"monomerId": "monomer5635",
"attachmentPointId": "R2"
},
"endpoint2": {
"moleculeId": "mol0",
"atomId": "1"
}
}
],
"templates": [
{
"$ref": "monomerTemplate-A___Alanine"
}
]
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
22.70380779065583,
-10.331249794220879,
0
]
},
{
"label": "N",
"location": [
23.569833212558642,
-10.831249821106224,
0
]
},
{
"label": "C",
"location": [
21.837782294247205,
-10.831249783853321,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
},
{
"type": 2,
"atoms": [
0,
2
]
}
],
"stereoFlagPosition": {
"x": 23.569833212558642,
"y": 9.331249794220879,
"z": 0
}
},
"monomer5635": {
"type": "monomer",
"id": "5635",
"position": {
"x": 25.774999999999988,
"y": -10.725000000000009
},
"alias": "A",
"templateId": "A___Alanine"
},
"monomerTemplate-A___Alanine": {
"type": "monomerTemplate",
"atoms": [
{
"label": "N",
"location": [
-1.2549,
-0.392,
0
]
},
{
"label": "C",
"location": [
-0.272,
0.2633,
0
],
"stereoLabel": "abs"
},
{
"label": "C",
"location": [
-0.3103,
1.7393,
0
]
},
{
"label": "C",
"location": [
1.0523,
-0.392,
0
]
},
{
"label": "O",
"location": [
1.0829,
-1.5722,
0
]
},
{
"label": "O",
"location": [
2.0353,
0.2633,
0
]
},
{
"label": "H",
"location": [
-2.3334,
0.0905,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
1,
0
]
},
{
"type": 1,
"atoms": [
1,
2
],
"stereo": 1
},
{
"type": 1,
"atoms": [
1,
3
]
},
{
"type": 2,
"atoms": [
3,
4
]
},
{
"type": 1,
"atoms": [
3,
5
]
},
{
"type": 1,
"atoms": [
0,
6
]
}
],
"class": "AminoAcid",
"classHELM": "PEPTIDE",
"id": "A___Alanine",
"fullName": "Alanine",
"alias": "A",
"attachmentPoints": [
{
"attachmentAtom": 0,
"leavingGroup": {
"atoms": [
6
]
},
"type": "left"
},
{
"attachmentAtom": 3,
"leavingGroup": {
"atoms": [
5
]
},
"type": "right"
}
],
"naturalAnalogShort": "A"
}
}
38 changes: 38 additions & 0 deletions core/indigo-core/molecule/src/sequence_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,25 @@ std::string SequenceSaver::saveHELM(KetDocument& document, std::vector<std::dequ
auto& molecules = document.jsonMolecules();
int molecule_idx = 0;
rapidjson::Document json{};
std::map<std::string, std::vector<int>> molecules_connections;
if (molecules.Size() > 0)
{
auto process_ep = [&molecules_connections](const KetConnectionEndPoint& ep) {
if (ep.hasStringProp("moleculeId"))
{
const auto& mol_id = ep.getStringProp("moleculeId");
if (molecules_connections.count(mol_id) == 0)
molecules_connections.try_emplace(mol_id);
if (ep.hasStringProp("atomId"))
molecules_connections.at(mol_id).push_back(std::stoi(ep.getStringProp("atomId")));
}
};
for (const auto& connection : document.nonSequenceConnections())
{
process_ep(connection.ep1());
process_ep(connection.ep2());
}
}
for (rapidjson::SizeType i = 0; i < molecules.Size(); i++)
{
const auto& molecule = molecules[i];
Expand All @@ -1341,6 +1360,7 @@ std::string SequenceSaver::saveHELM(KetDocument& document, std::vector<std::dequ
}
// convert Sup sgroup without name attachment points to rg-labels
auto& sgroups = pbmol->sgroups;
int ap_count = 0;
for (int i = sgroups.begin(); i != sgroups.end(); i = sgroups.next(i))
{
auto& sgroup = sgroups.getSGroup(i);
Expand All @@ -1355,6 +1375,7 @@ std::string SequenceSaver::saveHELM(KetDocument& document, std::vector<std::dequ
static std::string apid_prefix{'R'};
for (int ap_id = sa.attachment_points.begin(); ap_id != sa.attachment_points.end(); ap_id = sa.attachment_points.next(ap_id))
{
ap_count++;
auto& ap = sa.attachment_points.at(ap_id);
std::string apid = apid_prefix + ap.apid.ptr();
atom_to_ap->second.emplace(ap.aidx, apid);
Expand All @@ -1374,6 +1395,23 @@ std::string SequenceSaver::saveHELM(KetDocument& document, std::vector<std::dequ
}
sgroups.remove(i);
}
// check direct monomer to molecule connections without attachment point
if (molecules_connections.count(mol_id) > 0 && ap_count == 0)
{
int ap_idx = 1;
auto res = mol_atom_to_ap.try_emplace(mol_id);
auto& atom_to_ap = res.first;
static std::string apid_prefix{'R'};
for (auto atom_id : molecules_connections.at(mol_id))
{
std::string apid = apid_prefix + std::to_string(ap_idx);
atom_to_ap->second.emplace(atom_id, apid);
// add leaving atom and set it as R-site
auto leaving_atom = pbmol->addAtom(ELEM_RSITE);
pbmol->addBond(atom_id, leaving_atom, BOND_SINGLE);
pbmol->allowRGroupOnRSite(leaving_atom, ap_idx++);
}
}
// generate smiles
std::string smiles;
StringOutput s_out(smiles);
Expand Down
Loading