On Sep 25, 2012, at 3:18 PM, JP wrote:
> I understand the below returns false because of the different Mol instances, 
> but is there an "easyish" way (without comparing inchis, fingerprints, 
> converting to canonical Smiles etc) how to override the == to return True?
> 
> >>> import rdkit
> >>> from rdkit import Chem
> >>> m1 = Chem.MolFromSmiles('CC')
> >>> m2 = Chem.MolFromSmiles('CC')
> >>> m1 == m2
> False
> 

>>> from rdkit import Chem
>>> Chem.Mol
<class 'rdkit.Chem.rdchem.Mol'>
>>> Chem.Mol.__eq__
<method-wrapper '__eq__' of Boost.Python.class object at 0x7fc778ee2770>
>>> def return_true(self, other):
...     return True
... 
>>> Chem.Mol.__eq__ = return_true
>>> m1 = Chem.MolFromSmiles("CC")
>>> m2 = Chem.MolFromSmiles("CC")
>>> m1 == m2
True
>>> 

But I don't suppose that's what you want. What does it mean for two
molecules to be equal? That they have the same chemical graph? Do
they also need the same properties? Conformers?

More realistically, adding a non-trivial __eq__ is a bad thing.
Consider:

table = {}
for mol in molecules:
  table[mol] = compute_some_property(mol)

This gives a way to associate extra per-molecule information. It works
because hash(mol) is just the underlying pointer value, and m1 == m2 is
fast. If that's changed to do any non-trivial computation, then it's no
longer fast, and table lookup becomes prohibitively slow.

Also, in RDKit, SMARTS are turned into molecules. How does one
compare two different SMARTS molecules, like

>>> m1 = Chem.MolFromSmarts("[*+,*-;C]")
>>> m2 = Chem.MolFromSmarts("[C+,C-]")

                                Andrew
                                da...@dalkescientific.com



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to