pyreactlab-core 0.1.4__tar.gz → 0.1.5__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 (25) hide show
  1. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/PKG-INFO +1 -1
  2. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyproject.toml +1 -1
  3. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/configs/info.py +1 -1
  4. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/core/chem_react.py +56 -2
  5. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/models/reaction.py +16 -3
  6. pyreactlab_core-0.1.5/pyreactlab_core/utils/component_tools.py +36 -0
  7. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core.egg-info/PKG-INFO +1 -1
  8. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core.egg-info/SOURCES.txt +1 -0
  9. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/LICENSE +0 -0
  10. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/README.md +0 -0
  11. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/__init__.py +0 -0
  12. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/app.py +0 -0
  13. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/configs/__init__.py +0 -0
  14. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/configs/constants.py +0 -0
  15. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/core/__init__.py +0 -0
  16. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/docs/__init__.py +0 -0
  17. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/docs/chem_balance.py +0 -0
  18. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/docs/chem_utils.py +0 -0
  19. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/models/__init__.py +0 -0
  20. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/utils/__init__.py +0 -0
  21. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core/utils/tools.py +0 -0
  22. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core.egg-info/dependency_links.txt +0 -0
  23. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core.egg-info/requires.txt +0 -0
  24. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/pyreactlab_core.egg-info/top_level.txt +0 -0
  25. {pyreactlab_core-0.1.4 → pyreactlab_core-0.1.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyreactlab-core
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: pyreactlab-core is the core foundation of the PyReactLab ecosystem, offering shared data structures and algorithms for chemical reaction representation, stoichiometry, and reaction analysis.
5
5
  Author-email: Sina Gilassi <sina.gilassi@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pyreactlab-core"
7
- version = "0.1.4"
7
+ version = "0.1.5"
8
8
  description = "pyreactlab-core is the core foundation of the PyReactLab ecosystem, offering shared data structures and algorithms for chemical reaction representation, stoichiometry, and reaction analysis."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -1,5 +1,5 @@
1
1
  # version
2
- __version__ = "0.1.4"
2
+ __version__ = "0.1.5"
3
3
  # author
4
4
  __author__ = "Sina Gilassi"
5
5
  # email
@@ -2,13 +2,16 @@
2
2
  import logging
3
3
  import re
4
4
  from typing import Dict, Any, List, Optional, Literal, TypedDict
5
- from pythermodb_settings.models import Component
5
+ from pythermodb_settings.models import Component, ComponentKey
6
+ from pythermodb_settings.utils import set_component_id
7
+ # locals
6
8
  from ..configs.constants import (
7
9
  R_CONST_J__molK,
8
10
  PRESSURE_REF_Pa,
9
11
  TEMPERATURE_REF_K,
10
12
  )
11
13
 
14
+
12
15
  # NOTE: logger
13
16
  logger = logging.getLogger(__name__)
14
17
 
@@ -72,7 +75,8 @@ class ChemReact:
72
75
  def __init__(
73
76
  self,
74
77
  reaction_mode_symbol: ReactionMode,
75
- components: Optional[List[Component]]
78
+ components: Optional[List[Component]],
79
+ component_key: ComponentKey
76
80
  ):
77
81
  """
78
82
  Initialize the ChemReactUtils class.
@@ -83,6 +87,8 @@ class ChemReact:
83
87
  The symbol used to separate reactants and products in a reaction equation.
84
88
  components : Optional[List[Component]]
85
89
  A list of Component objects involved in the reaction.
90
+ component_key : ComponentKey
91
+ The key used to identify components in the reaction.
86
92
 
87
93
  Notes
88
94
  -----
@@ -98,6 +104,9 @@ class ChemReact:
98
104
  # NOTE: set components
99
105
  self.components = components
100
106
 
107
+ # NOTE: set component key
108
+ self.component_key = component_key
109
+
101
110
  # SECTION: Component id
102
111
  # NOTE: component ids
103
112
  if components is None:
@@ -396,6 +405,11 @@ class ChemReact:
396
405
  products,
397
406
  )
398
407
 
408
+ # SECTION: reaction stoichiometry dict
409
+ reaction_stoichiometry_dict = self.reaction_stoichiometry_dict(
410
+ reaction_stoichiometry
411
+ )
412
+
399
413
  # res
400
414
  res = {
401
415
  'name': name,
@@ -411,6 +425,7 @@ class ChemReact:
411
425
  'reaction_coefficients': reaction_coefficients,
412
426
  'reaction_stoichiometry': reaction_stoichiometry,
413
427
  'reaction_stoichiometry_matrix': reaction_stoichiometry_matrix,
428
+ 'reaction_stoichiometry_dict': reaction_stoichiometry_dict,
414
429
  'carbon_count': carbon_count,
415
430
  'reaction_state': reaction_state,
416
431
  'reaction_phase': reaction_phase,
@@ -1017,3 +1032,42 @@ class ChemReact:
1017
1032
  return component_map
1018
1033
  except Exception as e:
1019
1034
  raise Exception(f"Error mapping components: {e}")
1035
+
1036
+ def reaction_stoichiometry_dict(
1037
+ self,
1038
+ reaction_stoichiometry: Dict[str, float],
1039
+ ) -> Dict[str, float]:
1040
+ '''
1041
+ Generate the reaction stoichiometry matrix.
1042
+
1043
+ Parameters
1044
+ ----------
1045
+ reaction_stoichiometry: dict
1046
+ A dictionary containing the stoichiometry of the reaction, where keys are component IDs and values are their coefficients.
1047
+
1048
+ Returns
1049
+ -------
1050
+ dict
1051
+ A dictionary representing the reaction stoichiometry, where keys are component IDs and values are their coefficients.
1052
+ '''
1053
+ # >> check
1054
+ if self.components is None:
1055
+ return {}
1056
+
1057
+ # NOTE: component ids
1058
+ component_ids = list(reaction_stoichiometry.keys())
1059
+
1060
+ id_to_component = {}
1061
+ for comp in self.components:
1062
+ comp_id = set_component_id(comp, 'Formula-State') # type: ignore
1063
+ if comp_id in component_ids:
1064
+ # create component id
1065
+ comp_id_new = set_component_id(
1066
+ comp,
1067
+ self.component_key) # type: ignore
1068
+ id_to_component[comp_id_new] = reaction_stoichiometry[comp_id]
1069
+ else:
1070
+ logging.warning(
1071
+ f"Component '{comp_id}' not found in reaction stoichiometry.")
1072
+
1073
+ return id_to_component
@@ -1,9 +1,9 @@
1
1
  # import libs
2
2
  from __future__ import annotations
3
-
3
+ import logging
4
4
  from typing import Any, Dict, Optional, List
5
5
  from pydantic import BaseModel, Field, computed_field, model_validator
6
- from pythermodb_settings.models import Component
6
+ from pythermodb_settings.models import Component, ComponentKey
7
7
  # local imports
8
8
  from ..core.chem_react import (
9
9
  ChemReact,
@@ -11,6 +11,9 @@ from ..core.chem_react import (
11
11
  PhaseRule
12
12
  )
13
13
 
14
+ # NOTE: set up logger
15
+ logger = logging.getLogger(__name__)
16
+
14
17
 
15
18
  class Reaction(BaseModel):
16
19
  """
@@ -79,6 +82,10 @@ class Reaction(BaseModel):
79
82
  default_factory=dict,
80
83
  description="A dictionary containing the analysis results of the reaction."
81
84
  )
