Skip to content

Commit

Permalink
Adapting and cleaning up several SMARTS query matchers to use the new…
Browse files Browse the repository at this point in the history
… 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 <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Dec 10, 2013
1 parent 7d321e4 commit 2d7c628
Show file tree
Hide file tree
Showing 17 changed files with 622 additions and 493 deletions.

This file was deleted.

This file was deleted.

@@ -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
Expand All @@ -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<NUMBER>}.
*
* @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;
}
}

This file was deleted.

0 comments on commit 2d7c628

Please sign in to comment.