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 24, 2011
2 parents a4db4a2 + 284ff84 commit 7223cfb
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 16 deletions.
2 changes: 1 addition & 1 deletion doc/refs/cheminf.bibx
Expand Up @@ -1180,7 +1180,7 @@ Method </bibtex:title>
<bibtex:volume>24</bibtex:volume>
<bibtex:number>21</bibtex:number>
<bibtex:pages>2518-2525</bibtex:pages>
<bibtex:year>2008</bibtex:pages>
<bibtex:year>2008</bibtex:year>
<bibtex:doi>10.1093/bioinformatics/btn479</bibtex:doi>
<bibtex:URL>http://bioinformatics.oxfordjournals.org/content/24/21/2518.abstract</bibtex:URL>
<bibtex:eprint>http://bioinformatics.oxfordjournals.org/content/24/21/2518.full.pdf+html</bibtex:eprint>
Expand Down
Expand Up @@ -19,6 +19,8 @@
package org.openscience.cdk.qsar.descriptors.molecular;

import org.openscience.cdk.DefaultChemObjectBuilder;
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;
Expand All @@ -45,6 +47,7 @@
* @cdk.module qsarmolecular
* @cdk.githash
*/
@TestClass("org.openscience.cdk.qsar.descriptors.molecular.ChiIndexUtilsTest")
class ChiIndexUtils {

/**
Expand Down Expand Up @@ -193,7 +196,8 @@ private static int getValenceElectronCount(IAtom atom) {
* @return The empirical delta V if it is present in one of the above
* environments, -1 otherwise
*/
private static double deltavSulphur(IAtom atom, IAtomContainer atomContainer) {
@TestMethod("testDeltaVSuplhurSO,testDeltaVSulphurSO2")
protected static double deltavSulphur(IAtom atom, IAtomContainer atomContainer) {
if (!atom.getSymbol().equals("S")) return -1;

// check whether it's a S in S-S
Expand All @@ -204,21 +208,14 @@ private static double deltavSulphur(IAtom atom, IAtomContainer atomContainer) {
return .89;
}

// check whether it's a S in -SO-
for (IAtom connectedAtom : connected) {
if (connectedAtom.getSymbol().equals("O")
&& atomContainer.getBond(atom, connectedAtom).getOrder() == IBond.Order.DOUBLE)
return 1.33;
}

// check whether it's a S in -SO2-
int count = 0;
for (IAtom connectedAtom : connected) {
if (connectedAtom.getSymbol().equals("O")
&& atomContainer.getBond(atom, connectedAtom).getOrder() == IBond.Order.DOUBLE)
count++;
}
if (count == 2) return 2.67;
if (count == 1) return 1.33; // check whether it's a S in -SO-
else if (count == 2) return 2.67; // check whether it's a S in -SO2-

return -1;
}
Expand Down
24 changes: 21 additions & 3 deletions src/main/org/openscience/cdk/renderer/BoundsCalculator.java
Expand Up @@ -26,6 +26,8 @@

import javax.vecmath.Point2d;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
Expand All @@ -43,6 +45,7 @@
* @cdk.module renderbasic
* @cdk.githash
*/
@TestClass("org.openscience.cdk.renderer.BoundsCalculatorTest")
public class BoundsCalculator {

/**
Expand All @@ -51,6 +54,7 @@ public class BoundsCalculator {
* @param chemModel the chem model to use
* @return the bounding rectangle of the chem model
*/
@TestMethod("testCalculateBounds_IChemModel")
public static Rectangle2D calculateBounds(IChemModel chemModel) {
IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
IReactionSet reactionSet = chemModel.getReactionSet();
Expand All @@ -76,6 +80,7 @@ public static Rectangle2D calculateBounds(IChemModel chemModel) {
* @param reactionSet the reaction set to use
* @return the bounding rectangle of the reaction set
*/
@TestMethod("testCalculateBounds_IReactionSet")
public static Rectangle2D calculateBounds(IReactionSet reactionSet) {
Rectangle2D totalBounds = new Rectangle2D.Double();
for (IReaction reaction : reactionSet.reactions()) {
Expand All @@ -95,6 +100,7 @@ public static Rectangle2D calculateBounds(IReactionSet reactionSet) {
* @param reaction the reaction to use
* @return the bounding rectangle of the reaction
*/
@TestMethod("testCalculateBounds_IReaction")
public static Rectangle2D calculateBounds(IReaction reaction) {
// get the participants in the reaction
IMoleculeSet reactants = reaction.getReactants();
Expand All @@ -112,7 +118,8 @@ public static Rectangle2D calculateBounds(IReaction reaction) {
* @param moleculeSet the molecule set to use
* @return the bounding rectangle of the molecule set
*/
public static Rectangle2D calculateBounds(IAtomContainerSet moleculeSet) {
@TestMethod("testCalculateBounds_IMoleculeSet")
public static Rectangle2D calculateBounds(IMoleculeSet moleculeSet) {
Rectangle2D totalBounds = new Rectangle2D.Double();
for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) {
IAtomContainer container = moleculeSet.getAtomContainer(i);
Expand All @@ -132,14 +139,20 @@ public static Rectangle2D calculateBounds(IAtomContainerSet moleculeSet) {
* @param atomContainer the atom container to use
* @return the bounding rectangle of the atom container
*/
@TestMethod("testCalculateBounds_IAtomContainer")
public static Rectangle2D calculateBounds(IAtomContainer atomContainer) {
// this is essential, otherwise a rectangle
// of (+INF, -INF, +INF, -INF) is returned!
if (atomContainer.getAtomCount() == 0) {
return new Rectangle2D.Double();
} else if (atomContainer.getAtomCount() == 1) {
Point2d p = atomContainer.getAtom(0).getPoint2d();
return new Rectangle2D.Double(p.x, p.y, 0, 0);
Point2d point = atomContainer.getAtom(0).getPoint2d();
if (point == null) {
throw new IllegalArgumentException(
"Cannot calculate bounds when 2D coordinates are missing."
);
}
return new Rectangle2D.Double(point.x, point.y, 0, 0);
}

double xmin = Double.POSITIVE_INFINITY;
Expand All @@ -149,6 +162,11 @@ public static Rectangle2D calculateBounds(IAtomContainer atomContainer) {

for (IAtom atom : atomContainer.atoms()) {
Point2d point = atom.getPoint2d();
if (point == null) {
throw new IllegalArgumentException(
"Cannot calculate bounds when 2D coordinates are missing."
);
}
xmin = Math.min(xmin, point.x);
xmax = Math.max(xmax, point.x);
ymin = Math.min(ymin, point.y);
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/openscience/cdk/tools/ProteinBuilderTool.java
Expand Up @@ -104,7 +104,7 @@ public static BioPolymer addAminoAcidAtCTerminus(

/**
* Creates a BioPolymer from a sequence of amino acid as identified by a
* the sequence of there one letter codes.
* the sequence of their one letter codes.
*
* <p>For example:
* <pre>
Expand Down
Expand Up @@ -36,6 +36,7 @@
*
* @author egonw
* @cdk.module diff
* @cdk.githash
*/
@TestClass("org.openscience.cdk.tools.diff.AtomContainerDiffTest")
public class AtomContainerDiff {
Expand Down
Expand Up @@ -90,6 +90,7 @@ protected boolean runCoverageTest() {
private int checkClass(String className) {
Class coreClass = loadClass(getClassName(className));
if (coreClass.isInterface()) return 0;
if (Modifier.isAbstract(coreClass.getModifiers())) return 0;

int missingTestCount = 0;
HashMap<String, TestMethod> methodAnnotations = new HashMap<String, TestMethod>();
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.junit.runners.Suite.SuiteClasses;
import org.openscience.cdk.coverage.RenderbasicCoverageTest;
import org.openscience.cdk.renderer.AtomContainerRendererTest;
import org.openscience.cdk.renderer.BoundsCalculatorTest;
import org.openscience.cdk.renderer.elements.ArrowElementTest;
import org.openscience.cdk.renderer.elements.AtomSymbolElementTest;
import org.openscience.cdk.renderer.elements.GeneralPathTest;
Expand Down Expand Up @@ -69,6 +70,7 @@
LineToTest.class,
CubicToTest.class,
MoveToTest.class,
QuadToTest.class
QuadToTest.class,
BoundsCalculatorTest.class
})
public class MrenderbasicTests {}
Expand Up @@ -20,12 +20,66 @@
*/
package org.openscience.cdk.qsar.descriptors.molecular;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IMolecule;

/**
* @cdk.module test-qsarmolecular
*/
public class ChiIndexUtilsTest extends CDKTestCase {

DefaultChemObjectBuilder builder;

public ChiIndexUtilsTest() {
}

@Before
public void setup() {
builder = (DefaultChemObjectBuilder) DefaultChemObjectBuilder.getInstance();
}

@Test
public void testDeltaVSulphurSO() {
IAtom s = builder.newInstance(IAtom.class, "S");
IAtom o = builder.newInstance(IAtom.class, "O");
IBond b = builder.newInstance(IBond.class, s, o);
b.setOrder(IBond.Order.DOUBLE);

IMolecule m = builder.newInstance(IMolecule.class);
m.addAtom(s);
m.addAtom(o);
m.addBond(b);

double deltav = ChiIndexUtils.deltavSulphur(s, m);
Assert.assertEquals(1.33, deltav, 0.01);
}

@Test
public void testDeltaVSulphurSO2() {
IAtom s = builder.newInstance(IAtom.class, "S");
IAtom o1 = builder.newInstance(IAtom.class, "O");
IAtom o2 = builder.newInstance(IAtom.class, "O");
IBond b1 = builder.newInstance(IBond.class, s, o1);
IBond b2 = builder.newInstance(IBond.class, s, o2);
b1.setOrder(IBond.Order.DOUBLE);
b2.setOrder(IBond.Order.DOUBLE);

IMolecule m = builder.newInstance(IMolecule.class);
m.addAtom(s);
m.addAtom(o1);
m.addBond(b1);
m.addAtom(o2);
m.addBond(b2);

double deltav = ChiIndexUtils.deltavSulphur(s, m);
Assert.assertEquals(2.67, deltav, 0.01);
}

}

0 comments on commit 7223cfb

Please sign in to comment.