Skip to content

Commit

Permalink
Renamed MDLWriter into MDLV2000Writer (implements #3029447)
Browse files Browse the repository at this point in the history
Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Aug 29, 2010
1 parent d4045cc commit f0256d0
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/main/org/openscience/cdk/io/MDLRXNWriter.java
Expand Up @@ -293,9 +293,9 @@ private void writeMoleculeSet(IMoleculeSet som) throws IOException, CDKException
StringWriter sw = new StringWriter();
writer.write("$MOL");
writer.newLine();
MDLWriter mdlwriter = null;
MDLV2000Writer mdlwriter = null;
try {
mdlwriter = new MDLWriter(sw);
mdlwriter = new MDLV2000Writer(sw);
} catch (Exception ex) {
logger.error(ex.getMessage());
logger.debug(ex);
Expand Down
@@ -1,6 +1,4 @@
/* $Revision$ $Author$ $Date$
*
* Copyright (C) 1997-2007 The Chemistry Development Kit (CDK) project
/* Copyright (C) 1997-2007 The Chemistry Development Kit (CDK) project
* 2009 Egon Willighagen <egonw@users.sf.net>
* 2010 Mark Rijnbeek <mark_rynbeek@users.sf.net>
*
Expand Down Expand Up @@ -77,11 +75,11 @@
* @cdk.githash
* @cdk.keyword file format, MDL molfile
*/
@TestClass("org.openscience.cdk.io.MDLWriterTest")
public class MDLWriter extends DefaultChemObjectWriter {
@TestClass("org.openscience.cdk.io.MDLV2000WriterTest")
public class MDLV2000Writer extends DefaultChemObjectWriter {

private final static ILoggingTool logger =
LoggingToolFactory.createLoggingTool(MDLWriter.class);
LoggingToolFactory.createLoggingTool(MDLV2000Writer.class);

private BooleanIOSetting forceWriteAs2DCoords;

Expand All @@ -96,7 +94,7 @@ public class MDLWriter extends DefaultChemObjectWriter {
*
* @param out The Writer to write to
*/
public MDLWriter(Writer out) {
public MDLV2000Writer(Writer out) {
if (out instanceof BufferedWriter) {
writer = (BufferedWriter)out;
} else {
Expand All @@ -111,11 +109,11 @@ public MDLWriter(Writer out) {
*
* @param output The OutputStream to write to
*/
public MDLWriter(OutputStream output) {
public MDLV2000Writer(OutputStream output) {
this(new OutputStreamWriter(output));
}

public MDLWriter() {
public MDLV2000Writer() {
this(new StringWriter());
}

Expand Down
34 changes: 17 additions & 17 deletions src/main/org/openscience/cdk/io/RGroupQueryWriter.java
Expand Up @@ -52,7 +52,7 @@
* Each RGfile is a combination of Ctabs defining the root molecule and each
* member of each Rgroup in the query.
* <br>
* This class relies on the {@link org.openscience.cdk.io.MDLWriter} to
* This class relies on the {@link org.openscience.cdk.io.MDLV2000Writer} to
* create CTAB data blocks.
*
* @cdk.module io
Expand Down Expand Up @@ -120,7 +120,7 @@ public void close() throws IOException {
*/
private String getCTAB (IAtomContainer atomContainer) throws CDKException {
StringWriter strWriter = new StringWriter();
MDLWriter mdlWriter = new MDLWriter(strWriter);
MDLV2000Writer mdlWriter = new MDLV2000Writer(strWriter);
mdlWriter.write(atomContainer);
String ctab = strWriter.toString();
//strip of the individual header, as we have one super header instead.
Expand Down Expand Up @@ -194,10 +194,10 @@ public void write(IChemObject object) throws CDKException {
int restH = rgList.isRestH()?1:0;
String logLine =
"M LOG"+
MDLWriter.formatMDLInt(1, 3)+
MDLWriter.formatMDLInt(rgrpNum, 4)+
MDLWriter.formatMDLInt(rgList.getRequiredRGroupNumber(), 4)+
MDLWriter.formatMDLInt(restH, 4)+
MDLV2000Writer.formatMDLInt(1, 3)+
MDLV2000Writer.formatMDLInt(rgrpNum, 4)+
MDLV2000Writer.formatMDLInt(rgList.getRequiredRGroupNumber(), 4)+
MDLV2000Writer.formatMDLInt(restH, 4)+
" "+rgList.getOccurrence()
;
rootBlock.append(logLine).append(LSEP);
Expand Down Expand Up @@ -228,17 +228,17 @@ public void write(IChemObject object) throws CDKException {
StringBuffer aalLine=new StringBuffer("M AAL");
for (int atIdx = 0; atIdx < rootAtc.getAtomCount(); atIdx++) {
if (rootAtc.getAtom(atIdx).equals(rgroupAtom)) {
aalLine.append(MDLWriter.formatMDLInt((atIdx+1), 4));
aalLine.append(MDLWriter.formatMDLInt(rApo.size(), 3));
aalLine.append(MDLV2000Writer.formatMDLInt((atIdx+1), 4));
aalLine.append(MDLV2000Writer.formatMDLInt(rApo.size(), 3));

apoIdx=1;
while (rApo.get(apoIdx)!=null) {
IAtom partner=rApo.get(apoIdx).getConnectedAtom(rgroupAtom);

for(int a=0; a<rootAtc.getAtomCount(); a++) {
if (rootAtc.getAtom(a).equals(partner)) {
aalLine.append(MDLWriter.formatMDLInt(a+1, 4));
aalLine.append(MDLWriter.formatMDLInt(apoIdx, 4));
aalLine.append(MDLV2000Writer.formatMDLInt(a+1, 4));
aalLine.append(MDLV2000Writer.formatMDLInt(apoIdx, 4));
}
}
apoIdx++;
Expand All @@ -258,7 +258,7 @@ public void write(IChemObject object) throws CDKException {
List<RGroup> rgrpList = rGroupQuery.getRGroupDefinitions().get(rgrpNum).getRGroups();
if(rgrpList!=null && rgrpList.size()!=0) {
rgpBlock.append("$RGP").append(LSEP);;
rgpBlock.append(MDLWriter.formatMDLInt(rgrpNum, 4)).append(LSEP);
rgpBlock.append(MDLV2000Writer.formatMDLInt(rgrpNum, 4)).append(LSEP);

for (RGroup rgroup : rgrpList) {
//CTAB block
Expand All @@ -275,28 +275,28 @@ public void write(IChemObject object) throws CDKException {
StringBuffer apoLine=new StringBuffer();
for (int atIdx = 0; atIdx < rgroup.getGroup().getAtomCount(); atIdx++) {
if (rgroup.getGroup().getAtom(atIdx).equals(firstAttachmentPoint)) {
apoLine.append(MDLWriter.formatMDLInt((atIdx+1), 4));
apoLine.append(MDLV2000Writer.formatMDLInt((atIdx+1), 4));
apoCount++;
if (secondAttachmentPoint!=null &&
secondAttachmentPoint.equals(firstAttachmentPoint)) {
apoLine.append(MDLWriter.formatMDLInt(3, 4));
apoLine.append(MDLV2000Writer.formatMDLInt(3, 4));
}
else {
apoLine.append(MDLWriter.formatMDLInt(1, 4));
apoLine.append(MDLV2000Writer.formatMDLInt(1, 4));
}
}
}
if (secondAttachmentPoint!=null && !secondAttachmentPoint.equals(firstAttachmentPoint)) {
for (int atIdx = 0; atIdx < rgroup.getGroup().getAtomCount(); atIdx++) {
if (rgroup.getGroup().getAtom(atIdx).equals(secondAttachmentPoint)) {
apoCount++;
apoLine.append(MDLWriter.formatMDLInt((atIdx+1), 4));
apoLine.append(MDLWriter.formatMDLInt(2, 4));
apoLine.append(MDLV2000Writer.formatMDLInt((atIdx+1), 4));
apoLine.append(MDLV2000Writer.formatMDLInt(2, 4));
}
}
}
if (apoCount>0) {
apoLine.insert(0, "M APO"+MDLWriter.formatMDLInt(apoCount, 3));
apoLine.insert(0, "M APO"+MDLV2000Writer.formatMDLInt(apoCount, 3));
rgpBlock.append(apoLine).append(LSEP);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/openscience/cdk/io/SDFWriter.java
Expand Up @@ -197,7 +197,7 @@ private void writeMolecule(IAtomContainer container) throws CDKException {
try {
// write the MDL molfile bits
StringWriter stringWriter = new StringWriter();
MDLWriter mdlWriter = new MDLWriter(stringWriter);
MDLV2000Writer mdlWriter = new MDLV2000Writer(stringWriter);
mdlWriter.write(container);
mdlWriter.close();
writer.write(stringWriter.toString());
Expand Down
Expand Up @@ -69,7 +69,7 @@ public String getReaderClassName() {
}
@TestMethod("testGetWriterClassName")
public String getWriterClassName() {
return "org.openscience.cdk.io.MDLWriter";
return "org.openscience.cdk.io.MDLV2000Writer";
}

public boolean matches(int lineNumber, String line) {
Expand Down
Expand Up @@ -42,7 +42,7 @@
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.io.MDLWriter;
import org.openscience.cdk.io.MDLV2000Writer;
import org.openscience.cdk.io.iterator.IteratingMDLReader;
import org.openscience.cdk.isomorphism.matchers.QueryAtomContainerCreator;
import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder;
Expand Down Expand Up @@ -187,10 +187,10 @@ public void extractUniqueRingSystemsFromFile(String dataFile) {
String molfile = dataFile + "_UniqueRings";

// FileOutputStream fout=null;
MDLWriter mdlw = null;
MDLV2000Writer mdlw = null;
try {
FileOutputStream fout = new FileOutputStream(molfile);
mdlw = new MDLWriter(fout);
mdlw = new MDLV2000Writer(fout);
} catch (Exception ex2) {
System.out.println("IOError:cannot write file due to:"
+ ex2.toString());
Expand Down Expand Up @@ -297,7 +297,7 @@ public void writeChemModel(IMoleculeSet som, String file, String endFix) {
String molfile = file + endFix;
try {
FileOutputStream fout = new FileOutputStream(molfile);
MDLWriter mdlw = new MDLWriter(fout);
MDLV2000Writer mdlw = new MDLV2000Writer(fout);
mdlw.write(som);
mdlw.close();
} catch (Exception ex2) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/org/openscience/cdk/io/MDLCMLRoundtripTest.java
Expand Up @@ -70,7 +70,7 @@ public void testBug1649526() throws Exception{
IChemFile file = (IChemFile)cmlreader.read(new org.openscience.cdk.ChemFile());
//And finally write as mol
StringWriter writermdl = new StringWriter();
MDLWriter mdlWriter = new MDLWriter(writermdl);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writermdl);
mdlWriter.write(file);
String output = writermdl.toString();
//if there would be 3 instances (as in the bug), the only instance wouldnt't be right at the end
Expand Down
Expand Up @@ -63,19 +63,19 @@
*
* @cdk.module test-io
*
* @see org.openscience.cdk.io.MDLWriter
* @see org.openscience.cdk.io.MDLV2000Writer
*/
public class MDLWriterTest extends ChemObjectIOTest {
public class MDLV2000WriterTest extends ChemObjectIOTest {

private static IChemObjectBuilder builder;

@BeforeClass public static void setup() {
builder = DefaultChemObjectBuilder.getInstance();
setChemObjectIO(new MDLWriter());
setChemObjectIO(new MDLV2000Writer());
}

@Test public void testAccepts() throws Exception {
MDLWriter reader = new MDLWriter();
MDLV2000Writer reader = new MDLV2000Writer();
Assert.assertTrue(reader.accepts(ChemFile.class));
Assert.assertTrue(reader.accepts(ChemModel.class));
Assert.assertTrue(reader.accepts(Molecule.class));
Expand All @@ -93,7 +93,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
molecule.addAtom(new Atom("C"));
molecule.addAtom(new Atom("C"));

MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);
Assert.assertTrue(writer.toString().indexOf("M END") != -1);
}
Expand All @@ -108,7 +108,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
atom.setMassNumber(14);
molecule.addAtom(atom);

MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);
String output = writer.toString();
//logger.debug("MDL output for testBug1212219: " + output);
Expand All @@ -120,7 +120,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
Molecule molecule = MoleculeFactory.makeAlphaPinene();
molecule.getAtom(0).setValency(1);
molecule.getAtom(1).setValency(0);
MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);
String output = writer.toString();
Assert.assertTrue(output.indexOf("0 0 0 0 0 1 0 0 0 0 0 0") != -1);
Expand All @@ -132,7 +132,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
Molecule molecule = MoleculeFactory.makeAlphaPinene();
molecule.getAtom(0).setProperty(CDKConstants.ATOM_ATOM_MAPPING,1);
molecule.getAtom(1).setProperty(CDKConstants.ATOM_ATOM_MAPPING,15);
MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);
String output = writer.toString();
Assert.assertTrue(output.indexOf("0 0 0 0 0 0 0 0 0 1 0 0") != -1);
Expand Down Expand Up @@ -160,7 +160,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
molecule.addAtom(atom2);
molecule.addBond(bond);

MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);
String output = writer.toString();
Assert.assertEquals("Test for zero length pseudo atom label in MDL file", -1, output.indexOf("0.0000 0.0000 0.0000 0 0 0 0 0 0 0 0 0 0 0 0"));
Expand All @@ -173,7 +173,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
atom.setFormalCharge(null);
molecule.addAtom(atom);

MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);
String output = writer.toString();
// test ensures that the writer does not throw an exception on
Expand All @@ -191,7 +191,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
atom.setPoint3d(new Point3d(3.0, 4.0, 5.0));
molecule.addAtom(atom);

MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);
mdlWriter.close();
String output = writer.toString();
Expand All @@ -210,7 +210,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
atom.setPoint3d(new Point3d(3.0, 4.0, 5.0));
molecule.addAtom(atom);

MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
Properties prop = new Properties();
prop.setProperty("ForceWriteAs2DCoordinates","true");
PropertiesListener listener = new PropertiesListener(prop);
Expand All @@ -230,7 +230,7 @@ public class MDLWriterTest extends ChemObjectIOTest {
mol.getBond(0).setStereo(IBond.Stereo.UP_OR_DOWN);
mol.getBond(1).setStereo(IBond.Stereo.E_OR_Z);
StringWriter writer = new StringWriter();
MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(mol);
String output = writer.toString();
Assert.assertTrue(output.indexOf("1 2 2 4 0 0 0")>-1);
Expand All @@ -249,7 +249,7 @@ public void testUnsupportedBondOrder() throws Exception {
Order.QUADRUPLE
)
);
MDLWriter mdlWriter = new MDLWriter(new StringWriter());
MDLV2000Writer mdlWriter = new MDLV2000Writer(new StringWriter());
mdlWriter.write(molecule);
}

Expand All @@ -263,7 +263,7 @@ public void testUnsupportedBondOrder() throws Exception {
model.getMoleculeSet().addAtomContainer(mol1);
model.getMoleculeSet().addAtomContainer(mol2);
StringWriter writer = new StringWriter();
MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(model);
String output = writer.toString();
Assert.assertTrue(output.contains("title1; title2"));
Expand Down Expand Up @@ -293,7 +293,7 @@ public void testUnsupportedBondOrder() throws Exception {
molecule.addBond(bond);
molecule.addBond(bond2);

MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);
String output = writer.toString();

Expand All @@ -318,7 +318,7 @@ public void testUnsupportedBondOrder() throws Exception {
molecule.addBond(bond);

StringWriter writer = new StringWriter();
MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(molecule);

Assert.assertTrue(writer.toString().indexOf("V 1 Oxygen comment") != -1);
Expand All @@ -338,13 +338,13 @@ public void testUnsupportedBondOrder() throws Exception {


StringWriter writer = new StringWriter();
MDLWriter mdlWriter = new MDLWriter(writer);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(benzene);
Assert.assertTrue(writer.toString().indexOf("2 1 1 0 0 0 0") != -1);


writer = new StringWriter();
mdlWriter = new MDLWriter(writer);
mdlWriter = new MDLV2000Writer(writer);
Properties prop = new Properties();
prop.setProperty("WriteAromaticBondTypes","true");
PropertiesListener listener = new PropertiesListener(prop);
Expand Down
4 changes: 2 additions & 2 deletions src/test/org/openscience/cdk/modulesuites/MioTests.java
Expand Up @@ -45,7 +45,7 @@
import org.openscience.cdk.io.MDLReaderTest;
import org.openscience.cdk.io.MDLV2000ReaderTest;
import org.openscience.cdk.io.MDLV3000ReaderTest;
import org.openscience.cdk.io.MDLWriterTest;
import org.openscience.cdk.io.MDLV2000WriterTest;
import org.openscience.cdk.io.Mol2ReaderTest;
import org.openscience.cdk.io.PCCompoundASNReaderTest;
import org.openscience.cdk.io.PDBWriterTest;
Expand Down Expand Up @@ -88,7 +88,7 @@
MDLV2000ReaderTest.class,
MDLV3000ReaderTest.class,
SDFReaderTest.class,
MDLWriterTest.class,
MDLV2000WriterTest.class,
SDFWriterTest.class,
MDLRXNReaderTest.class,
MDLRXNV2000ReaderTest.class,
Expand Down

0 comments on commit f0256d0

Please sign in to comment.