Hi Dave,
I actually came across this perculiarity yesterday! I think the problem is
that the copy built-in module only works properly with Python objects, and
rdkit Mol objects are really C++ objects (I’m sure someone else can give a
better explanation). The solution that seemed to work for me is to call the Mol
constructor rather than use the copy module:
In [1]: from rdkit import Chem
In [2]: mol = Chem.MolFromSmiles('c1ccccc1')
In [3]: mol.SetProp('_Name', 'One')
In [4]: mol.SetProp('Prop', '1')
In [5]: mol2 = Chem.Mol(mol)
In [6]: print mol2.GetProp('_Name')
One
In [7]: print mol2.GetProp('Prop')
1
This seems to create a copy rather than just another reference to the same C++
object.
In [8]: mol.SetProp('check_if_same', 'mol')
In [9]: mol2.SetProp('check_if_same', 'mol2')
In [10]: mol.GetProp('check_if_same')
Out[10]: 'mol'
In [11]: mol2.GetProp('check_if_same')
Out[11]: 'mol2'
Hope this helps!
Rich
--
Richard Lewis
PhD Candidate
Centre for Molecular Informatics
University of Cambridge
http://www.ch.cam.ac.uk/group/bender <http://www.ch.cam.ac.uk/group/bender>
> On 27 Mar 2015, at 09:41, Dave Wood <[email protected]> wrote:
>
> Dear All,
>
> I was a little suprised by this behaviour when making a copy of a molecule.
> Is it the expected behaviour?
>
> It isn't a problem for me as I can copy the properties across seperately, but
> I thought it could be worth mentioning.
>
> Dave
>
> IPython 1.2.1 -- An enhanced Interactive Python.
> ? -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help -> Python's own help system.
> object? -> Details about 'object', use 'object??' for extra details.
>
> In [1]: from rdkit import Chem
> In [2]: import copy
> In [3]: mol = Chem.MolFromSmiles("c1ccccc1")
> In [4]: mol.SetProp("_Name", "One")
> In [5]: mol.SetProp("Prop", "1")
> In [6]: mol2 = copy.deepcopy(mol)
> In [7]: print mol2.GetProp("_Name")
> ---------------------------------------------------------------------------
> KeyError Traceback (most recent call last)
> <ipython-input-7-9ad92b63b870> in <module>()
> ----> 1 print mol2.GetProp("_Name")
>
> KeyError: '_Name'
>
> In [8]: print mol2.GetProp("Prop")
> ---------------------------------------------------------------------------
> KeyError Traceback (most recent call last)
> <ipython-input-8-668c3857671a> in <module>()
> ----> 1 print mol2.GetProp("Prop")
>
> KeyError: 'Prop'
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website, sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for all
> things parallel software development, from weekly thought leadership blogs to
> news, videos, case studies, tutorials and more. Take a look and join the
> conversation now.
> http://goparallel.sourceforge.net/_______________________________________________
> Rdkit-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss