Skip to content

Commit

Permalink
Avoid test-jar dependency for qsarcml - we only need the roundtrip fu…
Browse files Browse the repository at this point in the history
…nction.
  • Loading branch information
johnmay authored and egonw committed Dec 24, 2021
1 parent 777484a commit 350ce8f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
7 changes: 0 additions & 7 deletions descriptor/qsarcml/pom.xml
Expand Up @@ -73,13 +73,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cdk-libiocml</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cdk-qsarmolecular</artifactId>
Expand Down
Expand Up @@ -24,10 +24,16 @@

package org.openscience.cdk.io.cml;

import nu.xom.Element;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemModel;
import org.openscience.cdk.interfaces.IChemSequence;
import org.openscience.cdk.io.CMLReader;
import org.openscience.cdk.io.CMLWriter;
import org.openscience.cdk.libio.cml.Convertor;
import org.openscience.cdk.libio.cml.QSARCustomizer;
Expand All @@ -39,10 +45,11 @@
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;

import java.io.ByteArrayInputStream;
import java.io.StringWriter;

/**
* @author John May
* @author John Mayfield
* @cdk.module test-qsarcml
*/
public class QSARCMLRoundTripTest {
Expand All @@ -57,6 +64,34 @@ public static void setup() {
convertor.registerCustomizer(new QSARCustomizer());
}

// See also CMLRoundTripTool
public static IAtomContainer roundTripMolecule(Convertor convertor, IAtomContainer mol) throws Exception {
String cmlString = "<!-- failed -->";
Element cmlDOM = convertor.cdkAtomContainerToCMLMolecule(mol);
cmlString = cmlDOM.toXML();

IAtomContainer roundTrippedMol = null;
logger.debug("CML string: ", cmlString);
CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes()));

IChemFile file = (IChemFile) reader.read(new org.openscience.cdk.ChemFile());
reader.close();
Assert.assertNotNull(file);
Assert.assertEquals(1, file.getChemSequenceCount());
IChemSequence sequence = file.getChemSequence(0);
Assert.assertNotNull(sequence);
Assert.assertEquals(1, sequence.getChemModelCount());
IChemModel chemModel = sequence.getChemModel(0);
Assert.assertNotNull(chemModel);
IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
Assert.assertNotNull(moleculeSet);
Assert.assertEquals(1, moleculeSet.getAtomContainerCount());
roundTrippedMol = moleculeSet.getAtomContainer(0);
Assert.assertNotNull(roundTrippedMol);

return roundTrippedMol;
}

@Test
public void testDescriptorValue_QSAR() throws Exception {
IAtomContainer molecule = TestMoleculeFactory.makeBenzene();
Expand All @@ -65,7 +100,7 @@ public void testDescriptorValue_QSAR() throws Exception {
DescriptorValue originalValue = null;
originalValue = descriptor.calculate(molecule);
molecule.setProperty(originalValue.getSpecification(), originalValue);
IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, molecule);
IAtomContainer roundTrippedMol = roundTripMolecule(convertor, molecule);

Assert.assertEquals(1, roundTrippedMol.getProperties().size());
Object object = roundTrippedMol.getProperties().keySet().toArray()[0];
Expand Down

0 comments on commit 350ce8f

Please sign in to comment.