diff --git a/.gitignore b/.gitignore index be1907c..8dd84d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ __pycache__/ *.py[cod] -build/ -dist/ +/docs/_build/ +/dist/ *.egg-info/ .coverage .coverage.* diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc3ef1..5ec2110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,32 +1,43 @@ # Change Log -## [v1.0.5](https://github.com/mcs07/ChemSpiPy/releases/tag/v1.0.5) (2017-03-29) -[Full Changelog](https://github.com/mcs07/ChemSpiPy/compare/v1.0.4...v1.0.5) +## [v2.0.0](https://github.com/mcs07/ChemSpiPy/tree/v2.0.0) (2018-09-09) +[Full Changelog](https://github.com/mcs07/ChemSpiPy/compare/v1.0.5...v2.0.0) + +**Implemented enhancements:** + +- Switch to new RSC REST API [\#12](https://github.com/mcs07/ChemSpiPy/pull/12) ([mcs07](https://github.com/mcs07)) **Closed issues:** -- Add support for https [\#5](https://github.com/mcs07/ChemSpiPy/issues/5) +- Make conda-forge recipe [\#13](https://github.com/mcs07/ChemSpiPy/issues/13) +- return \# of data sources in search results [\#10](https://github.com/mcs07/ChemSpiPy/issues/10) -**Merged pull requests:** +## [v1.0.5](https://github.com/mcs07/ChemSpiPy/tree/v1.0.5) (2017-03-29) +[Full Changelog](https://github.com/mcs07/ChemSpiPy/compare/v1.0.4...v1.0.5) + +**Implemented enhancements:** - Switch to pytest [\#7](https://github.com/mcs07/ChemSpiPy/pull/7) ([mcs07](https://github.com/mcs07)) + +**Fixed bugs:** + +- Add support for https [\#5](https://github.com/mcs07/ChemSpiPy/issues/5) - Use https by default - fixes \#5 [\#6](https://github.com/mcs07/ChemSpiPy/pull/6) ([mcs07](https://github.com/mcs07)) + +**Merged pull requests:** + - Improve handling of invalid tokens [\#4](https://github.com/mcs07/ChemSpiPy/pull/4) ([mcs07](https://github.com/mcs07)) -## [v1.0.4](https://github.com/mcs07/ChemSpiPy/releases/tag/v1.0.4) (2015-06-13) +## [v1.0.4](https://github.com/mcs07/ChemSpiPy/tree/v1.0.4) (2015-06-13) [Full Changelog](https://github.com/mcs07/ChemSpiPy/compare/v1.0.3...v1.0.4) -## [v1.0.3](https://github.com/mcs07/ChemSpiPy/releases/tag/v1.0.3) (2015-03-05) +## [v1.0.3](https://github.com/mcs07/ChemSpiPy/tree/v1.0.3) (2015-03-05) [Full Changelog](https://github.com/mcs07/ChemSpiPy/compare/v1.0.2...v1.0.3) -## [v1.0.2](https://github.com/mcs07/ChemSpiPy/releases/tag/v1.0.2) (2015-03-04) +## [v1.0.2](https://github.com/mcs07/ChemSpiPy/tree/v1.0.2) (2015-03-04) [Full Changelog](https://github.com/mcs07/ChemSpiPy/compare/v1.0.1...v1.0.2) -## [v1.0.1](https://github.com/mcs07/ChemSpiPy/releases/tag/v1.0.1) (2014-09-15) -**Merged pull requests:** +## [v1.0.1](https://github.com/mcs07/ChemSpiPy/tree/v1.0.1) (2014-09-15) +**Implemented enhancements:** - Fix for UTF-8 encoding error \(and some other tweaks\)... [\#2](https://github.com/mcs07/ChemSpiPy/pull/2) ([nickfyson](https://github.com/nickfyson)) - - - -\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 97521a4..79140ec 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -22,11 +22,12 @@ Quick guide to contributing 1. `Fork the ChemSpiPy repository on GitHub`_, then clone your fork to your local machine:: git clone https://github.com//ChemSpiPy.git + cd ChemSpiPy -2. Install the development requirements:: +2. Install the development requirements into a `conda environment`_:: - cd chemspipy - pip install -r requirements/dev.txt + conda env create -n chemspipy -f environment.yml + source activate chemspipy 3. Create a new branch for your changes:: @@ -36,8 +37,6 @@ Quick guide to contributing pytest - The final line of the output should be ``OK``. - 5. Commit your changes and push to your fork on GitHub:: git add . @@ -53,15 +52,14 @@ Tips - Include docstrings as described in `PEP257`_. - Try and include tests that cover your changes. - Try to write `good commit messages`_. -- Consider `squashing your commits`_ with rebase. - Read the GitHub help page on `Using pull requests`_. .. _`Issue Tracker`: https://github.com/mcs07/ChemSpiPy/issues .. _`source code`: https://github.com/mcs07/ChemSpiPy .. _`Fork the ChemSpiPy repository on GitHub`: https://github.com/mcs07/ChemSpiPy/fork +.. _`conda environment`: https://conda.io/docs/ .. _`Submit a pull request`: https://github.com/mcs07/ChemSpiPy/compare/ -.. _`squashing your commits`: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html .. _`PEP8`: https://www.python.org/dev/peps/pep-0008 .. _`PEP257`: https://www.python.org/dev/peps/pep-0257 -.. _`good commit messages`: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html +.. _`good commit messages`: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html .. _`Using pull requests`: https://help.github.com/articles/using-pull-requests diff --git a/MANIFEST.in b/MANIFEST.in index 829ceb6..1748937 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include *.rst +include CHANGELOG.md +include environment.yml include LICENSE recursive-include tests *.py recursive-include docs * -recursive-include requirements *.txt -prune docs/build +prune docs/_build diff --git a/README.rst b/README.rst index ef9fdf0..a5d7564 100644 --- a/README.rst +++ b/README.rst @@ -1,16 +1,16 @@ ChemSpiPy ========= -.. image:: http://img.shields.io/pypi/v/ChemSpiPy.svg?style=flat +.. image:: https://img.shields.io/pypi/v/ChemSpiPy.svg?style=flat :target: https://pypi.python.org/pypi/ChemSpiPy -.. image:: http://img.shields.io/pypi/l/ChemSpiPy.svg?style=flat +.. image:: https://img.shields.io/pypi/l/ChemSpiPy.svg?style=flat :target: https://github.com/mcs07/ChemSpiPy/blob/master/LICENSE -.. image:: http://img.shields.io/travis/mcs07/ChemSpiPy/master.svg?style=flat +.. image:: https://img.shields.io/travis/mcs07/ChemSpiPy/master.svg?style=flat :target: https://travis-ci.org/mcs07/ChemSpiPy -.. image:: http://img.shields.io/coveralls/mcs07/ChemSpiPy/master.svg?style=flat +.. image:: https://img.shields.io/coveralls/mcs07/ChemSpiPy/master.svg?style=flat :target: https://coveralls.io/r/mcs07/ChemSpiPy?branch=master ChemSpiPy provides a way to interact with ChemSpider in Python. It allows chemical searches, chemical file downloads, @@ -24,7 +24,12 @@ depiction and retrieval of chemical properties:: Installation ------------ -Install ChemSpiPy using pip:: +Install ChemSpiPy using conda:: + + conda install -c conda-forge chemspipy + + +or using pip:: pip install chemspipy @@ -33,7 +38,7 @@ Alternatively, try one of the other `installation options`_. Documentation ------------- -Full documentation is available at http://chemspipy.readthedocs.io. +Full documentation is available at https://chemspipy.readthedocs.io/en/stable/. The `general documentation for the ChemSpider API`_ is also a useful resource. @@ -50,9 +55,9 @@ ChemSpiPy is licensed under the `MIT license`_. This project was originally forked from `ChemSpiPy by Cameron Neylon`_, which has been released into the public domain. -.. _`installation options`: http://chemspipy.readthedocs.io/en/latest/guide/install.html +.. _`installation options`: https://chemspipy.readthedocs.io/en/stable/guide/install.html .. _`source code`: https://github.com/mcs07/ChemSpiPy .. _`Issue Tracker`: https://github.com/mcs07/ChemSpiPy/issues .. _`MIT license`: https://github.com/mcs07/ChemSpiPy/blob/master/LICENSE .. _`ChemSpiPy by Cameron Neylon`: https://github.com/cameronneylon/ChemSpiPy -.. _`general documentation for the ChemSpider API`: http://www.chemspider.com/AboutServices.aspx +.. _`general documentation for the ChemSpider API`: https://developer.rsc.org/compounds-v1/apis diff --git a/chemspipy/__init__.py b/chemspipy/__init__.py index 99c9663..4e2f077 100644 --- a/chemspipy/__init__.py +++ b/chemspipy/__init__.py @@ -19,6 +19,6 @@ from .api import ChemSpider, MOL2D, MOL3D, BOTH, ASCENDING, DESCENDING, RECORD_ID, CSID, MASS_DEFECT, MOLECULAR_WEIGHT -from .api import REFERENCE_COUNT, DATASOURCE_COUNT, PUBMED_COUNT, RSC_COUNT +from .api import REFERENCE_COUNT, DATASOURCE_COUNT, PUBMED_COUNT, RSC_COUNT, FIELDS from .objects import Compound from .search import Results diff --git a/chemspipy/api.py b/chemspipy/api.py index 8019ff4..6762a1c 100644 --- a/chemspipy/api.py +++ b/chemspipy/api.py @@ -86,7 +86,15 @@ ] -class BaseChemSpider(object): +class ChemSpider(object): + """Provides access to the ChemSpider API. + + Usage:: + + >>> from chemspipy import ChemSpider + >>> cs = ChemSpider('') + + """ def __init__(self, api_key, user_agent=None, api_url=API_URL, api_version=API_VERSION): """ @@ -105,6 +113,9 @@ def __init__(self, api_key, user_agent=None, api_url=API_URL, api_version=API_VE self.api_key = api_key self.api_version = api_version + def __repr__(self): + return 'ChemSpider()' + def request(self, method, api, namespace, endpoint, params=None, json=None): """Make a request to the ChemSpider API. @@ -169,9 +180,41 @@ def post(self, api, namespace, endpoint, json=None): """ return self.request('POST', api=api, namespace=namespace, endpoint=endpoint, json=json) + def get_compound(self, csid): + """Return a Compound object for a given ChemSpider ID. + + :param string|int csid: ChemSpider ID. + :return: The Compound with the specified ChemSpider ID. + :rtype: :class:`~chemspipy.objects.Compound` + """ + return Compound(self, csid) + + def get_compounds(self, csids): + """Return a list of Compound objects, given a list ChemSpider IDs. + + :param list[string|int] csids: List of ChemSpider IDs. + :return: List of Compounds with the specified ChemSpider IDs. + :rtype: list[:class:`~chemspipy.objects.Compound`] + """ + return [Compound(self, csid) for csid in csids] + + def search(self, query, order=None, direction=ASCENDING, raise_errors=False): + """Search ChemSpider for the specified query and return the results. + + The accepted values for ``order`` are: :data:`~chemspipy.api.RECORD_ID`, :data:`~chemspipy.api.MASS_DEFECT`, + :data:`~chemspipy.api.MOLECULAR_WEIGHT`, :data:`~chemspipy.api.REFERENCE_COUNT`, + :data:`~chemspipy.api.DATASOURCE_COUNT`, :data:`~chemspipy.api.PUBMED_COUNT` or + :data:`~chemspipy.api.RSC_COUNT`. -class LookupsApi(BaseChemSpider): - """""" + :param string|int query: Search query. + :param string order: (Optional) Field to sort the result by. + :param string direction: (Optional) :data:`~chemspipy.api.ASCENDING` or :data:`~chemspipy.api.DESCENDING`. + :param bool raise_errors: (Optional) If True, raise exceptions. If False, store on Results ``exception`` + property. + :return: Search Results list. + :rtype: :class:`~chemspipy.search.Results` + """ + return Results(self, self.filter_name, (query, order, direction), raise_errors=raise_errors) def get_datasources(self): """Get the list of datasources in ChemSpider. @@ -185,10 +228,6 @@ def get_datasources(self): response = self.get(api='compounds', namespace='lookups', endpoint='datasources') return response['dataSources'] - -class RecordsApi(BaseChemSpider): - """""" - def get_details(self, record_id, fields=FIELDS): """Get details for a compound record. @@ -258,10 +297,6 @@ def get_mol(self, record_id): response = self.get(api='compounds', namespace='records', endpoint=endpoint) return response['sdf'] - -class FilterApi(BaseChemSpider): - """""" - def filter_element(self, include_elements, exclude_elements=None, include_all=False, complexity=None, isotopic=None, order=None, direction=None): """Search compounds by element. @@ -596,10 +631,6 @@ def filter_results_sdf(self, query_id): response = self.get(api='compounds', namespace='filter', endpoint=endpoint) return zlib.decompress(base64.b64decode(response['results']), 16 + zlib.MAX_WBITS) - -class ToolsApi(BaseChemSpider): - """""" - def convert(self, input, input_format, output_format): """Convert a chemical from one format to another. @@ -632,16 +663,21 @@ def validate_inchikey(self, inchikey): except errors.ChemSpiPyHTTPError: return False + def get_databases(self): + """Get the list of datasources in ChemSpider. -class MassSpecApi(BaseChemSpider): + .. deprecated:: 2.0.0 + Use :py:meth:`~chemspipy.api.ChemSpider.get_datasources` instead. - def get_databases(self): - """Get the list of datasources in ChemSpider.""" + """ warnings.warn('Use get_datasources instead of get_databases.', DeprecationWarning) return self.get_datasources() def get_extended_compound_info(self, csid): - """Get extended record details for a CSID. Security token is required. + """Get extended record details for a CSID. + + .. deprecated:: 2.0.0 + Use :py:meth:`~chemspipy.api.ChemSpider.get_details` instead. :param string|int csid: ChemSpider ID. """ @@ -649,7 +685,10 @@ def get_extended_compound_info(self, csid): return self.get_details(record_id=csid) def get_extended_compound_info_list(self, csids): - """Get extended record details for a list of CSIDs. Security token is required. + """Get extended record details for a list of CSIDs. + + .. deprecated:: 2.0.0 + Use :py:meth:`~chemspipy.api.ChemSpider.get_details_batch` instead. :param list[string|int] csids: ChemSpider IDs. """ @@ -660,7 +699,10 @@ def get_extended_mol_compound_info_list(self, csids, mol_type=MOL2D, include_ref include_external_references=False): """Get extended record details (including MOL) for a list of CSIDs. - A maximum of 250 CSIDs can be fetched per request. Security token is required. + A maximum of 250 CSIDs can be fetched per request. + + .. deprecated:: 2.0.0 + Use :py:meth:`~chemspipy.api.ChemSpider.get_details_batch` instead. :param list[string|int] csids: ChemSpider IDs. :param string mol_type: :data:`~chemspipy.api.MOL2D`, :data:`~chemspipy.api.MOL3D` or @@ -672,7 +714,10 @@ def get_extended_mol_compound_info_list(self, csids, mol_type=MOL2D, include_ref return self.get_details_batch(record_ids=csids) def get_record_mol(self, csid, calc3d=False): - """Get ChemSpider record in MOL format. Security token is required. + """Get ChemSpider record in MOL format. + + .. deprecated:: 2.0.0 + Use :py:meth:`~chemspipy.api.ChemSpider.get_mol` instead. :param string|int csid: ChemSpider ID. :param bool calc3d: Whether 3D coordinates should be calculated before returning record data. @@ -682,15 +727,13 @@ def get_record_mol(self, csid, calc3d=False): warnings.warn('calc3d parameter for get_record_mol is no longer supported.', DeprecationWarning) return self.get_mol(record_id=csid) - -class SearchApi(BaseChemSpider): - def async_simple_search(self, query): """Search ChemSpider with arbitrary query, returning results in order of the best match found. This method returns a transaction ID which can be used with other methods to get search status and results. - Security token is required. + .. deprecated:: 2.0.0 + Use :py:meth:`~chemspipy.api.ChemSpider.filter_name` instead. :param string query: Search query - a name, SMILES, InChI, InChIKey, CSID, etc. :return: Transaction ID. @@ -704,7 +747,8 @@ def async_simple_search_ordered(self, query, order=CSID, direction=ASCENDING): This method returns a transaction ID which can be used with other methods to get search status and results. - Security token is required. + .. deprecated:: 2.0.0 + Use :meth:`~chemspipy.api.ChemSpider.filter_name` instead. :param string query: Search query - a name, SMILES, InChI, InChIKey, CSID, etc. :param string order: (Optional) Field to sort the result by. @@ -718,7 +762,8 @@ def async_simple_search_ordered(self, query, order=CSID, direction=ASCENDING): def get_async_search_status(self, rid): """Check the status of an asynchronous search operation. - Security token is required. + .. deprecated:: 2.0.0 + Use :meth:`~chemspipy.api.ChemSpider.filter_status` instead. :param string rid: A transaction ID, returned by an asynchronous search method. :return: Unknown, Created, Scheduled, Processing, Suspended, PartialResultReady, ResultReady, Failed, @@ -731,7 +776,8 @@ def get_async_search_status(self, rid): def get_async_search_status_and_count(self, rid): """Check the status of an asynchronous search operation. If ready, a count and message are also returned. - Security token is required. + .. deprecated:: 2.0.0 + Use :meth:`~chemspipy.api.ChemSpider.filter_status` instead. :param string rid: A transaction ID, returned by an asynchronous search method. :rtype: dict @@ -740,24 +786,30 @@ def get_async_search_status_and_count(self, rid): return self.filter_status(query_id=rid) def get_async_search_result(self, rid): - """Get the results from a asynchronous search operation. Security token is required. + """Get the results from a asynchronous search operation. + + .. deprecated:: 2.0.0 + Use :meth:`~chemspipy.api.ChemSpider.filter_results` instead. :param string rid: A transaction ID, returned by an asynchronous search method. :return: A list of Compounds. - :rtype: list[:class:`~chemspipy.Compound`] + :rtype: list[:class:`~chemspipy.objects.Compound`] """ warnings.warn('Use filter_results instead of get_async_search_result.', DeprecationWarning) results = self.filter_results(query_id=rid) return [Compound(self, record_id) for record_id in results] def get_async_search_result_part(self, rid, start=0, count=-1): - """Get a slice of the results from a asynchronous search operation. Security token is required. + """Get a slice of the results from a asynchronous search operation. + + .. deprecated:: 2.0.0 + Use :meth:`~chemspipy.api.ChemSpider.filter_results` instead. :param string rid: A transaction ID, returned by an asynchronous search method. :param int start: The number of results to skip. :param int count: The number of results to return. -1 returns all through to end. :return: A list of Compounds. - :rtype: list[:class:`~chemspipy.Compound`] + :rtype: list[:class:`~chemspipy.objects.Compound`] """ warnings.warn('Use filter_results instead of get_async_search_result_part.', DeprecationWarning) if count == -1: @@ -766,7 +818,10 @@ def get_async_search_result_part(self, rid, start=0, count=-1): return [Compound(self, record_id) for record_id in results] def get_compound_info(self, csid): - """Get SMILES, StdInChI and StdInChIKey for a given CSID. Security token is required. + """Get SMILES, StdInChI and StdInChIKey for a given CSID. + + .. deprecated:: 2.0.0 + Use :meth:`~chemspipy.api.ChemSpider.get_details` instead. :param string|int csid: ChemSpider ID. :rtype: dict @@ -777,6 +832,9 @@ def get_compound_info(self, csid): def get_compound_thumbnail(self, csid): """Get PNG image as binary data. + .. deprecated:: 2.0.0 + Use :meth:`~chemspipy.api.ChemSpider.get_image` instead. + :param string|int csid: ChemSpider ID. :rtype: bytes """ @@ -786,65 +844,12 @@ def get_compound_thumbnail(self, csid): def simple_search(self, query): """Search ChemSpider with arbitrary query. - .. deprecated:: 2.0 + .. deprecated:: 2.0.0 Use :meth:`~chemspipy.api.ChemSpider.search` instead. :param string query: Search query - a chemical name. :return: Search Results list. - :rtype: chemspipy.search.Results + :rtype: :class:`~chemspipy.search.Results` """ warnings.warn('Use search instead of simple_search.', DeprecationWarning) return self.search(query=query) - - -class CustomApi(BaseChemSpider): - - def get_compound(self, csid): - """Return a Compound object for a given ChemSpider ID. Security token is required. - - :param string|int csid: ChemSpider ID. - :return: The Compound with the specified ChemSpider ID. - :rtype: :class:`~chemspipy.Compound` - """ - return Compound(self, csid) - - def get_compounds(self, csids): - """Return a list of Compound objects, given a list ChemSpider IDs. Security token is required. - - :param list[string|int] csids: List of ChemSpider IDs. - :return: List of Compounds with the specified ChemSpider IDs. - :rtype: list[:class:`~chemspipy.Compound`] - """ - return [Compound(self, csid) for csid in csids] - - def search(self, query, order=None, direction=ASCENDING, raise_errors=False): - """Search ChemSpider for the specified query and return the results. Security token is required. - - The accepted values for ``order`` are: :data:`~chemspipy.api.RECORD_ID`, :data:`~chemspipy.api.MASS_DEFECT`, - :data:`~chemspipy.api.MOLECULAR_WEIGHT`, :data:`~chemspipy.api.REFERENCE_COUNT`, - :data:`~chemspipy.api.DATASOURCE_COUNT`, :data:`~chemspipy.api.PUBMED_COUNT` or - :data:`~chemspipy.api.RSC_COUNT`. - - :param string|int query: Search query. - :param string order: (Optional) Field to sort the result by. - :param string direction: (Optional) :data:`~chemspipy.api.ASCENDING` or :data:`~chemspipy.api.DESCENDING`. - :param bool raise_errors: (Optional) If True, raise exceptions. If False, store on Results ``exception`` - property. - :return: Search Results list. - :rtype: chemspipy.search.Results - """ - return Results(self, self.filter_name, (query, order, direction), raise_errors=raise_errors) - - -class ChemSpider(CustomApi, FilterApi, LookupsApi, RecordsApi, ToolsApi, MassSpecApi, SearchApi): - """Provides access to the ChemSpider API. - - Usage:: - - >>> from chemspipy import ChemSpider - >>> cs = ChemSpider('') - - """ - - def __repr__(self): - return 'ChemSpider()' diff --git a/chemspipy/objects.py b/chemspipy/objects.py index 093f96f..9769011 100644 --- a/chemspipy/objects.py +++ b/chemspipy/objects.py @@ -45,18 +45,30 @@ def _repr_png_(self): @property def record_id(self): - """Compound record ID.""" + """Compound record ID. + + :rtype: int + """ return self._record_id @property def csid(self): - """ChemSpider ID.""" + """ChemSpider ID. + + .. deprecated:: 2.0.0 + Use :py:attr:`~chemspipy.objects.Compound.record_id` instead. + + :rtype: int + """ warnings.warn('Use record_id instead of csid.', DeprecationWarning) return self._record_id @property def image_url(self): - """Return the URL of a PNG image of the 2D chemical structure.""" + """Return the URL of a PNG image of the 2D chemical structure. + + :rtype: string + """ return 'http://www.chemspider.com/ImagesHandler.ashx?id=%s' % self.record_id @memoized_property @@ -86,6 +98,9 @@ def smiles(self): def stdinchi(self): """Return the Standard InChI for this Compound. + .. deprecated:: 2.0.0 + Use :py:attr:`~chemspipy.objects.Compound.inchi` instead. + :rtype: string """ warnings.warn('Use inchi instead of stdinchi.', DeprecationWarning) @@ -95,6 +110,9 @@ def stdinchi(self): def stdinchikey(self): """Return the Standard InChIKey for this Compound. + .. deprecated:: 2.0.0 + Use :py:attr:`~chemspipy.objects.Compound.inchikey` instead. + :rtype: string """ warnings.warn('Use inchikey instead of stdinchikey.', DeprecationWarning) @@ -184,6 +202,6 @@ def image(self): def external_references(self): """Return external references for this Compound. - :rtype: list[string] + :rtype: list[dict] """ return self._cs.get_external_references(self.record_id) diff --git a/docs/Makefile b/docs/Makefile index c46fa04..6d0b339 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,177 +1,20 @@ -# Makefile for Sphinx documentation +# Minimal makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build -PAPER = -BUILDDIR = build - -# User-friendly check for sphinx-build -ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) -$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) -endif - -# Internal variables. -PAPEROPT_a4 = -D latex_paper_size=a4 -PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source -# the i18n builder cannot share the environment and doctrees with the others -I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source - -.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext +SPHINXPROJ = ChemSpiPy +SOURCEDIR = . +BUILDDIR = _build +# Put it first so that "make" without argument is like "make help". help: - @echo "Please use \`make ' where is one of" - @echo " html to make standalone HTML files" - @echo " dirhtml to make HTML files named index.html in directories" - @echo " singlehtml to make a single large HTML file" - @echo " pickle to make pickle files" - @echo " json to make JSON files" - @echo " htmlhelp to make HTML files and a HTML help project" - @echo " qthelp to make HTML files and a qthelp project" - @echo " devhelp to make HTML files and a Devhelp project" - @echo " epub to make an epub" - @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" - @echo " latexpdf to make LaTeX files and run them through pdflatex" - @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" - @echo " text to make text files" - @echo " man to make manual pages" - @echo " texinfo to make Texinfo files" - @echo " info to make Texinfo files and run them through makeinfo" - @echo " gettext to make PO message catalogs" - @echo " changes to make an overview of all changed/added/deprecated items" - @echo " xml to make Docutils-native XML files" - @echo " pseudoxml to make pseudoxml-XML files for display purposes" - @echo " linkcheck to check all external links for integrity" - @echo " doctest to run all doctests embedded in the documentation (if enabled)" - -clean: - rm -rf $(BUILDDIR)/* - -html: - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." - -dirhtml: - $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." - -singlehtml: - $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml - @echo - @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." - -pickle: - $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle - @echo - @echo "Build finished; now you can process the pickle files." - -json: - $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json - @echo - @echo "Build finished; now you can process the JSON files." - -htmlhelp: - $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp - @echo - @echo "Build finished; now you can run HTML Help Workshop with the" \ - ".hhp project file in $(BUILDDIR)/htmlhelp." - -qthelp: - $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp - @echo - @echo "Build finished; now you can run "qcollectiongenerator" with the" \ - ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ChemSpiPy.qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ChemSpiPy.qhc" - -devhelp: - $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp - @echo - @echo "Build finished." - @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/ChemSpiPy" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ChemSpiPy" - @echo "# devhelp" - -epub: - $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub - @echo - @echo "Build finished. The epub file is in $(BUILDDIR)/epub." - -latex: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo - @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." - @echo "Run \`make' in that directory to run these through (pdf)latex" \ - "(use \`make latexpdf' here to do that automatically)." - -latexpdf: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through pdflatex..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -latexpdfja: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through platex and dvipdfmx..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -text: - $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text - @echo - @echo "Build finished. The text files are in $(BUILDDIR)/text." - -man: - $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man - @echo - @echo "Build finished. The manual pages are in $(BUILDDIR)/man." - -texinfo: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo - @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." - @echo "Run \`make' in that directory to run these through makeinfo" \ - "(use \`make info' here to do that automatically)." - -info: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo "Running Texinfo files through makeinfo..." - make -C $(BUILDDIR)/texinfo info - @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." - -gettext: - $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale - @echo - @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." - -changes: - $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes - @echo - @echo "The overview file is in $(BUILDDIR)/changes." - -linkcheck: - $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck - @echo - @echo "Link check complete; look for any errors in the above output " \ - "or in $(BUILDDIR)/linkcheck/output.txt." - -doctest: - $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest - @echo "Testing of doctests in the sources finished, look at the " \ - "results in $(BUILDDIR)/doctest/output.txt." + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -xml: - $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml - @echo - @echo "Build finished. The XML files are in $(BUILDDIR)/xml." +.PHONY: help Makefile -pseudoxml: - $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml - @echo - @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/docs/api.rst b/docs/api.rst new file mode 100644 index 0000000..e32ac97 --- /dev/null +++ b/docs/api.rst @@ -0,0 +1,37 @@ +.. _api: + +API Documentation +================= + +.. sectionauthor:: Matt Swain + +.. module:: chemspipy + +This part of the documentation is automatically generated from the ChemSpiPy source code and comments. + +.. automodule:: chemspipy.api + + .. autoclass:: ChemSpider() + :members: + + .. autodata:: ASCENDING + .. autodata:: DESCENDING + .. autodata:: RECORD_ID + .. autodata:: MASS_DEFECT + .. autodata:: MOLECULAR_WEIGHT + .. autodata:: REFERENCE_COUNT + .. autodata:: DATASOURCE_COUNT + .. autodata:: PUBMED_COUNT + .. autodata:: RSC_COUNT + .. autodata:: ORDERS + .. autodata:: DIRECTIONS + .. autodata:: FIELDS + +.. automodule:: chemspipy.objects + :members: + +.. automodule:: chemspipy.search + :members: + +.. automodule:: chemspipy.errors + :members: diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..069ea6a --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,226 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. + +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import inspect +import os +import sys +sys.path.insert(0, os.path.abspath('..')) + + +# -- Project information ----------------------------------------------------- + +project = 'ChemSpiPy' +copyright = '2018, Matt Swain' +author = 'Matt Swain' + +# The short X.Y version +version = '' +# The full version, including alpha/beta/rc tags +release = '1.0.5' + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.linkcode', + 'm2r', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +source_suffix = ['.rst', '.md'] +# source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path . +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + + +# -- Options for HTML output ------------------------------------------------- + +# on_rtd is whether we are on readthedocs.org +on_rtd = os.environ.get('READTHEDOCS', None) == 'True' + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +# html_theme = 'alabaster' + +if not on_rtd: # only import and set the theme if we're building docs locally + import sphinx_rtd_theme + html_theme = 'sphinx_rtd_theme' + html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'ChemSpiPydoc' + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'ChemSpiPy.tex', 'ChemSpiPy Documentation', + 'Matt Swain', 'manual'), +] + + +# -- Options for manual page output ------------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'chemspipy', 'ChemSpiPy Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'ChemSpiPy', 'ChemSpiPy Documentation', + author, 'ChemSpiPy', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Extension configuration ------------------------------------------------- + +# -- Options for intersphinx extension --------------------------------------- + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'https://docs.python.org/': None} + +# Sort autodoc members by the order they appear in the source code +autodoc_member_order = 'bysource' + +# Concatenate the class and __init__ docstrings together +autoclass_content = 'both' + +m2r_anonymous_references = True + + +# Function courtesy of NumPy to return URLs containing line numbers +def linkcode_resolve(domain, info): + """Determine the URL corresponding to Python object.""" + if domain != 'py': + return None + + modname = info['module'] + fullname = info['fullname'] + + submod = sys.modules.get(modname) + if submod is None: + return None + + obj = submod + for part in fullname.split('.'): + try: + obj = getattr(obj, part) + except: + return None + + try: + fn = inspect.getsourcefile(obj) + except: + fn = None + if not fn: + return None + + try: + source, lineno = inspect.findsource(obj) + except: + lineno = None + + if lineno: + linespec = '#L{}'.format(lineno + 1) + else: + linespec = "" + + fn = os.path.relpath(fn, start=os.path.abspath('..')) + + return 'http://github.com/mcs07/ChemSpiPy/blob/master/{}{}'.format(fn, linespec) diff --git a/docs/source/guide/advanced.rst b/docs/guide/advanced.rst similarity index 91% rename from docs/source/guide/advanced.rst rename to docs/guide/advanced.rst index 176f4b0..86370d6 100644 --- a/docs/source/guide/advanced.rst +++ b/docs/guide/advanced.rst @@ -3,7 +3,7 @@ Advanced ======== -Keep your API key secret +Keep Your API Key Secret ------------------------ Be careful not to include your API key when sharing code. A simple way to ensure this doesn't happen by accident is to @@ -38,4 +38,4 @@ ChemSpiPy can generate logging statements if required. Just set the desired logg The logger is named 'chemspipy'. There is more information on logging in the `Python logging documentation`_. -.. _`Python logging documentation`: http://docs.python.org/2/howto/logging.html +.. _`Python logging documentation`: https://docs.python.org/3/howto/logging.html diff --git a/docs/guide/compound.rst b/docs/guide/compound.rst new file mode 100644 index 0000000..412c449 --- /dev/null +++ b/docs/guide/compound.rst @@ -0,0 +1,126 @@ +.. _compound: + +Compound +======== + +Many ChemSpiPy search methods return :class:`~chemspipy.objects.Compound` objects, which provide more functionality that +a simple list of ChemSpider IDs. The primary benefit is allowing easy access to further compound properties after +performing a search. + +Creating a Compound +------------------- + +The easiest way to create a :class:`~chemspipy.objects.Compound` for a given ChemSpider ID is to use the +:meth:`~chemspipy.api.ChemSpider.get_compound` method:: + + >>> compound = cs.get_compound(2157) + +Alternatively, a :class:`~chemspipy.objects.Compound` can be instantiated directly:: + + >>> compound = Compound(cs, 2157) + +Either way, no requests are made to the ChemSpider servers until specific :class:`~chemspipy.objects.Compound` +properties are requested:: + + >>> print(compound.molecular_formula) + C_{9}H_{8}O_{4} + >>> print(compound.molecular_weight) + 180.1574 + >>> print(compound.smiles) + CC(=O)Oc1ccccc1C(=O)O + >>> print(compound.common_name) + Aspirin + +Properties are cached locally after the first time they are retrieved, speeding up subsequent access and reducing the +number of unnecessary requests to the ChemSpider servers. + +External References +------------------- + +Get a list of all external references for a given compound using the +:attr:`~chemspipy.objects.Compound.external_references` property:: + + >>> refs = compound.external_references + >>> print(len(refs)) + 28181 + >>> print(refs[0]) + {'source': 'ChemBank', 'sourceUrl': 'http://chembank.broadinstitute.org/', 'externalId': 'DivK1c_000555', 'externalUrl': 'http://chembank.broad.harvard.edu/chemistry/viewMolecule.htm?cbid=1171'} + +Each reference is a dict with details for an external source. The list of references can be very large and slow to +retrieve for popular compounds, so it is possible to filter it by datasource. To do this, use the +:meth:`~chemspipy.api.ChemSpider.get_external_references` method directly:: + + >>> refs = cs.get_external_references(2157, datasources=['PubChem']) + >>> print(refs) + [{'source': 'PubChem', 'sourceUrl': 'http://pubchem.ncbi.nlm.nih.gov/', 'externalId': 2244, 'externalUrl': 'http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=2244'}] + +See the :ref:`Data Sources ` documentation for how to get a list of all available data sources. + +Searching for Compounds +----------------------- + +See the :ref:`searching documentation ` for full details. + +Implementation Details +---------------------- + +Each :class:`~chemspipy.objects.Compound` object is a simple wrapper around a ChemSpider ID. Behind the scenes, the +property methods use the :meth:`~chemspipy.api.ChemSpider.get_details`, :meth:`~chemspipy.api.ChemSpider.convert`, +:meth:`~chemspipy.api.ChemSpider.get_image`, and :meth:`~chemspipy.api.ChemSpider.get_external_references` API methods +to retrieve the relevant information. It is possible to use these API methods directly if required:: + + >>> info = cs.get_details(2157) + >>> print(info.keys()) + dict_keys(['id', 'smiles', 'formula', 'averageMass', 'molecularWeight', 'monoisotopicMass', 'nominalMass', 'commonName', 'referenceCount', 'dataSourceCount', 'pubMedCount', 'rscCount', 'mol2D', 'mol3D']) + >>> print(info['smiles']) + CC(=O)Oc1ccccc1C(=O)O + +Results are returned as a python dictionary that is derived directly from the ChemSpider API JSON response. + +Compound Properties +------------------- + +.. class:: chemspipy.objects.Compound + :noindex: + + .. autoattribute:: record_id + :noindex: + + .. autoattribute:: image_url + :noindex: + + .. autoattribute:: molecular_formula + :noindex: + + .. autoattribute:: inchi + :noindex: + + .. autoattribute:: inchikey + :noindex: + + .. autoattribute:: average_mass + :noindex: + + .. autoattribute:: molecular_weight + :noindex: + + .. autoattribute:: monoisotopic_mass + :noindex: + + .. autoattribute:: nominal_mass + :noindex: + + .. autoattribute:: common_name + :noindex: + + .. autoattribute:: mol_2d + :noindex: + + .. autoattribute:: mol_3d + :noindex: + + .. autoattribute:: image + :noindex: + + .. autoattribute:: external_references + :noindex: diff --git a/docs/source/guide/gettingstarted.rst b/docs/guide/gettingstarted.rst similarity index 82% rename from docs/source/guide/gettingstarted.rst rename to docs/guide/gettingstarted.rst index a3a8fe4..ef445e5 100644 --- a/docs/source/guide/gettingstarted.rst +++ b/docs/guide/gettingstarted.rst @@ -1,17 +1,17 @@ .. _gettingstarted: -Getting started +Getting Started =============== This page gives a introduction on how to get started with ChemSpiPy. -Before we start +Before We Start --------------- - Make sure you have :ref:`installed ChemSpiPy `. - :ref:`Obtain an API key ` from the ChemSpider web site. -First steps +First Steps ----------- Start by importing ChemSpider:: @@ -33,19 +33,19 @@ Let's get the Compound with `ChemSpider ID 2157`_:: >>> c = cs.get_compound(2157) -Now we have a :class:`~chemspipy.Compound` object called ``c``. We can get various identifiers and calculated +Now we have a :class:`~chemspipy.objects.Compound` object called ``c``. We can get various identifiers and calculated properties from this object:: >>> print(c.molecular_formula) C_{9}H_{8}O_{4} >>> print(c.molecular_weight) - 180.15742 + 180.1574 >>> print(c.smiles) - CC(=O)OC1=CC=CC=C1C(=O)O + CC(=O)Oc1ccccc1C(=O)O >>> print(c.common_name) Aspirin -Search for a name +Search for a Name ----------------- What if you don't know the ChemSpider ID of the Compound you want? Instead use the ``search`` method:: @@ -56,8 +56,14 @@ What if you don't know the ChemSpider ID of the Compound you want? Instead use t Compound(58238) Compound(71358) Compound(96749) + Compound(2006622) + Compound(5341883) + Compound(5360239) + Compound(9129332) + Compound(9281077) Compound(9312824) Compound(9484839) + Compound(9655623) The ``search`` method accepts any identifer that ChemSpider can interpret, including names, registry numbers, SMILES and InChI. diff --git a/docs/source/guide/install.rst b/docs/guide/install.rst similarity index 53% rename from docs/source/guide/install.rst rename to docs/guide/install.rst index 37509f3..a3fc2f9 100644 --- a/docs/source/guide/install.rst +++ b/docs/guide/install.rst @@ -3,14 +3,30 @@ Installation ============ -ChemSpiPy supports Python versions 2.7, 3.2, 3.3 and 3.4. +ChemSpiPy supports Python versions 2.7 and 3.5+. There are two required dependencies: `six`_ and `requests`_. -Option 1: Use pip (recommended) -------------------------------- +Option 1: Use conda (recommended) +--------------------------------- -The easiest and recommended way to install is using pip:: +The easiest and recommended way to install is using conda. `Anaconda Python`_ is a self-contained Python environment +that is particularly useful for scientific applications. If you don't already have it, start by installing `Miniconda`_, +which includes a complete Python distribution and the conda package manager. Choose the Python 3 version, unless you +have a particular reason why you must use Python 2. + +To install ChemSpiPy, at the command line, run:: + + conda config --add channels conda-forge + conda install chemspipy + +This will add the `conda-forge`_ channel to your conda config, then install ChemSpiPy and all its dependencies into your +conda environment. + +Option 2: Use pip +----------------- + +An alternative method is to install using pip:: pip install chemspipy @@ -19,10 +35,10 @@ available to all your python scripts. It should also ensure that the dependencie If you don't already have pip installed, you can `install it using get-pip.py`_:: - curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py -Option 2: Download the latest release +Option 3: Download the Latest Release ------------------------------------- Alternatively, `download the latest release`_ manually and install yourself:: @@ -34,7 +50,7 @@ Alternatively, `download the latest release`_ manually and install yourself:: The setup.py command will install ChemSpiPy in your `site-packages` folder so it is automatically available to all your python scripts. -Option 3: Clone the repository +Option 4: Clone the Repository ------------------------------ The latest development version of ChemSpiPy is always `available on GitHub`_. This version is not guaranteed to be @@ -46,6 +62,9 @@ stable, but may include new features that have not yet been released. Simply clo .. _`six`: http://pythonhosted.org/six/ .. _`requests`: http://docs.python-requests.org/ -.. _`install it using get-pip.py`: http://www.pip-installer.org/en/latest/installing.html +.. _`Anaconda Python`: https://www.anaconda.com/distribution/ +.. _`Miniconda`: https://conda.io/miniconda.html +.. _`conda-forge`: https://conda-forge.org/ +.. _`install it using get-pip.py`: https://pip.pypa.io/en/stable/installing/ .. _`download the latest release`: https://github.com/mcs07/ChemSpiPy/releases/ .. _`available on GitHub`: https://github.com/mcs07/ChemSpiPy diff --git a/docs/source/guide/intro.rst b/docs/guide/intro.rst similarity index 93% rename from docs/source/guide/intro.rst rename to docs/guide/intro.rst index a61a267..ac33647 100644 --- a/docs/source/guide/intro.rst +++ b/docs/guide/intro.rst @@ -12,7 +12,7 @@ documentation before getting started with ChemSpiPy to get an idea of what sort .. _apikey: -Obtaining an API key +Obtaining an API Key -------------------- The Royal Society of Chemistry web services are currently available as an Open Developer Preview. During the preview you @@ -20,11 +20,6 @@ can make 1000 calls per month. For an increased allowance, contact `api@rsc.org` All operations require an API key. To obtain one, `Register for a RSC Developers account`_ and then `Add a new key`_. -ChemSpiPy license ------------------ - -.. include:: ../../../LICENSE - .. _`ChemSpider website`: http://www.chemspider.com .. _`full documentation for the ChemSpider APIs`: https://developer.rsc.org/compounds-v1/apis .. _`api@rsc.org`: api@rsc.org diff --git a/docs/guide/misc.rst b/docs/guide/misc.rst new file mode 100644 index 0000000..9df0e80 --- /dev/null +++ b/docs/guide/misc.rst @@ -0,0 +1,33 @@ +.. _misc: + +Miscellaneous +============= + +.. _datasources: + +Data Sources +------------ + +Get a list of data sources in ChemSpider using the :meth:`~chemspipy.api.ChemSpider.get_datasources` method: + + >>> cs.get_datasources() + ['Abacipharm', 'Abblis Chemicals', 'Abcam', 'ABI Chemicals', 'Abmole Bioscience', 'ACB Blocks', 'Accela ChemBio', ... ] + +Format Conversion +----------------- + +Convert between different molecular representations using the :meth:`~chemspipy.api.ChemSpider.convert` method:: + + >>> cs.convert('c1ccccc1', 'SMILES', 'InChI') + 'InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H' + +Allowed conversions: + +- From ``InChI`` to ``InChIKey`` +- From ``InChI`` to ``Mol`` +- From ``InChI`` to ``SMILES`` +- From ``InChIKey`` to ``InChI`` +- From ``InChIKey`` to ``Mol`` +- From ``Mol`` to ``InChI`` +- From ``Mol`` to ``InChIKey`` +- From ``SMILES`` to ``InChI`` diff --git a/docs/source/guide/searching.rst b/docs/guide/searching.rst similarity index 57% rename from docs/source/guide/searching.rst rename to docs/guide/searching.rst index e9923d2..dcbbd28 100644 --- a/docs/source/guide/searching.rst +++ b/docs/guide/searching.rst @@ -5,7 +5,7 @@ Searching ChemSpiPy provides a number of different ways to search ChemSpider. -Compound search +Compound Search --------------- The main ChemSpiPy search method functions in a similar way to the main search box on the ChemSpider website. Just @@ -14,91 +14,85 @@ provide any type of query, and ChemSpider will interpret it and provide the most >>> cs.search('O=C(OCC)C') Results([Compound(8525)]) >>> cs.search('glucose') - Results([Compound(5589), Compound(58238), Compound(71358), Compound(96749), Compound(9312824), Compound(9484839)]) + Results([Compound(5589), Compound(58238), Compound(71358), Compound(96749), Compound(2006622), Compound(5341883), Compound(5360239), Compound(9129332), Compound(9281077), Compound(9312824), Compound(9484839), Compound(9655623)]) >>> cs.search('2157') Results([Compound(2157)]) The supported query types include systematic names, synonyms, trade names, registry numbers, molecular formula, SMILES, InChI and InChIKey. -The :class:`~chemspipy.Results` object that is returned can be treated just like any regular python list. For example, -you can iterate over the results:: +The :class:`~chemspipy.search.Results` object that is returned can be treated just like any regular python list. For +example, you can iterate over the results:: >>> for result in cs.search('Glucose'): - ... print(result.csid) + ... print(result.record_id) 5589 58238 71358 96749 + 2006622 + 5341883 + 5360239 + 9129332 + 9281077 9312824 9484839 + 9655623 -The :class:`~chemspipy.Results` object also provides the time take to perform the search, and a message that explains -how the query type was resolved:: +The :class:`~chemspipy.search.Results` object also provides the time taken to perform the search, and a message that +explains how the query type was resolved:: >>> r = cs.search('Glucose') >>> print(r.duration) - u'0:00:00.017' + 0:00:00.513406 >>> print(r.message) - u'Found by approved synonym' + Found by approved synonym -Asynchronous searching +Asynchronous Searching ---------------------- Certain types of search can sometimes take slightly longer, which can be inconvenient if the search method blocks the Python interpreter until the search results are returned. Fortunately, the ChemSpiPy search method works asynchronously. -Once a search is executed, ChemSpiPy immediately returns the :class:`~chemspipy.Results` object, which is actually -empty at first:: +Once a search is executed, ChemSpiPy immediately returns the :class:`~chemspipy.search.Results` object, which is +actually empty at first:: >>> results = cs.search('O=C(OCC)C') >>> print(results.ready()) False In a background thread, ChemSpiPy is making the search request and waiting for the response. But in the meantime, it is -possible to continue performing other tasks in the main Python interpreter process. Call ``ready()`` at any -point to check if the results have been returned and are available. +possible to continue performing other tasks in the main Python interpreter process. Call +:meth:`~chemspipy.search.Results.ready()` at any point to check if the results have been returned and are available. Any attempt to access the results will just block until the results are ready, like a simple synchronous search. To -manually block the main thread until the results are ready, use the ``wait()`` method:: +manually block the main thread until the results are ready, use the :meth:`~chemspipy.search.Results.wait()` method:: >>> results.wait() >>> results.ready() True -For more detailed information about the status of a search, use the ``status`` property:: +For more detailed information about the status of a search, use the :attr:`~chemspipy.search.Results.status` property:: >>> results.status - u'Created' + 'Created' >>> results.wait() >>> results.status - u'ResultReady' + 'Complete' -The possible statuses are ``Unknown``, ``Created``, ``Scheduled``, ``Processing``, ``Suspended``, -``PartialResultReady``, ``ResultReady``. +The possible statuses are ``Created``, ``Failed``, ``Unknown``, ``Suspended``, ``Complete``. -Simple search -------------- - -The asynchronous search is designed to be simple as possible, but it's possible that the additional overhead might be -overkill in some cases. The ``simple_search`` method provides a simpler synchronous alternative. Use it in the same way:: - - >>> cs.simple_search('Glucose') - [Compound(5589), Compound(58238), Compound(71358), Compound(96749), Compound(9312824), Compound(9484839)] - -In this case, the main Python thread will be blocked until the search results are returned, and the results actually are -just in a regular Python list. A maximum of 100 results are returned. - -Search by formula +Search by Formula ----------------- -Searching by molecular formula is supported by the main ``search`` method, but there is the possibility that a formula -could be interpreted as a name or SMILES or another query type. To specifically search by formula, use:: +Searching by molecular formula is supported by the main :meth:`~chemspipy.api.ChemSpider.search()` method, but there is +the possibility that a formula could be interpreted as a name or SMILES or another query type. To specifically search +by formula, use:: >>> cs.search_by_formula('C44H30N4Zn') [Compound(436642), Compound(3232330), Compound(24746832), Compound(26995124)] -Search by mass +Search by Mass -------------- It is also possible to search ChemSpider by mass by specifying a certain range:: diff --git a/docs/source/index.rst b/docs/index.rst similarity index 63% rename from docs/source/index.rst rename to docs/index.rst index b6d548b..fb18615 100644 --- a/docs/source/index.rst +++ b/docs/index.rst @@ -1,4 +1,4 @@ -.. ChemSpiPy documentation master file, created by sphinx-quickstart on Mon Sep 15 10:51:47 2014. +.. ChemSpiPy documentation master file ChemSpiPy ========= @@ -22,9 +22,9 @@ Features - Download compound records as a MOL file with 2D or 3D coordinates. - Get a 2D compound depiction as a PNG image. - Complete interface to every endpoint of the ChemSpider Web APIs. -- Supports Python versions 2.7 – 3.4. +- Supports Python versions 2.7 and 3.5+. -User guide +User Guide ---------- A step-by-step guide to getting started with ChemSpiPy. @@ -39,9 +39,8 @@ A step-by-step guide to getting started with ChemSpiPy. guide/searching guide/misc guide/advanced - guide/contributing -API documentation +API Documentation ----------------- Comprehensive API documentation with information on every function, class and method. @@ -50,3 +49,29 @@ Comprehensive API documentation with information on every function, class and me :maxdepth: 2 api + +Additional Notes +---------------- + +.. toctree:: + :maxdepth: 2 + + notes/license + notes/contributing + notes/migrating + notes/changelog + +Useful links +------------ + +- `ChemSpiPy on GitHub`_ +- `ChemSpiPy on PyPI`_ +- `Issue tracker`_ +- `Release history`_ +- `ChemSpiPy Travis CI`_ + +.. _`ChemSpiPy on GitHub`: https://github.com/mcs07/ChemSpiPy +.. _`ChemSpiPy on PyPI`: https://pypi.python.org/pypi/ChemSpiPy +.. _`Issue tracker`: https://github.com/mcs07/ChemSpiPy/issues +.. _`Release history`: https://github.com/mcs07/ChemSpiPy/releases +.. _`ChemSpiPy Travis CI`: https://travis-ci.org/mcs07/ChemSpiPy diff --git a/docs/notes/changelog.rst b/docs/notes/changelog.rst new file mode 100644 index 0000000..fd82037 --- /dev/null +++ b/docs/notes/changelog.rst @@ -0,0 +1,3 @@ +.. _changelog: + +.. mdinclude:: ../../CHANGELOG.md diff --git a/docs/notes/contributing.rst b/docs/notes/contributing.rst new file mode 100644 index 0000000..2b6578f --- /dev/null +++ b/docs/notes/contributing.rst @@ -0,0 +1,3 @@ +.. _contributing: + +.. include:: ../../CONTRIBUTING.rst diff --git a/docs/notes/license.rst b/docs/notes/license.rst new file mode 100644 index 0000000..24b76c5 --- /dev/null +++ b/docs/notes/license.rst @@ -0,0 +1,18 @@ +.. _license: + +License +======= + +Authors +------- + +ChemSpiPy is developed and maintained by Matt Swain and community contributors. + +See a full list of contributors on the `GitHub Contributors page`_. + +ChemSpiPy License +----------------- + +.. include:: ../../LICENSE + +.. _`GitHub Contributors page`: https://github.com/mcs07/ChemSpiPy/graphs/contributors diff --git a/docs/notes/migrating.rst b/docs/notes/migrating.rst new file mode 100644 index 0000000..1360bf8 --- /dev/null +++ b/docs/notes/migrating.rst @@ -0,0 +1,68 @@ +.. _migrating: + +Migration Guide +=============== + +Upgrading to version 2.x +------------------------ + +The RSC released an entirely new REST API in 2018, necessitating a number of changes to ChemSpiPy. Where possible, +backwards compatibility has been maintained, but many methods are deprecated and some have been removed entirely. + +ChemSpider Object +~~~~~~~~~~~~~~~~~ + +- Instantiate the :class:`~chemspipy.api.ChemSpider` with a required ``api_key`` parameter instead of the optional + ``security_token`` parameter. + +- Deprecated methods: + + - ``get_databases`` → :meth:`~chemspipy.api.ChemSpider.get_datasources` + - ``get_extended_compound_info`` → :meth:`~chemspipy.api.ChemSpider.get_details` + - ``get_extended_compound_info_list`` → :meth:`~chemspipy.api.ChemSpider.get_details_batch` + - ``get_extended_mol_compound_info_list`` → :meth:`~chemspipy.api.ChemSpider.get_details_batch` + - ``get_record_mol`` → :meth:`~chemspipy.api.ChemSpider.get_mol` + - ``async_simple_search`` → :meth:`~chemspipy.api.ChemSpider.filter_name` + - ``async_simple_search_ordered`` → :meth:`~chemspipy.api.ChemSpider.filter_name` + - ``get_async_search_status`` → :meth:`~chemspipy.api.ChemSpider.filter_status` + - ``get_async_search_status_and_count`` → :meth:`~chemspipy.api.ChemSpider.filter_status` + - ``get_async_search_result`` → :meth:`~chemspipy.api.ChemSpider.filter_results` + - ``get_async_search_result_part`` → :meth:`~chemspipy.api.ChemSpider.filter_results` + - ``get_compound_info`` → :meth:`~chemspipy.api.ChemSpider.get_details` + - ``get_compound_thumbnail`` → :meth:`~chemspipy.api.ChemSpider.get_image` + - ``simple_search`` → :meth:`~chemspipy.api.ChemSpider.search` + +- Removed methods: + + - ``get_original_mol`` + - ``get_all_spectra_info`` + - ``get_spectrum_info`` + - ``get_compound_spectra_info`` + - ``get_spectra_info_list`` + +Compound Object +~~~~~~~~~~~~~~~ + +- Non-standard InChI and InChIKey are no longer available. All are now 'standard'. Deprecated properties: + + - ``stdinchi`` → :attr:`~chemspipy.objects.Compound.inchi` + - ``stdinchikey`` → :attr:`~chemspipy.objects.Compound.inchikey` + +- Removed properties: + + - ``xlogp`` + - ``alogp`` + - ``mol_3d`` + - ``mol_raw`` + +Spectrum Object +~~~~~~~~~~~~~~~ + +- ``Spectrum`` object has been removed entirely. + +:mod:`~chemspipy.api` Module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- Removed ``DIMENSIONS`` mapping. +- Replaced :attr:`~chemspipy.api.FIELDS` mapping with a list of available properties fields. +- Removed ``xml_to_dict`` function. diff --git a/docs/source/api.rst b/docs/source/api.rst deleted file mode 100644 index bfccda0..0000000 --- a/docs/source/api.rst +++ /dev/null @@ -1,64 +0,0 @@ -.. _api: - -API documentation -================= - -.. sectionauthor:: Matt Swain - -.. module:: chemspipy - -This part of the documentation is automatically generated from the ChemSpiPy source code and comments. - -.. automodule:: chemspipy.api -.. autoclass:: chemspipy.ChemSpider() - - .. automethod:: get_compound(csid) - .. automethod:: get_compounds(csids) - .. automethod:: search(query, order=None, direction=ASCENDING, raise_errors=False) - .. automethod:: simple_search(query) - .. automethod:: get_record_mol(csid, calc3d=False) - .. automethod:: get_compound_thumbnail(csid) - .. automethod:: get_databases() - .. automethod:: get_compound_info(csid) - .. automethod:: get_extended_compound_info(csid) - .. automethod:: get_extended_compound_info_list(csids) - .. automethod:: get_extended_mol_compound_info_list(csids, mol_type=MOL2D, include_reference_counts=False, include_external_references=False) - .. automethod:: request(api, endpoint, **params) - .. automethod:: construct_api_url(api, endpoint, **params) - .. automethod:: async_simple_search(query) - .. automethod:: async_simple_search_ordered(query, order=CSID, direction=ASCENDING) - .. automethod:: get_async_search_status(rid) - .. automethod:: get_async_search_status_and_count(rid) - .. automethod:: get_async_search_result(rid) - .. automethod:: get_async_search_result_part(rid, start=0, count=-1) - .. automethod:: simple_search_by_formula(formula) - .. automethod:: simple_search_by_mass(mass, mass_range) - -.. autodata:: chemspipy.api.MOL2D -.. autodata:: chemspipy.api.MOL3D -.. autodata:: chemspipy.api.BOTH -.. autodata:: chemspipy.api.ASCENDING -.. autodata:: chemspipy.api.DESCENDING -.. autodata:: chemspipy.api.CSID -.. autodata:: chemspipy.api.MASS_DEFECT -.. autodata:: chemspipy.api.MOLECULAR_WEIGHT -.. autodata:: chemspipy.api.REFERENCE_COUNT -.. autodata:: chemspipy.api.DATASOURCE_COUNT -.. autodata:: chemspipy.api.PUBMED_COUNT -.. autodata:: chemspipy.api.RSC_COUNT - -.. automodule:: chemspipy.objects -.. autoclass:: chemspipy.Compound() - :members: - -.. automodule:: chemspipy.search -.. autoclass:: chemspipy.Results() - :members: - -.. automodule:: chemspipy.errors -.. autoexception:: chemspipy.errors.ChemSpiPyError() -.. autoexception:: chemspipy.errors.ChemSpiPyParseError() -.. autoexception:: chemspipy.errors.ChemSpiPyAuthError() -.. autoexception:: chemspipy.errors.ChemSpiPyNotFoundError() -.. autoexception:: chemspipy.errors.ChemSpiPyTimeoutError() -.. autoexception:: chemspipy.errors.ChemSpiPyServerError() diff --git a/docs/source/conf.py b/docs/source/conf.py deleted file mode 100644 index e885122..0000000 --- a/docs/source/conf.py +++ /dev/null @@ -1,246 +0,0 @@ -# -*- coding: utf-8 -*- -# -# ChemSpiPy documentation build configuration file, created by sphinx-quickstart on Mon Sep 15 10:51:47 2014. -# This file is execfile()d with the current directory set to its containing dir. -# Note that not all possible configuration values are present in this autogenerated file. -# All configuration values have a default; values that are commented out serve to show the default. - -import sys -import os - -# on_rtd is whether we are on readthedocs.org -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' - -# If extensions (or modules to document with autodoc) are in another directory, add these directories to sys.path here. -# If the directory is relative to the documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('../..')) - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be extensions coming with Sphinx -# (named 'sphinx.ext.*') or your custom ones. -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.ifconfig', - 'sphinx.ext.viewcode', -] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix of source filenames. -source_suffix = '.rst' - -# The encoding of source files. -#source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = u'ChemSpiPy' -copyright = u'2018, Matt Swain' - -# The version info for the project you're documenting, acts as replacement for |version| and |release|, also used in -# various other places throughout the built documents. -# The short X.Y version. -version = '1.0.5' -# The full version, including alpha/beta/rc tags. -release = '1.0.5' - -# The language for content autogenerated by Sphinx. Refer to documentation for a list of supported languages. -#language = None - -# There are two options for replacing |today|: either, you set today to some non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and directories to ignore when looking for source -# files. -exclude_patterns = [] - -# The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True - -# If true, the current module name will be prepended to all description unit titles (such as .. function::). -#add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the output. They are ignored by default. -#show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for a list of builtin themes. -if not on_rtd: # only import and set the theme if we're building docs locally - import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] - -#html_theme = 'default' - -# Theme options are theme-specific and customize the look and feel of a theme further. For a list of options available -# for each theme, see the documentation. -#html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to " v documentation". -#html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None - -# The name of an image file (relative to this directory) to place at the top of the sidebar. -#html_logo = None - -# The name of an image file (within the static path) to use as favicon of the docs. This file should be a Windows icon -# file (.ico) being 16x16 or 32x32 pixels large. -#html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, relative to this directory. They are -# copied after the builtin static files, so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] - -# Add any extra paths that contain custom files (such as robots.txt or .htaccess) here, relative to this directory. -# These files are copied directly to the root of the documentation. -#html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to typographically correct entities. -#html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -#html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to template names. -#html_additional_pages = {} - -# If false, no module index is generated. -#html_domain_indices = True - -# If false, no index is generated. -#html_use_index = True - -# If true, the index is split into individual pages for each letter. -#html_split_index = False - -# If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will contain a tag referring to it. The -# value of this option must be the base URL from which the finished HTML is served. -#html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None - -# Output file base name for HTML help builder. -htmlhelp_basename = 'ChemSpiPydoc' - - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -'papersize': 'a4paper', - -# The font size ('10pt', '11pt' or '12pt'). -'pointsize': '12pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto, manual, or own class]). -latex_documents = [ - ('index', 'ChemSpiPy.tex', u'ChemSpiPy Documentation', u'Matt Swain', 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of the title page. -#latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, not chapters. -latex_use_parts = False - -# If true, show page references after internal links. -latex_show_pagerefs = True - -# If true, show URL addresses after external links. -latex_show_urls = True - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] - -# If false, no module index is generated. -latex_domain_indices = False - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'chemspipy', u'ChemSpiPy Documentation', [u'Matt Swain'], 1) -] - -# If true, show URL addresses after external links. -#man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, dir menu entry, description, category) -texinfo_documents = [ - ('index', 'ChemSpiPy', u'ChemSpiPy Documentation', u'Matt Swain', 'ChemSpiPy', 'One line description of project.', - 'Miscellaneous'), -] - -# Documents to append as an appendix to all manuals. -#texinfo_appendices = [] - -# If false, no module index is generated. -#texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'http://docs.python.org/': None} - -# Sort autodoc members by the order they appear in the source code -autodoc_member_order = 'bysource' - -# Concatenate the class and __init__ docstrings together -autoclass_content = 'both' diff --git a/docs/source/guide/compound.rst b/docs/source/guide/compound.rst deleted file mode 100644 index 7c17c4a..0000000 --- a/docs/source/guide/compound.rst +++ /dev/null @@ -1,76 +0,0 @@ -.. _compound: - -Compound -======== - -Many ChemSpiPy search methods return :class:`~chemspipy.Compound` objects, which provide more functionality that a -simple list of ChemSpider IDs. The primary benefit is allowing easy access to further compound properties after -performing a search. - -Creating a Compound -------------------- - -The easiest way to create a :class:`~chemspipy.Compound` for a given ChemSpider ID is to use the ``get_compound`` -method:: - - >>> compound = cs.get_compound(2157) - -Alternatively, a :class:`~chemspipy.Compound` can be instantiated directly:: - - >>> compound = Compound(cs, 2157) - -Either way, no requests are made to the ChemSpider servers until specific :class:`~chemspipy.Compound` properties are -requested:: - - >>> print(compound.molecular_formula) - C_{9}H_{8}O_{4} - >>> print(compound.molecular_weight) - 180.15742 - >>> print(compound.smiles) - CC(=O)OC1=CC=CC=C1C(=O)O - >>> print(compound.common_name) - Aspirin - -Properties are cached locally after the first time they are retrieved, speeding up subsequent access and reducing the -number of unnecessary requests to the ChemSpider servers. - -Searching for Compounds ------------------------ - -See the :ref:`searching documentation ` for full details. - -Compound properties -------------------- - -- ``csid``: ChemSpider ID. -- ``image_url``: URL of a PNG image of the 2D chemical structure. -- ``molecular_formula``: Molecular formula. -- ``smiles``: SMILES string. -- ``stdinchi``: Standard InChI string. -- ``stdinchikey``: Standard InChIKey. -- ``inchi``: InChI string. -- ``inchikey``: InChIKey. -- ``average_mass``: Average mass. -- ``molecular_weight``: Molecular weight. -- ``monoisotopic_mass``: Monoisotopic mass. -- ``nominal_mass``: Nominal mass. -- ``alogp``: AlogP. -- ``xlogp``: XlogP. -- ``common_name``: Common Name. -- ``mol_2d``: MOL file containing 2D coordinates. -- ``mol_3d``: MOL file containing 3D coordinates. -- ``mol_raw``: Unprocessed MOL file. -- ``image``: 2D depiction as binary data in PNG format. - -Implementation details ----------------------- - -Each :class:`~chemspipy.Compound` object is a simple wrapper around a ChemSpider ID. Behind the scenes, the property -methods use the ``get_compound_info``, ``get_extended_compound_info``, ``get_record_mol`` and -``get_compound_thumbnail`` API methods to retrieve the relevant information. It is possible to use these API methods -directly if required:: - - >>> info = cs.get_extended_compound_info(2157) - {u'smiles': u'CC(=O)Oc1ccccc1C(=O)O', u'common_name': u'Aspirin', u'nominal_mass': 180.0, u'molecular_formula': u'C_{9}H_{8}O_{4}', u'inchikey': u'BSYNRYMUTXBXSQ-UHFFFAOYAW', u'molecular_weight': 180.1574, u'inchi': u'InChI=1/C9H8O4/c1-6(10)13-8-5-3-2-4-7(8)9(11)12/h2-5H,1H3,(H,11,12)', u'average_mass': 180.1574, u'csid': 2157, u'alogp': 0.0, u'xlogp': 0.0, u'monoisotopic_mass': 180.042252} - -Results are returned as a python dictionary that is derived directly from the ChemSpider API XML response. diff --git a/docs/source/guide/contributing.rst b/docs/source/guide/contributing.rst deleted file mode 100644 index 544fcf3..0000000 --- a/docs/source/guide/contributing.rst +++ /dev/null @@ -1,3 +0,0 @@ -.. _contributing: - -.. include:: ../../../CONTRIBUTING.rst diff --git a/docs/source/guide/misc.rst b/docs/source/guide/misc.rst deleted file mode 100644 index b946bb6..0000000 --- a/docs/source/guide/misc.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. _misc: - -Miscellaneous -============= - -Data sources ------------- - -Get a list of data sources in ChemSpider:: - - >>> cs.get_datasources() - ['Abacipharm', 'Abblis Chemicals', 'Abcam', 'ABI Chemicals', 'Abmole Bioscience', 'ACB Blocks', 'Accela ChemBio', ... ] diff --git a/environment.yml b/environment.yml index 41f6b9e..daccb12 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,14 @@ name: chemspipy channels: -- mcs07 -- defaults + - conda-forge + - defaults dependencies: -- requests=2.13.0 -- six=1.10.0 + - bumpversion=0.5.3 + - coverage=4.5.1 + - coveralls=1.3.0 + - requests=2.19.1 + - pytest=3.6.2 + - six=1.11.0 + - sphinx=1.7.5 + - sphinx_rtd_theme=0.4.1 + diff --git a/requirements/common.txt b/requirements/common.txt deleted file mode 100644 index 2bf2942..0000000 --- a/requirements/common.txt +++ /dev/null @@ -1,2 +0,0 @@ -requests==2.5.0 -six==1.8.0 diff --git a/requirements/dev.txt b/requirements/dev.txt deleted file mode 100644 index 2effced..0000000 --- a/requirements/dev.txt +++ /dev/null @@ -1,7 +0,0 @@ --r common.txt -bumpversion==0.5.0 -coverage==3.7.1 -coveralls==0.4.4 -pytest==3.0.7 -Sphinx==1.2.3 -sphinx-rtd-theme==0.1.6 diff --git a/setup.py b/setup.py index 046d179..8cedc24 100644 --- a/setup.py +++ b/setup.py @@ -32,11 +32,7 @@ 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.2', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Bio-Informatics', 'Topic :: Scientific/Engineering :: Chemistry',