API documentation¶
This part of the documentation is automatically generated from the PubChemPy source code and comments.
Search functions¶
- pubchempy.get_compounds(identifier, namespace=u'cid', searchtype=None, as_dataframe=False, **kwargs)¶
Retrieve the specified compound records from PubChem.
Parameters: - identifier – The compound identifier to use as a search query.
- namespace – (optional) The identifier type, one of cid, name, smiles, sdf, inchi, inchikey or formula.
- searchtype – (optional) The advanced search type, one of substructure, superstructure or similarity.
- as_dataframe – (optional) Automatically extract the Compound properties into a pandas DataFrame and return that.
- pubchempy.get_substances(identifier, namespace=u'sid', as_dataframe=False, **kwargs)¶
Retrieve the specified substance records from PubChem.
Parameters:
- pubchempy.get_assays(identifier, namespace=u'aid', **kwargs)¶
Retrieve the specified assay records from PubChem.
Parameters: - identifier – The assay identifier to use as a search query.
- namespace – (optional) The identifier type.
- pubchempy.get_properties(properties, identifier, namespace=u'cid', searchtype=None, as_dataframe=False, **kwargs)¶
Compound, Substance and Assay¶
- class pubchempy.Compound(record)¶
Corresponds to a single record from the PubChem Compound database.
The PubChem Compound database is constructed from the Substance database using a standardization and deduplication process.
Each Compound is uniquely identified by a CID.
- classmethod from_cid(cid, **kwargs)¶
Retrieve the Compound record for the specified CID.
Parameters: cid – The PubChem Compound Identifier (CID).
- to_dict(properties=None)¶
Return a dictionary containing Compound data. Optionally specify a list of the desired properties.
synonyms, aids and sids are not included unless explicitly specified using the properties parameter. This is because they each require an extra request.
- to_series(properties=None)¶
Return a pandas Series containing Compound data. Optionally specify a list of the desired properties.
synonyms, aids and sids are not included unless explicitly specified using the properties parameter. This is because they each require an extra request.
- cid¶
The PubChem Compound Identifier (CID).
Note
When searching using a SMILES or InChI query that is not present in the PubChem Compound database, an automatically generated record may be returned that contains properties that have been calculated on the fly. These records will not have a CID property.
- synonyms¶
A ranked list of all the names associated with this Compound.
Requires an extra request. Result is cached.
- sids¶
Requires an extra request. Result is cached.
- aids¶
Requires an extra request. Result is cached.
- class pubchempy.Substance(record)¶
Corresponds to a single record from the PubChem Substance database.
The PubChem Substance database contains all chemical records deposited in PubChem in their most raw form, before any significant processing is applied. As a result, it contains duplicates, mixtures, and some records that don’t make chemical sense. This means that Substance records contain fewer calculated properties, however they do have additional information about the original source that deposited the record.
The PubChem Compound database is constructed from the Substance database using a standardization and deduplication process. Hence each Compound may be derived from a number of different Substances.
- classmethod from_sid(sid)¶
Retrieve the Substance record for the specified SID.
Parameters: sid – The PubChem Substance Identifier (SID).
- record = None¶
A dictionary containing the full Substance record that all other properties are obtained from.
- to_dict(properties=None)¶
Return a dictionary containing Substance data.
If the properties parameter is not specified, everything except cids and aids is included. This is because the aids and cids properties each require an extra request to retrieve.
Parameters: properties – (optional) A list of the desired properties.
- to_series(properties=None)¶
Return a pandas Series containing Substance data.
If the properties parameter is not specified, everything except cids and aids is included. This is because the aids and cids properties each require an extra request to retrieve.
Parameters: properties – (optional) A list of the desired properties.
- sid¶
The PubChem Substance Idenfitier (SID).
- synonyms¶
A ranked list of all the names associated with this Substance.
- source_name¶
The name of the PubChem depositor that was the source of this Substance.
- source_id¶
The ID of the PubChem depositor that was the source of this Substance.
- standardized_cid¶
The CID of the Compound that was produced when this Substance was standardized.
May not exist if this Substance was not standardizable.
- standardized_compound¶
Return the Compound that was produced when this Substance was standardized.
Requires an extra request. Result is cached.
- deposited_compound¶
Return a Compound produced from the unstandardized Substance record as deposited.
The resulting Compound will not have a cid and will be missing most properties.
- cids¶
A list of all CIDs for Compounds that were produced when this Substance was standardized.
Requires an extra request. Result is cached.
- aids¶
A list of all AIDs for Assays associated with this Substance.
Requires an extra request. Result is cached.
pandas functions¶
Each of the search functions, get_compounds(), get_substances() and get_properties() has an as_dataframe parameter. When set to True, these functions automatically extract properties from each result in the list into a pandas DataFrame and return that instead of the results themselves.
If you already have a list of Compounds or Substances, the functions below allow a DataFrame to be constructed easily.
Exceptions¶
- exception pubchempy.PubChemHTTPError¶
Generic error class to handle all HTTP error codes.
- exception pubchempy.BadRequestError¶
Request is improperly formed (syntax error in the URL, POST body, etc.).
- exception pubchempy.NotFoundError¶
The input record was not found (e.g. invalid CID).
- exception pubchempy.MethodNotAllowedError¶
Request not allowed (such as invalid MIME type in the HTTP Accept header).
- exception pubchempy.TimeoutError¶
The request timed out, from server overload or too broad a request.
See Avoiding TimeoutError for more information.
- exception pubchempy.UnimplementedError¶
The requested operation has not (yet) been implemented by the server.
- exception pubchempy.ServerError¶
Some problem on the server side (such as a database server down, etc.).
Changes¶
- As of v1.0.2, search functions now return an empty list instead of raising a NotFoundError exception when no results are found. NotFoundError is still raised when attempting to create a Compound using Compound.from_cid with an invalid CID.