亚洲一区二区三区亚瑟,亚洲一区二区三区无码中文字幕,成人伊人亚洲人综合网站222http://www.tkk7.com/rain1102/category/37642.html<br/><font color="green" style="font-family: 華文行楷;font-size:16px;">化學(xué)結(jié)構(gòu)搜索,化學(xué)信息學(xué),生物信息學(xué),實(shí)驗(yàn)室信息學(xué)等 。</font><br/><font color="#3C1435">以高科技的生物、化學(xué)信息技術(shù)實(shí)現(xiàn)生命科學(xué)領(lǐng)域中專業(yè)數(shù)據(jù)的計(jì)算和管理、提高研發(fā)能力、增強(qiáng)在科研和成本效率方面的國際競爭力,為生物、化學(xué)、醫(yī)藥和學(xué)術(shù)機(jī)構(gòu)提供一流的解決方案和技術(shù)咨詢。</font><br/> <br/><font color="green" style="font-family: 華文行楷;font-size:16px;">子曰:危邦不入,亂邦不居。天下有道則見,無道則隱。</font><font color="#3C1435"></font><br/> zh-cnTue, 26 Jul 2011 01:49:12 GMTTue, 26 Jul 2011 01:49:12 GMT60利用JPG圖片生成高質(zhì)量的縮略圖http://www.tkk7.com/rain1102/archive/2011/07/26/355029.html周銳周銳Tue, 26 Jul 2011 01:49:00 GMThttp://www.tkk7.com/rain1102/archive/2011/07/26/355029.htmlhttp://www.tkk7.com/rain1102/comments/355029.htmlhttp://www.tkk7.com/rain1102/archive/2011/07/26/355029.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/355029.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/355029.html如果給出縮略圖的寬度和高度,那么就會(huì)根據(jù)給出的寬度和高度生產(chǎn)縮略圖,如果只給出寬度或者高度值,那么就會(huì)根據(jù)比例生成縮略圖。
package com.founder.common.utils;

import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

//生成等比例高質(zhì)量縮略圖
public class ThumbnailUtil {
 private static int width;
 private static int height;
 private static int scaleWidth;
 static double support = (double) 3.0;
 static double PI = (double) 3.14159265358978;
 static double[] contrib;
 static double[] normContrib;
 static double[] tmpContrib;
 static int startContrib, stopContrib;
 static int nDots;
 static int nHalfDots;

 public static void saveImage(String fromFileStr, String saveToFileStr, int formatWidth, int formatHeight) throws Exception {
  File saveFile = new File(saveToFileStr);
  File fromFile = new File(fromFileStr);
  saveImage(fromFile, saveFile, formatWidth, formatHeight);
 }
 
 public static void saveImage(File fromFile  , File saveFile, int formatWidth, int formatHeight) throws Exception {
  BufferedImage srcImage;
  srcImage = javax.imageio.ImageIO.read(fromFile); // construct image
  int imageWidth = srcImage.getWidth(null);
  int imageHeight = srcImage.getHeight(null);
  int changeToWidth = 0;
  int changeToHeight = 0;
  if (formatWidth > 0 && formatHeight > 0) {
   changeToWidth = formatWidth;
   changeToHeight = formatHeight;
  } else {
   if (imageWidth > 0 && imageHeight > 0) {
    if (imageWidth / imageHeight >= formatWidth / formatHeight) {
     if (imageWidth > formatWidth) {
      changeToWidth = formatWidth;
      changeToHeight = (imageHeight * formatWidth) / imageWidth;
     } else {
      changeToWidth = imageWidth;
      changeToHeight = imageHeight;
     }
    } else {
     if (imageHeight > formatHeight) {
      changeToHeight = formatHeight;
      changeToWidth = (imageWidth * formatHeight) / imageHeight;
     } else {
      changeToWidth = imageWidth;
      changeToHeight = imageHeight;
     }
    }
   }
  }
  
  srcImage = imageZoomOut(srcImage, changeToWidth, changeToHeight);
  ImageIO.write(srcImage, "JPEG", saveFile);
 }

 public static BufferedImage imageZoomOut(BufferedImage srcBufferImage, int w, int h) {
  width = srcBufferImage.getWidth();
  height = srcBufferImage.getHeight();
  scaleWidth = w;

  if (DetermineResultSize(w, h) == 1) {
   return srcBufferImage;
  }
  CalContrib();
  BufferedImage pbOut = HorizontalFiltering(srcBufferImage, w);
  BufferedImage pbFinalOut = VerticalFiltering(pbOut, h);
  return pbFinalOut;
 }

 /**
  * 決定圖像尺寸
  */
 private static int DetermineResultSize(int w, int h) {
  double scaleH, scaleV;
  scaleH = (double) w / (double) width;
  scaleV = (double) h / (double) height;
  // 需要判斷一下scaleH,scaleV,不做放大操作
  if (scaleH >= 1.0 && scaleV >= 1.0) {
   return 1;
  }
  return 0;

 }

 private static double Lanczos(int i, int inWidth, int outWidth, double Support) {
  double x;

  x = (double) i * (double) outWidth / (double) inWidth;

  return Math.sin(x * PI) / (x * PI) * Math.sin(x * PI / Support)
    / (x * PI / Support);

 }

 private static void CalContrib() {
  nHalfDots = (int) ((double) width * support / (double) scaleWidth);
  nDots = nHalfDots * 2 + 1;
  try {
   contrib = new double[nDots];
   normContrib = new double[nDots];
   tmpContrib = new double[nDots];
  } catch (Exception e) {
   System.out.println("init contrib,normContrib,tmpContrib" + e);
  }

  int center = nHalfDots;
  contrib[center] = 1.0;

  double weight = 0.0;
  int i = 0;
  for (i = 1; i <= center; i++) {
   contrib[center + i] = Lanczos(i, width, scaleWidth, support);
   weight += contrib[center + i];
  }

  for (i = center - 1; i >= 0; i--) {
   contrib[i] = contrib[center * 2 - i];
  }

  weight = weight * 2 + 1.0;

  for (i = 0; i <= center; i++) {
   normContrib[i] = contrib[i] / weight;
  }

  for (i = center + 1; i < nDots; i++) {
   normContrib[i] = normContrib[center * 2 - i];
  }
 }

 // 處理邊緣
 private static void CalTempContrib(int start, int stop) {
  double weight = 0;

  int i = 0;
  for (i = start; i <= stop; i++) {
   weight += contrib[i];
  }

  for (i = start; i <= stop; i++) {
   tmpContrib[i] = contrib[i] / weight;
  }

 }

 private static int GetRedValue(int rgbValue) {
  int temp = rgbValue & 0x00ff0000;
  return temp >> 16;
 }

 private static int GetGreenValue(int rgbValue) {
  int temp = rgbValue & 0x0000ff00;
  return temp >> 8;
 }

 private static int GetBlueValue(int rgbValue) {
  return rgbValue & 0x000000ff;
 }

 private static int ComRGB(int redValue, int greenValue, int blueValue) {

  return (redValue << 16) + (greenValue << 8) + blueValue;
 }

 // 行水平濾波
 private static int HorizontalFilter(BufferedImage bufImg, int startX, int stopX,
   int start, int stop, int y, double[] pContrib) {
  double valueRed = 0.0;
  double valueGreen = 0.0;
  double valueBlue = 0.0;
  int valueRGB = 0;
  int i, j;

  for (i = startX, j = start; i <= stopX; i++, j++) {
   valueRGB = bufImg.getRGB(i, y);

   valueRed += GetRedValue(valueRGB) * pContrib[j];
   valueGreen += GetGreenValue(valueRGB) * pContrib[j];
   valueBlue += GetBlueValue(valueRGB) * pContrib[j];
  }

  valueRGB = ComRGB(Clip((int) valueRed), Clip((int) valueGreen),
    Clip((int) valueBlue));
  return valueRGB;

 }

 // 圖片水平濾波
 private static BufferedImage HorizontalFiltering(BufferedImage bufImage, int iOutW) {
  int dwInW = bufImage.getWidth();
  int dwInH = bufImage.getHeight();
  int value = 0;
  BufferedImage pbOut = new BufferedImage(iOutW, dwInH,
    BufferedImage.TYPE_INT_RGB);

  for (int x = 0; x < iOutW; x++) {

   int startX;
   int start;
   int X = (int) (((double) x) * ((double) dwInW) / ((double) iOutW) + 0.5);
   int y = 0;

   startX = X - nHalfDots;
   if (startX < 0) {
    startX = 0;
    start = nHalfDots - X;
   } else {
    start = 0;
   }

   int stop;
   int stopX = X + nHalfDots;
   if (stopX > (dwInW - 1)) {
    stopX = dwInW - 1;
    stop = nHalfDots + (dwInW - 1 - X);
   } else {
    stop = nHalfDots * 2;
   }

   if (start > 0 || stop < nDots - 1) {
    CalTempContrib(start, stop);
    for (y = 0; y < dwInH; y++) {
     value = HorizontalFilter(bufImage, startX, stopX, start,
       stop, y, tmpContrib);
     pbOut.setRGB(x, y, value);
    }
   } else {
    for (y = 0; y < dwInH; y++) {
     value = HorizontalFilter(bufImage, startX, stopX, start,
       stop, y, normContrib);
     pbOut.setRGB(x, y, value);
    }
   }
  }

  return pbOut;

 }

 private static int VerticalFilter(BufferedImage pbInImage, int startY, int stopY,
   int start, int stop, int x, double[] pContrib) {
  double valueRed = 0.0;
  double valueGreen = 0.0;
  double valueBlue = 0.0;
  int valueRGB = 0;
  int i, j;

  for (i = startY, j = start; i <= stopY; i++, j++) {
   valueRGB = pbInImage.getRGB(x, i);

   valueRed += GetRedValue(valueRGB) * pContrib[j];
   valueGreen += GetGreenValue(valueRGB) * pContrib[j];
   valueBlue += GetBlueValue(valueRGB) * pContrib[j];
  }

  valueRGB = ComRGB(Clip((int) valueRed), Clip((int) valueGreen), Clip((int) valueBlue));
  
  return valueRGB;

 }

 private static BufferedImage VerticalFiltering(BufferedImage pbImage, int iOutH) {
  int iW = pbImage.getWidth();
  int iH = pbImage.getHeight();
  int value = 0;
  BufferedImage pbOut = new BufferedImage(iW, iOutH,
    BufferedImage.TYPE_INT_RGB);

  for (int y = 0; y < iOutH; y++) {

   int startY;
   int start;
   int Y = (int) (((double) y) * ((double) iH) / ((double) iOutH) + 0.5);

   startY = Y - nHalfDots;
   if (startY < 0) {
    startY = 0;
    start = nHalfDots - Y;
   } else {
    start = 0;
   }

   int stop;
   int stopY = Y + nHalfDots;
   if (stopY > (int) (iH - 1)) {
    stopY = iH - 1;
    stop = nHalfDots + (iH - 1 - Y);
   } else {
    stop = nHalfDots * 2;
   }

   if (start > 0 || stop < nDots - 1) {
    CalTempContrib(start, stop);
    for (int x = 0; x < iW; x++) {
     value = VerticalFilter(pbImage, startY, stopY, start, stop,
       x, tmpContrib);
     pbOut.setRGB(x, y, value);
    }
   } else {
    for (int x = 0; x < iW; x++) {
     value = VerticalFilter(pbImage, startY, stopY, start, stop,
       x, normContrib);
     pbOut.setRGB(x, y, value);
    }
   }

  }

  return pbOut;

 }

 static int Clip(int x) {
  if (x < 0)
   return 0;
  if (x > 255)
   return 255;
  return x;
 }
}



周銳 2011-07-26 09:49 發(fā)表評論
]]>
在SQLPlus中執(zhí)行用Java編寫的Oracle存儲(chǔ)過程[轉(zhuǎn)載]http://www.tkk7.com/rain1102/archive/2011/06/22/352799.html周銳周銳Wed, 22 Jun 2011 04:38:00 GMThttp://www.tkk7.com/rain1102/archive/2011/06/22/352799.htmlhttp://www.tkk7.com/rain1102/comments/352799.htmlhttp://www.tkk7.com/rain1102/archive/2011/06/22/352799.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/352799.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/352799.html

首先在PL/Sql中分別執(zhí)行:

create or replace and compile java source named TestJava1 as 
public class TestJava1 

  public static void test() 
  { 
   System.out.println("Hello"); 
  } 
}


create or replace procedure testJava1 as language java name 'TestJava1.test()';

---------------------------------------------------------------------------------------------------------

在SQLPlus中

C:\Windows\System32>sqlplus nc5520110105/nc5520110105@192.168.10.87

SQL*Plus: Release 11.2.0.1.0 Production on Fri Apr 1 14:06:02 2011

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> set serveroutput on;
SQL> show serveroutput;
serveroutput ON SIZE UNLIMITED FORMAT WORD_WRAPPED
SQL> call dbms_java.set_output(2000);

Call completed.

SQL>
SQL> show serveroutput;
serveroutput ON SIZE UNLIMITED FORMAT WORD_WRAPPED
SQL> exec testJava1();
Hello

PL/SQL procedure successfully completed.

SQL>

---------------------------------------------------------------------------------------------------------

再看一個(gè)例子:

在PL/Sql中執(zhí)行:

--用Java編寫Oracle存儲(chǔ)過程。
create or replace and compile java source named test as
public class MyTest
{
    public static void myProc(int a,int b,int[] ret){
       ret[0]=a+b;
    }
    public static int myFunc(int a,int b){
       return a+b;
    }
}

--創(chuàng)建存儲(chǔ)過程
create or replace procedure myProc(a in number, b in number, ret out number) as
language java name 'MyTest.myProc(int,int,int[])';
--創(chuàng)建函數(shù)
create or replace function myFunc(a in number, b in number) return number is
language java name 'MyTest.myFunc(int,int) return int';

然后在SqlPlus中測試存儲(chǔ)過程——

SQL> set serveroutput on
SQL> DECLARE a INTEGER;
  2  BEGIN
  3  myProc(1, 2, a);
  4  DBMS_OUTPUT.PUT_LINE(a);
  5  END;
  6  /
3

PL/SQL procedure successfully completed.

 

SQL> select myFunc(1,2) from dual;

MYFUNC(1,2)
-----------
          3

SQL>



周銳 2011-06-22 12:38 發(fā)表評論
]]>
Ubuntu10.04中安裝jdk-6u25http://www.tkk7.com/rain1102/archive/2011/06/08/351911.html周銳周銳Wed, 08 Jun 2011 06:05:00 GMThttp://www.tkk7.com/rain1102/archive/2011/06/08/351911.htmlhttp://www.tkk7.com/rain1102/comments/351911.htmlhttp://www.tkk7.com/rain1102/archive/2011/06/08/351911.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/351911.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/351911.html2. 進(jìn)入/home/your_name/software下,執(zhí)行chmod +x jdk-6u25-linux-i586.bin
3. 繼續(xù)執(zhí)行./jdk-6u25-linux-i586.bin
4. 到/usr/lib下執(zhí)行sudo mkdir jvm,然后進(jìn)入/usr/lib/jvm執(zhí)行sudo mkdir java
5. 到/usr/lib/jvm/java下執(zhí)行mv /home/your_name/software/jdk1.6.0_25/* .
6. 執(zhí)行sudo gedit /etc/environment
7. 在PATH中添加"/usr/lib/jvm/java/bin", 添加CLASSPATH=.:/usr/lib/jvm/java/lib和JAVA_HOME=/usr/lib/jvm/java
8. 執(zhí)行sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java/bin/java 300
9. 執(zhí)行sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java/bin/javac 300
10. 執(zhí)行sudo update-alternatives --config java
最后執(zhí)行java -version

周銳 2011-06-08 14:05 發(fā)表評論
]]>
使用Ehcache對頁面緩存http://www.tkk7.com/rain1102/archive/2011/05/12/350097.html周銳周銳Thu, 12 May 2011 08:11:00 GMThttp://www.tkk7.com/rain1102/archive/2011/05/12/350097.htmlhttp://www.tkk7.com/rain1102/comments/350097.htmlhttp://www.tkk7.com/rain1102/archive/2011/05/12/350097.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/350097.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/350097.htmlThere are no code changes required for this - your application server should support servlet filtering already. Simply update your web.xml file, re-deploy and you should see the speedup right away.

The basic steps you'll need to follow to configure Ehcache for web page caching are (note that these steps assume you already have Ehcache installed in your application):

  1. Configure a servlet page filter in web.xml
  2. Configure an appropriate cache in ehcache.xml
  3. Start (or re-start) your application

The following settings should help you setup web caching for your application.

Step 1 - Add a filter to your web.xml

The first thing you'll need to do is add a filter to enable page caching.

The following web.xml settings will enable a servlet filter for page caching:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
version="2.5">
<filter>
<filter-name>SimplePageCachingFilter</filter-name>
<filter-class>net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter
</filter-class>
</filter>
<!-- This is a filter chain. They are executed in the order below.
Do not change the order. -->
<filter-mapping>
<filter-name>SimplePageCachingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

Step 2 - Configure an ehcache.xml

The second step to enabling web page caching is to configure ehcache with an appropriate ehcache.xml.

The following ehcache.xml file should configure a reasonable default ehcache:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../main/config/ehcache.xsd">
<cache name="SimplePageCachingFilter"
maxElementsInMemory="10000"
maxElementsOnDisk="1000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
/>
</ehcache>

Step 3 - Start your application server

Now start your application server. Pages should be cached.



周銳 2011-05-12 16:11 發(fā)表評論
]]>
chemtoolkits上線啦http://www.tkk7.com/rain1102/archive/2011/05/07/349748.html周銳周銳Sat, 07 May 2011 11:02:00 GMThttp://www.tkk7.com/rain1102/archive/2011/05/07/349748.htmlhttp://www.tkk7.com/rain1102/comments/349748.htmlhttp://www.tkk7.com/rain1102/archive/2011/05/07/349748.html#Feedback1http://www.tkk7.com/rain1102/comments/commentRss/349748.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/349748.html http://www.chemtoolkits.com

周銳 2011-05-07 19:02 發(fā)表評論
]]>
當(dāng)@PathVariable遇上中文和點(diǎn)http://www.tkk7.com/rain1102/archive/2011/05/05/349643.html周銳周銳Thu, 05 May 2011 15:03:00 GMThttp://www.tkk7.com/rain1102/archive/2011/05/05/349643.htmlhttp://www.tkk7.com/rain1102/comments/349643.htmlhttp://www.tkk7.com/rain1102/archive/2011/05/05/349643.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/349643.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/349643.htmlSpring MVC從3.0開始支持REST,而主要就是通過@PathVariable來處理請求參數(shù)和路徑的映射。
由于考慮到SEO的緣故,很多人喜歡把新聞的名稱作為路徑中的一部分去處理,這時(shí)候中文的名稱就會(huì)遇到問題,沒辦法映射,這個(gè)是因?yàn)榫幋a問題,只要到TOMCAT/conf下找到server.xml,添加URIEncoding="UTF-8"進(jìn)行URL編碼設(shè)置就可以解決中文問題。
另外經(jīng)常遇到路徑中有點(diǎn)".",而點(diǎn)是特殊字符,比如.html, .do等等,所以Spring MVC默認(rèn)是把點(diǎn)后面的信息當(dāng)作文件后綴,這時(shí)候我們就要修改這個(gè)默認(rèn)值。

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
  <property name="interceptors" ref="localeChangeInterceptor"/>
  <property name="useDefaultSuffixPattern" value="false" /> 
 </bean>

另外,這時(shí)候如果只設(shè)置這個(gè),請求可以傳遞到對于的controller,但傳過去的數(shù)據(jù)會(huì)有問題,只會(huì)傳最后一個(gè)點(diǎn)前面的數(shù)據(jù),除非你在最后加上“/”,比如/news/測試.點(diǎn)/  這樣就會(huì)把“測試.點(diǎn)”當(dāng)作整體,不然只會(huì)得到“測試”。這時(shí)候我們可以這樣設(shè)置@RequestMapping("/news/{title:.*}")
這樣就一切ok啦。


周銳 2011-05-05 23:03 發(fā)表評論
]]>
OSRA讓圖片上的結(jié)構(gòu)式活起來http://www.tkk7.com/rain1102/archive/2011/04/22/348820.html周銳周銳Fri, 22 Apr 2011 09:49:00 GMThttp://www.tkk7.com/rain1102/archive/2011/04/22/348820.htmlhttp://www.tkk7.com/rain1102/comments/348820.htmlhttp://www.tkk7.com/rain1102/archive/2011/04/22/348820.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/348820.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/348820.htmlOSRA: Optical Structure Recognition Application 地址:http://cactus.nci.nih.gov/osra/
OSRA是一個(gè)很實(shí)用的工具,可以把圖片上的結(jié)構(gòu)轉(zhuǎn)換為InChI,InChI-key,SMILES,SDF數(shù)據(jù)。目前一些商業(yè)的編輯化學(xué)結(jié)構(gòu)式軟件已經(jīng)把該功能引入到了各家的產(chǎn)品中了,ChemAxon的Marvin Sketch就是其中一個(gè),用戶可以直接拷貝圖片或者通過打開文件方式把圖片上的結(jié)構(gòu)式展現(xiàn)在編輯工具中。

另外NCI提供了一個(gè)demo,地址http://cactus.nci.nih.gov/cgi-bin/osra/index.cgi
可以直接上傳圖片,然后會(huì)把圖片中包含的化學(xué)結(jié)構(gòu)式返回給你。非常強(qiáng)大!

另外一個(gè)好消息,從1.3.8開始,java可以通過JNI去調(diào)用OSRA程序了,這樣我們可以通過這個(gè)做很多有意思的事情,比如點(diǎn)擊一個(gè)圖片,直接去結(jié)構(gòu)式搜索或者計(jì)算相關(guān)理化性質(zhì)等等!

周銳 2011-04-22 17:49 發(fā)表評論
]]>
通過使用Opsin進(jìn)行IUPAC名稱到結(jié)構(gòu)轉(zhuǎn)換http://www.tkk7.com/rain1102/archive/2011/04/19/348596.html周銳周銳Tue, 19 Apr 2011 13:52:00 GMThttp://www.tkk7.com/rain1102/archive/2011/04/19/348596.htmlhttp://www.tkk7.com/rain1102/comments/348596.htmlhttp://www.tkk7.com/rain1102/archive/2011/04/19/348596.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/348596.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/348596.html 下載地址: http://bitbucket.org/dan2097/opsin/
下面我們直接看代碼吧,很簡單!

package com.founder.opsin;

import nu.xom.Element;
import uk.ac.cam.ch.wwmm.opsin.NameToInchi;
import uk.ac.cam.ch.wwmm.opsin.NameToStructure;
import uk.ac.cam.ch.wwmm.opsin.NameToStructureConfig;
import uk.ac.cam.ch.wwmm.opsin.NameToStructureException;
import uk.ac.cam.ch.wwmm.opsin.OpsinResult;

public class OpsinTest {

 /**
  * @param args
  * @author Zhou Rui
  * @throws NameToStructureException
  */
 public static void main(String[] args) throws NameToStructureException {
  NameToStructure n2s = NameToStructure.getInstance();
  
  NameToStructureConfig n2sconfig = new NameToStructureConfig();
  
  OpsinResult result = n2s.parseChemicalName("acetonitrile", n2sconfig);
  
  System.out.println(result.getStatus());
  
  String smiles = result.getSmiles();
  String inchi = NameToInchi.convertResultToInChI(result);
  System.out.println(smiles);
  System.out.println(inchi);
 }

}

輸出結(jié)果如下:
SUCCESS
C(C)#N
InChI=1/C2H3N/c1-2-3/h1H3



周銳 2011-04-19 21:52 發(fā)表評論
]]>
通過Rsession在java中啟動(dòng)Rservehttp://www.tkk7.com/rain1102/archive/2011/04/13/348257.html周銳周銳Wed, 13 Apr 2011 14:45:00 GMThttp://www.tkk7.com/rain1102/archive/2011/04/13/348257.htmlhttp://www.tkk7.com/rain1102/comments/348257.htmlhttp://www.tkk7.com/rain1102/archive/2011/04/13/348257.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/348257.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/348257.html閱讀全文

周銳 2011-04-13 22:45 發(fā)表評論
]]>
chemtoolkits中分子描述符計(jì)算(molecular descriptor calculator)完成http://www.tkk7.com/rain1102/archive/2011/04/12/348175.html周銳周銳Tue, 12 Apr 2011 14:54:00 GMThttp://www.tkk7.com/rain1102/archive/2011/04/12/348175.htmlhttp://www.tkk7.com/rain1102/comments/348175.htmlhttp://www.tkk7.com/rain1102/archive/2011/04/12/348175.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/348175.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/348175.html閱讀全文

周銳 2011-04-12 22:54 發(fā)表評論
]]>
chemtoolkits(CTK)部分功能和界面http://www.tkk7.com/rain1102/archive/2011/04/09/347957.html周銳周銳Sat, 09 Apr 2011 09:16:00 GMThttp://www.tkk7.com/rain1102/archive/2011/04/09/347957.htmlhttp://www.tkk7.com/rain1102/comments/347957.htmlhttp://www.tkk7.com/rain1102/archive/2011/04/09/347957.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/347957.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/347957.html閱讀全文

周銳 2011-04-09 17:16 發(fā)表評論
]]>
chemtoolkits.com國內(nèi)免費(fèi)化學(xué)信息學(xué)服務(wù)平臺(tái)http://www.tkk7.com/rain1102/archive/2011/04/06/347676.html周銳周銳Wed, 06 Apr 2011 02:06:00 GMThttp://www.tkk7.com/rain1102/archive/2011/04/06/347676.htmlhttp://www.tkk7.com/rain1102/comments/347676.htmlhttp://www.tkk7.com/rain1102/archive/2011/04/06/347676.html#Feedback2http://www.tkk7.com/rain1102/comments/commentRss/347676.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/347676.html閱讀全文

周銳 2011-04-06 10:06 發(fā)表評論
]]>
Chemical Informatic tools developmenthttp://www.tkk7.com/rain1102/archive/2011/04/02/347502.html周銳周銳Sat, 02 Apr 2011 01:20:00 GMThttp://www.tkk7.com/rain1102/archive/2011/04/02/347502.htmlhttp://www.tkk7.com/rain1102/comments/347502.htmlhttp://www.tkk7.com/rain1102/archive/2011/04/02/347502.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/347502.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/347502.html1. Property calculations (LogP/LogD, PSA, solubility, pKa, Lipinski rule)

    計(jì)算插件(脂水分配系數(shù)/考慮電解時(shí)的脂水分配系數(shù)、極性表面積、溶解性、電解常數(shù)、Lipinski五規(guī)則)

        All are supported except solubility, in JChemBase, Cartridge, Knime, Pipeline pilot, Instant JChem, Jchem for Excel and in Marvin. See full list of our property predictors.Calculating Lipinski rule of 5:

2. Bulid and maintain project data viewer (SAR understanding)
SAR: structure-activity relationship, 結(jié)果與活性關(guān)系,簡稱構(gòu)效關(guān)系

       We have R-group decomposition, also a viewer in JChem for Excel, LibMCS GUI. That can be used for SAR understanding.

