Create Relational Data Tree
import chemaxon.formats.MolExporter
import chemaxon.formats.MolImporter
import chemaxon.struc.Molecule
import com.im.commons.progress.DFEnvironmentRO
// dbutler@chemaxon.com
// Sep 2012
//https://docs.chemaxon.com/display/CALCPLUGS/cxcalc+command+line+tool
def cxcalc = "C:/Program Files/Chemaxon/JChem/bin/cxcalc.bat"
def inputSDF = "C:/SDF/test.sdf"
//def options = " -m 100 " // generate N confs
def options = " leconformer " // generate single low energy
def command = cxcalc + options + inputSDF
// INSERT a call to export an SDF from IJC result set to suitable directory
// Must export CD_ID as handle
def ety = dataTree.rootVertex.entity
def edp = ety.schema.dataProvider.getEntityDataProvider(ety)
def structureFld = ety.fields.items.find { it.name == 'Structure' }
def cdidFld = ety.fields.items.find { it.name == 'CdId' }
def exporter = new MolExporter(inputSDF, 'sdf')
try {
def rs = ety.schema.dataProvider.getDefaultResultSet(dataTree, false,DFEnvironmentRO.DEV_NULL)
def rootVS = rs.getVertexState(dataTree.rootVertex)
// Get the selected IDs
List ids = rootVS.selectedRowsIds
ids.each { id ->
// Define the data fetching method from the root verstexstate
def data = rootVS.getData([id], DFEnvironmentRO.DEV_NULL)
def row = data[id]
// Get the molecule from the table, and the affiliated properties
def mol = row[structureFld.id]
String cdid = row[cdidFld.id]
// Clone the molecule to prevent modifying the original
def expMol = mol.native.cloneMolecule()
expMol.clearProperties()
expMol.setProperty("cdid", cdid)
// Set the properties for the molecule
// Write the molecule to the file
exporter.write(expMol)
}
} finally {
//Important! Be sure to flush and close the exporter so that the file is closed.
exporter.flush()
exporter.close()
}
println command
def initialSize = 4096
def outStream = new ByteArrayOutputStream(initialSize)
def errStream = new ByteArrayOutputStream(initialSize)
def proc = command.execute()
proc.waitForProcessOutput(outStream,errStream)
println "return code: ${ proc.exitValue()}"
println 'out:\n' + outStream
println 'err:\n' + errStream
// You might want to do somthing with this like extract 3D ctab and use in virtual screening !?