pythermodb-settings 0.1.1__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {pythermodb_settings-0.1.1/pythermodb_settings.egg-info → pythermodb_settings-0.1.3}/PKG-INFO +1 -1
  2. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pyproject.toml +1 -1
  3. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/configs/about.py +1 -1
  4. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/models/__init__.py +2 -1
  5. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/models/components.py +21 -0
  6. pythermodb_settings-0.1.3/pythermodb_settings/utils/__init__.py +12 -0
  7. pythermodb_settings-0.1.3/pythermodb_settings/utils/component_utils.py +189 -0
  8. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3/pythermodb_settings.egg-info}/PKG-INFO +1 -1
  9. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings.egg-info/SOURCES.txt +3 -1
  10. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/LICENSE +0 -0
  11. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/README.md +0 -0
  12. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/__init__.py +0 -0
  13. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/app.py +0 -0
  14. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/configs/__init__.py +0 -0
  15. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/models/conditions.py +0 -0
  16. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/models/configs.py +0 -0
  17. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/models/references.py +0 -0
  18. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/models/rules.py +0 -0
  19. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings/models/source.py +0 -0
  20. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings.egg-info/dependency_links.txt +0 -0
  21. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings.egg-info/requires.txt +0 -0
  22. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/pythermodb_settings.egg-info/top_level.txt +0 -0
  23. {pythermodb_settings-0.1.1 → pythermodb_settings-0.1.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythermodb-settings
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Add your description here
5
5
  Author-email: Sina Gilassi <sina.gilassi@gmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pythermodb-settings"
7
- version = "0.1.1"
7
+ version = "0.1.3"
8
8
  description = "Add your description here"
9
9
  authors = [
10
10
  { name = "Sina Gilassi", email = "sina.gilassi@gmail.com" }
@@ -1,5 +1,5 @@
1
1
  # NOTE: app info
2
- __version__ = "0.1.1"
2
+ __version__ = "0.1.3"
3
3
  __description__ = """PyThermoDB Settings is a Python package that acts as an interface between pythermdb and other applications, providing robust, Pydantic-based data models and configuration structures for managing thermodynamic database (ThermoDB) settings."""
4
4
  __author__ = "Sina Gilassi"
5
5
  __author_email__ = "sina.gilassi@gmail.com"
@@ -1,5 +1,5 @@
1
1
  # export
2
- from .components import Component
2
+ from .components import Component, ComponentIdentity
3
3
  from .conditions import Temperature, Pressure
4
4
  from .configs import ComponentConfig
5
5
  from .references import (
@@ -13,6 +13,7 @@ from .source import ComponentThermoDBSource
13
13
 
14
14
  __all__ = [
15
15
  "Component",
16
+ "ComponentIdentity",
16
17
  "Temperature",
17
18
  "Pressure",
18
19
  "ComponentConfig",
@@ -39,3 +39,24 @@ class Component(BaseModel):
39
39
  arbitrary_types_allowed=True,
40
40
  extra="allow"
41
41
  )
42
+
43
+
44
+ class ComponentIdentity(BaseModel):
45
+ """
46
+ Model for component identity.
47
+
48
+ Attributes
49
+ ----------
50
+ name_state : str
51
+ Component name-state identifier.
52
+ formula_state : str
53
+ Component formula-state identifier.
54
+ """
55
+ name_state: str = Field(
56
+ ...,
57
+ description="Component name-state identifier"
58
+ )
59
+ formula_state: str = Field(
60
+ ...,
61
+ description="Component formula-state identifier"
62
+ )
@@ -0,0 +1,12 @@
1
+ # export
2
+ from .component_utils import (
3
+ create_component_id,
4
+ set_component_id,
5
+ create_binary_mixture_id
6
+ )
7
+
8
+ __all__ = [
9
+ "create_component_id",
10
+ "set_component_id",
11
+ "create_binary_mixture_id",
12
+ ]
@@ -0,0 +1,189 @@
1
+ # import libs
2
+ import logging
3
+ from typing import Literal
4
+ from pythermodb_settings.models import Component
5
+ # local
6
+ from ..models import ComponentIdentity
7
+
8
+ # NOTE: logger
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ def create_component_id(
13
+ component: Component,
14
+ separator_symbol: str = '-'
15
+ ) -> ComponentIdentity:
16
+ '''
17
+ Create component name-state and formula-state identifiers.
18
+
19
+ Parameters
20
+ ----------
21
+ component : Component
22
+ The component for which to create the identifiers.
23
+ separator_symbol : str, optional
24
+ The symbol to use as a separator between the name/formula and
25
+
26
+ Returns
27
+ -------
28
+ ComponentIdentity
29
+ The component identity containing name-state and formula-state
30
+ identifiers.
31
+ '''
32
+ try:
33
+ # NOTE: extract component name
34
+ component_name = component.name.strip()
35
+ component_formula = component.formula.strip()
36
+ component_state = component.state.strip().lower()
37
+
38
+ # >> separator
39
+ separator_symbol = separator_symbol.strip()
40
+
41
+ # SECTION: create component identifiers
42
+ name_state = f"{component_name}{separator_symbol}{component_state}"
43
+ formula_state = f"{component_formula}{separator_symbol}{component_state}"
44
+
45
+ return ComponentIdentity(
46
+ name_state=name_state,
47
+ formula_state=formula_state
48
+ )
49
+ except Exception as e:
50
+ logger.error(
51
+ f"Failed to create component identifiers for "
52
+ f"'{component}': {e}"
53
+ )
54
+ raise e
55
+
56
+
57
+ def set_component_id(
58
+ component: Component,
59
+ component_key: Literal[
60
+ 'Name-State', 'Formula-State'
61
+ ],
62
+ separator_symbol: str = '-',
63
+ ) -> str:
64
+ '''
65
+ Set component identifier based on the specified key.
66
+
67
+ Parameters
68
+ ----------
69
+ component : Component
70
+ The component for which to set the identifier.
71
+ component_key : str
72
+ The key to determine which identifier to use.
73
+ Options are:
74
+ - 'Name-State': Use the name-state identifier.
75
+ - 'Formula-State': Use the formula-state identifier.
76
+ separator_symbol : str, optional
77
+ The symbol to use as a separator between the name/formula and state.
78
+ Default is '-'.
79
+
80
+ Returns
81
+ -------
82
+ str
83
+ The component identifier based on the specified key.
84
+ '''
85
+ try:
86
+ # NOTE: create component id
87
+ component_idx: ComponentIdentity = create_component_id(
88
+ component=component,
89
+ separator_symbol=separator_symbol
90
+ )
91
+
92
+ # set component id
93
+ if component_key == "Name-State":
94
+ return component_idx.name_state
95
+ elif component_key == "Formula-State":
96
+ return component_idx.formula_state
97
+ else:
98
+ raise ValueError(
99
+ f"Invalid component_key '{component_key}'. "
100
+ f"Must be 'Name-State' or 'Formula-State'."
101
+ )
102
+ except Exception as e:
103
+ logger.error(
104
+ f"Failed to set component identifier for "
105
+ f"'{component}': {e}"
106
+ )
107
+ raise e
108
+
109
+
110
+ def create_binary_mixture_id(
111
+ component_1: Component,
112
+ component_2: Component,
113
+ mixture_key: Literal[
114
+ 'Name', 'Formula'
115
+ ] = 'Name',
116
+ delimiter: str = "|"
117
+ ) -> str:
118
+ """Create a unique binary mixture ID based on two components.
119
+
120
+ Parameters
121
+ ----------
122
+ component1 : Component
123
+ The first component in the mixture.
124
+ component2 : Component
125
+ The second component in the mixture.
126
+ component_key : Literal['Name', 'Formula'], optional
127
+ The key to use for identifying the components, by default 'Name'.
128
+ delimiter : str, optional
129
+ Delimiter to separate the two components in the ID, by default "|".
130
+
131
+ Returns
132
+ -------
133
+ str
134
+ A unique binary mixture ID.
135
+
136
+ Raises
137
+ ------
138
+ ValueError
139
+ If the component_key is not recognized.
140
+
141
+ Examples
142
+ --------
143
+ The following example creates a binary mixture ID for water and ethanol
144
+ using their names:
145
+
146
+ >>> comp1 = Component(name="Water", formula="H2O", state="l")
147
+ >>> comp2 = Component(name="Ethanol", formula="C2H5OH", state="l")
148
+ >>> create_binary_mixture_id(comp1, comp2, mixture_key='Name')
149
+ 'Ethanol|Water'
150
+ """
151
+ try:
152
+ # SECTION: validate inputs
153
+ # NOTE: component
154
+ if (
155
+ not isinstance(component_1, Component) or
156
+ not isinstance(component_2, Component)
157
+ ):
158
+ raise TypeError(
159
+ "Both component1 and component2 must be instances of Component"
160
+ )
161
+
162
+ # NOTE: delimiter
163
+ if not isinstance(delimiter, str):
164
+ raise TypeError("delimiter must be a string")
165
+ # strip delimiter
166
+ delimiter = delimiter.strip()
167
+
168
+ # SECTION: get component IDs
169
+ if mixture_key == 'Name':
170
+ comp1_id = component_1.name.strip()
171
+ comp2_id = component_2.name.strip()
172
+ elif mixture_key == 'Formula':
173
+ comp1_id = component_1.formula.strip()
174
+ comp2_id = component_2.formula.strip()
175
+ else:
176
+ raise ValueError(
177
+ "component_key must be either 'Name' or 'Formula'"
178
+ )
179
+
180
+ # SECTION: create unique mixture ID (sorted to ensure uniqueness)
181
+ mixture_id = delimiter.join(sorted([comp1_id, comp2_id]))
182
+ # strip
183
+ mixture_id = mixture_id.strip()
184
+
185
+ # return
186
+ return mixture_id
187
+ except Exception as e:
188
+ logging.error(f"Error in create_binary_mixture_id: {e}")
189
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythermodb-settings
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Add your description here
5
5
  Author-email: Sina Gilassi <sina.gilassi@gmail.com>
6
6
  License-Expression: MIT
@@ -16,4 +16,6 @@ pythermodb_settings/models/conditions.py
16
16
  pythermodb_settings/models/configs.py
17
17
  pythermodb_settings/models/references.py
18
18
  pythermodb_settings/models/rules.py
19
- pythermodb_settings/models/source.py
19
+ pythermodb_settings/models/source.py
20
+ pythermodb_settings/utils/__init__.py
21
+ pythermodb_settings/utils/component_utils.py