I/O
load_assemblies(file_path)
Load assemblies and components from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
PathLike | str
|
Path to the YAML file to load. |
required |
Returns:
| Type | Description |
|---|---|
list[Assembly]
|
List of loaded assemblies. |
Examples:
Source code in src/nasap_net/io/assemblies/loading.py
load_reactions(file_path, assemblies, *, assembly_id_type='str', component_id_type='str', site_id_type='str', reaction_id_type='str', has_index_column=False)
Load reactions from a CSV file and convert to Reaction objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
PathLike | str
|
Path to the CSV file to load. |
required |
assemblies
|
Iterable[Assembly]
|
Assemblies referenced by the reactions. Must have unique IDs. |
required |
assembly_id_type
|
(str, int)
|
Type to cast assembly IDs to. Default is |
'str'
|
component_id_type
|
(str, int)
|
Type to cast component IDs to. Default is |
'str'
|
site_id_type
|
(str, int)
|
Type to cast site IDs to. Default is |
'str'
|
reaction_id_type
|
(str, int)
|
Type to cast reaction IDs to. Default is |
'str'
|
has_index_column
|
bool
|
If True, the first column is treated as a row index. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
list[Reaction]
|
List of loaded reactions. |
Examples:
>>> from nasap_net import load_reactions
>>> reactions = load_reactions('reactions.csv', assemblies=assemblies)
Source code in src/nasap_net/io/reactions/loading.py
save_assemblies(assemblies, file_path, *, overwrite=False)
Dump assemblies and components into a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assemblies
|
Iterable[Assembly]
|
Assemblies to dump. |
required |
file_path
|
PathLike | str
|
Path to the YAML file to write. |
required |
overwrite
|
bool
|
If True, overwrite the file if it already exists. If False, raise an error if the file already exists. Default is False. |
False
|
Examples:
>>> from nasap_net import save_assemblies
>>> save_assemblies(assemblies, 'assemblies.yaml')
>>> save_assemblies(assemblies, 'assemblies.yaml', overwrite=True)
Source code in src/nasap_net/io/assemblies/saving.py
save_reactions(reactions, file_path, *, overwrite=False, index=False)
Save reactions to a CSV file.
Resulting CSV columns:
- init_assem_id : str | int
- entering_assem_id : str | int | None
- product_assem_id : str | int
- leaving_assem_id : str | int | None
- metal_bs_component : str | int
- metal_bs_site : str | int
- leaving_bs_component : str | int
- leaving_bs_site : str | int
- entering_bs_component : str | int
- entering_bs_site : str | int
- duplicate_count : int
- id : str | int | None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reactions
|
Iterable[Reaction]
|
Reactions to save. |
required |
file_path
|
PathLike | str
|
Path to the CSV file to write. |
required |
overwrite
|
bool
|
If True, overwrite the file if it already exists. If False, raise an error if the file already exists. Default is False. |
False
|
index
|
bool
|
If True, write row names (index). Default is False. |
False
|
Examples:
>>> from nasap_net import save_reactions
>>> save_reactions(reactions, 'reactions.csv')
>>> save_reactions(reactions, 'reactions.csv', overwrite=True)
Source code in src/nasap_net/io/reactions/saving.py
save_classification_result(reaction_to_class, file_path, *, overwrite=False, index=False)
Save the classification result to a CSV file.
Resulting CSV columns:
- init_assem_id : str | int
- entering_assem_id : str | int | None
- product_assem_id : str | int
- leaving_assem_id : str | int | None
- metal_bs_component : str | int
- metal_bs_site : str | int
- leaving_bs_component : str | int
- leaving_bs_site : str | int
- entering_bs_component : str | int
- entering_bs_site : str | int
- duplicate_count : int
- id : str | int | None
- reaction_class : str
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reaction_to_class
|
Mapping[Reaction, str]
|
Mapping from Reaction objects to their corresponding class labels. |
required |
file_path
|
PathLike | str
|
Path to the CSV file to write. |
required |
overwrite
|
bool
|
If True, overwrite the file if it already exists. If False, raise an error if the file already exists. Default is False. |
False
|
index
|
bool
|
If True, write row names (index). Default is False. |
False
|
Examples:
>>> from nasap_net import save_classification_result
>>> save_classification_result(reaction_to_class, 'classification.csv')