forlilab / Ringtail

Package for storage and analysis of virtual screenings run with AutoDock-GPU and AutoDock Vina
GNU Lesser General Public License v2.1
41 stars 7 forks source link

Writting sdf files using python scripts #29

Closed alfredoq closed 11 months ago

alfredoq commented 11 months ago

Hello,

I would like to write a python script in order to import the generated database, create a dataframe from the Results table, and afterwards loop through the LigName column of the dataframe in order to extract each molecule as an sdf file to a specific path. Is this process possible using python ringtail modules?

A first guess is that I will need two modules:

from ringtail import StorageManagerSQLite from ringtail import RingtailCore

the first one to manage the database and the second one implementing the 'rt_core.write_molecule_sdfs()' function. However it is not clear to how to implement the code. Any advice would be greatly appreciated,

thanks in advance for the support,

Alfredo

diogomart commented 11 months ago

Excellent question. We are revising the Python API to facilitate this kind of scripting.

alfredoq commented 11 months ago

Thank you Diogo for the feedback. Looking forward for this feature implemented in a more straightforward procedure. In the meantime I will try to find the hard way to accomplish it :-)

diogomart commented 11 months ago

Let us know if you find specific parts to be particularly difficult, as we may be able to improve those first.

alfredoq commented 11 months ago

Dear Diogo,

In order to extract a filtered molecule from the database, I am trying to emulate the behavior of the _rt_processvs.py script from within my own script workflow using the RingtailCore module.

So what I want to reproduce from the script is something I execute in the bash terminal as:

_rt_process_vs.py read --input_db database.db --name query_molecule --export_sdfpath .

obviously, the ligand _querymolecule is indeed stored within database.db and executing this command in the terminal effectively extracts the corresponding sdf file.

Now, in order to accomplish this using a python script, I am doing the following:

# Import the module from ringtail import RingtailCore

_#Create the default dictionary to by parsed into ringtailcore library opts = RingtailCore.getdefaults()

_#Modify the corresponding values as needed opts['out_opts']['values']['export_sdf_path'] = '.' opts['filters']['values']['ligand_filters']['N'] = ['query_molecule'] opts['storage_opts']['values']['dbfile'] = 'database.db'

_#Search within the database and export the query molecule with RingtailCore(**opts) as rt_core: _____rt_core.write_moleculesdfs()

the opts dictionary looks ok, since it contains the modified fields. However I am getting the following error:

WARNING:root:Given results bookmark does not exist in database. Cannot write passing molecule SDFs

As I can see, the filter is not been adequately parsed or effectively used to search within the database. Am I missing something?

Thank you in advance for the support

diogomart commented 11 months ago

Thank you for this example.

You need to call rt_core.filter() before writing the SDFs.

alfredoq commented 11 months ago

Thank you for the reply. I applied this and it worked as expected.

diogomart commented 11 months ago

Glad it worked!

Please feel free to open new issues if you encounter further problems or have any comments regarding ringtail scripting. We are working on it and appreciate feedback and ideas.