国产精品视频一区视频二区,欧美色综合一区二区三区,一级毛片在线http://www.aygfsteel.com/rain1102/category/37642.html<br/><font color="green" style="font-family: 華文行楷;font-size:16px;">化學結構搜索,化學信息學,生物信息學,實驗室信息學等 。</font><br/><font color="#3C1435">以高科技的生物、化學信息技術實現生命科學領域中專業數據的計算和管理、提高研發能力、增強在科研和成本效率方面的國際競爭力,為生物、化學、醫藥和學術機構提供一流的解決方案和技術咨詢。</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圖片生成高質量的縮略圖http://www.aygfsteel.com/rain1102/archive/2011/07/26/355029.html周銳周銳Tue, 26 Jul 2011 01:49:00 GMThttp://www.aygfsteel.com/rain1102/archive/2011/07/26/355029.htmlhttp://www.aygfsteel.com/rain1102/comments/355029.htmlhttp://www.aygfsteel.com/rain1102/archive/2011/07/26/355029.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/355029.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/355029.html如果給出縮略圖的寬度和高度,那么就會根據給出的寬度和高度生產縮略圖,如果只給出寬度或者高度值,那么就會根據比例生成縮略圖。
package com.founder.common.utils;

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

//生成等比例高質量縮略圖
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 發表評論
]]>
在SQLPlus中執行用Java編寫的Oracle存儲過程[轉載]http://www.aygfsteel.com/rain1102/archive/2011/06/22/352799.html周銳周銳Wed, 22 Jun 2011 04:38:00 GMThttp://www.aygfsteel.com/rain1102/archive/2011/06/22/352799.htmlhttp://www.aygfsteel.com/rain1102/comments/352799.htmlhttp://www.aygfsteel.com/rain1102/archive/2011/06/22/352799.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/352799.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/352799.html

首先在PL/Sql中分別執行:

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>

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

再看一個例子:

在PL/Sql中執行:

--用Java編寫Oracle存儲過程。
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;
    }
}

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

然后在SqlPlus中測試存儲過程——

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

周銳 2011-06-08 14:05 發表評論
]]>
使用Ehcache對頁面緩存http://www.aygfsteel.com/rain1102/archive/2011/05/12/350097.html周銳周銳Thu, 12 May 2011 08:11:00 GMThttp://www.aygfsteel.com/rain1102/archive/2011/05/12/350097.htmlhttp://www.aygfsteel.com/rain1102/comments/350097.htmlhttp://www.aygfsteel.com/rain1102/archive/2011/05/12/350097.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/350097.htmlhttp://www.aygfsteel.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 發表評論
]]>
chemtoolkits上線啦http://www.aygfsteel.com/rain1102/archive/2011/05/07/349748.html周銳周銳Sat, 07 May 2011 11:02:00 GMThttp://www.aygfsteel.com/rain1102/archive/2011/05/07/349748.htmlhttp://www.aygfsteel.com/rain1102/comments/349748.htmlhttp://www.aygfsteel.com/rain1102/archive/2011/05/07/349748.html#Feedback1http://www.aygfsteel.com/rain1102/comments/commentRss/349748.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/349748.html http://www.chemtoolkits.com

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

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

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


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

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

另外一個好消息,從1.3.8開始,java可以通過JNI去調用OSRA程序了,這樣我們可以通過這個做很多有意思的事情,比如點擊一個圖片,直接去結構式搜索或者計算相關理化性質等等!

周銳 2011-04-22 17:49 發表評論
]]>
通過使用Opsin進行IUPAC名稱到結構轉換http://www.aygfsteel.com/rain1102/archive/2011/04/19/348596.html周銳周銳Tue, 19 Apr 2011 13:52:00 GMThttp://www.aygfsteel.com/rain1102/archive/2011/04/19/348596.htmlhttp://www.aygfsteel.com/rain1102/comments/348596.htmlhttp://www.aygfsteel.com/rain1102/archive/2011/04/19/348596.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/348596.htmlhttp://www.aygfsteel.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);
 }

}

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



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

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

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

