Created
March 11, 2012 18:11
Jython script for Knime node that adds a column with the molecular weight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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