3. Library enumeration, cleanup, profile and analysis

        Reactor, Screen, Calculator plugins, Markush Enumeration, Instant JChem, JChem for Excel, KNIME, Pipeline pilot
        Some presentations on the topic:
        Virtual Libraries and Virtual Screening in Drug Discovery Processes using KNIME
        Library Compound Design Methods for CustomLibrary Synthesis

4. Customized Spotfire view

        Yes this is the TIBCO Spotfire tool. Marvin is integrated into Spotfire, I think even JChem Cartridge can communicate with Spotfire, our new project is Instant JChem Integration which is under development

5.Similarity search

        Yes, JChemBase, Cartridge, Instant JChem, JChem for Excel Similarity search in databases
        For a more sophisticated approach of similarity, we provide the Screen package.

6.Clustering

       JKlustor, LibMCS

7.Generate SAR Tables
生成構(gòu)效關(guān)系表格

       We do not support directly but we have Rgroup decomposition, Fragmentation toolkit that can be visualized and analysed later.

8.Ligand binding Efficiency
配體結(jié)合效果

       LE can be calculated if the database contains the activity value, heavy atom counts can be calculated in JChem for Excel, Instant Jchem

9.Structure visualization
結(jié)構(gòu)可視化

       Marvin

10.Overlay/Docking
疊合/對接

       No, we do not support docking. Alignment can be done in Marvin, Screen3D, and a standalone GUI for low throughput screening.

11.Build predictive ADMET models
建立預(yù)測ADMET模型。ADMET分別代表吸收、分布、代謝、排泄和毒性。

       We do not support directly, although we have some calculation plugins that can be further used for these property calculations such as pKa, logP/D, Atom counts, PSA.



周銳 2011-04-02 09:20 發(fā)表評論
]]>
Java通過Rserve調(diào)研R函數(shù)http://www.tkk7.com/rain1102/archive/2011/03/30/347261.html周銳周銳Wed, 30 Mar 2011 02:57:00 GMThttp://www.tkk7.com/rain1102/archive/2011/03/30/347261.htmlhttp://www.tkk7.com/rain1102/comments/347261.htmlhttp://www.tkk7.com/rain1102/archive/2011/03/30/347261.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/347261.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/347261.html 而Java語言是目前最流行的語言,當(dāng)然對我自己來說也是最熟悉的語言了。所以今天嘗試通過java來調(diào)用R函數(shù)為下面通過調(diào)用數(shù)學(xué)函數(shù)實(shí)現(xiàn)業(yè)務(wù)功能做基礎(chǔ)。
目前我在windows xp上做測試。
1. 首先需要下載R的windows安裝程序,地址為http://cran.r-project.org/,選擇base進(jìn)行下載。然后安裝就可以了。
2. 安裝Rserve,可以通過R界面中的命令行輸入:install.packages("Rserve")或者在R界面上選擇:程序包->安裝程序包,然后找到Rserve進(jìn)行安裝。
3. 啟動(dòng)Rserve, 在R界面中的命令行中輸入:library(Rserve)來加載Rserve,然后輸入Rserve()進(jìn)行啟動(dòng)服務(wù)。
到此Rserve已經(jīng)配置并啟動(dòng)好,下面輪到Java程序調(diào)用了。
1. 下載Rserve提供的jar包,打開http://www.rforge.net/Rserve/files/,下載REngine.jarRserveEngine.jar,然后放到自己的項(xiàng)目中,并引入。
2. 編輯代碼如下:

 

import org.rosuda.REngine.REXP;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;

public class RTest {

 /**
  * @param args
  * @author Zhou Rui
  * @throws RserveException
  * @throws REXPMismatchException
  */
 public static void main(String[] args) throws RserveException, REXPMismatchException {
  RConnection c = new RConnection();
  REXP x = c.eval("R.version.string");
  System.out.println(x.asString());
 }

}


運(yùn)行,輸入結(jié)果:
R version 2.12.2 (2011-02-25)

周銳 2011-03-30 10:57 發(fā)表評論
]]>
Java導(dǎo)出csv文件處理逗號(hào)http://www.tkk7.com/rain1102/archive/2011/03/29/347241.html周銳周銳Tue, 29 Mar 2011 14:27:00 GMThttp://www.tkk7.com/rain1102/archive/2011/03/29/347241.htmlhttp://www.tkk7.com/rain1102/comments/347241.htmlhttp://www.tkk7.com/rain1102/archive/2011/03/29/347241.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/347241.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/347241.html sb.append("\""+document.getTitle() + "\"," + document.getNumber() + "," + document.getVersion() + "," + document.getApprovedDateString() + "," + document.getAuthor().getRealName() + "\n");


周銳 2011-03-29 22:27 發(fā)表評論
]]>
Generating PDFs for Fun and Profit with Flying Saucer and iTexthttp://www.tkk7.com/rain1102/archive/2010/04/18/318651.html周銳周銳Sun, 18 Apr 2010 03:29:00 GMThttp://www.tkk7.com/rain1102/archive/2010/04/18/318651.htmlhttp://www.tkk7.com/rain1102/comments/318651.htmlhttp://www.tkk7.com/rain1102/archive/2010/04/18/318651.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/318651.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/318651.htmlhttp://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html

周銳 2010-04-18 11:29 發(fā)表評論
]]>
Enable the jre plugin in chrome and firefox in ubuntu 9.04http://www.tkk7.com/rain1102/archive/2010/04/15/318392.html周銳周銳Thu, 15 Apr 2010 03:06:00 GMThttp://www.tkk7.com/rain1102/archive/2010/04/15/318392.htmlhttp://www.tkk7.com/rain1102/comments/318392.htmlhttp://www.tkk7.com/rain1102/archive/2010/04/15/318392.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/318392.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/318392.htmlGuys, (Ubuntu 9.04)

Before all this make sure that you have Java correctly installed. First I tried to installed java under my home directory, failed. I mean I though I have installed it, but it actually did not. (used exact same steps from www.java.com). Then I tried to install it under /usr/ directory, failed. Finally I tried to install it under /opt/, succeed. 

Then i followed the same routine "symbolic link" stuff for both of my web browsers (Firefox, Chrome), succeed. :)

for Chrome:
  >  mkdir /opt/google/chrome/plugins
  >  cd /opt/google/chrome/plugins
  >  ln -s /opt/java/jre1.6.0_17/lib/i386/libnpjp2.so 

for Firefox:

>cd <Firefox installation directory>/plugins
>ln -s /opt/java/jre1.6.0_17/lib/i386/libnpjp2.so 

restart them!

hope it works


周銳 2010-04-15 11:06 發(fā)表評論
]]>
Jbpm4.2+tomcat6+oracle9i安裝過程[轉(zhuǎn)載]http://www.tkk7.com/rain1102/archive/2009/12/03/304687.html周銳周銳Thu, 03 Dec 2009 11:48:00 GMThttp://www.tkk7.com/rain1102/archive/2009/12/03/304687.htmlhttp://www.tkk7.com/rain1102/comments/304687.htmlhttp://www.tkk7.com/rain1102/archive/2009/12/03/304687.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/304687.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/304687.html 1.軟件清單
   jdk1.6
   jbpm4.2
   tomcat6
   oracle9i
   ant1.7
   eclipse-jee-galileo-win32

2.配置JDK1.6
   在系統(tǒng)路徑上添加
   JAVA_HOME=c:\java\jdk16(我的JDK1.6安裝目錄)
   CLASS_PATH=.;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\jre\lib\rt.jar;

3.配置ANT
   在系統(tǒng)路徑上添加
   ANT_HOME=c:\java\ant
   path=%ANT_HOME%\bin

4.配置數(shù)據(jù)庫(使用Oracle,默認(rèn)使用的是hsqldb)
   (1)將class12.jar復(fù)制到j(luò)bpm-4.2\lib目錄下,否則找不到驅(qū)動(dòng)
   (2)進(jìn)入c:\jbpm-4.2\install\jdbc目錄修改文件oracle.properties文件,設(shè)置你自己的oracle數(shù)據(jù)庫名、用戶名和密碼
      注意jbpm-4.2的根目錄名稱不能更改,否則無法運(yùn)行ANT
   (3)修改c:\jbpm-4.2\install\build.xml,修改為<property name="database" value="oracle" /> <!-- {hsqldb | mysql | oracle | postgresql} -->
   (4)進(jìn)入c:\jbpm-4.2\install, 運(yùn)行 ant create.jbpm.schema,將創(chuàng)建數(shù)據(jù)庫腳本并在指定數(shù)據(jù)庫中創(chuàng)建表
  
4.配置Tomcat
   (1)復(fù)制apache-tomcat-6.0.20.zip文件到c:\jbpm-4.2\install\downloads目錄中
   (2)進(jìn)入c:\jbpm-4.2\install,運(yùn)行ant  install.tomcat.
      完成后,在c:\jbpm-4.2目錄下生成一個(gè)tomcat目錄

5.配置eclipse
   (1)復(fù)制eclipse-jee-galileo-win32.zip文件到c:\jbpm-4.2\install\downloads目錄中。
      注意:eclipse的名稱必須是eclipse-jee-galileo-win32
   (2)進(jìn)入c:\jbpm-4.2\install,運(yùn)行ant  install.eclipse,運(yùn)行時(shí)間較長
      完成后,在c:\jbpm-4.2目錄下生成一個(gè)eclipse目錄
   注意:如果沒有不用ant配置eclipse,安裝下面的GPD時(shí),提示出錯(cuò),點(diǎn)擊確定后,GPD依然可以使用,不知道為什么。

