|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectchemaxon.marvin.plugin.CalculatorPlugin
Common base class for calculator plugins. Provides a uniform framework for plugin calculations and calculation result queries.
Example usage:
// 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);
}
}
// fill parameters
Properties params = new Properties();
params.put("type", "logP,increments");
// create plugin
logPPlugin plugin = new logPPlugin();
plugin.validate(<logP license>);
// set plugin parameters
plugin.setParameters(params);
// set MolImporter
MolInputStream mis = new MolInputStream(new FileInputStream("target.sdf"));
MolImporter mi = new MolImporter(mis);
// for each input molecule run the calculation and display the results
System.out.println("molecule\tlogP\tincrements");
Molecule target = null;
while ((target = mi.read()) != null) {
// set the input molecule
plugin.setMolecule(target);
// run the calculation
plugin.run();
// get the overal logP value
double logp = ((Double)plugin.getResult("logP", 0)).doubleValue();
// get the incremental values
int count = target.getAtomCount();
String[] increments = new String[count];
for (int i=0; i < count; ++i) {
Object result = plugin.getResult("increments", i);
increments[i] = plugin.getResultAsString("increments", i, result);
}
// display the results
StringBuffer s = new StringBuffer();
s.append(target.toFormat("smiles")+"\t"+logp+"\t");
for (int i=0; i < count; ++i) {
if (i > 0) {
s.append(";");
}
s.append(increments[i]);
}
System.out.println(new String(s));
}
| Field Summary | |
static int |
ATOM
Calculation domain type: calculation refers to atoms. |
static int |
CHART
Calculation domain type: calculation can be represented in a chart. |
static int |
MOLECULE
Calculation domain type: calculation refers to the molecule. |
protected static java.lang.Double |
NAN
Double constant for Double.NaN. |
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. |
static CalculatorPlugin |
create(java.lang.String name)
Creates a CalculatorPlugin object. |
protected Molecule |
createStandardizedMolecule(Molecule mol)
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. |
protected 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. |
int |
getDoublePrecision()
Returns the precision. |
java.lang.String |
getErrorMessage()
Returns the calculation error information message if run()
returned false (calculation error). |
protected java.lang.String |
getLicenseKey()
Returns the built-in license key for the given plugin class. |
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. |
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). |
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. |
abstract boolean |
run()
Runs the tool. |
protected 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. |
void |
setMolecule(Molecule mol)
Sets the input molecule after standardization. |
void |
setMolecule(Molecule mol,
boolean st)
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 void |
standardizeNitro(Molecule mol)
Standardizes nitro groups: [O-]-[N+]=O >> O=N=O. |
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 |
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 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
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()public final int getDoublePrecision()
protected final void setDoublePrecision(java.lang.String pr)
pr - is the precision string ("0"..."8" or "inf")
protected 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 precsion=4, pad=false
12.56 -> 12.5600 if precsion=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 void setMolecule(Molecule mol) throws PluginException
mol - is the input molecule
PluginException - on errorpublic void setMolecule(Molecule mol, boolean st) throws PluginException
mol - is the input moleculest - is true if standardization is required
PluginException - on errorprotected final Molecule createStandardizedMolecule(Molecule mol)
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 molecule
public Molecule getReferenceMolecule(java.lang.Object type, int index)
type - is the result typeindex - is the result index
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.
public abstract void setParameters(java.util.Properties params)
throws PluginException
params - is the parameter table
PluginException - on errorpublic 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 error
public 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()
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 given
public 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 given
public 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 given
public 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 given
public 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 given
public 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 given
public 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 given
public 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.
protected 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.
To be overriden by subclasses that require other standardization (or none at all).
TODO: replace by call to chemaxon.reaction.Standardizer
mol - is the molecule to be standardizedprotected final void standardizeNitro(Molecule mol)
mol - is the molecule to be standardized
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||