Collection
Collections are the main tool given by the Chemotion system to organize elements. In the Python APi Collection are seperated in different classes. The root collection is the basic element to work with collections.
- class chemotion_api.collection.RootCollection(session: Connection)
The root collection is the foundation of working with collections. It serves with methods to navigate through the collections and creating new collections
Usage:
>>> from chemotion_api import Instance >>> import logging >>> try: >>> instance = Instance('http(d)://xxx.xxx.xxx').test_connection().login('<USER>', "<PASSWORD>") >>> except ConnectionError as e: >>> logging.error(f"A connection to Chemotion ({instance.host_url}) cannot be established") >>> rc = instance.get_root_collection(True) >>> # Navigate to collection 'Team One' in 'Projects' >>> col = rc.get_collection('/Projects/Team One') >>> # Create collection 'P 123' in '/Project/Team One' >>> col.get_or_create_collection('./P 123') >>> # Move collection P 122 into collection '/Done Projects' >>> col.get_collection('./P 122').move('/Done Projects') >>> for sample in col.get_samples(): >>> pass # Do something
- add_collection(path_to_new: str | list[str])
Creates a new collection at the path_to_new path. The collection is not saved. Please reload the collection after saving it.
- Parameters:
path_to_new – is either a string based on a unix path or a list
- Returns:
new Collection (not saved)
- property all: dict[slice(<class 'str'>, <built-in function any>, None)]
Returns all information of the ‘All’ collections
- Returns:
information of the ‘All’ collection
- property children: list[TAbstractCollection]
A list of all children collection
- Returns:
A list of all children collection
- delete(src: str | list[str], case_insensitive: bool = False)
Deletes a collection at the src path.
- Parameters:
src – is either a string based on a unix path or a list
case_insensitive – If true the cases of path are taken into account
- find(label: str | None = None, **kwargs) list[TAbstractCollection]
Finds a collection by its label or other properties. Path is not needed.
- Parameters:
label – String or None.
kwargs – Other properties used to search Collections
- Returns:
All found Collections
- get_collection(col_path: str | list[str], case_insensitive: bool = False) TAbstractCollection
Gets a collection a path points to.
- Parameters:
col_path – is either a string based on a unix path or a list
case_insensitive – If true the cases of path are taken into account
- Returns:
Collection the path points to
- get_elements_of_iri(element_type: str, per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
Gets all elements of given IRI type.
- Parameters:
element_type – IRI string chemotion:xxx/xxx/xxx
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet based on the IRI
- get_generics_by_label(label: str, per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all generic elements of a given label.
- Parameters:
label – generic element’s label
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of generic elements of a given name
- get_generics_by_name(name: str, per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all generic elements of a given name.
- Parameters:
name – generic element’s name
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of generic elements of a given name
- get_or_create_collection(col_path: str | list[str], case_insensitive: bool = False) TAbstractCollection
Gets or creates a collection the col_path path points to. If the collection needs to be created the collection is saved right away.
- Parameters:
col_path – is either a string based on a unix path or a list
case_insensitive – If true the cases of path are taken into account
- Returns:
Collection the path points to
- get_path() str
Generates the absolut path of collection
- Returns:
Absolut path of a collection
- get_reactions(per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all reactions.
- Parameters:
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of reactions
- get_research_plans(per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all research plans.
- Parameters:
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of research plans
- get_root() TRootCollection
Get root Collection
- Returns:
Instance of the RootCollection
- get_samples(per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None, product_only: bool = False) ElementSet
List of all samples.
- Parameters:
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
product_only – If True only samples which are products in a reaction are returned
- Returns:
ElementSet of samples
- get_wellplates(per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all well plates.
- Parameters:
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of well plates
- property id: int
The ‘All’ collection ID
- Returns:
Ihe ID of the ‘All’ collection
- property label: str | None
The collection label
- Returns:
The collection label
- load_collection() dict[slice(<class 'str'>, <built-in function any>, None)]
Load collection information
- Returns:
A collection off all collection information
- load_sync_collection() RootSyncCollection
Loads the RootSyncCollection. The RootSyncCollection collection can be used to access all collection synced with you.
- Returns:
instance of RootSyncCollection
- move(src: str | list[str], dest: str | list[str], case_insensitive: bool = False)
Moves a collection from a src path to a dest path.
- Parameters:
src – is either a string based on a unix path or a list
dest – is either a string based on a unix path or a list
case_insensitive – If true the cases of path are taken into account
- Returns:
Collection the path points to
- prepare_label(case_insensitive: bool) str
Prepares the label of a collection
- Parameters:
case_insensitive – If true it returns teh lower case label
- Returns:
The collection’s label
- save()
Saves ALL updates of done to owned (not synced) collection.
- set_element_manager(element_manager: ElementManager)
Set the ElementManager class
- Parameters:
element_manager – instance of ElementManager
- property sync_root: RootSyncCollection
The RootSyncCollection collection can be used to access all collection synced with you.
- Returns:
instance of RootSyncCollection
- to_json() dict[slice(<class 'str'>, <class 'list'>, None)]
Generates a dict containing all list of all children collection
- Returns:
list of children as savable JSON
The root collection organizes the standard Collections:
- class chemotion_api.collection.Collection(collection_json: dict | None = None)
The collection object represents the standard collection owned by the current user
- add_collection(name: str)
Creates a new child collection. The collection is not saved. Please reload the collection after saving it.
- Parameters:
name – new collection`s name
- Returns:
new Collection (not saved)
- property children: list[TAbstractCollection]
A list of all children collection
- Returns:
A list of all children collection
- delete()
Deletes this collection.
- find(label: str | None = None, **kwargs) list[TAbstractCollection]
Finds a collection by its label or other properties. Path is not needed.
- Parameters:
label – String or None.
kwargs – Other properties used to search Collections
- Returns:
All found Collections
- get_collection(col_path: str | list[str], case_insensitive: bool = False) TAbstractCollection
Gets a collection a path points to.
- Parameters:
col_path – is either a string based on a unix path or a list
case_insensitive – If true the cases of path are taken into account
- Returns:
Collection the path points to
- get_elements_of_iri(element_type: str, per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
Gets all elements of given IRI type.
- Parameters:
element_type – IRI string chemotion:xxx/xxx/xxx
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet based on the IRI
- get_generics_by_label(label: str, per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all generic elements of a given label.
- Parameters:
label – generic element’s label
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of generic elements of a given name
- get_generics_by_name(name: str, per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all generic elements of a given name.
- Parameters:
name – generic element’s name
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of generic elements of a given name
- get_or_create_collection(col_path: str | list[str], case_insensitive: bool = False) TAbstractCollection
Gets or creates a collection the col_path path points to. If the collection needs to be created the collection is saved right away.
- Parameters:
col_path – is either a string based on a unix path or a list
case_insensitive – If true the cases of path are taken into account
- Returns:
Collection the path points to
- get_path() str
Generates the absolut path of collection
- Returns:
Absolut path of a collection
- get_reactions(per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all reactions.
- Parameters:
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of reactions
- get_research_plans(per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all research plans.
- Parameters:
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of research plans
- get_root() TRootCollection
Get root Collection
- Returns:
Instance of the RootCollection
- get_samples(per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None, product_only: bool = False) ElementSet
List of all samples.
- Parameters:
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
product_only – If True only samples which are products in a reaction are returned
- Returns:
ElementSet of samples
- get_wellplates(per_page: int | None = 10, updated_to_date: datetime | None = None, updated_from_date: datetime | None = None) ElementSet
List of all well plates.
- Parameters:
per_page – How many Elements per page
updated_to_date – Set date time to fetch only elements which are updated before ‘updated_to_date’
updated_from_date – Set date time to fetch only elements which are updated after ‘updated_from_date’
- Returns:
ElementSet of well plates
- property id: int | None
The chemotion DB ID
- Returns:
The chemotion DB ID
- property label: str | None
The collection label
- Returns:
The collection label
- move(dest: str | list[str], case_insensitive: bool = False)
Moves this collection to a dest path.
- Parameters:
dest – is either a string based on a unix path or a list
case_insensitive – If true the cases of path are taken into account
- Returns:
Collection the path points to
- new_element_by_iri(element_type: str) AbstractElement
Creates a new element of given IRI type. However, if the type is generic the generated element is of the newest type.
- Parameters:
element_type – IRI string chemotion:xxx/xxx/xxx
- Returns:
AbstractElement
- new_generic(type_name: str) GenericElement
Creates a new element of given type name in this collection.
- Parameters:
type_name – Generic element’s type name
- Returns:
New (unsaved) GenericElement
- new_generic_by_label(label: str) GenericElement
Creates a new element of given label in this collection.
- Parameters:
label – Generic element’s label
- Returns:
GenericElement
- new_research_plan() ResearchPlan
Creates a new research plan in this collection.
- Returns:
New (unsaved) ResearchPlan
- new_sample_smiles(smiles_code: str) Sample
Creates a new sample with a molecule generated with a smiles code in this collection.
- Returns:
New (unsaved) Sample
- new_solvent(name) Sample
Creates a new solvent in this collection.
- Returns:
New (unsaved) solvent as Sample
- new_wellplate() Wellplate
Creates a new well plate in this collection.
- Returns:
New (unsaved) Wellplate
- prepare_label(case_insensitive: bool) str
Prepares the label of a collection
- Parameters:
case_insensitive – If true it returns teh lower case label
- Returns:
The collection’s label
- set_json(collection_json)
Set the json data received from the server
- Parameters:
collection_json – JSON object representing the collection
To synchronize a collection with a set of users or groups
- Parameters:
permission_level – Element from SyncPermission
users – a list of users or groups
- to_json()
Generates a dict containing all list of all children collection
- Returns:
list of children as savable JSON
- enum chemotion_api.collection.SyncPermission(value)
An enumeration.
Valid values are as follows:
- Read = <SyncPermission.Read: 0>
- Write = <SyncPermission.Write: 1>
- Delete = <SyncPermission.Delete: 3>
- ImportElements = <SyncPermission.ImportElements: 4>
- PassOwnership = <SyncPermission.PassOwnership: 5>
The RootCollection as also a property to get the RootSyncCollection
- class chemotion_api.collection.RootSyncCollection(session: Connection, element_manager: ElementManager)
This can be used amost like the root collection object. However, you cannot move, delete or create its child collections