Skip to content

Commit

Permalink
Merge branch 'cdk-1.4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Aug 29, 2011
2 parents 4777958 + 3152dd0 commit e49de87
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 27 deletions.
2 changes: 2 additions & 0 deletions javadoc.xml
Expand Up @@ -17,6 +17,8 @@
<property name="build" value="build" />
<property name="lib" value="jar" />
<property name="devellib" value="develjar" />
<property name="dist" value="dist" />
<property name="metainf" value="${src}/META-INF" />

<!-- Used in the html task to properly link to java library classes -->
<property name="javaURL" value="http://java.sun.com/j2se/1.5.0/docs/api/"/>
Expand Down
47 changes: 36 additions & 11 deletions src/main/org/openscience/cdk/atomtype/CDKAtomTypeMatcher.java
Expand Up @@ -169,7 +169,9 @@ public IAtomType findMatchingAtomType(IAtomContainer atomContainer, IAtom atom)
type = perceiveArsenic(atomContainer, atom);
} else if ("Cd".equals(atom.getSymbol())) {
type = perceiveCadmium(atomContainer, atom);
}else {
} else if ("Ca".equals(atom.getSymbol())) {
type = perceiveCalcium(atomContainer, atom);
} else {
if (type == null) type = perceiveHalogens(atomContainer, atom);
if (type == null) type = perceiveCommonSalts(atomContainer, atom);
if (type == null) type = perceiveOrganometallicCenters(atomContainer, atom);
Expand Down Expand Up @@ -236,6 +238,10 @@ private IAtomType perceiveBorons(IAtomContainer atomContainer, IAtom atom)
atomContainer.getConnectedAtomsCount(atom) <= 4) {
IAtomType type = getAtomType("B.minus");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atom.getFormalCharge() == +3
&& atomContainer.getConnectedAtomsCount(atom) == 4) {
IAtomType type = getAtomType("B.3plus");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atomContainer.getConnectedAtomsCount(atom) <= 3) {
IAtomType type = getAtomType("B");
if (isAcceptable(atom, atomContainer, type)) return type;
Expand Down Expand Up @@ -1391,16 +1397,7 @@ private IAtomType perceiveRubidium(IAtomContainer atomContainer, IAtom atom) thr
return null;
}
private IAtomType perceiveCommonSalts(IAtomContainer atomContainer, IAtom atom) throws CDKException {
if ("Ca".equals(atom.getSymbol())) {
if (hasOneSingleElectron(atomContainer, atom)) {
// no idea how to deal with this yet
return null;
} else if ((atom.getFormalCharge() != CDKConstants.UNSET &&
atom.getFormalCharge() == +2)) {
IAtomType type = getAtomType("Ca.2plus");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if ("Mg".equals(atom.getSymbol())) {
if ("Mg".equals(atom.getSymbol())) {
if (hasOneSingleElectron(atomContainer, atom)) {
// no idea how to deal with this yet
return null;
Expand Down Expand Up @@ -1983,6 +1980,34 @@ private IAtomType perceiveRadium(IAtomContainer atomContainer, IAtom atom) throw
}
return null;
}

private IAtomType perceiveCalcium(IAtomContainer atomContainer, IAtom atom) throws CDKException {
if ("Ca".equals(atom.getSymbol())) {
if (hasOneSingleElectron(atomContainer, atom)) {
// no idea how to deal with this yet
return null;
} else if ((atom.getFormalCharge() != CDKConstants.UNSET
&& atom.getFormalCharge() == 2 && atomContainer.getConnectedAtomsCount(atom) == 0)) {
IAtomType type = getAtomType("Ca.2plus");
if (isAcceptable(atom, atomContainer, type)) {
return type;
}
} else if ((atom.getFormalCharge() != CDKConstants.UNSET
&& atom.getFormalCharge() == 0 && atomContainer.getConnectedAtomsCount(atom) == 2)) {
IAtomType type = getAtomType("Ca.2");
if (isAcceptable(atom, atomContainer, type)) {
return type;
}
} else if ((atom.getFormalCharge() != CDKConstants.UNSET
&& atom.getFormalCharge() == 0 && atomContainer.getConnectedAtomsCount(atom) == 1)) {
IAtomType type = getAtomType("Ca.1");
if (isAcceptable(atom, atomContainer, type)) {
return type;
}
}
}
return null;
}

private int countAttachedDoubleBonds(IAtomContainer container, IAtom atom) {
return countAttachedDoubleBonds(container, atom, null);
Expand Down
23 changes: 23 additions & 0 deletions src/main/org/openscience/cdk/dict/data/cdk-atom-types.owl
Expand Up @@ -1227,6 +1227,13 @@
<at:piBondCount>0</at:piBondCount>
</at:AtomType>

<at:AtomType rdf:ID="Ca.2">
<at:formalCharge>0</at:formalCharge>
<at:hasElement rdf:resource="&elem;Ca"/>
<at:formalNeighbourCount>2</at:formalNeighbourCount>
<at:piBondCount>0</at:piBondCount>
</at:AtomType>

<at:AtomType rdf:ID="Ca.2plus">
<at:formalCharge>2</at:formalCharge>
<at:hasElement rdf:resource="&elem;Ca"/>
Expand All @@ -1236,6 +1243,13 @@
<at:lonePairCount>0</at:lonePairCount>
</at:AtomType>

<at:AtomType rdf:ID="Ca.1">
<at:formalCharge>0</at:formalCharge>
<at:hasElement rdf:resource="&elem;Ca"/>
<at:formalNeighbourCount>1</at:formalNeighbourCount>
<at:piBondCount>1</at:piBondCount>
</at:AtomType>

<at:AtomType rdf:ID="Mg.2plus">
<at:formalCharge>2</at:formalCharge>
<at:hasElement rdf:resource="&elem;Mg"/>
Expand Down Expand Up @@ -1778,6 +1792,15 @@
<at:piBondCount>0</at:piBondCount>
<at:hybridization rdf:resource="&at;sp3"/>
</at:AtomType>

<at:AtomType rdf:ID="B.3plus">
<at:formalCharge>3</at:formalCharge>
<at:hasElement rdf:resource="&elem;B"/>
<at:formalNeighbourCount>4</at:formalNeighbourCount>
<at:lonePairCount>0</at:lonePairCount>
<at:piBondCount>0</at:piBondCount>
<at:hybridization rdf:resource="&at;sp3"/>
</at:AtomType>

<at:AtomType rdf:ID="Rb.plus">
<at:formalCharge>1</at:formalCharge>
Expand Down
22 changes: 10 additions & 12 deletions src/main/org/openscience/cdk/renderer/visitor/AWTDrawVisitor.java
Expand Up @@ -57,7 +57,6 @@
import org.openscience.cdk.renderer.generators.BasicSceneGenerator;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.Scale;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.UseAntiAliasing;
import org.openscience.cdk.renderer.generators.IGeneratorParameter;


/**
Expand Down Expand Up @@ -90,8 +89,6 @@ public class AWTDrawVisitor extends AbstractAWTDrawVisitor {

private final Graphics2D graphics;

private Color backgroundColor;

/**
* Constructs a new {@link IDrawVisitor} using the AWT widget toolkit,
* taking a {@link Graphics2D} object to which the chemical content
Expand All @@ -106,12 +103,6 @@ public AWTDrawVisitor(Graphics2D graphics) {
this.rendererModel = null;

map.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);

for (IGeneratorParameter<?> param :
new BasicSceneGenerator().getParameters()) {
if (param instanceof BasicSceneGenerator.BackgroundColor)
this.backgroundColor = (Color)param.getDefault();
}
}

private void visit(ElementGroup elementGroup) {
Expand Down Expand Up @@ -175,14 +166,21 @@ private double[] transform(double xCoord, double yCoord) {
return result;
}

private Color getBackgroundColor() {
if (rendererModel == null)
return new BasicSceneGenerator.BackgroundColor().getDefault();

return rendererModel.getParameter(BasicSceneGenerator.BackgroundColor.class).getValue();
}

private void visit(TextElement textElement) {
this.graphics.setFont(this.fontManager.getFont());
Point point = this.getTextBasePoint(
textElement.text, textElement.xCoord, textElement.yCoord, graphics);
Rectangle2D textBounds =
this.getTextBounds(
textElement.text, textElement.xCoord, textElement.yCoord, graphics);
this.graphics.setColor(backgroundColor);
this.graphics.setColor(getBackgroundColor());
this.graphics.fill(textBounds);
this.graphics.setColor(textElement.color);
this.graphics.drawString(textElement.text, point.x, point.y);
Expand Down Expand Up @@ -260,7 +258,7 @@ private void visit(AtomSymbolElement atomSymbol) {
atomSymbol.text, atomSymbol.xCoord, atomSymbol.yCoord, graphics);
Rectangle2D textBounds =
this.getTextBounds(atomSymbol.text, atomSymbol.xCoord, atomSymbol.yCoord, graphics);
this.graphics.setColor(backgroundColor);
this.graphics.setColor(getBackgroundColor());
this.graphics.fill(textBounds);
this.graphics.setColor(atomSymbol.color);
this.graphics.drawString(atomSymbol.text, point.x, point.y);
Expand Down Expand Up @@ -384,7 +382,7 @@ private void visit(TextGroupElement textGroup) {
textGroup.text, textGroup.xCoord, textGroup.yCoord, graphics);
Rectangle2D textBounds =
this.getTextBounds(textGroup.text, textGroup.xCoord, textGroup.yCoord, graphics);
this.graphics.setColor(backgroundColor);
this.graphics.setColor(getBackgroundColor());
this.graphics.fill(textBounds);
this.graphics.setColor(textGroup.color);
this.graphics.drawString(textGroup.text, point.x, point.y);
Expand Down
@@ -1,6 +1,7 @@
/* $Revision: 9167 $ $Author: rajarshi $ $Date: 2007-10-22 01:26:11 +0200 (Mon, 22 Oct 2007) $
*
* Copyright (C) 2008 Rajarshi Guha <rajarshi@users.sf.net>
* 2011 Jonathan Alvarsson <jonalv@users.sf.net>
*
* Contact: cdk-devel@lists.sf.net
*
Expand Down Expand Up @@ -52,11 +53,11 @@
@TestClass("org.openscience.cdk.tools.periodictable.PeriodicTableTest")
public class PeriodicTable {

private static boolean isInitialized = false;
private static Map<String, PeriodicTableElement> elements;
private static Map<Integer, PeriodicTableElement> elementsByNumber;
private static volatile boolean isInitialized = false;
private static volatile Map<String, PeriodicTableElement> elements;
private static volatile Map<Integer, PeriodicTableElement> elementsByNumber;

private static void initialize() {
private synchronized static void initialize() {
if (isInitialized) return;

ElementPTFactory factory;
Expand Down
75 changes: 75 additions & 0 deletions src/test/org/openscience/cdk/atomtype/CDKAtomTypeMatcherTest.java
Expand Up @@ -1731,6 +1731,47 @@ public void test_Hg_2() throws Exception {
expectedTypes = new String[]{"Al.3plus"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void fix_Ca_2() throws Exception {
String molName = "Ca_2";
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class, "Ca");
a1.setFormalCharge(0);
mol.addAtom(a1);
IAtom a2 = builder.newInstance(IAtom.class, "C");
a2.setFormalCharge(0);
mol.addAtom(a2);
IAtom a3 = builder.newInstance(IAtom.class, "C");
a3.setFormalCharge(0);
mol.addAtom(a3);
IBond b1 = builder.newInstance(IBond.class, a1, a2, IBond.Order.SINGLE);
mol.addBond(b1);
IBond b2 = builder.newInstance(IBond.class, a1, a3, IBond.Order.SINGLE);
mol.addBond(b2);

String[] expectedTypes = {"Ca.2", "C.sp3", "C.sp3"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void fix_Ca_1() throws Exception {
String molName1 = "Ca_1";
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class, "Ca");
a1.setFormalCharge(0);
mol.addAtom(a1);
IAtom a2 = builder.newInstance(IAtom.class, "C");
a2.setFormalCharge(0);
mol.addAtom(a2);
IBond b1 = builder.newInstance(IBond.class, a1, a2, IBond.Order.DOUBLE);
mol.addBond(b1);

String[] expectedTypes1 = {"Ca.1", "C.sp2"};
assertAtomTypes(testedAtomTypes, expectedTypes1, mol);
}

@Test public void testCyclopentadienyl() throws Exception {
IAtomContainer cp = new Molecule();
Expand Down Expand Up @@ -3605,6 +3646,40 @@ public void testPentaMethylPhosphane() throws Exception {
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}


@Test
public void test_B_3plus() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"B");
a1.setFormalCharge(3);
mol.addAtom(a1);
IAtom a2 = builder.newInstance(IAtom.class,"C");
a2.setFormalCharge(0);
mol.addAtom(a2);
IAtom a3 = builder.newInstance(IAtom.class,"C");
a3.setFormalCharge(0);
mol.addAtom(a3);
IAtom a4 = builder.newInstance(IAtom.class,"C");
a4.setFormalCharge(0);
mol.addAtom(a4);
IAtom a5 = builder.newInstance(IAtom.class,"C");
a5.setFormalCharge(0);
mol.addAtom(a5);
IBond b1 = builder.newInstance(IBond.class,a1, a2, IBond.Order.SINGLE);
mol.addBond(b1);
IBond b2 = builder.newInstance(IBond.class,a1, a3, IBond.Order.SINGLE);
mol.addBond(b2);
IBond b3 = builder.newInstance(IBond.class,a1, a4, IBond.Order.SINGLE);
mol.addBond(b3);
IBond b4 = builder.newInstance(IBond.class,a1, a5, IBond.Order.SINGLE);
mol.addBond(b4);


String[] expectedTypes = {"B.3plus", "C.sp3", "C.sp3", "C.sp3", "C.sp3"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void test_Te_4plus() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
Expand Down

0 comments on commit e49de87

Please sign in to comment.