posts - 431,  comments - 344,  trackbacks - 0
          CDK提供了通過smiles值進(jìn)行子結(jié)構(gòu)搜索,  org.openscience.cdk.smiles.smarts.SMARTSQueryTool

          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左右.

          posted on 2009-10-20 08:33 周銳 閱讀(600) 評(píng)論(0)  編輯  收藏 所屬分類: JavaCDK
          主站蜘蛛池模板: 吉木乃县| 德钦县| 通渭县| 宁阳县| 中牟县| 万宁市| 江源县| 奉化市| 措勤县| 东山县| 丽江市| 明水县| 昆明市| 西昌市| 稷山县| 陈巴尔虎旗| 青铜峡市| 浦东新区| 广丰县| 徐汇区| 库车县| 嘉峪关市| 中西区| 武威市| 开江县| 仪陇县| 南平市| 海兴县| 田林县| 锡林浩特市| 股票| 巴中市| 葵青区| 万载县| 曲麻莱县| 六安市| 安阳县| 边坝县| 察哈| 白沙| 巩留县|