Skip to content

Commit

Permalink
Only write primitive non-structural data.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Mar 31, 2017
1 parent f91b329 commit 764bd8b
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions storage/io/src/main/java/org/openscience/cdk/io/SDFWriter.java
Expand Up @@ -280,11 +280,17 @@ private void writeMolecule(IAtomContainer container) throws CDKException {
String cleanHeaderKey = replaceInvalidHeaderChars(headerKey);
if (!cleanHeaderKey.equals(headerKey))
logger.info("Replaced characters in SDfile data header: ", headerKey, " written as: ", cleanHeaderKey);
writer.write("> <" + cleanHeaderKey + ">");
writer.newLine();
writer.write("" + sdFields.get(propKey));
writer.newLine();
writer.newLine();

Object val = sdFields.get(propKey);

if (isPrimitiveDataValue(val)) {
writer.write("> <" + cleanHeaderKey + ">");
writer.newLine();
if (val != null)
writer.write(val.toString());
writer.newLine();
writer.newLine();
}
}
}
}
Expand All @@ -296,6 +302,18 @@ private void writeMolecule(IAtomContainer container) throws CDKException {
}
}

private static boolean isPrimitiveDataValue(Object obj) {
return obj == null ||
obj.getClass() == String.class ||
obj.getClass() == Integer.class ||
obj.getClass() == Double.class ||
obj.getClass() == Boolean.class ||
obj.getClass() == Float.class ||
obj.getClass() == Byte.class ||
obj.getClass() == Short.class ||
obj.getClass() == Character.class;
}

private boolean writeV3000(IAtomContainer container) {
if (paramWriteV3000.isSet())
return true;
Expand Down

0 comments on commit 764bd8b

Please sign in to comment.