chemaxon.marvin.calculations
Class ElementalAnalyserPlugin

java.lang.Object
  extended by chemaxon.marvin.plugin.CalculatorPlugin
      extended by chemaxon.marvin.calculations.ElementalAnalyserPlugin
All Implemented Interfaces:
chemaxon.license.Licensable

public class ElementalAnalyserPlugin
extends CalculatorPlugin

Calculates molecular formula, mass, MS mass and composition.

API usage example (as an alternative, you can also use the ElementalAnalysisCalc class directly):

    // read input molecule
    MolImporter mi = new MolImporter("test.mol");
    Molecule mol = mi.read();
    mi.close();

    // create plugin
    ElementalAnalyserPlugin plugin = new ElementalAnalyserPlugin();

    // set plugin parameters
    Properties params = new Properties();
    params.put("precision", "3");
    plugin.setParameters(params);

    // set target molecule
    plugin.setMolecule(mol);

    // run the calculation
    plugin.run();

    // get results
    double exactMass = plugin.getExactMass();
    double mass = plugin.getMass();
    int atomCount1 = plugin.getAtomCount(8); // oxygen atom count
    int atomCount2 = plugin.getAtomCount(8, 0); // non-isotope oxygen count
    int atomCount3 = plugin.getAtomCount(8, 16); // oxygen isotope count with massno=16
    String formula = plugin.getFormula();
    String isotopeFormula = plugin.getIsotopeFormula();
    String composition = plugin.getComposition(); 
    String isotopeComposition = plugin.getIsotopeComposition();  
    // do something with the results ...
 

For concurrent plugin example applications using ChemAxon's concurrent framework, refer to the Concurrent plugin examples.

Since:
1.0, 11/03/2002
Version:
Marvin 5.11, 08/27/2012
Author:
Gyorgy Pirok, Zsolt Mohacsi

Nested Class Summary
 
Nested classes/interfaces inherited from class chemaxon.marvin.plugin.CalculatorPlugin
CalculatorPlugin.HydrogenData
 
Field Summary
 
Fields inherited from class chemaxon.marvin.plugin.CalculatorPlugin
ATOM, BLUE, CALCRGB_OFF, COVALENT_HYDRATION_ERROR_REMARK, CRITICAL_ERROR_MSG, EPSILON, explicitHydrogens, INCORRECT_AROMATIC_NITROGEN_REMARK, INSTABLE_TAUTOMERIC_FORM_REMARK, KEEP_HYDROGENS, keepHydrogens, licenseEnvironment, MOLECULE, MOLECULES, NAN, PLUGIN_CLASS_KEY, PLUGIN_DIR, RED, TRUE
 
Constructor Summary
ElementalAnalyserPlugin()
           
 
Method Summary
 void checkMolecule(Molecule mol)
          Checks the input molecule.
 int getAllAtomCount()
          Returns the atom count (including implicit hydrogens).
 int getAtomCount(int z)
          Returns the number of atoms with given atomic number (including its isotopes).
 int getAtomCount(int z, int m)
          Returns the number of atoms with given atomic number in the molecule isotope with the specified mass number.
 java.lang.String getComposition()
          Calculates the elemental analysis, the relative percent composition of a pure chemical substance by element (w/w%).
 java.lang.String getDotDisconnectedFormula()
          Calculates the dot-disconnected molecular formula of a multifragment molecule.
 java.lang.String getDotDisconnectedIsotopeFormula()
          Calculates the dot-disconnected isotope formula of a multifragment molecule.
 java.lang.String getDotDisconnectedIsotopeFormula(boolean symbolD)
          Calculates the dot-disconnected isotope formula of a multifragment molecule.
 java.lang.String getErrorMessage()
          Returns the calculation error information message if CalculatorPlugin.run() returned false (calculation error).
 double getExactMass()
          Calculates the weight of the MS molecule ion using the mass of the most frequent natural isotope for element atoms.
 java.lang.String getFormula()
          Calculates the molecular formula which is a string listing all atom types an their occurence in the molecule.
 java.lang.String getIsotopeComposition()
          Returns the molecular composition (w/w%).
 java.lang.String getIsotopeComposition(boolean symbolD)
          Returns the molecular composition (w/w%).
 java.lang.String getIsotopeFormula()
          Calculates the molecular formula (isotopes are separated).
 java.lang.String getIsotopeFormula(boolean symbolD)
          Calculates the molecular formula (isotopes are separated).
 double getMass()
          Calculates the molecular weight of the molecule.
 java.lang.String getProductName()
          Returns the product identifier of the plugin as given by LicenseManager.
 java.lang.Object getResult(java.lang.Object type, int index)
          Returns the result item for the specified key and index.
 java.lang.Object getResult(java.lang.Object type, java.lang.String arg)
          Returns the atom count of a specific atom.
 java.lang.String getResultAsString(java.lang.Object type, int index, java.lang.Object result)
          Returns the specified result in String format.
 int getResultCount(java.lang.Object type)
          Returns the number of result items for the given result key.
 int getResultDomain(java.lang.Object type)
          Returns the calculation domain CalculatorPlugin.ATOM or CalculatorPlugin.MOLECULE.
 Molecule getResultMolecule()
          Returns the result molecule for display.
 java.lang.Object[] getResultTypes()
          Returns the result types.
 java.lang.String getTypeString(java.lang.Object type)
          Returns a string representation of the given type.
 boolean handlesMultiFragmentMolecules()
          Returns true if the plugin handles multifragment molecules, false otherwise.
 boolean run()
          Runs the tool.
