PyThermoLinkDB 1.0.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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,288 @@
1
+ Metadata-Version: 2.1
2
+ Name: PyThermoLinkDB
3
+ Version: 1.0.0
4
+ Summary: PyThermoLinkDB is a Python package providing a robust and efficient interface between `PyThermoDB` and other applications.
5
+ Author: Sina Gilassi
6
+ Author-email: <sina.gilassi@gmail.com>
7
+ License: MIT
8
+ Keywords: python,chemical engineering,thermodynamics,PyThermoDB
9
+ Classifier: Development Status :: 1 - Planning
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Operating System :: Unix
13
+ Classifier: Operating System :: MacOS :: MacOS X
14
+ Classifier: Operating System :: Microsoft :: Windows
15
+ Requires-Python: >=3.6
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: pandas
19
+ Requires-Dist: pillow
20
+ Requires-Dist: requests
21
+ Requires-Dist: urllib3
22
+ Requires-Dist: matplotlib
23
+ Requires-Dist: numpy
24
+ Requires-Dist: PyYAML
25
+ Requires-Dist: PyThermoDB
26
+
27
+
28
+ # PyThermoLinkDB
29
+
30
+
31
+
32
+ ![Downloads](https://img.shields.io/pypi/dm/PyThermoLinkDB) ![PyPI](https://img.shields.io/pypi/v/PyThermoLinkDB) ![Python Version](https://img.shields.io/pypi/pyversions/PyThermoLinkDB.svg) ![License](https://img.shields.io/pypi/l/PyThermoLinkDB)
33
+
34
+
35
+
36
+ PyThermoLinkDB is a Python package providing a robust and efficient interface between `PyThermoDB` and other applications. It enables seamless thermodynamic data exchange, integration, and analysis. With PyThermoLinkDB, developers can easily link PyThermoDB to various tools, frameworks, and databases, streamlining thermodynamic workflows.
37
+
38
+
39
+
40
+ **Key Features:**
41
+
42
+
43
+
44
+ - Simple and intuitive API
45
+
46
+ - Efficient data transfer and integration
47
+
48
+ - Compatible with multiple data formats
49
+
50
+ - Extensive documentation and examples
51
+
52
+
53
+
54
+ Ideal for researchers, engineers, and developers working with thermodynamic data, PyThermoLinkDB simplifies data integration and analysis, accelerating scientific discoveries and industrial applications.
55
+
56
+
57
+
58
+ ## Installation
59
+
60
+
61
+
62
+ Install pyThermoLinkDB with pip
63
+
64
+
65
+
66
+ ```python
67
+
68
+ import pyThermoLinkDB as ptdblink
69
+
70
+ # check version
71
+
72
+ print(ptdblink.__version__)
73
+
74
+ ```
75
+
76
+
77
+
78
+ ## Usage Example
79
+
80
+
81
+
82
+ ```python
83
+
84
+ # import packages/modules
85
+
86
+ import pyThermoLinkDB as ptdblink
87
+
88
+ import pyThermoDB as ptdb
89
+
90
+ import os
91
+
92
+ from pprint import pprint as pp
93
+
94
+ ```
95
+
96
+
97
+
98
+ ### LOAD THERMODB
99
+
100
+
101
+
102
+ ```python
103
+
104
+ # ! ethanol
105
+
106
+ # thermodb file name
107
+
108
+ EtOH_thermodb_file = os.path.join(os.getcwd(), 'test', 'ethanol.pkl')
109
+
110
+ # load
111
+
112
+ EtOH_thermodb = ptdb.load_thermodb(EtOH_thermodb_file)
113
+
114
+ print(type(EtOH_thermodb))
115
+
116
+
117
+
118
+ # check
119
+
120
+ pp(EtOH_thermodb.check())
121
+
122
+ # check properties
123
+
124
+ pp(EtOH_thermodb.check_properties())
125
+
126
+ # datastrcuture
127
+
128
+ pp(EtOH_thermodb.check_property('GENERAL').data_structure())
129
+
130
+
131
+
132
+ # ! methanol
133
+
134
+ # thermodb file name
135
+
136
+ MeOH_thermodb_file = os.path.join(os.getcwd(), 'test', 'methanol.pkl')
137
+
138
+ # load
139
+
140
+ MeOH_thermodb = ptdb.load_thermodb(MeOH_thermodb_file)
141
+
142
+ print(type(MeOH_thermodb))
143
+
144
+
145
+
146
+ # check
147
+
148
+ pp(MeOH_thermodb.check())
149
+
150
+
151
+
152
+ # ! CO2
153
+
154
+ CO2_thermodb_file = os.path.join(
155
+
156
+ os.getcwd(), 'test', 'Carbon Dioxide-multiple.pkl')
157
+
158
+ # load
159
+
160
+ CO2_thermodb = ptdb.load_thermodb(CO2_thermodb_file)
161
+
162
+ print(type(CO2_thermodb))
163
+
164
+
165
+
166
+ # check
167
+
168
+ pp(CO2_thermodb.check())
169
+
170
+ pp(CO2_thermodb.check_property('GENERAL').data_structure())
171
+
172
+ pp(CO2_thermodb.check_property('GENERAL-2').data_structure())
173
+
174
+ ```
175
+
176
+
177
+
178
+ ### THERMODB LINK CONFIGURATION
179
+
180
+
181
+
182
+ ```python
183
+
184
+ # init thermodb hub
185
+
186
+ thub1 = ptdblink.thermodb_hub()
187
+
188
+ print(type(thub1))
189
+
190
+
191
+
192
+ # add component thermodb
193
+
194
+ thub1.add_thermodb('EtOH', EtOH_thermodb)
195
+
196
+ thub1.add_thermodb('MeOH', MeOH_thermodb)
197
+
198
+ thub1.add_thermodb('CO2', CO2_thermodb)
199
+
200
+
201
+
202
+ # * add thermodb rule
203
+
204
+ thermodb_config_file = os.path.join(os.getcwd(), 'test', 'thermodb_config.yml')
205
+
206
+ # one component
207
+
208
+ # thub1.config_thermodb_rule(thermodb_config_file, name='EtOH')
209
+
210
+ # all components
211
+
212
+ thub1.config_thermodb_rule(thermodb_config_file, name='ALL')
213
+
214
+
215
+
216
+ # thermodb
217
+
218
+ # pp(thub1.thermodb)
219
+
220
+
221
+
222
+ # thermodb rules
223
+
224
+ # pp(thub1.thermodb_rule)
225
+
226
+
227
+
228
+ # get components
229
+
230
+ pp(thub1.get_components())
231
+
232
+
233
+
234
+ # build
235
+
236
+ datasource, equationsource = thub1.build()
237
+
238
+ pp(datasource)
239
+
240
+ pp(equationsource)
241
+
242
+
243
+
244
+ # check
245
+
246
+ # pp(thub1.check())
247
+
248
+ ```
249
+
250
+
251
+
252
+ ### RETRIEVE DATA
253
+
254
+
255
+
256
+ ```python
257
+
258
+ # data
259
+
260
+ pp(datasource['CO2']['Pc']['value'])
261
+
262
+
263
+
264
+ # equation
265
+
266
+ pp(equationsource['CO2']['VaPr'].args)
267
+
268
+ pp(equationsource['CO2']['VaPr'].cal(T=298.15))
269
+
270
+ ```
271
+
272
+
273
+
274
+ ## FAQ
275
+
276
+
277
+
278
+ For any question, contact me on [LinkedIn](https://www.linkedin.com/in/sina-gilassi/)
279
+
280
+
281
+
282
+
283
+
284
+ ## Authors
285
+
286
+
287
+
288
+ - [@sinagilassi](https://www.github.com/sinagilassi)
@@ -0,0 +1,13 @@
1
+ pyThermoLinkDB/__init__.py,sha256=SdtbE5zCi4rUVF4QRcX1YUV58YKg7WHnatDKfWvXvso,135
2
+ pyThermoLinkDB/app.py,sha256=wWnnTY1G9pRLAG08usTNAkIIuE-BlxJ4RZzP7cgZqhE,880
3
+ pyThermoLinkDB/config/__init__.py,sha256=yfehvVIN_AZsPyTc7gYNcAlx-SiP5rD_zNsDMUSYvg0,126
4
+ pyThermoLinkDB/config/settings.py,sha256=nMYB0bi5DyhUqdpeMGOdrEsI3UIfiK2Htbved-1kwWM,225
5
+ pyThermoLinkDB/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ pyThermoLinkDB/docs/__init__.py,sha256=OaUqCAHPrWd50mVEIFfkVrMZLY6WzQ7WZb4WIOUrb0E,117
7
+ pyThermoLinkDB/docs/thermodbhub.py,sha256=4Qx9PzqNOwBPXPFmXy-9V6nJ3VxsAziEGppr7fXYcno,10906
8
+ pyThermoLinkDB/docs/thermolink.py,sha256=QS-XDfBqwV31RIw2K9zQ8g7T8VPG5BWBuhUrkT50Rso,4468
9
+ PyThermoLinkDB-1.0.0.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
10
+ PyThermoLinkDB-1.0.0.dist-info/METADATA,sha256=3KzQaaEOemcUEiL6DihuzjqMjZ92UI-6g-_LwDA6s6M,4662
11
+ PyThermoLinkDB-1.0.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
12
+ PyThermoLinkDB-1.0.0.dist-info/top_level.txt,sha256=1W-IWvJNett9H59MZFvL2wjvJOZKAhU_5LBlIk8rVso,15
13
+ PyThermoLinkDB-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ pyThermoLinkDB
@@ -0,0 +1,3 @@
1
+ from .app import __author__, __version__, __description__, thermodb_hub
2
+
3
+ __all__ = ["__author__", "__version__", "__description__"]
pyThermoLinkDB/app.py ADDED
@@ -0,0 +1,51 @@
1
+ # import packages/modules
2
+ import os
3
+ # local
4
+ from .config import __version__, __author__, __description__
5
+ from .docs import ThermoDBHub, ThermoLink
6
+
7
+
8
+ def get_version() -> str:
9
+ '''
10
+ Get the current version
11
+ '''
12
+ return __version__
13
+
14
+
15
+ def get_author() -> str:
16
+ '''
17
+ Get the author
18
+ '''
19
+ return __author__
20
+
21
+
22
+ def des() -> str:
23
+ '''
24
+ Get the description
25
+ '''
26
+ return __description__
27
+
28
+
29
+ def thermodb_hub() -> ThermoDBHub:
30
+ '''
31
+ Init thermolink
32
+
33
+ Parameters
34
+ ----------
35
+ None
36
+
37
+ Returns
38
+ -------
39
+ ThermoDBHub : ThermoDBHub
40
+ A thermolink object
41
+ '''
42
+ try:
43
+ # init thermolink
44
+ ThermoDBHubC = ThermoDBHub()
45
+ return ThermoDBHubC
46
+ except Exception as e:
47
+ raise Exception("Error: {}".format(e))
48
+
49
+
50
+ if __name__ == "__main__":
51
+ print(des())
@@ -0,0 +1,3 @@
1
+ from .settings import __author__, __version__, __description__
2
+
3
+ __all__ = ["__author__", "__version__", "__description__"]
@@ -0,0 +1,8 @@
1
+ # setting
2
+
3
+ # version
4
+ __version__ = "1.0.0"
5
+ # author
6
+ __author__ = "Sina Gilassi"
7
+ # description
8
+ __description__ = "A Python interface for connecting PyThermoDB to other applications and integrating thermodynamic data."
File without changes
@@ -0,0 +1,4 @@
1
+ from .thermolink import ThermoLink
2
+ from .thermodbhub import ThermoDBHub
3
+
4
+ __all__ = ["ThermoLink", "ThermoDBHub"]
@@ -0,0 +1,384 @@
1
+ # THERMODB
2
+
3
+ # import packages/modules
4
+ import pyThermoDB
5
+ import os
6
+ import yaml
7
+ # local
8
+ from .thermolink import ThermoLink
9
+
10
+
11
+ class ThermoDBHub(ThermoLink):
12
+ # vars
13
+ _thermodb = {}
14
+ _thermodb_rule = {}
15
+ _hub = {}
16
+
17
+ def __init__(self):
18
+ # init super class
19
+ ThermoLink().__init__()
20
+
21
+ @property
22
+ def thermodb(self):
23
+ return self._thermodb
24
+
25
+ @property
26
+ def thermodb_rule(self):
27
+ return self._thermodb_rule
28
+
29
+ @property
30
+ def hub(self):
31
+ return self._hub
32
+
33
+ def get_components(self):
34
+ '''
35
+ Gets a component list
36
+
37
+ Parameters
38
+ ----------
39
+ None
40
+
41
+ Returns
42
+ -------
43
+ components : list
44
+ list of components
45
+ '''
46
+ try:
47
+ components = list(self._thermodb.keys())
48
+ return components
49
+ except Exception as e:
50
+ raise Exception('Getting components failed!, ', e)
51
+
52
+ def config_thermodb_rule(self, config_file, name="ALL", disp=False) -> bool:
53
+ '''
54
+ Configs thermodb rule defined for each component
55
+
56
+ Parameters
57
+ ----------
58
+ config_file: str
59
+ config file path
60
+ name: str
61
+ name of the record, optional, default value is ALL.
62
+ disp: bool
63
+ display the config log
64
+
65
+ Returns
66
+ -------
67
+ True : bool
68
+ success
69
+
70
+ Notes
71
+ -----
72
+ config_file is a yml file format as:
73
+ ```
74
+ EtOH:
75
+ Pc: ['GENERAL','Pc']
76
+ Tc: ['GENERAL','Tc']
77
+ AcFa: ['GENERAL','AcFa']
78
+ VaPr: ['VAPOR-PRESSURE','VaPr']
79
+ MeOH:
80
+ Pc: ['GENERAL','Pc']
81
+ Tc: ['GENERAL','Tc']
82
+ AcFa: ['GENERAL','AcFa']
83
+ VaPr: ['VAPOR-PRESSURE','VaPr']
84
+ ```
85
+ '''
86
+ try:
87
+ # check
88
+ if config_file:
89
+ # check file
90
+ if not os.path.exists(config_file):
91
+ raise Exception('Configuration file not found!')
92
+
93
+ # set name
94
+ name = str(name).strip()
95
+ # load
96
+ with open(config_file, 'r') as f:
97
+ _ref = yaml.load(f, Loader=yaml.FullLoader)
98
+
99
+ # check
100
+ if name == "ALL":
101
+ # check name exists
102
+ if _ref.keys():
103
+ # looping through
104
+ for key in _ref.keys():
105
+ # get record
106
+ record_thermodb_rule = _ref[key]
107
+
108
+ # check key exists
109
+ if key in self._thermodb.keys():
110
+ # add
111
+ self._thermodb_rule[key].update(
112
+ record_thermodb_rule)
113
+
114
+ # check disp
115
+ if disp:
116
+ print(
117
+ f'{key} thermodb rule successfully registered.')
118
+ else:
119
+ print(
120
+ f'{key} not found, no thermodb provided!')
121
+ # res
122
+ return True
123
+ else:
124
+ raise Exception('Record not found!')
125
+ else:
126
+ # check name exists
127
+ if name in _ref.keys():
128
+ # get record
129
+ record_thermodb_rule = _ref[name]
130
+
131
+ # check name exists
132
+ if name in self._thermodb.keys():
133
+ # looping through
134
+ self._thermodb_rule[name].update(
135
+ record_thermodb_rule)
136
+
137
+ # check disp
138
+ if disp:
139
+ print(
140
+ f'{name} thermodb rule successfully registered.')
141
+ # res
142
+ return True
143
+ else:
144
+ print(
145
+ f'{name} not found, no thermodb provided!')
146
+ # res
147
+ return False
148
+ else:
149
+ print(f'{name} not found, no thermodb provided!')
150
+ return False
151
+
152
+ except Exception as e:
153
+ raise Exception('Configuration failed!, ', e)
154
+
155
+ def add_thermodb_rule(self, rules):
156
+ '''
157
+ Adds a thermodb rule dict
158
+
159
+ Parameters
160
+ ----------
161
+ rules: dict
162
+ thermodb rule dict for all components
163
+
164
+ Returns
165
+ -------
166
+ True : bool
167
+ success
168
+
169
+ Notes
170
+ -----
171
+ - A dictionary file with the following format:
172
+
173
+ {
174
+ 'CO2':
175
+ 'Pc': ['GENERAL','Pc']
176
+ 'Tc': ['GENERAL','Tc']
177
+ 'AcFa': ['GENERAL','AcFa']
178
+ 'VaPr': ['VAPOR-PRESSURE','VaPr'],
179
+ }
180
+ '''
181
+ try:
182
+ for key, value in rules.items():
183
+ # check key exist
184
+ if key not in self._thermodb.keys():
185
+ # log warning
186
+ print(f"{key} is not in thermodb!")
187
+ continue
188
+
189
+ # add
190
+ self._thermodb_rule[key] = value
191
+ # res
192
+ return True
193
+ # res
194
+ return True
195
+ except Exception as e:
196
+ raise Exception('Adding new rule failed!, ', e)
197
+
198
+ def delete_thermodb_rule(self, name):
199
+ '''
200
+ Deletes the current thermodb rule
201
+
202
+ Parameters
203
+ ----------
204
+ name: str
205
+ name of the record
206
+
207
+ Returns
208
+ -------
209
+ True : bool
210
+ success
211
+ '''
212
+ try:
213
+ # check key exist
214
+ if name not in self._thermodb_rule.keys():
215
+ # log warning
216
+ print(f"{name} is not in thermodb_rule!")
217
+ return False
218
+
219
+ # del
220
+ del self._thermodb_rule[name]
221
+ # res
222
+ return True
223
+ except Exception as e:
224
+ raise Exception('Deleting rule failed!, ', e)
225
+
226
+ def add_thermodb(self, name, data: pyThermoDB.docs.compbuilder.CompBuilder) -> bool:
227
+ '''
228
+ Adds new thermodb such as: CO2_thermodb
229
+
230
+ Parameters
231
+ ----------
232
+ name: str
233
+ name of the record
234
+ data: pyThermoDB.docs.compbuilder.CompBuilder
235
+ data of the record
236
+
237
+ Returns
238
+ -------
239
+ True : bool
240
+ success
241
+ '''
242
+ try:
243
+ self._thermodb[name] = data
244
+ # create thermodb rule
245
+ self._thermodb_rule[name] = {}
246
+ # res
247
+ return True
248
+ except Exception as e:
249
+ raise Exception('Adding new record failed!, ', e)
250
+
251
+ def update_thermodb(self, name, data: pyThermoDB.docs.compbuilder.CompBuilder) -> bool:
252
+ '''
253
+ Updates existing record
254
+
255
+ Parameters
256
+ ----------
257
+ name: str
258
+ name of the record
259
+ data: pyThermoDB.docs.compbuilder.CompBuilder
260
+ data of the record
261
+
262
+ Returns
263
+ -------
264
+ True : bool
265
+ success
266
+ '''
267
+ try:
268
+ self._thermodb[name] = data
269
+ # res
270
+ return True
271
+ except Exception as e:
272
+ raise Exception('Updating record failed!, ', e)
273
+
274
+ def delete_thermodb(self, name: str) -> bool:
275
+ '''
276
+ Deletes existing record
277
+
278
+ Parameters
279
+ ----------
280
+ name: str
281
+ name of the record
282
+
283
+ Returns
284
+ -------
285
+ True : bool
286
+ success
287
+ '''
288
+ try:
289
+ del self._thermodb[name]
290
+ # delete thermodb rule
291
+ del self._thermodb_rule[name]
292
+ # res
293
+ return True
294
+ except Exception as e:
295
+ raise Exception('Deleting record failed!, ', e)
296
+
297
+ def info_thermodb(self, name) -> dict:
298
+ '''
299
+ Gets info of thermodb
300
+
301
+ Parameters
302
+ ----------
303
+ name: str
304
+ name of the record
305
+
306
+ Returns
307
+ -------
308
+ res : CompBuilder
309
+ thermodb check
310
+ '''
311
+ try:
312
+ # check key exist
313
+ if name not in self._thermodb.keys():
314
+ # log warning
315
+ print(f"{name} is not in thermodb!")
316
+ return None
317
+
318
+ # res
319
+ res = self._thermodb[name].check()
320
+ return res
321
+ except Exception as e:
322
+ raise Exception('Getting info of record failed!, ', e)
323
+
324
+ def build(self):
325
+ '''
326
+ Builds a datasource
327
+
328
+ Parameters
329
+ ----------
330
+ None
331
+
332
+ Returns
333
+ -------
334
+ datasource : dict
335
+ datasource
336
+ equationsource : dict
337
+ equationsource
338
+
339
+ Notes
340
+ -----
341
+ - A dictionary contains data and equations
342
+ '''
343
+ try:
344
+ # components
345
+ components = list(self._thermodb.keys())
346
+ # datasource
347
+ datasource = self._set_datasource(
348
+ self._thermodb, self._thermodb_rule, components)
349
+ # equationsource
350
+ equationsource = self._set_equationsource(
351
+ self._thermodb, self._thermodb_rule, components)
352
+
353
+ # reset
354
+ self._hub = {}
355
+ # update hub
356
+
357
+ # for each component
358
+ for component in components:
359
+ _data = datasource[component]
360
+ _eq = equationsource[component]
361
+ # save
362
+ self._hub[component] = {**_data, **_eq}
363
+ # res
364
+ return datasource, equationsource
365
+ except Exception as e:
366
+ raise Exception('Building data/equation source failed!, ', e)
367
+
368
+ def check(self):
369
+ '''
370
+ Checks data/equation source
371
+
372
+ Parameters
373
+ ----------
374
+ None
375
+
376
+ Returns
377
+ -------
378
+ thermodb : dict
379
+ thermodb
380
+ '''
381
+ try:
382
+ return self._hub
383
+ except Exception as e:
384
+ raise Exception('Checking data/equation source failed!, ', e)
@@ -0,0 +1,128 @@
1
+ # THERMO LINK
2
+
3
+ # import packages/modules
4
+
5
+ # local
6
+
7
+
8
+ class ThermoLink:
9
+
10
+ def __init__(self):
11
+ # load reference
12
+ pass
13
+
14
+ def _set_datasource(self, thermodb: dict, thermodb_rule: dict, components: list) -> dict:
15
+ '''
16
+ Sets a datasource
17
+
18
+ Parameters
19
+ ----------
20
+ thermodb : dict
21
+ thermodb
22
+ thermodb_rule : dict
23
+ thermodb rule
24
+ components : list
25
+ list of components
26
+
27
+ Returns
28
+ -------
29
+ datasource : dict
30
+ datasource
31
+ '''
32
+ try:
33
+ # datasource
34
+ datasource = {}
35
+ for component in components:
36
+ if component in thermodb:
37
+ # set
38
+ datasource[component] = {}
39
+
40
+ # component registered data/equations
41
+ data = list(
42
+ thermodb[component].check_properties().keys())
43
+
44
+ # check
45
+ if len(data) != 0:
46
+ # looping through each data source (GENERAL)
47
+ for src in data:
48
+ # take data
49
+ df_src = thermodb[component].check_property(
50
+ src).data_structure()
51
+ # take all symbols
52
+ symbols = df_src['SYMBOL'].tolist()
53
+ # looping through item data
54
+ for symbol in symbols:
55
+ # check
56
+ if symbol is not None and symbol != 'None':
57
+ # symbol
58
+ symbol = str(symbol).strip()
59
+ # val
60
+ _val = thermodb[component].check_property(
61
+ src).get_property(str(symbol).strip())
62
+
63
+ # check symbol rename is required
64
+ if symbol in thermodb_rule[component]['DATA']:
65
+ # rename
66
+ symbol = thermodb_rule[component]['DATA'][symbol]
67
+
68
+ # update
69
+ datasource[component][symbol] = _val
70
+ # res
71
+ return datasource
72
+ except Exception as e:
73
+ raise Exception('Building datasource failed!, ', e)
74
+
75
+ def _set_equationsource(self, thermodb: dict, thermodb_rule: dict, components: list) -> dict:
76
+ '''
77
+ Sets equation source
78
+
79
+ Parameters
80
+ ----------
81
+ thermodb : dict
82
+ thermodb
83
+ thermodb_rule : dict
84
+ thermodb rule
85
+ components : list
86
+ list of components
87
+
88
+ Returns
89
+ -------
90
+ datasource : dict
91
+ datasource
92
+ '''
93
+ try:
94
+ # datasource
95
+ datasource = {}
96
+ for component in components:
97
+ if component in thermodb:
98
+ # set
99
+ datasource[component] = {}
100
+
101
+ # component registered data/equations
102
+ eq_data = list(
103
+ thermodb[component].check_functions().keys())
104
+
105
+ # check
106
+ if len(eq_data) != 0:
107
+ # parms
108
+ for eq in eq_data:
109
+ # get function structure
110
+ # eq_str = thermodb[component].get_function(
111
+ # eq).eq_structure(1)
112
+
113
+ # symbol
114
+ symbol = str(eq).strip()
115
+ # val
116
+ _val = thermodb[component].check_function(
117
+ eq)
118
+
119
+ # check symbol rename is required
120
+ if symbol in thermodb_rule[component]['EQUATIONS']:
121
+ # rename
122
+ symbol = thermodb_rule[component]['EQUATIONS'][symbol]
123
+
124
+ datasource[component][symbol] = _val
125
+ # res
126
+ return datasource
127
+ except Exception as e:
128
+ raise Exception('Building datasource failed!, ', e)