DimSpin 0.1.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.
dimspin/Team_Zeeman.py ADDED
@@ -0,0 +1,22 @@
1
+ """Electron Zeeman term for a static magnetic field along the laboratory z axis."""
2
+
3
+ from .Spin_Operators import Sx_get, Sy_get, Sz_get
4
+
5
+ # mu_B / h in MHz/G, converts g * B (G) to frequency (MHz).
6
+ MU_B_H = 1.399624493607271
7
+
8
+
9
+ def H_Zeeman(Bz, g, S, I):
10
+ """
11
+ Inputs: field Bz (G), 3x3 g tensor, electron spin S, nuclear spin I.
12
+
13
+ Returns: the electron Zeeman Hamiltonian for a field along z.
14
+
15
+ Notes: only the z row of ``g`` enters, because the field is along the
16
+ laboratory z axis.
17
+ """
18
+ Sx = Sx_get(S, I)
19
+ Sy = Sy_get(S, I)
20
+ Sz = Sz_get(S, I)
21
+
22
+ return MU_B_H * Bz * (g[2][0] * Sx + g[2][1] * Sy + g[2][2] * Sz)
dimspin/Tensor.py ADDED
@@ -0,0 +1,71 @@
1
+ """Construct g, D, A and spin-electric coupling tensors."""
2
+
3
+ import numpy as np
4
+
5
+
6
+ def gtensor(gx, gy, gz):
7
+ """Return the diagonal g tensor."""
8
+ return np.array([[gx, 0, 0],
9
+ [0, gy, 0],
10
+ [0, 0, gz]])
11
+
12
+
13
+ def Dtensor(D, E):
14
+ """Return the traceless zero-field-splitting tensor from D and E."""
15
+ return np.array([[-D/3 + E, 0, 0],
16
+ [0, -D/3 - E, 0],
17
+ [0, 0, 2*D/3]])
18
+
19
+
20
+ def Atensor(Ax, Ay, Az):
21
+ """Return the diagonal hyperfine tensor."""
22
+ return np.array([[Ax, 0, 0],
23
+ [0, Ay, 0],
24
+ [0, 0, Az]])
25
+
26
+
27
+ def unpack_tensor_3x6(T):
28
+ """Return the (3, 3, 3) stack of blocks from a 3x6 packed tensor.
29
+
30
+ Each row holds one electric-field direction with the columns
31
+ (xx, yy, zz, yz, xz, xy) of a symmetric 3x3 block.
32
+ """
33
+ arr = np.asarray(T, dtype=float)
34
+ if arr.shape != (3, 6):
35
+ raise ValueError('packed tensor must have shape (3, 6)')
36
+ stack = np.zeros((3, 3, 3))
37
+ for a in range(3):
38
+ xx, yy, zz, yz, xz, xy = arr[a]
39
+ stack[a] = ((xx, xy, xz), (xy, yy, yz), (xz, yz, zz))
40
+ return stack
41
+
42
+
43
+ def unpack_tensor_3x5(R):
44
+ """Return the (3, 3, 3) stack of traceless blocks from a 3x5 tensor.
45
+
46
+ Each row holds one electric-field direction with the columns
47
+ (D, E, yz, xz, xy), giving xx = -D/3 + E, yy = -D/3 - E, zz = 2D/3. The
48
+ trace part is not representable here; it shifts all levels by a constant
49
+ and does not affect the spectrum.
50
+ """
51
+ arr = np.asarray(R, dtype=float)
52
+ if arr.shape != (3, 5):
53
+ raise ValueError('short tensor must have shape (3, 5)')
54
+ stack = np.zeros((3, 3, 3))
55
+ for a in range(3):
56
+ D, E, yz, xz, xy = arr[a]
57
+ stack[a] = ((-D / 3 + E, xy, xz),
58
+ (xy, -D / 3 - E, yz),
59
+ (xz, yz, 2 * D / 3))
60
+ return stack
61
+
62
+
63
+ def Tijk2Txyz(T):
64
+ """Split a 3x6 SEC tensor into its Tx, Ty and Tz components.
65
+
66
+ Used for every spin-electric coupling tensor (T, R and F), not only T.
67
+ Setting Tx, Ty and Tz directly is recommended when the component
68
+ matrices are already available.
69
+ """
70
+ stack = unpack_tensor_3x6(T)
71
+ return stack[0], stack[1], stack[2]
@@ -0,0 +1,34 @@
1
+ """Selection of observable transitions after the resonance search.
2
+
3
+ The search methods return every transition they find. This module decides
4
+ which of them to keep for the spectrum: the strongest allowed transitions are
5
+ always kept, and forbidden transitions are kept only while their intensity is
6
+ above a relative threshold.
7
+ """
8
+
9
+
10
+ def truncate_observable(transitions, num_allowed, rel_thresh=1e-3):
11
+ """
12
+ Inputs: transitions (field, jj, kk, intensity); number of allowed
13
+ transitions to keep; relative intensity threshold.
14
+
15
+ Returns: the kept transitions, sorted by decreasing intensity magnitude.
16
+
17
+ Notes: the ``num_allowed`` strongest transitions are always kept; beyond
18
+ them, a transition is kept only while its intensity exceeds
19
+ ``rel_thresh`` times the maximum, which keeps observable forbidden lines
20
+ in systems with large anisotropy.
21
+ """
22
+ if not transitions:
23
+ return []
24
+ ordered = sorted(transitions, key=lambda t: -abs(t[3]))
25
+ max_int = abs(ordered[0][3])
26
+ if max_int <= 0.0:
27
+ return []
28
+ keep = list(ordered[:num_allowed])
29
+ for t in ordered[num_allowed:]:
30
+ if abs(t[3]) > rel_thresh * max_int:
31
+ keep.append(t)
32
+ else:
33
+ break
34
+ return keep
@@ -0,0 +1,9 @@
1
+ """Normalize a three-component vector."""
2
+
3
+ import numpy as np
4
+
5
+
6
+ def vec_normalize(a):
7
+ """Return ``a`` scaled to unit length."""
8
+ m = np.sqrt((a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2]))
9
+ return a/m
dimspin/__init__.py ADDED
@@ -0,0 +1,28 @@
1
+ """DimSpin: numerical EPR/ESR spectrum simulator.
2
+
3
+ The public API is:
4
+
5
+ - :class:`Spin`: spin centre, tensors and Hamiltonian state.
6
+ - :class:`Spec`: experimental parameters.
7
+ - :func:`autosim`: run a simulation and return the spectrum.
8
+ - :func:`plot_energy_levels`: draw an energy-level diagram for one
9
+ crystal orientation.
10
+
11
+ Two resonance-search methods are available: ``High_Field_Method`` and
12
+ ``Adaptive_Grid_Method``.
13
+ """
14
+
15
+ from .AutoSim import autosim
16
+ from .Class_Spec import Spec
17
+ from .Class_Spin import Spin
18
+ from .Levels_Plot import plot_energy_levels
19
+
20
+ __version__ = "0.1.0"
21
+
22
+ __all__ = [
23
+ "Spin",
24
+ "Spec",
25
+ "autosim",
26
+ "plot_energy_levels",
27
+ "__version__",
28
+ ]
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: DimSpin
3
+ Version: 0.1.0
4
+ Summary: EPR/ESR spectrum simulator for spin Hamiltonians and spin-electric coupling (SEC) tensors, featuring EFM, MFM and 2D angle-dependent single-crystal analysis
5
+ Author: Jia-Xin Chen
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/deservecjx/DimSpin
8
+ Project-URL: Repository, https://github.com/deservecjx/DimSpin
9
+ Keywords: EPR,ESR,electron paramagnetic resonance,spin Hamiltonian,spin-electric coupling,electric-field modulation,spectroscopy
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
18
+ Classifier: Topic :: Scientific/Engineering :: Physics
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.23
23
+ Requires-Dist: scipy>=1.9
24
+ Provides-Extra: plot
25
+ Requires-Dist: matplotlib>=3.6; extra == "plot"
26
+ Provides-Extra: docs
27
+ Requires-Dist: sphinx>=7; extra == "docs"
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8; extra == "dev"
30
+ Requires-Dist: pytest-cov>=5; extra == "dev"
31
+ Requires-Dist: ruff>=0.6; extra == "dev"
32
+ Requires-Dist: build>=1.2; extra == "dev"
33
+ Requires-Dist: twine>=5; extra == "dev"
34
+ Requires-Dist: matplotlib>=3.6; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # DimSpin
38
+
39
+ DimSpin is an EPR/ESR spectrum simulator for spin Hamiltonians and
40
+ spin-electric coupling (SEC) tensors (T, R, F), featuring electric-field
41
+ modulation (EFM), magnetic-field modulation (MFM), and 2D angle-dependent
42
+ single-crystal analysis.
43
+
44
+ > **Status:** 0.1.0. Core modules, public API, documentation and examples are
45
+ > in place.
46
+
47
+ ## Planned scope
48
+
49
+ - Spin systems with electron spin `S` and nuclear spin `I`
50
+ - Zeeman, zero-field splitting, hyperfine and high-order zero-field terms
51
+ - Magnetic-field modulation, electric-field modulation and parameter modulation
52
+ - Single-crystal one-side, single-crystal rotation and powder modes
53
+ - Resonance search with `High_Field_Method` and `Adaptive_Grid_Method`
54
+ - Voigt/Lorentzian/Gaussian line broadening, parallel evaluation and energy-level plots
55
+
56
+ ## Quick start
57
+
58
+ ```python
59
+ from dimspin import Spec, Spin, autosim
60
+
61
+ spin = Spin(1/2, 0)
62
+ spin.g = [2.009, 2.006, 2.002]
63
+
64
+ spec = Spec()
65
+ spec.mwfreq = 9560.0
66
+ spec.fieldrange = [3300.0, 3600.0]
67
+ spec.specpoints = 800
68
+ spec.lw_lorentzian = 0.5
69
+ spec.Bmod = 1.0
70
+
71
+ spectrum = autosim(spin, spec)
72
+ ```
73
+
74
+ More complete scripts are in [`examples/`](examples).
75
+
76
+ ## Installation
77
+
78
+ ```bash
79
+ pip install DimSpin
80
+ ```
81
+
82
+ Plotting needs the optional extra:
83
+
84
+ ```bash
85
+ pip install "DimSpin[plot]"
86
+ ```
87
+
88
+ ## Units and conventions
89
+
90
+ Magnetic fields are in gauss, energies in MHz and temperatures in kelvin.
91
+ Euler angles and rotation matrices use radians, while crystal-rotation ranges
92
+ are in degrees. Line shapes are area-normalized. See the
93
+ [documentation](docs/index.rst) for the Hamiltonian terms, frame conventions
94
+ and method descriptions.
95
+
96
+ ## Development setup
97
+
98
+ ```bash
99
+ python -m venv .venv
100
+ # Windows: .venv\Scripts\activate
101
+ # Linux/macOS: source .venv/bin/activate
102
+ python -m pip install --upgrade pip
103
+ pip install -e ".[dev]"
104
+ ```
105
+
106
+ ## Tests
107
+
108
+ ```bash
109
+ pytest
110
+ ```
111
+
112
+ ## License
113
+
114
+ MIT. See [LICENSE](LICENSE).
115
+
116
+ ## Citation
117
+
118
+ If you use DimSpin in your work, please cite the associated article:
119
+
120
+ > Jia-Xin Chen, You-Chao Liu, Qing-Song Deng, Ji-Min Song, Meng-Qi Zhong,
121
+ > Meng-Xiang Wu, Zheng-Chuan Lin, Zheng Zhang, Song Gao, Ye-Xin Wang,
122
+ > Zheng Liu and Shang-Da Jiang,
123
+ > *Quantification of the Molecular Spin-Electric Coupling Tensors: An
124
+ > EPR-Based Approach*, 2026 (in preparation).
125
+
126
+ Until the article is published, please cite this repository and its version.
127
+ Full citation metadata is provided in [CITATION.cff](CITATION.cff).
128
+
129
+ ## References
130
+
131
+ The adaptive-grid resonance search follows ideas from EasySpin:
132
+
133
+ > S. Stoll and A. Schweiger, *EasySpin, a comprehensive software package for
134
+ > spectral simulation and analysis in EPR*, J. Magn. Reson. **178** (2006)
135
+ > 42-55, doi:10.1016/j.jmr.2005.08.013.
136
+
137
+ ## Third-party data
138
+
139
+ The space-group operations in `dimspin.Space_Group` are generated with
140
+ [spglib](https://spglib.readthedocs.io) (BSD-3 license). Please cite
141
+ A. Togo, K. Shinohara and I. Tanaka, *Sci. Technol. Adv. Mater. Methods* 4,
142
+ 2384822 (2024), doi:10.1080/27660400.2024.2384822.
@@ -0,0 +1,40 @@
1
+ dimspin/Adaptive_Grid_Method.py,sha256=oDWlFDztghk4psganC6Eo7dd20E1Xv2if0H6CIN8ZaA,8192
2
+ dimspin/AutoSim.py,sha256=JZEu4aL9AjsCrI0C5yyKnzoVxUQXIY88_Ybg7iU8eHY,4492
3
+ dimspin/Class_Spec.py,sha256=czlmmzMq61s9f5QLFi2tmuFJJVcez6KuKlX1LgiuzQI,11744
4
+ dimspin/Class_Spin.py,sha256=FYtgl3uyrUlFnwEveHjGUHKfLBS8CavMBr4Ybl_ma7k,19115
5
+ dimspin/Crystal_Rotation.py,sha256=bCVaNOcns0YpnuMleIMzT2ett1qMXUAuUW9-jlQWc58,2382
6
+ dimspin/ETeam_Hyperfine.py,sha256=23uWEOSm0_TvMv6ySR0H6Nrx_QzaJPlwV3hcXWwcYZE,889
7
+ dimspin/ETeam_ZFS.py,sha256=G2bhe91_8FS4t7UhTbgMKKfO-RFSn4jEecUafWgyDVI,815
8
+ dimspin/ETeam_Zeeman.py,sha256=OlAfZFDhlr7OGCG21w2GixfNPT7ZOL2FCRmToPR7JM4,913
9
+ dimspin/Eigenfield_Method.py,sha256=7TfXnWp-qfLW_GjjPLzZvEOvwlFr5zzgT0xHstrKfAU,4461
10
+ dimspin/Eular2Rot.py,sha256=93mQnvnPB85p14aYjRhRml40wwjq3lqLqhqWV5f53yc,1804
11
+ dimspin/Fibonacci_Orientation.py,sha256=PimE95J76HHwelNiI_jUy1zgNbl6UzU76ewU2DtnkJo,540
12
+ dimspin/High_Field_Method.py,sha256=WuaVaBHWIaAuXHyOO71uPlRGc8XbHVsSLB9yQJyvNDk,5698
13
+ dimspin/Levels_Plot.py,sha256=8U61gRDAcfRzQqPxknhy50RWZhDV2bB8kg_s5S_CZ68,4515
14
+ dimspin/Line_Broadening.py,sha256=v-mwhSZDnPXlrgmCi31366a17_pVUOCJfpWOAlncOSA,6752
15
+ dimspin/Orientation_Switch.py,sha256=2sIBdWSMACkBXlKjkdmX0iklwguUsRawPQ3J975Z_oA,908
16
+ dimspin/Parallel.py,sha256=HM0xvFZcZWeAWGx8J_gGX7VhJeAtUvrQdtrqKjoedqM,3549
17
+ dimspin/Pointsnum_Optimise.py,sha256=bmZHXbW9olmfu96TiOlMxvbg07i_Yy1mo1NVg8DyIxc,584
18
+ dimspin/Powder.py,sha256=X_du6F4VperDC0RbRtEbcDAioaZpztRanYg40Z5Emm8,4356
19
+ dimspin/Rodrigues_Rotation.py,sha256=978pKTuhN8SFvhQr9JyCCfAlcU7bGMY8ic6MUh43ruk,403
20
+ dimspin/Root_Finder.py,sha256=rjlU5iqzda7jEjjVdOHeIabErYoamoBIYQzX5f5yV6E,7412
21
+ dimspin/Show_Spectra.py,sha256=m_qhNlWJ--Bzjfuv55ZJL4AnAe-ljwuQa6fLNIawYUA,1535
22
+ dimspin/Space_Group.py,sha256=wGwrkjB3YpjIV4Y2zVM1j0Fxfmi6EelDnFqtsEw6HYg,475836
23
+ dimspin/Space_Group_Expand.py,sha256=eq4x4hO1JjWRjDrehZL-5F_0u9eEfAT_euR9nLLrtuk,4978
24
+ dimspin/Space_Group_L.py,sha256=VqyQ4K8pph7kuvVfK4LRYAJEf311vXppZr-aJdos-m4,4036
25
+ dimspin/Spec_Oneside.py,sha256=-b-ctQ_w90NbOh6yirwxnTqZ--mGf7aB5zXu-mmqDrA,2627
26
+ dimspin/Spin_Operators.py,sha256=5pu7zuKoavBv2WzEuvY2tB-mpOt8wlqXigrZtZHjwjA,2330
27
+ dimspin/Steven_Operator.py,sha256=3xVYTPtmRvzSOVLYKJsLo1lrGGOhtStJ1XbLFOe7crI,5263
28
+ dimspin/Team_Hyperfine.py,sha256=vIp89_leyCHU33xeX-qikUFBCmEUxbH_1i3ftKpfTeI,636
29
+ dimspin/Team_ZFS.py,sha256=ylaxYGA6YjskaTcVCOe1LN-lmTs-mp61azFtTlgl07g,654
30
+ dimspin/Team_ZFS_HighOrder.py,sha256=ucpUgzanU8unsYg-J7gdQr1FVA4x5KkDTvhzjoXWz9g,1453
31
+ dimspin/Team_Zeeman.py,sha256=6Kbp00BWX6X4xKGMv8N1_705HsZpir5Rq6nJ36zQvEQ,644
32
+ dimspin/Tensor.py,sha256=TcqsAa9o8oA87Sms9bemHp6kxWFH6tz3LcyDXssIi7w,2235
33
+ dimspin/Truncate_Observable.py,sha256=qcckLXYZWNvPv4ncXNSd4JgmckQcZscy-7oocLbbHJk,1247
34
+ dimspin/Vec_normalize.py,sha256=Aubv7eY1BviXFwBXA7bJrW9q8oQbQk2JB6cXV8zPSyg,200
35
+ dimspin/__init__.py,sha256=_uTEERLkFc017sp3EIZvVWgsmuJgsPVQrp5XHu6GB6I,680
36
+ dimspin-0.1.0.dist-info/licenses/LICENSE,sha256=_Fnr0bF4qFabFgcXI9TqPj7FqVelRkcY5NPYM22RMhI,1069
37
+ dimspin-0.1.0.dist-info/METADATA,sha256=g4Qrq_R8Kacl3G7dkN1rTDJ0-dlBAQMtQFFhXwS-lmA,4499
38
+ dimspin-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
39
+ dimspin-0.1.0.dist-info/top_level.txt,sha256=wiy7gn1MrLkAjEO40L4aIMyT7BiThQhXcNhMeVMGvrI,8
40
+ dimspin-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jia-Xin Chen
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 @@
1
+ dimspin