Package chemaxon.chemterms
Class ChemTermsEvaluator
java.lang.Object
chemaxon.chemterms.ChemTermsEvaluator
Evaluates Chemical Terms expressions.
Provides command line interface or creates
ChemTermsExpression objects according to configuration.
See the documentation for details:
API usage examples:
- Evaluate a Chemical Terms expression on molecules and write the results to output:
// Create the evaluator ChemTermsEvaluator evaluator = new ChemTermsEvaluator(); // Compile the Chemical Terms expression ChemTermsExpression<MolContext> expression = evaluator.compile("logP()", MolContext.class); // Create the context MolContext context = new MolContext(); try (MolImporter importer = new MolImporter("mols.smiles")) { Molecule mol = null; while ((mol = importer.read()) != null) { // Set the input molecule context.setMolecule(mol); // Get the result by evaluating the expression // (Note: "logP()" expression returns a double, // so evaluateDouble() is used.) double result = expression.evaluateDouble(context); // Write output System.out.println(result); } } - Using a Chemical Terms expression for filtering molecules:
// Create the evaluator ChemTermsEvaluator evaluator = new ChemTermsEvaluator(); // Compile the Chemical Terms expression ChemTermsExpression<MolContext> expression = evaluator.compile( "mass()<=500 && logP()<=5 && donorCount()<=5 && acceptorCount()<=10", MolContext.class); // Create the context MolContext context = new MolContext(); try (MolImporter importer = new MolImporter("mols.smiles"); MolExporter exporter = new MolExporter(System.out, "smiles")) { Molecule mol = null; while ((mol = importer.read()) != null) { // Set the input molecule context.setMolecule(mol); // Filter molecules that fulfill the previously set // Chemical Terms expression (only molecules that // fulfill the expression are written to output) if(evaluator.evaluate_boolean(context)) { exporter.write(mol); } } }
- Since:
- JChem 2.2, Marvin 5.1
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ChemTermsEvaluator(File file) Constructor.ChemTermsEvaluator(String configString) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionCompiles the expression, createsChemTermsExpressionobject.<C extends ChemTermsContext>
ChemTermsExpression<C> Compiles the expression, createsChemTermsExpressionobject.<C extends ChemTermsContext>
ChemTermsExpression<C> compile(String expression, C contextClassInstance, ConstantTable constantTable) Compiles the expression, createsChemTermsExpressionobject.<C extends ChemTermsContext>
ChemTermsExpression<C> Compiles the expression, createsChemTermsExpressionobject.<C extends ChemTermsContext>
ChemTermsExpression<C> compile(String expression, Class<? extends C> contextClass, ConstantTable constantTable) Compiles the expression, createsChemTermsExpressionobject.Returns the table of predefined constants (molecules, molecule sets and other constants defined in the built-in and the user-defined jep.script).Returns the custom services configuration path.voidRuns a script, variables will be added to the base variable table and can be referenced by chemical expressions.voidSets the fingerprint generator object (needed for query strings).voidFor internal usage only.voidsetServicesConfigurationPath(String servicesConfigurationPath) Sets the custom services configuration path.voidsetVerbose(boolean verbose) Sets verbose mode.
-
Field Details
-
EVALUATOR_DEFAULTS_FILE
Default Function/Plugin settings filename.- See Also:
-
CONFIG_DIR
Default directory for storing configuration files.- See Also:
-
EVALUATOR_SCRIPT_FILE
Initial script filename.- See Also:
-
DEFAULT_TAG_NAME
Default SDFile tag to store the evaluation result.- See Also:
-
-
Constructor Details
-
ChemTermsEvaluator
Default constructor.- Throws:
ParseException
-
ChemTermsEvaluator
Constructor. Loads default configuration and configuration from specified file, loads default named molecule sets and runs default initial scripts.- Parameters:
file- is the XML configuration file- Throws:
ParseException- on error
-
ChemTermsEvaluator
Constructor. Loads default configuration and configuration from specified XML configuration string, loads default named molecule sets and runs default initial scripts.- Parameters:
configString- is the XML configuration string- Throws:
ParseException- on error- Since:
- JChem 5.0
-
-
Method Details
-
setLicenseEnvironment
For internal usage only.- Parameters:
env- the license environment
-
runScript
Runs a script, variables will be added to the base variable table and can be referenced by chemical expressions.- Parameters:
script- is the script (Chemical Terms expression)- Throws:
ParseException- on error- Since:
- JChem 3.2
-
getServicesConfigurationPath
Returns the custom services configuration path.- Returns:
- the custom services configuration path or
nullif using marvin's default lookup - Since:
- 5.10
-
setServicesConfigurationPath
Sets the custom services configuration path.- Parameters:
servicesConfigurationPath- the new file path or URL. Setnullto use marvin's default lookup- Since:
- 5.10
-
constantTable
Returns the table of predefined constants (molecules, molecule sets and other constants defined in the built-in and the user-defined jep.script).- Returns:
- the constant table
-
setFingerprintGenerator
Sets the fingerprint generator object (needed for query strings).- Parameters:
fg- is the fingerprint generator object
-
setVerbose
public void setVerbose(boolean verbose) Sets verbose mode.- Parameters:
verbose- is true if verbose mode
-
compile
Compiles the expression, createsChemTermsExpressionobject. CallChemTermsExpression.evaluate(ChemTermsContext)to evaluate the expression.- Parameters:
expression- is the expression string- Returns:
- the created
ChemTermsExpressionobject - Throws:
ParseException- on compile error
-
compile
public <C extends ChemTermsContext> ChemTermsExpression<C> compile(String expression, C contextClassInstance) throws ParseException Compiles the expression, createsChemTermsExpressionobject. CallChemTermsExpression.evaluate(ChemTermsContext)to evaluate the expression.- Parameters:
expression- is the expression stringcontextClassInstance- an instance of the context class that the resultingChemTermsExpressionobject will accept. Only the type of the object matters, it is otherwise unused by this method.- Returns:
- the created
ChemTermsExpressionobject - Throws:
ParseException- on compile error
-
compile
public <C extends ChemTermsContext> ChemTermsExpression<C> compile(String expression, Class<? extends C> contextClass) throws ParseException Compiles the expression, createsChemTermsExpressionobject. CallChemTermsExpression.evaluate(ChemTermsContext)to evaluate the expression.- Parameters:
expression- is the expression stringcontextClass- is the evaluation context class object- Returns:
- the created
ChemTermsExpressionobject - Throws:
ParseException- on compile error
-
compile
public <C extends ChemTermsContext> ChemTermsExpression<C> compile(String expression, C contextClassInstance, ConstantTable constantTable) throws ParseException Compiles the expression, createsChemTermsExpressionobject. CallChemTermsExpression.evaluate(ChemTermsContext)to evaluate the expression.- Parameters:
expression- is the expression stringcontextClassInstance- an instance of the context class that the resultingChemTermsExpressionobject will accept. Only the type of the object matters, it is otherwise unused by this method.constantTable- is the vaiable table, null if the default varibale table should be used- Returns:
- the created
ChemTermsExpressionobject - Throws:
ParseException- on compile error
-
compile
public <C extends ChemTermsContext> ChemTermsExpression<C> compile(String expression, Class<? extends C> contextClass, ConstantTable constantTable) throws ParseException Compiles the expression, createsChemTermsExpressionobject. CallChemTermsExpression.evaluate(ChemTermsContext)to evaluate the expression.- Parameters:
expression- is the expression stringcontextClass- is the evaluation context class objectconstantTable- is the vaiable table, null if the default varibale table should be used- Returns:
- the created
ChemTermsExpressionobject - Throws:
ParseException- on compile error
-