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

#1316 SMARTS saver miss component level grouping #1317

Merged
merged 1 commit into from
Oct 10, 2023
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/smarts.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ CC[C+5]CCCCC
[#9]/[#6]=[C]/[#17] is ok. smarts_in==smarts_out
[O;H] is ok. smarts_in==smarts_out
[!O;H] is ok. smarts_in==smarts_out
([#6]1-[#6]-[#6]-1.[#6]) is ok. smarts_in==smarts_out
1 change: 1 addition & 0 deletions api/tests/integration/tests/formats/smarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ def test_smarts_load_save(smarts_in):
test_smarts_load_save("[#9]/[#6]=[C]/[#17]")
test_smarts_load_save("[O;H]")
test_smarts_load_save("[!O;H]")
test_smarts_load_save("([#6]1-[#6]-[#6]-1.[#6])")
24 changes: 14 additions & 10 deletions core/indigo-core/molecule/src/smiles_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ void SmilesSaver::_saveMolecule()
v_to_comp_group.resize(v_seq.size());
v_to_comp_group.fffill();

if (_qmol != nullptr && smarts_mode && _qmol->components.size() >= v_seq.size())
if (_qmol != nullptr && smarts_mode)
{
if (v_seq.size() < 1)
return; // No atoms to save
std::set<int> components;
int cur_component = -1;
for (int i = 0; i < v_seq.size(); ++i)
for (int i = 0; i < v_seq.size(); ++i && _qmol->components.size() > 0)
{
// In v_seq each fragment started with vertex which parent == -1
// In SMARTS some fragments could be grouped (component-level grouping)
Expand All @@ -204,20 +204,24 @@ void SmilesSaver::_saveMolecule()
// All group fragments should go one by one - in SMARTS its inside "()".
if (v_seq[i].parent_vertex < 0) // New Fragment
{
int new_component = _qmol->components[v_seq[i].idx];
// if component defined for new fragment(id>0) and its different from previous and seen before
if (new_component > 0 && new_component != cur_component && components.count(new_component))
int new_component = 0;
if (_qmol->components.size() > v_seq[i].idx)
{
// According to the DfsWalk code, the groups components should be neighbors.
// If will be found case when it wrong - add code to rearrange fragments
throw Error("SMARTS fragments need to reaarange.");
new_component = _qmol->components[v_seq[i].idx];
// if component defined for new fragment(id>0) and its different from previous and seen before
if (new_component > 0 && new_component != cur_component && components.count(new_component))
{
// According to the DfsWalk code, the groups components should be neighbors.
// If will be found case when it wrong - add code to rearrange fragments
throw Error("SMARTS fragments need to reaarange.");
}
components.emplace(new_component);
}
components.emplace(new_component);
cur_component = new_component;
}
else
{
if (cur_component != _qmol->components[v_seq[i].idx])
if (_qmol->components.size() > v_seq[i].idx && cur_component != _qmol->components[v_seq[i].idx])
{
// Fragment contains atoms from different components - something went wrong
throw Error("Fragment contains atoms from different components.");
Expand Down
Loading