1 /* Copyright (C) 2004-2007  The Chemistry Development Kit (CDK) project
2  *               2013       European Bioinformatics Institute
3  *                          John May
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  * (or see http://www.gnu.org/copyleft/lesser.html)
19  */
20 package org.openscience.cdk.isomorphism.matchers.smarts;
21 
22 import org.openscience.cdk.interfaces.IAtom;
23 import org.openscience.cdk.interfaces.IChemObjectBuilder;
24 
25 /**
26  * Match an atom with the defined degree. The degree is also referred to as the
27  * explicit connectivity and is encoded in smarts using {@code D<NUMBER>}.
28  *
29  * @cdk.module smarts
30  * @cdk.keyword SMARTS
31  * @cdk.githash
32  */
33 @Deprecated
34 public final class ExplicitConnectionAtom extends SMARTSAtom {
35 
36     /** Number of explicit connections. */
37     private int degree;
38 
39     /**
40      * Create a query atom for matching the degree of an atom. The degree is the
41      * number connected atoms.
42      */
ExplicitConnectionAtom(int degree, IChemObjectBuilder builder)43     public ExplicitConnectionAtom(int degree, IChemObjectBuilder builder) {
44         super(builder);
45         this.degree = degree;
46     }
47 
48     /**{@inheritDoc} */
49     @Override
matches(IAtom atom)50     public boolean matches(IAtom atom) {
51         // XXX: this is incorrect but bug 824 expects this behaviour. The reason
52         //      Daylight matches is because the explicit hydrogens are
53         //      suppressed by default turning on explicit hydrogens in depict
54         //      match shows correct functionality. Discussion needed to revert
55         //      but because other invariants aren't adjusted (implicit h) we
56         //      can't really do this and the correct option is to enable/disable
57         //      hydrogen suppression (removal of explicit H atoms) as a prepossessing
58         //      step
59         return invariants(atom).connectivity() - invariants(atom).totalHydrogenCount() == degree;
60     }
61 }
62