pythermodb-settings 0.1.2__py3-none-any.whl → 0.1.4__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.2"
2
+ __version__ = "0.1.4"
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"
@@ -111,6 +111,35 @@ class ComponentReferenceThermoDB(BaseModel):
111
111
  extra="allow"
112
112
  )
113
113
 
114
+ # NOTE: mixture reference thermodb model
115
+
116
+
117
+ class MixtureReferenceThermoDB(BaseModel):
118
+ """
119
+ Model for mixture thermodynamic database (ThermoDB).
120
+
121
+ Attributes
122
+ ----------
123
+ components : List[Component]
124
+ The list of components forming the mixture for which the thermodynamic database is built.
125
+ reference_thermodb : ReferenceThermoDB
126
+ Reference thermodynamic database.
127
+ mixture_key : Literal['Name', 'Formula'], optional
128
+ Key to identify the mixture in the reference content, by default 'Name'.
129
+ """
130
+ components: List[Component] = Field(
131
+ ...,
132
+ description="The list of components forming the mixture for which the thermodynamic database is built."
133
+ )
134
+ reference_thermodb: ReferenceThermoDB = Field(
135
+ ..., description="Reference thermodynamic database."
136
+ )
137
+
138
+ model_config = ConfigDict(
139
+ arbitrary_types_allowed=True,
140
+ extra="allow"
141
+ )
142
+
114
143
  # NOTE: references thermodb model
115
144
 
116
145
 
@@ -1,7 +1,12 @@
1
1
  # export
2
- from .component_utils import create_component_id, set_component_id
2
+ from .component_utils import (
3
+ create_component_id,
4
+ set_component_id,
5
+ create_binary_mixture_id
6
+ )
3
7
 
4
8
  __all__ = [
5
9
  "create_component_id",
6
- "set_component_id"
10
+ "set_component_id",
11
+ "create_binary_mixture_id",
7
12
  ]
@@ -105,3 +105,85 @@ def set_component_id(
105
105
  f"'{component}': {e}"
106
106
  )
107
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.2
3
+ Version: 0.1.4
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=vOAWpWG2BtmC2n4vqLEpLmZeytlYxk4WMGk0CQhMbXA,379
4
+ pythermodb_settings/configs/about.py,sha256=Trp6S4eoy8ZC8KtiOaukejgMVYLM4SjCn74BHK4Lcz0,379
5
5
  pythermodb_settings/models/__init__.py,sha256=N0zptTFnWTNEcQQ00WFXXF5i3Xxq_zjbpSdIyhGRu7g,649
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
- pythermodb_settings/models/references.py,sha256=_MicXRkUdmZLMiuQEhMm2kJzmApHvz_CnjLaxxnueLg,5399
9
+ pythermodb_settings/models/references.py,sha256=A27Y-7L8X-g2m-pxuDk0ateFScPE1MMEyoR1SH8VDVA,6359
10
10
  pythermodb_settings/models/rules.py,sha256=1a9CyTHwpQkZQXFJWDMrEcKQAOTOwquepoOQPGznTlc,74
11
11
  pythermodb_settings/models/source.py,sha256=liN4v1o8mqxclz8khca4anTOzLHO-5gCnK0MsfVgxGY,533
12
- pythermodb_settings/utils/__init__.py,sha256=Vc3UjM42beWALBoqNV6Vx71ofC2CjYNxUUvFgR44lvk,148
13
- pythermodb_settings/utils/component_utils.py,sha256=uL-_WWl8Wat1LEFMpodmQe1BklzY7yI8enguWYeSWwo,3196
14
- pythermodb_settings-0.1.2.dist-info/licenses/LICENSE,sha256=pHRAx3wjVKpt2ec3NyhntY6_bGgJqV2SyE8xNUJ7MYE,1090
15
- pythermodb_settings-0.1.2.dist-info/METADATA,sha256=SDi6-9y2tSUaG6d2azVYan79R_767aGA009AU-nMwt0,4894
16
- pythermodb_settings-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- pythermodb_settings-0.1.2.dist-info/top_level.txt,sha256=6IdVIbW__wHFsKQYx7DDnXArm10qiJVIyaoSEFQylK4,20
18
- pythermodb_settings-0.1.2.dist-info/RECORD,,
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.4.dist-info/licenses/LICENSE,sha256=pHRAx3wjVKpt2ec3NyhntY6_bGgJqV2SyE8xNUJ7MYE,1090
15
+ pythermodb_settings-0.1.4.dist-info/METADATA,sha256=vz5T-OYIG6b3VKe_emOeraoCsryJ-5iktwCAlhDVIhs,4894
16
+ pythermodb_settings-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ pythermodb_settings-0.1.4.dist-info/top_level.txt,sha256=6IdVIbW__wHFsKQYx7DDnXArm10qiJVIyaoSEFQylK4,20
18
+ pythermodb_settings-0.1.4.dist-info/RECORD,,