redmine and rdkit

To think about DMTA cycle in drug discovery process, I think most important thing is ‘why you make the compound ‘.
We make hypothesis to solve problems, and think about priority what make first. And make it.
Next analyse assay data, and make next plan……
So, issue tracking system is good tool for hypothesis driven drug discovery.
Redmine is one of nice tool for ITS.
But it is not friendly for chemist, because this tool is often used for system development. There are no plug in for chemistry.

Med chem. wants to check issues with chemical structure ;-).
So, I try to very simple solution for post structure to redmine.
Redmine can use REST API.
So, from python, I make structure image using rdkit, and post structure as png image.
Procedure is following..

At first build redmine.(I used bitnami installer for this blogpost)
Then change setting use REST, and show thambnail.
If you check use REST for web app, you can get API key.
Then write simple python script.
I need two steps for post ticket with file.
1st, upload image and get token.
2nd post issue as xml.

# -*- coding:utf-8 -*-
import urllib2
import xml.etree.ElementTree

from rdkit import Chem
from rdkit.Chem import Draw
smiles = "CCCNCc1ccccc1"
filename = smiles+".jpg"
mol = Chem.MolFromSmiles( smiles )
Draw.MolToFile(mol, "out.png")
api_key = 'put on your API key'

f = open( "out.png", 'rb')
img =

url = 'http://localhost:8081/redmine/uploads.xml'
request = urllib2.Request(url, data=img)
request.add_header('Content-Type', 'application/octet-stream')
request.add_header('X-Redmine-API-Key', api_key)
request.get_method = lambda: 'POST'

response = urllib2.urlopen(request)
ret =

doc = xml.etree.ElementTree.fromstring(ret)
token = doc.findtext('token')

xml = """<?xml version="1.0"?>
 <uploads type="array">
</issue>"""%(smiles, token)

url = 'http://localhost:8081/redmine/issues.xml'

# Content-Type:text/xml
# X-Redmine-API-Key:[API]
# method:post

request = urllib2.Request(url, data=xml)
request.add_header('Content-Type', 'text/xml')
request.add_header('X-Redmine-API-Key', api_key)
request.get_method = lambda: 'POST'

response = urllib2.urlopen(request)
ret =
print 'Response:', ret

OK, run script.

Last login: Sat Jan 24 14:10:16 on ttys000
iwatobipen$ cd Desktop/
iwatobipen$ python 
<?xml version="1.0" encoding="UTF-8"?><upload><token>your token</token></upload>
your token
Response: <?xml version="1.0" encoding="UTF-8"?><issue><id>1</id><project id="1" name="ChemoPj"/><tracker id="1" name="バグ"/><status id="1" name="新規"/><priority id="2" name="通常"/><author id="1" name="iwatobipen Admin"/><subject>SytheticPlan1</subject><description>CCCNCc1ccccc1</description><start_date>2015-01-20</start_date><due_date>2015-02-10</due_date><done_ratio>0</done_ratio><is_private>false</is_private><estimated_hours/><spent_hours>0.0</spent_hours><created_on>2015-01-24T05:28:27Z</created_on><updated_on>2015-01-24T05:28:27Z</updated_on><closed_on/></issue>

Opps, I forgot set tracker id, so tracker was bug…
Now check redmine.
Before run script, gantt chart show no ticket.
Screen Shot 2015-01-24 at 2.27.53 PM
After run script, I get one ticket…
Screen Shot 2015-01-24 at 2.29.24 PM
Click this ticket…
Screen Shot 2015-01-24 at 2.58.47 PM
I can check structure.
I want to embed structure editor in redmine, but it is hard work for me. ;-(


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s