protected  void setInputMolecule(Molecule mol)
          Sets the input molecule.
 void setMolecule(java.lang.String formula)
          Specifies a molecule to calculate with.
 void setParameters(java.util.Properties params)
          Sets the input parameters for the plugin.
 void standardize(Molecule mol)
          Prevents default standardization: does nothing.
 
Methods inherited from class chemaxon.marvin.plugin.CalculatorPlugin
arrangeHydrogenIncerments, canRepeat, checkLicense, checkType, containsCoordinateBond, containsMulticenterSgroup, containsPseudoAtom, containsSRUSgroup, create, createModifiedInputMolecule, createStandardizedMolecule, createStandardizedMolecule, dehydrogenize, format, format, format, format, getAtomCount, getAtomIndex, getCalcMolecule, getDisplayMolecule, getDocument, getDoublePrecision, getExplicitHydrogenData, getInputMolDim, getMainMolecule, getpH, getPluginResource, getQueryMoleculeErrorMessage, getRemark, getResult, getResult, getResultAsRGB, getResultAsRGB, getResultAsString, getResultCount, getResultDomain, getResultMessage, getResultMolecules, getResultsAsRGB, getResultsAsRGB, getResultsAsString, getResultsAsString, getResultSource, getWarningMessage, isInputMoleculeAromatized, isLicensed, isMsCalc, isMultiThreadedRunEnabled, isNegligibleResult, isOK, isRgrouped, loadClass, readAttribute, removeWhitespace, restoreExplicitHydrogens, setDoublePrecision, setDoublePrecision, setDoublePrecision, setKeepHydrogens, setLicenseEnvironment, setMolecule, setMolecule, setMolecule, setMolecule, setProgressMonitor, standardizeIonicGroups, standardizeNeutralGroups
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementalAnalyserPlugin

public ElementalAnalyserPlugin()
Method Detail

setMolecule

public void setMolecule(java.lang.String formula)
                 throws java.lang.IllegalArgumentException
Specifies a molecule to calculate with.

Parameters:
formula - the molecular formula to calculate with
Throws:
java.lang.IllegalArgumentException - if the formula is invalid
Since:
Marvin 5.3.2

getProductName

public java.lang.String getProductName()
Description copied from class: CalculatorPlugin
Returns the product identifier of the plugin as given by LicenseManager. The name is used by the CalculatorPlugin.isLicensed() method.

Specified by:
getProductName in class CalculatorPlugin
Returns:
product identifier or a default string

setParameters

public void setParameters(java.util.Properties params)
                   throws PluginException
Sets the input parameters for the plugin. Parameters:

Overrides:
setParameters in class CalculatorPlugin
Parameters:
params - is the parameter table
Throws:
PluginException - on error

handlesMultiFragmentMolecules

public boolean handlesMultiFragmentMolecules()
Returns true if the plugin handles multifragment molecules, false otherwise. In the latter case the plugin takes the fragment with more atoms if a multifragment molecule is given as input. Returns true if parameter "single" is set to "false", false otherwise (default: false).