6.配置流程設(shè)計(jì)器GPD
    啟動(dòng)eclipse,在Eclipse里添加更新站點(diǎn)的方法:
       幫助 --> 安裝新軟件...
       點(diǎn)擊 添加...
       在 添加站點(diǎn) 對話框中,單擊 壓縮包...
       找到 install/src/gpd/jbpm-gpd-site.zip 并點(diǎn)擊 '打開'
       點(diǎn)擊 確定 在 添加站點(diǎn) 對話框中,會(huì)返回到 '安裝'對話框
       選擇出現(xiàn)的 jPDL 4 GPD 更新站點(diǎn),全部選中
       點(diǎn)擊 下一步.. 然后點(diǎn)擊 完成
       接受協(xié)議
       當(dāng)它詢問的時(shí)候重啟eclipse
  

7.配置elcipse工程
   配置jBPM:
      點(diǎn)擊 Window --> Preferences
      選擇 JBoss jBPM --> jBPM-4.2 --> Runtime Locations
      點(diǎn)擊 Add...
      在 Add Location 對話框中,輸入一個(gè)名字,比如  jBPM-4.2 然后點(diǎn)擊 Search...
      在 Browse For Folder 對話框中,選擇你的jbpm-4.2根目錄,然后點(diǎn)擊 OK
      點(diǎn)擊 OK 在 Add Location 對話框中

8.定義一個(gè)用戶庫
  用戶庫用來放置jBPM的庫文件。 如果你創(chuàng)建一個(gè)新工程, 只需要將用戶庫全部添加到build path
     點(diǎn)擊窗口 --> 屬性(Windows --> Preferences)
     選擇Java --> 創(chuàng)建路徑 --> 用戶類庫(Java --> Build Path --> User Libraries)
     點(diǎn)擊新建(New)
        類型名字jBPM Libraries
     點(diǎn)擊添加JARs(Add JARs...)
     找到j(luò)BPM安裝程序下的lib目錄
     選擇lib下的所有jar文件并點(diǎn)擊打開(Open)
     選擇jBPM Libraries作為入口
     重新點(diǎn)擊添加JARs(Add JARs)
     在jBPM的安裝程序的根目錄下選擇jbpm.jar文件
     點(diǎn)擊打開(Open)
         在jbpm.jar下選擇源碼附件(Source attachment)作為入口
     點(diǎn)擊編輯(Edit)
          在源碼附件的配置(Source Attachment Configuration)對話框中,點(diǎn)擊目錄(External Folder...)
     找到j(luò)BPM安裝程序下的src目錄
     點(diǎn)擊選擇(Choose)
     點(diǎn)擊兩次'確定'(Ok)會(huì)關(guān)閉所有對話框

9.創(chuàng)建一個(gè)jbpm demo
創(chuàng)建一個(gè)例子,并將工作流程定義保存到數(shù)據(jù)庫中
(1)創(chuàng)建一個(gè)java Project,起名“ myjbpm ”,然后就可以單擊“完成”了
(2)將c:\jbpm-4.2\examples\src中的所有配置文件復(fù)制到myjbpm工程中的根目錄下
         jbpm.cfg.xml
         jbpm.hibernate.cfg.xml
         jbpm.mail.properties
         jbpm.mail.templates.examples.xml
         logging.properties

(3)修改jbpm.hibernate.cfg.xml
      hibernate.cfg.xml 的默認(rèn)設(shè)置是用 HSQL ,這是一個(gè)內(nèi)存數(shù)據(jù)庫,這種內(nèi)存數(shù)據(jù)庫用來代替項(xiàng)目實(shí)際所用的數(shù)據(jù)庫來做單元測試挺不錯(cuò)的。不過我們這里是要試試用 MySQL 、 Oracle
MySQL 的更改如下:
   <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
   <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
   <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpm</property>
   <property name="hibernate.connection.username">root</property>
   <property name="hibernate.connection.password">123456</property>

Oracle 的更改如下:
   <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
   <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
   <property name="hibernate.connection.url">jdbc:oracle:thin:@192.168.123.10:1521:wxxrDB</property>
   <property name="hibernate.connection.username">xiong</property>
   <property name="hibernate.connection.password">xiong</property>

(4)定義流程
   創(chuàng)建流程的定義文件是 pd.jpdl.xml,將下面代碼復(fù)制到文件中
------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>

<process name="pd" xmlns="http://jbpm.org/4.0/jpdl">
   <start name="start1" g="207,62,48,48">
      <transition name="to state1" to="state1" g="-59,-17"/>
   </start>
   <end name="end1" g="208,293,48,48"/>
   <state name="state1" g="185,155,92,52">
      <transition name="to end1" to="end1" g="-47,-17"/>
   </state>
</process>
------------------------------------------------------------------------------------------

(5)布置jbpm

import junit.framework.TestCase;
import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.HistoryService;
import org.jbpm.api.ManagementService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;

public class ServicesTest extends TestCase {
   public void testObtainServicesAndDeployProcess() {
     Configuration configuration = new Configuration();
     ProcessEngine processEngine = configuration.buildProcessEngine();
 
     RepositoryService repositoryService = processEngine.getRepositoryService();
     ExecutionService executionService = processEngine.getExecutionService();
     TaskService taskService = processEngine.getTaskService();
     HistoryService historyService = processEngine.getHistoryService();
     ManagementService managementService = processEngine.getManagementService();
  
     // 開始部署一個(gè)新的流程文件
     String deploymentId = repositoryService.createDeployment().addResourceFromClasspath("pd.jpdl.xml").deploy();

   }
}

   無論是 MySQL 還是 Oracle ,
   jbpm4_deployment表,你會(huì)發(fā)現(xiàn)多了一條記錄
   jbpm4_deployprop表會(huì)多了三條記錄,對應(yīng)id,key,version
   jbpm4_lob 表會(huì)多了一條記錄,保存流程圖


參考文獻(xiàn):
1.bestyanghui. JBPM4.1配置實(shí)用過程. http://blog.csdn.net/bestyanghui/archive/2009/10/12/4656914.aspx
2.熊熊之家. jbpm4開發(fā)步驟. http://hi.baidu.com/freshman0502/blog/item/092bab19ea68a873dab4bd91.html


周銳 2009-12-03 19:48 發(fā)表評論
]]>
安裝tomcat問題http://www.tkk7.com/rain1102/archive/2009/11/20/303075.html周銳周銳Fri, 20 Nov 2009 09:06:00 GMThttp://www.tkk7.com/rain1102/archive/2009/11/20/303075.htmlhttp://www.tkk7.com/rain1102/comments/303075.htmlhttp://www.tkk7.com/rain1102/archive/2009/11/20/303075.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/303075.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/303075.htmlfailed to install tomcat6 service check your settings and permissions 經(jīng)過查看得知客戶的機(jī)器上原先裝了一個(gè),然后直接刪掉了tomcat安裝目錄而不是卸載的,所以服務(wù)里面還有tomcat的服務(wù)。所以需要?jiǎng)h掉該服務(wù)才可以安裝。

找到一個(gè)解壓版本的tomcat放到任意目錄,然后聽過命令行進(jìn)入到該目錄下的bin目錄里面,里面應(yīng)該有個(gè)service.bat文件,執(zhí)行service remove tomcat6,這樣就刪除服務(wù)了。下面就可以安裝!

周銳 2009-11-20 17:06 發(fā)表評論
]]>
JavaMail問題之Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStreamhttp://www.tkk7.com/rain1102/archive/2009/11/17/302654.html周銳周銳Tue, 17 Nov 2009 03:05:00 GMThttp://www.tkk7.com/rain1102/archive/2009/11/17/302654.htmlhttp://www.tkk7.com/rain1102/comments/302654.htmlhttp://www.tkk7.com/rain1102/archive/2009/11/17/302654.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/302654.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/302654.htmlException in thread "main" Java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream

解決方案:

   JavaEE版本和JavaMail的版本不一致,請將sun公司上下載最新版本.http://java.sun.com/products/javamail/downloads/index.html
   例如:javaMail 1.3以下的如果在javaEE5上就會(huì)出現(xiàn)上面的錯(cuò)誤,
   如果還出現(xiàn)此問題,則是因?yàn)閖avaEE5中包含有javaMail的類但是卻不全面,所以出本身的JavaMail
   包沖突.用rar打開X:/Program Files/MyEclipse 6.0/myeclipse/eclipse/plugins/com.genuitec.eclipse.j2eedt.core_x.x.x.zmyeclipsexxxxxxxxx/data/libraryset/EE_5/javaee.jar
,然后刪除mail,一切就ok了.



