Skip to content

Commit

Permalink
The IFingerprinter API can be made backwards compatible with CDK 1.4.…
Browse files Browse the repository at this point in the history
…x by re-adding and delegating the old method.
  • Loading branch information
johnmay committed Mar 29, 2017
1 parent fd684bd commit 19a7e15
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 23 deletions.
Expand Up @@ -23,6 +23,7 @@
*/
package org.openscience.cdk.fingerprint;

import java.util.BitSet;
import java.util.Map;

import org.openscience.cdk.exception.CDKException;
Expand All @@ -38,6 +39,17 @@
*/
public interface IFingerprinter {

/**
* Generate a binary fingerprint as a bit. This method will usually delegate to
* {@link #getBitFingerprint(IAtomContainer)} and invoke
* {@link IBitFingerprint#asBitSet()}, it is included for backwards compatibility.
*
* @param mol molecule
* @return BitSet
* @throws CDKException problem generating fingerprint
*/
BitSet getFingerprint(IAtomContainer mol) throws CDKException;

/**
* Returns the bit fingerprint for the given {@link IAtomContainer}.
*
Expand All @@ -47,7 +59,7 @@ public interface IFingerprinter {
* or (for key based fingerprints) if there is a SMARTS parsing error
* @throws UnsupportedOperationException if the Fingerprinter can not produce bit fingerprints
*/
public IBitFingerprint getBitFingerprint(IAtomContainer container) throws CDKException;
IBitFingerprint getBitFingerprint(IAtomContainer container) throws CDKException;

/**
* Returns the count fingerprint for the given {@link IAtomContainer}.
Expand All @@ -58,7 +70,7 @@ public interface IFingerprinter {
* or (for key based fingerprints) if there is a SMARTS parsing error.
* @throws UnsupportedOperationException if the Fingerprinter can not produce count fingerprints
*/
public ICountFingerprint getCountFingerprint(IAtomContainer container) throws CDKException;
ICountFingerprint getCountFingerprint(IAtomContainer container) throws CDKException;

/**
* Returns the raw representation of the fingerprint for the given IAtomContainer. The raw representation contains
Expand All @@ -68,13 +80,12 @@ public interface IFingerprinter {
* @return the raw fingerprint
* @throws CDKException
*/
public Map<String, Integer> getRawFingerprint(IAtomContainer container) throws CDKException;
Map<String, Integer> getRawFingerprint(IAtomContainer container) throws CDKException;

/**
* Returns the size of the fingerprints calculated.
* Returns the size (or length) of the fingerprint.
*
* @return the size of the fingerprint
*/
public int getSize();

int getSize();
}
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2017 John May <jwmay@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. 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 USA
*/

package org.openscience.cdk.fingerprint;

import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;

import java.util.BitSet;

public abstract class AbstractFingerprinter implements IFingerprinter {

/** {@inheritDoc} */
@Override
public BitSet getFingerprint(IAtomContainer mol) throws CDKException {
return getBitFingerprint(mol).asBitSet();
}
}
Expand Up @@ -90,7 +90,7 @@
* @cdk.module standard
* @cdk.githash
*/
public class Fingerprinter implements IFingerprinter {
public class Fingerprinter extends AbstractFingerprinter implements IFingerprinter {

/** Throw an exception if too many paths (per atom) are generated. */
private final static int DEFAULT_PATH_LIMIT = 1500;
Expand Down Expand Up @@ -163,7 +163,6 @@ public Fingerprinter(int size, int searchDepth) {
* perception
* @return A {@link BitSet} representing the fingerprint
*/

public IBitFingerprint getBitFingerprint(IAtomContainer container, AllRingsFinder ringFinder) throws CDKException {
int position = -1;
logger.debug("Entering Fingerprinter");
Expand Down
Expand Up @@ -73,7 +73,7 @@
* @cdk.module standard
* @cdk.githash
*/
public class HybridizationFingerprinter implements IFingerprinter {
public class HybridizationFingerprinter extends AbstractFingerprinter implements IFingerprinter {

/** The default length of created fingerprints. */
public final static int DEFAULT_SIZE = 1024;
Expand Down
Expand Up @@ -90,7 +90,7 @@
* @cdk.module standard
* @cdk.githash
*/
public class CircularFingerprinter implements IFingerprinter {
public class CircularFingerprinter extends AbstractFingerprinter implements IFingerprinter {

// ------------ constants ------------

Expand Down
Expand Up @@ -60,7 +60,7 @@
* @cdk.module fingerprint
* @cdk.githash
*/
public class EStateFingerprinter implements IFingerprinter {
public class EStateFingerprinter extends AbstractFingerprinter implements IFingerprinter {

private static final String[] PATTERNS = EStateFragments.getSmarts();

Expand Down
Expand Up @@ -22,14 +22,6 @@
*/
package org.openscience.cdk.fingerprint;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Map;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.graph.ConnectedComponents;
Expand All @@ -46,6 +38,14 @@
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Map;

/**
* This fingerprinter generates 166 bit MACCS keys.
*
Expand Down Expand Up @@ -73,7 +73,7 @@
* @cdk.module fingerprint
* @cdk.githash
*/
public class MACCSFingerprinter implements IFingerprinter {
public class MACCSFingerprinter extends AbstractFingerprinter implements IFingerprinter {

private static ILoggingTool logger = LoggingToolFactory.createLoggingTool(MACCSFingerprinter.class);

Expand Down
Expand Up @@ -84,7 +84,7 @@
* @cdk.githash
* @cdk.threadnonsafe
*/
public class PubchemFingerprinter implements IFingerprinter {
public class PubchemFingerprinter extends AbstractFingerprinter implements IFingerprinter {

/**
* Number of bits in this fingerprint.
Expand Down
Expand Up @@ -37,7 +37,7 @@
* @cdk.keyword fingerprint
* @cdk.githash
*/
public class SignatureFingerprinter implements IFingerprinter {
public class SignatureFingerprinter extends AbstractFingerprinter implements IFingerprinter {

private int signatureDepth;

Expand Down
Expand Up @@ -49,7 +49,7 @@
* @cdk.keyword hologram
* @cdk.githash
*/
public class LingoFingerprinter implements IFingerprinter {
public class LingoFingerprinter extends AbstractFingerprinter implements IFingerprinter {

private final int n;
private final SmilesGenerator gen = SmilesGenerator.unique().aromatic();
Expand Down

0 comments on commit 19a7e15

Please sign in to comment.