Skip to content

Commit

Permalink
Merge pull request #289 from cdk/patch/fingerprint-api
Browse files Browse the repository at this point in the history
OK, not sure how to rerun TravisCI on this branch, but I'll assume the tests will run fine again on this patch too.
  • Loading branch information
egonw committed Apr 2, 2017
2 parents 407ded9 + fe745dc commit 98725a4
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 21 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 @@ -46,7 +46,7 @@
*
* @see org.openscience.cdk.fingerprint.Fingerprinter
*/
public class ExtendedFingerprinter implements IFingerprinter {
public class ExtendedFingerprinter extends Fingerprinter implements IFingerprinter {

private final int RESERVED_BITS = 25;

Expand Down
Expand Up @@ -28,11 +28,9 @@
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.isomorphism.Pattern;
import org.openscience.cdk.isomorphism.VentoFoggia;
import org.openscience.cdk.isomorphism.matchers.smarts.SmartsMatchers;
import org.openscience.cdk.ringsearch.AllRingsFinder;
import org.openscience.cdk.smiles.smarts.parser.SMARTSParser;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
Expand Down Expand Up @@ -72,7 +70,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 @@ -80,7 +80,7 @@
* @cdk.githash
*
*/
public class ShortestPathFingerprinter extends RandomNumber implements IFingerprinter, Serializable {
public class ShortestPathFingerprinter extends AbstractFingerprinter implements IFingerprinter, Serializable {

/**
* The default length of created fingerprints.
Expand All @@ -94,6 +94,8 @@ public class ShortestPathFingerprinter extends RandomNumber implements IFingerpr
private static ILoggingTool logger = LoggingToolFactory
.createLoggingTool(ShortestPathFingerprinter.class);

private final RandomNumber rand = new RandomNumber();

/**
* Creates a fingerprint generator of length
* <code>DEFAULT_SIZE</code>
Expand Down Expand Up @@ -264,6 +266,6 @@ public ICountFingerprint getCountFingerprint(IAtomContainer iac) throws CDKExcep
* Returns a random number for a given object
*/
private int getRandomNumber(Integer hashValue) {
return generateMersenneTwisterRandomNumber(fingerprintLength, hashValue);
return rand.generateMersenneTwisterRandomNumber(fingerprintLength, hashValue);
}
}
Expand Up @@ -364,7 +364,7 @@
* @cdk.module fingerprint
* @cdk.githash
*/
public class SubstructureFingerprinter implements IFingerprinter {
public class SubstructureFingerprinter extends AbstractFingerprinter implements IFingerprinter {

private String[] smarts;

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 98725a4

Please sign in to comment.