Using CDK Nightly Jar 1.2.x as of 07Mar09...
getNatural mass works, but getTotal mass fails as follows:
C:\Tools\cinfony\trunk\test>jython
Jython 2.5b1 (trunk:5903:5905, Jan 9 2009, 16:01:29)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0-oem
Type "help", "copyright", "credits" or "license" for more information.
from cinfony import cdk
mol = cdk.readstring("smi", "C")
manip = cdk.cdk.tools.manipulator.AtomContainerManipulator
print "Mol weight is ", manip.getNaturalExactMass(mol.Molecule)
Mol weight is 12.0107358968
print "Exact mass is ", manip.getTotalExactMass(mol.Molecule)
Exact mass is
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
at org.openscience.cdk.tools.manipulator.AtomContainerManipulator.getTot
alExactMass(AtomContainerManipulator.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NullPointerException: java.lang.NullPointerException
This is because you have not set which isotopes the molecule is.
The 'natural' mass is defined even without that information, but the total exact mass is different for 12C or 13C, etc...
What you can do instead is:
mfManip = MolecularFormulaManipulator
mf = mfManip.getMolecularFormula(mol)
exactMass = mfManip.getMajorIsotopeMass(mf)
(Added pointers to the JavaDoc, r14370).