Skip to content

Commit

Permalink
Merged cdk-1.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Nov 2, 2011
2 parents 3a8307c + 5e828f5 commit d0d1b14
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 67 deletions.
72 changes: 30 additions & 42 deletions build.xml
Expand Up @@ -940,27 +940,21 @@
<copy todir="${sourcedist.dir}/src/META-INF">
<fileset dir="src/META-INF" />
</copy>
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/config/data/">
<fileset dir="${src}/main/org/openscience/cdk/config/data/"
includes="*" />
</copy>
<copy
file="${src}/main/org/openscience/cdk/dict/data/chemical.xml"
tofile="${sourcedist.dir}/${src}/main/org/openscience/cdk/dict/data/chemical.xml" />
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/dict/data/">
<fileset dir="${src}/main/org/openscience/cdk/dict/data/" includes="*.owl"/>
</copy>
<mkdir dir="${sourcedist.dir}/${src}/main/org/openscience/cdk/modeling/forcefield/data/"/>
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/modeling/forcefield/data/">
<fileset dir="${src}/main/org/openscience/cdk/modeling/forcefield/data/" includes="*.prm"/>
</copy>
<mkdir dir="${sourcedist.dir}/${src}/main/org/openscience/cdk/modeling/builder3d/data/"/>
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/modeling/builder3d/data/">
<fileset dir="${src}/main/org/openscience/cdk/modeling/builder3d/data/" includes="*.gz"/>
</copy>
<mkdir dir="${sourcedist.dir}/${src}/main/org/openscience/cdk/layout/templates"/>
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/layout/templates">
<fileset dir="${src}/main/org/openscience/cdk/layout/templates" includes="*"/>
<copy todir="${sourcedist.dir}/${src}/main/">
<fileset dir="${src}/main/" includesfile="${src}/META-INF/atomtype.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/builder3d.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/core.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/dict.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/extra.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/fingerprint.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/forcefield.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/io.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/log4j.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/pdb.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/qsaratomic.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/qsar.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/qsarmolecular.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/sdg.datafiles" />
</copy>
<mkdir dir="${sourcedist.dir}/doc/" />
<copy todir="${sourcedist.dir}/doc/">
Expand Down Expand Up @@ -1004,27 +998,21 @@
<copy todir="${sourcedist.dir}/src/META-INF">
<fileset dir="src/META-INF" />
</copy>
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/config/data/">
<fileset dir="${src}/main/org/openscience/cdk/config/data/"
includes="*" />
</copy>
<copy
file="${src}/main/org/openscience/cdk/dict/data/chemical.xml"
tofile="${sourcedist.dir}/${src}/main/org/openscience/cdk/dict/data/chemical.xml" />
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/dict/data/">
<fileset dir="${src}/main/org/openscience/cdk/dict/data/" includes="*.owl"/>
</copy>
<mkdir dir="${sourcedist.dir}/${src}/main/org/openscience/cdk/modeling/forcefield/data/"/>
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/modeling/forcefield/data/">
<fileset dir="${src}/main/org/openscience/cdk/modeling/forcefield/data/" includes="*.prm"/>
</copy>
<mkdir dir="${sourcedist.dir}/${src}/main/org/openscience/cdk/modeling/builder3d/data/"/>
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/modeling/builder3d/data/">
<fileset dir="${src}/main/org/openscience/cdk/modeling/builder3d/data/" includes="*.gz"/>
</copy>
<mkdir dir="${sourcedist.dir}/${src}/main/org/openscience/cdk/layout/templates"/>
<copy todir="${sourcedist.dir}/${src}/main/org/openscience/cdk/layout/templates">
<fileset dir="${src}/main/org/openscience/cdk/layout/templates" includes="*"/>
<copy todir="${sourcedist.dir}/${src}/main/">
<fileset dir="${src}/main/" includesfile="${src}/META-INF/atomtype.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/builder3d.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/core.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/dict.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/extra.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/fingerprint.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/forcefield.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/io.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/log4j.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/pdb.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/qsaratomic.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/qsar.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/qsarmolecular.datafiles" />
<fileset dir="${src}/main/" includesfile="${src}/META-INF/sdg.datafiles" />
</copy>
<mkdir dir="${sourcedist.dir}/doc/" />
<copy todir="${sourcedist.dir}/doc/">
Expand Down
Expand Up @@ -24,12 +24,13 @@
*/
package org.openscience.cdk.graph.invariant;

