llgs-simulation 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ian Chang
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.
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.4
2
+ Name: llgs-simulation
3
+ Version: 0.1.0
4
+ Summary: Spin-dynamics simulations using the Landau-Lifshitz-Gilbert-Slonczewski equation
5
+ Author: Ian Chang
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Ian Chang
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/ianchung621/LLGS-simulation
29
+ Project-URL: Repository, https://github.com/ianchung621/LLGS-simulation.git
30
+ Project-URL: Issues, https://github.com/ianchung621/LLGS-simulation/issues
31
+ Keywords: spintronics,LLGS,magnetism,spin dynamics,simulation
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3 :: Only
38
+ Classifier: Programming Language :: Python :: 3.9
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: Topic :: Scientific/Engineering :: Physics
44
+ Requires-Python: >=3.9
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: h5py
48
+ Requires-Dist: matplotlib
49
+ Requires-Dist: numba
50
+ Requires-Dist: numpy
51
+ Requires-Dist: scipy
52
+ Requires-Dist: tqdm
53
+ Provides-Extra: test
54
+ Requires-Dist: pytest; extra == "test"
55
+ Requires-Dist: pytest-cov; extra == "test"
56
+ Dynamic: license-file
57
+
58
+ # LLGS Simulation
59
+
60
+ [![Tests](https://github.com/ianchung621/LLGS-simulation/actions/workflows/test.yml/badge.svg)](https://github.com/ianchung621/LLGS-simulation/actions/workflows/test.yml)
61
+ [![Coverage](https://codecov.io/gh/ianchung621/LLGS-simulation/branch/main/graph/badge.svg)](https://codecov.io/gh/ianchung621/LLGS-simulation)
62
+ ![Python](https://img.shields.io/badge/python-3.9--3.13-blue)
63
+ ![OS](https://img.shields.io/badge/OS-Linux%20%7C%20macOS%20%7C%20Windows-lightgrey)
64
+
65
+ This package provides tools for simulating and analyzing spin dynamics using
66
+ the Landau-Lifshitz-Gilbert-Slonczewski (LLGS) equation on two-dimensional
67
+ lattices. It supports antiferromagnetic exchange, DMI, anisotropy, external
68
+ fields, and spin-orbit torque.
69
+
70
+ ## Install
71
+
72
+ LLGS Simulation requires Python 3.9 or newer:
73
+
74
+ ```bash
75
+ python -m venv .venv
76
+ source .venv/bin/activate
77
+ python -m pip install llgs-simulation
78
+ ```
79
+
80
+ ## Example Usage
81
+
82
+ Below is a step-by-step demonstration of how to use the repository to simulate spin dynamics and visualize the results.
83
+
84
+ ### 1. Creating a Lattice Object
85
+
86
+ The `lattice.py` module allows you to define a spin lattice. Here's an example of creating a hexagonal lattice:
87
+
88
+ ```python
89
+ import numpy as np
90
+
91
+ from llgs import Lattice_2D
92
+
93
+ honeycomb = Lattice_2D(
94
+ n_a=10,
95
+ n_b=8,
96
+ n_site=2,
97
+ r_a=[np.sqrt(3), 0],
98
+ r_b=[0.5 * np.sqrt(3), 1.5],
99
+ r_site=[
100
+ [1 / 3, 1 / 3],
101
+ [2 / 3, 2 / 3],
102
+ ],
103
+ )
104
+ honeycomb.plot(draw_unitcell=True)
105
+ ```
106
+
107
+ ![Honeycomb lattice](https://raw.githubusercontent.com/ianchung621/LLGS-simulation/main/doc/lattice.png)
108
+
109
+ ### 2. Initializing Spins
110
+
111
+ Initialize the spins on the lattice to a desired configuration:
112
+
113
+ ```python
114
+ zigzag_config = {
115
+ "b % 2 == 0": np.array([1, 0, 0]),
116
+ "b % 2 == 1": np.array([-1, 0, 0]),
117
+ }
118
+ honeycomb.initialize_spin(zigzag_config)
119
+ honeycomb.plot()
120
+ ```
121
+
122
+ ![Initialized spins](https://raw.githubusercontent.com/ianchung621/LLGS-simulation/main/doc/spin_initialized.png)
123
+
124
+ ### 3. Setting Up Parameters for Simulation
125
+
126
+ Build the exchange matrix from exact lattice bonds, then configure the
127
+ simulation. Each bond is `(source_site, target_site, cell_offset, coupling)`;
128
+ the reverse bond is added automatically.
129
+
130
+ ```python
131
+ from llgs import LLGS_Simulation_2D, build_exchange
132
+
133
+ J1 = -11.2 # exchange-matrix coefficient, Tesla
134
+ exchange_bonds = [
135
+ (0, 1, (0, 0), J1),
136
+ (1, 0, (0, 1), J1),
137
+ (1, 0, (1, 0), J1),
138
+ ]
139
+ H_E = build_exchange(honeycomb, exchange_bonds)
140
+ H_ext = np.array([5.0, 5.0, 0.0])
141
+
142
+ sim = LLGS_Simulation_2D(
143
+ honeycomb,
144
+ H_E=H_E,
145
+ H_ext=H_ext,
146
+ alpha=0.1,
147
+ H_para=0.086,
148
+ H_perp=1.812,
149
+ io_foldername="Data",
150
+ io_filename="results_RK4",
151
+ method="RK4",
152
+ )
153
+ ```
154
+
155
+ `H_E` may be a dense `(N, N)` array or a SciPy sparse matrix. For sparse DMI,
156
+ pass `H_DMI` as a sequence of three sparse `(N, N)` matrices, one for each
157
+ Cartesian component. Dense DMI remains a `(3, N, N)` array. Use
158
+ `matrix_type="sparse"` to convert both fields to CSR matrices,
159
+ `matrix_type="dense"` to convert them to NumPy arrays, or the default
160
+ `matrix_type="auto"` to preserve the supplied representation.
161
+
162
+ ### 4. Running the Simulation
163
+
164
+ Run the simulation for a specified number of steps and save the results:
165
+
166
+ ```python
167
+ sim.evolve(dt=2e-4, max_iters=1000)
168
+ ```
169
+
170
+ ### 5. Visualizing Spin Dynamics
171
+
172
+ The `read_result.py` module reads the simulation results and creates visualizations. Here is how you can animate the spin dynamics:
173
+
174
+ ```python
175
+ from llgs import ReadResult
176
+
177
+ results = ReadResult("Data/results_RK4.h5")
178
+
179
+ results.animate(period=50, save_fn="Data/movie.gif")
180
+ ```
181
+
182
+ ### Example Output
183
+
184
+ Here is an example of how the animation might look:
185
+
186
+ ![Spin dynamics animation](https://raw.githubusercontent.com/ianchung621/LLGS-simulation/main/doc/spin_animation.gif)
187
+
188
+ ### Additional Details
189
+
190
+ For a comprehensive explanation of the methods, equations, and parameters,
191
+ see the [example notebook](https://github.com/ianchung621/LLGS-simulation/blob/main/example.ipynb).
192
+
193
+ This notebook includes:
194
+ - Detailed descriptions of lattice construction.
195
+ - Explanation of the exchange field matrix and LLGS simulation.
196
+ - Mathematical derivations and parameter setups.
@@ -0,0 +1,139 @@
1
+ # LLGS Simulation
2
+
3
+ [![Tests](https://github.com/ianchung621/LLGS-simulation/actions/workflows/test.yml/badge.svg)](https://github.com/ianchung621/LLGS-simulation/actions/workflows/test.yml)
4
+ [![Coverage](https://codecov.io/gh/ianchung621/LLGS-simulation/branch/main/graph/badge.svg)](https://codecov.io/gh/ianchung621/LLGS-simulation)
5
+ ![Python](https://img.shields.io/badge/python-3.9--3.13-blue)
6
+ ![OS](https://img.shields.io/badge/OS-Linux%20%7C%20macOS%20%7C%20Windows-lightgrey)
7
+
8
+ This package provides tools for simulating and analyzing spin dynamics using
9
+ the Landau-Lifshitz-Gilbert-Slonczewski (LLGS) equation on two-dimensional
10
+ lattices. It supports antiferromagnetic exchange, DMI, anisotropy, external
11
+ fields, and spin-orbit torque.
12
+
13
+ ## Install
14
+
15
+ LLGS Simulation requires Python 3.9 or newer:
16
+
17
+ ```bash
18
+ python -m venv .venv
19
+ source .venv/bin/activate
20
+ python -m pip install llgs-simulation
21
+ ```
22
+
23
+ ## Example Usage
24
+
25
+ Below is a step-by-step demonstration of how to use the repository to simulate spin dynamics and visualize the results.
26
+
27
+ ### 1. Creating a Lattice Object
28
+
29
+ The `lattice.py` module allows you to define a spin lattice. Here's an example of creating a hexagonal lattice:
30
+
31
+ ```python
32
+ import numpy as np
33
+
34
+ from llgs import Lattice_2D
35
+
36
+ honeycomb = Lattice_2D(
37
+ n_a=10,
38
+ n_b=8,
39
+ n_site=2,
40
+ r_a=[np.sqrt(3), 0],
41
+ r_b=[0.5 * np.sqrt(3), 1.5],
42
+ r_site=[
43
+ [1 / 3, 1 / 3],
44
+ [2 / 3, 2 / 3],
45
+ ],
46
+ )
47
+ honeycomb.plot(draw_unitcell=True)
48
+ ```
49
+
50
+ ![Honeycomb lattice](https://raw.githubusercontent.com/ianchung621/LLGS-simulation/main/doc/lattice.png)
51
+
52
+ ### 2. Initializing Spins
53
+
54
+ Initialize the spins on the lattice to a desired configuration:
55
+
56
+ ```python
57
+ zigzag_config = {
58
+ "b % 2 == 0": np.array([1, 0, 0]),
59
+ "b % 2 == 1": np.array([-1, 0, 0]),
60
+ }
61
+ honeycomb.initialize_spin(zigzag_config)
62
+ honeycomb.plot()
63
+ ```
64
+
65
+ ![Initialized spins](https://raw.githubusercontent.com/ianchung621/LLGS-simulation/main/doc/spin_initialized.png)
66
+
67
+ ### 3. Setting Up Parameters for Simulation
68
+
69
+ Build the exchange matrix from exact lattice bonds, then configure the
70
+ simulation. Each bond is `(source_site, target_site, cell_offset, coupling)`;
71
+ the reverse bond is added automatically.
72
+
73
+ ```python
74
+ from llgs import LLGS_Simulation_2D, build_exchange
75
+
76
+ J1 = -11.2 # exchange-matrix coefficient, Tesla
77
+ exchange_bonds = [
78
+ (0, 1, (0, 0), J1),
79
+ (1, 0, (0, 1), J1),
80
+ (1, 0, (1, 0), J1),
81
+ ]
82
+ H_E = build_exchange(honeycomb, exchange_bonds)
83
+ H_ext = np.array([5.0, 5.0, 0.0])
84
+
85
+ sim = LLGS_Simulation_2D(
86
+ honeycomb,
87
+ H_E=H_E,
88
+ H_ext=H_ext,
89
+ alpha=0.1,
90
+ H_para=0.086,
91
+ H_perp=1.812,
92
+ io_foldername="Data",
93
+ io_filename="results_RK4",
94
+ method="RK4",
95
+ )
96
+ ```
97
+
98
+ `H_E` may be a dense `(N, N)` array or a SciPy sparse matrix. For sparse DMI,
99
+ pass `H_DMI` as a sequence of three sparse `(N, N)` matrices, one for each
100
+ Cartesian component. Dense DMI remains a `(3, N, N)` array. Use
101
+ `matrix_type="sparse"` to convert both fields to CSR matrices,
102
+ `matrix_type="dense"` to convert them to NumPy arrays, or the default
103
+ `matrix_type="auto"` to preserve the supplied representation.
104
+
105
+ ### 4. Running the Simulation
106
+
107
+ Run the simulation for a specified number of steps and save the results:
108
+
109
+ ```python
110
+ sim.evolve(dt=2e-4, max_iters=1000)
111
+ ```
112
+
113
+ ### 5. Visualizing Spin Dynamics
114
+
115
+ The `read_result.py` module reads the simulation results and creates visualizations. Here is how you can animate the spin dynamics:
116
+
117
+ ```python
118
+ from llgs import ReadResult
119
+
120
+ results = ReadResult("Data/results_RK4.h5")
121
+
122
+ results.animate(period=50, save_fn="Data/movie.gif")
123
+ ```
124
+
125
+ ### Example Output
126
+
127
+ Here is an example of how the animation might look:
128
+
129
+ ![Spin dynamics animation](https://raw.githubusercontent.com/ianchung621/LLGS-simulation/main/doc/spin_animation.gif)
130
+
131
+ ### Additional Details
132
+
133
+ For a comprehensive explanation of the methods, equations, and parameters,
134
+ see the [example notebook](https://github.com/ianchung621/LLGS-simulation/blob/main/example.ipynb).
135
+
136
+ This notebook includes:
137
+ - Detailed descriptions of lattice construction.
138
+ - Explanation of the exchange field matrix and LLGS simulation.
139
+ - Mathematical derivations and parameter setups.
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "llgs-simulation"
7
+ version = "0.1.0"
8
+ description = "Spin-dynamics simulations using the Landau-Lifshitz-Gilbert-Slonczewski equation"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { file = "LICENSE" }
12
+ authors = [
13
+ { name = "Ian Chang" },
14
+ ]
15
+ keywords = ["spintronics", "LLGS", "magnetism", "spin dynamics", "simulation"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Science/Research",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3 :: Only",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Topic :: Scientific/Engineering :: Physics",
29
+ ]
30
+ dependencies = [
31
+ "h5py",
32
+ "matplotlib",
33
+ "numba",
34
+ "numpy",
35
+ "scipy",
36
+ "tqdm",
37
+ ]
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/ianchung621/LLGS-simulation"
41
+ Repository = "https://github.com/ianchung621/LLGS-simulation.git"
42
+ Issues = "https://github.com/ianchung621/LLGS-simulation/issues"
43
+
44
+ [project.optional-dependencies]
45
+ test = ["pytest", "pytest-cov"]
46
+
47
+ [tool.setuptools.packages.find]
48
+ where = ["src"]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+ pythonpath = ["."]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+