Permalink
Browse files

automatically set atomic number when given an element symbol, fixes b…

…ug/1296

Change-Id: I5c7e79e1784935e4f0ab1feb7f7883dab940a154
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information...
johnmay authored and egonw committed Apr 12, 2013
1 parent 8fa55bc commit 2d80a80f0d726cd07aa51cb46290f9543377dd94
@@ -25,6 +25,7 @@
package org.openscience.cdk;
import org.openscience.cdk.interfaces.IElement;
import org.openscience.cdk.tools.periodictable.PeriodicTable;
import java.io.Serializable;
@@ -93,8 +94,7 @@ public Element(IElement element) {
* @param symbol The element symbol that this element should have.
*/
public Element(String symbol) {
this();
this.symbol = symbol;
this(symbol, PeriodicTable.getAtomicNumber(symbol));
}
/**
@@ -105,7 +105,7 @@ public Element(String symbol) {
* @param atomicNumber The atomicNumber of this element.
*/
public Element(String symbol, Integer atomicNumber) {
this(symbol);
this.symbol = symbol;
this.atomicNumber = atomicNumber;
}
@@ -23,6 +23,7 @@
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IElement;
import org.openscience.cdk.tools.periodictable.PeriodicTable;
/**
* Implements the idea of an element in the periodic table.
@@ -89,8 +90,7 @@ public Element(IElement element) {
* @param symbol The element symbol that this element should have.
*/
public Element(String symbol) {
this();
this.symbol = symbol;
this(symbol, PeriodicTable.getAtomicNumber(symbol));
}
/**
@@ -101,7 +101,7 @@ public Element(String symbol) {
* @param atomicNumber The atomicNumber of this element.
*/
public Element(String symbol, Integer atomicNumber) {
this(symbol);
this.symbol = symbol;
this.atomicNumber = atomicNumber;
}
@@ -1098,4 +1098,15 @@ public void testImplicitH() throws Exception {
Assert.assertEquals("C6H6", MolecularFormulaManipulator.getString(f));
}
/**
* @cdk.bug 1296
*/
@Test public void bug1296() {
IAtomContainer container = MolecularFormulaManipulator.getAtomContainer("C8H10N4O2",
DefaultChemObjectBuilder.getInstance());
for(IAtom a : container.atoms()){
Assert.assertNotNull(a.getAtomicNumber());
}
}
}

0 comments on commit 2d80a80

Please sign in to comment.