Package chemaxon.marvin.calculations
Class ElementalAnalyserPlugin
- java.lang.Object
-
- chemaxon.marvin.plugin.CalculatorPlugin
-
- chemaxon.marvin.calculations.ElementalAnalyserPlugin
-
- All Implemented Interfaces:
chemaxon.license.Licensable
@PublicAPI public class ElementalAnalyserPlugin extends CalculatorPlugin
Calculates molecular formula, mass, MS mass and composition.API usage example:
// 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ElementalAnalyserPlugin.ResultType
Represents the different result types of the elemental analyser plugin.-
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
Constructors Constructor Description ElementalAnalyserPlugin()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.String
getComposition()
Calculates the elemental analysis, the relative percent composition of a pure chemical substance by element (w/w%).String
getDotDisconnectedFormalChargeFormula()
Calculates the dot-disconnected molecular formula of a multifragment molecule with its formal charge.String
getDotDisconnectedFormula()
Calculates the dot-disconnected molecular formula of a multifragment molecule.String
getDotDisconnectedIsotopeFormalChargeFormula()
Calculates the dot-disconnected isotope formula of a multifragment molecule with its formal charge.String
getDotDisconnectedIsotopeFormalChargeFormula(boolean symbolD)
Calculates the dot-disconnected isotope formula of a multifragment molecule with its formal charge.String
getDotDisconnectedIsotopeFormula()
Calculates the dot-disconnected isotope formula of a multifragment molecule.String
getDotDisconnectedIsotopeFormula(boolean symbolD)
Calculates the dot-disconnected isotope formula of a multifragment molecule.String
getErrorMessage()
Returns the calculation error information message ifCalculatorPlugin.run()
returnedfalse
(calculation error).double
getExactMass()
Calculates the weight of the MS molecule ion using the mass of the most frequent natural isotope for element atoms.String
getFormalChargeFormula()
Calculates the molecular formula with formal charge.String
getFormalChargeFormula(int digits)
Calculates a fixed digit sortable molecular formula with formal charge.String
getFormula()
Calculates the molecular formula which is a string listing all atom types an their occurence in the molecule.String
getFormula(int digits)
Calculates a fixed digit sortable molecular formula.String
getGroupedDotDisconnectedFormula()
Calculates the grouped dot-disconnected molecular formula of a multifragment molecule.String
getIsotopeComposition()
Returns the molecular composition (w/w%).String
getIsotopeComposition(boolean symbolD)
Returns the molecular composition (w/w%).List<chemaxon.common.util.Pair<BigDecimal,BigDecimal>>
getIsotopeDistribution()
Calculates the isotopic distributions for the molecule.String
getIsotopeFormalChargeFormula()
Calculates the molecular formula (isotopes are separated).String
getIsotopeFormalChargeFormula(boolean symbolD)
Calculates the molecular formula with formal charge (isotopes are separated).String
getIsotopeFormula()
Calculates the molecular formula (isotopes are separated).String
getIsotopeFormula(boolean symbolD)
Calculates the molecular formula (isotopes are separated).double
getMass()
Calculates the molecular weight of the molecule.int
getNominalMass()
Mass of the molecule calculated using the isotope mass of the most abundant constituent element isotope of each element rounded to the nearest integer value and multiplied by the number of atoms of each element.String
getProductName()
Returns the product identifier of the plugin as given byLicenseManager
.Object
getResult(Object type, int index)
Returns the result item for the specified key and index.Object
getResult(Object type, String arg)
Returns the atom count of a specific atom.String
getResultAsString(Object type, int index, Object result)
Returns the specified result in String format.int
getResultCount(Object type)
Returns the number of result items for the given result key.int
getResultDomain(Object type)
Returns the calculation domainCalculatorPlugin.ATOM
orCalculatorPlugin.MOLECULE
.Molecule
getResultMolecule()
Returns the result molecule for display.List<ElementalAnalyserPlugin.ResultType>
getResultTypeList()
Returns the result types.Object[]
getResultTypes()
Returns the string IDs of theresult types
.String
getTypeString(Object type)
Returns a string representation of the given type.boolean
handlesMultiFragmentMolecules()
Returnstrue
if the plugin handles multifragment molecules,false
otherwise.boolean
run()
Runs the tool.void
setFormulaRecognition(boolean recognize)
Recognizes the molecular formulas in pseudo labels.protected void
setInputMolecule(Molecule mol)
Sets the input molecule.void
setMolecule(String formula)
Specifies a molecule to calculate with.void
setParameters(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
addHeavyAtomLimitChecker, addInputChecker, arrangeHydrogenIncerments, canRepeat, checkLicense, checkType, containsCoordinateBond, containsMulticenterSgroup, containsPseudoAtom, containsSRUSgroup, create, createModifiedInputMolecule, createStandardizedMolecule, createStandardizedMolecule, dehydrogenize, format, format, format, format, getAtomCount, getAtomIndex, getAtomIndexMap, getCalcMolecule, getDisplayMolecule, getDocument, getDoublePrecision, getExplicitHydrogenData, getInputMolDim, getMainMolecule, getOriginalMolecule, 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, setAtomIndexMap, setDoublePrecision, setDoublePrecision, setDoublePrecision, setKeepHydrogens, setLicenseEnvironment, setMolecule, setMolecule, setMolecule, setMolecule, setProgressMonitor, standardizeIonicGroups, standardizeNeutralGroups
-
-
-
-
Method Detail
-
setMolecule
public void setMolecule(String formula) throws IllegalArgumentException
Specifies a molecule to calculate with.- Parameters:
formula
- the molecular formula to calculate with- Throws:
IllegalArgumentException
- if the formula is invalid- Since:
- Marvin 5.3.2
-
getProductName
public String getProductName()
Description copied from class:CalculatorPlugin
Returns the product identifier of the plugin as given byLicenseManager
. The name is used by theCalculatorPlugin.isLicensed()
method.- Specified by:
getProductName
in classCalculatorPlugin
- Returns:
- product identifier or a default string
-
setParameters
public void setParameters(Properties params) throws PluginException
Sets the input parameters for the plugin. Parameters:- single: "true" if single fragment mode (calculation is performed separately for each fragment) (default: "false")
- type: result types, separated by ','
(for possible values, see the string IDs of the constants in the
ElementalAnalyserPlugin.ResultType
enum) (default: "mass,exactmass,formula,composition")
- Overrides:
setParameters
in classCalculatorPlugin
- Parameters:
params
- is the parameter table- Throws:
PluginException
- on error
-
setFormulaRecognition
public void setFormulaRecognition(boolean recognize)
Recognizes the molecular formulas in pseudo labels.- Parameters:
recognize
- true to set recognition
-
handlesMultiFragmentMolecules
public boolean handlesMultiFragmentMolecules()
Returnstrue
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. Returnstrue
if parameter "single" is set to "false",false
otherwise (default:false
).- Overrides:
handlesMultiFragmentMolecules
in classCalculatorPlugin
- 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 isRxnMolecule
or if the molecule contains R-groups.- Overrides:
checkMolecule
in classCalculatorPlugin
- 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 classCalculatorPlugin
- 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
-
getNominalMass
public int getNominalMass()
Mass of the molecule calculated using the isotope mass of the most abundant constituent element isotope of each element rounded to the nearest integer value and multiplied by the number of atoms of each element.- Returns:
- the nominal mass of the molecule
- Since:
- Marvin 21.14
-
getFormula
public 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
-
getFormula
public String getFormula(int digits)
Calculates a fixed digit sortable molecular formula. If the digits parameter is 4, then the formula of benzene will be "C0006H0006".- Parameters:
digits
- number of minimum digits- Returns:
- molecular formula
- Since:
- Marvin 6.0
-
getFormalChargeFormula
public String getFormalChargeFormula()
Calculates the molecular formula with formal charge.- Returns:
- formula with formal charge
-
getFormalChargeFormula
public String getFormalChargeFormula(int digits)
Calculates a fixed digit sortable molecular formula with formal charge. If the digits parameter is 4, then the formula of benzene will be "C0006H0006".- Parameters:
digits
- number of minimum digits- Returns:
- molecular formula with formal charge
-
getIsotopeFormula
public 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 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
-
getIsotopeFormalChargeFormula
public String getIsotopeFormalChargeFormula()
Calculates the molecular formula (isotopes are separated).- Returns:
- isotope formula with formal charge
-
getIsotopeFormalChargeFormula
public String getIsotopeFormalChargeFormula(boolean symbolD)
Calculates the molecular formula with formal charge (isotopes are separated).- Parameters:
symbolD
- uses the D symbol for Deuterium and T for Tritium if true, otherwise [2H] and [3H]- Returns:
- isotope formula with formal charge
-
getDotDisconnectedFormula
public String getDotDisconnectedFormula()
Calculates the dot-disconnected molecular formula of a multifragment molecule. For example, it returns C7H5O2.Na for sodium benzoate.- Returns:
- the dot-disconnected formula of the molecule
- Since:
- Marvin 3.4.1
-
getDotDisconnectedFormalChargeFormula
public String getDotDisconnectedFormalChargeFormula()
Calculates the dot-disconnected molecular formula of a multifragment molecule with its formal charge.- Returns:
- the dot-disconnected formula of the molecule its with formal charge
-
getDotDisconnectedIsotopeFormula
public 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-disconnected isotope formula of the molecule
- Since:
- Marvin 5.0
-
getDotDisconnectedIsotopeFormula
public 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-disconnected isotope formula of the molecule
- Since:
- Marvin 5.0
-
getDotDisconnectedIsotopeFormalChargeFormula
public String getDotDisconnectedIsotopeFormalChargeFormula()
Calculates the dot-disconnected isotope formula of a multifragment molecule with its formal charge.- Returns:
- the dot-disconnected isotope formula of the molecule with its formal charge
-
getDotDisconnectedIsotopeFormalChargeFormula
public String getDotDisconnectedIsotopeFormalChargeFormula(boolean symbolD)
Calculates the dot-disconnected isotope formula of a multifragment molecule with its formal charge.- Parameters:
symbolD
- uses the D symbol for Deuterium and T for Tritium if true, otherwise [2H] and [3H]- Returns:
- the dot-disconnected isotope formula of the molecule with its formal charge
-
getGroupedDotDisconnectedFormula
public String getGroupedDotDisconnectedFormula()
Calculates the grouped dot-disconnected molecular formula of a multifragment molecule.- Returns:
- the grouped dot-disconnected formula of the molecule
- Since:
- Marvin 14.8.14
-
getComposition
public 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 String getIsotopeComposition()
Returns the molecular composition (w/w%). Isotopes are separate atom types.- Returns:
- the molecular composition
- Since:
- Marvin 3.4.1
-
getIsotopeComposition
public 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
-
getIsotopeDistribution
public List<chemaxon.common.util.Pair<BigDecimal,BigDecimal>> getIsotopeDistribution()
Calculates the isotopic distributions for the molecule. The distribution of fragments are merged. Takes charge into account.- Returns:
- the list of masses and distributions. the maximum of distribution is normalized to 100.
-
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 is0
, then non-isotope atoms with the given atomic number are counted.- Parameters:
z
- is the atomic numberm
- 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 Object getResult(Object type, int index) throws PluginException
Returns the result item for the specified key and index.- Overrides:
getResult
in classCalculatorPlugin
- Parameters:
type
- is the result type (use the constants ofElementalAnalyserPlugin.ResultType
or their string IDs)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 Object getResult(Object type, String arg) throws PluginException
Returns the atom count of a specific atom.- Overrides:
getResult
in classCalculatorPlugin
- 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 String getResultAsString(Object type, int index, Object result) throws PluginException
Returns the specified result in String format.- Overrides:
getResultAsString
in classCalculatorPlugin
- Parameters:
type
- is the result type (use the constants ofElementalAnalyserPlugin.ResultType
or their string IDs)index
- is the result indexresult
- is the result item- Returns:
- the specified result in String format
- Throws:
PluginException
- if an invalid result item is given
-
getResultCount
public int getResultCount(Object type)
Returns the number of result items for the given result key.- Overrides:
getResultCount
in classCalculatorPlugin
- Parameters:
type
- is the result type (use the constants ofElementalAnalyserPlugin.ResultType
or their string IDs)- Returns:
- the number of result items
- See Also:
getResultTypes()
-
getResultDomain
public int getResultDomain(Object type)
Returns the calculation domainCalculatorPlugin.ATOM
orCalculatorPlugin.MOLECULE
.- Overrides:
getResultDomain
in classCalculatorPlugin
- Parameters:
type
- is the result key- Returns:
- the calculation domain
- See Also:
getResultTypes()
-
getResultTypes
public Object[] getResultTypes()
Returns the string IDs of theresult types
.- Overrides:
getResultTypes
in classCalculatorPlugin
- Returns:
- the result types
- See Also:
getResultTypeList()
-
getResultTypeList
public List<ElementalAnalyserPlugin.ResultType> getResultTypeList()
Returns the result types.- Returns:
- the result types
-
getTypeString
public String getTypeString(Object type)
Returns a string representation of the given type.- Overrides:
getTypeString
in classCalculatorPlugin
- Parameters:
type
- is the type object (use the constants ofElementalAnalyserPlugin.ResultType
or their string IDs)- Returns:
- the type string
-
run
public boolean run() throws PluginException
Runs the tool.- Specified by:
run
in classCalculatorPlugin
- Returns:
- true if the calculation was successful, false on calculation problems
- Throws:
PluginException
- on error- See Also:
CalculatorPlugin.getErrorMessage()
-
getErrorMessage
public String getErrorMessage()
Description copied from class:CalculatorPlugin
Returns the calculation error information message ifCalculatorPlugin.run()
returnedfalse
(calculation error). The default implementation returns the empty string.- Overrides:
getErrorMessage
in classCalculatorPlugin
- 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 classCalculatorPlugin
- 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 classCalculatorPlugin
- Parameters:
mol
- is the molecule to be standardized
-
-