switch xcode version

Today I updated xcode version from 7.x to 8.x. After upgrade xcode, keras cause following error.
;-(

iwatobipen$ python
Python 3.5.2 |Anaconda 2.4.0 (x86_64)| (default, Jul  2 2016, 17:52:12) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
......
th=79 :
5368 
===============================
nvcc fatal   : The version ('80000') of the host compiler ('Apple clang') is not supported

.....

Opps ! It is because Cuda version 8 is not supported xcode 8.x.
So, to fix the error, I switched xcode version.

iwatobipen$ sudo xcode-select --switch /Applications/Xcode72.app/Contents/Developer/
iwatobipen$ sudo xcode-select --switch /Applications/Xcode72.app

Retry!

iwatobipen$ ipython
Python 3.5.2 |Anaconda 2.4.0 (x86_64)| (default, Jul  2 2016, 17:52:12) 
Type "copyright", "credits" or "license" for more information.

IPython 4.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import keras
Using Theano backend.

In [2]: 

Worked fine !

Tips for MCS of RDKit

Find MCS is useful function for me, because sometime I want to extract common substructure from compounds.
But, in the case of large amount of compounds set give me boring results like a ethyl and so on. It’s no wonder.

FindMCS function of RDKit has unique solution to solve that. To use “threshold” option I can define the maximum number of molecules that need to calculate MCS.
I found tips, the result of FindMCS with the option depends on order of molecules.
See following codes….

from rdkit import Chem
from rdkit.Chem import MCS
from rdkit.Chem.Draw import IPythonConsole
from rdkit import RDConfig
from rdkit.Chem import FragmentCatalog

mol1 = Chem.MolFromSmiles("Cc1ccccc1")
mol2 = Chem.MolFromSmiles( "CCc1ccccc1" )
mol3 = Chem.MolFromSmiles( "Oc1ccccc1" )
mol4 = Chem.MolFromSmiles( "COc1ccccc1" )
Draw.MolsToGridImage([mol1,mol2,mol3,mol4])

res1

OK get MCS.

res = MCS.FindMCS([mol1,mol2,mol3,mol4], threshold=0.5)
res2 = MCS.FindMCS([mol4,mol3,mol2,mol1], threshold=0.5)
Chem.MolFromSmarts(res.smarts)

res2
Next…

Chem.MolFromSmarts(res2.smarts)

res3

Different order of molecules gave different result. I will keep that mind!!!

An article in JMC.

My background is organic chemistry. I was trained medicinal chemistry on the job.
A topic about training medicinal chemistry was discussed in following article. And It was impressive for me.
https://www.ncbi.nlm.nih.gov/pubmed/27668824

“On the job training” is important for medchems because it makes their back ground of molecular design etc.
The author said,
“””
For example, medicinal chemists who work primarily on CNS diseases will likely face different problems than oncology specialists.
“””

BTW, environment around us is changing.

“””
Chemistry CRO’s worldwide have realized explosive growth as the demand grows for low cost, budget flexible synthesis support. And large pharmas have undoubtedly realized significant operating cost savings as a result of chemistry staff reductions and elimination of expensive synthesis lab space.
“””
I think the sentence is true for large pharma but it does not apply to mid or small pharma. But this trend will be main stream of research area.
It’s means lost of opportunity of on the job training for medicinal chemistry and synthetic chemistry.

What is key factor of training medicinal chemistry ?
Knowledge, skill, mindset…? We often discuss about drug likeness. There are several parameters for drug likeness for example LE, LLE, LogP etc. I think it is experience, what kind of problems did they solve, what kind of chemical series did they make.
They will get sense of medicinal chemistry through these experiences.

One of the reference of the article describe interesting experiment.
http://pubs.acs.org/doi/abs/10.1021/jm049740z
In the reference, author tried simple experiment with a group of 13 chemist volunteers. They judged as unacceptable from a list of a list of 2000 candidate structures. Each list was unique with the exception of 250 compounds that has been previously rejected as lead candidates.
Surprisingly, only one embedded compound was rejected by all 13 chemists! Only one!!! @_@
And the result indicated that the likelihood of a chemist repeating the same judgement of a compound was roughly 50%. I think it is huge task to get consistency of compounds selection with chemists….. Of course I have no confidence to select same compounds set from large number of dataset.

Back to the article. Table1 shows a notable fact. The table describes about ratio of publications in JMC with property considerations during optimization.
The percentage of the ratio is low in U.S. academia. The author discussed about the data. If reader who is interested, I recommend to read the article.

Automatic molecular designer

Recently, there are many articles and news about deep learning in web, journal etc.

“AI” is hot word.  You know, one of the very unique example is a system named “deep dream” which is a computer vision program created by google. The system generate new images from trained network. Neural network app also can generate songs, documents, poems and so on.

I am interested in making molecular designer using AI like deepdream. It’s mean MedChem AI!

Yesterday I found amazing article. The title was “Automatic chemical design using a data-driven continuous representation of molecules”.

Click to access 1610.02415.pdf

One of the author is belonging to twitter inc. It’s interesting too. Is Twitter inc. interested in drug discovery ?? Hmm…

I felt the strategy of the article like a text mining because they used Smiles strings as input layer.

They used auto encoder and decoder  to generate molecules as smiles string. And RDKit is used for descriptor calculation and validate smiles. ;-)