import org.openscience.cdk.AtomContainer;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.exception.NoSuchAtomException;
import org.openscience.cdk.graph.PathTools;
import org.openscience.cdk.graph.matrix.ConnectionMatrix;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
Expand Down Expand Up @@ -67,7 +68,7 @@ public EquivalentClassPartitioner(){}
/**
* Constructor for the TopologicalEquivalentClass object
*/
public EquivalentClassPartitioner(AtomContainer atomContainer)
public EquivalentClassPartitioner(IAtomContainer atomContainer)
{
adjaMatrix = ConnectionMatrix.getMatrix(atomContainer);
apspMatrix = PathTools.computeFloydAPSP(adjaMatrix);
Expand All @@ -88,7 +89,7 @@ public EquivalentClassPartitioner(AtomContainer atomContainer)
* @param atomContainer atoms and bonds of the molecule
* @return an array contains the automorphism partition of the molecule
*/
public int[] getTopoEquivClassbyHuXu(AtomContainer atomContainer) throws NoSuchAtomException
public int[] getTopoEquivClassbyHuXu(IAtomContainer atomContainer) throws NoSuchAtomException
{
double nodeSequence[]=prepareNode(atomContainer);
nodeMatrix=buildNodeMatrix(nodeSequence);
Expand All @@ -106,7 +107,7 @@ public int[] getTopoEquivClassbyHuXu(AtomContainer atomContainer) throws NoSuchA
* @param atomContainer atoms and bonds of the molecule
* @return an array of node identifier
*/
public double[] prepareNode(AtomContainer atomContainer)
public double[] prepareNode(IAtomContainer atomContainer)
{
java.util.Iterator atoms=atomContainer.atoms().iterator();
double nodeSequence[]=new double[atomContainer.getAtomCount()];
Expand Down
21 changes: 21 additions & 0 deletions src/main/org/openscience/cdk/io/SDFWriter.java
Expand Up @@ -31,8 +31,10 @@
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
Expand All @@ -46,6 +48,7 @@
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.io.formats.IResourceFormat;
import org.openscience.cdk.io.formats.SDFFormat;
import org.openscience.cdk.io.listener.PropertiesListener;
import org.openscience.cdk.io.setting.BooleanIOSetting;
import org.openscience.cdk.io.setting.IOSetting;
import org.openscience.cdk.smiles.InvPair;
Expand All @@ -69,6 +72,7 @@ public class SDFWriter extends DefaultChemObjectWriter {

private BufferedWriter writer;
private BooleanIOSetting writerProperties;
private Map<String,IOSetting> mdlWriterSettings;

/**
* Constructs a new SDFWriter that writes to the given {@link Writer}.
Expand Down Expand Up @@ -198,6 +202,14 @@ private void writeMolecule(IAtomContainer container) throws CDKException {
// write the MDL molfile bits
StringWriter stringWriter = new StringWriter();
MDLV2000Writer mdlWriter = new MDLV2000Writer(stringWriter);
Properties ioSettings = new Properties();
for (String settingName : mdlWriterSettings.keySet()) {
ioSettings.put(settingName, mdlWriterSettings.get(settingName).getSetting());
}
mdlWriter.addChemObjectIOListener(
new PropertiesListener(ioSettings)
);
mdlWriter.customizeJob();
mdlWriter.write(container);
mdlWriter.close();
writer.write(stringWriter.toString());
Expand Down Expand Up @@ -246,10 +258,19 @@ private void initIOSettings() {
"Should molecular properties be written?",
"true"
);
// cache the MDLV2000Writer settings
IOSetting[] settings = new MDLV2000Writer().getIOSettings();
mdlWriterSettings = new HashMap<String,IOSetting>();
for (int i=0; i<settings.length; i++) {
mdlWriterSettings.put(settings[i].getName(), settings[i]);
}
}

public void customizeJob() {
fireIOSettingQuestion(writerProperties);
for (IOSetting setting : mdlWriterSettings.values()) {
fireIOSettingQuestion(setting);
}
}

public IOSetting[] getIOSettings() {
Expand Down
Expand Up @@ -53,8 +53,7 @@
/**
* <p>Prediction of logP based on the atom-type method called XLogP. <b>Requires
* all hydrogens to be explicit</b>.
* <p>For description of the methodology see Ref. @cdk.cite{WANG97} and @cdk.cite{WANG00}
* or <a href="http://www.chem.ac.ru/Chemistry/Soft/XLOGP.en.html">http://www.chem.ac.ru/Chemistry/Soft/XLOGP.en.html</a>.
* <p>For description of the methodology see Ref. {@cdk.cite WANG97} and {@cdk.cite WANG00}.
* Actually one molecular factor is missing (presence of para Hs donor pair).
*
* <p>This descriptor uses these parameters:
Expand Down
Expand Up @@ -116,6 +116,7 @@ private void visit(LineElement line) {

int width = (int) (line.width * this.rendererModel.getParameter(
Scale.class).getValue());
if (width < 1) width = 1;
if (strokeMap.containsKey(width)) {
this.graphics.setStroke(strokeMap.get(width));
} else {
Expand Down
37 changes: 20 additions & 17 deletions src/main/org/openscience/cdk/smiles/SmilesParser.java
Expand Up @@ -254,25 +254,28 @@ public IMolecule parseSmiles(String smiles) throws InvalidSmilesException {
molecule.addStereoElement(l4Chiral);
}

if (!preservingAromaticity ) {
// perceive atom types
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(molecule.getBuilder());
int i = 0;
for (IAtom atom : molecule.atoms()) {
i++;
try {
IAtomType type = matcher.findMatchingAtomType(molecule, atom);
AtomTypeManipulator.configure(atom, type);
} catch (NoSuchAtomTypeException exception) {
logger.warn("Cannot percieve atom type for the ", i, "th atom: ", atom.getSymbol());
// perceive atom types
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(molecule.getBuilder());
int i = 0;
for (IAtom atom : molecule.atoms()) {
i++;
try {
IAtomType type = matcher.findMatchingAtomType(molecule, atom);
boolean isAromatic = atom.getFlag(CDKConstants.ISAROMATIC);
AtomTypeManipulator.configure(atom, type);
atom.setFlag(CDKConstants.ISAROMATIC, isAromatic);
} catch (NoSuchAtomTypeException exception) {
logger.warn("Cannot percieve atom type for the ", i, "th atom: ", atom.getSymbol());
atom.setAtomTypeName("X");
} catch (Exception exception) {
logger.error("Caught unexpected Exception during atom typing.");
logger.debug(exception);
atom.setAtomTypeName("X");
} catch (Exception exception) {
logger.error("Caught unexpected Exception during atom typing.");
logger.debug(exception);
atom.setAtomTypeName("X");
}
}
this.addImplicitHydrogens(molecule);
}
this.addImplicitHydrogens(molecule);

if (!preservingAromaticity ) {
this.perceiveAromaticity(molecule);
}
else {
Expand Down
31 changes: 29 additions & 2 deletions src/test/org/openscience/cdk/io/SDFWriterTest.java
Expand Up @@ -34,16 +34,18 @@
import org.openscience.cdk.AtomContainerSet;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemModel;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.MoleculeSet;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.io.listener.PropertiesListener;
import org.openscience.cdk.smiles.InvPair;
import org.openscience.cdk.smiles.SmilesParser;

/**
* TestCase for the writer MDL SD file writer.
Expand Down Expand Up @@ -188,4 +190,29 @@ public class SDFWriterTest extends ChemObjectWriterTest {
Assert.assertTrue(writer.toString().indexOf("r-us") != -1);
Assert.assertTrue(writer.toString().indexOf("$$$$") != -1);
}

/**
* @cdk.bug 3392485
*/
@Test
public void testIOPropPropagation() throws Exception {
SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
IAtomContainer mol = sp.parseSmiles("c1ccccc1CC");
CDKHueckelAromaticityDetector.detectAromaticity(mol);

StringWriter strWriter = new StringWriter();
SDFWriter writer = new SDFWriter(strWriter);

Properties sdfWriterProps = new Properties();
sdfWriterProps.put("WriteAromaticBondTypes", "true");
writer.addChemObjectIOListener(
new PropertiesListener(sdfWriterProps)
);
writer.customizeJob();
writer.write(mol);
writer.close();

String output = strWriter.toString();
Assert.assertTrue(output.contains("4 0 0 0 0"));
}
}
7 changes: 7 additions & 0 deletions src/test/org/openscience/cdk/smiles/SmilesParserTest.java
Expand Up @@ -2292,6 +2292,13 @@ public void testAromaticity() throws InvalidSmilesException{

}

@Test public void testPreserveAromaticityAndPerceiveAtomTypes() throws InvalidSmilesException{
SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
sp.setPreservingAromaticity(true);
IMolecule molecule = sp.parseSmiles("c1ccccc1");
Assert.assertNotNull(molecule.getAtom(0).getAtomTypeName());
}

/**
* @cdk.bug 3160514
*/
Expand Down

0 comments on commit d0d1b14

Please sign in to comment.