micki 2.0.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.
micki-2.0.0/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
micki-2.0.0/PKG-INFO ADDED
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: micki
3
+ Version: 2.0.0
4
+ Summary: A modular, extensible, object-oriented microkinetic modeling package
5
+ Author: Eric D. Hermes, Aurora N. Janes, J.R. Schmidt
6
+ License-Expression: LGPL-3.0-only
7
+ Project-URL: Repository, https://github.com/jrschmidt2/micki
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: ase
14
+ Requires-Dist: numpy>=2.0
15
+ Requires-Dist: sundials4py<8,>=7.9
16
+ Requires-Dist: sympy
17
+ Dynamic: license-file
18
+
19
+ ### micki
20
+
21
+ A modular, extensible, robust object-oriented microkinetic modeling package
22
+ written in Python.
23
+
24
+ ### DEPENDENCIES (installed automatically, see below):
25
+ * Python >= 3.12
26
+ * sundials4py (the official SUNDIALS Python interface; >= 7.9, beta)
27
+ * numpy >= 2.0
28
+ * sympy
29
+ * ase
30
+
31
+ No compiler, SUNDIALS build or LAPACK library is needed: sundials4py ships
32
+ prebuilt wheels that include SUNDIALS.
33
+
34
+ Earlier versions that generate Fortran and compile it with f2py are kept on
35
+ branches: `fortran-sundials7` (SUNDIALS 7 Fortran 2003 interface) and
36
+ `sundials4` (SUNDIALS 4.X FCMIX interface).
37
+
38
+ ### Installation with conda (recommended):
39
+ #fetch Micki and create a conda environment with all dependencies<br>
40
+ git clone https://github.com/jrschmidt2/micki.git<br>
41
+ cd micki<br>
42
+ conda env create -f environment.yml<br>
43
+ conda activate micki<br>
44
+
45
+ Python, numpy, sympy and ase come from conda-forge. sundials4py and Micki
46
+ itself are not on conda-forge, so `environment.yml` installs them with pip
47
+ inside the environment (Micki in editable mode, so changes in the clone take
48
+ effect immediately).
49
+
50
+ ### Installation with pip:
51
+ #in an environment with Python >= 3.12<br>
52
+ pip install micki<br>
53
+
54
+ ### Testing:
55
+ Run the test suite (about 15 seconds; includes a water-gas shift regression test) from the repository root:<br>
56
+ python -m unittest discover -s tests -v
57
+
58
+ ### Releasing:
59
+ Releases are published to PyPI automatically by GitHub Actions
60
+ (`.github/workflows/publish.yml`, PyPI trusted publishing):
61
+
62
+ 1. Set the new version in `pyproject.toml` and commit it.
63
+ 2. Create a GitHub release with tag `v<version>` (e.g. `v2.0.0`).
64
+
65
+ Publishing the release runs the tests, builds the package and uploads it to
66
+ PyPI. The workflow refuses to publish if the tag does not match the version.
micki-2.0.0/README.md ADDED
@@ -0,0 +1,48 @@
1
+ ### micki
2
+
3
+ A modular, extensible, robust object-oriented microkinetic modeling package
4
+ written in Python.
5
+
6
+ ### DEPENDENCIES (installed automatically, see below):
7
+ * Python >= 3.12
8
+ * sundials4py (the official SUNDIALS Python interface; >= 7.9, beta)
9
+ * numpy >= 2.0
10
+ * sympy
11
+ * ase
12
+
13
+ No compiler, SUNDIALS build or LAPACK library is needed: sundials4py ships
14
+ prebuilt wheels that include SUNDIALS.
15
+
16
+ Earlier versions that generate Fortran and compile it with f2py are kept on
17
+ branches: `fortran-sundials7` (SUNDIALS 7 Fortran 2003 interface) and
18
+ `sundials4` (SUNDIALS 4.X FCMIX interface).
19
+
20
+ ### Installation with conda (recommended):
21
+ #fetch Micki and create a conda environment with all dependencies<br>
22
+ git clone https://github.com/jrschmidt2/micki.git<br>
23
+ cd micki<br>
24
+ conda env create -f environment.yml<br>
25
+ conda activate micki<br>
26
+
27
+ Python, numpy, sympy and ase come from conda-forge. sundials4py and Micki
28
+ itself are not on conda-forge, so `environment.yml` installs them with pip
29
+ inside the environment (Micki in editable mode, so changes in the clone take
30
+ effect immediately).
31
+
32
+ ### Installation with pip:
33
+ #in an environment with Python >= 3.12<br>
34
+ pip install micki<br>
35
+
36
+ ### Testing:
37
+ Run the test suite (about 15 seconds; includes a water-gas shift regression test) from the repository root:<br>
38
+ python -m unittest discover -s tests -v
39
+
40
+ ### Releasing:
41
+ Releases are published to PyPI automatically by GitHub Actions
42
+ (`.github/workflows/publish.yml`, PyPI trusted publishing):
43
+
44
+ 1. Set the new version in `pyproject.toml` and commit it.
45
+ 2. Create a GitHub release with tag `v<version>` (e.g. `v2.0.0`).
46
+
47
+ Publishing the release runs the tests, builds the package and uploads it to
48
+ PyPI. The workflow refuses to publish if the tag does not match the version.
@@ -0,0 +1,8 @@
1
+ from micki.reactants import Liquid, Gas, Adsorbate, Electron
2
+ from micki.model import Reaction, Model
3
+ from micki.eref import EnergyReference
4
+ from micki.analysis import ModelAnalysis
5
+ from micki.lattice import Lattice
6
+
7
+ __all__ = ['Liquid', 'Gas', 'Adsorbate', 'Electron', 'Reaction', 'Model',
8
+ 'EnergyReference', 'ModelAnalysis', 'Lattice']
@@ -0,0 +1,287 @@
1
+ """Module for doing sensitivity analysis of microkinetic model"""
2
+
3
+ import collections.abc
4
+
5
+ import numpy as np
6
+ import sympy as sym
7
+
8
+ from ase.units import kB
9
+
10
+ from micki.reactants import Adsorbate, _Fluid
11
+
12
+
13
+ class ModelAnalysis:
14
+ def __init__(self, model, product_reaction, Uequil, tol=1e-3, dt=3600):
15
+ self.model = model
16
+ self.reaction_name = product_reaction
17
+ self.product_reaction = model.reactions[product_reaction]
18
+ self.Uequil = Uequil
19
+ self.tol = tol
20
+ self.dt = dt
21
+
22
+ self.model.set_initial_conditions(self.Uequil)
23
+
24
+ t, self.U, self.r = self.model.find_steady_state()
25
+ model.finalize()
26
+
27
+ self.species_symbols = []
28
+ for species in self.model._species:
29
+ if species.symbol is not None:
30
+ self.species_symbols.append(species)
31
+ self.rmid = self.r[self.reaction_name]
32
+
33
+ def campbell_rate_control(self, rxn_name, scale=0.001):
34
+ reaction = self.model.reactions[rxn_name]
35
+
36
+ subs = {}
37
+ for species in self.species_symbols:
38
+ subs[species.symbol] = self.U[species.label]
39
+
40
+ kmid = reaction.get_kfor(self.model.T,
41
+ self.model.Asite,
42
+ self.model.z)
43
+
44
+ if isinstance(kmid, sym.Basic):
45
+ kmid = kmid.subs(subs)
46
+
47
+ reaction.set_scale('kfor', 1.0 - scale)
48
+ reaction.set_scale('krev', 1.0 - scale)
49
+ reaction.update(self.model.T,
50
+ self.model.Asite,
51
+ self.model.z,
52
+ force=True)
53
+ klow = reaction.get_kfor()
54
+ model = self.model.copy()
55
+
56
+ try:
57
+ t1, U1, r1 = model.find_steady_state()
58
+ finally:
59
+ reaction.set_scale('kfor', 1.0)
60
+ reaction.set_scale('krev', 1.0)
61
+
62
+ model.finalize()
63
+ rlow = r1[self.reaction_name]
64
+ if isinstance(klow, sym.Basic):
65
+ subs = {}
66
+ for species in self.species_symbols:
67
+ subs[species.symbol] = U1[species.label]
68
+ klow = klow.subs(subs)
69
+
70
+ reaction.set_scale('kfor', 1.0 + scale)
71
+ reaction.set_scale('krev', 1.0 + scale)
72
+ reaction.update(self.model.T,
73
+ self.model.Asite,
74
+ self.model.z,
75
+ force=True)
76
+ khigh = reaction.get_kfor()
77
+ model = self.model.copy()
78
+
79
+ try:
80
+ t2, U2, r2 = model.find_steady_state()
81
+ finally:
82
+ reaction.set_scale('kfor', 1.0)
83
+ reaction.set_scale('krev', 1.0)
84
+
85
+ model.finalize()
86
+ rhigh = r2[self.reaction_name]
87
+ if isinstance(khigh, sym.Basic):
88
+ subs = {}
89
+ for species in self.species_symbols:
90
+ subs[species.symbol] = U2[species.label]
91
+ khigh = khigh.subs(subs)
92
+ reaction.set_scale('kfor', 1.0)
93
+ reaction.set_scale('krev', 1.0)
94
+
95
+ return kmid * (rhigh - rlow) / (self.rmid * (khigh - klow))
96
+
97
+ def thermodynamic_rate_control(self, names, dg=None):
98
+ """Degree of thermodynamic rate control, -(kT/r) dr/dG.
99
+
100
+ The free energies of all species in `names` are shifted together
101
+ by -dg and +dg (default 0.001 kT) and the derivative is taken by
102
+ central differences.
103
+ """
104
+ T = self.model.T
105
+ if dg is None:
106
+ dg = 0.001 * kB * T
107
+
108
+ if not isinstance(names, (list, tuple)):
109
+ species = [self.model.species[names]]
110
+ else:
111
+ species = [self.model.species[name] for name in names]
112
+
113
+ for sp in species:
114
+ sp.dE -= dg
115
+
116
+ for reaction in self.model._reactions:
117
+ reaction.update(T=self.model.T,
118
+ Asite=self.model.Asite,
119
+ L=self.model.z,
120
+ force=True)
121
+
122
+ model = self.model.copy(initialize=False)
123
+ model.set_initial_conditions(self.U)
124
+
125
+ try:
126
+ t1, U1, r1 = model.find_steady_state()
127
+ finally:
128
+ for sp in species:
129
+ sp.dE += dg
130
+
131
+ model.finalize()
132
+ rlow = r1[self.reaction_name]
133
+
134
+ for sp in species:
135
+ sp.dE += dg
136
+
137
+ for reaction in self.model._reactions:
138
+ reaction.update(T=self.model.T,
139
+ Asite=self.model.Asite,
140
+ L=self.model.z,
141
+ force=True)
142
+
143
+ model = self.model.copy(initialize=False)
144
+ model.set_initial_conditions(self.U)
145
+
146
+ try:
147
+ t2, U2, r2 = model.find_steady_state()
148
+ finally:
149
+ for sp in species:
150
+ sp.dE -= dg
151
+
152
+ for reaction in self.model._reactions:
153
+ reaction.update(T=self.model.T,
154
+ Asite=self.model.Asite,
155
+ L=self.model.z,
156
+ force=True)
157
+
158
+ model.finalize()
159
+ rhigh = r2[self.reaction_name]
160
+
161
+ # central difference: the two rates are 2 * dg apart in free energy
162
+ return (rlow - rhigh) * kB * T / (self.rmid * 2 * dg)
163
+
164
+ def activation_barrier(self, dT=0.01):
165
+ T = self.model.T
166
+
167
+ model = self.model.copy(initialize=False)
168
+ model.T = T - dT
169
+ model.set_initial_conditions(self.Uequil)
170
+ t1, U1, r1 = model.find_steady_state()
171
+ model.finalize()
172
+
173
+ rlow = r1[self.reaction_name]
174
+
175
+ model = self.model.copy(initialize=False)
176
+ model.T = T + dT
177
+ model.set_initial_conditions(self.Uequil)
178
+ t2, U2, r2 = model.find_steady_state()
179
+ model.finalize()
180
+
181
+ rhigh = r2[self.reaction_name]
182
+
183
+ return kB * T**2 * (rhigh - rlow) / (self.rmid * 2 * dT)
184
+
185
+ def rate_order(self, name, drho=0.05):
186
+ species = self.model.species[name]
187
+
188
+ rhomid = self.Uequil[species.label]
189
+ if not rhomid > 0:
190
+ raise ValueError('{} has no positive concentration'.format(name))
191
+
192
+ U0 = self.Uequil.copy()
193
+ rholow = rhomid * (1.0 - drho)
194
+ U0[species.label] = rholow
195
+ model = self.model.copy(initialize=False)
196
+ model.set_initial_conditions(U0)
197
+ t1, U1, r1 = model.find_steady_state()
198
+ model.finalize()
199
+ rlow = r1[self.reaction_name]
200
+
201
+ rhohigh = rhomid * (1.0 + drho)
202
+ U0[species.label] = rhohigh
203
+ model.set_initial_conditions(U0)
204
+ t2, U2, r2 = model.find_steady_state()
205
+ model.finalize()
206
+ rhigh = r2[self.reaction_name]
207
+
208
+ return (rhomid / self.rmid) * (rhigh - rlow) / (rhohigh - rholow)
209
+
210
+ def drate_order_dg(self, fluid, adsorbates, rho_scale=0.01, g_scale=0.01):
211
+ """(rho/r) d^2 r / (d rho dG): the change of the rate order in
212
+ `fluid` with the free energy of `adsorbates` (shifted together).
213
+
214
+ Central differences in the concentration of `fluid` (+-drho) and in
215
+ the free energies of `adsorbates` (+-dg).
216
+ """
217
+ if not isinstance(fluid, _Fluid):
218
+ raise TypeError('fluid must be a Gas or Liquid species')
219
+
220
+ if not isinstance(adsorbates, collections.abc.Iterable):
221
+ adsorbates = [adsorbates]
222
+
223
+ if not isinstance(adsorbates[0], Adsorbate):
224
+ raise TypeError('adsorbates must be Adsorbate species')
225
+
226
+ rhomid = self.U[fluid.label]
227
+ if not rhomid > 0:
228
+ raise ValueError('{} has no positive concentration'
229
+ ''.format(fluid.label))
230
+ rmid = self.r[self.reaction_name]
231
+ gmid = adsorbates[0].get_G(self.model.T)
232
+ if isinstance(gmid, sym.Basic):
233
+ trans = {}
234
+ for species in self.model._species:
235
+ if isinstance(species, Adsorbate) \
236
+ and species.symbol is not None:
237
+ trans[species.symbol] = self.U[species.label]
238
+ gmid = gmid.subs(trans)
239
+ dg = np.abs(gmid * g_scale * 2)
240
+ drho = rhomid * rho_scale * 2
241
+
242
+ dr = 0
243
+
244
+ def set_dg(species, dg):
245
+ species.dE += dg
246
+
247
+ for i in [-1, 1]:
248
+ for adsorbate in adsorbates:
249
+ set_dg(adsorbate, i * dg)
250
+
251
+ for reaction in self.model._reactions:
252
+ reaction.update(T=self.model.T,
253
+ Asite=self.model.Asite,
254
+ L=self.model.z,
255
+ force=True)
256
+
257
+ for j in [-1, 1]:
258
+ U0 = self.Uequil.copy()
259
+ U0[fluid.label] = rhomid + j * drho
260
+
261
+ model = self.model.copy(initialize=False)
262
+ model.set_initial_conditions(U0)
263
+
264
+ ti, Ui, ri = model.find_steady_state()
265
+ dr += i * j * ri[self.reaction_name]
266
+
267
+ for adsorbate in adsorbates:
268
+ set_dg(adsorbate, -i * dg)
269
+
270
+ for reaction in self.model._reactions:
271
+ reaction.update(T=self.model.T,
272
+ Asite=self.model.Asite,
273
+ L=self.model.z,
274
+ force=True)
275
+
276
+ # the four rates are 2 * dg and 2 * drho apart
277
+ return (rhomid / rmid) * dr / (4 * dg * drho)
278
+
279
+ def check_converged(self, *vals):
280
+ for val in vals:
281
+ for i, key in enumerate(val[0]):
282
+ if np.abs(val[-1][key] - val[-2][key]) > self.tol:
283
+ raise ValueError("Calculation not converged ({}: {}, "
284
+ "change {})! Increase dt or use better "
285
+ "initial guess.".format(
286
+ key, val[-1][key],
287
+ val[-1][key] - val[-2][key]))
@@ -0,0 +1,80 @@
1
+ import warnings
2
+
3
+ from ase.db import connect
4
+ from ase.db.core import Database
5
+
6
+ from micki.reactants import Adsorbate, Gas, Liquid
7
+ from micki.eref import EnergyReference
8
+
9
+ class MickiDBReadError(ValueError):
10
+ pass
11
+
12
+ # Attempts to parse attribute 'name' from dictionary 'data' and raises a
13
+ # parse error if it cannot be found.
14
+ def get_data(row, param):
15
+ if param not in row.data:
16
+ raise MickiDBReadError("DB row named {} does not have '{}' entry!"
17
+ "".format(row.name, param))
18
+ return row.data[param]
19
+
20
+ # Converts a single ASE DB row to a Micki Thermo object.
21
+ def row_to_thermo(row):
22
+ name = row.name
23
+ freqs = get_data(row, 'freqs')
24
+ thermo = get_data(row, 'thermo')
25
+ sites = get_data(row, 'sites')
26
+ rhoref = get_data(row, 'rhoref')
27
+ dE = get_data(row, 'dE')
28
+ symm = get_data(row, 'symm')
29
+ ts = get_data(row, 'ts')
30
+ spin = get_data(row, 'spin')
31
+ D = get_data(row, 'D')
32
+ S = get_data(row, 'S')
33
+
34
+ if thermo == 'Adsorbate':
35
+ return Adsorbate(row.toatoms(), name, freqs,
36
+ ts=ts, sites=sites, dE=dE, symm=symm)
37
+ elif thermo == 'Gas':
38
+ return Gas(row.toatoms(), name, freqs,
39
+ symm=symm, spin=spin, rhoref=rhoref, dE=dE)
40
+ elif thermo == 'Liquid':
41
+ return Liquid(row.toatoms(), name, freqs,
42
+ symm=symm, spin=spin, D=D, S=S, rhoref=rhoref, dE=dE)
43
+ else:
44
+ raise ValueError('Unknown Thermo type {}!'.format(thermo))
45
+
46
+ # Creates a dictionary of Thermo objects from a properly-formatted ASE DB file.
47
+ def read_from_db(db, names=None, eref=None):
48
+ if isinstance(db, str):
49
+ db = connect(db)
50
+ elif not isinstance(db, Database):
51
+ raise ValueError("Must pass active ASE DB connection, "
52
+ "or name of ASE DB file!")
53
+
54
+ species = {}
55
+
56
+ for row in db.select():
57
+ name = row.name
58
+ try:
59
+ species[name] = row_to_thermo(row)
60
+ except MickiDBReadError:
61
+ warnings.warn("Could not parse row {}, skipping.".format(name),
62
+ RuntimeWarning, stacklevel=2)
63
+
64
+ for name, sp in species.items():
65
+ newsites = []
66
+ for site in sp.sites:
67
+ if site in species:
68
+ newsites.append(species[site])
69
+ else:
70
+ raise ValueError("Unknown site named {}!".format(site))
71
+ sp.sites = newsites
72
+
73
+ if eref is not None:
74
+ reference = EnergyReference([species[name] for name in eref])
75
+ for name, sp in species.items():
76
+ sp.eref = reference
77
+
78
+ if names is not None:
79
+ return {name: species[name] for name in names}
80
+ return species