Macs in Chemistry

Insanely great science

 

Scripting Vortex 16

About OCHEM

OCHEM is a free open access site of annotated models and chemical data. OCHEM contains 1831772 experimental records for about 477 properties collected from 12457 sources you are free to upload your own data and also build predictive models using existing or your own data.

OCHEM is a platform for medicinal chemists, toxicologists and chemical informatics. Using OCHEM, highly precise models for substance properties - quantitative struture-activity and structure-activity models (QSPR / QSAR) can be efficiently generated. It is a comprehensive software suite that provides an integration of multiple software components into a highly complex product. The platform is an evolution of the Virtual Computational Chemistry Laboratory (VCCLAB). The VCCLAB website is visited by more than 5,000 unique visitors per month and performs more than 136,000 analyses per year. OCHEM incorporates machine-learning tools that were used to develop the "ePhysProp" suite, i.e. the same highly predictive algorithms, which have demonstrated an exceptional performance of our software in aforementioned benchmarking studies.

There are a number of modelling tools available, these include linear and non-linear methods for model development, and estimation of their prediction accuracy

There are also a number of already built models that the public can access, these include

Whilst you can access the models from the website directly there are alternative licensing options.

OCHEM Academia is a public, freely accessible online version for academic users.
OCHEM Lite is a standalone version. The standard is based on a 27''iMac, which is operated under Ubuntu. They deliver a fully installed server including one days service for introduction and integration into your IT environment.
OCHEM Flex the configurable OCHEM standard version. They install OCHEM on one of your servers or provide you with a fully installed server. Do you own a computer cluster or a proven 3D-optimization process? They integrate OCHEM for you into your existing computer infrastructure. You decide on the maximum size of the computing cluster - and you can adjust it as needed anytime within minutes. They provide service for two days, including introduction and integration into your IT environment.
OCHEM Enterprise Edition is the version for large companies. This package comes without any restrictions. The version includes a complete month of installation support by an eADMET engineer plus all other necessary work to ensure a company-wide implementation and integration into the existing infrastructure.

Full documentation is available online

Accessing OCHEM via a RESTful web service

You can also run predictions on OCHEM using simple REST-like web services. Since a prediction is not instantaneous and can take several seconds to minutes depending on the model, number of compounds and server load, the prediction is performed asynchronously, that is in two steps: 1. Start a prediction task and get a task ID 2. Fetch your prediction task using the task ID from step (1).

To post a task, you need to format the request as follows

https://ochem.eu/modelservice/postModel.do?modelId=MODEL_ID&mol=YOUR_MOLECULE(S)

Were the model ID can be the ID from the public models described above or an ID for a private model you have built provided by the OCHEM admin. The molecule can be in SMILES or SD format. For both the formats, multiple molecules can be posted using $$$$ separator. It is much more efficient to predict molecules in batches rather than posting separate tasks for each molecule.

The response will look like this

{"taskId": "1000042989", // This is the task ID you need to know "metaserverTaskId": "-1","status": "success"}

You can then use the taskId to check the progress of the calculation.

http://ochem.eu/modelservice/fetchModel.do?taskId=1000042989

If the task is still running the response will be

{"taskId": "0","metaserverTaskId": "0","status": "pending"}

When finished the response will look like this in json format.

{ "status" : "success", "predictions" : [ { "depictionID" : 4307338, "moleculeID" : 65492, "predictions" : [ { "value" : 0.8561999797821045, "accuracy" : 0.8142201834862385, "dm" : 0.21636031568050385, "unit" : "Log unit", "property" : "AMES", "realValue" : 0.0, "predictedValueString" : "active" } ] } ], "modelDescriptionUrl" : "http://ochem.eu/model/1", "taskId" : 0, "metaserverTaskId" : 0 }

The Vortex Script, posting data

To access the web service we need two scripts, the first submits the data to the web service, the second script will get the data when the calculation is completed,

The following script submits the list of molecules as SMILES strings to the AMES prediction web service. The first part is pretty standard and warns the user they are submitting data to public site, of course if you have your own internal server this would need to be amended. We then create a column to store the taskID, and then loop through the list of molecules getting the SMILES and compiling a list with the “$$$$” separating each SMILES string. We then URLencode the SMILES to avoid issues with some of the characters that might be present in SMILES strings. We then create the URL and post it to the server, the json response from the server is then parsed to get the taskID.

The last part uses the taskID to see if the job is completed and puts the taskID into the column. If the task is very fast and is completed then it pops up a message to tell you “Your job is finished:.

# This uses the OCHEM web service (https://ochem.eu/home/show.do)
#https://ochem.eu/modelservice/postModel.do?modelId=94fb6ea7-c694-44e2-9561-1ba561327a15&mol=CCN1CCCc2c1cccc2

import sys
import com.dotmatics.vortex.util.Util as Util
sys.path.append("/Users/swain/vortex/scripts/lib/jyson-1.0.2.jar")
from com.xhaus.jyson import JysonCodec as json


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>Predict AMES activity using  the OCHEM 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, "This uses the OCHEM  Web Service")

