Macs in Chemistry

Insanely great science

Scripting Vortex 11

In previous scripts we have generated data using a local Java program, C program, PERL script, and SVL program. In this tutorial rather than have a local application generate the data we will use a web service.

The Virtual Computational Chemistry Laboratory provides a number of free online tools that are useful for computational chemistry. One of these tools is a web service is a LogPS which provides a prediction of logP and water solubility.

Whilst the website provides access using a Java applet there is also a web service interface that requires input in the following format

The result is returned thus

mol_N logP logS SMILES
mol_1 0.70 0.49 c1ncccc1


Since this script access an external web service it is probably not a good idea to send your proprietary structures to this service, the first part of the script reminds the user of this, if the user presses OK then the script runs.

The next part generates two new columns, “aLogP” and “aLogS”. We then need to get the SMILES string for each structure as we loop through the table.

smiles = vortex.getMolProperty(mfm.getMolFileAtRow(r), 'SMILES')

The next task is to generate the URL containing the SMILES string, however since SMILES often contain characters outside the ASCII set, the SMILES string has to be converted into a valid ASCII format. The URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.

We then submit the data to the web service and capture the text returned. The final part of the script parses the text returned to extract the LogP and LogS values. Finally we update the table.

This script calculates data that people may have access to via a desktop application however it should be possible to modify the script to interact with other web services, perhaps in house tools to calculate physicochemical properties based on experimental data within a series of compounds, or algorithms to predict ADME properties, unwanted HERG or CYP450 interactions.


The Vortex Script

\# This uses the Virtual Computational Chemistry Laboratory (

import sys
import com.dotmatics.vortex.util.Util as Util

if Util.getPlatform() == Util.PlatformIsWindows:
  sys.path.append(vortex.getVortexFolder() + '\\modules\\jythonconsole')
  sys.path.append(vortex.getVortexFolder() + '\\modules\\jythonlib')
  sys.path.append(vortex.getVortexFolder() + '/modules/jythonconsole')
  sys.path.append(vortex.getVortexFolder() + '/modules/jythonlib')

import urllib2
import urllib

content = javax.swing.JPanel()

label = javax.swing.JLabel("<html><b>Calculate aLogP using the web service</b><p>.<br>If you don't want to post your data to the internet press Cancel.</html>")

layout.fill(content, label, 2, 2)

ret = vortex.showInDialog(content, "Web Service to get aLogP")

if ret == vortex.OK:
   collogp = vtable.findColumnWithName("aLogP", 1, 1)
   collogs = vtable.findColumnWithName("aLogS", 1, 1)
   mfm = vtable.getMolFileManager()
  rows = vtable.getRealRowCount()
   for r in range(0, rows):
     smiles = vortex.getMolProperty(mfm.getMolFileAtRow(r), 'SMILES')
     encodedsmiles = urllib.urlencode({'':smiles})

     mystr = "" + encodedsmiles
       myreturn = urllib2.urlopen(mystr).readlines()
      if (len(myreturn) > 0):
         #parse data
         list1 = myreturn[0]
         lines = list1.split('<br>')
         data = lines[1]
         #'mol_1 1.73 -2.30 CC(=O)c1c(cccc1F)F'
         vals = data.split(' ', 3)

         collogp.setValueFromString(r, vals[1])
         collogs.setValueFromString(r, vals[2])


The vortex script can be downloaded from here

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 19 February 2013