周銳 2009-11-17 11:05 發(fā)表評論
]]>
Hibernate中主鍵增長步長為50的問題 Oraclehttp://www.tkk7.com/rain1102/archive/2009/11/11/302019.html周銳周銳Wed, 11 Nov 2009 13:54:00 GMThttp://www.tkk7.com/rain1102/archive/2009/11/11/302019.htmlhttp://www.tkk7.com/rain1102/comments/302019.htmlhttp://www.tkk7.com/rain1102/archive/2009/11/11/302019.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/302019.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/302019.html原文地址:http://jhyimu2005.javaeye.com/blog/514379
先聲明一下我用的框架是Spring + Hibernate + SpringMVC 數(shù)據(jù)庫使用的是Oracle
昨天遇到了一個(gè)特詭異的問題就是我使用Oracle序列,把主鍵的計(jì)數(shù)交給Hibernate處理, Entity @Table(name = "BIO_STUDY") public class Study implements Serializable{ private static final long serialVersionUID = -5932941248053882057L; private int id; private Project project; private String name; private String description; private Set<Experiment> experiments; @Id @Column(name = "ID") @SequenceGenerator(name = "BIO_STUDY_SQ", sequenceName = "BIO_STUDY_SQ" ) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BIO_STUDY_SQ") public int getId() { return id; }


寫完部署什么都沒問題,可當(dāng)我寫了測試類進(jìn)行測試時(shí)發(fā)現(xiàn)主鍵的初始值竟然是50,其步長亦是50,在同事的幫助下發(fā)現(xiàn)原來是Hibernate在做鬼,@SequenceGenerator中添加兩個(gè)參數(shù)(allocationSize = 1, initialValue = 1)就OK。通過查找Hibernate的資料發(fā)現(xiàn)原來是因?yàn)閍llocationSize的默認(rèn)值是50.具體請參考http://www.oracle.com/technology/global/cn/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SequenceGenerator

只需要增加allocationSize = 1就可以



周銳 2009-11-11 21:54 發(fā)表評論
]]>
oracle調(diào)用javahttp://www.tkk7.com/rain1102/archive/2009/10/29/300146.html周銳周銳Thu, 29 Oct 2009 03:20:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/29/300146.htmlhttp://www.tkk7.com/rain1102/comments/300146.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/29/300146.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/300146.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/300146.html前提是數(shù)據(jù)庫上需要安裝java虛擬機(jī)(JVM),使用下面的語句查看

select * from dba_registry where comp_id = 'JAVAVM'

為空,則未安裝,請執(zhí)行 $ORACLE_HOME/javavm/install/initjvm.sql安裝.
創(chuàng)建函數(shù)

create or replace function fn_oraclecall(mArea in VARCHAR2,mDevID in Number,mPORT in Number)
return varchar2
as
language Java name 'Caller.call(java.lang.String,Integer,Integer) return Java.lang.String';

創(chuàng)建存儲(chǔ)過程

create or replace procedure CHK_SETCAB_NUM
(mArea in VARCHAR2,mDevID in Number,mPORT in Number,v_out out varchar2) is
begin
v_out := fn_oraclecall(mArea,mDevID,mPORT);
end CHK_SETCAB_NUM;

loadjava

loadjava -u sys/sys@sid  -oci8 -verbose -grant user -synonym -resolve -schema user D:\Caller.jar

--這里也可以是class文件,注意兼容oracle的jre版本


注意編寫的java文件里,即Caller.java的call()方法,需要是staic



周銳 2009-10-29 11:20 發(fā)表評論
]]>
CDK中根據(jù)smiles計(jì)算Fingerprinter值http://www.tkk7.com/rain1102/archive/2009/10/26/299848.html周銳周銳Mon, 26 Oct 2009 14:24:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/26/299848.htmlhttp://www.tkk7.com/rain1102/comments/299848.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/26/299848.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/299848.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/299848.htmlpackage com.founder.cdk;

import Java.util.BitSet;

import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.exception.InvalidSmilesException;
import org.openscience.cdk.fingerprint.ExtendedFingerprinter;
import org.openscience.cdk.smiles.SmilesParser;

public class FingerprinterTest {

 /**
  * @param args
  * @throws CDKException
  * @throws InvalidSmilesException
  */
 public static void main(String[] args) throws InvalidSmilesException, CDKException {
  ExtendedFingerprinter fingerprinter = new ExtendedFingerprinter();
  SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
  BitSet bt = fingerprinter.getFingerprint(sp.parseSmiles("c2ccc1ccccc1c2"));
 }

}



周銳 2009-10-26 22:24 發(fā)表評論
]]>
在Python中使用openbabelhttp://www.tkk7.com/rain1102/archive/2009/10/25/299655.html周銳周銳Sun, 25 Oct 2009 04:37:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/25/299655.htmlhttp://www.tkk7.com/rain1102/comments/299655.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/25/299655.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/299655.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/299655.html如果你的環(huán)境還沒準(zhǔn)備好, 可以官方網(wǎng)站看如何配置環(huán)境:http://openbabel.org/wiki/Install_Python_bindings
1. 通過使用OBMol, OBAtom和OBBond來創(chuàng)建原子和鍵
import openbabel

mol = openbabel.OBMol()
print 'Should print 0 (atoms)'
print mol.NumAtoms()

a = mol.NewAtom()
a.SetAtomicNum(6)   # carbon atom
a.SetVector(0.0, 1.0, 2.0) # coordinates

b = mol.NewAtom()
mol.AddBond(1, 2, 1)   # atoms indexed from 1
print 'Should print 2 (atoms)'
print mol.NumAtoms()
print 'Should print 1 (bond)'
print mol.NumBonds()

mol.Clear();

2. 通過OBConversion來讀取分子, 并輸出不同格式文件或字符串值
import openbabel

obConversion = openbabel.OBConversion()
obConversion.SetInAndOutFormats("smi", "mdl")    //讀取smiles值, 然后輸出mdl值

mol = openbabel.OBMol()
obConversion.ReadString(mol, "C1=CC=CS1")

print 'Should print 5 (atoms)'
print mol.NumAtoms()

mol.AddHydrogens()
print 'Should print 9 (atoms) after adding hydrogens'
print mol.NumAtoms()      //輸出原子個(gè)數(shù)

outMDL = obConversion.WriteString(mol)

3. 計(jì)算fp值
import pybel
smiles = ['CCCC', 'CCCN']
mols = [pybel.readstring("smi", x) for x in smiles]   # Create two molecules from the SMILES
fps = [x.calcfp() for x in mols]   # Calculate their fingerprints
print fps[0].bits, fps[1].bits
print fps[0].fp[0]

mol2 = pybel.readstring('smi', 'c2ccc1ccccc1c2')
fp2 = mol2.calcfp("FP4")
print fp2
print fp2.bits


mol3 = pybel.readstring('smi', 'C1CCCCC1')
fp3 = mol3.calcfp()

print fp3.__or__(fp2)  //計(jì)算相似度值

4. 讀取sdf文件
#encoding=utf-8
import pybel
for mymol in pybel.readfile("sdf", "structures_all.sdf"):
    fp = mymol.calcfp("FP2")
    print fp

5. 輸出txt文件和sdf文件

print mymol.write("smi")    //'CCCC'
mymol.write("smi", "outputfile.txt")
largeSDfile = Outputfile("sdf", "multipleSD.sdf")
largeSDfile.write(mymol)
largeSDfile.write(myothermol)
largeSDfile.close()



周銳 2009-10-25 12:37 發(fā)表評論
]]>
使用CDK生成分子結(jié)構(gòu)圖http://www.tkk7.com/rain1102/archive/2009/10/22/299271.html周銳周銳Thu, 22 Oct 2009 00:51:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/22/299271.htmlhttp://www.tkk7.com/rain1102/comments/299271.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/22/299271.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/299271.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/299271.htmlimport Java.awt.Dimension;
import Java.awt.Graphics2D;
import Java.awt.geom.Rectangle2D;
import Java.awt.image.BufferedImage;
import Java.io.OutputStream;
import Java.io.StringReader;
import Java.util.Iterator;

import javax.servlet.http.HttpServletResponse;
import javax.vecmath.Point2d;

import org.apache.log4j.Logger;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.io.MDLReader;
import org.openscience.cdk.layout.StructureDiagramGenerator;
import org.openscience.cdk.renderer.Renderer2DModel;
import org.openscience.cdk.renderer.SimpleRenderer2D;

public class ImageTypeExporterUtil {
 private static final Logger logger = Logger.getLogger(ImageTypeExporterUtil.class);
 
