pyreactlab-core 0.1.0__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.
- pyreactlab_core/__init__.py +25 -0
- pyreactlab_core/app.py +123 -0
- pyreactlab_core/configs/__init__.py +0 -0
- pyreactlab_core/configs/constants.py +40 -0
- pyreactlab_core/configs/info.py +12 -0
- pyreactlab_core/core/__init__.py +1 -0
- pyreactlab_core/core/chem_react.py +839 -0
- pyreactlab_core/docs/__init__.py +14 -0
- pyreactlab_core/docs/chem_balance.py +719 -0
- pyreactlab_core/docs/chem_utils.py +114 -0
- pyreactlab_core/models/__init__.py +0 -0
- pyreactlab_core/models/reaction.py +174 -0
- pyreactlab_core/utils/__init__.py +0 -0
- pyreactlab_core/utils/tools.py +30 -0
- pyreactlab_core-0.1.0.dist-info/METADATA +179 -0
- pyreactlab_core-0.1.0.dist-info/RECORD +19 -0
- pyreactlab_core-0.1.0.dist-info/WHEEL +5 -0
- pyreactlab_core-0.1.0.dist-info/licenses/LICENSE +201 -0
- pyreactlab_core-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# config
|
|
2
|
+
from .configs.info import (
|
|
3
|
+
__version__,
|
|
4
|
+
__author__,
|
|
5
|
+
__package_name__,
|
|
6
|
+
__description__,
|
|
7
|
+
__email__,
|
|
8
|
+
__license__,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
from .app import rxn, rxn_stoichiometry, rxns_stoichiometry
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
# config
|
|
15
|
+
"__version__",
|
|
16
|
+
"__author__",
|
|
17
|
+
"__package_name__",
|
|
18
|
+
"__description__",
|
|
19
|
+
"__email__",
|
|
20
|
+
"__license__",
|
|
21
|
+
# app
|
|
22
|
+
"rxn",
|
|
23
|
+
"rxn_stoichiometry",
|
|
24
|
+
"rxns_stoichiometry",
|
|
25
|
+
]
|
pyreactlab_core/app.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# import libs
|
|
2
|
+
import logging
|
|
3
|
+
from typing import List, Optional, Dict
|
|
4
|
+
# locals
|
|
5
|
+
from .models.reaction import Reaction
|
|
6
|
+
from .docs.chem_utils import build_stoichiometry_matrix
|
|
7
|
+
|
|
8
|
+
# NOTE: configure logger
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def rxn(
|
|
13
|
+
reaction_str: str,
|
|
14
|
+
name: Optional[str] = None
|
|
15
|
+
) -> Optional[Reaction]:
|
|
16
|
+
"""
|
|
17
|
+
Create and analyze a chemical reaction.
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
reaction_str : str
|
|
22
|
+
reaction expression string such as "A + B => C + D"
|
|
23
|
+
name : Optional[str]
|
|
24
|
+
Name of the reaction
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
Reaction
|
|
29
|
+
An instance of the Reaction class containing analysis results.
|
|
30
|
+
"""
|
|
31
|
+
try:
|
|
32
|
+
# SECTION: validate inputs
|
|
33
|
+
if not isinstance(reaction_str, str) or not reaction_str.strip():
|
|
34
|
+
logger.error("Invalid reaction string provided.")
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
# check name format
|
|
38
|
+
if name is not None and not isinstance(name, str):
|
|
39
|
+
logger.error("Invalid name format provided.")
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
# SECTION: create Reaction instance
|
|
43
|
+
reaction = Reaction(
|
|
44
|
+
name=name if name else "Unnamed Reaction",
|
|
45
|
+
reaction=reaction_str
|
|
46
|
+
)
|
|
47
|
+
return reaction
|
|
48
|
+
except Exception as e:
|
|
49
|
+
logger.error(f"Error creating Reaction instance: {e}")
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def rxn_stoichiometry(
|
|
54
|
+
reaction: Reaction,
|
|
55
|
+
) -> Optional[List[float]]:
|
|
56
|
+
"""
|
|
57
|
+
Get the reaction stoichiometry matrix for a given chemical reaction.
|
|
58
|
+
|
|
59
|
+
Parameters
|
|
60
|
+
----------
|
|
61
|
+
reaction : Reaction
|
|
62
|
+
An instance of the Reaction class.
|
|
63
|
+
|
|
64
|
+
Returns
|
|
65
|
+
-------
|
|
66
|
+
Optional[List[float]]
|
|
67
|
+
The reaction stoichiometry matrix if successful, None otherwise.
|
|
68
|
+
"""
|
|
69
|
+
try:
|
|
70
|
+
# SECTION: validate inputs
|
|
71
|
+
if not isinstance(reaction, Reaction):
|
|
72
|
+
logger.error("Invalid Reaction instance provided.")
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
# SECTION: retrieve stoichiometry matrix
|
|
76
|
+
if reaction:
|
|
77
|
+
return reaction.reaction_stoichiometry_matrix
|
|
78
|
+
else:
|
|
79
|
+
logger.error("Failed to create Reaction instance.")
|
|
80
|
+
return None
|
|
81
|
+
except Exception as e:
|
|
82
|
+
logger.error(f"Error retrieving reaction stoichiometry matrix: {e}")
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def rxns_stoichiometry(
|
|
87
|
+
reactions: List[Reaction],
|
|
88
|
+
) -> Optional[Dict]:
|
|
89
|
+
"""
|
|
90
|
+
Get the reaction stoichiometry matrices for a list of chemical reactions.
|
|
91
|
+
|
|
92
|
+
Parameters
|
|
93
|
+
----------
|
|
94
|
+
reactions : List[Reaction]
|
|
95
|
+
List of Reaction instances.
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
Optional[List[List[float]]]
|
|
100
|
+
List of reaction stoichiometry matrices if successful, None otherwise.
|
|
101
|
+
"""
|
|
102
|
+
try:
|
|
103
|
+
# SECTION: validate inputs
|
|
104
|
+
if (
|
|
105
|
+
not isinstance(reactions, list) or
|
|
106
|
+
not all(isinstance(rxn, Reaction) for rxn in reactions)
|
|
107
|
+
):
|
|
108
|
+
logger.error("Invalid reactions list provided.")
|
|
109
|
+
return None
|
|
110
|
+
|
|
111
|
+
# SECTION: retrieve stoichiometry matrices
|
|
112
|
+
result = build_stoichiometry_matrix(reactions=reactions)
|
|
113
|
+
|
|
114
|
+
# NOTE: res
|
|
115
|
+
return {
|
|
116
|
+
"components": result["component_list"],
|
|
117
|
+
"component_ids": result["component_dict"],
|
|
118
|
+
"stoichiometry_matrices_list": result["comp_coeff"],
|
|
119
|
+
"stoichiometry_matrices_dict": result["comp_list"],
|
|
120
|
+
}
|
|
121
|
+
except Exception as e:
|
|
122
|
+
logger.error(f"Error retrieving reaction stoichiometry matrices: {e}")
|
|
123
|
+
return None
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# import libs
|
|
2
|
+
|
|
3
|
+
# SECTION: PyThermoDBLink/PyThermoDB
|
|
4
|
+
import math
|
|
5
|
+
DATASOURCE = "datasource"
|
|
6
|
+
EQUATIONSOURCE = "equationsource"
|
|
7
|
+
|
|
8
|
+
# NOTE: universal gas constant [J/mol.K]
|
|
9
|
+
R_CONST_J__molK = 8.314472
|
|
10
|
+
|
|
11
|
+
# NOTE: pi
|
|
12
|
+
PI_CONST = math.pi
|
|
13
|
+
|
|
14
|
+
# NOTE: STP condition
|
|
15
|
+
# pressure [Pa]
|
|
16
|
+
PRESSURE_STP_Pa = 101325
|
|
17
|
+
# temperature [K]
|
|
18
|
+
TEMPERATURE_STP_K = 273.15
|
|
19
|
+
# reference pressure [Pa]
|
|
20
|
+
PRESSURE_REF_Pa = 101325
|
|
21
|
+
# reference temperature [K]
|
|
22
|
+
TEMPERATURE_REF_K = 298.15
|
|
23
|
+
|
|
24
|
+
# SECTION: Periodic Table Elements
|
|
25
|
+
PERIODIC_TABLE_ELEMENTS = [
|
|
26
|
+
"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne",
|
|
27
|
+
"Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar",
|
|
28
|
+
"K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni",
|
|
29
|
+
"Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr",
|
|
30
|
+
"Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd",
|
|
31
|
+
"Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe",
|
|
32
|
+
"Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd",
|
|
33
|
+
"Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu",
|
|
34
|
+
"Hf", "Ta", "W", "Re", "Os", "Ir", "Pt",
|
|
35
|
+
"Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn",
|
|
36
|
+
"Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu",
|
|
37
|
+
"Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr",
|
|
38
|
+
"Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn",
|
|
39
|
+
"Nh", "Fl", "Mc", "Lv", "Ts", "Og",
|
|
40
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# version
|
|
2
|
+
__version__ = "0.1.0"
|
|
3
|
+
# author
|
|
4
|
+
__author__ = "Sina Gilassi"
|
|
5
|
+
# email
|
|
6
|
+
__email__ = "sina.gilassi@gmail.com"
|
|
7
|
+
# license
|
|
8
|
+
__license__ = "Apache-2.0"
|
|
9
|
+
# package name
|
|
10
|
+
__package_name__ = "PyReactLab-Core"
|
|
11
|
+
# package description
|
|
12
|
+
__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."
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|