周銳 2011-04-09 17:16 發表評論
]]>
chemtoolkits.com國內免費化學信息學服務平臺http://www.aygfsteel.com/rain1102/archive/2011/04/06/347676.html周銳周銳Wed, 06 Apr 2011 02:06:00 GMThttp://www.aygfsteel.com/rain1102/archive/2011/04/06/347676.htmlhttp://www.aygfsteel.com/rain1102/comments/347676.htmlhttp://www.aygfsteel.com/rain1102/archive/2011/04/06/347676.html#Feedback2http://www.aygfsteel.com/rain1102/comments/commentRss/347676.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/347676.html閱讀全文

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

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

        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, 結果與活性關系,簡稱構效關系

       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
生成構效關系表格

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

8.Ligand binding Efficiency
配體結合效果

       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
結構可視化

       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
建立預測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 發表評論
]]>
Java通過Rserve調研R函數http://www.aygfsteel.com/rain1102/archive/2011/03/30/347261.html周銳周銳Wed, 30 Mar 2011 02:57:00 GMThttp://www.aygfsteel.com/rain1102/archive/2011/03/30/347261.htmlhttp://www.aygfsteel.com/rain1102/comments/347261.htmlhttp://www.aygfsteel.com/rain1102/archive/2011/03/30/347261.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/347261.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/347261.html 而Java語言是目前最流行的語言,當然對我自己來說也是最熟悉的語言了。所以今天嘗試通過java來調用R函數為下面通過調用數學函數實現業務功能做基礎。
目前我在windows xp上做測試。
1. 首先需要下載R的windows安裝程序,地址為http://cran.r-project.org/,選擇base進行下載。然后安裝就可以了。
2. 安裝Rserve,可以通過R界面中的命令行輸入:install.packages("Rserve")或者在R界面上選擇:程序包->安裝程序包,然后找到Rserve進行安裝。
3. 啟動Rserve, 在R界面中的命令行中輸入:library(Rserve)來加載Rserve,然后輸入Rserve()進行啟動服務。
到此Rserve已經配置并啟動好,下面輪到Java程序調用了。
1. 下載Rserve提供的jar包,打開http://www.rforge.net/Rserve/files/,下載REngine.jarRserveEngine.jar,然后放到自己的項目中,并引入。
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());
 }

}


運行,輸入結果:
R version 2.12.2 (2011-02-25)

周銳 2011-03-30 10:57 發表評論
]]>
Java導出csv文件處理逗號http://www.aygfsteel.com/rain1102/archive/2011/03/29/347241.html周銳周銳Tue, 29 Mar 2011 14:27:00 GMThttp://www.aygfsteel.com/rain1102/archive/2011/03/29/347241.htmlhttp://www.aygfsteel.com/rain1102/comments/347241.htmlhttp://www.aygfsteel.com/rain1102/archive/2011/03/29/347241.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/347241.htmlhttp://www.aygfsteel.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 發表評論
]]>
Generating PDFs for Fun and Profit with Flying Saucer and iTexthttp://www.aygfsteel.com/rain1102/archive/2010/04/18/318651.html周銳周銳Sun, 18 Apr 2010 03:29:00 GMThttp://www.aygfsteel.com/rain1102/archive/2010/04/18/318651.htmlhttp://www.aygfsteel.com/rain1102/comments/318651.htmlhttp://www.aygfsteel.com/rain1102/archive/2010/04/18/318651.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/318651.htmlhttp://www.aygfsteel.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 發表評論
]]>
Enable the jre plugin in chrome and firefox in ubuntu 9.04http://www.aygfsteel.com/rain1102/archive/2010/04/15/318392.html周銳周銳Thu, 15 Apr 2010 03:06:00 GMThttp://www.aygfsteel.com/rain1102/archive/2010/04/15/318392.htmlhttp://www.aygfsteel.com/rain1102/comments/318392.htmlhttp://www.aygfsteel.com/rain1102/archive/2010/04/15/318392.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/318392.htmlhttp://www.aygfsteel.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 發表評論
]]>
Jbpm4.2+tomcat6+oracle9i安裝過程[轉載]http://www.aygfsteel.com/rain1102/archive/2009/12/03/304687.html周銳周銳Thu, 03 Dec 2009 11:48:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/12/03/304687.htmlhttp://www.aygfsteel.com/rain1102/comments/304687.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/12/03/304687.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/304687.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/304687.html 1.軟件清單
   jdk1.6
   jbpm4.2
   tomcat6
   oracle9i
   ant1.7
   eclipse-jee-galileo-win32

2.配置JDK1.6
   在系統路徑上添加
   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
   在系統路徑上添加
   ANT_HOME=c:\java\ant
   path=%ANT_HOME%\bin

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

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

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

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

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

9.創建一個jbpm demo
創建一個例子,并將工作流程定義保存到數據庫中
(1)創建一個java Project,起名“ myjbpm ”,然后就可以單擊“完成”了
(2)將c:\jbpm-4.2\examples\src中的所有配置文件復制到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 的默認設置是用 HSQL ,這是一個內存數據庫,這種內存數據庫用來代替項目實際所用的數據庫來做單元測試挺不錯的。不過我們這里是要試試用 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)定義流程
   創建流程的定義文件是 pd.jpdl.xml,將下面代碼復制到文件中
------------------------------------------------------------------------------------------
<?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();
  
     // 開始部署一個新的流程文件
     String deploymentId = repositoryService.createDeployment().addResourceFromClasspath("pd.jpdl.xml").deploy();

   }
}

   無論是 MySQL 還是 Oracle ,
   jbpm4_deployment表,你會發現多了一條記錄
   jbpm4_deployprop表會多了三條記錄,對應id,key,version
   jbpm4_lob 表會多了一條記錄,保存流程圖


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


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

找到一個解壓版本的tomcat放到任意目錄,然后聽過命令行進入到該目錄下的bin目錄里面,里面應該有個service.bat文件,執行service remove tomcat6,這樣就刪除服務了。下面就可以安裝!

周銳 2009-11-20 17:06 發表評論
]]>
JavaMail問題之Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStreamhttp://www.aygfsteel.com/rain1102/archive/2009/11/17/302654.html周銳周銳Tue, 17 Nov 2009 03:05:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/11/17/302654.htmlhttp://www.aygfsteel.com/rain1102/comments/302654.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/11/17/302654.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/302654.htmlhttp://www.aygfsteel.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上就會出現上面的錯誤,
   如果還出現此問題,則是因為javaEE5中包含有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 發表評論
]]>
Hibernate中主鍵增長步長為50的問題 Oraclehttp://www.aygfsteel.com/rain1102/archive/2009/11/11/302019.html周銳周銳Wed, 11 Nov 2009 13:54:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/11/11/302019.htmlhttp://www.aygfsteel.com/rain1102/comments/302019.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/11/11/302019.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/302019.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/302019.html原文地址:http://jhyimu2005.javaeye.com/blog/514379
先聲明一下我用的框架是Spring + Hibernate + SpringMVC 數據庫使用的是Oracle
昨天遇到了一個特詭異的問題就是我使用Oracle序列,把主鍵的計數交給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; }


寫完部署什么都沒問題,可當我寫了測試類進行測試時發現主鍵的初始值竟然是50,其步長亦是50,在同事的幫助下發現原來是Hibernate在做鬼,@SequenceGenerator中添加兩個參數(allocationSize = 1, initialValue = 1)就OK。通過查找Hibernate的資料發現原來是因為allocationSize的默認值是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 發表評論
]]>
oracle調用javahttp://www.aygfsteel.com/rain1102/archive/2009/10/29/300146.html周銳周銳Thu, 29 Oct 2009 03:20:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/29/300146.htmlhttp://www.aygfsteel.com/rain1102/comments/300146.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/29/300146.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/300146.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/300146.html前提是數據庫上需要安裝java虛擬機(JVM),使用下面的語句查看

select * from dba_registry where comp_id = 'JAVAVM'

為空,則未安裝,請執行 $ORACLE_HOME/javavm/install/initjvm.sql安裝.
創建函數

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';

