Skip to content

Commit

Permalink
Check for molecular descriptors modifying mol/atom/bond flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Jan 3, 2018
1 parent dd8823a commit 7ea64b4
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.vecmath.Point3d;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
Expand All @@ -29,6 +30,8 @@
import org.openscience.cdk.dict.Dictionary;
import org.openscience.cdk.dict.DictionaryDatabase;
import org.openscience.cdk.dict.Entry;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.exception.InvalidSmilesException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomType;
Expand All @@ -45,9 +48,13 @@
import org.openscience.cdk.qsar.result.IDescriptorResult;
import org.openscience.cdk.qsar.result.IntegerArrayResult;
import org.openscience.cdk.qsar.result.IntegerResult;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.templates.TestMoleculeFactory;
import org.openscience.cdk.tools.diff.AtomContainerDiff;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;

import java.util.Iterator;

/**
* Tests for molecular descriptors.
*
Expand All @@ -60,6 +67,38 @@ public abstract class MolecularDescriptorTest extends DescriptorTest<IMolecularD

public MolecularDescriptorTest() {}

private Number[] getAtomFlags(IAtomContainer mol) {
Number[] flags = new Number[mol.getAtomCount()];
for (int i = 0; i < mol.getAtomCount(); i++) {
flags[i] = mol.getAtom(i).getFlagValue();
}
return flags;
}

private Number[] getBondFlags(IAtomContainer mol) {
Number[] flags = new Number[mol.getBondCount()];
for (int i = 0; i < mol.getBondCount(); i++) {
flags[i] = mol.getBond(i).getFlagValue();
}
return flags;
}

@Test
public void descriptorDoesNotChangeFlags() throws CDKException {
IAtomContainer mol = TestMoleculeFactory.makeBenzene();
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
Number mflags = mol.getFlagValue();
Number[] aflags = getAtomFlags(mol);
Number[] bflags = getBondFlags(mol);
descriptor.calculate(mol);
Assert.assertThat("Molecule flags were modified by descriptor!",
mol.getFlagValue(), CoreMatchers.is(mflags));
Assert.assertThat("Molecule's Atom flags were modified by descriptor!",
getAtomFlags(mol), CoreMatchers.is(aflags));
Assert.assertThat("Molecule's Bond flags were modified by descriptor!",
getBondFlags(mol), CoreMatchers.is(bflags));
}

@Test
public void testDescriptorIdentifierExistsInOntology() {
Entry ontologyEntry = dict.getEntry(descriptor.getSpecification().getSpecificationReference()
Expand Down

0 comments on commit 7ea64b4

Please sign in to comment.