Macs in Chemistry

Insanely great science

 

Scripting Vortex 10

In the sixth tutorial on scripting Vortex I described how to use filter-it from silicos-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).

It is also possible to use filter-it to simply calculate a wide range of descriptors that are used in the filtering process, by including --tab without defining an output file the tabulated properties are sent to stdout and in the second tutorial I showed how to use the “Leadlike” filter to calculate properties. The exact descriptors that are calculated depends on the criterion defined in the filter file used. Silicos-it provide four ready made filters, Druglike, Leadlike, CMClike and Clean which flags unacceptable functional groups, and users may want to define their own filters.

Druglike

NAME
ONLYELEMENTS
AROMATIC
RINGS
ATOMS
ATOMSINLARGESTRING
ATOMS
INLARGESTRINGSYSTEM ATOMSINSMALLESTRING
ATOMS
INSMALLESTRINGSYSTEM
CARBONS CHIRALCENTERS FORMALCHARGES
HALIDES HBONDACCEPTORS HBONDDONORS HETEROATOMS
LIPINSKI
ACCEPTORS
LIPINSKIDONORS LIPINSKIVIOLATIONS NONAROMATICRINGS
RIGID
BONDS RINGS
RINGSINLARGESTRINGSYSTEM RINGSINSMALLESTRINGSYSTEM
RINGSYSTEMS ROTATABLEBONDS TOTALFORMALCHARGE HETEROCARBONRATIO HALIDEFRACTION LOGP
MOLWT
TPSA

Leadlike

NAME
ONLYELEMENTS
AROMATIC
RINGS ATOMS
ATOMSINCORE
ATOMSINLARGESTBRIDGE ATOMSINLARGESTRING
ATOMSINLARGESTRINGSYSTEM ATOMSINLARGESTSIDECHAIN
ATOMSINSMALLESTBRIDGE
ATOMS
INSMALLESTRING
ATOMSINSMALLESTRINGSYSTEM
ATOMS
INSMALLESTSIDECHAIN BRIDGES CARBONS CHIRALCENTERS CORES
FORMAL
CHARGES
HALIDES HBONDACCEPTORS HBONDDONORS HETEROATOMS
LIPINSKI
ACCEPTORS
LIPINSKIDONORS LIPINSKIVIOLATIONS NONAROMATICRINGS
RIGID
BONDS RINGS
RINGSINLARGESTRINGSYSTEM RINGSINSMALLESTRINGSYSTEM
RINGSYSTEMS ROTATABLEBONDS SIDECHAINS TOTALFORMALCHARGE ANDREWSENERGY
BRIDGEFRACTION COREFRACTION
HETEROCARBONRATIO HALIDEFRACTION LOGP
LOGS
MOLWT
SIDECHAIN
FRACTION
TPSA

CMClike

NAME
ONLYELEMENTS
ABSORPTION
ATOMS
ATOMS
INCORE
ATOMS
INLARGESTBRIDGE ATOMSINLARGESTRINGSYSTEM ATOMSINLARGESTSIDECHAIN
ATOMSINSMALLESTBRIDGE
ATOMS
INSMALLESTRING
ATOMSINSMALLESTRINGSYSTEM
ATOMS
INSMALLESTSIDECHAIN BRIDGES CARBONS CHIRALCENTERS
CORES
FORMAL
CHARGES
HALIDES HBONDACCEPTORS HBONDDONORS
HETEROATOMS
LIPINSKI
ACCEPTORS
LIPINSKIDONORS LIPINSKIVIOLATIONS RIGIDBONDS RINGSYSTEMS ROTATABLEBONDS SIDECHAINS
TOTALFORMALCHARGE ANDREWSENERGY
FLEXIBILITY BRIDGE
FRACTION COREFRACTION
HETERO
CARBONRATIO HALIDEFRACTION LIGANDEFFICIENCY
LOGP
LOGS
MOLWT
RING
FRACTION
SIDECHAIN_FRACTION
TPSA

Clean

