Skip to content

Commit

Permalink
Disable AuxInfo generation in InChIFactory by default. This can be as…
Browse files Browse the repository at this point in the history
… much as 20% of the compute time and is largely ignored. If the AuxInfo is wanted it can be generated by explicitly passing in an empty set of options.
  • Loading branch information
johnmay committed Aug 24, 2015
1 parent 7acf190 commit d5afb4c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Expand Up @@ -23,6 +23,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Collections;

import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
Expand Down Expand Up @@ -56,6 +57,8 @@
import org.openscience.cdk.interfaces.ITetrahedralChirality;
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
import org.openscience.cdk.stereo.ExtendedTetrahedral;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;

/**
* <p>This class generates the IUPAC International Chemical Identifier (InChI) for
Expand Down Expand Up @@ -99,10 +102,14 @@
*/
public class InChIGenerator {

protected JniInchiInput input;
protected JniInchiInput input;

protected JniInchiOutput output;

private final boolean auxNone;

private static final ILoggingTool LOGGER = LoggingToolFactory.createLoggingTool(InChIGenerator.class);

/**
* AtomContainer instance refers to.
*/
Expand All @@ -120,12 +127,7 @@ public class InChIGenerator {
* error during InChI generation
*/
protected InChIGenerator(IAtomContainer atomContainer, boolean ignoreAromaticBonds) throws CDKException {
try {
input = new JniInchiInput("");
generateInchiFromCDKAtomContainer(atomContainer, ignoreAromaticBonds);
} catch (JniInchiException jie) {
throw new CDKException("InChI generation failed: " + jie.getMessage(), jie);
}
this(atomContainer, Collections.singletonList(INCHI_OPTION.AuxNone), ignoreAromaticBonds);
}

/**
Expand All @@ -146,6 +148,7 @@ protected InChIGenerator(IAtomContainer atomContainer, String options, boolean i
try {
input = new JniInchiInput(options);
generateInchiFromCDKAtomContainer(atomContainer, ignoreAromaticBonds);
auxNone = input.getOptions() != null && input.getOptions().contains("AuxNone");
} catch (JniInchiException jie) {
throw new CDKException("InChI generation failed: " + jie.getMessage(), jie);
}
Expand All @@ -167,6 +170,7 @@ protected InChIGenerator(IAtomContainer atomContainer, List<INCHI_OPTION> option
try {
input = new JniInchiInput(options);
generateInchiFromCDKAtomContainer(atomContainer, ignoreAromaticBonds);
auxNone = input.getOptions() != null && input.getOptions().contains("AuxNone");
} catch (JniInchiException jie) {
throw new CDKException("InChI generation failed: " + jie.getMessage(), jie);
}
Expand Down Expand Up @@ -551,6 +555,9 @@ public String getInchiKey() throws CDKException {
* Gets auxillary information.
*/
public String getAuxInfo() {
if (auxNone) {
LOGGER.warn("AuxInfo requested but AuxNone option is set (default).");
}

This comment has been minimized.

Copy link
@egonw

egonw Aug 25, 2015

Member

Should it not better throw an error? the warning will get lost... I mean, really throw... logger messages are for debugging purposes, right? Not for operational behavior...

This comment has been minimized.

Copy link
@johnmay

johnmay Aug 25, 2015

Author Member

I'm happy to throw an unchecked exception - but the return value is null (i.e. not calc) the log is just there in case people wonder why.

This comment has been minimized.

Copy link
@egonw

egonw Aug 25, 2015

Member

No, clear!

return (output.getAuxInfo());
}

Expand Down
Expand Up @@ -135,7 +135,9 @@ public boolean getIgnoreAromaticBonds() {
}

/**
* Gets an Standard InChI generator for a {@link IAtomContainer}.
* Gets an Standard InChI generator for a {@link IAtomContainer}. AuxInfo is not
* generated by this method, please use {@link #getInChIGenerator(IAtomContainer, List)}
* with no options specified if you would like to generate AuxInfo.
*
* @param container AtomContainer to generate InChI for.
* @return the InChI generator object
Expand Down
Expand Up @@ -100,7 +100,7 @@ public void testGetAuxInfo() throws Exception {
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, CDKConstants.BONDORDER_SINGLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac);
InChIGenerator gen = getFactory().getInChIGenerator(ac, "");
Assert.assertNotNull(gen.getAuxInfo());
Assert.assertTrue(gen.getAuxInfo().startsWith("AuxInfo="));
}
Expand Down Expand Up @@ -712,7 +712,6 @@ public void testDoubleBondStereochemistry() throws Exception {

InChIGenerator genE = getFactory().getInChIGenerator(acE);
Assert.assertEquals(INCHI_RET.OKAY, genE.getReturnStatus());
System.out.println(genE.getMessage());
Assert.assertEquals("InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1+", genE.getInchi());
}

Expand Down

0 comments on commit d5afb4c

Please sign in to comment.