Macs in Chemistry

Insanely great science

 

Scripting Vortex 6

This is the sixth page on scripting Vortex, in the second tutorial I described how to use filter-it from silicos-it to calculate a wide selection of chemical properties including

In this script we will make use of the ability of filter-it to categorise input molecules into 1) a set of molecules that fulfil all criteria as defined in the filter definition file (passed molecules), and 2) a set of molecules that do not fulfil at least one of the defined filter criteria (failed molecules). The filter file defines the criteria for acceptable calculated phisicochemical properties and also any substructures that should be included or excluded during the filtering. The filter file is a simple text file that users can define for themselves, there is a detailed explanation on the silicos-it website. They also provide several example filters “Leadlike”, “Druglike”, “CMCLike” and “Clean” which cleans up a file without imposing a “drug like” filter. It should be relatively straight-forward for users to create their own filters, one could imagine a rule-of-3 filter that might be used in fragment-based screening approaches, or a toxicphore filter based on SMARTS shown to be implicated in a specific toxicity. It might also be possible to define project specific filters if a project requires a specific profile. If you need help it might be worth contacting Silicos-it. In theory the filter files can be anywhere but I created a folder in my applications folder and keep all the Silicos files there.

The script is shown below, the first part is very similar to the other scripts getting the sdf file, constructing the filter-it command and capturing the output. Remember you need the full path to both filter-it AND the filter file.

/usr/local/bin/filter-it  --input=‘/Users/username/Desktop/ChemicalStructures/acetophenones.sdf' --filter=‘/Applications/Silicos/filter-it-1.0.0/filters/Druglike.sieve' --pass --passFormat=txt

To get the output piped to stdout we need to include the --pass parameter (with no file specified) and specify the output format as text --passFormat=txt.

The result is a list of structure names of molecules that have passed the filter criterion. I’m now grateful for Dan at Dotmatics who suggested a very nice way to append the output to the table. We first remove the line-feeds and then put the list into a dictionary and test if the IDs are in it for each row of the table using has_key to test if each row is a PASS or FAIL. One thing to remember if that in Python/Jython the indenting is important! The result is shown in the image below.

filter_pass

This script can be easily modified to use the other scripts that Silico-it provide or that users create for themselves by simply editing the path to the filter file.

The script can be downloaded from here filter_leadlike.vpy.zip

The script

import sys
import com

# Uncomment the following 2 lines if running in console
#vortex = console.vortex
#vtable = console.vtable

sys.path.append(vortex.getVortexFolder() + '/modules/jythonlib')

import subprocess

# Get the path to the currently open sdf file
sdfFile = vortex.getFileForPropertyCalculation(vtable)

# Run filter-it on the file and get pass/fail


#   userprompt$  /usr/local/bin/filter-it  --input=‘/Users/username/Desktop/ChemicalStructures/acetophenones.sdf' --filter=‘/Applications/Silicos/filter-it-1.0.0/filters/Druglike.sieve' ' ' --pass --passFormat=txt
p = subprocess.Popen(['/usr/local/bin/filter-it', '--input=' + sdfFile, '--filter=/Applications/Silicos/filter-it-1.0.0/filters/Leadlike.sieve', '--pass', '--passFormat=txt'], stdout=subprocess.PIPE)
output = p.communicate()[0]

# Create list of mols that passed
list = output.split('\n')


dict = {}

for r in range(0, len(list)):
    dict[list[r]] = True

#Names you are testing
namecol = vtable.findColumnWithName('Name', 0)

#Results go in here
resultcol = vtable.findColumnWithName('Pass', 1)

#Makes the column a string type
resultcol.setType(com.dotmatics.vortex.Vortex.STRING)

#Use has_key to test if this row is a PASS or FAIL.
for s in range(0, namecol.getRowCount()):
    if dict.has_key(namecol.getValueAsString(s)):
        resultcol.setValueFromString(s, 'PASS')
    else:
        resultcol.setValueFromString(s, 'FAIL')

#Fire this to let Vortex know a new column is there.
vtable.fireTableStructureChanged()

The Vortex Scripts

Scripting Vortex Using OpenBabel
Scripting Vortex 2 Using filter-it
Scripting Votrex 3 Using cxcalc
Scripting Vortex 4 Using MOE
Scripting Vortex 5 Calculating similarities using OpenBabel
Scripting Vortex 6 Filtering compounds
Scripting Vortex 7 Using MayaChemTools
Scripting Vortex 8 Molecular Shape matching
Scripting Vortex 9 Getting a 2D depiction
Scripting Vortex 10 Interacting with the user
Scripting Vortex 11 Interacting with a web service
Scripting Vortex 12 JSON import
Scripting Vortex 13 Using OpenBabel fastsearch

Other Hints, Tips and Tutorials

Last updated 1 March 2012