Overrides:
handlesMultiFragmentMolecules in class CalculatorPlugin
Returns:
true if the plugin handles multifragment molecules, false otherwise

checkMolecule

public void checkMolecule(Molecule mol)
                   throws PluginException
Checks the input molecule. Throws exception if the molecule is RxnMolecule or if the molecule contains R-groups.

Overrides:
checkMolecule in class CalculatorPlugin
Parameters:
mol - is the input molecule
Throws:
PluginException - with error message for the user if the molecule is refused

setInputMolecule

protected void setInputMolecule(Molecule mol)
                         throws PluginException
Sets the input molecule.

Specified by:
setInputMolecule in class CalculatorPlugin
Parameters:
mol - is the input molecule
Throws:
PluginException - on error

getMass

public double getMass()
Calculates the molecular weight of the molecule.

Returns:
the molecular weigth of the molecule
Since:
Marvin 3.4.1

getExactMass

public double getExactMass()
Calculates the weight of the MS molecule ion using the mass of the most frequent natural isotope for element atoms.

Returns:
the weight of the molecule ion
Since:
Marvin 3.4.1

getFormula

public java.lang.String getFormula()
Calculates the molecular formula which is a string listing all atom types an their occurence in the molecule. For example the formula of benzene is C6H6.

Returns:
the molecular formula
Since:
Marvin 3.4.1

getIsotopeFormula

public java.lang.String getIsotopeFormula()
Calculates the molecular formula (isotopes are separated). For example, it returns C7D5NaO2 for the deuterated sodium benzoate.

Returns:
isotope formula
Since:
Marvin 3.4.1

getIsotopeFormula

public java.lang.String getIsotopeFormula(boolean symbolD)
Calculates the molecular formula (isotopes are separated). For example, it returns C7[2H]5NaO2 or C7D5NaO2 for the deuterated sodium benzoate depending on symbolD parameter.

Parameters:
symbolD - uses the D symbol for Deuterium and T for Tritium if true, otherwise [2H] and [3H]
Returns:
isotope formula
Since:
Marvin 5.0

getDotDisconnectedFormula

public java.lang.String getDotDisconnectedFormula()
Calculates the dot-disconnected molecular formula of a multifragment molecule. For example, it returns C7H5O2.Na for sodium benzoate.

Returns:
the dot diconnected formula of the molecule
Since:
Marvin 3.4.1

getDotDisconnectedIsotopeFormula

public java.lang.String getDotDisconnectedIsotopeFormula()
Calculates the dot-disconnected isotope formula of a multifragment molecule. For example, it returns C7D5O2.Na for the deuterated sodium benzoate.

Returns:
the dot diconnected isotope formula of the molecule
Since:
Marvin 5.0

getDotDisconnectedIsotopeFormula

public java.lang.String getDotDisconnectedIsotopeFormula(boolean symbolD)
Calculates the dot-disconnected isotope formula of a multifragment molecule. For example, it returns C7[2H]5O2.Na or C7D5O2.Na for the deuterated sodium benzoate depending on symbolD parameter.

Parameters:
symbolD - uses the D symbol for Deuterium and T for Tritium if true, otherwise [2H] and [3H]
Returns:
the dot diconnected isotope formula of the molecule
Since:
Marvin 5.0

getComposition

public java.lang.String getComposition()
Calculates the elemental analysis, the relative percent composition of a pure chemical substance by element (w/w%).

Returns:
the molecular composition
Since:
Marvin 3.4.1

getIsotopeComposition

public java.lang.String getIsotopeComposition()
Returns the molecular composition (w/w%). Isotopes are separate atom types.

Returns:
the molecular composition
Since:
Marvin 3.4.1

getIsotopeComposition

public java.lang.String getIsotopeComposition(boolean symbolD)
Returns the molecular composition (w/w%). Isotopes are separate atom types.

Parameters:
symbolD - uses the D symbol for Deuterium and T for Tritium if true, otherwise [2H] and [3H]
Returns:
the molecular composition
Since:
Marvin 5.0.3

getAllAtomCount

public int getAllAtomCount()
Returns the atom count (including implicit hydrogens).

