diff --git a/.classpath b/.classpath index eee6bd451b5..f24ebe0b4ef 100644 --- a/.classpath +++ b/.classpath @@ -5,7 +5,7 @@ - + @@ -19,7 +19,16 @@ + + + + + + + + + diff --git a/build.xml b/build.xml index 04dda31a962..02beb5bb627 100644 --- a/build.xml +++ b/build.xml @@ -531,7 +531,7 @@ list="io,structgen"/> + list="pdb,smiles,sdg,inchi,sinchi,libiocml"/> @@ -546,7 +546,7 @@ list="qsaratomic,qsarbond,qsarprotein,qsarcml,qsarmolecular"/> + list="forcefield,qsarionpot,iordf"/> @@ -563,13 +563,13 @@ test-valencycheck,test-smarts,test-standard,test-reaction, test-pcore,test-sdg,test-forcefield,test-fingerprint, test-ionpot,test-qm,test-isomorphism,test-libiomd,test-dict, - test-diff,test-charges,test-inchi,test-formula, + test-diff,test-charges,test-inchi,test-sinchi,test-formula, test-render,test-ioformats,test-log4j"/> + test-structgen,test-iordf"/> + @@ -677,6 +678,7 @@ + @@ -1058,7 +1060,7 @@ smarts,fingerprint,smiles,qsar,qsaratomic,qsarbond, qsarmolecular,qsarionpot,qsarprotein,pdb,pcore,inchi, structgen,libiomd,libiocml,formula,render,extra,sdg, - ioformats,log4j,smsd,signature"/> + ioformats,log4j,smsd,signature,iordf"/> + + + Yang, Y. and Chen, H. and Nilsson, I. and Muresan, S. and Engkvist, O. + Investigation of the Relationship between Topology and Selectivity for Druglike Molecules + J. Med. Chem. + 2010 + ASAP + + + + diff --git a/jar/jena/commons-logging-1.1.1.jar b/jar/jena/commons-logging-1.1.1.jar new file mode 100644 index 00000000000..8758a96b70c Binary files /dev/null and b/jar/jena/commons-logging-1.1.1.jar differ diff --git a/jar/jena/icu4j_3_4.jar b/jar/jena/icu4j_3_4.jar new file mode 100644 index 00000000000..d35e3c3466e Binary files /dev/null and b/jar/jena/icu4j_3_4.jar differ diff --git a/jar/jena/iri.jar b/jar/jena/iri.jar new file mode 100644 index 00000000000..b2026e455d1 Binary files /dev/null and b/jar/jena/iri.jar differ diff --git a/jar/jena/jena.jar b/jar/jena/jena.jar new file mode 100644 index 00000000000..6a532bd43a0 Binary files /dev/null and b/jar/jena/jena.jar differ diff --git a/jar/jena/slf4j-api-1.5.6.jar b/jar/jena/slf4j-api-1.5.6.jar new file mode 100644 index 00000000000..9b422169442 Binary files /dev/null and b/jar/jena/slf4j-api-1.5.6.jar differ diff --git a/jar/jena/slf4j-simple-1.5.0.jar b/jar/jena/slf4j-simple-1.5.0.jar new file mode 100644 index 00000000000..6bf86eb55e5 Binary files /dev/null and b/jar/jena/slf4j-simple-1.5.0.jar differ diff --git a/jar/jniinchi-0.7.jar b/jar/jniinchi-0.7.jar new file mode 100644 index 00000000000..ed779ba7f62 Binary files /dev/null and b/jar/jniinchi-0.7.jar differ diff --git a/jar/jniinchi-0.7.jar.meta b/jar/jniinchi-0.7.jar.meta new file mode 100644 index 00000000000..4b45ad5e451 --- /dev/null +++ b/jar/jniinchi-0.7.jar.meta @@ -0,0 +1,30 @@ +[jniinchi-0.7.jar] +Library=JNI-InChI +Version=0.7 +#Copyright= +License=GNU Lesser General Public License +LicenseURL=http://jni-inchi.sourceforge.net/license.html +#Download= +#SourceCode= +Homepage=http://jni-inchi.sourceforge.net/ + +[jniinchi-0.7.jar/org/apache/log4j] +Library=Apache Log4J +#Version= +#Copyright= +#License= +#LicenseURL= +#Download= +#SourceCode= +#Homepage= + +[jniinchi-0.7.jar/META-INF/jniinchi/1.6] +Library=InChI Software +Version=1.02 +#Copyright= +License=GNU LGPL +#LicenseURL= +#Download= +#SourceCode= +Homepage=http://iupac.org/inchi/ + diff --git a/javadoc.xml b/javadoc.xml index 15a1c0346fa..3b5c9f2ae1b 100755 --- a/javadoc.xml +++ b/javadoc.xml @@ -117,6 +117,7 @@ + diff --git a/pmd-unused.xml b/pmd-unused.xml index a08bb441b3f..8313e7759ec 100644 --- a/pmd-unused.xml +++ b/pmd-unused.xml @@ -57,6 +57,7 @@ + @@ -80,6 +81,7 @@ + diff --git a/pmd.xml b/pmd.xml index 6366fbe5b40..072d5c29a5e 100644 --- a/pmd.xml +++ b/pmd.xml @@ -64,6 +64,7 @@ + @@ -92,6 +93,7 @@ + + + + + FMF + + + + 2004-11-24 + + + + Descriptor characterizing molecular complexity in terms of its Murcko framework + + + This descriptor is described by Yang et al + and is the ratio of heavy atoms in the Murcko + framework of a molecule to the total number of heavy atoms in the molecule. + + + + diff --git a/src/main/org/openscience/cdk/fragment/MurckoFragmenter.java b/src/main/org/openscience/cdk/fragment/MurckoFragmenter.java index 86a5c86ce30..0606b3e97ee 100644 --- a/src/main/org/openscience/cdk/fragment/MurckoFragmenter.java +++ b/src/main/org/openscience/cdk/fragment/MurckoFragmenter.java @@ -149,14 +149,16 @@ private void run(IAtomContainer atomContainer) throws CDKException { // only add this in if there is actually a framework // in some cases we might just have rings and sidechains if (hasframework(currentFramework)) { - smiles = smilesGenerator.createSMILES(clone); + smiles = smilesGenerator.createSMILES(currentFramework); // if we only want the single framework according to Murcko, then // it was the first framework that is added, since subsequent recursive // calls will work on substructures of the original framework if (singleFrameworkOnly) { - if (frameMap.size() == 0) frameMap.put(smiles, clone); - } else frameMap.put(smiles, clone); + if (frameMap.size() == 0) { + frameMap.put(smiles, currentFramework); + } + } else frameMap.put(smiles, currentFramework); } // extract ring systems - we also delete pseudo linker bonds as described by diff --git a/src/main/org/openscience/cdk/inchi/standard/InChIGenerator.java b/src/main/org/openscience/cdk/inchi/standard/InChIGenerator.java new file mode 100644 index 00000000000..958fbb74565 --- /dev/null +++ b/src/main/org/openscience/cdk/inchi/standard/InChIGenerator.java @@ -0,0 +1,435 @@ +/* Copyright (C) 2006-2007 Sam Adams + * 2010 Egon Willighagen + * + * 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. + * + * 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.inchi.standard; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.vecmath.Point2d; +import javax.vecmath.Point3d; + +import net.sf.jniinchi.INCHI_BOND_STEREO; +import net.sf.jniinchi.INCHI_BOND_TYPE; +import net.sf.jniinchi.INCHI_KEY; +import net.sf.jniinchi.INCHI_PARITY; +import net.sf.jniinchi.INCHI_RADICAL; +import net.sf.jniinchi.INCHI_RET; +import net.sf.jniinchi.INCHI_STEREOTYPE; +import net.sf.jniinchi.JniInchiAtom; +import net.sf.jniinchi.JniInchiBond; +import net.sf.jniinchi.JniInchiException; +import net.sf.jniinchi.JniInchiInput; +import net.sf.jniinchi.JniInchiOutput; +import net.sf.jniinchi.JniInchiOutputKey; +import net.sf.jniinchi.JniInchiStereo0D; +import net.sf.jniinchi.JniInchiWrapper; + +import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; +import org.openscience.cdk.config.IsotopeFactory; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IAtomParity; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; + +/** + *

This class generates the IUPAC International Chemical Identifier (InChI) for + * a CDK IAtomContainer. It places calls to a JNI wrapper for the InChI C++ library. + * It outputs the Standard InChI. + * + *

If the atom container has 3D coordinates for all of its atoms then they + * will be used, otherwise 2D coordinates will be used if available. + * + *

Spin multiplicities and some aspects of stereochemistry are not + * currently handled completely. + * + *

Example usage

+ * + * // Generate factory - throws CDKException if native code does not load
+ * InChIGeneratorFactory factory = new InChIGeneratorFactory();
+ * // Get InChIGenerator
+ * InChIGenerator gen = factory.getInChIGenerator(container);
+ *
+ * INCHI_RET ret = gen.getReturnStatus();
+ * if (ret == INCHI_RET.WARNING) {
+ * // InChI generated, but with warning message
+ * System.out.println("InChI warning: " + gen.getMessage());
+ * } else if (ret != INCHI_RET.OKAY) {
+ * // InChI generation failed
+ * throw new CDKException("InChI failed: " + ret.toString()
+ * + " [" + gen.getMessage() + "]");
+ * }
+ *
+ * String inchi = gen.getInchi();
+ * String auxinfo = gen.getAuxInfo();
+ *

