Simple Substructure Search

This very basic script will perform a substructure search on the structures table it is installed on, searching for the SMILES structure 'C1=CC=CC=C1'. It returns the count of rows found that match, and the total rows. This is a very nice example for Java coders who are learning Groovy, as a number of the Objects are presented in Java format.


import chemaxon.sss.search.JChemSearchOptions
import com.im.df.query.JChemSearchConstants
import chemaxon.sss.SearchConstants
import com.im.df.api.chem.MarvinStructure
import com.im.commons.progress.*
import com.im.df.api.ddl.*
import com.im.df.api.dml.*
import com.im.df.api.support.SortDirective

def ety = dataTree.rootVertex.entity
def edp = ety.schema.dataProvider.getEntityDataProvider(ety)
def rows = edp.getRowCount(env)
def dt = dataTree;
println "Entity has $rows rows"

def DFLock l = edp.getLockable().obtainLock("Structure Query");
try {
    env = EnvUtils.createRWFromRO(env, l);
    DFEntity entity = dt.getRootVertex().getEntity();

    DFField structureField = null;
    for (DFField f: entity.getFields().getItems()) {
        if (DFFields.isStructure(f)) {
            structureField = f;
            break;
        }
    }
    println 'structure field' + structureField

    String structureString = "C1=CC=CC=C1";
    MarvinStructure mrv = new MarvinStructure(structureString, true);
    String structureSearchOptions = "t:s";
    JChemSearchOptions jchemOpts = new JChemSearchOptions(SearchConstants.SUBSTRUCTURE);
    jchemOpts.setOptions(structureSearchOptions);

    Map<String, Object> expOptions = new HashMap<String, Object>();
    expOptions.put(JChemSearchConstants.JCHEM_SEARCH_OPTIONS, jchemOpts);

    DFTermExpression structureExp = DFTermsFactory.createFieldOperatorValueExpr(Operators.STRUCTURE_SUBSTRUCTURE,
            structureField, expOptions, mrv, "");

    int error = structureExp.validate(dt).getErrorsCount();
    println 'errors1 = ' + error

    int size = edp.queryForIds(structureExp, SortDirective.EMPTY, env).size();
    println 'size = ' + size

    println 'total row count = ' + edp.getRowCount(env)

} finally {
    if (l != null) {
        l.release();
    }
}

Versions: This script has been tested on IJC version 6.0



Copyright © 1999-2012 ChemAxon Ltd.    All rights reserved.