Conversion from ArrayList to Molecule & Export to sdf

User 2235ec4634

26-04-2016 10:45:10

Hello
I would like to convert an array from:



def Rows = this.sql.rows(SQL)


Where SQL is string containig MySQL query.



I would like to export that array  "Rows" (it contains a molecule field ) into sdf file.
What should I do?
Convert into Molecule class object? How?
Use MolExporter object?

best regards
Rafal

ChemAxon 26d92e5dcd

26-04-2016 12:53:57

Dear Rafal,


please consult the example here https://docs.chemaxon.com/display/docs/Simple+SDF+Exporter


In general, it is better to rely on our DIF API instead of pure SQL as when accessing with DIF, the appropriate fields will be taken care of as needed (structure will be Molecule instance, etc...). 


In theory, what you could do, is to parse the content of this.sql.rows(SQL) array into the given objects and then use MolExporter for the export, but again, DIF would be better choice. See https://docs.chemaxon.com/display/docs/IJC+API for more info


Wishing all the best


David

User 2235ec4634

29-04-2016 06:50:06

Ok, I will try.
Thanks.

User 2235ec4634

29-04-2016 08:14:06










dpech wrote:

Dear Rafal,


please consult the example here https://docs.chemaxon.com/display/docs/Simple+SDF+Exporter


In general, it is better to rely on our DIF API instead of pure SQL as when accessing with DIF, the appropriate fields will be taken care of as needed (structure will be Molecule instance, etc...). 


In theory, what you could do, is to parse the content of this.sql.rows(SQL) array into the given objects and then use MolExporter for the export, but again, DIF would be better choice. See https://docs.chemaxon.com/display/docs/IJC+API for more info


Wishing all the best


David



One more question:
How can I convert a field with a structure into Molecule object?
Now I have something like that in sdf:

>  <cd_structure>
[54, 45, 65, 109, 105, 110, 111, 45, 52, 45, 40, 52, 45, 100, 105, 109,....]

Please be patient, I am newbie in Groovy

ChemAxon 26d92e5dcd

29-04-2016 10:01:18

Dear Rafal,


that is fine :) Groovy can be tough sometimes. If you have a molecule already in the database, please see this button script for starters on how to read that particular molecule. You would be interested especially in those parts:


import com.im.df.api.dml.*

import com.im.df.api.*

import com.im.df.api.support.SelectionDescription

import com.im.ijc.core.api.util.IJCCoreUtils

import chemaxon.struc.Molecule

import chemaxon.formats.MolExporter

import chemaxon.formats.MolImporter

import com.im.df.api.chem.MarvinStructure


def ety = dataTree.rootVertex.entity // assumes you have reference to the data tree

    def edp = ety.schema.dataProvider.getEntityDataProvider(ety)

    def molFld = ety.fields.items.find { it.name == 'Structure' // find the structure field

    def rs = ety.schema.dataProvider.getDefaultResultSet(dataTree, false, DFEnvironmentRO.DEV_NULL) // find the ResultSet

    def rootVS = rs.getVertexState(dataTree.rootVertex) // obtain the VertexState

  

    List ids = rootVS.getSelectedRowsIds() // get the selected IDs



Map rows = rootVS.getData(ids, DFEnvironmentRO.DEV_NULL) // get the data

        Map row = rows[ids[0]] // get the first and only row

        MarvinStructure mol = row[molFld.id] // Get the Structure. Its a com.im.df.api.chem.MarvinStructure instance

        Molecule cxnMol = mol.getNative() // obtain the chemaxon.struc.Molecule instance

         

        // convert chemaxon.struc.Molecule instance into canonical SMILES

        molSmiles = cxnMol.toFormat("smiles:u")

As you can see, with the code above, you will access the molecule in the Structure field of the currently selected row, but that can be changed.


I hope this helps


Wishing all the best 


David


User 2235ec4634

29-04-2016 10:43:27

Great, thank you. It works!