+ * TODO: distinguish between singlet and undefined spin multiplicity
+ * TODO: double bond and allene parities
+ * TODO: problem recognising bond stereochemistry
+ *
+ * + * @author Sam Adams + * + * @cdk.module sinchi + * @cdk.githash + */ +@TestClass("org.openscience.cdk.inchi.standard.InChIGeneratorTest") +public class InChIGenerator { + + protected JniInchiInput input; + + protected JniInchiOutput output; + + /** + * AtomContainer instance refers to. + */ + protected IAtomContainer atomContainer; + + /** + *

Constructor. Generates InChI from CDK AtomContainer. + * + *

Reads atoms, bonds etc from atom container and converts to format + * InChI library requires, then calls the library. + * + * @param atomContainer AtomContainer to generate InChI for. + * @throws org.openscience.cdk.exception.CDKException if there is an + * error during InChI generation + */ + @TestClass("testGetInchiFromChlorineAtom,testGetInchiFromLithiumIontestGetInchiFromChlorine37Atom") + protected InChIGenerator(IAtomContainer atomContainer) throws CDKException { + try { + input = new JniInchiInput(""); + generateInchiFromCDKAtomContainer(atomContainer); + } catch (JniInchiException jie) { + throw new CDKException("InChI generation failed: " + jie.getMessage(), jie); + } + } + + /** + *

Constructor. Generates InChI from CDK AtomContainer. + * + *

Reads atoms, bonds etc from atom container and converts to format + * InChI library requires, then calls the library. + * + * @param atomContainer AtomContainer to generate InChI for. + * @param options Space delimited string of options to pass to InChI library. + * Each option may optionally be preceded by a command line + * switch (/ or -). + * @throws CDKException + */ + protected InChIGenerator(IAtomContainer atomContainer, String options) throws CDKException { + try { + input = new JniInchiInput(options); + generateInchiFromCDKAtomContainer(atomContainer); + } catch (JniInchiException jie) { + throw new CDKException("InChI generation failed: " + jie.getMessage(), jie); + } + } + + + /** + *

Constructor. Generates InChI from CDK AtomContainer. + * + *

Reads atoms, bonds etc from atom container and converts to format + * InChI library requires, then calls the library. + * + * @param atomContainer AtomContainer to generate InChI for. + * @param options List of INCHI_OPTION. + * @throws CDKException + */ + protected InChIGenerator(IAtomContainer atomContainer, List options) throws CDKException { + try { + input = new JniInchiInput(options); + generateInchiFromCDKAtomContainer(atomContainer); + } catch (JniInchiException jie) { + throw new CDKException("InChI generation failed: " + jie.getMessage(), jie); + } + } + + + /** + *

Reads atoms, bonds etc from atom container and converts to format + * InChI library requires, then places call for the library to generate + * the InChI. + * + * @param atomContainer AtomContainer to generate InChI for. + * @throws CDKException + */ + private void generateInchiFromCDKAtomContainer(IAtomContainer atomContainer) throws CDKException { + this.atomContainer = atomContainer; + + Iterator atoms = atomContainer.atoms().iterator(); + + // Check for 3d coordinates + boolean all3d = true; + boolean all2d = true; + while (atoms.hasNext()) { + IAtom atom = (IAtom)atoms.next(); + if (atom.getPoint3d() == null) { + all3d = false; + } + if (atom.getPoint2d() == null) { + all2d = false; + } + } + + // Process atoms + IsotopeFactory ifact = null; + try { + ifact = IsotopeFactory.getInstance(atomContainer.getBuilder()); + } catch (Exception e) { + // Do nothing + } + + Map atomMap = new HashMap(); + atoms = atomContainer.atoms().iterator(); + while (atoms.hasNext()) { + IAtom atom = atoms.next(); + + // Get coordinates + // Use 3d if possible, otherwise 2d or none + double x, y, z; + if (all3d) { + Point3d p = atom.getPoint3d(); + x = p.x; + y = p.y; + z = p.z; + } else if (all2d) { + Point2d p = atom.getPoint2d(); + x = p.x; + y = p.y; + z = 0.0; + } else { + x = 0.0; + y = 0.0; + z = 0.0; + } + + // Chemical element symbol + String el = atom.getSymbol(); + + // Generate InChI atom + JniInchiAtom iatom = input.addAtom(new JniInchiAtom(x, y, z, el)); + atomMap.put(atom, iatom); + + // Check if charged + int charge = atom.getFormalCharge(); + if (charge != 0) { + iatom.setCharge(charge); + } + + // Check whether isotopic + Integer isotopeNumber = atom.getMassNumber(); + if (isotopeNumber != CDKConstants.UNSET && ifact != null) { + IAtom isotope = atomContainer.getBuilder().newInstance(IAtom.class,el); + ifact.configure(isotope); + if (isotope.getMassNumber().intValue() == isotopeNumber.intValue()) { + isotopeNumber = 0; + } + } + if (isotopeNumber != CDKConstants.UNSET) { + iatom.setIsotopicMass(isotopeNumber); + } + + // Check for implicit hydrogens + // atom.getHydrogenCount() returns number of implict hydrogens, not + // total number + // Ref: Posting to cdk-devel list by Egon Willighagen 2005-09-17 + Integer implicitH = atom.getImplicitHydrogenCount(); + if (implicitH == CDKConstants.UNSET) implicitH = 0; + + if (implicitH != 0) { + iatom.setImplicitH(implicitH); + } + + // Check if radical + int count = atomContainer.getConnectedSingleElectronsCount(atom); + if (count == 0) { + // TODO - how to check whether singlet or undefined multiplicity + } else if (count == 1) { + iatom.setRadical(INCHI_RADICAL.DOUBLET); + } else if (count == 2) { + iatom.setRadical(INCHI_RADICAL.TRIPLET); + } else { + throw new CDKException("Unrecognised radical type"); + } + } + + + // Process bonds + Iterator bonds = atomContainer.bonds().iterator(); + while (bonds.hasNext()) { + IBond bond = bonds.next(); + + // Assumes 2 centre bond + JniInchiAtom at0 = (JniInchiAtom) atomMap.get(bond.getAtom(0)); + JniInchiAtom at1 = (JniInchiAtom) atomMap.get(bond.getAtom(1)); + + // Get bond order + INCHI_BOND_TYPE order; + IBond.Order bo = bond.getOrder(); + if (bond.getFlag(CDKConstants.ISAROMATIC)) { + order = INCHI_BOND_TYPE.ALTERN; + } else if (bo == CDKConstants.BONDORDER_SINGLE) { + order = INCHI_BOND_TYPE.SINGLE; + } else if (bo == CDKConstants.BONDORDER_DOUBLE) { + order = INCHI_BOND_TYPE.DOUBLE; + } else if (bo == CDKConstants.BONDORDER_TRIPLE) { + order = INCHI_BOND_TYPE.TRIPLE; + } else { + throw new CDKException("Failed to generate InChI: Unsupported bond type"); + } + + // Create InChI bond + JniInchiBond ibond = new JniInchiBond(at0, at1, order); + input.addBond(ibond); + + // Check for bond stereo definitions + IBond.Stereo stereo = bond.getStereo(); + // No stereo definition + if (stereo == IBond.Stereo.NONE) { + ibond.setStereoDefinition(INCHI_BOND_STEREO.NONE); + } + // Bond ending (fat end of wedge) below the plane + else if (stereo == IBond.Stereo.DOWN) { + ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_1DOWN); + } + // Bond ending (fat end of wedge) above the plane + else if (stereo == IBond.Stereo.UP) { + ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_1UP); + } + // Bond starting (pointy end of wedge) below the plane + else if (stereo == IBond.Stereo.DOWN_INVERTED) { + ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_2DOWN); + } + // Bond starting (pointy end of wedge) above the plane + else if (stereo == IBond.Stereo.UP_INVERTED) { + ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_2UP); + } + // Bond with undefined stereochemistry + else if (stereo == CDKConstants.UNSET) { + if (order == INCHI_BOND_TYPE.SINGLE) { + ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_1EITHER); + } else if (order == INCHI_BOND_TYPE.DOUBLE) { + ibond.setStereoDefinition(INCHI_BOND_STEREO.DOUBLE_EITHER); + } + } + } + + // Process atom parities (tetrahedral InChI Stereo0D Parities) + atoms = atomContainer.atoms().iterator(); + while (atoms.hasNext()) { + IAtom atom = atoms.next(); + IAtomParity parity = AtomContainerManipulator.getAtomParity(atomContainer, atom); + if (parity != null) { + IAtom[] surroundingAtoms = parity.getSurroundingAtoms(); + int sign = parity.getParity(); + + JniInchiAtom atC = (JniInchiAtom) atomMap.get(atom); + JniInchiAtom at0 = (JniInchiAtom) atomMap.get(surroundingAtoms[0]); + JniInchiAtom at1 = (JniInchiAtom) atomMap.get(surroundingAtoms[1]); + JniInchiAtom at2 = (JniInchiAtom) atomMap.get(surroundingAtoms[2]); + JniInchiAtom at3 = (JniInchiAtom) atomMap.get(surroundingAtoms[3]); + INCHI_PARITY p = INCHI_PARITY.UNKNOWN; + if (sign > 0) { + p = INCHI_PARITY.EVEN; + } else if (sign < 0) { + p = INCHI_PARITY.ODD; + } else { + throw new CDKException("Atom parity of zero"); + } + + input.addStereo0D(new JniInchiStereo0D(atC, at0, at1, at2, at3, + INCHI_STEREOTYPE.TETRAHEDRAL, p)); + } + } + + try { + output = JniInchiWrapper.getInchi(input); + } catch (JniInchiException jie) { + throw new CDKException("Failed to generate InChI: " + jie.getMessage(), jie); + } + } + + + /** + * Gets return status from InChI process. OKAY and WARNING indicate + * InChI has been generated, in all other cases InChI generation + * has failed. + */ + @TestMethod("testGetInchiFromLandDAlanine3D,testGetInchiEandZ12Dichloroethene2D") + public INCHI_RET getReturnStatus() { + return(output.getReturnStatus()); + } + + /** + * Gets generated InChI string. + */ + @TestMethod("testGetInchiEandZ12Dichloroethene2D,testGetInchiFromEthyne,testGetInchiFromEthene") + public String getInchi() { + return(output.getInchi()); + } + + /** + * Gets generated InChIKey string. + */ + @TestMethod("testGetInchiFromEthane") + public String getInchiKey() throws CDKException { + JniInchiOutputKey key; + try { + key = JniInchiWrapper.getInChIKey(output.getInchi()); + if (key.getReturnStatus() == INCHI_KEY.OK) { + return key.getKey(); + } else { + throw new CDKException("Error while creating InChIKey: " + + key.getReturnStatus()); + } + } catch (JniInchiException exception) { + throw new CDKException("Error while creating InChIKey: " + + exception.getMessage(), exception); + } + } + + /** + * Gets auxillary information. + */ + public String getAuxInfo() { + return(output.getAuxInfo()); + } + + /** + * Gets generated (error/warning) messages. + */ + public String getMessage() { + return(output.getMessage()); + } + + /** + * Gets generated log. + */ + public String getLog() { + return(output.getLog()); + } +} diff --git a/src/main/org/openscience/cdk/inchi/standard/InChIGeneratorFactory.java b/src/main/org/openscience/cdk/inchi/standard/InChIGeneratorFactory.java new file mode 100644 index 00000000000..e54af3e33ca --- /dev/null +++ b/src/main/org/openscience/cdk/inchi/standard/InChIGeneratorFactory.java @@ -0,0 +1,186 @@ +/* Copyright (C) 2006-2007 Sam Adams + * 2009 Jonathan Alvarsson + * 2010 Egon Willighagen + * + * 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. + * + * 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.inchi.standard; + +import java.util.List; + +import net.sf.jniinchi.JniInchiWrapper; +import net.sf.jniinchi.LoadNativeLibraryException; + +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +/** + *

Factory providing access to InChIGenerator and InChIToStructure. See those + * classes for examples of use. These methods make use of the JNI-InChI library. + * + *

The InchiGeneratorFactory is a singleton class, which means that there + * exists only one instance of the class. An instance of this class is obtained + * with: + *

+ * InchiGeneratorFactory factory = InchiGeneratorFactory.getInstance();
+ * 
+ * + *

InChI/Structure interconversion is implemented in this way so that we can + * check whether or not the native code required is available. If the native + * code cannot be loaded during the first call to getInstance + * method (when the instance is created) a CDKException will be thrown. The + * most common problem is that the native code is not in the * the correct + * location. Java searches the locations in the PATH environmental + * variable, under Windows, and LD_LIBRARY_PATH under Linux, so the JNI-InChI + * native libraries must be in one of these locations. If the JNI-InChI jar file + * is being used and either the current working directory, or '.' are contained + * in PATH of LD_LIBRARY_PATH then the native code should be placed + * automatically. If the native files are in the correct location but fail to + * load, then they may need to be recompiled for your system. See: + *

    + *
  • http://sourceforge.net/projects/jni-inchi + *
  • http://www.iupac.org/inchi/ + *
+ * + * @author Sam Adams + * + * @cdk.module sinchi + * @cdk.githash + */ +public class InChIGeneratorFactory { + + private static InChIGeneratorFactory INSTANCE; + + /** + *

Constructor for InChIGeneratorFactory. Ensures that native code + * required for InChI/Structure interconversion is available, otherwise + * throws CDKException. + * + * @throws CDKException if unable to load native code + */ + private InChIGeneratorFactory() throws CDKException { + try { + JniInchiWrapper.loadLibrary(); + } catch (LoadNativeLibraryException lnle) { + throw new CDKException( "Unable to load native code; " + + lnle.getMessage(), lnle ); + } + } + + /** + * Gives the one InChIGeneratorFactory instance, + * if needed also creates it. + * + * @return the one InChIGeneratorFactory instance + * @throws CDKException if unable to load native code when attempting + * to create the factory + */ + public static InChIGeneratorFactory getInstance() throws CDKException { + synchronized ( InChIGeneratorFactory.class ) { + if ( INSTANCE == null ) { + INSTANCE = new InChIGeneratorFactory(); + } + return INSTANCE; + } + } + + /** + * Gets InChI generator for CDK IAtomContainer. + * + * @param container AtomContainer to generate InChI for. + * @return the InChI generator object + * @throws CDKException if the generator cannot be instantiated + */ + public InChIGenerator getInChIGenerator(IAtomContainer container) + throws CDKException { + return(new InChIGenerator(container)); + } + + /** + * Gets InChI generator for CDK IAtomContainer. + * + * @param container AtomContainer to generate InChI for. + * @param options String of options for InChI generation. + * @return the InChI generator object + * @throws CDKException if the generator cannot be instantiated + */ + public InChIGenerator getInChIGenerator(IAtomContainer container, + String options) + throws CDKException { + return(new InChIGenerator(container, options)); + } + + /** + * Gets InChI generator for CDK IAtomContainer. + * + * @param container AtomContainer to generate InChI for. + * @param options List of options (net.sf.jniinchi.INCHI_OPTION) for InChI generation. + * @return the InChI generator object + * @throws CDKException if the generator cannot be instantiated + */ + public InChIGenerator getInChIGenerator(IAtomContainer container, + List options) throws CDKException { + return(new InChIGenerator(container, options)); + } + + /** + * Gets structure generator for an InChI string. + * + * @param inchi InChI to generate structure from. + * @param builder the builder to use + * @return the InChI structure generator object + * @throws CDKException if the generator cannot be instantiated + */ + public InChIToStructure getInChIToStructure(String inchi, + IChemObjectBuilder builder) + throws CDKException { + return(new InChIToStructure(inchi, builder)); + } + + /** + *

Gets structure generator for an InChI string. + * + * @param inchi InChI to generate structure from. + * @param builder the builder to employ + * @param options String of options for structure generation. + * @return the InChI structure generator object + * @throws CDKException if the generator cannot be instantiated + */ + public InChIToStructure getInChIToStructure(String inchi, + IChemObjectBuilder builder, + String options) + throws CDKException { + return(new InChIToStructure(inchi, builder, options)); + } + + /** + *

Gets structure generator for an InChI string. + * + * @param inchi InChI to generate structure from. + * @param options List of options (net.sf.jniinchi.INCHI_OPTION) for structure generation. + * @param builder the builder to employ + * @return the InChI structure generator object + * @throws CDKException if the generator cannot be instantiated + */ + public InChIToStructure getInChIToStructure(String inchi, + IChemObjectBuilder builder, + List options) + throws CDKException { + return(new InChIToStructure(inchi, builder, options)); + } +} diff --git a/src/main/org/openscience/cdk/inchi/standard/InChIToStructure.java b/src/main/org/openscience/cdk/inchi/standard/InChIToStructure.java new file mode 100644 index 00000000000..8375c621524 --- /dev/null +++ b/src/main/org/openscience/cdk/inchi/standard/InChIToStructure.java @@ -0,0 +1,307 @@ +/* Copyright (C) 2006-2007 Sam Adams + * 2010 Egon Willighagen + * + * 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. + * + * 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.inchi.standard; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sf.jniinchi.INCHI_BOND_STEREO; +import net.sf.jniinchi.INCHI_BOND_TYPE; +import net.sf.jniinchi.INCHI_PARITY; +import net.sf.jniinchi.INCHI_RET; +import net.sf.jniinchi.INCHI_STEREOTYPE; +import net.sf.jniinchi.JniInchiAtom; +import net.sf.jniinchi.JniInchiBond; +import net.sf.jniinchi.JniInchiException; +import net.sf.jniinchi.JniInchiInputInchi; +import net.sf.jniinchi.JniInchiOutputStructure; +import net.sf.jniinchi.JniInchiStereo0D; +import net.sf.jniinchi.JniInchiWrapper; + +import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IAtomParity; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemObjectBuilder; + +/** + *

This class generates a CDK IAtomContainer from an InChI string. It places + * calls to a JNI wrapper for the InChI C++ library. + * + *

The generated IAtomContainer will have all 2D and 3D coordinates set to 0.0, + * but may have atom parities set. Double bond and allene stereochemistry are + * not currently recorded. + * + *

Example usage

+ * + * // Generate factory - throws CDKException if native code does not load
+ * InChIGeneratorFactory factory = new InChIGeneratorFactory();
+ * // Get InChIToStructure
+ * InChIToStructure intostruct = factory.getInChIToStructure(inchi);
+ *
+ * INCHI_RET ret = intostruct.getReturnStatus();
+ * if (ret == INCHI_RET.WARNING) {
+ * // Structure generated, but with warning message
+ * System.out.println("InChI warning: " + intostruct.getMessage());
+ * } else if (ret != INCHI_RET.OKAY) {
+ * // Structure generation failed
+ * throw new CDKException("Structure generation failed failed: " + ret.toString()
+ * + " [" + intostruct.getMessage() + "]");
+ * }
+ *
+ * IAtomContainer container = intostruct.getAtomContainer();
+ *

+ * + * @author Sam Adams + * + * @cdk.module sinchi + * @cdk.githash + */ +public class InChIToStructure { + +protected JniInchiInputInchi input; + + protected JniInchiOutputStructure output; + + protected IAtomContainer molecule; + + /** + * Constructor. Generates CDK AtomContainer from InChI. + * @param inchi + * @throws CDKException + */ + protected InChIToStructure(String inchi, IChemObjectBuilder builder) throws CDKException { + try { + input = new JniInchiInputInchi(inchi, ""); + } catch (JniInchiException jie) { + throw new CDKException("Failed to convert InChI to molecule: " + jie.getMessage(), jie); + } + generateAtomContainerFromInchi(builder); + } + + /** + * Constructor. Generates CMLMolecule from InChI. + * @param inchi + * @param options + * @throws CDKException + */ + protected InChIToStructure(String inchi, IChemObjectBuilder builder, String options) throws CDKException { + try { + input = new JniInchiInputInchi(inchi, options); + } catch (JniInchiException jie) { + throw new CDKException("Failed to convert InChI to molecule: " + jie.getMessage(), jie); + } + generateAtomContainerFromInchi(builder); + } + + /** + * Constructor. Generates CMLMolecule from InChI. + * @param inchi + * @param options + * @throws CDKException + */ + protected InChIToStructure(String inchi, IChemObjectBuilder builder, List options) throws CDKException { + try { + input = new JniInchiInputInchi(inchi, options); + } catch (JniInchiException jie) { + throw new CDKException("Failed to convert InChI to molecule: " + jie.getMessage()); + } + generateAtomContainerFromInchi(builder); + } + + /** + * Gets structure from InChI, and converts InChI library data structure + * into an IAtomContainer. + * + * @throws CDKException + */ + protected void generateAtomContainerFromInchi(IChemObjectBuilder builder) throws CDKException { + try { + output = JniInchiWrapper.getStructureFromInchi(input); + } catch (JniInchiException jie) { + throw new CDKException("Failed to convert InChI to molecule: " + jie.getMessage(), jie); + } + + //molecule = new AtomContainer(); + molecule = builder.newInstance(IAtomContainer.class); + + Map inchiCdkAtomMap = new HashMap(); + + for (int i = 0; i < output.getNumAtoms(); i ++) { + JniInchiAtom iAt = output.getAtom(i); + IAtom cAt = builder.newInstance(IAtom.class); + + inchiCdkAtomMap.put(iAt, cAt); + + cAt.setID("a" + i); + cAt.setSymbol(iAt.getElementType()); + + // Ignore coordinates - all zero + + int charge = iAt.getCharge(); + if (charge != 0) { + cAt.setFormalCharge(charge); + } + + // hydrogenCount contains number of implict hydrogens, not + // total number + // Ref: Posting to cdk-devel list by Egon Willighagen 2005-09-17 + int numH = iAt.getImplicitH(); + if (numH != 0) { + cAt.setImplicitHydrogenCount(numH); + } + + molecule.addAtom(cAt); + } + + for (int i = 0; i < output.getNumBonds(); i ++) { + JniInchiBond iBo = output.getBond(i); + IBond cBo = builder.newInstance(IBond.class); + + IAtom atO = inchiCdkAtomMap.get(iBo.getOriginAtom()); + IAtom atT = inchiCdkAtomMap.get(iBo.getTargetAtom()); + IAtom[] atoms = new IAtom[2]; + atoms[0] = atO; + atoms[1] = atT; + cBo.setAtoms(atoms); + + INCHI_BOND_TYPE type = iBo.getBondType(); + if (type == INCHI_BOND_TYPE.SINGLE) { + cBo.setOrder(CDKConstants.BONDORDER_SINGLE); + } else if (type == INCHI_BOND_TYPE.DOUBLE) { + cBo.setOrder(CDKConstants.BONDORDER_DOUBLE); + } else if (type == INCHI_BOND_TYPE.TRIPLE) { + cBo.setOrder(CDKConstants.BONDORDER_TRIPLE); + } else if (type == INCHI_BOND_TYPE.ALTERN) { + cBo.setFlag(CDKConstants.ISAROMATIC, true); + } else { + throw new CDKException("Unknown bond type: " + type); + } + + INCHI_BOND_STEREO stereo = iBo.getBondStereo(); + + // No stereo definition + if (stereo == INCHI_BOND_STEREO.NONE) { + cBo.setStereo(IBond.Stereo.NONE); + } + // Bond ending (fat end of wedge) below the plane + else if (stereo == INCHI_BOND_STEREO.SINGLE_1DOWN) { + cBo.setStereo(IBond.Stereo.DOWN); + } + // Bond ending (fat end of wedge) above the plane + else if (stereo == INCHI_BOND_STEREO.SINGLE_1UP) { + cBo.setStereo(IBond.Stereo.UP); + } + // Bond starting (pointy end of wedge) below the plane + else if (stereo == INCHI_BOND_STEREO.SINGLE_2DOWN) { + cBo.setStereo(IBond.Stereo.DOWN_INVERTED); + } + // Bond starting (pointy end of wedge) above the plane + else if (stereo == INCHI_BOND_STEREO.SINGLE_2UP) { + cBo.setStereo(IBond.Stereo.UP_INVERTED); + } + // Bond with undefined stereochemistry + else if (stereo == INCHI_BOND_STEREO.SINGLE_1EITHER + || stereo == INCHI_BOND_STEREO.DOUBLE_EITHER) { + cBo.setStereo((IBond.Stereo)CDKConstants.UNSET); + } + + molecule.addBond(cBo); + } + + for (int i = 0; i < output.getNumStereo0D(); i ++) { + JniInchiStereo0D stereo0d = output.getStereo0D(i); + if (stereo0d.getStereoType() == INCHI_STEREOTYPE.TETRAHEDRAL) { + JniInchiAtom central = stereo0d.getCentralAtom(); + JniInchiAtom[] neighbours = stereo0d.getNeighbors(); + + IAtom atC = (IAtom) inchiCdkAtomMap.get(central); + IAtom at0 = (IAtom) inchiCdkAtomMap.get(neighbours[0]); + IAtom at1 = (IAtom) inchiCdkAtomMap.get(neighbours[1]); + IAtom at2 = (IAtom) inchiCdkAtomMap.get(neighbours[2]); + IAtom at3 = (IAtom) inchiCdkAtomMap.get(neighbours[3]); + + int sign; + if (stereo0d.getParity() == INCHI_PARITY.ODD) { + sign = -1; + } else if (stereo0d.getParity() == INCHI_PARITY.EVEN) { + sign = +1; + } else { + // CDK Only supports parities of + or - + continue; + } + + IAtomParity parity = builder.newInstance(IAtomParity.class,atC, at0, at1, at2, at3, sign); + molecule.addStereoElement(parity); + } else { + // TODO - other types of atom parity - double bond, etc + } + } + } + + /** + * Returns generated molecule. + * @return An AtomContainer object + */ + public IAtomContainer getAtomContainer() { + return(molecule); + } + + + /** + * Gets return status from InChI process. OKAY and WARNING indicate + * InChI has been generated, in all other cases InChI generation + * has failed. + */ + public INCHI_RET getReturnStatus() { + return(output.getReturnStatus()); + } + + /** + * Gets generated (error/warning) messages. + */ + public String getMessage() { + return(output.getMessage()); + } + + /** + * Gets generated log. + */ + public String getLog() { + return(output.getLog()); + } + + /** + *

Returns warning flags, see INCHIDIFF in inchicmp.h. + * + *

[x][y]: + *
x=0 => Reconnected if present in InChI otherwise Disconnected/Normal + *
x=1 => Disconnected layer if Reconnected layer is present + *
y=1 => Main layer or Mobile-H + *
y=0 => Fixed-H layer + */ + public long[][] getWarningFlags() { + return(output.getWarningFlags()); + } + +} diff --git a/src/main/org/openscience/cdk/io/CDKSourceCodeWriter.java b/src/main/org/openscience/cdk/io/CDKSourceCodeWriter.java index ee39d9d2245..0dfaa08ff6c 100644 --- a/src/main/org/openscience/cdk/io/CDKSourceCodeWriter.java +++ b/src/main/org/openscience/cdk/io/CDKSourceCodeWriter.java @@ -1,6 +1,4 @@ -/* $Revision$ $Author$ $Date$ - * - * Copyright (C) 2003-2007 Egon Willighagen +/* Copyright (C) 2003-2007,2010 Egon Willighagen * * Contact: cdk-devel@lists.sourceforge.net * @@ -210,13 +208,15 @@ public void writeAtomContainer(IAtomContainer molecule) throws Exception { public void writeAtom(IAtom atom) throws Exception { if (atom instanceof IPseudoAtom) { - writer.write(" IPseudoAtom " + atom.getID() + " = mol.getNewBuilder().newInstance(IPseudoAtom.class);"); + writer.write(" IPseudoAtom " + atom.getID() + + " = mol.getBuilder().newInstance(IPseudoAtom.class);"); writer.newLine(); writer.write(" atom.setLabel(\"" + ((IPseudoAtom)atom).getLabel() + "\");"); writer.newLine(); } else { - writer.write(" IAtom " + atom.getID() + " = mol.getNewBuilder().newInstance(IAtom.class,\"" + atom.getSymbol() + - "\");"); + writer.write(" IAtom " + atom.getID() + + " = mol.getBuilder().newInstance(IAtom.class,\"" + + atom.getSymbol() + "\");"); writer.newLine(); } if (atom.getFormalCharge() != null) { @@ -240,7 +240,8 @@ public void writeAtom(IAtom atom) throws Exception { } public void writeBond(IBond bond) throws Exception { - writer.write(" IBond " + bond.getID() + " = mol.getNewBuilder().newInstance(IBond.class," + + writer.write(" IBond " + bond.getID() + + " = mol.getBuilder().newInstance(IBond.class," + bond.getAtom(0).getID() + ", " + bond.getAtom(1).getID() + ", IBond.Order." + bond.getOrder() + ");"); diff --git a/src/main/org/openscience/cdk/io/formats/CDKOWLFormat.java b/src/main/org/openscience/cdk/io/formats/CDKOWLFormat.java new file mode 100644 index 00000000000..eb2e41042d5 --- /dev/null +++ b/src/main/org/openscience/cdk/io/formats/CDKOWLFormat.java @@ -0,0 +1,102 @@ +/* Copyright (C) 2009 Egon Willighagen + * + * Contact: cdk-devel@lists.sourceforge.net + * + * 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 + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.io.formats; + +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; +import org.openscience.cdk.tools.DataFeatures; + +/** + * Serializes a CDK model into the Web Ontology Language using the + * N3 format. + * + * @cdk.module ioformats + * @cdk.githash + * @cdk.set io-formats + */ +@TestClass("org.openscience.cdk.io.formats.CDKOWLFormatTest") +public class CDKOWLFormat implements IChemFormatMatcher { + + private static IResourceFormat myself = null; + + private CDKOWLFormat() {} + + @TestMethod("testResourceFormatSet") + public static IResourceFormat getInstance() { + if (myself == null) myself = new CDKOWLFormat(); + return myself; + } + + @TestMethod("testGetFormatName") + public String getFormatName() { + return "CDK OWL (N3)"; + } + + @TestMethod("testGetMIMEType") + public String getMIMEType() { + return "text/n3"; + } + @TestMethod("testGetPreferredNameExtension") + public String getPreferredNameExtension() { + return getNameExtensions()[0]; + } + @TestMethod("testGetNameExtensions") + public String[] getNameExtensions() { + return new String[]{"n3"}; + } + + @TestMethod("testGetReaderClassName") + public String getReaderClassName() { + return "org.openscience.cdk.io.rdf.CDKOWLReader"; + } + @TestMethod("testGetWriterClassName") + public String getWriterClassName() { + return "org.openscience.cdk.io.rdf.CDKOWLWriter"; + } + + public boolean matches(int lineNumber, String line) { + if (line.startsWith("PREFIX") && + line.contains("http://cdk.sourceforge.net/model.owl#")) { + return true; + } + return false; + } + + @TestMethod("testIsXMLBased") + public boolean isXMLBased() { + return false; + } + + @TestMethod("testGetSupportedDataFeatures") + public int getSupportedDataFeatures() { + return DataFeatures.HAS_2D_COORDINATES | + DataFeatures.HAS_3D_COORDINATES | + DataFeatures.HAS_ATOM_PARTIAL_CHARGES | + DataFeatures.HAS_ATOM_FORMAL_CHARGES | + DataFeatures.HAS_ATOM_MASS_NUMBERS | + DataFeatures.HAS_ATOM_ISOTOPE_NUMBERS | + DataFeatures.HAS_GRAPH_REPRESENTATION | + DataFeatures.HAS_ATOM_ELEMENT_SYMBOL; + } + + @TestMethod("testGetRequiredDataFeatures") + public int getRequiredDataFeatures() { + return DataFeatures.NONE; + } +} diff --git a/src/main/org/openscience/cdk/io/rdf/CDKOWLReader.java b/src/main/org/openscience/cdk/io/rdf/CDKOWLReader.java new file mode 100644 index 00000000000..8a4ff83df88 --- /dev/null +++ b/src/main/org/openscience/cdk/io/rdf/CDKOWLReader.java @@ -0,0 +1,131 @@ +/* Copyright (C) 2009 Egon Willighagen + * + * 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.io.rdf; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IChemObject; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.io.DefaultChemObjectReader; +import org.openscience.cdk.io.formats.CDKOWLFormat; +import org.openscience.cdk.io.formats.IResourceFormat; + +/** + * Reads content from a CDK OWL serialization. + * + * @cdk.module iordf + * @cdk.githash + * @cdk.keyword file format, OWL + */ +@TestClass("org.openscience.cdk.io.rdf.CDKOWLReaderTest") +public class CDKOWLReader extends DefaultChemObjectReader { + + private Reader input; + + /** + * Creates a new CDKOWLReader sending output to the given Writer. + * + * @param input {@link Reader} from which is OWL input is taken. + */ + public CDKOWLReader(Reader input) { + this.input = input; + } + + /** + * Creates a new CDKOWLReader with an undefined input. + */ + public CDKOWLReader() { + this.input = null; + } + + /** + * Returns the {@link IResourceFormat} for this reader. + * + * @return returns a {@link CDKOWLFormat}. + */ + @TestMethod("testGetFormat") + public IResourceFormat getFormat() { + return CDKOWLFormat.getInstance(); + } + + /** + * This method must not be used; XML reading requires the use of an + * {@link InputStream}. Use {@link #setReader(InputStream)} instead. + * + * @param reader reader to which should be written. + * @deprecated + */ + @TestMethod("testSetReader_Reader") + public void setReader(Reader reader) throws CDKException { + this.input = reader; + } + + /** {@inheritDoc} */ + @TestMethod("testSetReader_InputStream") + public void setReader(InputStream input) throws CDKException { + this.input = new InputStreamReader(input); + } + + /** {@inheritDoc} */ + @TestMethod("testAccepts") + public boolean accepts(Class classObject) { + Class[] interfaces = classObject.getInterfaces(); + for (int i=0; i + * + * Contact: cdk-devel@lists.sourceforge.net + * + * 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 + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.io.rdf; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import org.openscience.cdk.annotations.TestMethod; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IChemObject; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.io.DefaultChemObjectWriter; +import org.openscience.cdk.io.formats.CDKOWLFormat; +import org.openscience.cdk.io.formats.IResourceFormat; +import org.openscience.cdk.libio.jena.Convertor; + +import com.hp.hpl.jena.rdf.model.Model; + +/** + * Serializes the data model into CDK OWL. + * + * @cdk.module iordf + * @cdk.githash + */ +public class CDKOWLWriter extends DefaultChemObjectWriter { + + private Writer output; + + /** + * Creates a new CDKOWLWriter sending output to the given Writer. + * + * @param output {@link Writer} to which is OWL output is routed. + */ + public CDKOWLWriter(Writer output) { + this.output = output; + } + + /** + * Creates a new CDKOWLWriter with an undefined output. + */ + public CDKOWLWriter() { + this.output = null; + } + + /** + * Returns the {@link IResourceFormat} for this writer. + * + * @return returns a {@link CDKOWLFormat}. + */ + public IResourceFormat getFormat() { + return CDKOWLFormat.getInstance(); + } + + /** {@inheritDoc} */ + public void setWriter(Writer out) throws CDKException { + this.output = out; + } + + /** {@inheritDoc} */ + public void setWriter(OutputStream output) throws CDKException { + this.output = new OutputStreamWriter(output); + } + + /** {@inheritDoc} */ + public void close() throws IOException { + if (output != null) output.close(); + } + + /** {@inheritDoc} */ + @TestMethod("testAccepts") + public boolean accepts(Class classObject) { + Class[] interfaces = classObject.getInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + if (IMolecule.class.equals(interfaces[i])) return true; + } + Class superClass = classObject.getSuperclass(); + if (superClass != null) return this.accepts(superClass); + return false; + } + + /** {@inheritDoc} */ + public void write(IChemObject object) throws CDKException { + if (object instanceof IMolecule) { + try { + writeMolecule((IMolecule)object); + } catch (Exception ex) { + throw new CDKException( + "Error while writing HIN file: " + ex.getMessage(), ex + ); + } + } else { + throw new CDKException( + "CDKOWLWriter only supports output of IMolecule classes." + ); + } + } + + private void writeMolecule(IMolecule mol) { + Model model = Convertor.molecule2Model(mol); + model.write(output, "N3"); + } + +} diff --git a/src/main/org/openscience/cdk/libio/jena/CDK.java b/src/main/org/openscience/cdk/libio/jena/CDK.java new file mode 100644 index 00000000000..959043fb3f0 --- /dev/null +++ b/src/main/org/openscience/cdk/libio/jena/CDK.java @@ -0,0 +1,95 @@ +/* Copyright (C) 2009 Egon Willighagen + * + * Contact: jchempaint-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.libio.jena; + +import com.hp.hpl.jena.rdf.model.Property; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.ResourceFactory; +import com.hp.hpl.jena.vocabulary.RDF; + +/** + * Helper class to provide a Java API to the CDK OWL ontology, following the design of similar namespace + * classes in the Jena library, like {@link RDF}. + * + * @cdk.module iordf + * @cdk.githash + */ +public class CDK { + + public static final String URI ="http://cdk.sourceforge.net/model.owl#"; + + private static final Resource resource(String local) { + return ResourceFactory.createResource(URI + local); + } + + private static final Property property(String local) { + return ResourceFactory.createProperty(URI, local); + } + + public static final Resource MOLECULE = resource("Molecule"); + public static final Resource ATOM = resource("Atom"); + public static final Resource PSEUDOATOM = resource("PseudoAtom"); + public static final Resource BOND = resource("Bond"); + public static final Resource CHEMOBJECT = resource("ChemObject"); + public static final Resource ELEMENT = resource("Element"); + public static final Resource ATOMTYPE = resource("AtomType"); + public static final Resource ISOTOPE = resource("Isotope"); + + // IBond.Order + public static final Resource SINGLEBOND = resource("SingleBond"); + public static final Resource DOUBLEBOND = resource("DoubleBond"); + public static final Resource TRIPLEBOND = resource("TripleBond"); + public static final Resource QUADRUPLEBOND = resource("QuadrupleBond"); + + // IAtomType.Hybridization + public static final Resource HYBRID_S = resource("S"); + public static final Resource HYBRID_SP1 = resource("SP1"); + public static final Resource HYBRID_SP2 = resource("SP2"); + public static final Resource HYBRID_SP3 = resource("SP3"); + public static final Resource HYBRID_PLANAR3 = resource("PLANAR3"); + public static final Resource HYBRID_SP3D1 = resource("SP3D1"); + public static final Resource HYBRID_SP3D2 = resource("SP3D2"); + public static final Resource HYBRID_SP3D3 = resource("SP3D3"); + public static final Resource HYBRID_SP3D4 = resource("SP3D4"); + public static final Resource HYBRID_SP3D5 = resource("SP3D5"); + + public static final Property HASATOM = property("hasAtom"); + public static final Property HASBOND = property("hasBond"); + public static final Property BINDSATOM = property("bindsAtom"); + public static final Property HASORDER = property("hasOrder"); + public static final Property SYMBOL = property("symbol"); + public static final Property HASLABEL = property("hasLabel"); + public static final Property IDENTIFIER = property("identifier"); + public static final Property HASATOMICNUMBER = property("hasAtomicNumber"); + public static final Property HASHYBRIDIZATION = property("hasHybridization"); + public static final Property HASATOMTYPENAME = property("hasAtomTypeName"); + public static final Property HASMAXBONDORDER = property("hasMaxBondOrder"); + public static final Property HASFORMALCHARGE = property("hasFormalCharge"); + public static final Property HASMASSNUMBER = property("hasMassNumber"); + public static final Property HASEXACTMASS = property("hasExactMass"); + public static final Property HASNATURALABUNDANCE = + property("hasNaturalAbundance"); + public static final Property HASELECTRONCOUNT = + property("hasElectronCount"); + +} \ No newline at end of file diff --git a/src/main/org/openscience/cdk/libio/jena/Convertor.java b/src/main/org/openscience/cdk/libio/jena/Convertor.java new file mode 100644 index 00000000000..e372699de43 --- /dev/null +++ b/src/main/org/openscience/cdk/libio/jena/Convertor.java @@ -0,0 +1,403 @@ +/* Copyright (C) 2009 Egon Willighagen + * + * Contact: jchempaint-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.libio.jena; + +import java.util.HashMap; +import java.util.Map; + +import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomType; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemObject; +import org.openscience.cdk.interfaces.IChemObjectBuilder; +import org.openscience.cdk.interfaces.IElectronContainer; +import org.openscience.cdk.interfaces.IElement; +import org.openscience.cdk.interfaces.IIsotope; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.interfaces.IPseudoAtom; +import org.openscience.cdk.interfaces.IAtomType.Hybridization; +import org.openscience.cdk.interfaces.IBond.Order; + +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.ResIterator; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.Statement; +import com.hp.hpl.jena.rdf.model.StmtIterator; +import com.hp.hpl.jena.vocabulary.RDF; + +/** + * Helper class that converts a CDK {@link IChemObject} into RDF using a + * Jena model and the CDK data model ontology. + * + * @cdk.module iordf + * @cdk.githash + * @cdk.keyword Resource Description Framework + * @cdk.keyword Jena + * @cdk.keyword RDF + * @cdk.keyword Web Ontology Language + * @cdk.keyword OWL + */ +public class Convertor { + + /** + * Converts a {@link IMolecule} into a {@link Model} representation using the CDK OWL. + * + * @param molecule {@link IMolecule} to serialize into a RDF graph. + * @return the RDF graph representing the {@link IMolecule}. + */ + public static Model molecule2Model(IMolecule molecule) { + Model model = createCDKModel(); + Resource subject = model.createResource( + createIdentifier(model, molecule) + ); + model.add(subject, RDF.type, CDK.MOLECULE); + Map cdkToRDFAtomMap = new HashMap(); + for (IAtom atom : molecule.atoms()) { + Resource rdfAtom = model.createResource( + createIdentifier(model, atom) + ); + cdkToRDFAtomMap.put(atom, rdfAtom); + model.add(subject, CDK.HASATOM, rdfAtom); + if (atom instanceof IPseudoAtom) { + model.add(rdfAtom, RDF.type, CDK.PSEUDOATOM); + serializePseudoAtomFields(model, rdfAtom, (IPseudoAtom)atom); + } else { + model.add(rdfAtom, RDF.type, CDK.ATOM); + serializeAtomFields(model, rdfAtom, atom); + } + } + for (IBond bond : molecule.bonds()) { + Resource rdfBond = model.createResource( + createIdentifier(model, bond) + ); + model.add(rdfBond, RDF.type, CDK.BOND); + for (IAtom atom : bond.atoms()) { + model.add(rdfBond, CDK.BINDSATOM, cdkToRDFAtomMap.get(atom)); + } + if (bond.getOrder() != null) { + model.add( + rdfBond, CDK.HASORDER, + order2Resource(bond.getOrder()) + ); + } + model.add(subject, CDK.HASBOND, rdfBond); + serializeElectronContainerFields(model, rdfBond, bond); + } + return model; + } + + private static void serializePseudoAtomFields(Model model, + Resource rdfAtom, IPseudoAtom atom) { + serializeAtomFields(model, rdfAtom, atom); + if (atom.getLabel() != CDKConstants.UNSET) + model.add(rdfAtom, CDK.HASLABEL, atom.getLabel()); + } + + private static void serializeAtomFields(Model model, Resource rdfAtom, + IAtom atom) { + serializeAtomTypeFields(model, rdfAtom, atom); + model.add(rdfAtom, RDF.type, CDK.ATOM); + if (atom.getSymbol() != CDKConstants.UNSET) + model.add(rdfAtom, CDK.SYMBOL, atom.getSymbol()); + } + + private static void serializeElectronContainerFields(Model model, + Resource rdfBond, IElectronContainer bond) { + serializeChemObjectFields(model, rdfBond, bond); + if (bond.getElectronCount() != null) + model.add( + rdfBond, CDK.HASELECTRONCOUNT, + bond.getElectronCount().toString() + ); + } + + private static void serializeChemObjectFields(Model model, + Resource rdfObject, IChemObject object) { + if (object.getID() != null) + model.add(rdfObject, CDK.IDENTIFIER, object.getID()); + } + + private static void deserializeChemObjectFields( + Resource rdfObject, IChemObject object) { + Statement identifier = rdfObject.getProperty(CDK.IDENTIFIER); + if (identifier != null) object.setID(identifier.getString()); + } + + private static void serializeElementFields(Model model, + Resource rdfObject, IElement element) { + serializeChemObjectFields(model, rdfObject, element); + if (element.getSymbol() != null) + model.add(rdfObject, CDK.SYMBOL, element.getSymbol()); + if (element.getAtomicNumber() != null) + model.add(rdfObject, CDK.HASATOMICNUMBER, + element.getAtomicNumber().toString()); + } + + private static void deserializeElementFields( + Resource rdfObject, IElement element) { + deserializeChemObjectFields(rdfObject, element); + Statement symbol = rdfObject.getProperty(CDK.SYMBOL); + if (symbol != null) element.setSymbol(symbol.getString()); + Statement atomicNumber = rdfObject.getProperty(CDK.HASATOMICNUMBER); + if (atomicNumber != null) + element.setAtomicNumber(atomicNumber.getInt()); + } + + private final static Map HYBRID_TO_RESOURCE = new HashMap(10) { + private static final long serialVersionUID = 1027415392461000485L; + { + put(Hybridization.S, CDK.HYBRID_S); + put(Hybridization.SP1, CDK.HYBRID_SP1); + put(Hybridization.SP2, CDK.HYBRID_SP2); + put(Hybridization.SP3, CDK.HYBRID_SP3); + put(Hybridization.PLANAR3, CDK.HYBRID_PLANAR3); + put(Hybridization.SP3D1, CDK.HYBRID_SP3D1); + put(Hybridization.SP3D2, CDK.HYBRID_SP3D2); + put(Hybridization.SP3D3, CDK.HYBRID_SP3D3); + put(Hybridization.SP3D4, CDK.HYBRID_SP3D4); + put(Hybridization.SP3D5, CDK.HYBRID_SP3D5); + }}; + + private static void serializeAtomTypeFields(Model model, + Resource rdfObject, IAtomType type) { + serializeIsotopeFields(model, rdfObject, type); + if (type.getHybridization() != null) { + Hybridization hybrid = type.getHybridization(); + if (HYBRID_TO_RESOURCE.containsKey(hybrid)) + model.add(rdfObject, CDK.HASHYBRIDIZATION, HYBRID_TO_RESOURCE.get(hybrid)); + } + if (type.getAtomTypeName() != null) { + model.add(rdfObject, CDK.HASATOMTYPENAME, type.getAtomTypeName()); + } + if (type.getFormalCharge() != null) { + model.add( + rdfObject, CDK.HASFORMALCHARGE, + type.getFormalCharge().toString() + ); + } + if (type.getMaxBondOrder() != null) { + model.add( + rdfObject, CDK.HASMAXBONDORDER, + order2Resource(type.getMaxBondOrder()) + ); + } + } + + private static void serializeIsotopeFields(Model model, Resource rdfObject, + IIsotope isotope) { + serializeElementFields(model, rdfObject, isotope); + if (isotope.getMassNumber() != CDKConstants.UNSET) { + model.add( + rdfObject, CDK.HASMASSNUMBER, + isotope.getMassNumber().toString() + ); + } + if (isotope.getExactMass() != CDKConstants.UNSET) { + model.add( + rdfObject, CDK.HASEXACTMASS, + isotope.getExactMass().toString() + ); + } + if (isotope.getNaturalAbundance() != CDKConstants.UNSET) { + model.add( + rdfObject, CDK.HASNATURALABUNDANCE, + isotope.getNaturalAbundance().toString() + ); + } + } + + private final static Map RESOURCE_TO_HYBRID = new HashMap(10) { + private static final long serialVersionUID = -351285511820100853L; + { + put(CDK.HYBRID_S, Hybridization.S); + put(CDK.HYBRID_SP1, Hybridization.SP1); + put(CDK.HYBRID_SP2, Hybridization.SP2); + put(CDK.HYBRID_SP3, Hybridization.SP3); + put(CDK.HYBRID_PLANAR3, Hybridization.PLANAR3); + put(CDK.HYBRID_SP3D1, Hybridization.SP3D1); + put(CDK.HYBRID_SP3D2, Hybridization.SP3D2); + put(CDK.HYBRID_SP3D3, Hybridization.SP3D3); + put(CDK.HYBRID_SP3D4, Hybridization.SP3D4); + put(CDK.HYBRID_SP3D5, Hybridization.SP3D5); + }}; + + private static void deserializeAtomTypeFields( + Resource rdfObject, IAtomType element) { + deserializeIsotopeFields(rdfObject, element); + Statement hybrid = rdfObject.getProperty(CDK.HASHYBRIDIZATION); + if (hybrid != null) { + Resource rdfHybrid = (Resource)hybrid.getObject(); + if (RESOURCE_TO_HYBRID.containsKey(rdfHybrid)) { + element.setHybridization(RESOURCE_TO_HYBRID.get(rdfHybrid)); + } + } + Statement name = rdfObject.getProperty(CDK.HASATOMTYPENAME); + if (name != null) { + element.setAtomTypeName(name.getString()); + } + Statement order = rdfObject.getProperty(CDK.HASMAXBONDORDER); + if (order != null) { + Resource maxOrder = (Resource)order.getResource(); + element.setMaxBondOrder(resource2Order(maxOrder)); + } + Statement formalCharge = rdfObject.getProperty(CDK.HASFORMALCHARGE); + if (formalCharge != null) + element.setFormalCharge(formalCharge.getInt()); + } + + private static void deserializeIsotopeFields(Resource rdfObject, + IIsotope isotope) { + deserializeElementFields(rdfObject, isotope); + Statement massNumber = rdfObject.getProperty(CDK.HASMASSNUMBER); + if (massNumber != null) + isotope.setMassNumber(massNumber.getInt()); + Statement exactMass = rdfObject.getProperty(CDK.HASEXACTMASS); + if (exactMass != null) + isotope.setExactMass(exactMass.getDouble()); + Statement naturalAbundance = + rdfObject.getProperty(CDK.HASNATURALABUNDANCE); + if (naturalAbundance != null) + isotope.setNaturalAbundance(naturalAbundance.getDouble()); + } + + /** + * Converts a {@link Resource} object into the matching {@link Order}. + * + * @param rdfOrder Resource for which the matching {@link Order} should be given. + * @return the matching {@link Order}. + */ + public static Order resource2Order(Resource rdfOrder) { + if (rdfOrder.equals(CDK.SINGLEBOND)) { + return Order.SINGLE; + } else if (rdfOrder.equals(CDK.DOUBLEBOND)) { + return Order.DOUBLE; + } else if (rdfOrder.equals(CDK.TRIPLEBOND)) { + return Order.TRIPLE; + } else if (rdfOrder.equals(CDK.QUADRUPLEBOND)) { + return Order.QUADRUPLE; + } + return null; + } + + /** + * Create the {@link Resource} matching the given {@link Order}. + * + * @param order bond order to return the matching {@link Resource} for. + * @return the matching {@link Resource}. + */ + public static Resource order2Resource(Order order) { + if (order == Order.SINGLE) { + return CDK.SINGLEBOND; + } else if (order == Order.DOUBLE) { + return CDK.DOUBLEBOND; + } else if (order == Order.TRIPLE) { + return CDK.TRIPLEBOND; + } else if (order == Order.QUADRUPLE) { + return CDK.QUADRUPLEBOND; + } + return null; + } + + private static String createIdentifier(Model model, IChemObject object) { + StringBuilder result = new StringBuilder(); + result.append("http://example.com/"); + result.append(model.hashCode()).append('/'); + result.append(object.getClass().getSimpleName()).append('/'); + result.append(object.hashCode()); + return result.toString(); + } + + private static void deserializeElectronContainerFields( + Resource rdfObject, IElectronContainer bond) { + deserializeChemObjectFields(rdfObject, bond); + Statement count = rdfObject.getProperty(CDK.HASELECTRONCOUNT); + if (count != null) + bond.setElectronCount(count.getInt()); + } + + /** + * Converts a {@link Model} into an {@link IMolecule} using the given {@link IChemObjectBuilder}. + * + * @param model RDF graph to deserialize into an {@link IMolecule}. + * @param builder {@link IChemObjectBuilder} used to create new {@link IChemObject}s. + * @return a {@link IMolecule} deserialized from the RDF graph. + */ + public static IMolecule model2Molecule(Model model, + IChemObjectBuilder builder) { + ResIterator mols = + model.listSubjectsWithProperty(RDF.type, CDK.MOLECULE); + IMolecule mol = null; + if (mols.hasNext()) { + Resource rdfMol = mols.next(); + mol = builder.newInstance(IMolecule.class); + Map rdfToCDKAtomMap = new HashMap(); + StmtIterator atoms = rdfMol.listProperties(CDK.HASATOM); + while (atoms.hasNext()) { + Resource rdfAtom = atoms.nextStatement().getResource(); + IAtom atom; + if (rdfAtom.hasProperty(RDF.type, CDK.PSEUDOATOM)) { + atom = builder.newInstance(IPseudoAtom.class); + atom.setStereoParity(0); + Statement label = rdfAtom.getProperty(CDK.HASLABEL); + if (label != null) + ((IPseudoAtom)atom).setLabel(label.getString()); + } else { + atom = builder.newInstance(IAtom.class); + } + Statement symbol = rdfAtom.getProperty(CDK.SYMBOL); + if (symbol != null) atom.setSymbol(symbol.getString()); + rdfToCDKAtomMap.put(rdfAtom, atom); + deserializeAtomTypeFields(rdfAtom, atom); + mol.addAtom(atom); + } + StmtIterator bonds = rdfMol.listProperties(CDK.HASBOND); + while (bonds.hasNext()) { + Resource rdfBond = bonds.nextStatement().getResource(); + IBond bond = builder.newInstance(IBond.class); + StmtIterator bondAtoms = rdfBond.listProperties(CDK.BINDSATOM); + int atomCounter = 0; + while (bondAtoms.hasNext()) { + Statement rdfAtom = bondAtoms.nextStatement(); + IAtom atom = rdfToCDKAtomMap.get(rdfAtom.getResource()); + bond.setAtom(atom, atomCounter); + atomCounter++; + } + Resource order = rdfBond. + getProperty(CDK.HASORDER).getResource(); + bond.setOrder(resource2Order(order)); + mol.addBond(bond); + deserializeElectronContainerFields(rdfBond, bond); + } + } + return mol; + } + + private static Model createCDKModel() { + Model model = ModelFactory.createOntologyModel(); + model.setNsPrefix("cdk", "http://cdk.sourceforge.net/model.owl#"); + return model; + } + +} diff --git a/src/main/org/openscience/cdk/qsar/descriptors/molecular/FMFDescriptor.java b/src/main/org/openscience/cdk/qsar/descriptors/molecular/FMFDescriptor.java new file mode 100644 index 00000000000..ff8c51c08c4 --- /dev/null +++ b/src/main/org/openscience/cdk/qsar/descriptors/molecular/FMFDescriptor.java @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2010 Rajarshi Guha + * + * 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. + * + * 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.qsar.descriptors.molecular; + +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.fragment.MurckoFragmenter; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.qsar.DescriptorSpecification; +import org.openscience.cdk.qsar.DescriptorValue; +import org.openscience.cdk.qsar.IMolecularDescriptor; +import org.openscience.cdk.qsar.result.DoubleResult; +import org.openscience.cdk.qsar.result.DoubleResultType; +import org.openscience.cdk.qsar.result.IDescriptorResult; + +/** + * An implementation of the FMF descriptor characterizing complexity of a molecule. + *

+ * The descriptor is described in {@cdk.cite YANG2010} and is an approach to + * characterizing molecular complexity based on the Murcko framework present + * in the molecule. The descriptor is the ratio of heavy atoms in the framework to the + * total number of heavy atoms in the molecule. By definition, acyclic molecules + * which have no frameworks, will have a value of 0. + * + * Note that the authors consider an isolated ring system to be a framework (even + * though there is no linker). + * + * This descriptor returns a single double value, labeled as "FMF" + * + * @author Rajarshi Guha + * @cdk.module qsarmolecular + * @cdk.set qsar-descriptors + * @cdk.dictref qsar-descriptors:FMF + * @see org.openscience.cdk.fragment.MurckoFragmenter + */ +@TestClass("org.openscience.cdk.qsar.descriptors.molecular.FMFDescriptorTest") +public class FMFDescriptor implements IMolecularDescriptor { + + public FMFDescriptor() { + } + + + /** + * Calculates the FMF descriptor value for the given {@link IAtomContainer}. + * + * @param container An {@link org.openscience.cdk.interfaces.IAtomContainer} for which this descriptor + * should be calculated + * @return An object of {@link org.openscience.cdk.qsar.DescriptorValue} that contains the + * calculated FMF descriptor value as well as specification details + */ + @TestMethod("testCarbinoxamine,testIsamoltane,testPirenperone") + public DescriptorValue calculate(IAtomContainer container) { + MurckoFragmenter fragmenter = new MurckoFragmenter(true, 3); + DoubleResult result; + try { + fragmenter.generateFragments(container); + IAtomContainer[] framework = fragmenter.getFrameworksAsContainers(); + IAtomContainer[] ringSystems = fragmenter.getRingSystemsAsContainers(); + if (framework.length == 1) { + result = new DoubleResult(framework[0].getAtomCount() / (double) container.getAtomCount()); + } else if (framework.length == 0 && ringSystems.length == 1) { + result = new DoubleResult(ringSystems[0].getAtomCount() / (double) container.getAtomCount()); + } else result = new DoubleResult(0.0); + } catch (CDKException e) { + result = new DoubleResult(Double.NaN); + } + return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), result, + getDescriptorNames()); + + } + + /** + * Returns the specific type of the FMF descriptor value. + * + * The FMF descriptor is a single, double value. + * + * The return value from this method really indicates what type of result will + * be obtained from the {@link org.openscience.cdk.qsar.DescriptorValue} object. Note that the same result + * can be achieved by interrogating the {@link org.openscience.cdk.qsar.DescriptorValue} object; this method + * allows you to do the same thing, without actually calculating the descriptor. + *

+ *

Additionally, the length indicated by the result type must match the actual + * length of a descriptor calculated with the current parameters. Typically, the + * length of array result types vary with the values of the parameters. See + * {@link org.openscience.cdk.qsar.IDescriptor} for more details. + * + * @return an instance of the {@link org.openscience.cdk.qsar.result.DoubleResultType} + */ + public IDescriptorResult getDescriptorResultType() { + return new DoubleResultType(); + } + + /** + * Returns a Map which specifies which descriptor + * is implemented by this class. + *

+ * These fields are used in the map: + *

    + *
  • Specification-Reference: refers to an entry in a unique dictionary + *
  • Implementation-Title: anything + *
  • Implementation-Identifier: a unique identifier for this version of + * this class + *
  • Implementation-Vendor: CDK, JOELib, or anything else + *
+ * + * @return An object containing the descriptor specification + */ + public DescriptorSpecification getSpecification() { + return new DescriptorSpecification( + "http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#fmf", + this.getClass().getName(), + "$Id$", + "The Chemistry Development Kit"); + } + + /** + * Returns the names of the parameters for this descriptor. + * + * Since this descriptor takes no parameters, null is returned + * + * @return null, since there are no parameters + */ + public String[] getParameterNames() { + return null; + } + + /** + * Returns a class matching that of the parameter with the given name. + * + * Since this descriptor has no parameters, null is always returned + * + * @param name The name of the parameter whose type is requested + * @return null, since this descriptor has no parameters + */ + public Object getParameterType(String name) { + return null; + } + + /** + * Sets the parameters for this descriptor. + *

+ * This method does nothing, since the descriptor has no parameters + * + * @param params An array of Object containing the parameters for this descriptor + * @throws org.openscience.cdk.exception.CDKException + * if invalid number of type of parameters are passed to it + * @see #getParameters + */ + public void setParameters(Object[] params) throws CDKException { + } + + /** + * Returns the current parameter values. + * + * null is returned since the descriptor has no parameters + * @return null, since there are no parameters + * @see #setParameters + */ + public Object[] getParameters() { + return null; + } + + /** + * Returns an array of names for each descriptor value calculated. + *

+ * Since this descriptor returns a single value, the array has a single element, + * viz., "FMF" + * @return A 1-element string array, with the value "FMF" + */ + public String[] getDescriptorNames() { + return new String[]{"FMF"}; + } +} diff --git a/src/test/data/mdl/boronBuckyBall.mol b/src/test/data/mdl/boronBuckyBall.mol new file mode 100644 index 00000000000..20cdcee0e83 --- /dev/null +++ b/src/test/data/mdl/boronBuckyBall.mol @@ -0,0 +1,297 @@ + + CDK 12/18/09,15:29 + + 80210 0 0 0 0 0 0 0 0999 V2000 + -0.3637 4.0495 1.3474 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.7474 3.3091 2.0890 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.9201 3.0169 0.8453 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.2629 3.5789 -0.6621 B 0 0 0 0 0 0 0 0 0 0 0 0 + -0.6814 4.2189 -0.3519 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.5821 3.9816 -1.4933 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.1769 3.5719 -0.9460 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.4913 3.4047 0.7356 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.2166 3.6445 1.8883 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.4263 2.4963 3.1745 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.0553 1.7636 3.9082 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.5397 2.1724 3.3618 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.5045 0.7298 3.4053 B 0 0 0 0 0 0 0 0 0 0 0 0 + -3.6673 0.4397 2.1731 B 0 0 0 0 0 0 0 0 0 0 0 0 + -3.8756 1.5890 0.8871 B 0 0 0 0 0 0 0 0 0 0 0 0 + -4.1812 0.7094 -0.5760 B 0 0 0 0 0 0 0 0 0 0 0 0 + -3.5308 1.2645 -2.0670 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.5671 2.7067 -2.1117 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.2921 2.4669 -3.2665 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.2759 3.1015 -2.9592 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.6827 2.1481 -3.3188 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.8564 2.4392 -2.0732 B 0 0 0 0 0 0 0 0 0 0 0 0 + 3.8425 1.1512 -1.5043 B 0 0 0 0 0 0 0 0 0 0 0 0 + 4.1590 0.9830 0.1944 B 0 0 0 0 0 0 0 0 0 0 0 0 + 3.4867 2.1049 1.3091 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.8304 1.5442 2.8158 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.8523 -0.1324 3.1937 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.4687 -0.8743 3.9353 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.0763 0.0691 4.2909 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.5070 -0.5708 3.9808 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.6825 -2.1475 3.3180 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.8568 -2.4392 2.0731 B 0 0 0 0 0 0 0 0 0 0 0 0 + -3.8437 -1.1516 1.5046 B 0 0 0 0 0 0 0 0 0 0 0 0 + -4.1597 -0.9833 -0.1941 B 0 0 0 0 0 0 0 0 0 0 0 0 + -3.4865 -2.1050 -1.3087 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.8294 -1.5438 -2.8150 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.8515 0.1328 -3.1927 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.4682 0.8745 -3.9353 B 0 0 0 0 0 0 0 0 0 0 0 0 + -0.0759 -0.0689 -4.2914 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.5073 0.5714 -3.9818 B 0 0 0 0 0 0 0 0 0 0 0 0 + 3.6660 -0.4396 -2.1732 B 0 0 0 0 0 0 0 0 0 0 0 0 + 3.8749 -1.5882 -0.8869 B 0 0 0 0 0 0 0 0 0 0 0 0 + 4.1808 -0.7093 0.5766 B 0 0 0 0 0 0 0 0 0 0 0 0 + 3.5310 -1.2647 2.0677 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.5673 -2.7070 2.1116 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.2922 -2.4666 3.2660 B 0 0 0 0 0 0 0 0 0 0 0 0 + -0.2759 -3.1008 2.9584 B 0 0 0 0 0 0 0 0 0 0 0 0 + -0.5820 -3.9816 1.4930 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.1770 -3.5721 0.9462 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.4915 -3.4049 -0.7353 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.2167 -3.6446 -1.8883 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.4257 -2.4959 -3.1742 B 0 0 0 0 0 0 0 0 0 0 0 0 + -0.0548 -1.7634 -3.9080 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.5399 -2.1732 -3.3617 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.7474 -3.3097 -2.0888 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.9204 -3.0168 -0.8452 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.2630 -3.5791 0.6618 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.6814 -4.2193 0.3517 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.3634 -4.0501 -1.3477 B 0 0 0 0 0 0 0 0 0 0 0 0 + -0.1136 -1.6520 3.9523 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.5829 0.8845 3.8734 B 0 0 0 0 0 0 0 0 0 0 0 0 + -0.1721 3.1685 2.8645 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.9541 2.0450 2.3181 B 0 0 0 0 0 0 0 0 0 0 0 0 + -3.5135 2.3375 -0.6688 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.0809 3.6439 -1.9706 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.9849 4.1555 0.2157 B 0 0 0 0 0 0 0 0 0 0 0 0 + 3.4549 2.4802 -0.4143 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.9187 0.9335 -2.9900 B 0 0 0 0 0 0 0 0 0 0 0 0 + 3.5134 -2.3376 0.6690 B 0 0 0 0 0 0 0 0 0 0 0 0 + -3.4554 -2.4806 0.4144 B 0 0 0 0 0 0 0 0 0 0 0 0 + -2.9192 -0.9334 2.9896 B 0 0 0 0 0 0 0 0 0 0 0 0 + -3.8222 -0.4596 -1.8445 B 0 0 0 0 0 0 0 0 0 0 0 0 + -0.9851 -4.1559 -0.2157 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.1723 -3.1689 -2.8645 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.9537 -2.0450 -2.3180 B 0 0 0 0 0 0 0 0 0 0 0 0 + 1.0810 -3.6440 1.9702 B 0 0 0 0 0 0 0 0 0 0 0 0 + 3.8227 0.4596 1.8450 B 0 0 0 0 0 0 0 0 0 0 0 0 + 0.1138 1.6525 -3.9533 B 0 0 0 0 0 0 0 0 0 0 0 0 + -1.5820 -0.8843 -3.8728 B 0 0 0 0 0 0 0 0 0 0 0 0 + 2.5037 -0.7298 -3.4058 B 0 0 0 0 0 0 0 0 0 0 0 0 + 12 2 1 0 0 0 0 + 3 2 1 0 0 0 0 + 13 12 1 0 0 0 0 + 15 3 1 0 0 0 0 + 14 15 1 0 0 0 0 + 4 3 1 0 0 0 0 + 16 15 1 0 0 0 0 + 18 4 1 0 0 0 0 + 17 18 1 0 0 0 0 + 6 5 1 0 0 0 0 + 4 5 1 0 0 0 0 + 20 6 1 0 0 0 0 + 19 18 1 0 0 0 0 + 9 1 1 0 0 0 0 + 5 1 1 0 0 0 0 + 8 9 1 0 0 0 0 + 7 6 1 0 0 0 0 + 2 1 1 0 0 0 0 + 10 9 1 0 0 0 0 + 11 12 1 0 0 0 0 + 26 10 1 0 0 0 0 + 11 10 1 0 0 0 0 + 27 26 1 0 0 0 0 + 29 11 1 0 0 0 0 + 28 29 1 0 0 0 0 + 30 13 1 0 0 0 0 + 14 13 1 0 0 0 0 + 31 30 1 0 0 0 0 + 33 14 1 0 0 0 0 + 32 33 1 0 0 0 0 + 34 16 1 0 0 0 0 + 17 16 1 0 0 0 0 + 35 34 1 0 0 0 0 + 37 17 1 0 0 0 0 + 36 37 1 0 0 0 0 + 21 20 1 0 0 0 0 + 19 20 1 0 0 0 0 + 40 21 1 0 0 0 0 + 38 19 1 0 0 0 0 + 39 38 1 0 0 0 0 + 25 8 1 0 0 0 0 + 7 8 1 0 0 0 0 + 24 25 1 0 0 0 0 + 22 7 1 0 0 0 0 + 23 22 1 0 0 0 0 + 25 26 1 0 0 0 0 + 29 30 1 0 0 0 0 + 33 34 1 0 0 0 0 + 37 38 1 0 0 0 0 + 21 22 1 0 0 0 0 + 27 44 1 0 0 0 0 + 28 27 1 0 0 0 0 + 28 46 1 0 0 0 0 + 45 46 1 0 0 0 0 + 44 45 1 0 0 0 0 + 57 45 1 0 0 0 0 + 31 47 1 0 0 0 0 + 32 31 1 0 0 0 0 + 32 49 1 0 0 0 0 + 48 49 1 0 0 0 0 + 47 48 1 0 0 0 0 + 58 48 1 0 0 0 0 + 24 43 1 0 0 0 0 + 23 24 1 0 0 0 0 + 23 41 1 0 0 0 0 + 42 41 1 0 0 0 0 + 43 42 1 0 0 0 0 + 56 42 1 0 0 0 0 + 40 80 1 0 0 0 0 + 39 40 1 0 0 0 0 + 39 53 1 0 0 0 0 + 54 53 1 0 0 0 0 + 80 54 1 0 0 0 0 + 55 54 1 0 0 0 0 + 35 50 1 0 0 0 0 + 36 35 1 0 0 0 0 + 36 52 1 0 0 0 0 + 51 52 1 0 0 0 0 + 50 51 1 0 0 0 0 + 59 51 1 0 0 0 0 + 43 44 1 0 0 0 0 + 46 47 1 0 0 0 0 + 49 50 1 0 0 0 0 + 52 53 1 0 0 0 0 + 80 41 1 0 0 0 0 + 56 57 1 0 0 0 0 + 57 58 1 0 0 0 0 + 58 59 1 0 0 0 0 + 59 55 1 0 0 0 0 + 55 56 1 0 0 0 0 + 56 69 1 0 0 0 0 + 69 57 1 0 0 0 0 + 37 72 1 0 0 0 0 + 72 36 1 0 0 0 0 + 72 35 1 0 0 0 0 + 72 34 1 0 0 0 0 + 17 72 1 0 0 0 0 + 16 72 1 0 0 0 0 + 42 69 1 0 0 0 0 + 43 69 1 0 0 0 0 + 44 69 1 0 0 0 0 + 69 45 1 0 0 0 0 + 23 67 1 0 0 0 0 + 24 67 1 0 0 0 0 + 25 67 1 0 0 0 0 + 22 67 1 0 0 0 0 + 7 67 1 0 0 0 0 + 8 67 1 0 0 0 0 + 7 66 1 0 0 0 0 + 8 66 1 0 0 0 0 + 6 66 1 0 0 0 0 + 5 66 1 0 0 0 0 + 1 66 1 0 0 0 0 + 9 66 1 0 0 0 0 + 1 62 1 0 0 0 0 + 9 62 1 0 0 0 0 + 10 62 1 0 0 0 0 + 11 62 1 0 0 0 0 + 2 62 1 0 0 0 0 + 12 62 1 0 0 0 0 + 14 71 1 0 0 0 0 + 33 71 1 0 0 0 0 + 13 71 1 0 0 0 0 + 30 71 1 0 0 0 0 + 31 71 1 0 0 0 0 + 32 71 1 0 0 0 0 + 20 65 1 0 0 0 0 + 6 65 1 0 0 0 0 + 5 65 1 0 0 0 0 + 19 65 1 0 0 0 0 + 18 65 1 0 0 0 0 + 4 65 1 0 0 0 0 + 18 64 1 0 0 0 0 + 17 64 1 0 0 0 0 + 4 64 1 0 0 0 0 + 3 64 1 0 0 0 0 + 15 64 1 0 0 0 0 + 16 64 1 0 0 0 0 + 3 63 1 0 0 0 0 + 15 63 1 0 0 0 0 + 14 63 1 0 0 0 0 + 13 63 1 0 0 0 0 + 2 63 1 0 0 0 0 + 12 63 1 0 0 0 0 + 10 61 1 0 0 0 0 + 26 61 1 0 0 0 0 + 27 61 1 0 0 0 0 + 28 61 1 0 0 0 0 + 11 61 1 0 0 0 0 + 29 61 1 0 0 0 0 + 68 21 1 0 0 0 0 + 68 40 1 0 0 0 0 + 68 80 1 0 0 0 0 + 41 68 1 0 0 0 0 + 23 68 1 0 0 0 0 + 22 68 1 0 0 0 0 + 45 76 1 0 0 0 0 + 57 76 1 0 0 0 0 + 76 47 1 0 0 0 0 + 76 48 1 0 0 0 0 + 76 58 1 0 0 0 0 + 34 70 1 0 0 0 0 + 35 70 1 0 0 0 0 + 50 70 1 0 0 0 0 + 33 70 1 0 0 0 0 + 32 70 1 0 0 0 0 + 49 70 1 0 0 0 0 + 51 73 1 0 0 0 0 + 50 73 1 0 0 0 0 + 49 73 1 0 0 0 0 + 59 73 1 0 0 0 0 + 48 73 1 0 0 0 0 + 58 73 1 0 0 0 0 + 56 75 1 0 0 0 0 + 42 75 1 0 0 0 0 + 75 54 1 0 0 0 0 + 75 55 1 0 0 0 0 + 75 41 1 0 0 0 0 + 53 74 1 0 0 0 0 + 51 74 1 0 0 0 0 + 52 74 1 0 0 0 0 + 54 74 1 0 0 0 0 + 55 74 1 0 0 0 0 + 74 59 1 0 0 0 0 + 43 77 1 0 0 0 0 + 24 77 1 0 0 0 0 + 25 77 1 0 0 0 0 + 44 77 1 0 0 0 0 + 26 77 1 0 0 0 0 + 27 77 1 0 0 0 0 + 46 60 1 0 0 0 0 + 28 60 1 0 0 0 0 + 29 60 1 0 0 0 0 + 60 30 1 0 0 0 0 + 60 47 1 0 0 0 0 + 60 31 1 0 0 0 0 + 40 78 1 0 0 0 0 + 21 78 1 0 0 0 0 + 20 78 1 0 0 0 0 + 19 78 1 0 0 0 0 + 39 78 1 0 0 0 0 + 38 78 1 0 0 0 0 + 39 79 1 0 0 0 0 + 38 79 1 0 0 0 0 + 37 79 1 0 0 0 0 + 36 79 1 0 0 0 0 + 52 79 1 0 0 0 0 + 53 79 1 0 0 0 0 + 46 76 1 0 0 0 0 + 75 80 1 0 0 0 0 +M END + +$$$$ diff --git a/src/test/data/owl/molecule.n3 b/src/test/data/owl/molecule.n3 new file mode 100644 index 00000000000..73e531d26e6 --- /dev/null +++ b/src/test/data/owl/molecule.n3 @@ -0,0 +1,9 @@ +@prefix rdfs: . +@prefix cdk: . +@prefix owl: . +@prefix xsd: . +@prefix rdf: . + + + a . + diff --git a/src/test/org/openscience/cdk/aromaticity/CDKHueckelAromaticityDetectorTest.java b/src/test/org/openscience/cdk/aromaticity/CDKHueckelAromaticityDetectorTest.java index 3673bc66798..0ee70b4c2af 100644 --- a/src/test/org/openscience/cdk/aromaticity/CDKHueckelAromaticityDetectorTest.java +++ b/src/test/org/openscience/cdk/aromaticity/CDKHueckelAromaticityDetectorTest.java @@ -30,6 +30,7 @@ import org.openscience.cdk.DefaultChemObjectBuilder; import org.openscience.cdk.Molecule; import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.graph.SpanningTree; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IAtomType; @@ -50,6 +51,7 @@ import javax.vecmath.Point2d; import java.io.InputStream; import java.util.Iterator; +import java.util.List; /** * @author steinbeck @@ -872,5 +874,66 @@ public void testAromaticNOxideCharged() throws Exception { } } + /** + * @cdk.bug 3001616 + */ + @Test + public void test3001616() throws Exception { + SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); + IMolecule mol = sp.parseSmiles("OC(=O)N1C=NC2=CC=CC=C12"); + AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); + Assert.assertTrue(CDKHueckelAromaticityDetector.detectAromaticity(mol)); + for (IAtom atom : mol.atoms()) { + if (atom.getSymbol().equals("N")) { + Assert.assertTrue(atom.getFlag(CDKConstants.ISAROMATIC)); + List conbonds = mol.getConnectedBondsList(atom); + if (conbonds.size() == 2) { + Assert.assertTrue(conbonds.get(0).getFlag(CDKConstants.ISAROMATIC)); + Assert.assertTrue(conbonds.get(1).getFlag(CDKConstants.ISAROMATIC)); + } else if (conbonds.size() == 3) { + for (IBond bond : conbonds) { + if (bond.getOrder().equals(IBond.Order.SINGLE)) continue; + Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); + } + } + } + } + SpanningTree st = new SpanningTree(mol); + IRingSet ringSet = st.getAllRings(); + for (IAtomContainer ring : ringSet.atomContainers()) { + for (IBond bond : ring.bonds()) { + Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); + } + } + } + + /** + * @cdk.bug 2853035 + */ + @Test + public void testBug2853035() throws Exception { + SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); + IMolecule mol = sp.parseSmiles("C(=O)c1cnn2ccccc12"); + AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); + Assert.assertTrue(CDKHueckelAromaticityDetector.detectAromaticity(mol)); + for (IAtom atom : mol.atoms()) { + if (atom.getSymbol().equals("N")) { + Assert.assertTrue(atom.getFlag(CDKConstants.ISAROMATIC)); + List conbonds = mol.getConnectedBondsList(atom); + for (IBond bond : conbonds) { + if (bond.getOrder().equals(IBond.Order.SINGLE)) continue; + Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); + } + } + } + SpanningTree st = new SpanningTree(mol); + IRingSet ringSet = st.getAllRings(); + for (IAtomContainer ring : ringSet.atomContainers()) { + for (IBond bond : ring.bonds()) { + Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); + } + } + } + } diff --git a/src/test/org/openscience/cdk/coverage/CoverageAnnotationTest.java b/src/test/org/openscience/cdk/coverage/CoverageAnnotationTest.java index 220b208d48d..bb24dadcdd9 100644 --- a/src/test/org/openscience/cdk/coverage/CoverageAnnotationTest.java +++ b/src/test/org/openscience/cdk/coverage/CoverageAnnotationTest.java @@ -27,6 +27,7 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -90,10 +91,29 @@ private int checkClass(String className) { Class coreClass = loadClass(getClassName(className)); if (coreClass.isInterface()) return 0; - // lets get all the methods in the class we're checking - // we're going to skip private. int missingTestCount = 0; HashMap methodAnnotations = new HashMap(); + + // lets get all the constructors in the class we're checking + // we're going to skip private. + Constructor[] constructors = coreClass.getDeclaredConstructors(); + for (Constructor constructor : constructors) { + int modifiers = constructor.getModifiers(); + if (Modifier.isPrivate(modifiers)) continue; + + TestMethod testMethodAnnotation = (TestMethod)constructor.getAnnotation(TestMethod.class); + + if (constructor.getName().startsWith("access$")) { + // skip this test + } else if (testMethodAnnotation == null) { + // if a method does not have the annotation, it's missing a test + System.out.println(className + toString(constructor) + " does not have a test method"); + missingTestCount++; + } else methodAnnotations.put(constructor.getName(), testMethodAnnotation); + } + + // lets get all the methods in the class we're checking + // we're going to skip private. Method[] sourceMethods = coreClass.getDeclaredMethods(); for (Method method : sourceMethods) { int modifiers = method.getModifiers(); @@ -185,6 +205,19 @@ private String toString(Method method) { return methodString.toString(); } + private String toString(Constructor constructor) { + StringBuffer methodString = new StringBuffer(); + methodString.append('('); + Class[] classes = constructor.getParameterTypes(); + for (int i=0;i + * + * 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. + * + * 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.coverage; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @cdk.module test-sinchi + */ +public class SinchiCoverageTest extends CoverageAnnotationTest { + + private final static String CLASS_LIST = "sinchi.javafiles"; + + @BeforeClass public static void setUp() throws Exception { + loadClassList(CLASS_LIST, SinchiCoverageTest.class.getClassLoader()); + } + + @Test public void testCoverage() { + super.runCoverageTest(); + } +} diff --git a/src/test/org/openscience/cdk/fingerprint/FingerprinterTest.java b/src/test/org/openscience/cdk/fingerprint/FingerprinterTest.java index be6e492ef49..462fda5de0b 100644 --- a/src/test/org/openscience/cdk/fingerprint/FingerprinterTest.java +++ b/src/test/org/openscience/cdk/fingerprint/FingerprinterTest.java @@ -24,13 +24,10 @@ */ package org.openscience.cdk.fingerprint; -import java.io.InputStream; -import java.math.BigInteger; -import java.util.BitSet; - import org.junit.Assert; import org.junit.Test; import org.openscience.cdk.Atom; +import org.openscience.cdk.ChemFile; import org.openscience.cdk.Molecule; import org.openscience.cdk.Reaction; import org.openscience.cdk.exception.CDKException; @@ -38,13 +35,20 @@ import org.openscience.cdk.graph.AtomContainerBondPermutor; import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemFile; import org.openscience.cdk.interfaces.IMolecule; import org.openscience.cdk.interfaces.IReaction; import org.openscience.cdk.io.IChemObjectReader.Mode; import org.openscience.cdk.io.MDLRXNV2000Reader; +import org.openscience.cdk.io.MDLV2000Reader; import org.openscience.cdk.templates.MoleculeFactory; import org.openscience.cdk.tools.ILoggingTool; import org.openscience.cdk.tools.LoggingToolFactory; +import org.openscience.cdk.tools.manipulator.ChemFileManipulator; + +import java.io.InputStream; +import java.math.BigInteger; +import java.util.BitSet; /** * @cdk.module test-standard @@ -158,6 +162,21 @@ public void testBug1851202() throws Exception { Assert.assertNotNull(bs2); } + @Test + public void testbug2917084() throws Exception { + String filename1 = "data/mdl/boronBuckyBall.mol"; + logger.info("Testing: " + filename1); + InputStream ins1 = this.getClass().getClassLoader().getResourceAsStream(filename1); + MDLV2000Reader reader = new MDLV2000Reader(ins1, Mode.STRICT); + IChemFile chemFile = reader.read(new ChemFile()); + Assert.assertNotNull(chemFile); + IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); + + Fingerprinter fingerprinter = new Fingerprinter(); + BitSet bs1 = fingerprinter.getFingerprint(mol); + Assert.assertNotNull(bs1); + } + /** * @cdk.bug 2819557 * @throws org.openscience.cdk.exception.CDKException diff --git a/src/test/org/openscience/cdk/fingerprint/SubstructureFingerprinterTest.java b/src/test/org/openscience/cdk/fingerprint/SubstructureFingerprinterTest.java index 569b984c29b..15eaa1bd2c6 100644 --- a/src/test/org/openscience/cdk/fingerprint/SubstructureFingerprinterTest.java +++ b/src/test/org/openscience/cdk/fingerprint/SubstructureFingerprinterTest.java @@ -28,14 +28,14 @@ */ package org.openscience.cdk.fingerprint; -import java.util.BitSet; - import org.junit.Assert; import org.junit.Test; import org.openscience.cdk.DefaultChemObjectBuilder; import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.smiles.SmilesParser; +import java.util.BitSet; + /** * @cdk.module test-fingerprint */ @@ -87,5 +87,22 @@ public void testFingerprint() throws Exception { Assert.assertTrue(fp.get(1)); Assert.assertFalse(fp.get(100)); } + + /** + * @cdk.bug 2871303 + * + * While this test fails, Daylight says that the + * SMARTS pattern used for vinylogous ester should + * match benzaldehyde twice. So according to the + * supplied definition this answer is actually correct. + */ + @Test + public void testVinylogousEster() throws Exception { + String benzaldehyde = "c1ccccc1C=O"; + IFingerprinter fprinter = new SubstructureFingerprinter(); + SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); + BitSet fp = fprinter.getFingerprint(sp.parseSmiles(benzaldehyde)); + Assert.assertFalse("Bit 136 (vinylogous ester) is set to true", fp.get(136)); + } } diff --git a/src/test/org/openscience/cdk/fragment/MurckoFragmenterTest.java b/src/test/org/openscience/cdk/fragment/MurckoFragmenterTest.java index 26c5bccd208..3efda833539 100644 --- a/src/test/org/openscience/cdk/fragment/MurckoFragmenterTest.java +++ b/src/test/org/openscience/cdk/fragment/MurckoFragmenterTest.java @@ -200,7 +200,7 @@ public void testCarbinoxamine_Bug3088164() throws Exception { fragmenter.generateFragments(mol); String[] f = fragmenter.getFrameworks(); - IAtomContainer[] fc = fragmenter.getFragmentsAsContainers(); + IAtomContainer[] fc = fragmenter.getFrameworksAsContainers(); Assert.assertEquals(1, f.length); Assert.assertEquals(f.length, fc.length); Assert.assertEquals("c1ccc(cc1)Cc2ncccc2", f[0]); @@ -219,17 +219,17 @@ public void testCarbinoxamine_Bug3088164() throws Exception { public void testPirenperone_Bug3088164() throws Exception { SmilesGenerator sg = new SmilesGenerator(true); - IAtomContainer mol = smilesParser.parseSmiles("Fc1ccc(cc1)C(=O)C4CCN(CCC\\3=C(\\N=C2\\C=C/C=C\\N2C/3=O"); + IAtomContainer mol = smilesParser.parseSmiles("Fc1ccc(cc1)C(=O)C4CCN(CCC\\3=C(\\N=C2\\C=C/C=C\\N2C/3=O)C)CC4"); CDKHueckelAromaticityDetector.detectAromaticity(mol); MurckoFragmenter fragmenter = new MurckoFragmenter(true, 6); fragmenter.generateFragments(mol); String[] f = fragmenter.getFrameworks(); - IAtomContainer[] fc = fragmenter.getFragmentsAsContainers(); + IAtomContainer[] fc = fragmenter.getFrameworksAsContainers(); Assert.assertEquals(1, f.length); Assert.assertEquals(f.length, fc.length); - Assert.assertEquals("N=1C=C(CN2C=CC=CC=12)CCN4CCC(Cc3ccccc3)CC4", f[0]); + Assert.assertEquals("C=1N=C4C=CC=CN4(CC=1CCN3CCC(Cc2ccccc2)CC3)", f[0]); for (int i = 0; i < f.length; i++) { String newsmiles = sg.createSMILES(fc[i]); @@ -250,7 +250,7 @@ public void testIsomoltane_Bug3088164() throws Exception { fragmenter.generateFragments(mol); String[] f = fragmenter.getFrameworks(); - IAtomContainer[] fc = fragmenter.getFragmentsAsContainers(); + IAtomContainer[] fc = fragmenter.getFrameworksAsContainers(); Assert.assertEquals(1, f.length); Assert.assertEquals(f.length, fc.length); Assert.assertEquals("c1ccccc1n2cccc2", f[0]); diff --git a/src/test/org/openscience/cdk/inchi/standard/InChIGeneratorTest.java b/src/test/org/openscience/cdk/inchi/standard/InChIGeneratorTest.java new file mode 100644 index 00000000000..85329fd88d5 --- /dev/null +++ b/src/test/org/openscience/cdk/inchi/standard/InChIGeneratorTest.java @@ -0,0 +1,330 @@ +/* Copyright (C) 2006-2007 Sam Adams + * 2010 Egon Willighagen + * + * 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. + * + * 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.inchi.standard; + +import net.sf.jniinchi.INCHI_RET; +import org.junit.Assert; +import org.junit.Test; +import org.openscience.cdk.*; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; + +import javax.vecmath.Point2d; +import javax.vecmath.Point3d; + +/** + * TestCase for the {@link InChIGenerator}. + * + * @cdk.module test-sinchi + */ +public class InChIGeneratorTest extends CDKTestCase { + + protected InChIGeneratorFactory factory; + + protected InChIGeneratorFactory getFactory() throws Exception { + if (factory == null) { + factory = InChIGeneratorFactory.getInstance(); + } + return(factory); + } + + + /** + * Tests element name is correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiFromChlorineAtom() throws Exception { + IAtomContainer ac = new AtomContainer(); + ac.addAtom(new Atom("Cl")); + InChIGenerator gen = getFactory().getInChIGenerator(ac); + Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus()); + Assert.assertEquals("InChI=1S/ClH/h1H", gen.getInchi()); + } + + /** + * Tests charge is correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiFromLithiumIon() throws Exception { + IAtomContainer ac = new AtomContainer(); + IAtom a = new Atom("Li"); + a.setFormalCharge(+1); + ac.addAtom(a); + InChIGenerator gen = getFactory().getInChIGenerator(ac); + Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus()); + Assert.assertEquals("InChI=1S/Li/q+1", gen.getInchi()); + } + + /** + * Tests isotopic mass is correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiFromChlorine37Atom() throws Exception { + IAtomContainer ac = new AtomContainer(); + IAtom a = new Atom("Cl"); + a.setMassNumber(37); + ac.addAtom(a); + InChIGenerator gen = getFactory().getInChIGenerator(ac); + Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus()); + Assert.assertEquals("InChI=1S/ClH/h1H/i1+2", gen.getInchi()); + } + + /** + * Tests implicit hydrogen count is correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiFromHydrogenChlorideImplicitH() throws Exception { + IAtomContainer ac = new AtomContainer(); + IAtom a = new Atom("Cl"); + a.setImplicitHydrogenCount(1); + ac.addAtom(a); + InChIGenerator gen = getFactory().getInChIGenerator(ac); + Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY); + Assert.assertEquals( + "InChI=1S/ClH/h1H", + gen.getInchi() + ); + } + + /** + * Tests radical state is correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiFromMethylRadical() throws Exception { + IAtomContainer ac = new AtomContainer(); + IAtom a = new Atom("C"); + a.setImplicitHydrogenCount(3); + ac.addAtom(a); + ac.addSingleElectron(new SingleElectron(a)); + InChIGenerator gen = getFactory().getInChIGenerator(ac); + Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus()); + Assert.assertEquals( + "InChI=1S/CH3/h1H3", + gen.getInchi() + ); + } + + /** + * Tests single bond is correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiFromEthane() throws Exception { + IAtomContainer ac = new AtomContainer(); + IAtom a1 = new Atom("C"); + IAtom a2 = new Atom("C"); + a1.setImplicitHydrogenCount(3); + a2.setImplicitHydrogenCount(3); + ac.addAtom(a1); + ac.addAtom(a2); + ac.addBond(new Bond(a1, a2, CDKConstants.BONDORDER_SINGLE)); + InChIGenerator gen = getFactory().getInChIGenerator(ac); + Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus()); + Assert.assertEquals( + "InChI=1S/C2H6/c1-2/h1-2H3", + gen.getInchi() + ); + Assert.assertEquals("OTMSDBZUPAUEDD-UHFFFAOYSA-N", gen.getInchiKey()); + } + + /** + * Tests double bond is correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiFromEthene() throws Exception { + IAtomContainer ac = new AtomContainer(); + IAtom a1 = new Atom("C"); + IAtom a2 = new Atom("C"); + a1.setImplicitHydrogenCount(2); + a2.setImplicitHydrogenCount(2); + ac.addAtom(a1); + ac.addAtom(a2); + ac.addBond(new Bond(a1, a2, CDKConstants.BONDORDER_DOUBLE)); + InChIGenerator gen = getFactory().getInChIGenerator(ac); + Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus()); + Assert.assertEquals( + "InChI=1S/C2H4/c1-2/h1-2H2", + gen.getInchi() + ); + } + + /** + * Tests triple bond is correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiFromEthyne() throws Exception { + IAtomContainer ac = new AtomContainer(); + IAtom a1 = new Atom("C"); + IAtom a2 = new Atom("C"); + a1.setImplicitHydrogenCount(1); + a2.setImplicitHydrogenCount(1); + ac.addAtom(a1); + ac.addAtom(a2); + ac.addBond(new Bond(a1, a2, CDKConstants.BONDORDER_TRIPLE)); + InChIGenerator gen = getFactory().getInChIGenerator(ac); + Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus()); + Assert.assertEquals( + "InChI=1S/C2H2/c1-2/h1-2H", + gen.getInchi() + ); + } + + /** + * Tests 2D coordinates are correctly passed to InChI. + * + * @throws Exception + */ + @Test public void testGetInchiEandZ12Dichloroethene2D() throws Exception { + + // (E)-1,2-dichloroethene + IAtomContainer acE = new AtomContainer(); + IAtom a1E = new Atom("C", new Point2d(2.866, -0.250)); + IAtom a2E = new Atom("C", new Point2d(3.732, 0.250)); + IAtom a3E = new Atom("Cl", new Point2d(2.000, 2.500)); + IAtom a4E = new Atom("Cl", new Point2d(4.598, -0.250)); + a1E.setImplicitHydrogenCount(1); + a2E.setImplicitHydrogenCount(1); + acE.addAtom(a1E); + acE.addAtom(a2E); + acE.addAtom(a3E); + acE.addAtom(a4E); + + acE.addBond(new Bond(a1E, a2E, CDKConstants.BONDORDER_DOUBLE)); + acE.addBond(new Bond(a1E, a2E, CDKConstants.BONDORDER_DOUBLE)); + acE.addBond(new Bond(a1E, a3E, CDKConstants.BONDORDER_SINGLE)); + acE.addBond(new Bond(a2E, a4E, CDKConstants.BONDORDER_SINGLE)); + + InChIGenerator genE = getFactory().getInChIGenerator(acE); + Assert.assertEquals(INCHI_RET.OKAY, genE.getReturnStatus()); + Assert.assertEquals( + "InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1+", + genE.getInchi() + ); + + + // (Z)-1,2-dichloroethene + IAtomContainer acZ = new AtomContainer(); + IAtom a1Z = new Atom("C", new Point2d(2.866, -0.440)); + IAtom a2Z = new Atom("C", new Point2d(3.732, 0.060)); + IAtom a3Z = new Atom("Cl", new Point2d(2.000, 0.060)); + IAtom a4Z = new Atom("Cl", new Point2d(3.732, 1.060)); + a1Z.setImplicitHydrogenCount(1); + a2Z.setImplicitHydrogenCount(1); + acZ.addAtom(a1Z); + acZ.addAtom(a2Z); + acZ.addAtom(a3Z); + acZ.addAtom(a4Z); + + acZ.addBond(new Bond(a1Z, a2Z, CDKConstants.BONDORDER_DOUBLE)); + acZ.addBond(new Bond(a1Z, a2Z, CDKConstants.BONDORDER_DOUBLE)); + acZ.addBond(new Bond(a1Z, a3Z, CDKConstants.BONDORDER_SINGLE)); + acZ.addBond(new Bond(a2Z, a4Z, CDKConstants.BONDORDER_SINGLE)); + + InChIGenerator genZ = getFactory().getInChIGenerator(acZ); + Assert.assertEquals(INCHI_RET.OKAY, genZ.getReturnStatus()); + Assert.assertEquals( + "InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1-", + genZ.getInchi() + ); + } + + + /** + * Tests 3D coordinates are correctly passed to InChI. + * + * @throws Exception + */ + @Test + public void testGetInchiFromLandDAlanine3D() throws Exception { + + // L-Alanine + IAtomContainer acL = new AtomContainer(); + IAtom a1L = new Atom("C", new Point3d(-0.358, 0.819, 20.655)); + IAtom a2L = new Atom("C", new Point3d(-1.598, -0.032, 20.905)); + IAtom a3L = new Atom("N", new Point3d(-0.275, 2.014, 21.574)); + IAtom a4L = new Atom("C", new Point3d(0.952, 0.043, 20.838)); + IAtom a5L = new Atom("O", new Point3d(-2.678, 0.479, 21.093)); + IAtom a6L = new Atom("O", new Point3d(-1.596, -1.239, 20.958)); + a1L.setImplicitHydrogenCount(1); + a3L.setImplicitHydrogenCount(2); + a4L.setImplicitHydrogenCount(3); + a5L.setImplicitHydrogenCount(1); + acL.addAtom(a1L); + acL.addAtom(a2L); + acL.addAtom(a3L); + acL.addAtom(a4L); + acL.addAtom(a5L); + acL.addAtom(a6L); + + acL.addBond(new Bond(a1L, a2L, CDKConstants.BONDORDER_SINGLE)); + acL.addBond(new Bond(a1L, a3L, CDKConstants.BONDORDER_SINGLE)); + acL.addBond(new Bond(a1L, a4L, CDKConstants.BONDORDER_SINGLE)); + acL.addBond(new Bond(a2L, a5L, CDKConstants.BONDORDER_SINGLE)); + acL.addBond(new Bond(a2L, a6L, CDKConstants.BONDORDER_DOUBLE)); + + InChIGenerator genL = getFactory().getInChIGenerator(acL); + Assert.assertEquals(INCHI_RET.OKAY, genL.getReturnStatus()); + Assert.assertEquals( + "InChI=1S/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m0/s1", + genL.getInchi() + ); + + + // D-Alanine + IAtomContainer acD = new AtomContainer(); + IAtom a1D = new Atom("C", new Point3d(0.358, 0.819, 20.655)); + IAtom a2D = new Atom("C", new Point3d(1.598, -0.032, 20.905)); + IAtom a3D = new Atom("N", new Point3d(0.275, 2.014, 21.574)); + IAtom a4D = new Atom("C", new Point3d(-0.952, 0.043, 20.838)); + IAtom a5D = new Atom("O", new Point3d(2.678, 0.479, 21.093)); + IAtom a6D = new Atom("O", new Point3d(1.596, -1.239, 20.958)); + a1D.setImplicitHydrogenCount(1); + a3D.setImplicitHydrogenCount(2); + a4D.setImplicitHydrogenCount(3); + a5D.setImplicitHydrogenCount(1); + acD.addAtom(a1D); + acD.addAtom(a2D); + acD.addAtom(a3D); + acD.addAtom(a4D); + acD.addAtom(a5D); + acD.addAtom(a6D); + + acD.addBond(new Bond(a1D, a2D, CDKConstants.BONDORDER_SINGLE)); + acD.addBond(new Bond(a1D, a3D, CDKConstants.BONDORDER_SINGLE)); + acD.addBond(new Bond(a1D, a4D, CDKConstants.BONDORDER_SINGLE)); + acD.addBond(new Bond(a2D, a5D, CDKConstants.BONDORDER_SINGLE)); + acD.addBond(new Bond(a2D, a6D, CDKConstants.BONDORDER_DOUBLE)); + + InChIGenerator genD = getFactory().getInChIGenerator(acD); + Assert.assertEquals(INCHI_RET.OKAY, genD.getReturnStatus()); + Assert.assertEquals( + "InChI=1S/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m1/s1", + genD.getInchi() + ); + } + +} diff --git a/src/test/org/openscience/cdk/io/CDKSourceCodeWriterTest.java b/src/test/org/openscience/cdk/io/CDKSourceCodeWriterTest.java index 384a01e1e4d..a55d22bca1b 100644 --- a/src/test/org/openscience/cdk/io/CDKSourceCodeWriterTest.java +++ b/src/test/org/openscience/cdk/io/CDKSourceCodeWriterTest.java @@ -1,9 +1,8 @@ -/* $Revision$ $Author$ $Date$ +/* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project + * 2010 Egon Willighagen * - * Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project - * * Contact: cdk-devel@slists.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 @@ -12,18 +11,20 @@ * - 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.io; +import groovy.lang.GroovyShell; + import java.io.StringWriter; import org.junit.Assert; @@ -61,6 +62,16 @@ public class CDKSourceCodeWriterTest extends ChemObjectIOTest { CDKSourceCodeWriter sourceWriter = new CDKSourceCodeWriter(writer); sourceWriter.write(molecule); String output = writer.toString(); - Assert.assertTrue(output.indexOf("IAtom a1 = mol.getNewBuilder().newInstance(IAtom.class,\"C\")") != -1); + Assert.assertTrue(output.indexOf("IAtom a1 = mol.getBuilder().newInstance(IAtom.class,\"C\")") != -1); + + GroovyShell shell = new GroovyShell(); + shell.evaluate( + // import the classes used in the output + "import org.openscience.cdk.interfaces.*;" + + "import org.openscience.cdk.*;" + + // compensate for the write to wrap the output in { ... } + "if (true) " + + output + ); } } diff --git a/src/test/org/openscience/cdk/io/formats/CDKOWLFormatTest.java b/src/test/org/openscience/cdk/io/formats/CDKOWLFormatTest.java new file mode 100644 index 00000000000..b7b884f1aad --- /dev/null +++ b/src/test/org/openscience/cdk/io/formats/CDKOWLFormatTest.java @@ -0,0 +1,38 @@ +/* $Revision$ $Author$ $Date$ + * + * Copyright (C) 2008 Egon Willighagen + * + * Contact: cdk-devel@slists.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.io.formats; + +/** + * @cdk.module test-ioformats + */ +public class CDKOWLFormatTest extends ChemFormatMatcherTest { + + public CDKOWLFormatTest() { + super.setChemFormatMatcher( + (IChemFormatMatcher)CDKOWLFormat.getInstance() + ); + } + +} diff --git a/src/test/org/openscience/cdk/io/iterator/IteratingMDLReaderTest.java b/src/test/org/openscience/cdk/io/iterator/IteratingMDLReaderTest.java index 128f29cc5c2..8893daf71c1 100644 --- a/src/test/org/openscience/cdk/io/iterator/IteratingMDLReaderTest.java +++ b/src/test/org/openscience/cdk/io/iterator/IteratingMDLReaderTest.java @@ -45,6 +45,8 @@ import org.openscience.cdk.io.setting.IOSetting; import org.openscience.cdk.tools.ILoggingTool; import org.openscience.cdk.tools.LoggingToolFactory; +import java.io.InputStreamReader; +import java.io.IOException; /** * TestCase for the reading MDL mol files using one test file. @@ -78,6 +80,34 @@ public class IteratingMDLReaderTest extends CDKTestCase { Assert.assertEquals(6, molCount); } + @Test public void testSDF_broken_stream() throws Exception { + String filename = "data/mdl/test2.sdf"; + logger.info("Testing: " + filename); + InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); + InputStreamReader streamReader = new InputStreamReader(ins) { + @Override + public boolean ready() throws IOException { + return false; + } + }; + + IteratingMDLReader reader = new IteratingMDLReader( + streamReader, DefaultChemObjectBuilder.getInstance() + ); + + int molCount = 0; + while (reader.hasNext()) { + Object object = reader.next(); + Assert.assertNotNull(object); + Assert.assertTrue(object instanceof Molecule); + molCount++; + Assert.assertEquals("Molecule # was not in MDL V2000 format: " + molCount, + MDLV2000Format.getInstance(), reader.getFormat()); + } + + Assert.assertEquals(6, molCount); + } + @Test public void testReadTitle() throws Exception { String filename = "data/mdl/test.sdf"; logger.info("Testing: " + filename); diff --git a/src/test/org/openscience/cdk/io/rdf/CDKOWLReaderTest.java b/src/test/org/openscience/cdk/io/rdf/CDKOWLReaderTest.java new file mode 100644 index 00000000000..478a6c00290 --- /dev/null +++ b/src/test/org/openscience/cdk/io/rdf/CDKOWLReaderTest.java @@ -0,0 +1,66 @@ +/* Copyright (C) 2009 The Chemistry Development Kit (CDK) project + * + * Contact: cdk-devel@slists.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.io.rdf; + +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openscience.cdk.Molecule; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.io.SimpleChemObjectReaderTest; +import org.openscience.cdk.nonotify.NNMolecule; +import org.openscience.cdk.tools.ILoggingTool; +import org.openscience.cdk.tools.LoggingToolFactory; + +/** + * @cdk.module test-iordf + */ +public class CDKOWLReaderTest extends SimpleChemObjectReaderTest { + + private ILoggingTool logger = + LoggingToolFactory.createLoggingTool(CDKOWLReaderTest.class); + + @BeforeClass public static void setup() { + setSimpleChemObjectReader(new CDKOWLReader(), "data/owl/molecule.n3"); + } + + @Test public void testAccepts() { + Assert.assertTrue(chemObjectIO.accepts(Molecule.class)); + } + + @Test public void testMolecule() throws Exception { + String filename = "data/owl/molecule.n3"; + logger.info("Testing: " + filename); + InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); + CDKOWLReader reader = new CDKOWLReader( + new InputStreamReader(ins) + ); + IMolecule mol = (IMolecule)reader.read(new NNMolecule()); + + Assert.assertNotNull(mol); + } + +} diff --git a/src/test/org/openscience/cdk/io/rdf/CDKOWLWriterTest.java b/src/test/org/openscience/cdk/io/rdf/CDKOWLWriterTest.java new file mode 100644 index 00000000000..09899af4efd --- /dev/null +++ b/src/test/org/openscience/cdk/io/rdf/CDKOWLWriterTest.java @@ -0,0 +1,62 @@ +/* Copyright (C) 2009 Egon Willighagen + * + * Contact: cdk-devel@slists.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.io.rdf; + +import java.io.StringWriter; + +import junit.framework.Assert; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.io.ChemObjectWriterTest; +import org.openscience.cdk.nonotify.NNAtom; +import org.openscience.cdk.nonotify.NNMolecule; + +/** + * TestCase for the {@link CDKOWLWriter}. + * + * @cdk.module test-iordf + */ +public class CDKOWLWriterTest extends ChemObjectWriterTest { + + @BeforeClass public static void setup() { + setChemObjectWriter(new CDKOWLWriter()); + } + + @Test public void testWriteMolecule() throws Exception { + StringWriter output = new StringWriter(); + CDKOWLWriter writer = new CDKOWLWriter(output); + + IMolecule mol = new NNMolecule(); + mol.addAtom(new NNAtom("C")); + mol.addAtom(new NNAtom("C")); + mol.addBond(0,1,IBond.Order.DOUBLE); + writer.write(mol); + String outputString = output.toString(); + Assert.assertTrue(outputString.contains( + "http://cdk.sourceforge.net/model.owl#" + )); + } +} diff --git a/src/test/org/openscience/cdk/libio/jena/ConvertorTest.java b/src/test/org/openscience/cdk/libio/jena/ConvertorTest.java new file mode 100644 index 00000000000..09aa0c1d7b6 --- /dev/null +++ b/src/test/org/openscience/cdk/libio/jena/ConvertorTest.java @@ -0,0 +1,247 @@ +/* Copyright (C) 2009 Egon Willighagen + * + * 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.libio.jena; + +import junit.framework.Assert; + +import org.junit.Test; +import org.openscience.cdk.CDKTestCase; +import org.openscience.cdk.PseudoAtom; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemObjectBuilder; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.interfaces.IPseudoAtom; +import org.openscience.cdk.interfaces.IAtomType.Hybridization; +import org.openscience.cdk.interfaces.IBond.Order; +import org.openscience.cdk.nonotify.NNAtom; +import org.openscience.cdk.nonotify.NNMolecule; +import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder; +import org.openscience.cdk.tools.diff.AtomContainerDiff; + +import com.hp.hpl.jena.rdf.model.Model; + +/** + * @cdk.module test-iordf + */ +public class ConvertorTest extends CDKTestCase { + + private static IChemObjectBuilder builder = + NoNotificationChemObjectBuilder.getInstance(); + + @Test public void roundtripMolecule() { + IMolecule mol = new NNMolecule(); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals(0, diff.length()); + } + + @Test public void roundtripAtom() { + IMolecule mol = new NNMolecule(); + mol.addAtom(new NNAtom("C")); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripBond_SINGLE() { + roundtripBond_Order(IBond.Order.SINGLE); + } + @Test public void roundtripBond_DOUBLE() { + roundtripBond_Order(IBond.Order.DOUBLE); + } + @Test public void roundtripBond_TRIPLE() { + roundtripBond_Order(IBond.Order.TRIPLE); + } + @Test public void roundtripBond_QUAD() { + roundtripBond_Order(IBond.Order.QUADRUPLE); + } + + private void roundtripBond_Order(IBond.Order order) { + IMolecule mol = new NNMolecule(); + mol.addAtom(new NNAtom("C")); + mol.addAtom(new NNAtom("C")); + mol.addBond(0,1,order); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripElectronContainer_ElectronCount() { + IMolecule mol = new NNMolecule(); + mol.addAtom(new NNAtom("C")); + mol.addAtom(new NNAtom("C")); + mol.addBond(0,1,IBond.Order.SINGLE); + mol.getBond(0).setElectronCount(1); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripChemObject() { + IMolecule mol = new NNMolecule(); + IAtom object = new NNAtom("C"); + object.setID("atom1"); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripElement() { + IMolecule mol = new NNMolecule(); + IAtom object = new NNAtom("C"); + object.setAtomicNumber(6); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripPseudoAtom() { + IMolecule mol = new NNMolecule(); + IPseudoAtom object = new PseudoAtom("FunnyAtom"); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripAtomType() { + IMolecule mol = new NNMolecule(); + IAtom object = new NNAtom("C"); + object.setAtomTypeName("C.sp3"); + object.setFormalCharge(+1); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripIsotope_ExactMass() { + IMolecule mol = new NNMolecule(); + IAtom object = new NNAtom("C"); + object.setExactMass(0.3); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripIsotope_MassNumber() { + IMolecule mol = new NNMolecule(); + IAtom object = new NNAtom("C"); + object.setMassNumber(13); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripIsotope_NaturalAbundance() { + IMolecule mol = new NNMolecule(); + IAtom object = new NNAtom("C"); + object.setNaturalAbundance(0.95); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void roundtripAtomType_S() { + roundtripAtomType_Hybridization(Hybridization.S); + } + @Test public void roundtripAtomType_SP1() { + roundtripAtomType_Hybridization(Hybridization.SP1); + } + @Test public void roundtripAtomType_SP2() { + roundtripAtomType_Hybridization(Hybridization.SP2); + } + @Test public void roundtripAtomType_SP3() { + roundtripAtomType_Hybridization(Hybridization.SP3); + } + @Test public void roundtripAtomType_PLANAR3() { + roundtripAtomType_Hybridization(Hybridization.PLANAR3); + } + @Test public void roundtripAtomType_SP3D1() { + roundtripAtomType_Hybridization(Hybridization.SP3D1); + } + @Test public void roundtripAtomType_SP3D2() { + roundtripAtomType_Hybridization(Hybridization.SP3D2); + } + @Test public void roundtripAtomType_SP3D3() { + roundtripAtomType_Hybridization(Hybridization.SP3D3); + } + @Test public void roundtripAtomType_SP3D4() { + roundtripAtomType_Hybridization(Hybridization.SP3D4); + } + @Test public void roundtripAtomType_SP3D5() { + roundtripAtomType_Hybridization(Hybridization.SP3D5); + } + + private void roundtripAtomType_Hybridization(Hybridization hybrid) { + IMolecule mol = new NNMolecule(); + IAtom object = new NNAtom("C"); + object.setHybridization(hybrid); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } + + @Test public void testAtomType_MaxBondOrder_SINGLE() { + roundtripAtomType_MaxBondOrder(Order.SINGLE); + } + @Test public void testAtomType_MaxBondOrder_DOUBLE() { + roundtripAtomType_MaxBondOrder(Order.DOUBLE); + } + @Test public void testAtomType_MaxBondOrder_TRIPLE() { + roundtripAtomType_MaxBondOrder(Order.TRIPLE); + } + @Test public void testAtomType_MaxBondOrder_QUAD() { + roundtripAtomType_MaxBondOrder(Order.QUADRUPLE); + } + + private void roundtripAtomType_MaxBondOrder(Order order) { + IMolecule mol = new NNMolecule(); + IAtom object = new NNAtom("C"); + object.setMaxBondOrder(order); + mol.addAtom(object); + Model model = Convertor.molecule2Model(mol); + IMolecule rtMol = Convertor.model2Molecule(model, builder); + String diff = AtomContainerDiff.diff(mol, rtMol); + Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); + } +} diff --git a/src/test/org/openscience/cdk/modulesuites/MioformatsTests.java b/src/test/org/openscience/cdk/modulesuites/MioformatsTests.java index 404107076d9..412b9603c58 100644 --- a/src/test/org/openscience/cdk/modulesuites/MioformatsTests.java +++ b/src/test/org/openscience/cdk/modulesuites/MioformatsTests.java @@ -35,6 +35,7 @@ import org.openscience.cdk.io.formats.BGFFormatTest; import org.openscience.cdk.io.formats.BSFormatTest; import org.openscience.cdk.io.formats.CACheFormatTest; +import org.openscience.cdk.io.formats.CDKOWLFormatTest; import org.openscience.cdk.io.formats.CIFFormatTest; import org.openscience.cdk.io.formats.CMLFormatTest; import org.openscience.cdk.io.formats.CMLRSSFormatTest; @@ -134,6 +135,7 @@ CacaoCartesianFormatTest.class, CacaoInternalFormatTest.class, CACheFormatTest.class, + CDKOWLFormatTest.class, Chem3D_Cartesian_1FormatTest.class, Chem3D_Cartesian_2FormatTest.class, ChemDrawFormatTest.class, diff --git a/src/test/org/openscience/cdk/modulesuites/MiordfTests.java b/src/test/org/openscience/cdk/modulesuites/MiordfTests.java new file mode 100644 index 00000000000..f6fafea4e45 --- /dev/null +++ b/src/test/org/openscience/cdk/modulesuites/MiordfTests.java @@ -0,0 +1,39 @@ +/* Copyright (C) 2009 Egon Willighagen + * + * 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. + * + * 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.modulesuites; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +import org.openscience.cdk.io.rdf.CDKOWLReaderTest; +import org.openscience.cdk.io.rdf.CDKOWLWriterTest; +import org.openscience.cdk.libio.jena.ConvertorTest; + +/** + * TestSuite that runs all the sample tests for iordf module. + * + * @cdk.module test-iordf + */ +@RunWith(value=Suite.class) +@SuiteClasses(value={ + CDKOWLReaderTest.class, + CDKOWLWriterTest.class, + ConvertorTest.class +}) +public class MiordfTests {} \ No newline at end of file diff --git a/src/test/org/openscience/cdk/modulesuites/MqsarmolecularTests.java b/src/test/org/openscience/cdk/modulesuites/MqsarmolecularTests.java index d332d30bfdb..a049b0ce807 100644 --- a/src/test/org/openscience/cdk/modulesuites/MqsarmolecularTests.java +++ b/src/test/org/openscience/cdk/modulesuites/MqsarmolecularTests.java @@ -91,6 +91,7 @@ AutocorrelationDescriptorMassTest.class, AutocorrelationDescriptorPolarizabilityTest.class, CarbonTypesDescriptorTest.class, - HybridizationRatioDescriptorTest.class + HybridizationRatioDescriptorTest.class, + FMFDescriptorTest.class }) public class MqsarmolecularTests {} diff --git a/src/test/org/openscience/cdk/modulesuites/MsinchiTests.java b/src/test/org/openscience/cdk/modulesuites/MsinchiTests.java new file mode 100644 index 00000000000..0e0c3ecc39f --- /dev/null +++ b/src/test/org/openscience/cdk/modulesuites/MsinchiTests.java @@ -0,0 +1,37 @@ +/* Copyright (C) 2010 Egon Willighagen + * + * 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. + * + * 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.modulesuites; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +import org.openscience.cdk.coverage.SinchiCoverageTest; +import org.openscience.cdk.inchi.standard.InChIGeneratorTest; + +/** + * TestSuite that runs all the sample tests for the CDK module sinchi. + * + * @cdk.module test-sinchi + */ +@RunWith(value=Suite.class) +@SuiteClasses(value={ + SinchiCoverageTest.class, + InChIGeneratorTest.class +}) +public class MsinchiTests {} diff --git a/src/test/org/openscience/cdk/nonotify/NNAminoAcidTest.java b/src/test/org/openscience/cdk/nonotify/NNAminoAcidTest.java index 52a573389e9..f43f0fc423a 100644 --- a/src/test/org/openscience/cdk/nonotify/NNAminoAcidTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNAminoAcidTest.java @@ -75,4 +75,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNAtomContainerSetTest.java b/src/test/org/openscience/cdk/nonotify/NNAtomContainerSetTest.java index 4675fbb59be..9c3d5964b71 100644 --- a/src/test/org/openscience/cdk/nonotify/NNAtomContainerSetTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNAtomContainerSetTest.java @@ -75,4 +75,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNAtomContainerTest.java b/src/test/org/openscience/cdk/nonotify/NNAtomContainerTest.java index 211cbad9966..cdd75563153 100644 --- a/src/test/org/openscience/cdk/nonotify/NNAtomContainerTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNAtomContainerTest.java @@ -120,4 +120,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNAtomTest.java b/src/test/org/openscience/cdk/nonotify/NNAtomTest.java index 527ff1bead3..c6bbf0ee7f9 100644 --- a/src/test/org/openscience/cdk/nonotify/NNAtomTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNAtomTest.java @@ -116,4 +116,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNAtomTypeTest.java b/src/test/org/openscience/cdk/nonotify/NNAtomTypeTest.java index cc71a60f82b..c1846fc6c18 100644 --- a/src/test/org/openscience/cdk/nonotify/NNAtomTypeTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNAtomTypeTest.java @@ -91,4 +91,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNBioPolymerTest.java b/src/test/org/openscience/cdk/nonotify/NNBioPolymerTest.java index 5f9a556d1a8..34b4a0e92f9 100644 --- a/src/test/org/openscience/cdk/nonotify/NNBioPolymerTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNBioPolymerTest.java @@ -129,4 +129,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNBondTest.java b/src/test/org/openscience/cdk/nonotify/NNBondTest.java index acdb7e248b4..d74b5216bae 100644 --- a/src/test/org/openscience/cdk/nonotify/NNBondTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNBondTest.java @@ -27,7 +27,6 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.openscience.cdk.CDKConstants; import org.openscience.cdk.interfaces.AbstractBondTest; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IBond; @@ -158,4 +157,10 @@ public void testNNBond_IAtom_IAtom_IBond_Order_IBond_Stereo() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNChemFileTest.java b/src/test/org/openscience/cdk/nonotify/NNChemFileTest.java index a2a8f3e5f92..9a67ee9f44c 100644 --- a/src/test/org/openscience/cdk/nonotify/NNChemFileTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNChemFileTest.java @@ -78,4 +78,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNChemModelTest.java b/src/test/org/openscience/cdk/nonotify/NNChemModelTest.java index 3ccb1d00bf4..c3712f45b32 100644 --- a/src/test/org/openscience/cdk/nonotify/NNChemModelTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNChemModelTest.java @@ -213,4 +213,10 @@ public IChemObject newTestObject() { ringSet.addAtomContainer(chemObject.getBuilder().newInstance(IRing.class)); Assert.assertFalse(listener.getChanged()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNChemObjectTest.java b/src/test/org/openscience/cdk/nonotify/NNChemObjectTest.java index 38e5cf53668..41d1f6f68c7 100644 --- a/src/test/org/openscience/cdk/nonotify/NNChemObjectTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNChemObjectTest.java @@ -80,4 +80,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNChemObjectTestHelper.java b/src/test/org/openscience/cdk/nonotify/NNChemObjectTestHelper.java index b1f811883f1..d7a53ebd1a0 100644 --- a/src/test/org/openscience/cdk/nonotify/NNChemObjectTestHelper.java +++ b/src/test/org/openscience/cdk/nonotify/NNChemObjectTestHelper.java @@ -104,4 +104,22 @@ public static void testSetNotification_true(IChemObject chemObject) { chemObject.setID("Changed"); Assert.assertFalse(listener.getChanged()); } + + public static void testNotifyChanged_SetProperty(IChemObject chemObject) { + NNChemObjectListener listener = new NNChemObjectListener(); + chemObject.addListener(listener); + + chemObject.setProperty("Changed", "Yes"); + Assert.assertFalse(listener.getChanged()); + } + + public static void testNotifyChanged_RemoveProperty(IChemObject chemObject) { + chemObject.setProperty("Changed", "Yes"); + + NNChemObjectListener listener = new NNChemObjectListener(); + chemObject.addListener(listener); + + chemObject.removeProperty("Changed"); + Assert.assertFalse(listener.getChanged()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNChemSequenceTest.java b/src/test/org/openscience/cdk/nonotify/NNChemSequenceTest.java index 0803e2efe21..f2f88856811 100644 --- a/src/test/org/openscience/cdk/nonotify/NNChemSequenceTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNChemSequenceTest.java @@ -78,4 +78,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNCrystalTest.java b/src/test/org/openscience/cdk/nonotify/NNCrystalTest.java index 1d691f62920..46f388113f4 100644 --- a/src/test/org/openscience/cdk/nonotify/NNCrystalTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNCrystalTest.java @@ -106,4 +106,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNElectronContainerTest.java b/src/test/org/openscience/cdk/nonotify/NNElectronContainerTest.java index 037eead0f79..bc538af5abf 100644 --- a/src/test/org/openscience/cdk/nonotify/NNElectronContainerTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNElectronContainerTest.java @@ -79,4 +79,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNElementTest.java b/src/test/org/openscience/cdk/nonotify/NNElementTest.java index 35e5f3f60be..29930adb281 100644 --- a/src/test/org/openscience/cdk/nonotify/NNElementTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNElementTest.java @@ -95,4 +95,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNFragmentAtomTest.java b/src/test/org/openscience/cdk/nonotify/NNFragmentAtomTest.java index 654c77f46b7..6ac03181f77 100644 --- a/src/test/org/openscience/cdk/nonotify/NNFragmentAtomTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNFragmentAtomTest.java @@ -78,4 +78,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNIsotopeTest.java b/src/test/org/openscience/cdk/nonotify/NNIsotopeTest.java index ef97963444b..584697e8bae 100644 --- a/src/test/org/openscience/cdk/nonotify/NNIsotopeTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNIsotopeTest.java @@ -108,4 +108,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNLonePairTest.java b/src/test/org/openscience/cdk/nonotify/NNLonePairTest.java index a448a95623e..05267e8b6ac 100644 --- a/src/test/org/openscience/cdk/nonotify/NNLonePairTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNLonePairTest.java @@ -88,4 +88,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNMappingTest.java b/src/test/org/openscience/cdk/nonotify/NNMappingTest.java index 59944acd4b2..9e072043028 100644 --- a/src/test/org/openscience/cdk/nonotify/NNMappingTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNMappingTest.java @@ -80,4 +80,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNMoleculeSetTest.java b/src/test/org/openscience/cdk/nonotify/NNMoleculeSetTest.java index cb37dc949ea..e586b95eec6 100644 --- a/src/test/org/openscience/cdk/nonotify/NNMoleculeSetTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNMoleculeSetTest.java @@ -78,4 +78,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNMoleculeTest.java b/src/test/org/openscience/cdk/nonotify/NNMoleculeTest.java index 0247688f6d1..742dff8daa2 100644 --- a/src/test/org/openscience/cdk/nonotify/NNMoleculeTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNMoleculeTest.java @@ -113,4 +113,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNMonomerTest.java b/src/test/org/openscience/cdk/nonotify/NNMonomerTest.java index fe5b23dd7a1..5d9acf9a5f1 100644 --- a/src/test/org/openscience/cdk/nonotify/NNMonomerTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNMonomerTest.java @@ -78,4 +78,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNPDBAtomTest.java b/src/test/org/openscience/cdk/nonotify/NNPDBAtomTest.java index 0b1cec21097..7a8643cdd24 100644 --- a/src/test/org/openscience/cdk/nonotify/NNPDBAtomTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNPDBAtomTest.java @@ -101,4 +101,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNPDBMonomerTest.java b/src/test/org/openscience/cdk/nonotify/NNPDBMonomerTest.java index 35c121ccca2..b7b5c870b37 100644 --- a/src/test/org/openscience/cdk/nonotify/NNPDBMonomerTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNPDBMonomerTest.java @@ -79,4 +79,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNPDBPolymerTest.java b/src/test/org/openscience/cdk/nonotify/NNPDBPolymerTest.java index 70a06e3c2a5..8486b6d57cc 100644 --- a/src/test/org/openscience/cdk/nonotify/NNPDBPolymerTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNPDBPolymerTest.java @@ -129,4 +129,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNPolymerTest.java b/src/test/org/openscience/cdk/nonotify/NNPolymerTest.java index 2534207a6b7..a71d8259eb3 100644 --- a/src/test/org/openscience/cdk/nonotify/NNPolymerTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNPolymerTest.java @@ -79,4 +79,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNPseudoAtomTest.java b/src/test/org/openscience/cdk/nonotify/NNPseudoAtomTest.java index a31d0963a37..eafade8cc03 100644 --- a/src/test/org/openscience/cdk/nonotify/NNPseudoAtomTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNPseudoAtomTest.java @@ -136,4 +136,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNReactionSchemeTest.java b/src/test/org/openscience/cdk/nonotify/NNReactionSchemeTest.java index 4fe4779e9a9..9574b3284a5 100644 --- a/src/test/org/openscience/cdk/nonotify/NNReactionSchemeTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNReactionSchemeTest.java @@ -74,4 +74,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNReactionSetTest.java b/src/test/org/openscience/cdk/nonotify/NNReactionSetTest.java index 46cf897018f..fbc7e7b2676 100644 --- a/src/test/org/openscience/cdk/nonotify/NNReactionSetTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNReactionSetTest.java @@ -78,4 +78,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } \ No newline at end of file diff --git a/src/test/org/openscience/cdk/nonotify/NNReactionTest.java b/src/test/org/openscience/cdk/nonotify/NNReactionTest.java index 0d048091eb3..e9d0fc9a25a 100644 --- a/src/test/org/openscience/cdk/nonotify/NNReactionTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNReactionTest.java @@ -78,4 +78,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNRingSetTest.java b/src/test/org/openscience/cdk/nonotify/NNRingSetTest.java index c7554c65683..e3630e5399d 100644 --- a/src/test/org/openscience/cdk/nonotify/NNRingSetTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNRingSetTest.java @@ -78,4 +78,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } \ No newline at end of file diff --git a/src/test/org/openscience/cdk/nonotify/NNRingTest.java b/src/test/org/openscience/cdk/nonotify/NNRingTest.java index b29500ff4f7..bdb29478126 100644 --- a/src/test/org/openscience/cdk/nonotify/NNRingTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNRingTest.java @@ -105,4 +105,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } \ No newline at end of file diff --git a/src/test/org/openscience/cdk/nonotify/NNSingleElectronTest.java b/src/test/org/openscience/cdk/nonotify/NNSingleElectronTest.java index 7a2f034e7a2..8b0e929e7bf 100644 --- a/src/test/org/openscience/cdk/nonotify/NNSingleElectronTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNSingleElectronTest.java @@ -88,4 +88,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/nonotify/NNStrandTest.java b/src/test/org/openscience/cdk/nonotify/NNStrandTest.java index 46379a98334..94712c9b12d 100644 --- a/src/test/org/openscience/cdk/nonotify/NNStrandTest.java +++ b/src/test/org/openscience/cdk/nonotify/NNStrandTest.java @@ -121,4 +121,10 @@ public IChemObject newTestObject() { @Test public void testSetNotification_true() { NNChemObjectTestHelper.testSetNotification_true(newChemObject()); } + @Test public void testNotifyChanged_SetProperty() { + NNChemObjectTestHelper.testNotifyChanged_SetProperty(newChemObject()); + } + @Test public void testNotifyChanged_RemoveProperty() { + NNChemObjectTestHelper.testNotifyChanged_RemoveProperty(newChemObject()); + } } diff --git a/src/test/org/openscience/cdk/qsar/descriptors/molecular/FMFDescriptorTest.java b/src/test/org/openscience/cdk/qsar/descriptors/molecular/FMFDescriptorTest.java new file mode 100644 index 00000000000..5d63a918482 --- /dev/null +++ b/src/test/org/openscience/cdk/qsar/descriptors/molecular/FMFDescriptorTest.java @@ -0,0 +1,80 @@ +/* Copyright (C) 2010 Rajarshi Guha + * + * 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. + * + * 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.qsar.descriptors.molecular; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openscience.cdk.DefaultChemObjectBuilder; +import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.qsar.result.DoubleResult; +import org.openscience.cdk.smiles.SmilesParser; + +/** + * @cdk.module test-qsarmolecular + */ +public class FMFDescriptorTest extends MolecularDescriptorTest { + + public FMFDescriptorTest() { + } + + @Before + public void setUp() throws Exception { + setDescriptor(FMFDescriptor.class); + } + + @Test + public void testClenbuterol() throws Exception { + SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); + IAtomContainer mol = sp.parseSmiles("Clc1cc(cc(Cl)c1N)C(O)CNC(C)(C)C"); + CDKHueckelAromaticityDetector.detectAromaticity(mol); + DoubleResult result = (DoubleResult) descriptor.calculate(mol).getValue(); + Assert.assertEquals(0.353, result.doubleValue(), 0.01); + } + + @Test + public void testCarbinoxamine() throws Exception { + SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); + IAtomContainer mol = sp.parseSmiles("CN(C)CCOC(C1=CC=C(Cl)C=C1)C1=CC=CC=N1"); + CDKHueckelAromaticityDetector.detectAromaticity(mol); + DoubleResult result = (DoubleResult) descriptor.calculate(mol).getValue(); + Assert.assertEquals(0.65, result.doubleValue(), 0.01); + } + + @Test + public void testIsamoltane() throws CDKException { + SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); + IAtomContainer mol = sp.parseSmiles("CC(C)NCC(O)COC1=C(C=CC=C1)N1C=CC=C1"); + CDKHueckelAromaticityDetector.detectAromaticity(mol); + DoubleResult result = (DoubleResult) descriptor.calculate(mol).getValue(); + Assert.assertEquals(0.55, result.doubleValue(), 0.01); + } + + @Test + public void testPirenperone() throws CDKException { + SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); + IAtomContainer mol = sp.parseSmiles("Fc1ccc(cc1)C(=O)C4CCN(CCC\\3=C(\\N=C2\\C=C/C=C\\N2C/3=O)C)CC4"); + CDKHueckelAromaticityDetector.detectAromaticity(mol); + DoubleResult result = (DoubleResult) descriptor.calculate(mol).getValue(); + Assert.assertEquals(0.862, result.doubleValue(), 0.001); + } + +} \ No newline at end of file diff --git a/src/test/org/openscience/cdk/smiles/smarts/parser/SMARTSSearchTest.java b/src/test/org/openscience/cdk/smiles/smarts/parser/SMARTSSearchTest.java index 1804d0731e4..ead3075c465 100644 --- a/src/test/org/openscience/cdk/smiles/smarts/parser/SMARTSSearchTest.java +++ b/src/test/org/openscience/cdk/smiles/smarts/parser/SMARTSSearchTest.java @@ -20,9 +20,6 @@ */ package org.openscience.cdk.smiles.smarts.parser; -import java.io.InputStream; -import java.util.List; - import org.junit.Assert; import org.junit.Test; import org.openscience.cdk.CDKTestCase; @@ -41,6 +38,9 @@ import org.openscience.cdk.tools.LoggingToolFactory; import org.openscience.cdk.tools.manipulator.ChemFileManipulator; +import java.io.InputStream; +import java.util.List; + /** * JUnit test routines for the SMARTS substructure search. * @@ -50,7 +50,7 @@ */ public class SMARTSSearchTest extends CDKTestCase { - private static ILoggingTool logger = + private static ILoggingTool logger = LoggingToolFactory.createLoggingTool(SMARTSSearchTest.class); private int[] match(String smarts, String smiles) throws Exception { @@ -1627,6 +1627,18 @@ public void testLeadingHydrogen() throws Exception { Assert.assertEquals(1, results[1]); } - + /** + * @cdk.bug 2871303 + *

+ * Note that this test passes, and really indicates that + * the SMARTS below is not a correct one for vinylogous + * esters + */ + @Test + public void testVinylogousEster() throws Exception { + int[] results = match("[#6X3](=[OX1])[#6X3]=,:[#6X3][#6;!$(C=[O,N,S])]", "c1ccccc1C=O"); + Assert.assertEquals(2, results[0]); + Assert.assertEquals(2, results[1]); + } }