85
+ component_key: ComponentKey = Field(
86
+ default='Name-Formula',
87
+ description="The key used to identify components in the reaction analysis."
88
+ )
82
89
 
83
90
  @model_validator(mode="after")
84
91
  def _run_existing_analysis(self):
@@ -97,7 +104,8 @@ class Reaction(BaseModel):
97
104
  # NOTE: analyze reaction
98
105
  util = ChemReact(
99
106
  reaction_mode_symbol=self.reaction_mode_symbol,
100
- components=self.components
107
+ components=self.components,
108
+ component_key=self.component_key
101
109
  )
102
110
 
103
111
  # NOTE: perform analysis
@@ -154,6 +162,11 @@ class Reaction(BaseModel):
154
162
  def reaction_stoichiometry_matrix(self) -> list[float]:
155
163
  return self.analysis.get("reaction_stoichiometry_matrix", [])
156
164
 
165
+ @computed_field
166
+ @property
167
+ def reaction_stoichiometry_dict(self) -> Dict[str, float]:
168
+ return self.analysis.get("reaction_stoichiometry_dict", {})
169
+
157
170
  @computed_field
158
171
  @property
159
172
  def carbon_count(self) -> int:
@@ -0,0 +1,36 @@
1
+ # import libs
2
+ import logging
3
+ from typing import Dict, Any, List, Optional, Literal
4
+ from pythermodb_settings.models import Component, ComponentKey
5
+ from pythermodb_settings.utils import set_component_id
6
+
7
+
8
+ def map_component_ids(
9
+ component_ids: list[str],
10
+ component: List[Component],
11
+ component_key: ComponentKey
12
+ ):
13
+ """
14
+ Map component IDs to their corresponding components.
15
+
16
+ Parameters
17
+ ----------
18
+ component_ids : list[str]
19
+ A list of component IDs to be mapped.
20
+ component : List[Component]
21
+ A list of Component objects to be mapped against.
22
+ component_key : ComponentKey
23
+ The key used to identify components in the reaction.
24
+
25
+ Returns
26
+ -------
27
+ Dict[str, Component]
28
+ A dictionary mapping component IDs to their corresponding Component objects.
29
+ """
30
+ id_to_component = {}
31
+ for comp in component:
32
+ comp_id = set_component_id(comp, component_key)
33
+ if comp_id in component_ids:
34
+ id_to_component[comp_id] = comp
35
+
36
+ return id_to_component
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyreactlab-core
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: pyreactlab-core is the core foundation of the PyReactLab ecosystem, offering shared data structures and algorithms for chemical reaction representation, stoichiometry, and reaction analysis.
5
5
  Author-email: Sina Gilassi <sina.gilassi@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -19,4 +19,5 @@ pyreactlab_core/docs/chem_utils.py
19
19
  pyreactlab_core/models/__init__.py
20
20
  pyreactlab_core/models/reaction.py
21
21
  pyreactlab_core/utils/__init__.py
22
+ pyreactlab_core/utils/component_tools.py
22
23
  pyreactlab_core/utils/tools.py
File without changes