Returns:
the atom count
Since:
Marvin 3.4.1

getAtomCount

public int getAtomCount(int z)
Returns the number of atoms with given atomic number (including its isotopes).

Parameters:
z - is the atomic number
Returns:
the number of atoms with given atomic number
Since:
Marvin 3.4.1

getAtomCount

public int getAtomCount(int z,
                        int m)
Returns the number of atoms with given atomic number in the molecule isotope with the specified mass number. If the mass number is 0, then non-isotope atoms with the given atomic number are counted.

Parameters:
z - is the atomic number
m - is the mass number
Returns:
the number of atoms with given atomic number in the molecule isotope with the specified mass number
Since:
Marvin 3.4.1

getResult

public java.lang.Object getResult(java.lang.Object type,
                                  int index)
                           throws PluginException
Returns the result item for the specified key and index.

Overrides:
getResult in class CalculatorPlugin
Parameters:
type - is the result type
index - is the result index
Returns:
the result item for the specified key and index
Throws:
PluginException - if the result cannot be returned
See Also:
CalculatorPlugin.getResultTypes()

getResult

public java.lang.Object getResult(java.lang.Object type,
                                  java.lang.String arg)
                           throws PluginException
Returns the atom count of a specific atom.

Overrides:
getResult in class CalculatorPlugin
Parameters:
type - is the result type ("atomcount")
arg - is the atomic number or the atomic number and the mass number separated by "." (e.g. "7.14")
Returns:
number of atoms with the specified atomic number and mass number
Throws:
PluginException - if the result cannot be returned
See Also:
CalculatorPlugin.getResultTypes()

getResultAsString

public java.lang.String getResultAsString(java.lang.Object type,
                                          int index,
                                          java.lang.Object result)
                                   throws PluginException
Returns the specified result in String format.

Overrides:
getResultAsString in class CalculatorPlugin
Parameters:
type - is the result type
index - is the result index
result - is the result item
Returns:
the specified result in String format
Throws:
PluginException - if an invalid result item is given

getResultCount

public int getResultCount(java.lang.Object type)
Returns the number of result items for the given result key.

Overrides:
getResultCount in class CalculatorPlugin
Parameters:
type - is the result type
Returns:
the number of result items
See Also:
getResultTypes()

getResultDomain

public int getResultDomain(java.lang.Object type)
Returns the calculation domain CalculatorPlugin.ATOM or CalculatorPlugin.MOLECULE.

Overrides:
getResultDomain in class CalculatorPlugin
Parameters:
type - is the result key
Returns:
the calculation domain
See Also:
getResultTypes()

getResultTypes

public java.lang.Object[] getResultTypes()
Returns the result types. Possible result types:

Overrides:
getResultTypes in class CalculatorPlugin
Returns:
the result types

getTypeString

public java.lang.String getTypeString(java.lang.Object type)
Returns a string representation of the given type.

Overrides:
getTypeString in class CalculatorPlugin
Parameters:
type - is the type object
Returns:
the type string

run

public boolean run()
            throws PluginException
Runs the tool.

Specified by:
run in class CalculatorPlugin
Returns:
true if the calculation was successful, false on calculation problems
Throws:
PluginException - on error
See Also:
CalculatorPlugin.getErrorMessage()

getErrorMessage

public java.lang.String getErrorMessage()
Description copied from class: CalculatorPlugin
Returns the calculation error information message if CalculatorPlugin.run() returned false (calculation error). The default implementation returns the empty string.

Overrides:
getErrorMessage in class CalculatorPlugin
Returns:
the calculation error information message

getResultMolecule

public Molecule getResultMolecule()
                           throws PluginException
Returns the result molecule for display. Atomic results are stored in atom extra labels (MolAtom.getExtraLabel()). Molecular results are stored in molecule properties with keys being the result types (Molecule.getProperty(String)).

Overrides:
getResultMolecule in class CalculatorPlugin
Returns:
the result molecule
Throws:
PluginException - on error
Since:
Marvin 4.0

standardize

public void standardize(Molecule mol)
Prevents default standardization: does nothing. ElementalAnalyser does not need standardization.

Overrides:
standardize in class CalculatorPlugin
Parameters:
mol - is the molecule to be standardized