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

#1371 Chirality symbol is added to the SMARTS when 'single up/down' or 'double cis/trans' bond type is set up #1382

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions api/tests/integration/ref/formats/custom_query.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
ket_with_rb_as_drawn.ket OK. Smarts equals expected string '[#6](-[#6])(-[#6;x0])-[#6]'
**** #1337 wrong smarts for ring bond count as drawn ****
ket_with_custom_query_with_list.ket OK. Smarts equals expected string '[#6]1-[#6]=[Cl,Br,I,Na,O]-[#6]=[#6]-[#6]=1'
**** #1371Chirality symbol is added to the SMARTS when 'single up/down' or 'double cis/trans' bond type is set up wrong smarts for ring bond count as drawn ****
ket_with_bond_stereo_ether.ket OK. Smarts equals expected string '[#6]1-[#6]=[#6]-[#6]=[#6]\[#6]=1'
9 changes: 9 additions & 0 deletions api/tests/integration/tests/formats/custom_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ def test_ket_to_smarts(filename, expected_str):
fname = "ket_with_custom_query_with_list.ket"
expected = "[#6]1-[#6]=[Cl,Br,I,Na,O]-[#6]=[#6]-[#6]=1"
test_ket_to_smarts(fname, expected)

print(
"**** #1371Chirality symbol is added to the SMARTS when "
"'single up/down' or 'double cis/trans' bond type is set up"
" wrong smarts for ring bond count as drawn ****"
)
fname = "ket_with_bond_stereo_ether.ket"
expected = "[#6]1-[#6]=[#6]-[#6]=[#6]\[#6]=1"
test_ket_to_smarts(fname, expected)
108 changes: 108 additions & 0 deletions api/tests/integration/tests/formats/ref/ket_with_bond_stereo_ether.ket
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"root": {
"nodes": [
{
"$ref": "mol0"
}
]
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
2.9673491521285666,
-16.35007441717461,
0
]
},
{
"label": "C",
"location": [
4.697650847871435,
-16.349589229177205,
0
],
"stereoLabel": "abs"
},
{
"label": "C",
"location": [
3.8341375094912395,
-15.849966888850188,
0
]
},
{
"label": "C",
"location": [
4.697650847871435,
-17.35053206782215,
0
]
},
{
"label": "C",
"location": [
2.9673491521285666,
-17.35502005679814,
0
]
},
{
"label": "C",
"location": [
3.836320855479559,
-17.850033111149813,
0
]
}
],
"bonds": [
{
"type": 2,
"atoms": [
2,
0
]
},
{
"type": 1,
"atoms": [
0,
4
]
},
{
"type": 2,
"atoms": [
4,
5
]
},
{
"type": 1,
"atoms": [
5,
3
]
},
{
"type": 2,
"atoms": [
3,
1
]
},
{
"type": 1,
"atoms": [
1,
2
],
"stereo": 6
}
]
}
}
5 changes: 3 additions & 2 deletions core/indigo-core/molecule/query_molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,9 @@ namespace indigo

static std::string getSmartsBondStr(QueryMolecule::Bond* bond);
static void writeSmartsBond(Output& output, QueryMolecule::Bond* bond, bool has_or_parent);
static std::string getSmartsAtomStr(QueryMolecule::Atom* atom);
static void writeSmartsAtom(Output& output, Atom* atom, int aam, int chirality, int depth, bool has_or_parent, bool has_not_parent);
static std::string getSmartsAtomStr(QueryMolecule::Atom* atom, int original_format);
static void writeSmartsAtom(Output& output, Atom* atom, int aam, int chirality, int depth, bool has_or_parent, bool has_not_parent,
int original_format);

enum QUERY_ATOM
{
Expand Down
2 changes: 1 addition & 1 deletion core/indigo-core/molecule/src/molecule_json_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ void MoleculeJsonSaver::saveAtoms(BaseMolecule& mol, JsonWriter& writer)
if (needCustomQuery)
{
QueryMolecule::Atom& atom = _pqmol->getAtom(i);
std::string customQuery = QueryMolecule::getSmartsAtomStr(&atom);
std::string customQuery = QueryMolecule::getSmartsAtomStr(&atom, _pqmol->original_format);
writer.Key("customQuery");
writer.String(customQuery.c_str());
}
Expand Down
29 changes: 19 additions & 10 deletions core/indigo-core/molecule/src/query_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,11 @@ void QueryMolecule::writeSmartsBond(Output& output, Bond* bond, bool has_or_pare
}
}

std::string QueryMolecule::getSmartsAtomStr(QueryMolecule::Atom* atom)
std::string QueryMolecule::getSmartsAtomStr(QueryMolecule::Atom* atom, int original_format)
{
Array<char> out;
ArrayOutput output(out);
writeSmartsAtom(output, atom, -1, -1, 1, false, false);
writeSmartsAtom(output, atom, -1, -1, 1, false, false, original_format);
std::string result{out.ptr(), static_cast<std::size_t>(out.size())};
return result;
}
Expand Down Expand Up @@ -438,7 +438,7 @@ static void writeAnd(Output& _output, QueryMolecule::Node* node, bool has_or_par
_output.writeChar(';');
}

void QueryMolecule::writeSmartsAtom(Output& output, Atom* atom, int aam, int chirality, int depth, bool has_or_parent, bool has_not_parent)
void QueryMolecule::writeSmartsAtom(Output& output, Atom* atom, int aam, int chirality, int depth, bool has_or_parent, bool has_not_parent, int original_format)
{
int i;

Expand All @@ -454,7 +454,7 @@ void QueryMolecule::writeSmartsAtom(Output& output, Atom* atom, int aam, int chi
break;
}
output.writeChar('!');
writeSmartsAtom(output, atom->child(0), aam, chirality, depth + 1, has_or_parent, true);
writeSmartsAtom(output, atom->child(0), aam, chirality, depth + 1, has_or_parent, true, original_format);
break;
}
case OP_AND: {
Expand Down Expand Up @@ -498,7 +498,7 @@ void QueryMolecule::writeSmartsAtom(Output& output, Atom* atom, int aam, int chi
output.writeChar(has_or_parent ? '&' : ';');
cur_pos = output.tell();
}
writeSmartsAtom(output, atom->child(i), aam, chirality, depth + 1, has_or_parent, has_not_parent);
writeSmartsAtom(output, atom->child(i), aam, chirality, depth + 1, has_or_parent, has_not_parent, original_format);
}
break;
}
Expand All @@ -512,7 +512,7 @@ void QueryMolecule::writeSmartsAtom(Output& output, Atom* atom, int aam, int chi

if (i > 0)
output.printf(has_not_parent ? "!" : ",");
writeSmartsAtom(output, atom->child(i), aam, chirality, depth + 1, true, has_not_parent);
writeSmartsAtom(output, atom->child(i), aam, chirality, depth + 1, true, has_not_parent, original_format);
}
break;
}
Expand All @@ -521,10 +521,19 @@ void QueryMolecule::writeSmartsAtom(Output& output, Atom* atom, int aam, int chi
break;
case ATOM_NUMBER: {
output.printf("#%d", atom->value_max);
if (chirality == 1)
output.printf("@");
else if (chirality == 2)
output.printf("@@");
switch (original_format)
{
case SMARTS:
case KET:
// SMARTS and ket save chirality in ATOM_CHIRALITY for query molecule
break;
default:
if (chirality == 1)
AliaksandrDziarkach marked this conversation as resolved.
Show resolved Hide resolved
output.printf("@");
else if (chirality == 2)
AliaksandrDziarkach marked this conversation as resolved.
Show resolved Hide resolved
output.printf("@@");
break;
}

if (aam > 0)
output.printf(":%d", aam);
Expand Down
2 changes: 1 addition & 1 deletion core/indigo-core/molecule/src/smiles_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ void SmilesSaver::_saveMolecule()
else if (_qmol != 0)
{
int aam = _bmol->reaction_atom_mapping[v_idx];
QueryMolecule::writeSmartsAtom(_output, &_qmol->getAtom(v_idx), aam, _atoms[v_idx].chirality, 0, false, false);
QueryMolecule::writeSmartsAtom(_output, &_qmol->getAtom(v_idx), aam, _atoms[v_idx].chirality, 0, false, false, _qmol->original_format);
}
else
throw Error("SMARTS format available for query only!");
Expand Down