Hi,

You can create new object that stores MMP and has default pandas and
ipython representation as base64 encoded png. This usually works for me,
but I'm not sure why in this case it works only for ipython representation
and not for pandas.. The code:

# <codecell>

import pandas as pd
import rdkit.Chem as Chem
from rdkit.Chem import PandasTools
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole

# <codecell>

from base64 import b64encode
from StringIO import StringIO

class Reaction():
    def __init__(self, reaction=None):
        self.reaction = reaction

    def _repr_html_(self):
        sio = StringIO()
        Draw.ReactionToImage(self.reaction).save(sio,format='PNG')
        s = b64encode(sio.getvalue())
        return '<img src="data:image/png;base64,%s"/>' %s
    def __str__(self):
        sio = StringIO()
        Draw.ReactionToImage(self.reaction).save(sio,format='PNG')
        s = b64encode(sio.getvalue())
        return '<img src="data:image/png;base64,%s"/>' %s

# <codecell>

MMP_reaction = Chem.rdChemReactions.ReactionFromSmarts("[*:1][H]>>[*:1]C")

# <codecell>

mmp = Reaction(MMP_reaction)

# <codecell>

mmp

# <codecell>

newnew_df = pd.DataFrame(columns=['fig'],index=[1] )
newnew_df['fig'].ix[1] = mmp

# <codecell>

newnew_df

# <codecell>


Regards,
Samo


On Fri, May 9, 2014 at 8:19 AM, <paul.czodrow...@merckgroup.com> wrote:

> Dear Grégori,
>
> when storing the image into a new data frame:
> "
> MMP_reaction = Chem.rdChemReactions.ReactionFromSmarts("[*:1][H]>>[*:1]C")
> newnew_df = pd.DataFrame(columns=['fig'],index=[1] )
> newnew_df['fig'].ix[1] = Draw.ReactionToImage(MMP_reaction)
> "
>
> apparently, the image can be stored in a data frame, but in the ipython
> notebook it is displayed as "<PIL image...."
>
>
>
> Cheers & Thanks so far (in particular for the impressive speed in
> response!),
> Paul
>
> > Hi Paul,
> >
> > You first have to read the MMP into a reaction object
> > (Chem.ReactionFromSmarts).
> >
> > Greg
> >
> > On Friday, May 9, 2014, <paul.czodrow...@merckgroup.com> wrote:
> > Dear Gregori & Samo,
> >
> > thanks for your hints.
> >
> > I just tried running
> >
> > Draw.ReactionToImage("[*:1][H]>>[*:1]C")
> >
> > =>
> >
> > AttributeError: 'str' object has no attribute 'GetNumReactantTemplates'
> >
> >
> >
> > BTW, how would I finally add a picture to a Pandas data frame?
> >
> >
> > Cheers,
> > Paul
>
>
> This message and any attachment are confidential and may be privileged or
> otherwise protected from disclosure. If you are not the intended recipient,
> you must not copy this message or attachment or disclose the contents to
> any other person. If you have received this transmission in error, please
> notify the sender immediately and delete the message and any attachment
> from your system. Merck KGaA, Darmstadt, Germany and any of its
> subsidiaries do not accept liability for any omissions or errors in this
> message which may arise as a result of E-Mail-transmission or for damages
> resulting from any unauthorized changes of the content of this message and
> any attachment thereto. Merck KGaA, Darmstadt, Germany and any of its
> subsidiaries do not guarantee that this message is free of viruses and does
> not accept liability for any damages caused by any virus transmitted
> therewith.
>
> Click http://www.merckgroup.com/disclaimer to access the German, French,
> Spanish and Portuguese versions of this disclaimer.
>
>
> ------------------------------------------------------------------------------
> Is your legacy SCM system holding you back? Join Perforce May 7 to find
> out:
> &#149; 3 signs your SCM is hindering your productivity
> &#149; Requirements for releasing software faster
> &#149; Expert tips and advice for migrating your SCM now
> http://p.sf.net/sfu/perforce
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to