From 2d7c62850277466eb275a4494cf6cc84cf882a6b Mon Sep 17 00:00:00 2001 From: John May Date: Thu, 24 Oct 2013 13:51:41 +0100 Subject: [PATCH] Adapting and cleaning up several SMARTS query matchers to use the new invariants. The query value is now stored in the class and not on the query atom - this mirrors how other matchers work and generally makes things cleaner. Access to the values was not used (or currently useful). Serialization was removed - the class did not implement the interface and it looks like the UID was just added by default. Serialization was removed rather than fixed as it is rarely useful and there are much better techniques. Several unused classes were removed - these fullfilled the same functionality as others and it was confusing to have two for the same purpose. The RingAtom/SmallestRingAtom can now be done by using different invariants. The DegreeAtom was incorrect, matching charge, and the ExplicitConnectionAtom fulfilled it's use case. Signed-off-by: Egon Willighagen --- .../matchers/smarts/ConnectionCountAtom.java | 79 --------------- .../matchers/smarts/DegreeAtom.java | 62 ------------ .../smarts/ExplicitConnectionAtom.java | 79 +++++---------- .../isomorphism/matchers/smarts/RingAtom.java | 84 ---------------- .../matchers/smarts/RingMembershipAtom.java | 54 +++++----- .../matchers/smarts/SmallestRingAtom.java | 94 +++++++++--------- .../matchers/smarts/TotalConnectionAtom.java | 58 +++++------ .../matchers/smarts/TotalHCountAtom.java | 61 ++++++------ .../smarts/TotalRingConnectionAtom.java | 77 ++++++--------- .../matchers/smarts/TotalValencyAtom.java | 53 +++++----- .../smarts/ExplicitConnectionAtomTest.java | 55 +++++++++++ .../smarts/RingMembershipAtomTest.java | 98 +++++++++++++++++++ .../matchers/smarts/SmallestRingAtomTest.java | 54 ++++++++++ .../smarts/TotalConnectionAtomTest.java | 55 +++++++++++ .../matchers/smarts/TotalHCountAtomTest.java | 40 ++++++++ .../smarts/TotalRingConnectionAtomTest.java | 56 +++++++++++ .../matchers/smarts/TotalValencyAtomTest.java | 56 +++++++++++ 17 files changed, 622 insertions(+), 493 deletions(-) delete mode 100644 src/main/org/openscience/cdk/isomorphism/matchers/smarts/ConnectionCountAtom.java delete mode 100644 src/main/org/openscience/cdk/isomorphism/matchers/smarts/DegreeAtom.java delete mode 100644 src/main/org/openscience/cdk/isomorphism/matchers/smarts/RingAtom.java create mode 100644 src/test/org/openscience/cdk/isomorphism/matchers/smarts/ExplicitConnectionAtomTest.java create mode 100644 src/test/org/openscience/cdk/isomorphism/matchers/smarts/RingMembershipAtomTest.java create mode 100644 src/test/org/openscience/cdk/isomorphism/matchers/smarts/SmallestRingAtomTest.java create mode 100644 src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalConnectionAtomTest.java create mode 100644 src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalHCountAtomTest.java create mode 100644 src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalRingConnectionAtomTest.java create mode 100644 src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalValencyAtomTest.java diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/ConnectionCountAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/ConnectionCountAtom.java deleted file mode 100644 index 585c27e011a..00000000000 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/ConnectionCountAtom.java +++ /dev/null @@ -1,79 +0,0 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2004-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. - * - * 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.isomorphism.matchers.smarts; - -import org.openscience.cdk.interfaces.IAtom; -import org.openscience.cdk.interfaces.IChemObjectBuilder; - -/** - * This matcher checks the total valency of the Atom. - * This cannot be matched with a unpreprocessed Atom! - * - * @cdk.module smarts - * @cdk.githash - * @cdk.keyword SMARTS - */ -public class ConnectionCountAtom extends SMARTSAtom { - - private static final long serialVersionUID = 8787570498467055257L; - - final static String CC_PROP = "org.openscience.cdk.Atom.connectionCount"; - - /** - * Creates a new instance - * - * @param count - */ - public ConnectionCountAtom(int count, IChemObjectBuilder builder) { - super(builder); - this.setProperty(CC_PROP, count); - } - - /** - * Returns the connection count of an atom. - */ - public int getCC(IAtom atom){ - return ((Integer)atom.getProperty(CC_PROP)).intValue(); - } - - /* (non-Javadoc) - * @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom) - */ - public boolean matches(IAtom atom) { - return (getCC(atom)!=0 && getCC(atom)==getCC(this)); - } - - /* (non-Javadoc) - * @see org.openscience.cdk.PseudoAtom#toString() - */ - public String toString() { - StringBuffer s = new StringBuffer(); - s.append("ConnectionCountAtom("); - s.append(this.hashCode() + ", "); - s.append("CC:" + getCC(this)); - s.append(")"); - return s.toString(); - } -} - diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/DegreeAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/DegreeAtom.java deleted file mode 100644 index 6bf1a073413..00000000000 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/DegreeAtom.java +++ /dev/null @@ -1,62 +0,0 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2004-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. - * - * 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.isomorphism.matchers.smarts; - -import org.openscience.cdk.interfaces.IAtom; -import org.openscience.cdk.interfaces.IChemObjectBuilder; - -/** - * This matcher checks the number of connections of the checked Atom - * with other Atom's. This cannot be matched with a unpreprocessed Atom! - * - * @cdk.module smarts - * @cdk.githash - * @cdk.keyword SMARTS - */ -public class DegreeAtom extends SMARTSAtom { - - private static final long serialVersionUID = 2623272739045200480L; - - public DegreeAtom(int charge, IChemObjectBuilder builder) { - super(builder); - setFormalCharge(charge); - } - - /* (non-Javadoc) - * @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom) - */ - public boolean matches(IAtom atom) { - return atom.getFormalCharge() == this.getFormalCharge(); - } - - public String toString() { - StringBuffer s = new StringBuffer(); - s.append("DegreeAtom("); - s.append(this.hashCode() + ", "); - s.append("D:" + getFormalCharge()); - s.append(")"); - return s.toString(); - } -} - diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/ExplicitConnectionAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/ExplicitConnectionAtom.java index beda7e697c0..4c94c6f804e 100644 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/ExplicitConnectionAtom.java +++ b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/ExplicitConnectionAtom.java @@ -1,7 +1,7 @@ -/* $Revision$ $Author$ $Date$ - * - * Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project - * +/* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project + * 2013 European Bioinformatics Institute + * John May + * * This library 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 @@ -19,64 +19,37 @@ */ package org.openscience.cdk.isomorphism.matchers.smarts; -import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IChemObjectBuilder; /** - * This smarts atom matches any atom with a certain number of explicit - * connections. + * Match an atom with the defined degree. The degree is also referred to as the + * explicit connectivity and is encoded in smarts using {@code D}. * - * @cdk.module smarts - * @cdk.githash - * @cdk.keyword SMARTS + * @cdk.module smarts + * @cdk.keyword SMARTS */ -public class ExplicitConnectionAtom extends SMARTSAtom { - private static final long serialVersionUID = 7453671653627040279L; +@TestClass("org.openscience.cdk.isomorphism.matchers.smarts.ExplicitConnectionAtomTest") +public final class ExplicitConnectionAtom extends SMARTSAtom { - /** - * Number of explicit connections. - */ - private int numOfConnection; + /** Number of explicit connections. */ + private int degree; - /** - * Creates a new instance. - */ - public ExplicitConnectionAtom(IChemObjectBuilder builder) { - super(builder); - } - - /** - * Creates a new instance. - */ - public ExplicitConnectionAtom(int connection, IChemObjectBuilder builder) { - super(builder); - this.numOfConnection = connection; - } + /** + * Create a query atom for matching the degree of an atom. The degree is the + * number connected atoms. + */ + public ExplicitConnectionAtom(int degree, IChemObjectBuilder builder) { + super(builder); + this.degree = degree; + } - /* (non-Javadoc) - * @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom) - */ + /** @inheritDoc */ + @Override + @TestMethod("matches") public boolean matches(IAtom atom) { - int conn = (Integer) atom.getProperty(CDKConstants.TOTAL_CONNECTIONS) - - (Integer) atom.getProperty(CDKConstants.TOTAL_H_COUNT); - - return numOfConnection == conn; + return invariants(atom).degree() == degree; } - - /** - * Returns number of explicit connections. - */ - public int getNumOfConnection() { - return numOfConnection; - } - - /** - * Sets number of explicit connections. - * - * @param numOfConnection - */ - public void setNumOfConnection(int numOfConnection) { - this.numOfConnection = numOfConnection; - } } diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/RingAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/RingAtom.java deleted file mode 100644 index 66dc40f3904..00000000000 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/RingAtom.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2002-2006 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 I ask is that proper credit is given for my 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.isomorphism.matchers.smarts; - -import org.openscience.cdk.CDKConstants; -import org.openscience.cdk.interfaces.IAtom; -import org.openscience.cdk.interfaces.IChemObjectBuilder; - -import java.util.ArrayList; - -/** - * This matches an atom in a specific size ring. - * - * @cdk.module smarts - * @cdk.githash - * @cdk.keyword SMARTS - */ -public class RingAtom extends SMARTSAtom { - - private static final long serialVersionUID = -5145049891214205622L; - - private int ringSize; - - /** - * Creates a new instance - * - * @param ringSize - */ - public RingAtom(int ringSize, IChemObjectBuilder builder) { - super(builder); - this.ringSize = ringSize; - } - - /* (non-Javadoc) - * @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom) - */ - public boolean matches(IAtom atom) { - if (atom.getFlag(CDKConstants.ISINRING)) { - ArrayList ll = (ArrayList) atom - .getProperty(CDKConstants.RING_SIZES); - for (int i = 0; i < ll.size(); i++) { - if (((Integer) ll.get(i)).intValue() == ringSize) { - return true; - } - } - } - return false; - } - - /* (non-Javadoc) - * @see org.openscience.cdk.PseudoAtom#toString() - */ - public String toString() { - return ("RingAtom(" + ringSize + ")"); - } -} diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/RingMembershipAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/RingMembershipAtom.java index 78c5dedc2ea..fbd666ea7b8 100644 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/RingMembershipAtom.java +++ b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/RingMembershipAtom.java @@ -1,6 +1,4 @@ -/* $Revision$ $Author$ $Date$ - * - * Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project +/* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,23 +17,29 @@ */ package org.openscience.cdk.isomorphism.matchers.smarts; -import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IChemObjectBuilder; -import org.openscience.cdk.interfaces.IRingSet; /** - * This query atom matches any atom with a certain number of SSSR. + * This query is found in a specified number of ring. The ring membership is + * specified with the SMARTS {@code R}. The membership depends on the + * ring set used and as such is not a portable term. If the Smallest Set of + * Smallest Rings (SSSR) is used then changing the order of atoms + * may change which atoms match in a pattern. * - * @cdk.module smarts - * @cdk.githash - * @cdk.keyword SMARTS + * @cdk.module smarts + * @cdk.keyword SMARTS */ +@TestClass("org.openscience.cdk.isomorphism.matchers.smarts.RingMembershipAtomTest") public class RingMembershipAtom extends SMARTSAtom { - private static final long serialVersionUID = -7963168231557641862L; - /** Number of rings to which this atom belongs, if < 0 check any ring membership. */ - private int numSSSR; + /** + * Number of rings to which this atom belongs, if < 0 check any ring + * membership. + */ + private int ringNumber; /** * Ring membership query atom. Check if the an atom belongs to num of @@ -46,22 +50,16 @@ public class RingMembershipAtom extends SMARTSAtom { * * @param num number of rings which this atom belongs to, < 0 any ring. */ - public RingMembershipAtom(int num, IChemObjectBuilder builder) { + public RingMembershipAtom(int num, IChemObjectBuilder builder) { super(builder); - this.numSSSR = num; - } + this.ringNumber = num; + } - /* (non-Javadoc) - * @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom) - */ - public boolean matches(IAtom atom) { - if (atom.getFlag(CDKConstants.ISINRING)) { - IRingSet ringSet = (IRingSet)atom.getProperty(CDKConstants.SMALLEST_RINGS); - // < 0 means any ring, as you can see below R0 is valid - return numSSSR < 0 || ringSet.getAtomContainerCount() == numSSSR; - } else { - if (numSSSR == 0) return true; - } - return false; - } + /** @inheritDoc */ + @Override + @TestMethod("matches") + public boolean matches(IAtom atom) { + return ringNumber < 0 ? invariants(atom).ringNumber() > 0 + : ringNumber == invariants(atom).ringNumber(); + } } diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/SmallestRingAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/SmallestRingAtom.java index cd99281dcc8..70ce7c20d53 100644 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/SmallestRingAtom.java +++ b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/SmallestRingAtom.java @@ -1,63 +1,65 @@ -/* $Revision$ $Author$ $Date$ +/* Copyright (C) 2002-2006 The Chemistry Development Kit (CDK) project * - * Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project + * Contact: cdk-devel@lists.sourceforge.net * - * This library 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 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 I ask is that proper credit is given for my 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 library 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. + * 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. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * (or see http://www.gnu.org/copyleft/lesser.html) */ -package org.openscience.cdk.isomorphism.matchers.smarts; -import java.util.Collections; -import java.util.List; +package org.openscience.cdk.isomorphism.matchers.smarts; -import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IChemObjectBuilder; /** - * This smarts atom matches any atom with the smallest SSSR size being a - * certain value. + * Match an atom in a specific size ring. The ring size is specified by {@code + * r} in a SMARTS pattern. This term is non-portable, depending on the + * set of rings chosen and which ring sizes are used. The default implementation + * (Daylight) only stores the smallest ring each atom belongs to whilst other + * implementations may store multiple values. A more portable term is the + * ring connectivity which is specified as {@code x}. * - * @cdk.module smarts - * @cdk.githash - * @cdk.keyword SMARTS + * @cdk.module smarts + * @cdk.keyword SMARTS */ -public class SmallestRingAtom extends SMARTSAtom { - private static final long serialVersionUID = 8201040824866400163L; - /** - * The size of the smallest SSSR - */ - private int smallestRingSize; +@TestClass("org.openscience.cdk.isomorphism.matchers.smarts.SmallestRingAtomTest") +public final class SmallestRingAtom extends SMARTSAtom { + + /** Ring size to check. */ + private int ringSize; - public SmallestRingAtom(int size, IChemObjectBuilder builder) { + /** + * Creates a matcher for specified ring size. + * + * @param ringSize size of the ring to check. + */ + public SmallestRingAtom(int ringSize, IChemObjectBuilder builder) { super(builder); - this.smallestRingSize = size; - } + this.ringSize = ringSize; + } - public boolean matches(IAtom atom) { - if (atom.getFlag(CDKConstants.ISINRING)) { - List rings = (List) atom - .getProperty(CDKConstants.RING_SIZES); - if (rings == null || rings.size() == 0) { - return false; - } - Collections.sort(rings); - if ((rings.get(0)).intValue() == smallestRingSize) { - return true; - } - } - return false; - } + /** @inheritDoc */ + @Override + @TestMethod("matches") + public boolean matches(IAtom atom) { + return invariants(atom).ringSize().contains(ringSize); + } } diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalConnectionAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalConnectionAtom.java index 9278a8945d3..ebceed38e55 100644 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalConnectionAtom.java +++ b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalConnectionAtom.java @@ -1,10 +1,4 @@ -/* - * $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2002-2006 The Chemistry Development Kit (CDK) project +/* Copyright (C) 2002-2006 The Chemistry Development Kit (CDK) project * * Contact: cdk-devel@lists.sourceforge.net * @@ -30,42 +24,36 @@ package org.openscience.cdk.isomorphism.matchers.smarts; -import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IChemObjectBuilder; /** - * This matches an atom using total number of connections. - * - * @cdk.module smarts + * This matches an atom using total number of connections - referred to in + * SMARTS as the connectivity. The connectivity is specified using the {@code + * X} pattern. + * + * @cdk.module smarts * @cdk.githash * @cdk.keyword SMARTS */ -public class TotalConnectionAtom extends SMARTSAtom { - private static final long serialVersionUID = 2714616726873309671L; +@TestClass("org.openscience.cdk.isomorphism.matchers.smarts.ExplicitConnectionAtomTest") +public final class TotalConnectionAtom extends SMARTSAtom { + + /** Total number of connections from an atom including H count. */ + private final int connectivity; - /** - * Creates a new instance. - */ - public TotalConnectionAtom(int count, IChemObjectBuilder builder) { + /** Creates a new instance. */ + public TotalConnectionAtom(int connectivity, IChemObjectBuilder builder) { super(builder); - this.setProperty(CDKConstants.TOTAL_CONNECTIONS, count); - } - - /** - * This returns the total connection of an atom. - */ - public int getTC(IAtom atom) { - if (atom.getProperty(CDKConstants.TOTAL_CONNECTIONS) != null) - return (Integer) atom.getProperty(CDKConstants.TOTAL_CONNECTIONS); - else - return 0; - } + this.connectivity = connectivity; + } - /* (non-Javadoc) - * @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom) - */ - public boolean matches(IAtom atom) { - return (getTC(atom) != 0 && getTC(atom) == getTC(this)); - } + /** @inheritDoc */ + @Override + @TestMethod("matches") + public boolean matches(IAtom atom) { + return invariants(atom).connectivity() == connectivity; + } } diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalHCountAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalHCountAtom.java index 629ae92067d..fdbc6767d97 100644 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalHCountAtom.java +++ b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalHCountAtom.java @@ -1,9 +1,6 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project +/* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project + * 2013 European Bioinformatics Institute + * John May * * Contact: cdk-devel@lists.sourceforge.net * @@ -23,42 +20,44 @@ */ package org.openscience.cdk.isomorphism.matchers.smarts; -import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.annotations.TestMethod; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IChemObjectBuilder; /** - * This matcher checks the formal charge of the Atom. This cannot be matched - * with a unpreprocessed Atom! + * SMARTS query atom for matching the total hydrogen count. This count is + * specified in SMARTS using {@code H}. * * @cdk.module smarts - * @cdk.githash * @cdk.keyword SMARTS */ -public class TotalHCountAtom extends SMARTSAtom { +public final class TotalHCountAtom extends SMARTSAtom { - private static final long serialVersionUID = -3532280322660394553L; + /** The total hydrogen count to match. */ + private final int totalHCount; - public TotalHCountAtom(int hCount, IChemObjectBuilder builder) { + public TotalHCountAtom(int totalHCount, IChemObjectBuilder builder) { super(builder); - setProperty(CDKConstants.TOTAL_H_COUNT, hCount); - } - - public int getHC(IAtom atom) { - return (Integer)atom.getProperty(CDKConstants.TOTAL_H_COUNT); - } + this.totalHCount = totalHCount; + } - public boolean matches(IAtom atom) { - return getHC(atom) == getHC(this); - } - + /** + * Check if the total hydrogen count of the {@code atom} is equal to the + * query. + * + * @param atom the atom to match + * @return the hydrogen count matches + */ + @Override + @TestMethod("matches") + public boolean matches(final IAtom atom) { + return invariants(atom).totalHydrogenCount() == totalHCount; + } - public String toString() { - StringBuffer s = new StringBuffer(); - s.append("TotalHCountAtom("); - s.append(this.hashCode() + ", "); - s.append("HC:" + getHC(this)); - s.append(")"); - return s.toString(); - } + /** @inheritDoc */ + @Override + @TestMethod("testToString") + public String toString() { + return "H" + totalHCount; + } } diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalRingConnectionAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalRingConnectionAtom.java index 4a3d9775e2e..a49671e4296 100644 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalRingConnectionAtom.java +++ b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalRingConnectionAtom.java @@ -1,10 +1,4 @@ -/* - * $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2002-2006 The Chemistry Development Kit (CDK) project +/* Copyright (C) 2002-2006 The Chemistry Development Kit (CDK) project * * Contact: cdk-devel@lists.sourceforge.net * @@ -29,56 +23,41 @@ */ package org.openscience.cdk.isomorphism.matchers.smarts; -import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IChemObjectBuilder; /** * This matcher checks the number of ring connections of the checked Atom with - * other Atom's. This cannot be matched with a unpreprocessed Atom! - * - * @cdk.module smarts + * other Atom's. This cannot be matched without prepossessing Atom - {@link + * SMARTSAtomInvariants}. The ring connectivity is encoded in smarts using + * {@code x}. + * + * @cdk.module smarts * @cdk.githash - * @cdk.keyword SMARTS + * @cdk.keyword SMARTS */ +@TestClass("org.openscience.cdk.isomorphism.matchers.smarts.TotalRingConnectionAtomTest") +public final class TotalRingConnectionAtom extends SMARTSAtom { -public class TotalRingConnectionAtom extends SMARTSAtom { - /** - * Creates a new instance - * - * @param ringConn number of ring connections - */ - public TotalRingConnectionAtom(int ringConn, IChemObjectBuilder builder) { - super(builder); - this.setProperty(CDKConstants.RING_CONNECTIONS, ringConn); - } - - /** - * Returns the ring connection of an atom - * - * @param atom - * @return - */ - private int getRC(IAtom atom) { - if (atom.getFlag(CDKConstants.ISINRING)) - return ((Integer) atom.getProperty(CDKConstants.RING_CONNECTIONS)) - .intValue(); - else - return 0; - } + /** Number of rings. */ + private final int ringConnectivity; - /* (non-Javadoc) - * @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom) - */ - public boolean matches(IAtom atom) { - return getRC(atom) != 0 && getRC(atom) == getRC(this); - } - - /* (non-Javadoc) - * @see org.openscience.cdk.PseudoAtom#toString() - */ - public String toString() { - return ("TotalRingConnectionAtom(" + getRC(this) + ")"); - } + /** + * Create a matcher for the number of rings an atom belongs to. + * + * @param ringConnectivity number of ring bonds this atom is adjacent to + */ + public TotalRingConnectionAtom(int ringConnectivity, IChemObjectBuilder builder) { + super(builder); + this.ringConnectivity = ringConnectivity; + } + /** @inheritDoc */ + @Override + @TestMethod("matches") + public boolean matches(IAtom atom) { + return invariants(atom).ringConnectivity() == ringConnectivity; + } } diff --git a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalValencyAtom.java b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalValencyAtom.java index b92c1b53753..da98fa5be6f 100644 --- a/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalValencyAtom.java +++ b/src/main/org/openscience/cdk/isomorphism/matchers/smarts/TotalValencyAtom.java @@ -1,9 +1,4 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project +/* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project * * Contact: cdk-devel@lists.sourceforge.net * @@ -23,37 +18,43 @@ */ package org.openscience.cdk.isomorphism.matchers.smarts; +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IChemObjectBuilder; /** - * This matcher checks the total valency of the Atom. - * This cannot be matched with a unpreprocessed Atom! - * + * This matcher checks the valence of the Atom. The valence is the number of + * bonds formed by an atom (including bonds to implicit hydrogens). + * * @cdk.module smarts - * @cdk.githash * @cdk.keyword SMARTS */ -public class TotalValencyAtom extends SMARTSAtom { +@TestClass("org.openscience.cdk.isomorphism.matchers.smarts.TotalValencyAtom") +public final class TotalValencyAtom extends SMARTSAtom { - private static final long serialVersionUID = -8067867220731999668L; - - public TotalValencyAtom(int valency, IChemObjectBuilder builder) { + /** + * The valence to match. + */ + private final int valence; + + /** + * Match the valence of atom. + * @param valence valence value + * @param builder chem object builder (required for ChemObject.getBuilder) + */ + public TotalValencyAtom(int valence, IChemObjectBuilder builder) { super(builder); - setValency(valency); - } - - public boolean matches(IAtom atom) { - return (atom.getValency()!=0 && atom.getValency() == this.getValency()); + this.valence = valence; } - public String toString() { - StringBuffer s = new StringBuffer(); - s.append("TotalValency("); - s.append(this.hashCode() + ", "); - s.append("V:" + getValency()); - s.append(")"); - return s.toString(); + /** + * @inheritDoc + */ + @Override + @TestMethod("matches") + public boolean matches(IAtom atom) { + return invariants(atom).valence() == valence; } } diff --git a/src/test/org/openscience/cdk/isomorphism/matchers/smarts/ExplicitConnectionAtomTest.java b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/ExplicitConnectionAtomTest.java new file mode 100644 index 00000000000..27205ff93af --- /dev/null +++ b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/ExplicitConnectionAtomTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) + * John May + * + * 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 U + */ + +package org.openscience.cdk.isomorphism.matchers.smarts; + +import org.junit.Test; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +import java.util.Collections; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author John May + * @cdk.module test-smarts + */ +public class ExplicitConnectionAtomTest { + @Test + public void matches() throws Exception { + ExplicitConnectionAtom matcher = new ExplicitConnectionAtom(2, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 0, + Collections.emptySet(), + 0, + 2, + 0, + 0)); + assertTrue(matcher.matches(atom)); + } +} diff --git a/src/test/org/openscience/cdk/isomorphism/matchers/smarts/RingMembershipAtomTest.java b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/RingMembershipAtomTest.java new file mode 100644 index 00000000000..0dd45f703fd --- /dev/null +++ b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/RingMembershipAtomTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) + * John May + * + * 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 U + */ + +package org.openscience.cdk.isomorphism.matchers.smarts; + +import org.junit.Test; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +import java.util.Collections; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +/** + * @author John May + * @cdk.module test-smarts + */ +public class RingMembershipAtomTest { + + @Test + public void matches() throws Exception { + RingMembershipAtom matcher = new RingMembershipAtom(2, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 2, + Collections.emptySet(), + 0, + 0, + 0, + 0)); + assertTrue(matcher.matches(atom)); + } + + @Test + public void mismatches() throws Exception { + RingMembershipAtom matcher = new RingMembershipAtom(2, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 1, + Collections.emptySet(), + 0, + 0, + 0, + 0)); + assertFalse(matcher.matches(atom)); + } + + @Test + public void none() throws Exception { + RingMembershipAtom matcher = new RingMembershipAtom(0, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 0, + Collections.emptySet(), + 0, + 0, + 0, + 0)); + assertTrue(matcher.matches(atom)); + } + + @Test + public void any() throws Exception { + RingMembershipAtom matcher = new RingMembershipAtom(-1, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 5, + Collections.emptySet(), + 0, + 0, + 0, + 0)); + assertTrue(matcher.matches(atom)); + } +} diff --git a/src/test/org/openscience/cdk/isomorphism/matchers/smarts/SmallestRingAtomTest.java b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/SmallestRingAtomTest.java new file mode 100644 index 00000000000..b5349d51eb1 --- /dev/null +++ b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/SmallestRingAtomTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) + * John May + * + * 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 U + */ + +package org.openscience.cdk.isomorphism.matchers.smarts; + +import org.junit.Test; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +import java.util.Collections; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author John May + * @cdk.module test-smarts + */ +public class SmallestRingAtomTest { + @Test public void matches() { + SmallestRingAtom matcher = new SmallestRingAtom(5, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 0, + Collections.singleton(5), + 0, + 0, + 0, + 0)); + assertTrue(matcher.matches(atom)); + } +} diff --git a/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalConnectionAtomTest.java b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalConnectionAtomTest.java new file mode 100644 index 00000000000..a4c54170460 --- /dev/null +++ b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalConnectionAtomTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) + * John May + * + * 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 U + */ + +package org.openscience.cdk.isomorphism.matchers.smarts; + +import org.junit.Test; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +import java.util.Collections; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author John May + * @cdk.module test-smarts + */ +public class TotalConnectionAtomTest { + @Test + public void matches() throws Exception { + TotalConnectionAtom matcher = new TotalConnectionAtom(2, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 0, + Collections.emptySet(), + 0, + 2, + 0, + 0)); + assertTrue(matcher.matches(atom)); + } +} diff --git a/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalHCountAtomTest.java b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalHCountAtomTest.java new file mode 100644 index 00000000000..dbe02b9133a --- /dev/null +++ b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalHCountAtomTest.java @@ -0,0 +1,40 @@ +package org.openscience.cdk.isomorphism.matchers.smarts; + +import org.junit.Test; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +import java.util.Collections; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author John May + * @cdk.module test-smarts + */ +public class TotalHCountAtomTest { + + @Test + public void matches() throws Exception { + TotalHCountAtom matcher = new TotalHCountAtom(4, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 0, + Collections.emptySet(), + 0, + 0, + 0, + 4)); + assertTrue(matcher.matches(atom)); + } + + @Test + public void testToString() throws Exception { + TotalHCountAtom total = new TotalHCountAtom(4, mock(IChemObjectBuilder.class)); + assertThat(total.toString(), is("H4")); + } +} diff --git a/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalRingConnectionAtomTest.java b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalRingConnectionAtomTest.java new file mode 100644 index 00000000000..b4fbf3ab223 --- /dev/null +++ b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalRingConnectionAtomTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) + * John May + * + * 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 U + */ + +package org.openscience.cdk.isomorphism.matchers.smarts; + +import org.junit.Test; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +import java.util.Collections; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author John May + * @cdk.module test-smarts + */ +public class TotalRingConnectionAtomTest { + + @Test + public void matches() throws Exception { + TotalRingConnectionAtom matcher = new TotalRingConnectionAtom(2, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(0, + 0, + Collections.emptySet(), + 2, + 0, + 0, + 0)); + assertTrue(matcher.matches(atom)); + } +} diff --git a/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalValencyAtomTest.java b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalValencyAtomTest.java new file mode 100644 index 00000000000..1a996b76bc8 --- /dev/null +++ b/src/test/org/openscience/cdk/isomorphism/matchers/smarts/TotalValencyAtomTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) + * John May + * + * 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 U + */ + +package org.openscience.cdk.isomorphism.matchers.smarts; + +import org.junit.Test; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +import java.util.Collections; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author John May + * @cdk.module test-smarts + */ +public class TotalValencyAtomTest { + + @Test + public void matches() throws Exception { + TotalValencyAtom matcher = new TotalValencyAtom(4, mock(IChemObjectBuilder.class)); + IAtom atom = mock(IAtom.class); + when(atom.getProperty(SMARTSAtomInvariants.KEY)).thenReturn(new SMARTSAtomInvariants(4, + 0, + Collections.emptySet(), + 0, + 0, + 0, + 0)); + assertTrue(matcher.matches(atom)); + } +}