Skip to content

Instantly share code, notes, and snippets.

@baoilleach
Created March 11, 2012 18:11
Jython script for Knime node that adds a column with the molecular weight
import java
import org.openscience.cdk as cdk
mdlreader = cdk.io.MDLV2000Reader
iterator = inData0.iterator()
while iterator.hasNext():
row = iterator.next()
rowkey = row.getKey()
cell = row.getCell(0)
value = str(cell)
reader = mdlreader(java.io.StringReader(value))
chemfile = reader.read(cdk.ChemFile())
manip = cdk.tools.manipulator.ChemFileManipulator
molecule = manip.getAllAtomContainers(chemfile)[0]
clone = molecule.clone()
atommanip = cdk.tools.manipulator.AtomContainerManipulator
atommanip.convertImplicitToExplicitHydrogens(clone)
molwt = atommanip.getNaturalExactMass(clone)
newDoubleCell = DoubleCell(molwt)
newRow = AppendedColumnRow(row, [newDoubleCell])
outContainer.addRowToTable(newRow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment