June 29, 2010
跳跃,两岁半
Filed by
charlie
at 9:55 pm under son
No Comments
Lucene is a great tool for retrieving fragmented information even including the fragmenting process (the Analyzer). So there was an intuitional way to retrieving molecules from a cheminformation database with the Lucene engine. ChemSink’s about (http://www.chemsink.com/about/) also mentions that "The chemical search uses Open Babel, Lucene, and MySQL ". Recently I have worked it out and have deployed on production services.
The concepts is connected as blow and the implementation is not hard. I work on my cheminformation platforms based on .NET and use Lucene.NET.
The most popular similarity algorithm being used is the Tanimato as written as
As my understanding, this coefficient is so widely used most because it’s simple and running fast for some time-critical cases such as online searching.
Lucene employs Cosin-Similarity with Vector Space Model (VSM) of Information Retrieval.
http://lucene.apache.org/java/3_0_0/api/all/org/apache/lucene/search/Similarity.html
and norm(t,d) part includes three parts to be multiplied, the lengthNorm part stands for what is effected by the length of the document (total fingerprint bits count of a molecule).
The default Similarity implementation inside Lucene is ready to be used for similar molecules retrieving.
In my researching phase I have found that the scores of several different target molecules are the same in value. It’s found that the lengthNorms are all the same for this several molecule while they have various number of fingerprint bits been set. The lengthNorm is not calculated while the searching phase but pre-calculated and stored at the indexing phase. Finally I have found this sentence inside the Lucene documents.
"However the resulted norm value is encoded as a single byte before being stored… comes with the price of precision loss"
So my molecules are treated as the same length documents when being queried.
| Molecule ID | # of bits set |
lengthNorm calculated |
lengthNorm stored and been |
|
| 11096 | 23 | 0.2085 | 0.1875 | |
| 11578 | 27 | 0.19245 | 0.1875 | |
| 201736 | 28 | 0.18838 | 0.1875 |
The formula to calculate lengthNorm is 1.0 / Math.Sqrt(bits_set)
Fortunately, the DefaultSimilarity class could be overrided including the lengthNorm function. According to Duan Lian’s diagram of distribution of number of fingerprint bit set, there exists a function to mapping this distribution to a more flat one and been using to calculate lengthNorm and take full advantage of the precision-limited value.
Here is the distribution of fingerprint darkness of my database of 80000 commercial compounds.
Filed by
charlie
at 11:36 pm under Lucene, chemoinformatics
6 Comments
开车两年多,所有倒霉事都在这一周一起发生了,人品危机集中爆发。
礼拜一
一大早,上车之后准备从车位倒车,咦?好大的霜啊,白花花一片啥也看不见涅。老婆说,霜你个头,后风挡玻璃碎了!
然后和保安交涉,保安大哥没有半点承担责任的意思,还叫来同伴一起看,哇塞,玻璃碎成这样了,这得 duangduangduang敲半天啊,咱们咋都没听见呢?我说,我靠,这是钢化玻璃。一想反正有保险,还着急上班,就跟保安讲了讲职业精神和当责的态 度,鼓励他们在平凡的岗位上要做出不平凡的事业。差不多b装足了,开车上班。
保险公司服务态度忒好,看到早上我打过去的未接来电,主动找上来服务,说,我们派人上门给你装玻璃。窃喜。
保险公司的各个岗位、玻璃公司的总公司、分公司、业务员分别给我打电话,把基本情况轮番问过一遍,差点把 我逼疯才说好磨蹭到周二才到办公司上了门换。
礼拜二
因为满办公室找不到当天的报纸,玻璃大哥对我们公司的高科技性质和我的高级白领身份表 示了充分的怀疑。玻璃装得很快,期间要求我跟碎玻璃合影时pose摆得也不赖。不过天黑我快要回家的时候,玻璃大哥又回来了,说,保险公司说,你的车没年检。
哦?买车的时候已经检过了啊…
玻璃大哥有点激了。但是一想到没有必要跟一个假白领说这些,就怜悯地嘱咐我48小时内赶快检车,还有戏。
礼拜三
早上网上查好,马池口检车容易点,也比不像海淀那样车多。同时4S店推荐,去找个检车俱乐部,多花点钱省事。想趁中午吃饭, 赶快办完,到了一看,喔靠,满院子车排队都转了圈了。俱乐部大姐看我可怜,说,你先把尾气检了,明早八点之前就来,排头一号,检别的。
礼拜四
天没亮二奔北六环。亏着有俱乐部大姐,要不这乱码七糟的事情非把我这个外行整死不可。眼瞅就完事大吉,大姐说,我不是让你把保险单副本带来吗?你这个是正 本!我说,复印一个不就有副本了吗?从大姐眼神里我读懂一个字,滚,我照办了。
礼拜四中午
开车回家,死活找不到今年的副本,头两年的都找 到了。打电话问问头两年的好使不,俱乐部大姐直接给挂了。
一怒之下,打电话给保险公司,重办一个副本,哥有正本还愁副本吗?保险公司态度很好,你 来吧,我们在宣武。喔靠,保险公司在宣武?!好几年了我咋不知道涅?电话投保上门送单子,压根就没想过保险公司在哪这个问题。
不管是哪,今天必须 办完,哥就这么倔。
从回龙观一路干到南二环,走过头了,再回来,好歹是找到了。副本办的还挺顺利。重新上路,目标北六环。太tm远了,北京环路照这种半径的指数增长,九环就可以把高丽国都圈进来了。
八达岭高速上, 又产生一个傻b念头,从高速主路直接跑到北六环出来,岂不是省钱且快速?md北六环没有上辅路的出口,一路飘过,高速费翻了三倍,还要折返跑回,天都黑 了。
终于在检测场下班前15分钟赶到,俱乐部大姐还在等我。我也莫名迈出一种使命完成的豪迈脚步,掏出副本,加西亚,你的信!
俱乐部大姐 不愧是专业的,没两分钟回来了。还是不通过,你有违章。我一举手,大姐赶快捂脸。何必呢?至于吗?我举手理了理头发,脸上不变的洒脱的微笑,咬着牙根说, 再见。
玻璃大哥还在昏暗的路灯下,痴痴等我拿着新行驶证去照相。鼓起勇气打电话帮忙跟保险公司再通融一日。咋地吧,反正玻璃已经装上了,保险不赔 我也不给钱,我就不厚道了。玻璃大哥咬着牙说再给一天时间。
回到家,一年来第一次上交局网站,喔再靠,三次违章!两次都是因为没有年检被照相 了!!
礼拜五
虽然是第一次到交警队,但并不是那么紧张,我感觉自己这几天已脱胎换骨,不是那样青涩了。一边排队一边笑看交警队里的各色嬉 笑怒骂。我很从容。到我了。交警大叔的几句如冰魄入我骨缝。
叔:一次闯红灯,三次未车检被照相,800块钱12分。
我:不是两次没车检 吗?昨天刚查的。
叔:昨天下午在西直门桥还有一次。
我:(靠~昨天下午我这不是去搞副本办年检了吗?我还是成熟了,这句话没真说出口。)
我: 那这三次算一次吧,反正都是一个原因。
叔:按法规每个月都应该记一次,你这都半年了!
我:(灭火)
叔:12分,该进学习班了。
我: (彻底灭火)
叔:(毕竟老成,情绪已经缓和)你是进学习班啊还是今天别办了?
我:我不进学习班
叔:那别办了
我:那我得办
叔: 进学习班?
我:不进
叔:那别办了
我:那我得办。早晚不得办吗?
叔:那你就进学习班!!!(叔激了)
玻璃大哥还在 等我…
俱乐部大姐也在等我…
我儿子也在等我回家举高高,可是爸爸就要进学习班了…我的心都凉了…不对!顿然觉醒重返人 世,学习班不是拘留所!
后面一个小老弟赶快跟我说,他的意思是您赶快找一个人帮你消几分,你看我这不是找了好几个哥们儿一起来的么。
总算 人品没有沦丧,有兄弟打车来解围,看到他我感动得湿了。今天看来还能搞定,玻璃不用自费了。Mission possible!
警察大叔再帮我 办,给我看摄像头照片,喔靠(这是叔说的),这张,你被套牌了!还是个奥迪嘢!你赶快给朝阳的交警队打电话,三天就能消去这个违章啦!热情的大叔和仗义的 哥们都很兴奋,恨不得抱在一起庆祝一下。
我哭了。那个套牌车算我的还不行吗?要不然玻璃就要自费了。本来想从“礼拜一我家车玻璃碎了”开始说,但是叔和哥们还处在兴奋的余热中,我放弃了…
一路回来,哥们还在不停地叨叨叨地问我咋的了,亲身遭遇套牌让他很兴奋。半小时前我盼他从天而降, 半小时后我盼他瞬间消失。
自动开车以来,什么事情都没经历过,新手的不干胶都懒得揭下去,不晓得其他人开车那么多烦恼从何而来。这一次, 出险、理赔、年检、重办保险单、违章、接受处罚、被套牌,大全套的初体验了一圈。一个字,悲剧啊。

Filed by
charlie
at 11:17 pm under Life, 不以物喜
2 Comments
这些模板太体贴到位了,太符合国情、民情了,尽情展现山寨精神的精髓。看图

Filed by
charlie
at 11:27 am under Life
6 Comments
JSDraw是Tony Yuan开发的基于javascript的在线化学结构编辑器,也能作为化学结构式的显示工具。效果很棒。
我之前所了解的类似的软件是Chemhack jsMolEditor and Chemdoodle。
JSDraw的特点是
Tony现在在Novartis工作。提到这个公司,自然会想到一个人,就是Peter Ertl,大名鼎鼎的JME就是他多年前开发出来并广泛使用起来的。可见这个公司文化的开放和对行业多角度的贡献。
不过JSDraw并不是开源的,对商业应用也不免费。这一点Duan Lian的jsMolEditor就开放得多(LGPL)。
JSDraw目前还没有SMILES导出的功能,但是这在Tony的计划之中。如果我写的Javascript SMILES writer能够起到一些帮助,将是我很大的荣幸。
Filed by
charlie
at 11:23 pm under chemoinformatics
1 Comment
Indigo is recently introduced as open-source chemoinformatics toolkit <1>, <2>.
Dingo is a molecule and reaction rendering library included in Indigo and with .NET C# wrapper to make it possible for me to build a WPF app with it. Dingo and WPF make things so simple.
Amazing feeling to stand on the giant’s shoulder. Not too much code pasted here
public class Compound
{
public String smi{ get; set;}
public Compound(String smiles)
{
smi = smiles;
}
public BitmapSource bmp {
get{
return Smi2Bitmap(smi, 160, 160);
}
}
public static BitmapSource loadBitmap(System.Drawing.Bitmap source)
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
public static BitmapSource Smi2Bitmap(String smi, int Width, int Height)
{
Dingo dg = new Dingo();
dg.loadMolecule(smi);
dg.setBackgroundColor(System.Drawing.Color.White);
System.Drawing.Bitmap bmp = dg.renderToBitmap(Width, Height);
return loadBitmap(bmp);
}
}
public class SMIReader: System.Collections.IEnumerable
{
private StreamReader sr;
public SMIReader(String path)
{
sr = new StreamReader(path);
}
public IEnumerator GetEnumerator()
{
String line;
while ((line = sr.ReadLine()) != null)
{
yield return new Compound(line.Split('\t')[0].Split(' ')[0]);
}
}
}
Notes: To show as many structure pictures blocks on screen the WrapPanel is used as ItemsPanel. This depresses performance for large file that all SMILES are read in but lazy loaded in the default StackPanel mode.
<ListBox Name="list1" Height="539" Width="790"
ItemTemplate="{StaticResource MolListboxTemplate}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
IsSynchronizedWithCurrentItem ="True">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
<Window.Resources>
<DataTemplate x:Key="MolListboxTemplate">
<WrapPanel Margin="3">
<StackPanel>
<Image Source="{Binding bmp}" Height="160" Width="160"></Image>
<TextBox Text="{Binding smi}" Width="160"></TextBox>
</StackPanel>
</WrapPanel>
</DataTemplate>
</Window.Resources>
private void button1_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
ofd.Filter = "SMILES file(*.smi)|*.smi";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
String path = ofd.FileName;
textBlock1.Text = path;
list1.ItemsSource = new nchem.SMIReader(path);
}
}
Done.
Filed by
charlie
at 11:40 pm under Coding, chemoinformatics
1 Comment
Rich在用ChemWriter的License作奖品请大家写一些结构输入软件的重要功能特性,进行竞赛。我不如就写点中文的吧。仅限于在线编辑的软件 ( online editor only )。
没有谁的研究工作是在某个在线编辑器上进行的,更多的是文件形式存在的结构文件。比如Chemdraw的CDX文件。而重画一遍结构式,绝对是痛苦的事情。没有哪个研发助理和采购助理乐意干这件事。所以需要导入功能。导入功能在另一个侧面可以弥补功能上的不足,因为结构都已经在其他商业软件上做好了。
在线的结构文件导入,基于ActiveX的Chemdraw功能最全;硕大的JChemPaint可以支持InChI/SMILE等输入;Chemwriter可以导入mol文件;如果网页开发人员不多写一些代码,JME只能干画。
既然是在线使用,size就重要。比如JChemPaint有 382kB;Chemwriter 111kB;JME 40kB。
这一点Chemwriter可居榜首。鼠标在原子、键悬停时有显示;反复点击某个键更改键类型;直接在键盘上输入元素名称等等实用功能都做到了。
而且也比较美观。
所以综合来说,我很想用用Chemwriter,所以就写上面这些希望有点运气。
Filed by
charlie
at 10:20 pm under chemoinformatics, 不以物喜
No Comments