The ChemSpider web services are intended to allow you to use the functionality of ChemSpider and query the data in it in your own website or program or script. There are many different webservices as described here, and also many different ways to use them.

One example of how to use them was sent to us by Jimmy Moore from the University of Manchester. He includes a call on the SimpleSearch operation of the Search web service in a perl script. THis searches the whole of ChemSpider by an input value which can be the molecule’s name, SMILES string, InChI, InChIKey, and returns the ChemSpider ID:

use strict;
my $unknown = shift;
use SOAP::Lite on_action => sub {sprintf '"%s%s"', @_};
my $token = ' '; # Your token value should be input here. I'm not going to give mine away!
my $service = SOAP::Lite -> uri('http://www.chemspider.com/')
-> proxy('http://www.chemspider.com/Search.asmx');
my $output = $service->call(SOAP::Data->name('SimpleSearch')
-> attr({xmlns => 'http://www.chemspider.com/'})
=> SOAP::Data->name('query')->value($unknown)->type('')
=> SOAP::Data->name('token')->value($token)->type(''));
my @result = $output->valueof('//SimpleSearchResult/int');
print @result;

For further background, and also an example of a perl script which uses the SMILESToInChI operation of the InChI web service see his blog page.

Please note that to use this (and some of the other) web services you need to obtain a token, by registering with ChemSpider (if you have not already), and then logging into ChemSpider and viewing your Profile page. The Security Token shown needs to be copied into the perl script itself in Jimmy’s example.

Also note that you will need to install the SOAP::Lite for Perl modules to your Perl library to run this script if you don’t already.

If you have an example of how you have used the ChemSpider web services then please reply to this ChemSpider forum post. More examples will inspire more new ideas, and also make it easier for other people trying to do similar things.

Stumble it!

2 Responses to “Example of ChemSpider web service use”

  1. Danny says:

    The perl code doesn’t work for me. I keep getting “500 Can’t connect to http://www.chemspider.com:80 (connect: timeout)” when I attempt to run it.

  2. Aileen Day says:

    Perhaps you could email us at chemspiderdev-at-rsc.org and we can work out what’s going wrong.
    I just confirmed that this script is working for us still, so should work out what’s different with your local set up and try to fix it.

Leave a Reply