After training and optimizing hyper parameters, the NN could generate similar but different molecules. It was amazing for me.

I think the work is nice, but there are some problems.

1st, this system used smiles strings as input and convert it to fixed length vector. Is the vector represents primitive of molecules?

2nd, the vector depends on 2D descriptors I think. For the protein, molecules are 3D object. So, we need to think the molecules as 3D.

Do data scientists produce artificial medicinal chemist, molecular designer  ?

I started to think about the  role of medicinal chemist again.

 

 

 

 

 

 

Extract Chemical Data From PDF, HTML, text etc.

I think medicinal chemist often grapple with many patents ,literatures and etc.
You know, recently there are many commercially available patent database. So, if we could use these databases, we can get data that is embedded in patens. But, if we don’t have them, we need to extract data from pdf or xml. This is time consuming step for me. ;-(

Yesterday, I read very cool article in J Chem Inf Model.
The title of the article is “ChemDataExtractor: A toolkit for automated extraction of chemical information from the scientific literature”.
DOI: 10.1021/acs.jcim.6b00207
http://pubs.acs.org/doi/abs/10.1021/acs.jcim.6b00207
Fortunately the authors released the tookit under MIT license and available to download from following URL.
http://chemdataextractor.org
Chemdataextractor also be installed using pip command!! ;-)

What’s ChemDataExtractor ?
ChemDataExtractor is text-mining pipeline. The system reads PDF/HTML/XML and categorize Abstract/Full text/captions and tables. Then process document / tables.

PDF documents are analyzed with PDFMiner framework.
It means that ChemDataExtractor can analyze PDF files like Patents!

Surprisingly, the system has table parser! In the article, fig.6 shows scheme of text parsing system. I think it is useful to extract biological data from tables.

Now I tested PDF parsing.
In my default environment (python3.5), chemdataextractor did not work so I switched python2.7 environment.
When I used python2.7, the system worked.
At first, I got sample data from patentlens.
https://www.lens.org/lens/
Then read PDF. My code is following.

from pdfminer.pdfdocument import PDFDocument
from chemdataextractor import Document
from chemdataextractor.reader import PdfReader
import cirpy
pdffile = open("AU_2004_236144_A1.pdf")

#This code is different from official document example.
#readers=[PdfDocumentReader] did not work.
#cems means chemical named entity.
doc=Document.from_file(pdffile, readers=[PdfReader()])
len(doc.cems)

Out[37]:927

OK, I got 927 chemical named entities.
Then I extracted some data.

doc.cems[600:620]

Out[54]:
[Span('vinca  alkaloids', 883, 899),
 Span('sertraline', 163, 173),
 Span('thienyl', 148, 155),
 Span('vincristine', 907, 918),
 Span('prednisolone', 202, 214),
 Span('vindesine', 935, 944),
..........

It worked fine.

In the official site, more examples are described.
Also interactive online demo is worth to trying.
http://chemdataextractor.org/demo

The system has opsin/cirpy so, the demo site can convert name to structure too.

I think the article is useful not only medicinal chemist for extract structure data but also computer chemist for text mining.

Draw radar chart with R

A radar chart is a graphical method of displaying multivariate data in the form of a two-dimensional chart of three or more quantitative variables represented on axes starting from the same point. The relative position and angle of the axes is typically uninformative. (from wikipedia)

It’s useful for visualize multi parameters in drug discovery.
For example, visualize compound profile, Lipinsky rule, ADMET profile etc….
Yesterday, I found new library to make radar chart in R language named ggradar.
https://github.com/ricardo-bion/ggradar
You know, ggradar is library based on ggplot2. It sounds nice! I used ggradar.
I wrote simple example using iris dataset.
I used dpylr for data preparation. ( dplyr is cool library !!!! )

library(ggradar);
library(scales);
suppressMessages( library(dplyr) );
irisdata <- iris %>% 
            group_by( Species ) %>%
            mutate_each(funs(rescale)) %>%
            summarise( mean(Sepal.Length), mean(Sepal.Width), mean( Petal.Length ), mean( Petal.Width )  )
ggradar( irisdata )

Then I got following image.
rplot

ggradar can set many option, font color, size and line size etc.
But now legend text size can not change. The issue is submitted github.

Ggradar is early project, but useful and attractive library for me.

沼津港に釣りに行った話(何も釣れなかったけど)

今日は、10年以上ぶりに沼津港に釣りに行った。釣竿も新調したが、初心者用のサビキでの挑戦。
昼前くらいからのんびり釣り糸を投げ込むわけですが、まったく釣れない(−_−;)
隣ではイワシがぽこぽこ上がってるわけですが、、、がっかりとうなだれつつ、ヒトカゲをゲットして帰宅となりましたとさ。
沼津港は昔から鉄くず置き場がありまして、ちょっと前は火事もあったようですね。

久しぶりに近くで見たんですが、普段の会社と家の通勤では感じることのない非日常がポコっとそこだけあるような雰囲気を感じ、しばらくボケーっと見てました。あたり一面鉄錆の赤色と、サビの匂いと、潮の匂いと。当たり前ですが普段会社の研究室過ごしている時とは全く異なった風景。
この辺りに釣りに来たのは中学生の頃だったかなあ、、、もう随分と前の話。

img_2455

img_2458
釣りに行ったって書いておいて海の写真と魚の写真がないのは、ご愛嬌。
一匹も釣れなくて今日は大失敗。