diff --git a/api/tests/integration/ref/formats/smarts.py.out b/api/tests/integration/ref/formats/smarts.py.out index f335aca6ec..76389645d9 100644 --- a/api/tests/integration/ref/formats/smarts.py.out +++ b/api/tests/integration/ref/formats/smarts.py.out @@ -61,3 +61,5 @@ smarts loaded OK [!#6!#7!#8] is ok. smarts_in==smarts_out [!#6!#7!#8] is ok. json_in==json_out [!#6!#7!#8] is ok. expected string found in json +#1355 Error appeared at save query molecule with RSite as smarts +Ok expected smarts generated diff --git a/api/tests/integration/tests/formats/smarts.py b/api/tests/integration/tests/formats/smarts.py index f1cb3aa367..7c573fcbcf 100755 --- a/api/tests/integration/tests/formats/smarts.py +++ b/api/tests/integration/tests/formats/smarts.py @@ -184,3 +184,15 @@ def test_smarts_load_save_through_ket(smarts_in, expected_str): "[!#6!#7!#8]", '"atoms":[{"type":"atom-list","notList":true,"elements":["C","N","O"],"location":[0.0,0.0,0.0]}]', ) +print("#1355 Error appeared at save query molecule with RSite as smarts") +m = indigo.loadQueryMolecule( + "S=CC(F)CCCCC[C@@](CCO)/C=C/[C@@](N)CCC[C]C([13C]CC([C+2]CC(CC%91)CC(C)CCC)CCC)CC%92.[*:2]%92.[*:1]%91 |$;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;_R2;_R1$,rb:32:*,u:3|" +) +smarts = m.smarts() +expected = "[#16]=[#6]-[#6](-[#6]-[#6]-[#6]-[#6]-[#6]-[#6@](-[#6]=[#6]-[#6@](-[#6]-[#6]-[#6]-[#6]-[#6](-[#6]-[#6]%91)-[13;#6]-[#6]-[#6](-[#6]-[#6]-[#6])-[#6;+2]-[#6]-[#6](-[#6]-[#6](-[#6]-[#6]-[#6])-[#6;x0])-[#6]-[#6]%92)-[#7])-[#6]-[#6]-[#8])-[#9;$([*,#1]=,#,:[*,#1])].[*:2]-%91.[*:1]-%92" +if smarts == expected: + print("Ok expected smarts generated") +else: + print( + "Fail. Expected smarts is\n%s\nbut generated\n%s" % (expected, smarts) + ) diff --git a/core/indigo-core/molecule/src/molecule_json_saver.cpp b/core/indigo-core/molecule/src/molecule_json_saver.cpp index 149c381bf4..981abde417 100644 --- a/core/indigo-core/molecule/src/molecule_json_saver.cpp +++ b/core/indigo-core/molecule/src/molecule_json_saver.cpp @@ -686,7 +686,8 @@ void MoleculeJsonSaver::saveAtoms(BaseMolecule& mol, JsonWriter& writer) int radical = 0; int query_atom_type = QueryMolecule::QUERY_ATOM_UNKNOWN; std::map query_atom_properties; - if (mol.isRSite(i)) + bool is_rSite = mol.isRSite(i); + if (is_rSite) { mol.getAllowedRGroups(i, rg_list); writer.Key("type"); @@ -810,7 +811,7 @@ void MoleculeJsonSaver::saveAtoms(BaseMolecule& mol, JsonWriter& writer) bool ecflag = mol.reaction_atom_exact_change[i]; int hcount = MoleculeSavers::getHCount(mol, i, anum, charge); - if (_pqmol) + if (_pqmol && !is_rSite) // No custom query for RSite { bool needCustomQuery = query_atom_type == QueryMolecule::QUERY_ATOM_UNKNOWN; std::map qprops{{QueryMolecule::ATOM_SSSR_RINGS, "ringMembership"}, @@ -908,7 +909,7 @@ void MoleculeJsonSaver::saveAtoms(BaseMolecule& mol, JsonWriter& writer) writer.Int(query_atom_properties[QueryMolecule::ATOM_IMPLICIT_H]->value_min); } } - else + else if (_pmol) { if (Molecule::shouldWriteHCount(mol.asMolecule(), i) && hcount > 0) { diff --git a/core/indigo-core/molecule/src/query_molecule.cpp b/core/indigo-core/molecule/src/query_molecule.cpp index 8c2989bd75..a64d105cc9 100644 --- a/core/indigo-core/molecule/src/query_molecule.cpp +++ b/core/indigo-core/molecule/src/query_molecule.cpp @@ -678,6 +678,9 @@ void QueryMolecule::writeSmartsAtom(Output& output, Atom* atom, int aam, int chi } break; } + case ATOM_RSITE: + output.printf("*:%d", atom->value_min); + break; default: { throw Error("Unknown atom attribute %d", atom->type);