Vortex script interacting with a web service

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.

  • 1-octanol/water calculation: ALOGPs was developed with 12908 molecules from the PHYSPROP database using 75 E-state indicies. 64 neural networks were trained using 50% of molecules selected by chance from the whole set. The logP prediction accuracy is root mean squared error rms=0.35 and standard mean error s=0.26.
  • Aqueous solubility calculation: ALOGpS was developed using 1291 molecules and provided improved aqueous solubility prediction (rms=0.49, s=0.38) compared to our previous analysis.

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

 http://www.vcclab.org/web/alogps/calc?SMILES=c1ncccc1

The result is returned thus

mol_N logP logS SMILES
mol_1 0.70 0.49 c1ncccc1

Explanation

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 (http://www.vcclab.org)
\# http://www.vcclab.org/web/alogps/calc?SMILES=c1ncccc1

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')
else:
  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 vcclab.org 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 = "http://www.vcclab.org/web/alogps/calc?SMILES" + encodedsmiles
     try:
       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])
    except:
       pass

   vtable.fireTableStructureChanged()

The vortex script can be downloaded from here

Last updated 19 Feb 2013

Related Posts