chemistry_tools.pubchem.synonyms

Attention

This package has the following additional requirements:

cawdrey>=0.1.7
mathematical>=0.1.13
pillow>=7.0.0
pyparsing>=2.4.6
tabulate>=0.8.9

These can be installed as follows:

python -m pip install chemistry-tools[pubchem]

Functions for obtaining the synonyms of a compound from the PubChem database.

Classes:

Synonyms(initlist)

Contains a list of synonyms for a compound.

Functions:

get_synonyms(identifier[, namespace])

Returns a list of synonyms for the compound with the given identifier.

rest_get_synonyms(identifier[, namespace])

Get the list of synonyms for the given compound.

class Synonyms(initlist)[source]

Bases: List[str]

Contains a list of synonyms for a compound.

Parameters

initlist – The content to initialise the list with.

Methods:

__contains__(synonym)

Return synonym in self.

append(synonym)

Append synonym to the end of the list.

__contains__(synonym)[source]

Return synonym in self.

The comparison treats hyphens and underscores as whitespace.

Parameters

synonym

Return type

bool

append(synonym)[source]

Append synonym to the end of the list.

Parameters

synonym (str)

get_synonyms(identifier, namespace=<PubChemNamespace.Name: 'name'>)[source]

Returns a list of synonyms for the compound with the given identifier. As more than one compound may be identified the results are returned in a list.

Parameters
  • identifier (Union[str, int, Sequence[Union[str, int]]]) – Identifiers (e.g. name, CID) for the compound to look up. When using the CID namespace data for multiple compounds can be retrieved at once by supplying either a comma-separated string or a list.

  • namespace (Union[PubChemNamespace, str]) – The type of identifier to look up. Valid values are in PubChemNamespace. Default <PubChemNamespace.Name: 'name'>.

Return type

List[Dict]

Returns

List of dictionaries containing the CID and a list of synonyms for the compounds.

rest_get_synonyms(identifier, namespace=<PubChemNamespace.Name: 'name'>, **kwargs)[source]

Get the list of synonyms for the given compound.

Parameters
  • identifier (Union[str, int, Sequence[Union[str, int]]]) – Identifiers (e.g. name, CID) for the compound to look up. When using the CID namespace data for multiple compounds can be retrieved at once by supplying either a comma-separated string or a list.

  • namespace (Union[PubChemNamespace, str]) – The type of identifier to look up. Valid values are in PubChemNamespace. Default <PubChemNamespace.Name: 'name'>.

  • kwargs – Optional arguments that json.loads takes.

Raises

ValueError – If the response body does not contain valid JSON.

Return type

Dict

Returns

Parsed JSON data.