 /**
  * show molecule structure to image type (png, jpeg)
  *
  * @param mol String molecule stucture
  * @param length width and height
  * @param response HttpServletResponse object
  * @throws Exception
  *             if occurred exception ,then throw Exception
  */
 public static void showAsImage(String stucture, Integer length, HttpServletResponse response) throws Exception {
  logger.debug("ImageTypeExporterUtil.showAsImage..");
  
  StringReader mdl = new StringReader(stucture);
  MDLReader cdkMDL = new MDLReader(mdl);
  Molecule mol = new Molecule();
  cdkMDL.read(mol);
  // null coordinates
  Iterator<IAtom> itatoms = mol.atoms();
  while (itatoms.hasNext()) {
   IAtom atom = itatoms.next();
   atom.setPoint2d(null);
   atom.setPoint3d(null);
  }
  // generate 2D coordinates
  StructureDiagramGenerator sdg = new StructureDiagramGenerator();
  sdg.setMolecule(mol);
  try {
   sdg.generateCoordinates();
  } catch (Exception ex) {
   ex.printStackTrace();
  }
  IMolecule layedOutMol = sdg.getMolecule();
  // scale molecule
  final double UNDEF_POS = 100000;
  double minX = UNDEF_POS, minY = UNDEF_POS, maxX = UNDEF_POS, maxY = UNDEF_POS;
  itatoms = layedOutMol.atoms();
  while (itatoms.hasNext()) {
   IAtom atom = itatoms.next();
   Point2d point2d = atom.getPoint2d();
   if (minX == UNDEF_POS || minX > point2d.x)
    minX = point2d.x;
   if (minY == UNDEF_POS || minY > point2d.y)
    minY = point2d.y;
   if (maxX == UNDEF_POS || maxX < point2d.x)
    maxX = point2d.x;
   if (maxY == UNDEF_POS || maxY < point2d.y)
    maxY = point2d.y;
  }
  double scaleX = length / (maxX - minX + 1);
  double scaleY = length / (maxY - minY + 1);
  double scale = scaleX > scaleY ? scaleY : scaleX;
  double centreX = scale * (maxX + minX) / 2.;
  double centreY = scale * (maxY + minY) / 2.;
  double offsetX = length / 2. - centreX;
  double offsetY = length / 2. - centreY;
  itatoms = layedOutMol.atoms();
  while (itatoms.hasNext()) {
   IAtom atom = itatoms.next();
   Point2d a = atom.getPoint2d();
   Point2d b = new Point2d();
   b.x = a.x * scale + offsetX;
   b.y = a.y * scale + offsetY;
   atom.setPoint2d(b);
  }
  // set rendering properties
  Renderer2DModel r2dm = new Renderer2DModel();
  r2dm.setDrawNumbers(false);
  r2dm.setUseAntiAliasing(true);
  r2dm.setColorAtomsByType(true);
  r2dm.setShowAtomTypeNames(false);
  r2dm.setShowAromaticity(true);
  r2dm.setShowImplicitHydrogens(false);
  r2dm.setShowReactionBoxes(false);
  r2dm.setKekuleStructure(false);
  Dimension dim = new Dimension();
  dim.setSize(length, length);
  r2dm.setBackgroundDimension(dim);
  r2dm.setBackColor(java.awt.Color.WHITE);
  // render the image
  SimpleRenderer2D renderer = new SimpleRenderer2D();
  renderer.setRenderer2DModel(r2dm);
  BufferedImage bufferedImage = new BufferedImage(length, length,
    BufferedImage.TYPE_INT_RGB);
  Graphics2D graphics = bufferedImage.createGraphics();
  graphics.setPaint(java.awt.Color.WHITE);
  Rectangle2D.Float rectangle = new Rectangle2D.Float(0, 0, length, length);
  graphics.fill(rectangle);
  renderer.paintMolecule(layedOutMol, graphics);
  // write the image to response
  response.setContentType("image/png");
  OutputStream out = response.getOutputStream();
  try {
   javax.imageio.ImageIO.write(bufferedImage, "png", out);
  } finally {
   out.close();
  }
 }
}



周銳 2009-10-22 08:51 發(fā)表評論
]]>
使用CDK進(jìn)行子結(jié)構(gòu)搜索http://www.tkk7.com/rain1102/archive/2009/10/20/298919.html周銳周銳Tue, 20 Oct 2009 00:33:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/20/298919.htmlhttp://www.tkk7.com/rain1102/comments/298919.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/20/298919.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/298919.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/298919.html

package com.founder.cdk;

import Java.io.File;
import Java.io.FileNotFoundException;
import Java.io.FileReader;
import Java.util.ArrayList;
import Java.util.List;

import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemObject;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.io.MDLV2000Reader;
import org.openscience.cdk.smiles.smarts.SMARTSQueryTool;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;

public class SMARTSQueryToolTest {

 static SMARTSQueryTool sqt;static {
        try {
            sqt = new SMARTSQueryTool("c2ccc1ccccc1c2");
        } catch (CDKException e) {           
        }
    }

 /**
  * @param args
  */
 public static void main(String[] args) {
  String filename = "H:\\molecules.sdf";
  try {
            MDLV2000Reader reader = new MDLV2000Reader(new FileReader(new File(filename)));
            ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
            List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
           
            List<IAtomContainer> substructureList = new ArrayList<IAtomContainer>();
            
            sqt.setSmarts("c1ccc3c(c1)ccc4c2ccccc2ccc34");  //重新設(shè)置匹配的smiles值
            boolean matched = false;
            for (IAtomContainer molecule : containersList) {
                matched = sqt.matches(molecule);
                if (matched){
                 substructureList.add(molecule);
                }
            }
            System.out.println(substructureList.size());
           
            for (IAtomContainer molecule : substructureList) {
                 System.out.println(molecule.getProperty("ID"));
            }
           
        } catch (CDKException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
           e.printStackTrace();
        }

 }

}

通過測試, matches方法速度很慢, 一般一個(gè)結(jié)構(gòu)需要200ms-1000ms左右.



周銳 2009-10-20 08:33 發(fā)表評論
]]>
使用CDK解析SDF文件http://www.tkk7.com/rain1102/archive/2009/10/19/298802.html周銳周銳Mon, 19 Oct 2009 01:45:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/19/298802.htmlhttp://www.tkk7.com/rain1102/comments/298802.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/19/298802.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/298802.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/298802.htmlpackage com.founder.cdk;

import Java.io.File;
import Java.io.FileNotFoundException;
import Java.io.FileReader;
import Java.util.List;

import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemObject;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.io.MDLReader;
import org.openscience.cdk.io.MDLV2000Reader;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;

public class ReadSDFTest {

 /**
  * @param args
  * @throws CDKException
  * @throws FileNotFoundException
  */
 public static void main(String[] args) throws CDKException, FileNotFoundException {
  String filename = "H:\\molecules.sdf";
       
//  InputStream ins = ReadSDFTest.class.getClassLoader().getResourceAsStream(filename);
//  MDLReader reader = new MDLReader(ins);

   //alternatively, you can specify a file directly
   MDLV2000Reader reader = new MDLV2000Reader(new FileReader(new File(filename)));

  ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
  
  List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
  
  Molecule molecule = null;
  for (IAtomContainer mol : containersList) {
   molecule = (Molecule) mol;
   System.out.println(molecule.getProperties());
   System.out.println(molecule.getProperty("CD_MOLWEIGHT"));
//   Fingerprinter fp = new Fingerprinter();
//   BitSet bt = fp.getFingerprint(molecule);
//   System.out.println(bt);
  }
 }

}



周銳 2009-10-19 09:45 發(fā)表評論
]]>
使用CDK進(jìn)行相似度搜索http://www.tkk7.com/rain1102/archive/2009/10/19/298801.html周銳周銳Mon, 19 Oct 2009 01:37:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/19/298801.htmlhttp://www.tkk7.com/rain1102/comments/298801.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/19/298801.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/298801.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/298801.htmlpackage com.founder.cdk;

import Java.io.StringReader;
import Java.sql.Connection;
import Java.sql.ResultSet;
import Java.sql.SQLException;
import Java.util.ArrayList;
import Java.util.BitSet;
import Java.util.List;

import org.openscience.cdk.Molecule;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.fingerprint.Fingerprinter;
import org.openscience.cdk.io.MDLReader;
import org.openscience.cdk.similarity.Tanimoto;

public class CDKTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  
  // MySQL
  long t1 = System.currentTimeMillis();
  try {
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   Connection con = Java.sql.DriverManager
     .getConnection(
       "jdbc:mysql://localhost/coocoo?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull",
       "root", "root");
   

   ResultSet results = null;
   String querySQL = "select id, structure from structure ";
   
   results = con.createStatement().executeQuery(querySQL);
 
   // dump out the results

   List<Molecule> list = new ArrayList<Molecule>();
   Fingerprinter fp = new Fingerprinter();
   BitSet bt = null;
   while (results.next()) {
    Long id = results.getLong("id");
    
    //根據(jù)結(jié)構(gòu)數(shù)據(jù)生成分子對象
    StringReader mdl = new StringReader(results.getString("structure"));
    MDLReader cdkMDL = new MDLReader(mdl);
    Molecule molecule = new Molecule();
    cdkMDL.read(molecule);

    if (id == 1220) {
     bt = fp.getFingerprint(molecule);
    }
    list.add(molecule);
    
   } 
   System.out.println("size:=" + list.size());
   
   List<Molecule> resultList = new ArrayList<Molecule>();
        
         long t2 = System.currentTimeMillis();
         System.out.println("Thread: collection data in " + (t2 - t1) + " ms.");
         for (Molecule molecule : list) {
             try {
                 float coefficient = Tanimoto.calculate(fp.getFingerprint(molecule), bt);  //計(jì)算相似度
                 if (coefficient > 0.9) {
                  resultList.add(molecule);
                 }
             } catch (CDKException e) {

             }
         }
         long t3 = System.currentTimeMillis();
        
         System.out.println(resultList.size());
         System.out.println("Thread: Search in " + (t3 - t2) + " ms.");
        
   con.close();
  } catch (InstantiationException e) {
   e.printStackTrace();
  } catch (IllegalAccessException e) {
   e.printStackTrace();
  } catch (ClassNotFoundException e) {
   e.printStackTrace();
  } catch (SQLException e) {
   e.printStackTrace();
  } catch (CDKException e) {
   e.printStackTrace();
  }
  long t4 = System.currentTimeMillis();
        System.out.println("Thread: all in " + (t4 - t1) + " ms.");
 }

}



