pythermodb-settings 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl

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.
@@ -1,5 +1,5 @@
1
1
  # NOTE: app info
2
- __version__ = "0.1.5"
2
+ __version__ = "0.1.7"
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"
@@ -10,7 +10,7 @@ from .references import (
10
10
  MixtureReferenceThermoDB
11
11
  )
12
12
  from .rules import ComponentRule
13
- from .source import ComponentThermoDBSource
13
+ from .source import ComponentThermoDBSource, MixtureThermoDBSource
14
14
 
15
15
  __all__ = [
16
16
  "Component",
@@ -24,5 +24,6 @@ __all__ = [
24
24
  "CustomReference",
25
25
  "MixtureReferenceThermoDB",
26
26
  "ComponentRule",
27
- "ComponentThermoDBSource"
27
+ "ComponentThermoDBSource",
28
+ "MixtureThermoDBSource"
28
29
  ]
@@ -10,7 +10,7 @@ from .components import Component
10
10
 
11
11
  class ComponentThermoDBSource(BaseModel):
12
12
  '''
13
- ThermoDB source containing component thermodb.
13
+ ThermoDB source containing `component` thermodb.
14
14
 
15
15
  Attributes
16
16
  ----------
@@ -19,8 +19,39 @@ class ComponentThermoDBSource(BaseModel):
19
19
  source: str
20
20
  Path to the thermodb file
21
21
  '''
22
- component: Component
22
+ component: Component = Field(
23
+ ..., description="Component object containing name, formula, and state"
24
+ )
25
+ source: str = Field(
26
+ ...,
27
+ description="Path to the thermodb file"
28
+ )
29
+
30
+ model_config = ConfigDict(
31
+ arbitrary_types_allowed=True,
32
+ extra="allow"
33
+ )
34
+
35
+
36
+ class MixtureThermoDBSource(BaseModel):
37
+ '''
38
+ ThermoDB source containing `mixture` thermodb.
39
+
40
+ Attributes
41
+ ----------
42
+ components: list[Component]
43
+ List of components in the mixture thermodb
23
44
  source: str
45
+ Path to the thermodb file
46
+ '''
47
+ components: list[Component] = Field(
48
+ ...,
49
+ description="List of components in the mixture thermodb"
50
+ )
51
+ source: str = Field(
52
+ ...,
53
+ description="Path to the thermodb file"
54
+ )
24
55
 
25
56
  model_config = ConfigDict(
26
57
  arbitrary_types_allowed=True,
@@ -2,11 +2,13 @@
2
2
  from .component_utils import (
3
3
  create_component_id,
4
4
  set_component_id,
5
- create_binary_mixture_id
5
+ create_binary_mixture_id,
6
+ create_mixture_id
6
7
  )
7
8
 
8
9
  __all__ = [
9
10
  "create_component_id",
10
11
  "set_component_id",
11
12
  "create_binary_mixture_id",
13
+ "create_mixture_id"
12
14
  ]
@@ -187,3 +187,88 @@ def create_binary_mixture_id(
187
187
  except Exception as e:
188
188
  logging.error(f"Error in create_binary_mixture_id: {e}")
189
189
  raise
190
+
191
+
192
+ def create_mixture_id(
193
+ components: list[Component],
194
+ mixture_key: Literal[
195
+ 'Name', 'Formula', 'Name-State', 'Formula-State',
196
+ ] = 'Name',
197
+ delimiter: str = "|"
198
+ ) -> str:
199
+ """Create a unique mixture ID based on a list of components (sorted alphabetically).
200
+
201
+ Parameters
202
+ ----------
203
+ components : list[Component]
204
+ List of components in the mixture.
205
+ component_key : Literal['Name', 'Formula'], optional
206
+ The key to use for identifying the components, by default 'Name'.
207
+ delimiter : str, optional
208
+ Delimiter to separate the components in the ID, by default "|".
209
+
210
+ Returns
211
+ -------
212
+ str
213
+ A unique mixture ID.
214
+
215
+ Raises
216
+ ------
217
+ ValueError
218
+ If the component_key is not recognized.
219
+
220
+ Examples
221
+ --------
222
+ The following example creates a mixture ID for water, ethanol, and methanol
223
+ using their names:
224
+
225
+ >>> comp1 = Component(name="Water", formula="H2O", state="l")
226
+ >>> comp2 = Component(name="Ethanol", formula="C2H5OH", state="l")
227
+ >>> comp3 = Component(name="Methanol", formula="CH3OH", state="l")
228
+ >>> create_mixture_id([comp1, comp2, comp3], mixture_key='Name')
229
+ 'Ethanol|Methanol|Water'
230
+ """
231
+ try:
232
+ # SECTION: validate inputs
233
+ # NOTE: components
234
+ if not all(isinstance(comp, Component) for comp in components):
235
+ raise TypeError(
236
+ "All items in components must be instances of Component"
237
+ )
238
+ if len(components) == 0:
239
+ raise ValueError("components list cannot be empty")
240
+
241
+ # NOTE: delimiter
242
+ if not isinstance(delimiter, str):
243
+ raise TypeError("delimiter must be a string")
244
+ # strip delimiter
245
+ delimiter = delimiter.strip()
246
+
247
+ # SECTION: get component IDs
248
+ component_ids = []
249
+ for comp in components:
250
+ if mixture_key == 'Name':
251
+ comp_id = comp.name.strip().lower()
252
+ elif mixture_key == 'Formula':
253
+ comp_id = comp.formula.strip().lower()
254
+ elif mixture_key == 'Name-State':
255
+ comp_id = f"{comp.name.strip().lower()}-{comp.state.strip().lower()}"
256
+ elif mixture_key == 'Formula-State':
257
+ comp_id = f"{comp.formula.strip().lower()}-{comp.state.strip().lower()}"
258
+ else:
259
+ raise ValueError(
260
+ "component_key must be either 'Name' or 'Formula'"
261
+ )
262
+ component_ids.append(comp_id)
263
+
264
+ # SECTION: create unique mixture ID (sorted to ensure uniqueness)
265
+ mixture_id = delimiter.join(sorted(component_ids))
266
+
267
+ # strip
268
+ mixture_id = mixture_id.strip()
269
+
270
+ # return
271
+ return mixture_id
272
+ except Exception as e:
273
+ logging.error(f"Error in create_mixture_id: {e}")
274
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythermodb-settings
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Add your description here
5
5
  Author-email: Sina Gilassi <sina.gilassi@gmail.com>
6
6
  License-Expression: MIT
@@ -1,18 +1,18 @@
1
1
  pythermodb_settings/__init__.py,sha256=VzJSYgJJNw_j5NmnIbq0pJhBd_9Kp-bbfOsRLepplSw,229
2
2
  pythermodb_settings/app.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  pythermodb_settings/configs/__init__.py,sha256=QR38PBCzgoFwYqcViR9bFT2YIR5m9s7q8C7cV4fZjz4,211
4
- pythermodb_settings/configs/about.py,sha256=MAPCptiE9W2ATRViCGW3buj6XBvaQasem-MKk29Ds4o,379
5
- pythermodb_settings/models/__init__.py,sha256=BUPWYUo4dhRz2FZgm5_iTQX3Nxz8LO71lnuXNWNmUlI,713
4
+ pythermodb_settings/configs/about.py,sha256=UQmiOmXUpKxumKocGKuOOw-1scVmKCLf_A8X72geHqI,379
5
+ pythermodb_settings/models/__init__.py,sha256=4qi2Gut42auzeEpK4Gw0UkbALYlQ-kLnes0blSu_UFs,766
6
6
  pythermodb_settings/models/components.py,sha256=4CwZcGpbm1PiEBQUpEmo6T6mP4y3S3LIiHCM0y9C7XU,1674
7
7
  pythermodb_settings/models/conditions.py,sha256=Zm5JcM2kyMlS6b8hPbs6awa_6ps3xFoCVA4zwNPc5eg,1083
8
8
  pythermodb_settings/models/configs.py,sha256=57nXShSbtiVo9fP2OFIbzRqS87oT4ITRLYJi_bp5cFI,674
9
9
  pythermodb_settings/models/references.py,sha256=A27Y-7L8X-g2m-pxuDk0ateFScPE1MMEyoR1SH8VDVA,6359
10
10
  pythermodb_settings/models/rules.py,sha256=1a9CyTHwpQkZQXFJWDMrEcKQAOTOwquepoOQPGznTlc,74
11
- pythermodb_settings/models/source.py,sha256=liN4v1o8mqxclz8khca4anTOzLHO-5gCnK0MsfVgxGY,533
12
- pythermodb_settings/utils/__init__.py,sha256=eDbjrvNnRVt3SJ4d0h0BJtHoxQ9hemRQ7oN0An6-nZ0,228
13
- pythermodb_settings/utils/component_utils.py,sha256=Ko8PG1qG9A_mYV524Vews8H30mFRwowzhJmVpziKcV8,5755
14
- pythermodb_settings-0.1.5.dist-info/licenses/LICENSE,sha256=pHRAx3wjVKpt2ec3NyhntY6_bGgJqV2SyE8xNUJ7MYE,1090
15
- pythermodb_settings-0.1.5.dist-info/METADATA,sha256=eRj4a1Z9JauGDHwHSQQ4-sxpZiDN65OeBHdM57GCVrc,4894
16
- pythermodb_settings-0.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- pythermodb_settings-0.1.5.dist-info/top_level.txt,sha256=6IdVIbW__wHFsKQYx7DDnXArm10qiJVIyaoSEFQylK4,20
18
- pythermodb_settings-0.1.5.dist-info/RECORD,,
11
+ pythermodb_settings/models/source.py,sha256=0yU21YpYSqnew8rjTrlRuoWAuSAlUvMOebC5X0Sr8X4,1325
12
+ pythermodb_settings/utils/__init__.py,sha256=j3MYKYv7nx5u356J82cacKBzC-CBUJ8GPI4J3c5ss_U,277
13
+ pythermodb_settings/utils/component_utils.py,sha256=MrqqcFCb0ksQu4Q3gm2UtuKpnCMYjJ21nM5baB1KaGs,8675
14
+ pythermodb_settings-0.1.7.dist-info/licenses/LICENSE,sha256=pHRAx3wjVKpt2ec3NyhntY6_bGgJqV2SyE8xNUJ7MYE,1090
15
+ pythermodb_settings-0.1.7.dist-info/METADATA,sha256=DBbhLyQS7QEmZVm7Hyja8zAl_rdtAdfFX5Ils3Dm9lA,4894
16
+ pythermodb_settings-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ pythermodb_settings-0.1.7.dist-info/top_level.txt,sha256=6IdVIbW__wHFsKQYx7DDnXArm10qiJVIyaoSEFQylK4,20
18
+ pythermodb_settings-0.1.7.dist-info/RECORD,,