Class ChemTermsEvaluator

java.lang.Object
chemaxon.chemterms.ChemTermsEvaluator

@PublicApi public class ChemTermsEvaluator extends Object
Evaluates Chemical Terms expressions. Provides command line interface or creates ChemTermsExpression objects according to configuration. See the documentation for details:

API usage examples:

  1. 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);
         }
     }
     
     
  2. 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 Details

    • EVALUATOR_DEFAULTS_FILE

      public static final String EVALUATOR_DEFAULTS_FILE
      Default Function/Plugin settings filename.
      See Also:
    • CONFIG_DIR

      public static final String CONFIG_DIR
      Default directory for storing configuration files.
      See Also:
    • EVALUATOR_SCRIPT_FILE

      public static final String EVALUATOR_SCRIPT_FILE
      Initial script filename.
      See Also:
    • DEFAULT_TAG_NAME

      public static final String DEFAULT_TAG_NAME
      Default SDFile tag to store the evaluation result.
      See Also:
  • Constructor Details

    • ChemTermsEvaluator

      public ChemTermsEvaluator() throws ParseException
      Default constructor.
      Throws:
      ParseException
    • ChemTermsEvaluator

      public ChemTermsEvaluator(File file) throws ParseException
      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

      public ChemTermsEvaluator(String configString) throws ParseException
      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