ó
a#nSc           @   sm   d  d l  m Z d e j f d „  ƒ  YZ d „  Z e d k ri d  d l Z e ƒ  \ Z Z e j	 e ƒ n  d S(   iÿÿÿÿ(   t   Chemt   PropertyMolc           B   s8   e  Z d  Z e Z d „  Z d „  Z d „  Z d „  Z RS(   s   allows rdkit molecules to be pickled with their properties saved.

   >>> import cPickle
   >>> m = Chem.MolFromMolFile('test_data/benzene.mol')
   >>> m.GetProp('_Name')
   'benzene.mol'

   by default pickling removes properties:
   >>> m2 = cPickle.loads(cPickle.dumps(m))
   >>> m2.HasProp('_Name')
   0

   Property mols solve this:
   >>> pm = PropertyMol(m)
   >>> pm.GetProp('_Name')
   'benzene.mol'
   >>> pm.SetProp('MyProp','foo')
   >>> pm.HasProp('MyProp')
   1

   >>> pm2 = cPickle.loads(cPickle.dumps(pm))
   >>> Chem.MolToSmiles(pm2)
   'c1ccccc1'
   >>> pm2.GetProp('_Name')
   'benzene.mol'
   >>> pm2.HasProp('MyProp')
   1
   >>> pm2.GetProp('MyProp')
   'foo'
   >>> pm2.HasProp('MissingProp')
   0

   Property mols are a bit more permissive about the types
   of property values:
   >>> pm.SetProp('IntVal',1)

   That wouldn't work with a standard mol:
   >>> m.SetProp('IntVal',1)
   Traceback (most recent call last):
     ...
   ArgumentError: Python argument types in
       Mol.SetProp(Mol, str, int)
   did not match C++ signature:
     ...

   but the Property mols still convert all values to strings before storing:
   >>> pm.GetProp('IntVal')
   '1'
   
   This is a test for sf.net issue 2880943: make sure properties end up in SD files:
   >>> import tempfile,os
   >>> fn = tempfile.mktemp('.sdf')
   >>> w = Chem.SDWriter(fn)
   >>> w.write(pm)
   >>> w=None
   >>> txt = file(fn,'r').read()
   >>> '<IntVal>' in txt
   True
   >>> try:
   ...   os.unlink(fn)
   ... except:
   ...   pass

   The next level of that bug: does writing a *depickled* propertymol
   to an SD file include properties:
   >>> fn = tempfile.mktemp('.sdf')
   >>> w = Chem.SDWriter(fn)
   >>> pm = cPickle.loads(cPickle.dumps(pm))
   >>> w.write(pm)
   >>> w=None
   >>> txt = file(fn,'r').read()
   >>> '<IntVal>' in txt
   True
   >>> try:
   ...   os.unlink(fn)
   ... except:
   ...   pass


   
  c         C   sc   t  | t j ƒ s d  St j j |  | ƒ x3 | j d t ƒ D] } |  j | | j | ƒ ƒ q< Wd  S(   Nt   includePrivate(   t
   isinstanceR    t   Molt   __init__t   GetPropNamest   Truet   SetPropt   GetProp(   t   selft   molt   pn(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/PropertyMol.pyR   [   s
     c         C   s    t  j j |  | t | ƒ ƒ d  S(   N(   R    R   R   t   str(   R
   t   nmt   val(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/PropertyMol.pyR   `   s    c         C   sN   i  } x- |  j  d t ƒ D] } |  j | ƒ | | <q Wi |  j ƒ  d 6| d 6S(   NR   t   pklt   propD(   R   R   R	   t   ToBinary(   R
   t   pDictR   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/PropertyMol.pyt   __getstate__b   s
    c         C   sL   t  j j |  | d ƒ x. | d j ƒ  D] \ } } |  j | | ƒ q( Wd  S(   NR   R   (   R    R   R   t	   iteritemsR   (   R
   t   stateDt   propR   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/PropertyMol.pyt   __setstate__h   s    (	   t   __name__t
   __module__t   __doc__R   t   __getstate_manages_dict__R   R   R   R   (    (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/PropertyMol.pyR      s   Q			c          C   s5   d d  l  }  d d  l } |  j | j d d |  j ƒS(   Niÿÿÿÿt   __main__t   optionflags(   t   doctestt   syst   testmodt   modulest   ELLIPSIS(   R   R    (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/PropertyMol.pyt   _testr   s    R   N(
   t   rdkitR    R   R   R$   R   R    t   failedt   triedt   exit(    (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/PropertyMol.pyt   <module>   s   j	