stsouko / CGRtools

CGRs, molecules and reactions manipulation
GNU Lesser General Public License v3.0
2 stars 0 forks source link

Query isomorphism unexepected behaviour #172

Closed tagirshin closed 3 years ago

tagirshin commented 3 years ago

I wanted to create a query from SMILES, so I decided to use molecule.substructure(as_query=True). Then I needed to use isomorphism, but it didn't work as I expected:

Снимок экрана 2021-05-19 в 09 14 35

Next, I decided to delete all hybridization and neighbors marks, but it didn't change anything:

Снимок экрана 2021-05-19 в 09 09 16

Finally, when I constructed query myself, it worked as supposed:

Снимок экрана 2021-05-19 в 09 12 12

So, I don't understand if it is supposed to be like that or it's a bug.

Notebook to reproduce this experiment: query_bug.ipynb.zip

stsouko commented 3 years ago

Molecule Queries now have extra attrs. implicit_hydrogens - for searching atoms with specified amount of hydrogens. ring_sizes - for searching atoms in rings.

For example double bonded CC fragment in 6-member ring where one of atoms contains only one implicit H.

query = QueryContainer()
query.add_atom('C', rings_sizes=6)
query.add_atom('C', rings_sizes=6, hydrogens=1)
query.add_bond(1, 2, 2)

This is fix:

for _, atom in query.atoms():
    atom.neighbors = None
    atom.hybridization = None
    atom.implicit_hydrogens = None
    atom.ring_sizes = None
query
tagirshin commented 3 years ago

Thanks a lot!