kmcpy 0.1.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.
kmcpy-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Caneparesearch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
kmcpy-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: kmcpy
3
+ Version: 0.1.0
4
+ Summary: Kinetic Monte Carlo Simulation using Python (kMCpy)
5
+ Author-email: kMCpy Development Team <dengzeyu@gmail.com>
6
+ Maintainer-email: Zeyu Deng <dengzeyu@gmail.com>, Weihang Xie <david.xie1998@gmail.com>, Pieremanuele Canepa <pieremanuele.canepa@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2021 Caneparesearch
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/caneparesearch/kmcpy
30
+ Project-URL: Repository, https://github.com/caneparesearch/kmcpy
31
+ Project-URL: Issues, https://github.com/caneparesearch/kmcpy/issues
32
+ Project-URL: Documentation, https://kmcpy.readthedocs.io/
33
+ Keywords: kinetic monte carlo,kmc,simulation,materials science,condensed matter physics,chemistry
34
+ Classifier: Development Status :: 4 - Beta
35
+ Classifier: Intended Audience :: Science/Research
36
+ Classifier: Intended Audience :: Developers
37
+ Classifier: License :: OSI Approved :: MIT License
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Programming Language :: Python :: 3.13
43
+ Classifier: Operating System :: OS Independent
44
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
45
+ Classifier: Topic :: Scientific/Engineering :: Physics
46
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
47
+ Requires-Python: >=3.10
48
+ Description-Content-Type: text/markdown
49
+ License-File: LICENSE
50
+ Requires-Dist: glob2>=0.7
51
+ Requires-Dist: joblib>=1.5.1
52
+ Requires-Dist: numba>=0.61.2
53
+ Requires-Dist: pymatgen>=2025.5.2
54
+ Requires-Dist: scikit-learn>=1.6.1
55
+ Provides-Extra: dev
56
+ Requires-Dist: pytest>=8.0; extra == "dev"
57
+ Requires-Dist: pytest-cov; extra == "dev"
58
+ Provides-Extra: doc
59
+ Requires-Dist: sphinx>=7.0; extra == "doc"
60
+ Requires-Dist: sphinx-rtd-theme; extra == "doc"
61
+ Requires-Dist: nbsphinx; extra == "doc"
62
+ Requires-Dist: sphinx-autodoc-typehints; extra == "doc"
63
+ Requires-Dist: myst-parser; extra == "doc"
64
+ Requires-Dist: tqdm; extra == "doc"
65
+ Requires-Dist: psutil; extra == "doc"
66
+ Dynamic: license-file
67
+
68
+ # Kinetic Monte Carlo Simulation using Python (kMCpy)
69
+ ![image](docs/source/_static/kmcpy_logo.png)
70
+ - Author: Zeyu Deng
71
+ - Email: dengzeyu@gmail.com
72
+
73
+ kMCpy is an open source python based package intended to study the migration of atoms using the kinetic Monte Carlo technique. kMCpy provides an all python, systematic way to compute kinetic properties, which can be readily used for investigation, development, and prediction of new functional materials.
74
+
75
+ This package includes a local cluster expansion model toolkit, a rejection-free kinetic Monte Carlo (rf-kMC) solver, and several python classes to extract ion transport properties such as diffusivities and conductivities.
76
+
77
+ The local cluster expansion model toolkit can be used to fit a model from barrier calculated from first-principles or any other empirical methods. Following the training process the local cluster expansion model can compute migration barriers in crystalline materials within the transition state theory.
78
+
79
+ Some of the advantages of using this package are:
80
+
81
+ 1. kMCpy is fully based on python and is modular which makes it developer centric thus facilitating quick addition of new features.
82
+
83
+ 2. It is cross-platform and supports most operating systems such as Windows, macOS, and Linux.
84
+
85
+ 3. Intensive kMC routines has been optimized into machine code in the fly using Numba (https://numba.pydata.org), which results in manifold increase in performance.
86
+
87
+
88
+ This code has been recently used to explore the transport properties of Na-ion in NaSICON solid electrolyte (https://www.nature.com/articles/s41467-022-32190-7).
89
+ Some of the relevant aspects of the code from the mentioned paper are shown below.
90
+
91
+ The rf-kMC as a part of this code was used to model the Na-ion conductivity in the $\mathrm{Na_{1+x}Zr_{2}Si_{x}P_{3-x}O_{12}}$ which led to the discovery of maximum conductivity of the solid electrolyte is achieved for Na=3.4.
92
+
93
+ ![image](docs/source/_static/computed_conductivity.png)
94
+
95
+ Calculated Na+ diffusivity (a), conductivity (b), Haven's ratio (c) and averaged correlation factor (d) of $\mathrm{Na_{1+x}Zr_{2}Si_{x}P_{3-x}O_{12}}$ at several temperatures: 373 (dark blue circles), 473 (orange squares) and 573 (red triangles) K, respectively. In panel (b), the computed ionic conductivities are compared with the experimental values of this work (Supplementary Fig. 6) at selected temperatures. Experimental values in (b) from this work are depicted with light blue (373 K), yellow (473 K), and red (573 K) crosses belonging to the same $\mathrm{Na_{1+x}Zr_{2}Si_{x}P_{3-x}O_{12}}$ compositions but of pellets with different compacities (>70 and >90%, see legend).
96
+
97
+ # Installation
98
+ ## Prerequisite
99
+ Check `pyproject.toml` for the required packages. The following Python packages are required to run kMCpy:
100
+ - pymatgen: **Windows users need to install Microsoft C++ build tools (https://visualstudio.microsoft.com/visual-cpp-build-tools/) to compile pymatgen.**
101
+ - numba: for fast computation of kMCpy routines
102
+ - scikit-learn: for fitting local cluster expansion model
103
+ - pytest: for unit tests
104
+ - joblib
105
+ - glob2
106
+
107
+ > **⚠️ Warning for Windows users:**
108
+ > You need to install [Microsoft C++ build tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) to compile `pymatgen`.
109
+
110
+ ## Command line environment
111
+ It is highly recommended to install kMCpy using [UV](https://docs.astral.sh/uv/getting-started/installation/) and use it with virtual environment.
112
+
113
+ ```shell
114
+ uv venv #optional if you have already created a venv
115
+ source .venv/bin/activate
116
+ uv sync
117
+ uv pip install .
118
+ ```
119
+
120
+ ## For developers
121
+ ```shell
122
+ uv venv #optional if you have already created a venv
123
+ source .venv/bin/activate
124
+ uv sync --extra dev
125
+ uv pip install -e .
126
+ ```
127
+
128
+ ## Graphic user interface (GUI)
129
+ `wxpython` needs `conda` to be installed.
130
+ ```shell
131
+ conda create -n kmcpy python wxpython -c conda-forge
132
+ conda activate kmcpy
133
+ pip install -r requirement_gui.txt .
134
+ ```
135
+
136
+ ## Build documentation
137
+ - Documentation is built using `pandoc` and `sphinx-build`.
138
+ - You can access the documentation from: `./docs/html/index.html`.
139
+ ```shell
140
+ source .venv/bin/activate
141
+ uv sync --extra doc
142
+ python build_doc.py
143
+ ```
144
+
145
+ # Run kMCpy
146
+ It is recommended to run kMCpy using the API. See examples for more details. A wrapper is also provided if you want to run kMCpy through command line only.
147
+
148
+ - If GUI enabled: try `pythonw gui_wrapper.py` or `python gui_wrapper`
149
+ - If GUI not enabled: `wrapper.py PATH_TO_INPUT.json`
kmcpy-0.1.0/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Kinetic Monte Carlo Simulation using Python (kMCpy)
2
+ ![image](docs/source/_static/kmcpy_logo.png)
3
+ - Author: Zeyu Deng
4
+ - Email: dengzeyu@gmail.com
5
+
6
+ kMCpy is an open source python based package intended to study the migration of atoms using the kinetic Monte Carlo technique. kMCpy provides an all python, systematic way to compute kinetic properties, which can be readily used for investigation, development, and prediction of new functional materials.
7
+
8
+ This package includes a local cluster expansion model toolkit, a rejection-free kinetic Monte Carlo (rf-kMC) solver, and several python classes to extract ion transport properties such as diffusivities and conductivities.
9
+
10
+ The local cluster expansion model toolkit can be used to fit a model from barrier calculated from first-principles or any other empirical methods. Following the training process the local cluster expansion model can compute migration barriers in crystalline materials within the transition state theory.
11
+
12
+ Some of the advantages of using this package are:
13
+
14
+ 1. kMCpy is fully based on python and is modular which makes it developer centric thus facilitating quick addition of new features.
15
+
16
+ 2. It is cross-platform and supports most operating systems such as Windows, macOS, and Linux.
17
+
18
+ 3. Intensive kMC routines has been optimized into machine code in the fly using Numba (https://numba.pydata.org), which results in manifold increase in performance.
19
+
20
+
21
+ This code has been recently used to explore the transport properties of Na-ion in NaSICON solid electrolyte (https://www.nature.com/articles/s41467-022-32190-7).
22
+ Some of the relevant aspects of the code from the mentioned paper are shown below.
23
+
24
+ The rf-kMC as a part of this code was used to model the Na-ion conductivity in the $\mathrm{Na_{1+x}Zr_{2}Si_{x}P_{3-x}O_{12}}$ which led to the discovery of maximum conductivity of the solid electrolyte is achieved for Na=3.4.
25
+
26
+ ![image](docs/source/_static/computed_conductivity.png)
27
+
28
+ Calculated Na+ diffusivity (a), conductivity (b), Haven's ratio (c) and averaged correlation factor (d) of $\mathrm{Na_{1+x}Zr_{2}Si_{x}P_{3-x}O_{12}}$ at several temperatures: 373 (dark blue circles), 473 (orange squares) and 573 (red triangles) K, respectively. In panel (b), the computed ionic conductivities are compared with the experimental values of this work (Supplementary Fig. 6) at selected temperatures. Experimental values in (b) from this work are depicted with light blue (373 K), yellow (473 K), and red (573 K) crosses belonging to the same $\mathrm{Na_{1+x}Zr_{2}Si_{x}P_{3-x}O_{12}}$ compositions but of pellets with different compacities (>70 and >90%, see legend).
29
+
30
+ # Installation
31
+ ## Prerequisite
32
+ Check `pyproject.toml` for the required packages. The following Python packages are required to run kMCpy:
33
+ - pymatgen: **Windows users need to install Microsoft C++ build tools (https://visualstudio.microsoft.com/visual-cpp-build-tools/) to compile pymatgen.**
34
+ - numba: for fast computation of kMCpy routines
35
+ - scikit-learn: for fitting local cluster expansion model
36
+ - pytest: for unit tests
37
+ - joblib
38
+ - glob2
39
+
40
+ > **⚠️ Warning for Windows users:**
41
+ > You need to install [Microsoft C++ build tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) to compile `pymatgen`.
42
+
43
+ ## Command line environment
44
+ It is highly recommended to install kMCpy using [UV](https://docs.astral.sh/uv/getting-started/installation/) and use it with virtual environment.
45
+
46
+ ```shell
47
+ uv venv #optional if you have already created a venv
48
+ source .venv/bin/activate
49
+ uv sync
50
+ uv pip install .
51
+ ```
52
+
53
+ ## For developers
54
+ ```shell
55
+ uv venv #optional if you have already created a venv
56
+ source .venv/bin/activate
57
+ uv sync --extra dev
58
+ uv pip install -e .
59
+ ```
60
+
61
+ ## Graphic user interface (GUI)
62
+ `wxpython` needs `conda` to be installed.
63
+ ```shell
64
+ conda create -n kmcpy python wxpython -c conda-forge
65
+ conda activate kmcpy
66
+ pip install -r requirement_gui.txt .
67
+ ```
68
+
69
+ ## Build documentation
70
+ - Documentation is built using `pandoc` and `sphinx-build`.
71
+ - You can access the documentation from: `./docs/html/index.html`.
72
+ ```shell
73
+ source .venv/bin/activate
74
+ uv sync --extra doc
75
+ python build_doc.py
76
+ ```
77
+
78
+ # Run kMCpy
79
+ It is recommended to run kMCpy using the API. See examples for more details. A wrapper is also provided if you want to run kMCpy through command line only.
80
+
81
+ - If GUI enabled: try `pythonw gui_wrapper.py` or `python gui_wrapper`
82
+ - If GUI not enabled: `wrapper.py PATH_TO_INPUT.json`
@@ -0,0 +1,64 @@
1
+ """Main kMCpy module."""
2
+ import datetime
3
+ import logging
4
+ import os
5
+
6
+ from ._version import __version__
7
+
8
+ __author__ = "Zeyu Deng"
9
+ __author_email__ = "dengzeyu@gmail.com"
10
+
11
+ # Expose the version and the logo function as the public API for this module.
12
+ __all__ = ["__version__", "get_logo"]
13
+
14
+
15
+ # 2. LOGGING SETUP: This is perfect.
16
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
17
+
18
+
19
+ # 3. LOGO FUNCTION: A stateless function to generate and print the logo.
20
+
21
+ def get_logo():
22
+ """
23
+ Prints the kMCpy ASCII logo and version/citation information to the console.
24
+
25
+ This function can be called multiple times. It's recommended to call
26
+ it once at the start of an application's main entry point.
27
+ """
28
+ # Ansi color codes for a professional look.
29
+ class Colors:
30
+ CYAN = '\033[96m'
31
+ YELLOW = '\033[93m'
32
+ BOLD = '\033[1m'
33
+ END = '\033[0m'
34
+
35
+ # The logo art. Using a raw string (r"...") is good practice.
36
+ logo_art = r"""
37
+ _ __ __ _____
38
+ | | | \/ |/ ____|
39
+ | | _| \ / | | _ __ _ _
40
+ | |/ / |\/| | | | '_ \| | | |
41
+ | <| | | | |____| |_) | |_| |
42
+ |_|\_\_| |_|\_____| .__/ \__, |
43
+ | | __/ |
44
+ |_| |___/
45
+ """
46
+
47
+ # Using os.uname() is not cross-platform (it fails on Windows).
48
+ # platform.node() is a more robust alternative.
49
+ import platform
50
+ hostname = platform.node()
51
+
52
+ # Assemble the final message string inside the function.
53
+ # This ensures all information (like datetime) is current.
54
+ message = (
55
+ f"{Colors.CYAN}{Colors.BOLD}{logo_art}{Colors.END}"
56
+ f"kMCpy: A python package to simulate transport properties in solids with kinetic Monte Carlo\n"
57
+ f"{Colors.YELLOW}Please cite:{Colors.END} DOI: 10.1016/j.commatsci.2023.112394 and 10.1038/s41467-022-32190-7 \n"
58
+ f"{Colors.YELLOW}Author:{Colors.END} {__author__} <{__author_email__}>\n"
59
+ f"Version: {__version__}\n"
60
+ f"Timestamp: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
61
+ f"Host: {hostname}\n"
62
+ )
63
+
64
+ return message
@@ -0,0 +1,3 @@
1
+ __all__ = ["__version__"]
2
+
3
+ __version__ = "0.1dev"
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ This module defines the Event class, which encapsulates the information and methods required to represent and analyze a migration event in a lattice-based simulation, such as those used in kinetic Monte Carlo (kMC) studies. The Event class manages indices of mobile ions, local environments, sublattice information, and provides methods for initializing, updating, and serializing event data. It also includes methods for calculating occupation, correlation, migration barriers, and probabilities associated with migration events.
4
+ """
5
+
6
+ import numpy as np
7
+ import numba as nb
8
+ from copy import deepcopy
9
+ import json
10
+ from kmcpy.io import convert
11
+ import logging
12
+
13
+ logger = logging.getLogger(__name__)
14
+ logging.getLogger('numba').setLevel(logging.WARNING)
15
+
16
+ class Event:
17
+ """
18
+ mobile_ion_specie_1_index
19
+ mobile_ion_specie_2_index
20
+ local_env_indices_list
21
+ """
22
+
23
+ def __init__(self):
24
+ pass
25
+
26
+ def initialization(
27
+ self,
28
+ mobile_ion_specie_1_index=12,
29
+ mobile_ion_specie_2_index=15,
30
+ local_env_indices_list=[1, 2, 3, 4, 5],
31
+ ):
32
+ """3rd version of initialization. The input local_env_indices_list is already sorted. Center atom is equivalent to the Na1 in the 1st version and mobile_ion_specie_2_index is equivalent to the Na2 in the 1st version
33
+
34
+ Args:
35
+ mobile_ion_specie_1_index (int, optional): the global index (index in supercell) of the center atom. Defaults to 12.
36
+ mobile_ion_specie_2_index (int, optional): the global index of the atom that the center atom is about to diffuse to. Defaults to 15.
37
+ local_env_indices_list (list, optional): list of integers, which is a list of indices of the neighboring sites in supercell, and is already sorted. Defaults to [1,2,3,4,5].
38
+ """
39
+ self.mobile_ion_specie_1_index = mobile_ion_specie_1_index
40
+ self.mobile_ion_specie_2_index = mobile_ion_specie_2_index
41
+
42
+ self.local_env_indices_list = local_env_indices_list
43
+ self.local_env_indices_list_site = local_env_indices_list
44
+
45
+ def set_sublattice_indices(self, sublattice_indices, sublattice_indices_site):
46
+ self.sublattice_indices = sublattice_indices # this stores the site indices from local_cluster_expansion object
47
+ self.sublattice_indices_site = sublattice_indices_site # this stores the site indices from local_cluster_expansion object
48
+
49
+ def show_info(self):
50
+ logger.info(
51
+ "Event: mobile_ion(1)[%s]<--> mobile_ion(2)[%s]",
52
+ self.mobile_ion_specie_1_index,
53
+ self.mobile_ion_specie_2_index,
54
+ )
55
+ logger.debug('Global sites indices are (excluding O and Zr): %s', self.local_env_indices_list)
56
+ logger.debug('Local template structure: %s', getattr(self, 'sorted_local_structure', None))
57
+
58
+ try:
59
+ logger.info("occ_sublat\tE_KRA\tProbability")
60
+ logger.info("%s\t%s\t%s", self.occ_sublat, self.ekra, self.probability)
61
+ except Exception:
62
+ pass
63
+
64
+ def clear_property(self):
65
+ pass
66
+
67
+ def analyze_local_structure(self, local_env_info):
68
+ #
69
+ indices_sites_group = [(s["site_index"], s["site"]) for s in local_env_info]
70
+
71
+ # this line is to sort the neighbors. First sort by x coordinate, and then sort by specie (Na, then Si/P)
72
+ # the sorted list, store the sequence of hash.
73
+ # for other materials, need to find another method to sort.
74
+ # this sort only works for the NaSICON!
75
+ indices_sites_group_sorted = sorted(
76
+ sorted(indices_sites_group, key=lambda x: x[1].coords[0]),
77
+ key=lambda x: x[1].specie,
78
+ )
79
+
80
+ local_env_indices_list = [s[0] for s in indices_sites_group_sorted]
81
+ return local_env_indices_list
82
+
83
+ # @profile
84
+ def set_occ(self, occ_global):
85
+ self.occ_sublat = deepcopy(
86
+ occ_global[self.local_env_indices_list]
87
+ ) # occ is an 1D numpy array
88
+
89
+ # @profile
90
+ def initialize_corr(self):
91
+ self.corr = np.empty(shape=len(self.sublattice_indices))
92
+ self.corr_site = np.empty(shape=len(self.sublattice_indices_site))
93
+
94
+ # @profile
95
+ def set_corr(self):
96
+ _set_corr(self.corr, self.occ_sublat, self.sublattice_indices)
97
+ _set_corr(self.corr_site, self.occ_sublat, self.sublattice_indices_site)
98
+
99
+ # @profile
100
+ def set_ekra(
101
+ self, keci, empty_cluster, keci_site, empty_cluster_site
102
+ ): # input is the keci and empty_cluster; ekra = corr*keci + empty_cluster
103
+ self.ekra = np.inner(self.corr, keci) + empty_cluster
104
+ self.esite = np.inner(self.corr_site, keci_site) + empty_cluster_site
105
+
106
+ # @profile
107
+ def set_probability(
108
+ self, occ_global, v, T
109
+ ): # calc_probability() will evaluate migration probability for this event, should be updated everytime when change occupation
110
+ k = 8.617333262145 * 10 ** (-2) # unit in meV/K
111
+ direction = (
112
+ occ_global[self.mobile_ion_specie_2_index]
113
+ - occ_global[self.mobile_ion_specie_1_index]
114
+ ) / 2 # 1 if na1 -> na2, -1 if na2 -> na1
115
+ self.barrier = self.ekra + direction * self.esite / 2 # ekra
116
+ self.probability = abs(direction) * v * np.exp(-1 * (self.barrier) / (k * T))
117
+
118
+ # @profile
119
+ def update_event(
120
+ self, occ_global, v, T, keci, empty_cluster, keci_site, empty_cluster_site
121
+ ):
122
+ self.set_occ(occ_global) # change occupation and correlation for this unit
123
+ self.set_corr()
124
+ self.set_ekra(
125
+ keci, empty_cluster, keci_site, empty_cluster_site
126
+ ) # calculate ekra and probability
127
+ self.set_probability(occ_global, v, T)
128
+
129
+ def as_dict(self):
130
+ d = {
131
+ "mobile_ion_specie_1_index": self.mobile_ion_specie_1_index,
132
+ "mobile_ion_specie_2_index": self.mobile_ion_specie_2_index,
133
+ "local_env_indices_list": self.local_env_indices_list,
134
+ "local_env_indices_list": self.local_env_indices_list,
135
+ "local_env_indices_list_site": self.local_env_indices_list_site,
136
+ }
137
+ return d
138
+
139
+ def to_json(self, fname):
140
+ logger.info("Saving: %s", fname)
141
+ with open(fname, "w") as fhandle:
142
+ d = self.as_dict()
143
+ jsonStr = json.dumps(
144
+ d, indent=4, default=convert
145
+ ) # to get rid of errors of int64
146
+ fhandle.write(jsonStr)
147
+
148
+ @classmethod
149
+ def from_json(self, fname):
150
+ logger.info("Loading: %s", fname)
151
+ with open(fname, "rb") as fhandle:
152
+ objDict = json.load(fhandle)
153
+ obj = Event()
154
+ obj.__dict__ = objDict
155
+ return obj
156
+ @classmethod
157
+ def from_dict(self, event_dict): # convert dict into event object
158
+ event = Event()
159
+ event.__dict__ = event_dict
160
+ return event
161
+
162
+
163
+ @nb.njit
164
+ def _set_corr(corr, occ_latt, sublattice_indices):
165
+ i = 0
166
+ for sublat_ind_orbit in sublattice_indices:
167
+ corr[i] = 0
168
+ for sublat_ind_cluster in sublat_ind_orbit:
169
+ corr_cluster = 1
170
+ for occ_site in sublat_ind_cluster:
171
+ corr_cluster *= occ_latt[occ_site]
172
+ corr[i] += corr_cluster
173
+ i += 1