Skip to content

Commit

Permalink
add some basic docs for using the cartridge from python
Browse files Browse the repository at this point in the history
  • Loading branch information
greglandrum committed Oct 24, 2013
1 parent 02aff3a commit 7fe3b46
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Docs/Book/Cartridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,41 @@ Other

There are additional functions defined in the cartridge, but these are used for internal purposes.


Using the Cartridge from Python
+++++++++++++++++++++++++++++++

The recommended adapter for connecting to postgresql is pyscopg2
(https://pypi.python.org/pypi/psycopg2).

Here's an example of connecting to our local copy of ChEMBL and doing
a basic substructure search::

>>> import psycopg2
>>> conn = psycopg2.connect(database='chembl_16')
>>> curs = conn.cursor()
>>> curs.execute('select * from rdk.mols where m@>%s',('c1cccc2c1nncc2',))
>>> curs.fetchone()
(9830, 'CC(C)Sc1ccc(CC2CCN(C3CCN(C(=O)c4cnnc5ccccc54)CC3)CC2)cc1')

That returns a SMILES for each molecule. If you plan to do more work
with the molecules after retrieving them, it is much more efficient to
ask postgresql to give you the molecules in pickled form::

>>> curs.execute('select molregno,mol_send(m) from rdk.mols where m@>%s',('c1cccc2c1nncc2',))
>>> row = curs.fetchone()
>>> row
(9830, <read-only buffer for 0x...>)

These pickles can then be converted into molecules::

>>> from rdkit import Chem
>>> m = Chem.Mol(str(row[1]))
>>> Chem.MolToSmiles(m,True)
'CC(C)Sc1ccc(CC2CCN(C3CCN(C(=O)c4cnnc5ccccc54)CC3)CC2)cc1'



License
+++++++

Expand Down

0 comments on commit 7fe3b46

Please sign in to comment.