Search in sources :

Example 1 with SymbolQueryAtom

use of org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom in project cdk by cdk.

the class SMARTSTest method testSMARTS.

@Test
public void testSMARTS() throws Exception {
    IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
    SmilesParser sp = new SmilesParser(builder);
    // acetic acid anhydride
    IAtomContainer atomContainer = sp.parseSmiles("CC(=O)OC(=O)C");
    QueryAtomContainer query = new QueryAtomContainer(builder);
    AnyAtom atom1 = new AnyAtom(builder);
    SymbolQueryAtom atom2 = new SymbolQueryAtom(builder);
    atom2.setSymbol("C");
    query.addAtom(atom1);
    query.addAtom(atom2);
    query.addBond(new OrderQueryBond(atom1, atom2, IBond.Order.DOUBLE, builder));
    Assert.assertTrue(uiTester.isSubgraph(atomContainer, query));
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.OrderQueryBond) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom) SymbolQueryAtom(org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom) Test(org.junit.Test)

Example 2 with SymbolQueryAtom

use of org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom in project cdk by cdk.

the class CDKMCSTest method testSFBug1708336.

/**
 * @cdk.bug 1708336
 * @throws Exception
 */
@Test
public void testSFBug1708336() throws Exception {
    IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
    IAtomContainer atomContainer = builder.newInstance(IAtomContainer.class);
    atomContainer.addAtom(builder.newInstance(IAtom.class, "C"));
    atomContainer.addAtom(builder.newInstance(IAtom.class, "C"));
    atomContainer.addAtom(builder.newInstance(IAtom.class, "N"));
    atomContainer.addBond(0, 1, IBond.Order.SINGLE);
    atomContainer.addBond(1, 2, IBond.Order.SINGLE);
    IQueryAtomContainer query = new QueryAtomContainer(DefaultChemObjectBuilder.getInstance());
    IQueryAtom a1 = new SymbolQueryAtom(DefaultChemObjectBuilder.getInstance());
    a1.setSymbol("C");
    AnyAtom a2 = new AnyAtom(DefaultChemObjectBuilder.getInstance());
    IBond b1 = new OrderQueryBond(a1, a2, IBond.Order.SINGLE, DefaultChemObjectBuilder.getInstance());
    IQueryAtom a3 = new SymbolQueryAtom(DefaultChemObjectBuilder.getInstance());
    a3.setSymbol("C");
    IBond b2 = new OrderQueryBond(a2, a3, IBond.Order.SINGLE, DefaultChemObjectBuilder.getInstance());
    query.addAtom(a1);
    query.addAtom(a2);
    query.addAtom(a3);
    query.addBond(b1);
    query.addBond(b2);
    List<List<CDKRMap>> list = CDKMCS.getSubgraphMaps(atomContainer, query, true);
    Assert.assertTrue(list.isEmpty());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) IBond(org.openscience.cdk.interfaces.IBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.OrderQueryBond) List(java.util.List) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) IAtom(org.openscience.cdk.interfaces.IAtom) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) SymbolQueryAtom(org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom) Test(org.junit.Test)

Example 3 with SymbolQueryAtom

use of org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom in project cdk by cdk.

the class SMARTSTest method testMatchInherited.

@Test
public void testMatchInherited() {
    try {
        IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
        SymbolQueryAtom c1 = new SymbolQueryAtom(new org.openscience.cdk.Atom("C"));
        SymbolAndChargeQueryAtom c2 = new SymbolAndChargeQueryAtom(new org.openscience.cdk.Atom("C"));
        IAtomContainer c = TestMoleculeFactory.makeAlkane(2);
        QueryAtomContainer query1 = new QueryAtomContainer(builder);
        query1.addAtom(c1);
        query1.addAtom(c2);
        query1.addBond(new OrderQueryBond(c1, c2, Order.SINGLE, builder));
        Assert.assertTrue(uiTester.isSubgraph(c, query1));
        QueryAtomContainer query = new QueryAtomContainer(builder);
        query.addAtom(c1);
        query.addAtom(c2);
        query.addBond(new AnyOrderQueryBond(c1, c2, Order.SINGLE, builder));
        Assert.assertTrue(uiTester.isSubgraph(c, query));
    } catch (CDKException exception) {
        Assert.fail(exception.getMessage());
    }
}
Also used : AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.OrderQueryBond) SymbolAndChargeQueryAtom(org.openscience.cdk.isomorphism.matchers.SymbolAndChargeQueryAtom) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) SymbolQueryAtom(org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom) Test(org.junit.Test)

Example 4 with SymbolQueryAtom

use of org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom in project cdk by cdk.

the class SMARTSTest method testStrictSMARTS.

@Test
public void testStrictSMARTS() throws Exception {
    IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
    SmilesParser sp = new SmilesParser(builder);
    // acetic acid anhydride
    IAtomContainer atomContainer = sp.parseSmiles("CC(=O)OC(=O)C");
    QueryAtomContainer query = new QueryAtomContainer(builder);
    SymbolQueryAtom atom1 = new SymbolQueryAtom(builder);
    atom1.setSymbol("N");
    SymbolQueryAtom atom2 = new SymbolQueryAtom(builder);
    atom2.setSymbol("C");
    query.addAtom(atom1);
    query.addAtom(atom2);
    query.addBond(new OrderQueryBond(atom1, atom2, IBond.Order.DOUBLE, builder));
    Assert.assertFalse(uiTester.isSubgraph(atomContainer, query));
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.OrderQueryBond) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) SymbolQueryAtom(org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)4 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)4 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.OrderQueryBond)4 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)4 SymbolQueryAtom (org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom)4 AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)3 AnyAtom (org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)2 SmilesParser (org.openscience.cdk.smiles.SmilesParser)2 List (java.util.List)1 CDKException (org.openscience.cdk.exception.CDKException)1 IAtom (org.openscience.cdk.interfaces.IAtom)1 IBond (org.openscience.cdk.interfaces.IBond)1 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)1 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)1 SymbolAndChargeQueryAtom (org.openscience.cdk.isomorphism.matchers.SymbolAndChargeQueryAtom)1