Permalink
Browse files

Added writer IO option to force writing of 2D coordinates if 3D coord…

…inates are present too, which now are preferably outputted.

See upstream patch report:

http://sourceforge.net/tracker/index.php?func=detail&aid=2805271&group_id=20024&atid=320024

git-svn-id: https://bioclipse.svn.sourceforge.net/svnroot/bioclipse/bioclipse2/trunk@11290 fcb5ba71-d80d-0410-8237-ba3920747fcc
  • Loading branch information...
1 parent c45da60 commit a78f80bf47f35871015a033c59e342cc081944b0 egonw committed with Jun 12, 2009
@@ -54,6 +54,8 @@
import org.openscience.cdk.interfaces.IPseudoAtom;
import org.openscience.cdk.io.formats.IResourceFormat;
import org.openscience.cdk.io.formats.MDLFormat;
+import org.openscience.cdk.io.setting.BooleanIOSetting;
+import org.openscience.cdk.io.setting.IOSetting;
import org.openscience.cdk.tools.LoggingTool;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
@@ -77,6 +79,8 @@
private final static LoggingTool logger = new LoggingTool(MDLWriter.class);
+ private BooleanIOSetting forceWriteAs2DCoords;
+
private BufferedWriter writer;
/**
@@ -91,6 +95,7 @@ public MDLWriter(Writer out) {
} else {
writer = new BufferedWriter(out);
}
+ initIOSettings();
}
/**
@@ -155,6 +160,7 @@ public boolean accepts(Class classObject) {
* @see #accepts(Class)
*/
public void write(IChemObject object) throws CDKException {
+ customizeJob();
try {
if (object instanceof IChemFile) {
writeChemFile((IChemFile)object);
@@ -237,7 +243,7 @@ public void writeMolecule(IAtomContainer container) throws Exception {
for (int f = 0; f < container.getAtomCount(); f++) {
IAtom atom = container.getAtom(f);
line = "";
- if (atom.getPoint3d() != null) {
+ if (atom.getPoint3d() != null && !forceWriteAs2DCoords.isSet()) {
line += formatMDLFloat((float) atom.getPoint3d().x);
line += formatMDLFloat((float) atom.getPoint3d().y);
line += formatMDLFloat((float) atom.getPoint3d().z) + " ";
@@ -414,6 +420,25 @@ private String formatMDLString(String s, int le) {
return s;
}
+ private void initIOSettings() {
+ forceWriteAs2DCoords = new BooleanIOSetting(
+ "ForceWriteAs2DCoordinates",
+ IOSetting.LOW,
+ "Should coordinates always be written as 2D?",
+ "false"
+ );
+ }
+
+ public void customizeJob() {
+ fireIOSettingQuestion(forceWriteAs2DCoords);
+ }
+
+ public IOSetting[] getIOSettings() {
+ IOSetting[] settings = new IOSetting[1];
+ settings[0] = forceWriteAs2DCoords;
+ return settings;
+ }
+
}

0 comments on commit a78f80b

Please sign in to comment.