創建存儲過程

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 發表評論
]]>
CDK中根據smiles計算Fingerprinter值http://www.aygfsteel.com/rain1102/archive/2009/10/26/299848.html周銳周銳Mon, 26 Oct 2009 14:24:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/26/299848.htmlhttp://www.aygfsteel.com/rain1102/comments/299848.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/26/299848.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/299848.htmlhttp://www.aygfsteel.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 發表評論
]]>
在Python中使用openbabelhttp://www.aygfsteel.com/rain1102/archive/2009/10/25/299655.html周銳周銳Sun, 25 Oct 2009 04:37:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/25/299655.htmlhttp://www.aygfsteel.com/rain1102/comments/299655.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/25/299655.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/299655.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/299655.html如果你的環境還沒準備好, 可以官方網站看如何配置環境:http://openbabel.org/wiki/Install_Python_bindings
1. 通過使用OBMol, OBAtom和OBBond來創建原子和鍵
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()      //輸出原子個數

outMDL = obConversion.WriteString(mol)

3. 計算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)  //計算相似度值

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 發表評論
]]>
使用CDK生成分子結構圖http://www.aygfsteel.com/rain1102/archive/2009/10/22/299271.html周銳周銳Thu, 22 Oct 2009 00:51:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/22/299271.htmlhttp://www.aygfsteel.com/rain1102/comments/299271.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/22/299271.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/299271.htmlhttp://www.aygfsteel.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 發表評論
]]>
使用CDK進行子結構搜索http://www.aygfsteel.com/rain1102/archive/2009/10/20/298919.html周銳周銳Tue, 20 Oct 2009 00:33:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/20/298919.htmlhttp://www.aygfsteel.com/rain1102/comments/298919.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/20/298919.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/298919.htmlhttp://www.aygfsteel.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");  //重新設置匹配的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方法速度很慢, 一般一個結構需要200ms-1000ms左右.



周銳 2009-10-20 08:33 發表評論
]]>
使用CDK解析SDF文件http://www.aygfsteel.com/rain1102/archive/2009/10/19/298802.html周銳周銳Mon, 19 Oct 2009 01:45:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/19/298802.htmlhttp://www.aygfsteel.com/rain1102/comments/298802.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/19/298802.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/298802.htmlhttp://www.aygfsteel.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 發表評論
]]>
使用CDK進行相似度搜索http://www.aygfsteel.com/rain1102/archive/2009/10/19/298801.html周銳周銳Mon, 19 Oct 2009 01:37:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/19/298801.htmlhttp://www.aygfsteel.com/rain1102/comments/298801.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/19/298801.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/298801.htmlhttp://www.aygfsteel.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");
    
    //根據結構數據生成分子對象
    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);  //計算相似度
                 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 發表評論
]]>
Faster Fingerprint Search with Java & CDKhttp://www.aygfsteel.com/rain1102/archive/2009/10/18/298745.html周銳周銳Sun, 18 Oct 2009 06:09:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/18/298745.htmlhttp://www.aygfsteel.com/rain1102/comments/298745.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/18/298745.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/298745.htmlhttp://www.aygfsteel.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 發表評論
]]>
CDK中的相似度搜索http://www.aygfsteel.com/rain1102/archive/2009/10/18/298744.html周銳周銳Sun, 18 Oct 2009 05:36:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/10/18/298744.htmlhttp://www.aygfsteel.com/rain1102/comments/298744.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/10/18/298744.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/298744.htmlhttp://www.aygfsteel.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)方法,是通過比較兩個分子的fingerprint的位,來計算相似度.通過BitSet的and操作得到共同的個數,然后在除以總共為true的個數,這樣就得到相似值.



周銳 2009-10-18 13:36 發表評論
]]>
主站蜘蛛池模板: 普洱| 洞头县| 汨罗市| 庆城县| 资兴市| 随州市| 永胜县| 扶余县| 西华县| 金川县| 额济纳旗| 阿克陶县| 哈巴河县| 五台县| 五常市| 建昌县| 安陆市| 富锦市| 五大连池市| 宁津县| 诏安县| 原平市| 大洼县| 尖扎县| 北海市| 新巴尔虎左旗| 靖江市| 贞丰县| 阳信县| 台东县| 高州市| 大城县| 沂源县| 孟连| 衢州市| 西昌市| 鄂伦春自治旗| 梁平县| 九寨沟县| 巴林右旗| 淮安市|