Dear Markus,
On Tue, Aug 25, 2009 at 3:28 PM, markus<[email protected]> wrote:
> Hi there,
> I want to store some RD Molecule objects in an arbitrary database along
> with some other arrays, numbers ect. Now I looked at the DBase Folders
> as well as the DB command line tools in the DbCLI Project, but I just
> don't get an overview, so here's the question:
> I have the plenty of database Modules and SQL based servers installed
> (not fixed to one particular as I will have to learn them anyway :-) )
I think this is a good way to do it.
> and what I now want to do is simply store a RD Mol (precisely: a
> PropertyMol, Greg) object in a column.
>
> What I tried:
> ''''''''''''''''''''''''''''''''''''''''
> #!/usr/bin/python
> from rdkit import Chem
> import sys,time
> import pg
> import cPickle
> from Chem.PropertyMol import *
>
> dbname='mydb'
> tablename='test2'
>
> db=pg.DB(dbname)
> mol=Chem.MolFromSmiles('CC(O)CCCN')
> pkl=cPickle.dumps(mol)
> test={}
> test['mol']=pkl
> db.insert('test2', test)
> ''''''''''''''''''''''''''''''''''''''''''''''
> The error I get complains about the special characters
> in the pickled Mol :-(
> Storing the binString didn't work either.
> Which dattatype does work?
I'm not completely certain about the database wrapper you are using,
but one normally needs to provide some special structure to be able to
store binary strings (pickled mols from RDKit are binary strings) in
databases. You will have to look at the details of your database layer
to see exactly what type you need to provide. For example, for sqlite
you need to provide a python buffer, for the pyPgSQL wrapper for
postgresql it's a pyPgSQL.PgBytea, etc. You might want to try:
> test['mol']=buffer(pkl)
> db.insert('test2', test)
if that doesn't work, check the documentation for your database wrapper.
>
> Second Trial:
> Using the RDKit DbCLI modules directly, but how?
> Didn't get it working
>
> Any help/explanation/pointers would be fine
What specific problems are you having? Have you seen this wiki page?
http://code.google.com/p/rdkit/wiki/UsingTheDbCLI
>
> PS:
> I also tried to use the shelve module and use the smiles as key and the
> mol as value -> no Problem.
glad that it works, but as you know that's not quite as convenient as
a proper database.
-greg