NAME ONLYELEMENTS Carboxylate Ester Acetal Acyclic-NCN AcylCyanide AcylHalide AcylImidazole AcylSulfide AcylTriazole Aldehyde Aldoxime AlkylHalide1 AlkylHalide2 AlkylHalide3 Allene AminaAnhydride Anionic-C Azide Aziridine Azo AzoCarbonylBeta AzoCyanamide Azoxy Bunte Carbamate CarbamicAcid CarbodiImide Carbonate Cationic-Br Cationic-C Cationic-Cl Cationic-I Cationic-O Cationic-P Cationic-S Chloramine Cyanate Cyanohydrin Diazo Diazonium Dichloramine Disulfide Dithioacetal Epoxide Enamine EnolEther HaloAmine HaloAmineAlfa HaloAmineBeta HaloAlkene HaloCarbamate HaloCarbonate HaloCarbonyl HaloCarbonylAlfa HaloCarbonylBeta HaloMethylEther HaloMethylThioether HaloPyrimidine HaloSulfide HaloSulfideAlfa HaloSulfideBeta HemiAcetal HemiAminal HemiKetal Hydrazide Hydrazine Hydrazone Hydroxylamine Hydroxytriazolester Imidoyl Imine Iodoso Iodoxy IsoCyanate IsoNitrile IsoThiocyanate Ketal Ketene Ketoxime Lactone LawessonsReagent MichaelAcceptor N-Halide Nitrate1 Nitrate2 Nitro1 Nitro2 Nitroso N-Methoyl NOxide1 NOxide2 NOxide3 Oxalyl Oxaziridine Oxetane P-Halide Pentafluorophenylester PerhaloketonePeroxide Phosphine Phosphinite1 Phosphonite2 Phosphite PhosphineOxide Phosphinate Phosphonate Phosphate Phosphorane Polyene QuatenaryAmmonium QuatenaryNitrogenCarbonylBeta SchiffBase SCN2 S-Halides SulfenicAcid SulfenicEster SulfinicAcid SulfinicEster SulfinylImine SulfinylHalide SulfinylNitrile SulfinylThio SulfonicAcid SulfonicEster Sulfone SulfonImine SulfonylAnhydride Sulfoxide TerminalVinylThietane ThiIrane ThioAmide ThioAcetal ThioCarbamate ThioEster-01 ThioEster-02 ThioKetal Thiol Thion ThioUrea Triazene Triflate Urea Adamantane Aminotriazole Aniline Aryl-4H-Pyridine Barbitarate Benzodioxolane Benzylhalogenide Clozapine DeltaLactam Dioxine Dibenzofurane Hydantoin Naphthylamine1 Naphthylamine_2 PosChargedNHeterocycle Psoralen Quinone tBOC CBZ Fmoc TBDMS TBDPS TIPS TMS

Providing user interaction.

With the possibility of multiple filters the original script is limited because the path to the filter file is hard coded into the script, also if users want to keep filters in a place of their own choosing or create their own filters then the script breaks. Much of this script is very similar to previous scripts, but in this script we start to explore providing the user with the opportunity to choose a file from the local file system.

file = vortex.getFile("Choose a filter file", [".sieve"], 0)

Pops up a dialog box asking the user to choose a filter file that has the extension .sieve, when the user chooses a file this is returned as a file path.

/Applications/Silicos/filter-it-1.0.0/filters/Leadlike.sieve

We then need to coerce it into a format Python understands.

sieveFile=file.getAbsolutePath()

returns

u'/Applications/Silicos/filter-it-1.0.0/filters/Leadlike.sieve'

Which we can now use in constructing the command line options.

'/usr/local/bin/filter-it', '--input='+sdfFile,  '--filter='+sieveFile, '--tab'

The rest of the script runs the command and captures the output, this is then parsed to extract the first line to provide the column headers, and the rest of the output to provide the data.

The Vortex Script

import sys


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

import subprocess

# Open a dialog to choose a file
# getFile(title, extensions, 0 = Open, 1 = Save)
# vortex will keep track of the last folder you looked in etc

file = vortex.getFile("Choose a filter file", [".sieve"], 0)

if file:
    vortex.alert(str(file))


# Need to coerce file path  
sieveFile=file.getAbsolutePath() 

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

# http://silicos-it.com/tools/filter-it/filter-it.html
# Run filter-it on the file
# p = subprocess.Popen(['/usr/local/bin/filter-it', '--input='+sdfFile,  '--filter=/Applications/Silicos/filter-it-1.0.0/filters/Druglike.sieve', '--tab'], stdout=subprocess.PIPE)
p = subprocess.Popen(['/usr/local/bin/filter-it', '--input='+sdfFile,  '--filter='+sieveFile, '--tab'], stdout=subprocess.PIPE)
output = p.communicate()[0]

# Create new columns in table if needed
lines = output.split('\n')
colName = lines[0].split('\t')
for c in colName:
    column = vtable.findColumnWithName(c, 1)
    vtable.fireTableStructureChanged()

keys = []
for i in lines:
    words = i.split('\t')
    if len(words) == 2:
        keys.append(words[0])

# Parse the output
rows = lines[1:len(lines)]
for r in range(0, vtable.getRealRowCount()):
    vals = rows[r].split('\t')
    for j in range(0, len(vals)):
        column = vtable.findColumnWithName(colName[j], 0)
        column.setValueFromString(r, vals[j])

The vortex script can be downloaded from here filterit.vpy.zip

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

I’ve now created Vortex script exchange that users can use to download or share scripts. Other Hints, Tips and Tutorials

Last Updated 18 September 2012