if ret == vortex.OK:

coltaskid = vtable.findColumnWithName("AMEStaskID", 1, 1)

mfm = vtable.getMolFileManager()
rows = vtable.getRealRowCount()
allsmiles=""
for r in range(0, rows):
     smiles = str(vortex.getMolProperty(mfm.getMolFileAtRow(r), 'SMILES'))

     newsmiles=""
  newsmiles = smiles + "$$$$"
    allsmiles = allsmiles + newsmiles

#print(allsmiles)     
encodedsmiles = urllib.urlencode({'':allsmiles})    
#print(encodedsmiles)

mystr = "https://ochem.eu/modelservice/postModel.do?modelId=94fb6ea7-c694-44e2-9561-1ba561327a15&mol" + encodedsmiles

try:
    myreturn = urllib2.urlopen(mystr).read()

    if (len(myreturn) > 0):
    #parse data
        j = json.loads(myreturn)
        taskID=str(j['taskId'])

        print(taskID)


    mystr2 = "http://ochem.eu/modelservice/fetchModel.do?taskId=" + taskID
    result = urllib2.urlopen(mystr2).read()
    #print(result) 
    jr = json.loads(result)
    thestatus=str(jr['status'])
    print(thestatus)

 if thestatus == 'pending':
        coltaskid.setValueFromString(0, str(j['taskId']))
        vtable.fireTableStructureChanged()
    elif thestatus == 'success':
            coltaskid.setValueFromString(0, str(j['taskId']))
        vtable.fireTableStructureChanged()
         vortex.alert('Your job has finished.') 

except:
    pass

The Vortex Script, getting data

Once the task is complete we have to now get the results. The first part of the script gets the taskID and if there is a valid taskID it then creates the columns for the predicted data and get the number of rows. We then request the model data in json format and then parse the response filling in the table row by row, and finally update the table. You need to put this script in the “context” folder which is inside the “Vortex_Add-ons” folder. This means that you simply need to right-click on the taskID to get the option to retrieve the data.

# Getting Ochem data
# 

import sys
import com.dotmatics.vortex.util.Util as Util
sys.path.append("/Users/swain/vortex/scripts/lib/jyson-1.0.2.jar")
    from com.xhaus.jyson import JysonCodec as json

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


taskID = ''

col = vtable.findColumnWithName('AMEStaskID', 0)
if (col == None):
    vortex.alert('Load a workspace with a AMEStaskID column please.')
    quit()
else:
    taskID = col.getValueAsString(cell_row)

#print(taskID)
mfm = vtable.getMolFileManager()
rows = vtable.getRealRowCount()
colAMES = vtable.findColumnWithName("AMES", 1, 1)
colpredAMESAct = vtable.findColumnWithName("AMES Activity", 1, 3)
coldistAMESModel = vtable.findColumnWithName("Dist AMES Model", 1, 1)
colAMESaccuracy = vtable.findColumnWithName("AMES Accuracy", 1, 1)



#https://ochem.eu/modelservice/fetchModel.do?taskId=251668

mystr = "https://ochem.eu/modelservice/fetchModel.do?taskId=" + taskID

try:
    myreturn = urllib2.urlopen(mystr).read()
    if (len(myreturn) > 0):



        j = json.loads(myreturn)
        thestatus=str(j['status'])

        data = json.loads(myreturn)

        if thestatus == 'success':
        #parse data
            for r in range(0, rows):
            modelData = data['predictions'][r]['predictions'][0]

            colAMES.setValueFromString(r, str(modelData['value']))
            colpredAMESAct .setValueFromString(r, str(modelData['predictedValueString']))
            coldistAMESModel.setValueFromString(r, str(modelData['dm']))
            colAMESaccuracy.setValueFromString(r, str(modelData['accuracy']))



except:
     pass


vtable.fireTableStructureChanged()

The result should look something like this.

amesresult

We can retrieve the results for the other models in a similar manner, there is a minor modification needed for the LogP Solubility script because it returns to predictions for each of the molecules.

j = json.loads(myreturn)
        thestatus=str(j['status'])

        modeldata = json.loads(myreturn)

        if thestatus == 'success':
        #parse data
            for r in range(0, rows):
            logp = modeldata['predictions'][r]['predictions'][0]
            aqsol = modeldata['predictions'][r]['predictions'][1]
            collogp.setValueFromString(r, str(logp['value']))

            collogs.setValueFromString(r, str(aqsol['value']))

The results should look like this

ochemprops

You can download the pack of six scripts, a script to submit to each of the three models (CYP1a2, AMES, and LogP/LogS predictions) together with a separate script to retrieve data from each of the models which will need to go into the “context” folder..

DOWNLOAD Files

There are a number of other similar scripts in the Other Hints, Tips and Tutorials

Page Updated 13 October 2013