|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object chemaxon.marvin.plugin.CalculatorPlugin
Common base class for calculator plugins. Provides a uniform framework for plugin calculations and calculation result queries.
API usage examples:
// fill parameters Properties params = new Properties(); params.put("precision", "3"); params.put("type", "total,sigma"); // create plugin ChargePlugin plugin = new ChargePlugin(); plugin.validate(<charge license>); // set plugin parameters plugin.setParameters(params); // set target molecule MolInputStream mis = new MolInputStream(new ByteArrayInputStream("Clc1cc(Cl)c(Cl)cc1".getBytes())); MolImporter mi = new MolImporter(mis); plugin.setMolecule(mi.read()); // run the calculation plugin.run(); // get the calculation results Object[] types = plugin.getResultTypes(); // now this is {"total", "sigma"} for (int i=0; i < types.length; ++i) { Object type = types[i]; System.out.println(); System.out.println(type + " charge: "); System.out.println("atom\tcharge"); int count = plugin.getResultCount(type); // now this is the atom count for (int j=0; j < count; ++j) { Object result = plugin.getResult(type, j); // now this is the charge value on atom j String rtext = plugin.getResultAsString(type, j, result); // string representation System.out.println((j+1)+"\t"+rtext); } }
Field Summary | |
static int |
ATOM
Calculation domain type: calculation refers to atoms. |
static int |
BLUE
Constant storing the blue rgb value (the basic pKa result color). |
protected static int |
CALCRGB_OFF
Calculator rgb offset. |
static int |
CHART
Calculation domain type: calculation can be represented in a chart. |
protected static java.lang.String |
HYDROGEN_VALENCE_ERROR_MSG
|
static int |
MOLECULE
Calculation domain type: calculation refers to the molecule. |
protected static java.lang.Double |
NAN
Double constant for Double.NaN . |
static int |
RED
Constant storing the red rgb value (the acidic pKa result color). |
static int |
SUBRESULT
Calculation domain type: subresult to be displayed in a separate text area. |
Constructor Summary | |
CalculatorPlugin()
|
Method Summary | |
protected boolean |
check()
Protects plugin license. |
protected void |
checkLicense()
Increases the call counter if no valid license exists for this plugin class. |
boolean |
checkLicenseKey()
Checks the license key. |
void |
checkMolecule(Molecule mol)
Checks the input molecule. |
protected void |
checkType(java.lang.String type,
java.lang.String[] typerange)
Checks result types. |
static CalculatorPlugin |
create(java.lang.String name)
Creates a CalculatorPlugin object. |
protected Molecule |
createImageMolecule()
Transforms molecule 'origmol' for molecule image purpose. |
protected Molecule |
createStandardizedMolecule(Molecule mol,
boolean om)
Creates standardized molecule, the original input molecule is cloned. |
protected static void |
dehydrogenize(Molecule mol)
Makes all explicit H-s implicit. |
java.lang.String |
format(double x)
Converts a double into String, applying the maximum number of fractional digits specified. |
java.lang.String |
format(double[][] t,
int intlen)
Converts a double[][] 2xN table
to a 2-column tab-separated string representation of the table. |
java.lang.String |
format(double x,
int intlen)
Converts a double into String, applying the maximum number of fractional digits specified. |
java.lang.StringBuffer |
format(double x,
java.lang.StringBuffer s)
Converts a double into String, applying the maximum number of fractional digits specified. |
int |
getAtomCount()
Returns the number of atoms in the input molecule. |
protected int |
getAtomIndex(int index)
Returns the atom index in the standardized molecule, or the atom index itself if the input molecule has not been standardized. |
protected java.awt.Color |
getChartColor(java.lang.Object type)
Returns the chart colors to be displayed in msketch/mview GUI. |
int |
getDoublePrecision()
Returns the precision. |
java.lang.String |
getErrorMessage()
Returns the calculation error information message if run()
returned false (calculation error). |
protected java.lang.Object[] |
getGUIResultTypes()
Returns the result types to be displayed in msketch/mview GUI. |
protected java.lang.String |
getLicenseKey()
Returns the built-in license key for the given plugin class. |
protected Molecule |
getMainMolecule(Molecule mol)
Returns the molecule form with largest distribution. |
protected java.lang.String |
getMolText()
Returns the plugin molecule text to be displayed in the viewer. |
java.lang.String |
getOutputClassName()
Returns the output provider class name for the command line interface. |
Molecule |
getReferenceMolecule(java.lang.Object type,
int index)
Returns the molecule to be used as reference image for the given result type and index. |
java.lang.Object |
getResult(int index)
Returns the result item for the specified type and index. |
abstract java.lang.Object |
getResult(java.lang.Object type,
int index)
Returns the result item for the specified type and index. |
java.lang.Object |
getResult(java.lang.Object type,
java.lang.String arg)
Returns the result item for the specified argument string. |
java.lang.Object |
getResult(java.lang.String arg)
Returns the result item for the specified argument string. |
int |
getResultAsRGB(int index,
java.lang.Object result)
Returns the specified result color as int format (alpha<<24 + red<<16 + green<<8 + blue). |
int |
getResultAsRGB(java.lang.Object type,
int index,
java.lang.Object result)
Returns the specified result color as int format (alpha<<24 + red<<16 + green<<8 + blue). |
java.lang.String |
getResultAsString(int index,
java.lang.Object result)
Returns the specified result in String format for the first result type. |
abstract java.lang.String |
getResultAsString(java.lang.Object type,
int index,
java.lang.Object result)
Returns the specified result in String format. |
int |
getResultCount()
Returns the number of result items for the first result type. |
abstract int |
getResultCount(java.lang.Object type)
Returns the number of result items for the given result key. |
int |
getResultDomain()
Returns the calculation domain ATOM or MOLECULE . |
abstract int |
getResultDomain(java.lang.Object type)
Returns the calculation domain ATOM or MOLECULE . |
long |
getResultsAsRGB(int index,
java.lang.Object result)
Returns the specified result color(s) as int format (alpha<<24 + red<<16 + green<<8 + blue). |
long |
getResultsAsRGB(java.lang.Object type,
int index,
java.lang.Object result)
Returns the specified result color(s) as int format (alpha<<24 + red<<16 + green<<8 + blue). |
java.lang.String |
getResultsAsString(int index,
java.lang.Object result)
Returns the specified result with possible subresults. |
java.lang.String |
getResultsAsString(java.lang.Object type,
int index,
java.lang.Object result)
Returns the specified result with possible subresults. |
abstract java.lang.Object[] |
getResultTypes()
Returns the result types. |
protected java.lang.String |
getSuffix()
Returns the plugin text suffix. |
java.lang.String |
getTypeString(java.lang.Object type)
Returns a string representation of the given type. |
java.lang.String |
getXAxisLabel(java.lang.Object type)
Returns the X axis label to be displayed. |
java.lang.String[] |
getXLabels()
Returns the X labels, X values formatted as strings. |
java.lang.String |
getYAxisLabel(java.lang.Object type)
Returns the Y axis label to be displayed. |
boolean |
handlesMultiFragmentMolecules()
Returns true if the plugin handles multifragment molecules,
false otherwise. |
boolean |
isLicensed()
Returns true if the plugin is licensed (has a license key). |
protected boolean |
isMajorityMsCalculation()
Returns true if majority microspecies calculation takes place,
ie, if pH is different formDouble.NaN . |
protected boolean |
isMajorMs()
Returns true if major microspecies required,
false otherwise. |
protected boolean |
isMsCalc()
Returns true if microspecies calculation. |
boolean |
isNegligibleResult(java.lang.Object type,
int index,
java.lang.Object result)
Returns whether the result can be ignored. |
protected static boolean |
isRgrouped(Molecule mol)
Returns true if molecule with R-groups. |
protected static java.lang.String |
removeWhitespace(java.lang.String str)
Removes whitespace characters from the given string. |
abstract boolean |
run()
Runs the tool. |
void |
saveLicense()
Saves licenses in license file. |
void |
setDoublePrecision(int precision)
Sets the double -> string conversion precision (maximal number of fraction digits) with zero-padding (12.56 -> 12.5600 if precision=4). |
void |
setDoublePrecision(int precision,
boolean pad)
Sets the double -> string conversion precision (maximal number of fraction digits). |
protected void |
setDoublePrecision(java.lang.String pr)
Sets the precision in the decimal format. |
protected abstract void |
setInputMolecule(Molecule mol)
Sets the input molecule. |
boolean |
setLicense(java.lang.String license)
Sets the license key in the license manager if the given license key matches the plugin's license key. |
Molecule |
setMolecule(Molecule mol)
Sets the input molecule after standardization. |
Molecule |
setMolecule(Molecule mol,
boolean st)
Sets the input molecule after an optional standardization. |
Molecule |
setMolecule(Molecule mol,
boolean st,
boolean om)
Sets the input molecule after an optional standardization. |
abstract void |
setParameters(java.util.Properties params)
Sets the input parameters for the plugin. |
protected void |
standardize(Molecule mol)
Standardizes the molecule by performing the transformations necessary to run the plugin (aromatize, dehydrogenize, bring nitro groups to common form, ...). |
protected static void |
standardizeGroups(Molecule mol)
Default standardization: nitro groups: [O-]-[N+] >> O=N
sulphynil groups: [#6][S+:1]([#6])[#8-:2]>>[#6][S:1]([#6])=[O:2]
|
void |
validate(java.lang.String license)
Validates the plugin. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.lang.String HYDROGEN_VALENCE_ERROR_MSG
public static final int RED
public static final int BLUE
protected static final int CALCRGB_OFF
public static final int ATOM
public static final int MOLECULE
public static final int CHART
public static final int SUBRESULT
protected static final java.lang.Double NAN
Double.NaN
.
Constructor Detail |
public CalculatorPlugin()
Method Detail |
public static CalculatorPlugin create(java.lang.String name) throws PluginException
name
- is the plugin class name in package chemaxon.marvin.calculations
or the full plugin class name with package name
PluginException
- if the class cannot be loaded or not found
or cannot be instantiatedprotected static boolean isRgrouped(Molecule mol)
true
if molecule with R-groups.
mol
- is the molecule
protected static void dehydrogenize(Molecule mol)
mol
- is the moleculeprotected static java.lang.String removeWhitespace(java.lang.String str)
str
- is the string
protected final boolean check()
public final void validate(java.lang.String license)
license
- is the license keypublic final boolean isLicensed()
public final boolean checkLicenseKey()
public final boolean setLicense(java.lang.String license)
license
- is the license key to be checked
public final void saveLicense()
protected final void checkLicense() throws PluginException
run()
method of the plugin.
PluginException
- if license check fails and
the max number of calls without license has been reachedprotected java.lang.String getLicenseKey()
checkLicense()
protected void checkType(java.lang.String type, java.lang.String[] typerange) throws PluginException
type
- is the type given by the usertyperange
- is the array containing the valid types
PluginException
- if the user-type is not contained in the type-rangepublic final int getDoublePrecision()
protected final void setDoublePrecision(java.lang.String pr)
pr
- is the precision string ("0"..."8" or "inf")public final void setDoublePrecision(int precision)
precision
- is the precisionpublic final void setDoublePrecision(int precision, boolean pad)
precision
- is the precisionpad
- is true if fractional ending zeros should be printed
e.g. 12.56 -> 12.56 if precision=4, pad=false
12.56 -> 12.5600 if precision=4, pad=truepublic final java.lang.String format(double x)
x
- is the double value to be converted
setDoublePrecision(int precision, boolean pad)
public final java.lang.String format(double x, int intlen)
x
- is the double value to be convertedintlen
- is the required integral part length
setDoublePrecision(int precision, boolean pad)
public final java.lang.StringBuffer format(double x, java.lang.StringBuffer s)
x
- is the double value to be converteds
- is the StringBuffer to be used
setDoublePrecision(int precision, boolean pad)
public final java.lang.String format(double[][] t, int intlen)
double[][]
2xN
table
to a 2-column tab-separated string representation of the table.
t
- is the tableintlen
- is the required integral part length
public final Molecule setMolecule(Molecule mol) throws PluginException
mol
- is the input molecule
PluginException
- on errorpublic Molecule setMolecule(Molecule mol, boolean st) throws PluginException
mol
- is the input moleculest
- is true if standardization is required
PluginException
- on errorpublic Molecule setMolecule(Molecule mol, boolean st, boolean om) throws PluginException
mol
- is the input moleculest
- is true if standardization is requiredom
- is true if original input molecule is to be used for atom indexing
false if modified molecule is to be used for atom indexing
PluginException
- on errorprotected final Molecule createStandardizedMolecule(Molecule mol, boolean om)
handlesMultiFragmentMolecules()
returns false
then takes the largest fragment (measured by atom count).
The cloned molecule is standardized by standardize(Molecule)
.
Sets the atomIndexMap
:
atomIndexMap[i]
is the index in the standardized molecule
of the i-th atom in the original molecule or -1 if this atom has been removed.
mol
- is the input moleculeom
- is true if original input molecule is to be used for atom indexing
false if modified molecule is to be used for atom indexing
protected boolean isMajorityMsCalculation()
true
if majority microspecies calculation takes place,
ie, if pH is different formDouble.NaN
.
The default implementation returns false
.
true
if majority microspecies calculation takes placeprotected java.lang.String getSuffix()
protected java.lang.String getMolText()
null
.
protected Molecule getMainMolecule(Molecule mol)
Double.NaN
,
otherwise returns the input molecule itself.
The default implementation returns the input molecule itself.
mol
- is the input molecule
public Molecule getReferenceMolecule(java.lang.Object type, int index)
type
- is the result typeindex
- is the result index
protected Molecule createImageMolecule()
public boolean handlesMultiFragmentMolecules()
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.
The default implementation returns false
.
protected boolean isMsCalc()
true
if microspecies calculation.
The default implementation returns false
.
false
public abstract void setParameters(java.util.Properties params) throws PluginException
params
- is the parameter table
PluginException
- on errorprotected boolean isMajorMs()
true
if major microspecies required,
false
otherwise.
The default implementation returns false
.
true
if major microspecies requiredpublic void checkMolecule(Molecule mol) throws PluginException
mol
- is the input molecule
PluginException
- with error message for the user if the molecule is refusedprotected abstract void setInputMolecule(Molecule mol) throws PluginException
mol
- is the input molecule
PluginException
- on errorpublic abstract boolean run() throws PluginException
PluginException
- on errorgetErrorMessage()
public java.lang.String getErrorMessage()
run()
returned false (calculation error). The default implementation
returns the empty string.
public abstract java.lang.Object[] getResultTypes()
protected java.lang.Object[] getGUIResultTypes()
getResultTypes()
.
protected java.awt.Color getChartColor(java.lang.Object type)
null
which means
that the default colors should be used in case of chart display.
type
- is the result type
public java.lang.String getTypeString(java.lang.Object type)
type.toString()
.
type
- is the type object
public abstract int getResultDomain(java.lang.Object type)
ATOM
or MOLECULE
.
Can be combined with CHART
to denote chart-type data.
type
- is the result type
getResultTypes()
public abstract int getResultCount(java.lang.Object type)
type
- is the result type
getResultTypes()
public abstract java.lang.Object getResult(java.lang.Object type, int index) throws PluginException
type
- is the result typeindex
- is the result index
PluginException
- if the result cannot be returnedgetResultTypes()
public abstract java.lang.String getResultAsString(java.lang.Object type, int index, java.lang.Object result) throws PluginException
type
- is the result typeindex
- is the result indexresult
- is the result item
PluginException
- if an invalid result item is givenpublic java.lang.String getResultsAsString(java.lang.Object type, int index, java.lang.Object result) throws PluginException
type
- is the result typeindex
- is the result indexresult
- is the result item
PluginException
- if an invalid result item is givenpublic int getResultAsRGB(java.lang.Object type, int index, java.lang.Object result) throws PluginException
type
- is the result typeindex
- is the result indexresult
- is the result item
PluginException
- if an invalid result item is givenpublic long getResultsAsRGB(java.lang.Object type, int index, java.lang.Object result) throws PluginException
type
- is the result typeindex
- is the result indexresult
- is the result item
PluginException
- if an invalid result item is givenpublic boolean isNegligibleResult(java.lang.Object type, int index, java.lang.Object result) throws PluginException
false
.
type
- is the result typeindex
- is the result indexresult
- is the result object
PluginException
public java.lang.Object getResult(java.lang.Object type, java.lang.String arg) throws PluginException
getResult(Object, int)
with the argument string converted to an integer (result index).
type
- is the result typearg
- is the argument string
PluginException
- if the result cannot be returnedgetResultTypes()
public java.lang.String getXAxisLabel(java.lang.Object type)
type
- is the result typepublic java.lang.String getYAxisLabel(java.lang.Object type)
getTypeString(Object)
.
type
- is the result typepublic java.lang.String[] getXLabels()
public int getResultDomain()
ATOM
or MOLECULE
.
for the first result type.
public int getResultCount()
getResultTypes()
public java.lang.Object getResult(int index) throws PluginException
index
- is the result index
PluginException
- if the result cannot be returnedgetResultTypes()
public java.lang.Object getResult(java.lang.String arg) throws PluginException
getResult(Object, int)
with the argument string converted to an integer (result index)
and with the first result type.
arg
- is the argument string
PluginException
- if the result cannot be returnedgetResultTypes()
public java.lang.String getResultAsString(int index, java.lang.Object result) throws PluginException
index
- is the result indexresult
- is the result item
PluginException
- if an invalid result item is givenpublic java.lang.String getResultsAsString(int index, java.lang.Object result) throws PluginException
index
- is the result indexresult
- is the result item
PluginException
- if an invalid result item is givenpublic int getResultAsRGB(int index, java.lang.Object result) throws PluginException
index
- is the result indexresult
- is the result item
PluginException
- if an invalid result item is givenpublic long getResultsAsRGB(int index, java.lang.Object result) throws PluginException
index
- is the result indexresult
- is the result item
PluginException
- if an invalid result item is givenpublic java.lang.String getOutputClassName()
CalculatorOutput
, override
this method if your plugin requires a subclass of CalculatorOutput.
public final int getAtomCount()
protected final int getAtomIndex(int index)
index
- is the atom index in the input molecule
protected void standardize(Molecule mol)
[O-]-[N+]=O >> O=N=O
[#6][S+:1]([#6])[#8-:2]>>[#6][S:1]([#6])=[O:2]
mol
- is the molecule to be standardizedprotected static void standardizeGroups(Molecule mol)
[O-]-[N+] >> O=N
[#6][S+:1]([#6])[#8-:2]>>[#6][S:1]([#6])=[O:2]
mol
- is the molecule to be standardized
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |