In a previous tutorial we made use of the Virtual Computational Chemistry Laboratory web service to calculate aLogP and LogS, both these results were returned in a simple text format. More recently there has been an increased use of JSON format for data exchange.

JSON, or JavaScript Object Notation, is a text-based open standard designed for easy human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects. Despite its relationship to JavaScript, it is language-independent, with parsers available for many languages including including C, C++, C#, Java, JavaScript, Perl, Python.

JSON is built on two structures

  • A collection of name/value pairs. In various languages, this is realised as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realised as an array, vector, list, or sequence.

JSON can be used to provide the results of a calculation via a web service or it could be used to provide the results of a database search, indeed the popular database mongoDB uses JSON-style document storage. It can be regarded as less verbose alternative to XML.

Unfortunately the current version of Jython (2.5.x) does not support JSON however there is A fast JSON opensource codec for jython 2.5, written in java called jyson.

Installing jyson

You can download jyson from here, I’m not sure where the best place to install the jyson-1.0.2.jar file is, but I put it in “/Users/username/vortex/scripts/lib/jyson-1.0.2.jar. You need to make a note of where you put it because you need the full path to include in the script.

Molinspiration web services

Molinspiration provide a number of cheminformatics tools but also provide a RESTful web service these web services can be used to calculate a range of molecular properties and bioactivity predictions.

The output from both web services is available either as a JSON string or plain text, the web service can be accessed by submitting a URL in the following format, noting that the SMILES string needs to be encoded

If bioactivity is required simply change to &type=ba

The result is returned in JSON format

Where the property name and value appear as colon separated pairs.

Note:-

The limit for a number of calculations for an IP address is 1000 per month to assure good availability of services for all users. 

Explanation

Since we are going to be using an external java module we need to tell the script where the jar file is and then import it. You will need to modify the path to the jar file.

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

The next part of the script sets up all the columns and sets the column type to double. 

We then need to get the SMILES string for each structure as we loop through the table.

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 output in JSON format (shown below)

One useful feature to aid error checking is to include the print() command, this prints the results to the Jython console (you can open the Console from the Scripts menu).

The print command results in this appearing in the console.

It is important to note that the order of objects is not the same as returned by the web service and to access each of them when need to use the object name.

e,g.

One last minor issue is Vortex uses setValueFromString because it is most reusable as you don’t then have to code for data types, this does mean however that we need to convert the values to strings before importing them into the table.

Finally we update the table.

The Molinspiration properties Vortex Script

The vortex script can be downloaded from here 

The Molinspiration predicted biological activity Vortex Script

This is a modification of the above script and accesses the predicted biological properties.

The vortex script can be downloaded from here

Last updated 21 February 2013

Related Posts