Giter Club home page Giter Club logo

cirpy's Introduction

CIRpy

image

image

image

image

Introduction

CIRpy is a Python interface for the Chemical Identifier Resolver (CIR) by the CADD Group at the NCI/NIH.

CIR is a web service that will resolve any chemical identifier to another chemical representation. For example, you can pass it a chemical name and and request the corresponding SMILES string:

>>> import cirpy
>>> cirpy.resolve('Aspirin', 'smiles')
'C1=CC=CC(=C1C(O)=O)OC(C)=O'

CIRpy makes interacting with CIR through Python easy. There's no need to construct url requests and parse XML responses โ€” CIRpy does all this for you.

Installation

Install CIRpy using:

pip install cirpy

Alternatively, try one of the other installation options.

Documentation

Full documentation is available at http://cirpy.readthedocs.org.

Contribute

  • Feature ideas and bug reports are welcome on the Issue Tracker.
  • Fork the source code on GitHub, make changes and file a pull request.

Acknowledgements

All of CIRpy's functionality relies on the fantastic CIR web service created by the CADD Group at the NCI/NIH.

License

CIRpy is licensed under the MIT license.

cirpy's People

Contributors

mcs07 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cirpy's Issues

API Not responding.

urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

Having the above issue while running this command
cirpy.resolve('Aspirin', 'smiles')

Suggestion of code sample: get SMILES of list of molecules

Dear CIRpy developers, I would like to give you a code sample that could be useful for many people and could be provided in some form in the basic documentation (or even integrated as a function). This simple code gets a list of molecule names in a text file and outputs their SMILES in the command prompt.

#!/usr/bin/python
# -*- coding: Latin-1 -*-
# ----- Get SMILES from list of names -----
# 

import cirpy

with open("names.txt") as file:
    data = file.readlines()
    for molecule in data:
        name   = molecule.rstrip("\n\r")
        SMILES = cirpy.resolve(name, 'smiles')
        print name, SMILES

Resolver times out

I just installed CIRpy and tried it out, but got this error, even though my internet is fine:

>>> from cirpy import Molecule
>>> Molecule("water")
Molecule(input='water', resolvers=None, get3d=False, kwargs={})
>>> Molecule("water").formula
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1392, in connect
    super().connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 722, in create_connection
    raise err
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/BenjaminLee/Desktop/Python/Research/flow-chem/env/lib/python3.6/site-packages/cirpy.py", line 296, in fget_memoized
    setattr(self, attr_name, fget(self))
  File "/Users/BenjaminLee/Desktop/Python/Research/flow-chem/env/lib/python3.6/site-packages/cirpy.py", line 384, in formula
    return resolve(self.input, 'formula', self.resolvers, **self.kwargs)
  File "/Users/BenjaminLee/Desktop/Python/Research/flow-chem/env/lib/python3.6/site-packages/cirpy.py", line 192, in resolve
    results = query(input, representation, resolvers, False, get3d, **kwargs)
  File "/Users/BenjaminLee/Desktop/Python/Research/flow-chem/env/lib/python3.6/site-packages/cirpy.py", line 162, in query
    tree = request(input, representation, resolvers, get3d, tautomers, **kwargs)
  File "/Users/BenjaminLee/Desktop/Python/Research/flow-chem/env/lib/python3.6/site-packages/cirpy.py", line 95, in request
    response = urlopen(url)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 60] Operation timed out>```

SMILES string full of tungsten

4,4',4''-methanetriyltris(N,N-diethylaniline) (https://pubchem.ncbi.nlm.nih.gov/compound/Leucocrystal-Violet#section=MeSH-Entry-Terms) comes up with the following SMILES:
[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].[W].CCN(CC)c1ccc(cc1)C+c3ccc(cc3)N(CC)CC'

urllib2.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:590)>

I recently installed cirpy on mac osx (10.11.1) using pip. I tried the example and got the following:

cirpy.resolve('Aspirin', 'smiles')
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/cirpy.py", line 192, in resolve
results = query(input, representation, resolvers, False, get3d, *_kwargs)
File "/Library/Python/2.7/site-packages/cirpy.py", line 162, in query
tree = request(input, representation, resolvers, get3d, tautomers, *_kwargs)
File "/Library/Python/2.7/site-packages/cirpy.py", line 95, in request
response = urlopen(url)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:590)>

About triple bond in smiles

Hi.
CIRpy is so nice tool for me.
I found some trouble about "image_url".
To get imange_url with smiles, when the smiles has triple bond "#", this query will fail.
For example, smiles = "C#N" could not get the image_url.
So, I got image like that

  1. get smiles.
    smi = cirpy.resolve(query,"smiles",["cir_name","chemspider_name","opsin_name"])

  2. then replace "#"
    html_smi = smi.replace("#","%23")

  3. and get image
    imageurl = cirpy.Molecule(html_smi, ["smiles"]).image_url

Is that correct way?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.