The cheminfopy API reference
Contents
The cheminfopy API reference#
The manager package#
Sample#
Interface for the sample abstraction in the cheminfo ELN
- class cheminfopy.managers.sample.Sample(*args, **kwargs)[source]#
Bases:
cheminfopy.managers.manager.Manager
Sample manager handles operations on samples
- __init__(*args, **kwargs)[source]#
- Parameters
instance (str) – URL the the ELN instance, for example https://mydb.cheminfo.org/db/eln for the c6h6.org deployment
token (str) – Token string. Can be any kind of token (user/entry) with any rights. If the token does not have suitable rights, the library will raise and Exception. Tokens can be generated in the ELN using the “Access Token” view
sample_uuid (str) – UUID of the sample
- property creation_date#
Returns the creation date
- property em#
Returns the exact mass in Dalton
- get_data(data_type, file_name)[source]#
Allows to get a specific spectrum from the ELN. For this you need to select the type and the filename of the spectrum. You can get an overview of all the attached spectra from the table of contents of the sample.
- Parameters
data_type (str) – spectrum type. Valid types are in VALID_DATA_TYPES
file_name (str) – filename (with extension)
- Returns
The filecontent of the selected spectrum.
- Return type
[str]
- Raises
InvalidAttachmentTypeError – If the selected type is not supported by the schema of the ELN. The allowed types are in VALID_DATA_TYPES
- has_right(right)[source]#
Checks if the token with which the manager was initialized has certain rights.
- Parameters
right (str) – right to test (“write”, “create”, “read”, “addAttachment” are the most relevant ones)
- Returns
True if the manager instance has the rights
- Return type
[bool]
- property id#
ID of the sample
- property last_modified_by#
Returns the username who performed the last modification
- property mf#
Returns a string with the molecular formula
- property modification_date#
Returns the date of the last modification
- property molfile#
Return the molfile for this sample
- property mw#
Return the molecular weight in g/mol
- property owners#
Owners of the sample
- put_data(data_type, file_name, file_content, metadata=None, source_info=None)[source]#
This methods allows to add spectra to a sample. Follow the dataschema at https://cheminfo.github.io/data_schema/. In particular, use JCAMP-DX files for spectra. You can use the pytojcamp library (https://github.com/cheminfo-py/pytojcamp) to convert Python dictionaries to JCAMP-DX files.
- Parameters
data_type (str) – spectrum type. Valid types are in VALID_DATA_TYPES
file_name (str) – filename (with extension)
file_content (str) – String with the content of the file
metadata (str) – Metadata dictionary. Please follow the schema at https://cheminfo.github.io/data_schema/. For example, for gas adsorption isotherms you might want to add the keys ‘adsorptive’ and ‘temperature’. Defaults to None.
source_info (Union[dict, None], optional) – You can provide a dictionary with source information. Allowed keys are “name”, “url”, ‘uuid”, “doi”. Use this to describe the source of the data you want to attach to the sample. If you do not provide this dictionary / leave the default value of None, we will default the values in DEFAULT_SOURCE_DICT. Defaults to None.
- Raises
InvalidAttachmentTypeError – If the selected type is not supported by the schema of the ELN. The allowed types are in VALID_DATA_TYPES
- property revision#
Revision of the document
- property spectra#
Lists all spectra that are attached to the sample
- property toc#
Get the table of contents entry for this sample
- property type#
Type of the document
- property uuid#
UUID of the sample
UserManager#
Handle operations on the user level
- class cheminfopy.managers.user.User(instance, token, **kwargs)[source]#
Bases:
cheminfopy.managers.manager.Manager
User manager handles operations on users
- has_rights(rights)[source]#
Checks if the token with which the manager was initialized has certain rights.
- Parameters
rights (Collection[str]) – right to test (“write”, “create”, “read”, “addAttachment” are the most relevant ones)
- Returns
True if the manager instance has the rights
- Return type
[bool]
- property is_valid_token#
Checks if the token is actually a user token
ExperimentManager#
Dealing with experiments/reactions
- class cheminfopy.managers.experiment.Experiment(*args, **kwargs)[source]#
Bases:
cheminfopy.managers.manager.Manager
Experiment manager handles operations on experiments
- __init__(*args, **kwargs)[source]#
- Parameters
instance (str) – URL the the ELN instance, for example https://mydb.cheminfo.org/db/eln for the c6h6.org deployment
token (str) – Token string. Can be any kind of token (user/entry) with any rights. If the token does not have suitable rights, the library will raise and Exception. Tokens can be generated in the ELN using the “Access Token” view
experiment_uuid (str) – UUID of the experiment
- property date#
Date of the experiment
- property id#
UUID of the reaction
- property kind#
Kind of the entry
- property owners#
Owners of the reaction
- property procedure#
Procedure of the reaction
- property products#
Products of the reaction
- property reactionRXN#
Reaction RXN file
- property reagents#
Reagents of the reaction
- property remarks#
Remarks of the reaction
- property revision#
Revision of the reaction
- property title#
Title of the reaction
- property toc#
Get the table of contents entry for this experiment
Manager base class#
Base manager class
- class cheminfopy.managers.manager.Manager(instance, token, **kwargs)[source]#
Bases:
object
Base class for all managers
- __init__(instance, token, **kwargs)[source]#
A manager instance provides the basic functionality to interact with the rest-on-couch API
- Parameters
instance (str) – URL the the ELN instance, for example https://mydb.cheminfo.org/ for the c6h6.org deployment
token (str) – Token string. Can be any kind of token (user/entry) with any rights. If the token does not have suitable rights, the library will raise and Exception. Tokens can be generated in the ELN using the “Access Token” view
- __weakref__#
list of weak references to the object (if defined)
- property instance#
Provide the eln database URL
Requester#
Implementing the basic logic for requests the rest-on-couch API
- class cheminfopy.request.ELNRequest(token)[source]#
Bases:
object
Class that runs the actual request using token authentication.
- __init__(token)[source]#
- Parameters
token (str) – Token string. Can be any kind of token (user/entry) with any rights. If the token does not have suitable rights, the library will raise and Exception. Tokens can be generated in the ELN using the “Access Token” view
- __weakref__#
list of weak references to the object (if defined)
- get(url)[source]#
Make a GET request to the URL
- Parameters
url (str) – URL to which the request should be made
- Returns
Response of the request
- Return type
requests.Response
- put(url, data=None, json_payload=None)[source]#
Make a PUT request to the URL with the provided data
- Parameters
url (str) – URL to which the request should be made
data (object) – Some data to be sent with the request. Defaults to None
json_payload (dict) – JSON payload. If not None, this method will default to using the JSON payload instead of the data
- Returns
Response of the request
- Return type
[requests.Response]
Errors#
Custom error types for cheminfopy
- exception cheminfopy.errors.AuthenticationError[source]#
Bases:
ValueError
Raised if authentication fails
- __weakref__#
list of weak references to the object (if defined)
- exception cheminfopy.errors.InvalidAttachmentTypeError[source]#
Bases:
ValueError
Raised in case of incompatible attachment type
- __weakref__#
list of weak references to the object (if defined)
- exception cheminfopy.errors.InvalidInstanceUrlError[source]#
Bases:
ValueError
Raised if the provided instance URL seems invalid
- __weakref__#
list of weak references to the object (if defined)
Constants#
Globals to be reused across the cheminfopy package