周銳 2009-10-19 09:37 發(fā)表評論
]]>
Faster Fingerprint Search with Java & CDKhttp://www.tkk7.com/rain1102/archive/2009/10/18/298745.html周銳周銳Sun, 18 Oct 2009 06:09:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/18/298745.htmlhttp://www.tkk7.com/rain1102/comments/298745.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/18/298745.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/298745.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/298745.html

Rich Apodaca wrote a great serious posts named Fast Substructure Search Using Open Source Tools providing details on substructure search with MySQL. But, however, poor binary data operation functions of MySQL limited the implementation of similar structure search which typically depends on the calculation of Tanimato coefficient. We are going to use Java & CDK to add this feature.

As default output of CDK fingerprint, java.util.BitSet with Serializable interface is perfect data format of fingerprint data storage. Java itself provides several collections such as ArrayList, LinkedList, Vector class in package Java.util. To provide web access to the search engine, thread unsafe ArrayList and LinkedList have to be kicked out. How about Vector? Once all the fingerprint data is well prepared, the collection  function we need to do similarity search is just iteration. No add, no delete. So, a light weight array is enough.

Most of the molecule information is stored in MySQL database, so we are going to map fingerprint to corresponding row in data table. Here is the MolDFData class, we use a long variable to store corresponding primary key in data table.

public class MolDFData implements Serializable {
    private long id;
   private BitSet fingerprint;
    public MolDFData(long id, BitSet fingerprint) {
        this.id = id;
        this.fingerprint = fingerprint;
    }
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public BitSet getFingerprint() {
        return fingerprint;
    }
    public void setFingerprint(BitSet fingerprint) {
        this.fingerprint = fingerprint;
    }
}

This is how we storage our fingerprints.

private MolFPData[] arrayData;

No big deal with similarity search. Just calculate the Tanimoto coefficient, if it’s bigger than minimal  similarity you set, add this one into result.

    public List searchTanimoto(BitSet bt, float minSimlarity) {

        List resultList = new LinkedList();
        int i;
        for (i = 0; i < arrayData.length; i++) {
            MolDFData aListData = arrayData[i];
            try {
                float coefficient = Tanimoto.calculate(aListData.getFingerprint(), bt);
                if (coefficient > minSimlarity) {
                    resultList.add(new SearchResultData(aListData.getId(), coefficient));
                }
            } catch (CDKException e) {
            }
            Collections.sort(resultList);
        }
        return resultList;
    }
Pretty ugly code?  Maybe. But it really works, at a acceptable speed.

Tests were done using the code blow on a macbook(Intel Core Due 1.83 GHz, 2G RAM).

long t3 = System.currentTimeMillis();
List<SearchResultData> listResult = se.searchTanimoto(bs, 0.8f);
long t4 = System.currentTimeMillis();
System.out.println("Thread: Search done in " + (t4 - t3) + " ms.");

In my database of 87364 commercial compounds, it takes 335 ms.



周銳 2009-10-18 14:09 發(fā)表評論
]]>
CDK中的相似度搜索http://www.tkk7.com/rain1102/archive/2009/10/18/298744.html周銳周銳Sun, 18 Oct 2009 05:36:00 GMThttp://www.tkk7.com/rain1102/archive/2009/10/18/298744.htmlhttp://www.tkk7.com/rain1102/comments/298744.htmlhttp://www.tkk7.com/rain1102/archive/2009/10/18/298744.html#Feedback0http://www.tkk7.com/rain1102/comments/commentRss/298744.htmlhttp://www.tkk7.com/rain1102/services/trackbacks/298744.html/*  $RCSfile$
 *  $Author$
 *  $Date$
 *  $Revision$
 *
 *  Copyright (C) 1997-2007  The Chemistry Development Kit (CDK) project
 *
 *  Contact: cdk-devel@lists.sourceforge.net
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
 *  All we ask is that proper credit is given for our work, which includes
 *  - but is not limited to - adding the above copyright notice to the beginning
 *  of your source code files, and to any copyright notice that you may distribute
 *  with programs based on this work.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
package org.openscience.cdk.similarity;


import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;

import Java.util.BitSet;

/**
 *  Calculates the Tanimoto coefficient for a given pair of two
 *  fingerprint bitsets or real valued feature vectors.
 *
 *  The Tanimoto coefficient is one way to
 *  quantitatively measure the "distance" or similarity of
 *  two chemical structures.
 *
 *  <p>You can use the FingerPrinter class to retrieve two fingerprint bitsets.
 *  We assume that you have two structures stored in cdk.Molecule objects.
 *  A tanimoto coefficient can then be calculated like:
 *  <pre>
 *   BitSet fingerprint1 = Fingerprinter.getFingerprint(molecule1);
 *   BitSet fingerprint2 = Fingerprinter.getFingerprint(molecule2);
 *   float tanimoto_coefficient = Tanimoto.calculate(fingerprint1, fingerprint2);
 *  </pre>
 *
 *  <p>The FingerPrinter assumes that hydrogens are explicitely given, if this
 *  is desired!
 *  <p>Note that the continuous Tanimoto coefficient does not lead to a metric space
 *
 *@author         steinbeck
 * @cdk.githash
 *@cdk.created    2005-10-19
 *@cdk.keyword    jaccard
 *@cdk.keyword    similarity, tanimoto
 * @cdk.module fingerprint
 */
@TestClass("org.openscience.cdk.similarity.TanimotoTest")
public class Tanimoto
{

    /**
     * Evaluates Tanimoto coefficient for two bit sets.
     *
     * @param bitset1 A bitset (such as a fingerprint) for the first molecule
     * @param bitset2 A bitset (such as a fingerprint) for the second molecule
     * @return The Tanimoto coefficient
     * @throws org.openscience.cdk.exception.CDKException  if bitsets are not of the same length
     */
    @TestMethod("testTanimoto1,testTanimoto2")
    public static float calculate(BitSet bitset1, BitSet bitset2) throws CDKException
    {
        float _bitset1_cardinality = bitset1.cardinality();
        float _bitset2_cardinality = bitset2.cardinality();
        if (bitset1.size() != bitset2.size()) {
            throw new CDKException("Bisets must have the same bit length");
        }
        BitSet one_and_two = (BitSet)bitset1.clone();
        one_and_two.and(bitset2);
        float _common_bit_count = one_and_two.cardinality();
        return _common_bit_count/(_bitset1_cardinality + _bitset2_cardinality - _common_bit_count);
    }
   
    /**
     * Evaluates the continuous Tanimoto coefficient for two real valued vectors.
     *
     * @param features1 The first feature vector
     * @param features2 The second feature vector
     * @return The continuous Tanimoto coefficient
     * @throws org.openscience.cdk.exception.CDKException  if the features are not of the same length
     */
    @TestMethod("testTanimoto3")
    public static float calculate(double[] features1, double[] features2) throws CDKException {

        if (features1.length != features2.length) {
            throw new CDKException("Features vectors must be of the same length");
        }

        int n = features1.length;
        double ab = 0.0;
        double a2 = 0.0;
        double b2 = 0.0;

        for (int i = 0; i < n; i++) {
            ab += features1[i] * features2[i];
            a2 += features1[i]*features1[i];
            b2 += features2[i]*features2[i];
        }
        return (float)ab/(float)(a2+b2-ab);
    }
}

通過源碼可以看出calculate(BitSet bitset1, BitSet bitset2)方法,是通過比較兩個(gè)分子的fingerprint的位,來計(jì)算相似度.通過BitSet的and操作得到共同的個(gè)數(shù),然后在除以總共為true的個(gè)數(shù),這樣就得到相似值.



周銳 2009-10-18 13:36 發(fā)表評論
]]>
主站蜘蛛池模板: 久久久久久久久久免免费精品| 一级毛片不卡片免费观看| 国产亚洲成归v人片在线观看 | 亚洲永久在线观看| 伊人久久亚洲综合影院| 日韩精品人妻系列无码专区免费| 国产精品亚洲精品观看不卡| 国产AV无码专区亚洲AV手机麻豆| 国产精品1024永久免费视频 | 免费A级毛片av无码| 亚洲国产日韩a在线播放| 国产亚洲av片在线观看播放| 日韩免费a级毛片无码a∨| 插鸡网站在线播放免费观看| 亚洲日本乱码卡2卡3卡新区| 亚洲级αV无码毛片久久精品| 成人黄动漫画免费网站视频 | 无码专区一va亚洲v专区在线| 95老司机免费福利| 四虎影视久久久免费观看| 亚洲成aⅴ人片在线观| 亚洲一级特黄大片无码毛片 | 亚洲剧情在线观看| 中文字幕久久亚洲一区| 永久免费无码网站在线观看| 亚洲国产精品免费视频| 九九视频高清视频免费观看 | a级片免费观看视频| 久久久久久亚洲精品无码| 亚洲嫩草影院在线观看| 国产成人精品日本亚洲网站 | 亚洲AV无码码潮喷在线观看| 又黄又爽无遮挡免费视频| 无码国产精品一区二区免费式直播| 国产一区二区三区免费观在线| 亚洲AV成人精品一区二区三区| 亚洲一区中文字幕在线观看| 久久精品国产亚洲av高清漫画| 亚洲中文字幕无码一区二区三区 | 亚洲国产精品日韩在线| 亚洲AV日韩精品久久久久久久|