Skip to content

Commit

Permalink
Made QueryChemObject require a IChemObject builder when being constru…
Browse files Browse the repository at this point in the history
…cted. This has a knock on effect that all the SMARTs atoms require the builder also. Although there are a lot of changes there's little front end API changes - the SMARTSQueryTool and PubChemFingerprinter now require a builder but other methods (e.g. descriptors and QueryAtomContainerCreator) could make use of the builder from other IChemObjects.

Change-Id: I64a6d7a3450ad1ad9b684d3679a11ace293e58fa
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Mar 18, 2013
1 parent bc9d9fc commit 9b736ad
Show file tree
Hide file tree
Showing 80 changed files with 471 additions and 309 deletions.
Expand Up @@ -76,7 +76,7 @@ public IBitFingerprint getBitFingerprint(IAtomContainer atomContainer)
int bitsetLength = PATTERNS.length;
BitSet fingerPrint = new BitSet(bitsetLength);

SMARTSQueryTool sqt = new SMARTSQueryTool("C");
SMARTSQueryTool sqt = new SMARTSQueryTool("C", atomContainer.getBuilder());
for (int i = 0; i < PATTERNS.length; i++) {
sqt.setSmarts(PATTERNS[i]);
boolean status = sqt.matches(atomContainer);
Expand Down
Expand Up @@ -97,7 +97,7 @@ public IBitFingerprint getBitFingerprint(IAtomContainer atomContainer)
int bitsetLength = keys.length;
BitSet fingerPrint = new BitSet(bitsetLength);

SMARTSQueryTool sqt = new SMARTSQueryTool("C");
SMARTSQueryTool sqt = new SMARTSQueryTool("C", atomContainer.getBuilder());
for (int i = 0; i < keys.length; i++) {
String smarts = keys[i].getSmarts();
if (smarts.equals("?")) continue;
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.ringsearch.SSSRFinder;
import org.openscience.cdk.smiles.smarts.SMARTSQueryTool;
Expand Down Expand Up @@ -94,8 +95,8 @@ public class PubchemFingerprinter implements IFingerprinter {
private byte[] m_bits;

private SMARTSQueryTool sqt;
public PubchemFingerprinter() {
sqt = new SMARTSQueryTool("C");
public PubchemFingerprinter(IChemObjectBuilder builder) {
sqt = new SMARTSQueryTool("C", builder);
m_bits = new byte[(FP_SIZE + 7) >> 3];
}

Expand Down Expand Up @@ -369,7 +370,9 @@ public static BitSet decode(String enc) {
"Input is not a proper PubChem base64 encoded fingerprint");
}

PubchemFingerprinter pc = new PubchemFingerprinter();
// note the IChemObjectBuilder is passed as null because the SMARTSQueryTool
// isn't needed when decoding
PubchemFingerprinter pc = new PubchemFingerprinter(null);
for (int i = 0; i < pc.m_bits.length; ++i) {
pc.m_bits[i] = fp[i + 4];
}
Expand Down
Expand Up @@ -409,7 +409,7 @@ public IBitFingerprint getBitFingerprint(IAtomContainer atomContainer)
int bitsetLength = smarts.length;
BitSet fingerPrint = new BitSet(bitsetLength);

SMARTSQueryTool sqt = new SMARTSQueryTool("C");
SMARTSQueryTool sqt = new SMARTSQueryTool("C", atomContainer.getBuilder());
for (int i = 0; i < smarts.length; i++) {
String pattern = smarts[i];

Expand Down
4 changes: 2 additions & 2 deletions src/main/org/openscience/cdk/io/MDLV2000Reader.java
Expand Up @@ -723,7 +723,7 @@ private IAtomContainer readAtomContainer(IAtomContainer molecule) throws CDKExce
}
else {
queryBondCount++;
newBond = new CTFileQueryBond();
newBond = new CTFileQueryBond(molecule.getBuilder());
IAtom[] bondAtoms = {a1,a2};
newBond.setAtoms(bondAtoms);
newBond.setOrder(null);
Expand All @@ -743,7 +743,7 @@ private IAtomContainer readAtomContainer(IAtomContainer molecule) throws CDKExce
if(queryBondCount==0)
outputContainer = molecule;
else {
outputContainer = new QueryAtomContainer();
outputContainer = new QueryAtomContainer(molecule.getBuilder());
}

outputContainer.setProperty(CDKConstants.TITLE, title);
Expand Down
Expand Up @@ -24,6 +24,8 @@

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObject;
import org.openscience.cdk.interfaces.IChemObjectBuilder;

/**
* Captures query bond types defined in the CTFile.
Expand Down Expand Up @@ -51,6 +53,9 @@ public enum Type {
ANY
}

public CTFileQueryBond(IChemObjectBuilder builder){
super(builder);
}
/**
* The type of this bond.
*/
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;

import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IChemObjectBuilder;

/**
* A QueryAtom that matches all symbols but those in this container. You may
Expand All @@ -45,7 +46,9 @@ public class InverseSymbolSetQueryAtom extends QueryAtom implements IQueryAtom {
/**
* Constructor for the InverseSymbolSetQueryAtom object
*/
public InverseSymbolSetQueryAtom() { }
public InverseSymbolSetQueryAtom(IChemObjectBuilder builder) {
super(builder);
}
public void setOperator(String str){}

/**
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObjectBuilder;

/**
* @cdk.module isomorphism
Expand All @@ -35,11 +36,12 @@ public class OrderQueryBond extends QueryBond implements IQueryBond {

private static final long serialVersionUID = 2292654937621883661L;

public OrderQueryBond() {
public OrderQueryBond(IChemObjectBuilder builder) {
super(builder);
}

public OrderQueryBond(IQueryAtom atom1, IQueryAtom atom2, IBond.Order order) {
super(atom1, atom2, order);
public OrderQueryBond(IQueryAtom atom1, IQueryAtom atom2, IBond.Order order, IChemObjectBuilder builder) {
super(atom1, atom2, order, builder);
}

public boolean matches(IBond bond) {
Expand Down
Expand Up @@ -25,6 +25,7 @@

import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObjectBuilder;

/**
* <code>IQueryBond</code> that matches IBond object only based on bond order, and
Expand All @@ -37,11 +38,12 @@ public class OrderQueryBondOrderOnly extends QueryBond implements IQueryBond {

private static final long serialVersionUID = 2292654937621883661L;

public OrderQueryBondOrderOnly() {
public OrderQueryBondOrderOnly(IChemObjectBuilder builder) {
super(builder);
}

public OrderQueryBondOrderOnly(IQueryAtom atom1, IQueryAtom atom2, IBond.Order order) {
super(atom1, atom2, order);
public OrderQueryBondOrderOnly(IQueryAtom atom1, IQueryAtom atom2, IBond.Order order, IChemObjectBuilder builder) {
super(atom1, atom2, order, builder);
}

public boolean matches(IBond bond) {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObjectBuilder;

/**
* @cdk.module isomorphism
Expand Down Expand Up @@ -127,11 +128,14 @@ public abstract class QueryAtom extends QueryChemObject implements IQueryAtom {
/** The atomic number for this element giving their position in the periodic table. */
protected Integer atomicNumber = (Integer) CDKConstants.UNSET;

public QueryAtom(String symbol) {
public QueryAtom(String symbol, IChemObjectBuilder builder) {
this(builder);
this.symbol = symbol;
}

public QueryAtom() {}
public QueryAtom(IChemObjectBuilder builder) {
super(builder);
}

/**
* Sets the partial charge of this atom.
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IChemObjectChangeEvent;
import org.openscience.cdk.interfaces.IElectronContainer;
import org.openscience.cdk.interfaces.ILonePair;
Expand Down Expand Up @@ -117,8 +118,9 @@ public String toString() {
/**
* Constructs an empty AtomContainer.
*/
public QueryAtomContainer() {
this(10, 10, 0, 0);
public QueryAtomContainer(IChemObjectBuilder builder) {
this(10, 10, 0, 0,
builder);
}


Expand All @@ -129,8 +131,9 @@ public QueryAtomContainer() {
*
* @param container An AtomContainer to copy the atoms and electronContainers from
*/
public QueryAtomContainer(IAtomContainer container)
public QueryAtomContainer(IAtomContainer container, IChemObjectBuilder builder)
{
super(builder);
this.atomCount = container.getAtomCount();
this.bondCount = container.getBondCount();
this.lonePairCount = container.getLonePairCount();
Expand Down Expand Up @@ -172,8 +175,10 @@ public QueryAtomContainer(IAtomContainer container)
*@param seCount Number of single electrons to be in this container
*
*/
public QueryAtomContainer(int atomCount, int bondCount, int lpCount, int seCount)
public QueryAtomContainer(int atomCount, int bondCount, int lpCount, int seCount,
IChemObjectBuilder builder)
{
super(builder);
this.atomCount = 0;
this.bondCount = 0;
this.lonePairCount = 0;
Expand Down

0 comments on commit 9b736ad

Please sign in to comment.