📄 parsertest.java
字号:
/* $Revision: 8245 $ $Author: egonw $ $Date: 2007-04-22 17:20:57 -0400 (Sun, 22 Apr 2007) $
*
* Copyright (C) 2004-2007 Egon Willighagen <egonw@users.sf.net>
*
* 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.
*
* 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.test.smiles.smarts.parser;
import java.io.StringReader;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.openscience.cdk.isomorphism.matchers.QueryAtomContainer;
import org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond;
import org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond;
import org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond;
import org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom;
import org.openscience.cdk.smiles.smarts.parser.SMARTSParser;
import org.openscience.cdk.test.CDKTestCase;
/**
* JUnit test routines for the SMARTS parser.
*
* @cdk.module test-smarts
* @cdk.require ant1.6
*
* @author Egon Willighagen
*/
public class ParserTest extends CDKTestCase {
public ParserTest() {}
public ParserTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(ParserTest.class);
}
public void parse(String smarts) throws Exception {
//SMARTSParser.parse(smarts);
SMARTSParser parser = new SMARTSParser(new StringReader(smarts));
parser.Start();
}
public void testQueryAtomCreation() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("*");
assertEquals(1, container.getAtomCount());
org.openscience.cdk.interfaces.IAtom atom = container.getAtom(0);
assertTrue(atom instanceof SMARTSAtom);
}
public void testAliphaticAtom() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("A");
assertEquals(1, container.getAtomCount());
org.openscience.cdk.interfaces.IAtom atom = container.getAtom(0);
assertTrue(atom instanceof SMARTSAtom);
}
public void testAromaticAtom() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("a");
assertEquals(1, container.getAtomCount());
org.openscience.cdk.interfaces.IAtom atom = container.getAtom(0);
assertTrue(atom instanceof SMARTSAtom);
}
public void testDegree() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("[D2]");
assertEquals(1, container.getAtomCount());
org.openscience.cdk.interfaces.IAtom atom = container.getAtom(0);
assertTrue(atom instanceof SMARTSAtom);
}
public void testImplicitHCount() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("[h3]");
assertEquals(1, container.getAtomCount());
org.openscience.cdk.interfaces.IAtom atom = container.getAtom(0);
assertTrue(atom instanceof SMARTSAtom);
}
public void testTotalHCount() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("[H2]");
assertEquals(1, container.getAtomCount());
org.openscience.cdk.interfaces.IAtom atom = container.getAtom(0);
assertTrue(atom instanceof SMARTSAtom);
}
public void testSingleBond() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("C-C");
assertEquals(2, container.getAtomCount());
assertEquals(1, container.getBondCount());
org.openscience.cdk.interfaces.IBond bond = container.getBond(0);
assertTrue(bond instanceof OrderQueryBond);
OrderQueryBond qBond = (OrderQueryBond)bond;
assertEquals(1.0, qBond.getOrder(), 0.001);
}
public void testDoubleBond() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("C=C");
assertEquals(2, container.getAtomCount());
assertEquals(1, container.getBondCount());
org.openscience.cdk.interfaces.IBond bond = container.getBond(0);
assertTrue(bond instanceof OrderQueryBond);
OrderQueryBond qBond = (OrderQueryBond)bond;
assertEquals(2.0, qBond.getOrder(), 0.001);
}
public void testTripleBond() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("C#C");
assertEquals(2, container.getAtomCount());
assertEquals(1, container.getBondCount());
org.openscience.cdk.interfaces.IBond bond = container.getBond(0);
assertTrue(bond instanceof OrderQueryBond);
OrderQueryBond qBond = (OrderQueryBond)bond;
assertEquals(3.0, qBond.getOrder(), 0.001);
}
public void testAromaticBond() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("C:C");
assertEquals(2, container.getAtomCount());
assertEquals(1, container.getBondCount());
org.openscience.cdk.interfaces.IBond bond = container.getBond(0);
assertTrue(bond instanceof AromaticQueryBond);
}
public void testAnyOrderBond() throws Exception {
QueryAtomContainer container = SMARTSParser.parse("C~C");
assertEquals(2, container.getAtomCount());
assertEquals(1, container.getBondCount());
org.openscience.cdk.interfaces.IBond bond = container.getBond(0);
assertTrue(bond instanceof AnyOrderQueryBond);
}
public void testPattern1() throws Exception {
parse("[CX4]");
}
public void testPattern2() throws Exception {
parse("[$([CX2](=C)=C)]");
}
public void testPattern3() throws Exception {
parse("[$([CX3]=[CX3])]");
}
public void testPattern4() throws Exception {
parse("[$([CX2]#C)]");
}
public void testPattern5() throws Exception {
parse("[CX3]=[OX1]");
}
public void testPattern6() throws Exception {
parse("[$([CX3]=[OX1]),$([CX3+]-[OX1-])]");
}
public void testPattern7() throws Exception {
parse("[CX3](=[OX1])C");
}
public void testPattern8() throws Exception {
parse("[OX1]=CN");
}
public void testPattern9() throws Exception {
parse("[CX3](=[OX1])O");
}
public void testPattern10() throws Exception {
parse("[CX3](=[OX1])[F,Cl,Br,I]");
}
public void testPattern11() throws Exception {
parse("[CX3H1](=O)[#6]");
}
public void testPattern12() throws Exception {
parse("[CX3](=[OX1])[OX2][CX3](=[OX1])");
}
public void testPattern13() throws Exception {
parse("[NX3][CX3](=[OX1])[#6]");
}
public void testPattern14() throws Exception {
parse("[NX3][CX3]=[NX3+]");
}
public void testPattern15() throws Exception {
parse("[NX3,NX4+][CX3](=[OX1])[OX2,OX1-]");
}
public void testPattern16() throws Exception {
parse("[NX3][CX3](=[OX1])[OX2H0]");
}
public void testPattern17() throws Exception {
parse("[NX3,NX4+][CX3](=[OX1])[OX2H,OX1-]");
}
public void testPattern18() throws Exception {
parse("[CX3](=O)[O-]");
}
public void testPattern19() throws Exception {
parse("[CX3](=[OX1])(O)O");
}
public void testPattern20() throws Exception {
parse("[CX3](=[OX1])([OX2])[OX2H,OX1H0-1]");
}
public void testPattern21() throws Exception {
parse("[CX3](=O)[OX2H1]");
}
public void testPattern22() throws Exception {
parse("[CX3](=O)[OX1H0-,OX2H1]");
}
public void testPattern23() throws Exception {
parse("[NX3][CX2]#[NX1]");
}
public void testPattern24() throws Exception {
parse("[#6][CX3](=O)[OX2H0][#6]");
}
public void testPattern25() throws Exception {
parse("[#6][CX3](=O)[#6]");
}
public void testPattern26() throws Exception {
parse("[OD2]([#6])[#6]");
}
public void testPattern27() throws Exception {
parse("[H]");
}
public void testPattern28() throws Exception {
parse("[!#1]");
}
public void testPattern29() throws Exception {
parse("[H+]");
}
public void testPattern30() throws Exception {
parse("[+H]");
}
public void testPattern31() throws Exception {
parse("[NX3;H2,H1;!$(NC=O)]");
}
public void testPattern32() throws Exception {
parse("[NX3][CX3]=[CX3]");
}
public void testPattern33() throws Exception {
parse("[NX3;H2,H1;!$(NC=O)].[NX3;H2,H1;!$(NC=O)]");
}
public void testPattern34() throws Exception {
parse("[NX3][$(C=C),$(cc)]");
}
public void testPattern35() throws Exception {
parse("[NX3,NX4+][CX4H]([*])[CX3](=[OX1])[O,N]");
}
public void testPattern36() throws Exception {
parse("[NX3H2,NH3X4+][CX4H]([*])[CX3](=[OX1])[NX3,NX4+][CX4H]([*])[CX3](=[OX1])[OX2H,OX1-]");
}
public void testPattern37() throws Exception {
parse("[$([NX3H2,NX4H3+]),$([NX3H](C)(C))][CX4H]([*])[CX3](=[OX1])[OX2H,OX1-,N]");
}
public void testPattern38() throws Exception {
parse("[CH3X4]");
}
public void testPattern39() throws Exception {
parse("[CH2X4][CH2X4][CH2X4][NHX3][CH0X3](=[NH2X3+,NHX2+0])[NH2X3]");
}
public void testPattern40() throws Exception {
parse("[CH2X4][CX3](=[OX1])[NX3H2]");
}
public void testPattern41() throws Exception {
parse("[CH2X4][CX3](=[OX1])[OH0-,OH]");
}
public void testPattern42() throws Exception {
parse("[CH2X4][SX2H,SX1H0-]");
}
public void testPattern43() throws Exception {
parse("[CH2X4][CH2X4][CX3](=[OX1])[OH0-,OH]");
}
public void testPattern44() throws Exception {
parse("[$([$([NX3H2,NX4H3+]),$([NX3H](C)(C))][CX4H2][CX3](=[OX1])[OX2H,OX1-,N])]");
}
public void testPattern45() throws Exception {
parse("[CH2X4][#6X3]1:[$([#7X3H+,#7X2H0+0]:[#6X3H]:[#7X3H]),$([#7X3H])]:[#6X3H]:[$([#7X3H+,#7X2H0+0]:[#6X3H]:[#7X3H]),$([#7X3H])]:[#6X3H]1");
}
public void testPattern47() throws Exception {
parse("[CHX4]([CH3X4])[CH2X4][CH3X4]");
}
public void testPattern48() throws Exception {
parse("[CH2X4][CHX4]([CH3X4])[CH3X4]");
}
public void testPattern49() throws Exception {
parse("[CH2X4][CH2X4][CH2X4][CH2X4][NX4+,NX3+0]");
}
public void testPattern50() throws Exception {
parse("[CH2X4][CH2X4][SX2][CH3X4]");
}
public void testPattern51() throws Exception {
parse("[CH2X4][cX3]1[cX3H][cX3H][cX3H][cX3H][cX3H]1");
}
public void testPattern52() throws Exception {
parse("[$([NX3H,NX4H2+]),$([NX3](C)(C)(C))]1[CX4H]([CH2][CH2][CH2]1)[CX3](=[OX1])[OX2H,OX1-,N]");
}
public void testPattern53() throws Exception {
parse("[CH2X4][OX2H]");
}
public void testPattern54() throws Exception {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -