Forgot to reply to the mailing list:
---
You would need to register the OID of the mol type in psycopg2, like
this for example:
def cast_cube(value, cursor):
"""
"""
if value:
return map(float, value[1:-1].split(','))
CUBE = psycopg2.extensions.new_type((CUBE_OID,), "CUBE", cast_cube)
psycopg2.extensions.register_type(CUBE)
Instead of cast_cube you would create an RDMol from the SMILES string.
On Tue, May 8, 2012 at 12:52 PM, Greg Landrum <[email protected]> wrote:
> Dear Jean-Paul,
>
> On Tue, May 8, 2012 at 11:59 AM, JP <[email protected]> wrote:
>>
>> I have an rdkit enabled database - with a table which contains a "mol"
>> column (called rdkitmol).
>>
>> I am using the python database driver psycopg2 to access this table from a
>> python program.
>>
>> My question is: Is there a way how to use the "mol" object in the DB as an
>> rdkit mol in python directly?
>>
>> I was thinking I could do something like:
>>
>>> cur.execute("SELECT rdkitmol FROM molecule LIMIT 5;")
>>> for t in cur:
>>> print t[0]
>>> print Descriptors.MolWt(t[0])
>>
>>
>> But this doesn't work as t[0] is not of the correct type (i.e.
>> rdkit.Chem.rdchem.Mol).
>>
>> Of course, I could use the rdkitmol smiles to create an
>> rdkit.Chem.rdchem.Mol instance in python (e.g. Chem.MolFromSmiles) but I was
>> wondering if there was a more efficient way to do this as presumably the
>> "mol" column stores an instance of the rdkit.Chem.rdchem.Mol already.
>
> There is. The solution is a bit ugly, but it should work. To prevent
> the automatic conversion to a string (which gives you a smiles), you
> need to do the following:
>
> In [5]: curs.execute("select molregno,m,mol_send(m) from rdk.mols limit 10")
>
> In [6]: r = curs.fetchone()
>
> In [7]: r
> Out[7]:
> (122,
> 'c1cc(CN2CCN(C[C@H]3NCCC3)CC2)ccn1',
> <read-only buffer for 0x100429a10, size 283, offset 0 at 0x1026b6c30>)
>
> In [10]: m = Chem.Mol(str(r[-1]))
>
> In [11]: Chem.MolToSmiles(m)
> Out[11]: 'c1cc(CN2CCN(CC3NCCC3)CC2)ccn1'
>
>> Hope you had a good holiday Greg!
>
> I did!
>
> -greg
>
> ------------------------------------------------------------------------------
> 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
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss