Skip to main content

pubchem tools

is a small packet to query the pubchem APIs. For simple and easy access, one can use the pubchempy library. It is not as nice as pubchempy neither so complete, but works well for things like finding CAS numbers, safety codes, and anything one knows in the record. Key point: it works with pulling the record, not querying it every time one asks a question.

pubchem has two interfaces

Actually the PUG-RES API is available two ways:

and they provide slightly different facilities. Using the former, one can get simple answer to things like: what is the CID (or pubchem ID) of compound 'a'? The latter fetches the full record in a hierarchic JSON object.

using only pug

Trying the various output methods did not provide a response as rich as the pug_view did. Thus, the double call is important at the moment.

Handling the JSON hierarchy

One thing to do is to pick out the internal lists of dicts to some objects, e.g. turning them to dicts. Then a crawler across the dict structure can discover information we need. We use the dictDigUtils, a c.a. 5 kB set of functions help digging the hierarchy returned by the json python library.

Lists are:

  • Section
  • Value
  • StringWithMarkup
  • Number
  • Boolean

Funcitons like clean_section help managing this.

A Pubchem class is formed which has simple get_value calls to provide parameters, such as molecular_weight, molecular_formula, etc.

full record

is available as the _record_ private variable. Some parts are simplified during the processing to remove formating instructions, not needed here. You can always use:

a = Pubchem('your molecule')
get_value('Molecular Weight', a._record_)

to query into the record. dictDigUtils can provide you dict_list_keys to discover possible keys within.

names and synonyms

The PUG-RES API will recognize any names what is listed in the synonym list, thus one needs no other trics to find the material. However, foreign names may be encoded e.g. the German ä as ae. Now the list of synonyms is available as the synonyms element of the class.

InChi

There are two fields coming from Pubchem:

  • InChI key
  • InChI, which is indicated with InChi= in the text

density

The data set may contain several versions of this, and unfortunately it is not really uniform across the chemicals. There are:

  • a number
  • a number and unit
  • < a value
  • reference to a table image
  • a text describing value ranges and conditions So, for now, the function just returns the list it finds.

A bit more generic solution is to allow a filter in the general searc. This is now the get_value_filtered() function, which handles the density and the CAS numbers. For density, use a cut for vapor values. Others did not work, because they were listed under the same key.

1.0.9: bugfix a typo in pubchem.

Release files for pubchemTool 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pubchemTool 1.0.9
File Size Uploaded
pubchemTool-1.0.9.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pubchemTool 1.0.9
File Interpreter ABI Platform
pubchemTool-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 14.3 kB

Release files / pubchemTool-1.0.9.tar.gz

Download URL pubchemTool-1.0.9.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6df341efcbf6e44054350ee66993da5ff5b082e34891c0611ed702e78139542d
BLAKE2b-256 checksum
How to use checksums
d78784448180e71b3e348df43d08b3474e8c197593ca8e1ac29b9c9035465519
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / pubchemTool-1.0.9-py3-none-any.whl

Download URL pubchemTool-1.0.9-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02ab41ef2710ba0654d888297a06a65dd3c97479f49b4173e5b4e4179fd380fc
BLAKE2b-256 checksum
How to use checksums
8bab9e1efdd329b1542d898a3512aebb99f76ac10cdedf594e2a4f586b75b2ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page