Skip to content

Instantly share code, notes, and snippets.

@tdudgeon
Created January 19, 2016 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdudgeon/08a858da05c958527242 to your computer and use it in GitHub Desktop.
Save tdudgeon/08a858da05c958527242 to your computer and use it in GitHub Desktop.
import org.openscience.cdk.ChemFile
import org.openscience.cdk.interfaces.IAtomContainer
import org.openscience.cdk.io.ISimpleChemObjectReader
import org.openscience.cdk.io.MDLV2000Reader
import org.openscience.cdk.io.MDLV3000Reader
import org.openscience.cdk.tools.manipulator.ChemFileManipulator
String v2000 = '''
Mrv0541 02231512112D
3 2 0 0 0 0 999 V2000
-4.1987 0.0884 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.4842 0.5009 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.9008 -0.0825 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
2 3 1 0 0 0 0
M END
'''
String v3000 = '''
Mrv0541 01191615492D
0 0 0 0 0 999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 3 2 0 0 0
M V30 BEGIN ATOM
M V30 1 C 2.31 -1.3337 0 0
M V30 2 C 3.6437 -2.1037 0 0
M V30 3 O 4.9774 -1.3337 0 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 1 1 2
M V30 2 1 2 3
M V30 END BOND
M V30 END CTAB
M END
'''
// V2000
ISimpleChemObjectReader vreader = new MDLV2000Reader(new ByteArrayInputStream(v2000.getBytes()))
ChemFile chemFile = vreader.read(new ChemFile())
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile)
assert containersList != null
assert containersList.size() == 1
println "V2000 OK"
// V3000
reader = new MDLV3000Reader(new ByteArrayInputStream(v3000.getBytes()))
chemFile = reader.read(new ChemFile())
containersList = ChemFileManipulator.getAllAtomContainers(chemFile) // throws NPE. Why?
assert containersList != null
assert containersList.size() == 1
println "V3000 OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment