PyThermoLinkDB 1.4.16__tar.gz → 1.5.0__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.
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/PKG-INFO +1 -1
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/PyThermoLinkDB.egg-info/SOURCES.txt +2 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/__init__.py +3 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/app.py +331 -18
- pythermolinkdb-1.5.0/pyThermoLinkDB/config/__init__.py +21 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/config/constants.py +2 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/config/settings.py +1 -1
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/docs/thermodbhub.py +213 -11
- pythermolinkdb-1.5.0/pyThermoLinkDB/docs/thermolink.py +635 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/docs/thermoutils.py +78 -1
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/models/__init__.py +3 -1
- pythermolinkdb-1.5.0/pyThermoLinkDB/models/source.py +224 -0
- pythermolinkdb-1.5.0/pyThermoLinkDB/thermo/constants_source.py +29 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/thermo/context.py +324 -324
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/thermo/data_source.py +1 -1
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/thermo/equation_source.py +4 -1
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/thermo/main.py +42 -1
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/thermo/source.py +603 -104
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/utils/__init__.py +10 -2
- pythermolinkdb-1.5.0/pyThermoLinkDB/utils/input_builder.py +238 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/utils/properties.py +332 -4
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyproject.toml +1 -1
- pythermolinkdb-1.4.16/pyThermoLinkDB/config/__init__.py +0 -11
- pythermolinkdb-1.4.16/pyThermoLinkDB/docs/thermolink.py +0 -321
- pythermolinkdb-1.4.16/pyThermoLinkDB/models/source.py +0 -121
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/LICENSE +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/MANIFEST.in +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/README.md +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/config/deps.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/docs/__init__.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/docs/utils.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/models/component_models.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/models/ref.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/thermo/__init__.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/thermo/equation_sources.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/utils/convertor.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/utils/loader.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/pyThermoLinkDB/utils/tools.py +0 -0
- {pythermolinkdb-1.4.16 → pythermolinkdb-1.5.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyThermoLinkDB
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
4
4
|
Summary: PyThermoLinkDB is a Python package providing a robust and efficient interface between `PyThermoDB` and other applications.
|
|
5
5
|
Author-email: Sina Gilassi <sina.gilassi@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -18,6 +18,7 @@ pyThermoLinkDB/models/component_models.py
|
|
|
18
18
|
pyThermoLinkDB/models/ref.py
|
|
19
19
|
pyThermoLinkDB/models/source.py
|
|
20
20
|
pyThermoLinkDB/thermo/__init__.py
|
|
21
|
+
pyThermoLinkDB/thermo/constants_source.py
|
|
21
22
|
pyThermoLinkDB/thermo/context.py
|
|
22
23
|
pyThermoLinkDB/thermo/data_source.py
|
|
23
24
|
pyThermoLinkDB/thermo/equation_source.py
|
|
@@ -26,6 +27,7 @@ pyThermoLinkDB/thermo/main.py
|
|
|
26
27
|
pyThermoLinkDB/thermo/source.py
|
|
27
28
|
pyThermoLinkDB/utils/__init__.py
|
|
28
29
|
pyThermoLinkDB/utils/convertor.py
|
|
30
|
+
pyThermoLinkDB/utils/input_builder.py
|
|
29
31
|
pyThermoLinkDB/utils/loader.py
|
|
30
32
|
pyThermoLinkDB/utils/properties.py
|
|
31
33
|
pyThermoLinkDB/utils/tools.py
|
|
@@ -6,6 +6,7 @@ from .app import (
|
|
|
6
6
|
init,
|
|
7
7
|
build_component_model_source,
|
|
8
8
|
build_components_model_source,
|
|
9
|
+
build_constants_model_source,
|
|
9
10
|
build_model_source,
|
|
10
11
|
load_and_build_model_source,
|
|
11
12
|
load_and_build_component_model_source,
|
|
@@ -25,6 +26,7 @@ from .thermo import (
|
|
|
25
26
|
)
|
|
26
27
|
|
|
27
28
|
__all__ = [
|
|
29
|
+
# config
|
|
28
30
|
"__author__",
|
|
29
31
|
"__version__",
|
|
30
32
|
"__description__",
|
|
@@ -32,6 +34,7 @@ __all__ = [
|
|
|
32
34
|
"init",
|
|
33
35
|
"build_component_model_source",
|
|
34
36
|
"build_components_model_source",
|
|
37
|
+
"build_constants_model_source",
|
|
35
38
|
"build_model_source",
|
|
36
39
|
"load_and_build_model_source",
|
|
37
40
|
"build_mixture_model_source",
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# import packages/modules
|
|
2
2
|
import logging
|
|
3
|
-
from typing import Dict, List, Optional, Literal
|
|
3
|
+
from typing import Dict, List, Optional, Literal, Any
|
|
4
4
|
import pyThermoDB as ptdb
|
|
5
|
-
from pyThermoDB import
|
|
5
|
+
from pyThermoDB import (
|
|
6
|
+
CompBuilder,
|
|
7
|
+
ComponentThermoDB,
|
|
8
|
+
MixtureThermoDB,
|
|
9
|
+
ConstantsThermoDB
|
|
10
|
+
)
|
|
6
11
|
from pythermodb_settings.models import (
|
|
7
12
|
Component,
|
|
8
13
|
ComponentConfig,
|
|
@@ -13,7 +18,13 @@ from pythermodb_settings.models import (
|
|
|
13
18
|
)
|
|
14
19
|
# local
|
|
15
20
|
from .docs import ThermoDBHub
|
|
16
|
-
from .
|
|
21
|
+
from .docs.thermoutils import ThermoUtils
|
|
22
|
+
from .models import (
|
|
23
|
+
ModelSource,
|
|
24
|
+
ComponentModelSource,
|
|
25
|
+
MixtureModelSource,
|
|
26
|
+
ConstantsModelSource
|
|
27
|
+
)
|
|
17
28
|
from .utils import (
|
|
18
29
|
set_component_key,
|
|
19
30
|
create_rules_from_str,
|
|
@@ -21,7 +32,11 @@ from .utils import (
|
|
|
21
32
|
look_up_component_rules,
|
|
22
33
|
find_mixture_ids_in_rules,
|
|
23
34
|
normalize_rules,
|
|
24
|
-
look_up_mixture_rules
|
|
35
|
+
look_up_mixture_rules,
|
|
36
|
+
look_up_constants_rules,
|
|
37
|
+
look_up_default_rules,
|
|
38
|
+
combine_rules_into_constants_key,
|
|
39
|
+
extract_labels_from_constants_rules
|
|
25
40
|
)
|
|
26
41
|
from .config import DEFAULT_RULES_KEY
|
|
27
42
|
# ! deps
|
|
@@ -31,6 +46,7 @@ from .config.deps import set_config, AppConfig
|
|
|
31
46
|
logger = logging.getLogger(__name__)
|
|
32
47
|
|
|
33
48
|
|
|
49
|
+
# SECTION: init thermodb hub
|
|
34
50
|
def init() -> ThermoDBHub:
|
|
35
51
|
'''
|
|
36
52
|
Init thermolinkdb app
|
|
@@ -51,6 +67,7 @@ def init() -> ThermoDBHub:
|
|
|
51
67
|
raise Exception("Error: {}".format(e))
|
|
52
68
|
|
|
53
69
|
|
|
70
|
+
# SECTION: build component model source
|
|
54
71
|
def build_component_model_source(
|
|
55
72
|
component_thermodb: ComponentThermoDB,
|
|
56
73
|
rules: Optional[
|
|
@@ -92,7 +109,7 @@ def build_component_model_source(
|
|
|
92
109
|
try:
|
|
93
110
|
# SECTION: create thermodb hub
|
|
94
111
|
try:
|
|
95
|
-
thermodb_hub = init()
|
|
112
|
+
thermodb_hub: ThermoDBHub = init()
|
|
96
113
|
except Exception as e:
|
|
97
114
|
logger.error(f"Error in init thermodb hub: {e}")
|
|
98
115
|
raise Exception(f"Error in init thermodb hub: {e}")
|
|
@@ -325,6 +342,7 @@ def build_component_model_source(
|
|
|
325
342
|
rule_ = None
|
|
326
343
|
|
|
327
344
|
# NOTE: name state as id
|
|
345
|
+
# ! thermodb_hub contains methods to transform the thermodb data and equations based on the provided rules, and build the model source data source and equation source
|
|
328
346
|
# >> add
|
|
329
347
|
add_thermodb_res_ = thermodb_hub.add_thermodb(
|
|
330
348
|
name=name_state,
|
|
@@ -373,6 +391,7 @@ def build_component_model_source(
|
|
|
373
391
|
f"Failed to add thermodb for component: {name_formula}")
|
|
374
392
|
|
|
375
393
|
# SECTION: build component model source
|
|
394
|
+
# ! thermodb_hub builds the data source and equation source based on the added thermodb and rules, and the built data source and equation source are used to create the component model source
|
|
376
395
|
datasource, equationsource = thermodb_hub.build()
|
|
377
396
|
|
|
378
397
|
# NOTE: create component model source
|
|
@@ -389,6 +408,8 @@ def build_component_model_source(
|
|
|
389
408
|
logger.error(f"Error in build_component_model_source: {e}")
|
|
390
409
|
raise Exception(f"Error in build_component_model_source: {e}")
|
|
391
410
|
|
|
411
|
+
# SECTION: build components model source
|
|
412
|
+
|
|
392
413
|
|
|
393
414
|
def build_components_model_source(
|
|
394
415
|
components_thermodb: List[ComponentThermoDB],
|
|
@@ -444,6 +465,7 @@ def build_components_model_source(
|
|
|
444
465
|
raise Exception(f"Error in build_components_model_source: {e}")
|
|
445
466
|
|
|
446
467
|
|
|
468
|
+
# SECTION: build mixture model source
|
|
447
469
|
def build_mixture_model_source(
|
|
448
470
|
mixture_thermodb: MixtureThermoDB,
|
|
449
471
|
rules: Optional[
|
|
@@ -789,6 +811,8 @@ def build_mixture_model_source(
|
|
|
789
811
|
logger.error(f"Error in build_mixture_model_source: {e}")
|
|
790
812
|
raise Exception(f"Error in build_mixture_model_source: {e}")
|
|
791
813
|
|
|
814
|
+
# SECTION: build mixture model source for multiple mixtures
|
|
815
|
+
|
|
792
816
|
|
|
793
817
|
def build_mixtures_model_source(
|
|
794
818
|
mixtures_thermodb: List[MixtureThermoDB],
|
|
@@ -851,17 +875,261 @@ def build_mixtures_model_source(
|
|
|
851
875
|
logger.error(f"Error in build_mixtures_model_source: {e}")
|
|
852
876
|
raise Exception(f"Error in build_mixtures_model_source: {e}")
|
|
853
877
|
|
|
878
|
+
# SECTION: build constant model source
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
def build_constants_model_source(
|
|
882
|
+
constants_thermodb: ConstantsThermoDB,
|
|
883
|
+
rules: Optional[
|
|
884
|
+
Dict[str, Dict[str, ComponentRule]] | str
|
|
885
|
+
] = None,
|
|
886
|
+
check_labels: bool = True,
|
|
887
|
+
overwrite_rules: bool = False,
|
|
888
|
+
verbose: bool = False,
|
|
889
|
+
) -> ConstantsModelSource:
|
|
890
|
+
try:
|
|
891
|
+
# SECTION: create thermodb hub
|
|
892
|
+
try:
|
|
893
|
+
thermodb_hub: ThermoDBHub = init()
|
|
894
|
+
except Exception as e:
|
|
895
|
+
logger.error(f"Error in init thermodb hub: {e}")
|
|
896
|
+
raise Exception(f"Error in init thermodb hub: {e}")
|
|
897
|
+
|
|
898
|
+
# SECTION: extract constants thermodb
|
|
899
|
+
# NOTE: thermodb
|
|
900
|
+
thermodb: CompBuilder = constants_thermodb.thermodb
|
|
901
|
+
# NOTE: reference thermodb
|
|
902
|
+
# ! reference thermodb is optional
|
|
903
|
+
reference_thermodb: Optional[ReferenceThermoDB] = constants_thermodb.reference_thermodb
|
|
904
|
+
|
|
905
|
+
# check reference thermodb
|
|
906
|
+
if reference_thermodb:
|
|
907
|
+
# ! >>> reference configs
|
|
908
|
+
reference_configs: Dict[
|
|
909
|
+
str,
|
|
910
|
+
ComponentConfig
|
|
911
|
+
] = reference_thermodb.configs
|
|
912
|
+
|
|
913
|
+
# ! >>> reference rules
|
|
914
|
+
reference_rules: Dict[
|
|
915
|
+
str,
|
|
916
|
+
ComponentRule
|
|
917
|
+
] = reference_thermodb.rules
|
|
918
|
+
|
|
919
|
+
# ! >>> labels
|
|
920
|
+
labels: List[str] = reference_thermodb.labels if reference_thermodb.labels else [
|
|
921
|
+
]
|
|
922
|
+
|
|
923
|
+
# ! >>> ignore labels
|
|
924
|
+
ignore_labels: List[str] = reference_thermodb.ignore_labels if reference_thermodb.ignore_labels else [
|
|
925
|
+
]
|
|
926
|
+
|
|
927
|
+
# ! >>> ignore props
|
|
928
|
+
ignore_props: List[str] = reference_thermodb.ignore_props if reference_thermodb.ignore_props else [
|
|
929
|
+
]
|
|
930
|
+
|
|
931
|
+
# ?? constants ids
|
|
932
|
+
constants_ids = list(reference_configs.keys())
|
|
933
|
+
else:
|
|
934
|
+
# ! set empty
|
|
935
|
+
reference_configs = {}
|
|
936
|
+
# >> for the case of no reference (reference_thermodb), set empty rules
|
|
937
|
+
reference_rules = {}
|
|
938
|
+
labels = []
|
|
939
|
+
ignore_labels = []
|
|
940
|
+
ignore_props = []
|
|
941
|
+
# constants ids
|
|
942
|
+
constants_ids = []
|
|
943
|
+
|
|
944
|
+
# NOTE: constant rules
|
|
945
|
+
# create dict to hold constant rules
|
|
946
|
+
if rules is None:
|
|
947
|
+
constant_rules_dict: Dict[str, Dict[str, ComponentRule]] = {
|
|
948
|
+
'Constants': reference_rules
|
|
949
|
+
}
|
|
950
|
+
else:
|
|
951
|
+
constant_rules_dict: Dict[str, Dict[str, ComponentRule]] = {
|
|
952
|
+
'Constants': {}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
# SECTION: check rules
|
|
956
|
+
if rules:
|
|
957
|
+
# NOTE: verbose
|
|
958
|
+
if verbose:
|
|
959
|
+
logger.info(
|
|
960
|
+
f"Checking rules for constants: using provided rules"
|
|
961
|
+
)
|
|
962
|
+
|
|
963
|
+
# NOTE: overwrite existing rules in the thermodb hub
|
|
964
|
+
if overwrite_rules:
|
|
965
|
+
# reset constant_rules_dict
|
|
966
|
+
constant_rules_dict = {}
|
|
967
|
+
|
|
968
|
+
# >> log
|
|
969
|
+
if verbose:
|
|
970
|
+
logger.info(
|
|
971
|
+
"Overwriting existing rules in the thermodb hub"
|
|
972
|
+
)
|
|
973
|
+
|
|
974
|
+
# NOTE: load rules
|
|
975
|
+
if isinstance(rules, str):
|
|
976
|
+
try:
|
|
977
|
+
rules = create_rules_from_str(rules)
|
|
978
|
+
except Exception as e:
|
|
979
|
+
logger.error(f"Error in load rules from file: {e}")
|
|
980
|
+
raise Exception(f"Error in load rules from file: {e}")
|
|
981
|
+
elif not isinstance(rules, dict):
|
|
982
|
+
logger.error(
|
|
983
|
+
"Rules must be a dictionary or a file path to a YAML file.")
|
|
984
|
+
raise ValueError(
|
|
985
|
+
"Rules must be a dictionary or a file path to a YAML file.")
|
|
986
|
+
|
|
987
|
+
# NOTE: check for constant rules if exists
|
|
988
|
+
# >> iterate over constants ids
|
|
989
|
+
for constants_id in constants_ids:
|
|
990
|
+
constant_rules_ = look_up_constants_rules(
|
|
991
|
+
constants_id=constants_id,
|
|
992
|
+
rules=rules,
|
|
993
|
+
)
|
|
994
|
+
|
|
995
|
+
if constant_rules_:
|
|
996
|
+
constant_rules_dict[constants_id] = constant_rules_
|
|
997
|
+
|
|
998
|
+
# NOTE: check if `constant_rules_dict` is still empty, then use default rules if exists
|
|
999
|
+
all_empty = True
|
|
1000
|
+
|
|
1001
|
+
for key in constant_rules_dict:
|
|
1002
|
+
# skip 'Constants' key
|
|
1003
|
+
if key == 'Constants':
|
|
1004
|
+
continue
|
|
1005
|
+
|
|
1006
|
+
# check if rules for this constants id is not empty
|
|
1007
|
+
if len(constant_rules_dict[key]) > 0:
|
|
1008
|
+
all_empty = False
|
|
1009
|
+
break
|
|
1010
|
+
|
|
1011
|
+
# ! combine all rules into 'Constants' key if all other keys are empty
|
|
1012
|
+
combined_rules = combine_rules_into_constants_key(
|
|
1013
|
+
rules=constant_rules_dict
|
|
1014
|
+
)
|
|
1015
|
+
|
|
1016
|
+
# >> set combined rules to 'Constants' key
|
|
1017
|
+
if combined_rules:
|
|
1018
|
+
constant_rules_dict = {
|
|
1019
|
+
'Constants': combined_rules['Constants']
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
if (
|
|
1023
|
+
all_empty is True and
|
|
1024
|
+
combined_rules is None
|
|
1025
|
+
):
|
|
1026
|
+
# ! >> by default rules key
|
|
1027
|
+
default_rules_ = look_up_constants_rules(
|
|
1028
|
+
constants_id='ALL',
|
|
1029
|
+
rules=rules,
|
|
1030
|
+
)
|
|
1031
|
+
|
|
1032
|
+
if default_rules_:
|
|
1033
|
+
constant_rules_dict = {
|
|
1034
|
+
'Constants': default_rules_
|
|
1035
|
+
}
|
|
1036
|
+
else:
|
|
1037
|
+
# log
|
|
1038
|
+
logger.warning(
|
|
1039
|
+
f"No rules found for constants in the provided rules."
|
|
1040
|
+
)
|
|
1041
|
+
|
|
1042
|
+
# SECTION: extract labels
|
|
1043
|
+
constants_rules_labels = extract_labels_from_constants_rules(
|
|
1044
|
+
constant_rules_dict['Constants']
|
|
1045
|
+
) if constant_rules_dict['Constants'] else {}
|
|
1046
|
+
|
|
1047
|
+
# SECTION: check labels
|
|
1048
|
+
# check label results
|
|
1049
|
+
label_link = True
|
|
1050
|
+
|
|
1051
|
+
# NOTE: check labels
|
|
1052
|
+
if (
|
|
1053
|
+
check_labels and
|
|
1054
|
+
len(labels) > 0 and
|
|
1055
|
+
len(constants_rules_labels) > 0
|
|
1056
|
+
):
|
|
1057
|
+
# check if all labels in constants_rules_labels are in labels
|
|
1058
|
+
for label in constants_rules_labels:
|
|
1059
|
+
if label not in labels:
|
|
1060
|
+
# set
|
|
1061
|
+
label_link = False
|
|
1062
|
+
# log
|
|
1063
|
+
logger.error(
|
|
1064
|
+
f"Label '{label}' in rules not found in rules labels"
|
|
1065
|
+
)
|
|
1066
|
+
else:
|
|
1067
|
+
# NOTE: verbose
|
|
1068
|
+
if verbose:
|
|
1069
|
+
logger.info(
|
|
1070
|
+
f"No rules provided, using reference rules for constants")
|
|
1071
|
+
|
|
1072
|
+
# no rules provided, use reference rules
|
|
1073
|
+
# check label results
|
|
1074
|
+
label_link = False
|
|
1075
|
+
|
|
1076
|
+
# SECTION: add constants thermodb to thermodb hub
|
|
1077
|
+
# >> set rule
|
|
1078
|
+
rule_ = constant_rules_dict.get(
|
|
1079
|
+
'Constants',
|
|
1080
|
+
None
|
|
1081
|
+
)
|
|
1082
|
+
|
|
1083
|
+
# ! >> check rule
|
|
1084
|
+
if not rule_:
|
|
1085
|
+
rule_ = None
|
|
1086
|
+
|
|
1087
|
+
# >> if empty, set to None
|
|
1088
|
+
if rule_ and len(rule_) == 0:
|
|
1089
|
+
rule_ = None
|
|
1090
|
+
|
|
1091
|
+
# NOTE: thermodb_hub contains methods to define thermodb items with the provided rules, and build the model source.
|
|
1092
|
+
# >> add
|
|
1093
|
+
add_thermodb_res_ = thermodb_hub.add_thermodb(
|
|
1094
|
+
name='Constants',
|
|
1095
|
+
data=thermodb,
|
|
1096
|
+
rules=rule_,
|
|
1097
|
+
)
|
|
1098
|
+
|
|
1099
|
+
# >> log
|
|
1100
|
+
if verbose:
|
|
1101
|
+
if add_thermodb_res_:
|
|
1102
|
+
logger.info(f"Added thermodb for constants")
|
|
1103
|
+
else:
|
|
1104
|
+
logger.warning(f"Failed to add thermodb for constants")
|
|
1105
|
+
|
|
1106
|
+
# SECTION: build constant model source
|
|
1107
|
+
constantssource = thermodb_hub._build_cte_src()
|
|
1108
|
+
|
|
1109
|
+
# NOTE: create constant model source
|
|
1110
|
+
constant_model_source = ConstantsModelSource(
|
|
1111
|
+
constants_source=constantssource,
|
|
1112
|
+
)
|
|
1113
|
+
|
|
1114
|
+
# return
|
|
1115
|
+
return constant_model_source
|
|
1116
|
+
except Exception as e:
|
|
1117
|
+
logger.error(f"Error in build_constants_model_source: {e}")
|
|
1118
|
+
raise Exception(f"Error in build_constants_model_source: {e}")
|
|
1119
|
+
|
|
1120
|
+
# SECTION: build model source for multiple components/mixtures
|
|
1121
|
+
|
|
854
1122
|
|
|
855
1123
|
def build_model_source(
|
|
856
|
-
source: List[ComponentModelSource] | List[MixtureModelSource]
|
|
1124
|
+
source: List[ComponentModelSource] | List[MixtureModelSource] | List[ConstantsModelSource]
|
|
857
1125
|
) -> ModelSource:
|
|
858
1126
|
'''
|
|
859
1127
|
Build model source from list of component model source
|
|
860
1128
|
|
|
861
1129
|
Parameters
|
|
862
1130
|
----------
|
|
863
|
-
source: List[ComponentModelSource] | List[MixtureModelSource]
|
|
864
|
-
List of ComponentModelSource/MixtureModelSource object containing data source and
|
|
1131
|
+
source: List[ComponentModelSource] | List[MixtureModelSource] | List[ConstantsModelSource]
|
|
1132
|
+
List of ComponentModelSource/MixtureModelSource object containing data source, equation source, and constants source
|
|
865
1133
|
|
|
866
1134
|
Returns
|
|
867
1135
|
-------
|
|
@@ -873,19 +1141,64 @@ def build_model_source(
|
|
|
873
1141
|
model_source = ModelSource(
|
|
874
1142
|
data_source={},
|
|
875
1143
|
equation_source={},
|
|
1144
|
+
constants_source={}
|
|
876
1145
|
)
|
|
877
1146
|
|
|
878
|
-
# iterate over components model source
|
|
1147
|
+
# NOTE: iterate over components model source
|
|
879
1148
|
for component_model_source in source:
|
|
880
|
-
#
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
component_model_source
|
|
884
|
-
)
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1149
|
+
# >> check type
|
|
1150
|
+
if (
|
|
1151
|
+
isinstance(component_model_source, ComponentModelSource) or
|
|
1152
|
+
isinstance(component_model_source, MixtureModelSource)
|
|
1153
|
+
):
|
|
1154
|
+
# ! for ComponentModelSource and MixtureModelSource
|
|
1155
|
+
# add to model source
|
|
1156
|
+
# >> data source
|
|
1157
|
+
model_source.data_source.update(
|
|
1158
|
+
component_model_source.data_source
|
|
1159
|
+
)
|
|
1160
|
+
# >> equation source
|
|
1161
|
+
model_source.equation_source.update(
|
|
1162
|
+
component_model_source.equation_source
|
|
1163
|
+
)
|
|
1164
|
+
elif isinstance(component_model_source, ConstantsModelSource):
|
|
1165
|
+
# ! for ConstantsModelSource
|
|
1166
|
+
# >> check if constants source is not empty
|
|
1167
|
+
if (
|
|
1168
|
+
model_source.constants_source is not None and
|
|
1169
|
+
isinstance(model_source.constants_source, dict)
|
|
1170
|
+
):
|
|
1171
|
+
# add to model source
|
|
1172
|
+
# >> constants source
|
|
1173
|
+
model_source.constants_source.update(
|
|
1174
|
+
component_model_source.constants_source
|
|
1175
|
+
)
|
|
1176
|
+
else:
|
|
1177
|
+
logger.error(
|
|
1178
|
+
"Each item in source must be a ComponentModelSource, MixtureModelSource, or ConstantsModelSource object.")
|
|
1179
|
+
raise ValueError(
|
|
1180
|
+
"Each item in source must be a ComponentModelSource, MixtureModelSource, or ConstantsModelSource object.")
|
|
1181
|
+
|
|
1182
|
+
# NOTE: symbol configurations
|
|
1183
|
+
# ! datasource symbol configs
|
|
1184
|
+
data_symbols = ThermoUtils().extract_data_symbols(
|
|
1185
|
+
model_source.data_source
|
|
1186
|
+
)
|
|
1187
|
+
|
|
1188
|
+
# ! equationsource symbol configs
|
|
1189
|
+
equation_symbols = ThermoUtils().extract_equation_symbols(
|
|
1190
|
+
model_source.equation_source
|
|
1191
|
+
)
|
|
1192
|
+
|
|
1193
|
+
# ! constants source symbol configs
|
|
1194
|
+
constants_symbols = ThermoUtils().extract_constants_symbols(
|
|
1195
|
+
model_source.constants_source or {}
|
|
1196
|
+
)
|
|
1197
|
+
|
|
1198
|
+
# >>> update model source symbol configs
|
|
1199
|
+
model_source.data_symbols = data_symbols
|
|
1200
|
+
model_source.equation_symbols = equation_symbols
|
|
1201
|
+
model_source.constants_symbols = constants_symbols
|
|
889
1202
|
|
|
890
1203
|
return model_source
|
|
891
1204
|
except Exception as e:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from .settings import (
|
|
2
|
+
__author__,
|
|
3
|
+
__version__,
|
|
4
|
+
__description__
|
|
5
|
+
)
|
|
6
|
+
from .constants import (
|
|
7
|
+
DEFAULT_RULES_KEY,
|
|
8
|
+
DATA_KEY,
|
|
9
|
+
EQUATIONS_KEY,
|
|
10
|
+
CONSTANTS_KEY,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"__author__",
|
|
15
|
+
"__version__",
|
|
16
|
+
"__description__",
|
|
17
|
+
"DEFAULT_RULES_KEY",
|
|
18
|
+
"DATA_KEY",
|
|
19
|
+
"EQUATIONS_KEY",
|
|
20
|
+
"CONSTANTS_KEY",
|
|
21
|
+
]
|
|
@@ -6,7 +6,9 @@ DEFAULT_RULES_KEY = "ALL"
|
|
|
6
6
|
# NOTE: data/equations key
|
|
7
7
|
DATA_KEY = "DATA"
|
|
8
8
|
EQUATIONS_KEY = "EQUATIONS"
|
|
9
|
+
CONSTANTS_KEY = "CONSTANTS"
|
|
9
10
|
|
|
10
11
|
# SECTION: PyThermoDBLink/PyThermoDB
|
|
11
12
|
DATASOURCE = "datasource"
|
|
12
13
|
EQUATIONSOURCE = "equationsource"
|
|
14
|
+
CONSTANTSSOURCE = "constantssource"
|