Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Throw a CDKException when a QUADRUPLE bond order is in the input, whi…
…ch is not supported by the MDL/Symyx molfile format (fixes #3029352)

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Aug 15, 2010
1 parent c66039d commit 32cdc48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/org/openscience/cdk/io/MDLWriter.java
Expand Up @@ -35,12 +35,9 @@
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.TimeZone;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.annotations.TestClass;
Expand All @@ -50,6 +47,7 @@
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemModel;
import org.openscience.cdk.interfaces.IChemObject;
Expand Down Expand Up @@ -345,6 +343,8 @@ else if(atom.getValency()==0)
int bondType;
if (writeAromaticBondTypes.isSet() && bond.getFlag(CDKConstants.ISAROMATIC))
bondType=4;
else if (Order.QUADRUPLE == bond.getOrder())
throw new CDKException("MDL molfiles do not support quadruple bonds.");
else
bondType=(int)bond.getOrder().ordinal()+1;
line += formatMDLInt(bondType,3);
Expand Down
18 changes: 18 additions & 0 deletions src/test/org/openscience/cdk/io/MDLWriterTest.java
Expand Up @@ -36,6 +36,7 @@

import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.Bond;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemModel;
Expand All @@ -45,6 +46,7 @@
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.IChemModel;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IMolecule;
Expand Down Expand Up @@ -235,6 +237,22 @@ public class MDLWriterTest extends ChemObjectIOTest {
Assert.assertTrue(output.indexOf("2 3 1 3 0 0 0")>-1);
}

@Test(expected=CDKException.class)
public void testUnsupportedBondOrder() throws Exception {
Molecule molecule = new Molecule();
molecule.addAtom(new Atom("C"));
molecule.addAtom(new Atom("C"));
molecule.addBond(
new Bond(
molecule.getAtom(0),
molecule.getAtom(1),
Order.QUADRUPLE
)
);
MDLWriter mdlWriter = new MDLWriter(new StringWriter());
mdlWriter.write(molecule);
}

@Test public void testTwoFragmentsWithTitle() throws CDKException{
IMolecule mol1 = MoleculeFactory.makeAlphaPinene();
mol1.setProperty(CDKConstants.TITLE,"title1");
Expand Down

0 comments on commit 32cdc48

Please sign in to comment.