inspy-conv 0.2.7__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.
Files changed (40) hide show
  1. inspy_conv-0.2.7/LICENSE +21 -0
  2. inspy_conv-0.2.7/PKG-INFO +120 -0
  3. inspy_conv-0.2.7/README.md +89 -0
  4. inspy_conv-0.2.7/pyproject.toml +52 -0
  5. inspy_conv-0.2.7/setup.cfg +4 -0
  6. inspy_conv-0.2.7/src/inspy/__init__.py +32 -0
  7. inspy_conv-0.2.7/src/inspy/constants.py +57 -0
  8. inspy_conv-0.2.7/src/inspy/crystal/__init__.py +7 -0
  9. inspy_conv-0.2.7/src/inspy/crystal/atom.py +51 -0
  10. inspy_conv-0.2.7/src/inspy/crystal/lattice.py +244 -0
  11. inspy_conv-0.2.7/src/inspy/crystal/material.py +174 -0
  12. inspy_conv-0.2.7/src/inspy/crystal/sample.py +142 -0
  13. inspy_conv-0.2.7/src/inspy/crystal/structure_factors.py +93 -0
  14. inspy_conv-0.2.7/src/inspy/crystal/symmetry.py +207 -0
  15. inspy_conv-0.2.7/src/inspy/energy.py +135 -0
  16. inspy_conv-0.2.7/src/inspy/gui/__init__.py +14 -0
  17. inspy_conv-0.2.7/src/inspy/gui/gui_convfit_escan.py +479 -0
  18. inspy_conv-0.2.7/src/inspy/gui/gui_convfit_escan_uf.py +490 -0
  19. inspy_conv-0.2.7/src/inspy/gui/gui_convfit_qscan.py +471 -0
  20. inspy_conv-0.2.7/src/inspy/gui/gui_convfit_qscan_ff.py +448 -0
  21. inspy_conv-0.2.7/src/inspy/gui/gui_convfit_qscan_uf.py +485 -0
  22. inspy_conv-0.2.7/src/inspy/gui/main_gui.py +254 -0
  23. inspy_conv-0.2.7/src/inspy/gui/tools.py +246 -0
  24. inspy_conv-0.2.7/src/inspy/insfit/__init__.py +9 -0
  25. inspy_conv-0.2.7/src/inspy/insfit/fitconv.py +489 -0
  26. inspy_conv-0.2.7/src/inspy/insfit/uffitconv.py +345 -0
  27. inspy_conv-0.2.7/src/inspy/instrument/__init__.py +16 -0
  28. inspy_conv-0.2.7/src/inspy/instrument/ana.py +27 -0
  29. inspy_conv-0.2.7/src/inspy/instrument/components.py +114 -0
  30. inspy_conv-0.2.7/src/inspy/instrument/exceptions.py +39 -0
  31. inspy_conv-0.2.7/src/inspy/instrument/mono.py +172 -0
  32. inspy_conv-0.2.7/src/inspy/instrument/tas_spectr.py +2496 -0
  33. inspy_conv-0.2.7/src/inspy/instrument/tof_spectr.py +52 -0
  34. inspy_conv-0.2.7/src/inspy/instrument/tools.py +392 -0
  35. inspy_conv-0.2.7/src/inspy_conv.egg-info/PKG-INFO +120 -0
  36. inspy_conv-0.2.7/src/inspy_conv.egg-info/SOURCES.txt +38 -0
  37. inspy_conv-0.2.7/src/inspy_conv.egg-info/dependency_links.txt +1 -0
  38. inspy_conv-0.2.7/src/inspy_conv.egg-info/requires.txt +14 -0
  39. inspy_conv-0.2.7/src/inspy_conv.egg-info/top_level.txt +1 -0
  40. inspy_conv-0.2.7/tests/test_tas.py +25 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2026 Guochu Deng
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,120 @@
1
+ Metadata-Version: 2.4
2
+ Name: inspy-conv
3
+ Version: 0.2.7
4
+ Summary: Toolkit for inelastic neutron scattering resolution calculation and resolution convolution data fitting
5
+ Author-email: Guochu Deng <gc.deng.ansto@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/gcdengansto/inspy
8
+ Project-URL: Repository, https://github.com/gcdengansto/inspy
9
+ Keywords: neutron,scattering,resolution,spectrometer,triple-axis,time-of-flight
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Topic :: Scientific/Engineering :: Physics
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy>=1.20
18
+ Requires-Dist: matplotlib>=3.5
19
+ Requires-Dist: scipy>=1.7
20
+ Requires-Dist: pandas>=1.3
21
+ Requires-Dist: lmfit>=1.0
22
+ Requires-Dist: h5py>=3.0
23
+ Requires-Dist: plotly>=5.0
24
+ Requires-Dist: QtPy
25
+ Requires-Dist: PySide6
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest; extra == "dev"
28
+ Requires-Dist: black; extra == "dev"
29
+ Requires-Dist: flake8; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # inspy
33
+
34
+ **inspy** is a Python toolkit for scientific data analysis and simulation workflows, with a focus on inelastic neutron scattering instrument resolution calculation and related resolution convolution data fitting.
35
+
36
+ > Install name: `inspy-conv`
37
+ > Import name: `inspy`
38
+
39
+ ---
40
+
41
+ ## 🚀 Installation
42
+
43
+ ```bash
44
+ pip install inspy-conv
45
+ ```
46
+
47
+ ## 📦 Usage
48
+ ```bash
49
+ import inspy
50
+
51
+ # Example usage
52
+ # (replace with real functionality)
53
+ result = inspy.do_something()
54
+ print(result)
55
+ ```
56
+
57
+ ## 🎯 Features
58
+ Modular design for scientific workflows
59
+ Lightweight and easy to integrate into existing pipelines
60
+ Designed for extensibility in research environments
61
+ Compatible with NumPy-based data processing
62
+
63
+
64
+ ## 📁 Project Structure
65
+ ```bash
66
+ inspy-conv/
67
+ ├── src/inspy/ # Main package (import inspy)
68
+ ├── pyproject.toml # Build configuration
69
+ ├── README.md
70
+ └── LICENSE
71
+ ```
72
+
73
+ ## 🔬 Scope
74
+
75
+ This package is intended for:
76
+
77
+ > Neutron Scattering Data Analysis
78
+
79
+ > Instrument Resolution Calculation
80
+
81
+ > Resolution Convolution Fitting to Inelastic Neutron Scattering Data
82
+
83
+ > General Inelastic Neutron Scattering Geometric Calculation
84
+
85
+ ## 🛠️ Development
86
+
87
+ Repository:
88
+
89
+ https://github.com/gcdengansto/inspy.git
90
+
91
+
92
+ Install in editable mode:
93
+ ```bash
94
+ pip install -e .
95
+ ```
96
+
97
+ ## 📖 Documentation
98
+
99
+ Documentation is under development.
100
+ Usage examples and tutorials can be found at https://github.com/gcdengansto/inspy.
101
+
102
+ ## 🤝 Contributing
103
+
104
+ Please contact the author for fixing bugs and adding additional functions
105
+
106
+
107
+ ## 📜 License
108
+
109
+ This project is licensed under the MIT License — see the LICENSE file for details.
110
+
111
+ ## 👤 Author
112
+
113
+ Guochu Deng
114
+
115
+ Email: gc.deng.ansto@gmail.com
116
+
117
+ ## ⚠️ Disclaimer
118
+
119
+ This software is provided for scientific research purposes.
120
+ No guarantees are made regarding correctness or fitness for a particular application.
@@ -0,0 +1,89 @@
1
+ # inspy
2
+
3
+ **inspy** is a Python toolkit for scientific data analysis and simulation workflows, with a focus on inelastic neutron scattering instrument resolution calculation and related resolution convolution data fitting.
4
+
5
+ > Install name: `inspy-conv`
6
+ > Import name: `inspy`
7
+
8
+ ---
9
+
10
+ ## 🚀 Installation
11
+
12
+ ```bash
13
+ pip install inspy-conv
14
+ ```
15
+
16
+ ## 📦 Usage
17
+ ```bash
18
+ import inspy
19
+
20
+ # Example usage
21
+ # (replace with real functionality)
22
+ result = inspy.do_something()
23
+ print(result)
24
+ ```
25
+
26
+ ## 🎯 Features
27
+ Modular design for scientific workflows
28
+ Lightweight and easy to integrate into existing pipelines
29
+ Designed for extensibility in research environments
30
+ Compatible with NumPy-based data processing
31
+
32
+
33
+ ## 📁 Project Structure
34
+ ```bash
35
+ inspy-conv/
36
+ ├── src/inspy/ # Main package (import inspy)
37
+ ├── pyproject.toml # Build configuration
38
+ ├── README.md
39
+ └── LICENSE
40
+ ```
41
+
42
+ ## 🔬 Scope
43
+
44
+ This package is intended for:
45
+
46
+ > Neutron Scattering Data Analysis
47
+
48
+ > Instrument Resolution Calculation
49
+
50
+ > Resolution Convolution Fitting to Inelastic Neutron Scattering Data
51
+
52
+ > General Inelastic Neutron Scattering Geometric Calculation
53
+
54
+ ## 🛠️ Development
55
+
56
+ Repository:
57
+
58
+ https://github.com/gcdengansto/inspy.git
59
+
60
+
61
+ Install in editable mode:
62
+ ```bash
63
+ pip install -e .
64
+ ```
65
+
66
+ ## 📖 Documentation
67
+
68
+ Documentation is under development.
69
+ Usage examples and tutorials can be found at https://github.com/gcdengansto/inspy.
70
+
71
+ ## 🤝 Contributing
72
+
73
+ Please contact the author for fixing bugs and adding additional functions
74
+
75
+
76
+ ## 📜 License
77
+
78
+ This project is licensed under the MIT License — see the LICENSE file for details.
79
+
80
+ ## 👤 Author
81
+
82
+ Guochu Deng
83
+
84
+ Email: gc.deng.ansto@gmail.com
85
+
86
+ ## ⚠️ Disclaimer
87
+
88
+ This software is provided for scientific research purposes.
89
+ No guarantees are made regarding correctness or fitness for a particular application.
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "inspy-conv"
7
+ version = "0.2.7"
8
+ description = "Toolkit for inelastic neutron scattering resolution calculation and resolution convolution data fitting"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+
12
+ authors = [
13
+ { name = "Guochu Deng", email = "gc.deng.ansto@gmail.com" }
14
+ ]
15
+
16
+
17
+
18
+ license = "MIT"
19
+ license-files = ["LICEN[CS]E*"]
20
+
21
+
22
+ dependencies = [
23
+ "numpy>=1.20",
24
+ "matplotlib>=3.5",
25
+ "scipy>=1.7",
26
+ "pandas>=1.3",
27
+ "lmfit>=1.0",
28
+ "h5py>=3.0",
29
+ "plotly>=5.0",
30
+ "QtPy",
31
+ "PySide6"
32
+ ]
33
+
34
+ keywords = ["neutron", "scattering", "resolution", "spectrometer", "triple-axis", "time-of-flight"]
35
+
36
+ classifiers = [
37
+ "Programming Language :: Python :: 3",
38
+ "Intended Audience :: Science/Research",
39
+ "Topic :: Scientific/Engineering :: Physics",
40
+ "Operating System :: OS Independent",
41
+ ]
42
+
43
+ [project.urls]
44
+ Homepage = "https://github.com/gcdengansto/inspy"
45
+ Repository = "https://github.com/gcdengansto/inspy"
46
+
47
+ [tool.setuptools.packages.find]
48
+ where = ["src"]
49
+
50
+ [project.optional-dependencies]
51
+ dev = ["pytest", "black", "flake8"]
52
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Thu Jan 30 13:27:29 2020
4
+ @author: dgc
5
+ """
6
+
7
+
8
+ from __future__ import absolute_import
9
+ import sys
10
+ import warnings
11
+ import pkg_resources
12
+
13
+ from . import constants
14
+ from . import instrument
15
+ from .crystal import Lattice
16
+ from .crystal import Material
17
+ from .crystal import Sample
18
+ from .crystal import symmetry
19
+ #from .data import Data
20
+ from .energy import Energy
21
+ from .instrument import TripleAxisSpectr, TimeOfFlightSpectr, tools
22
+ from .insfit import FitConv
23
+ try:
24
+ from .gui.main_gui import main
25
+ except ImportError:
26
+ warnings.warn('QtPy not found, cannot run Resolution GUI')
27
+
28
+ __version__ = pkg_resources.require("inspy")[0].version
29
+
30
+ if sys.version_info[:2] == (2, 6) or sys.version_info[:2] == (3, 3):
31
+ warnings.warn('Support for Python 2.6 and Python 3.3 is depreciated and will be dropped in inspy 0.1.0',
32
+ DeprecationWarning)
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is adapted from neutronpy
3
+
4
+ """
5
+ Useful constants for neutron scattering calculations, including:
6
+
7
+ * ``magnetic_form_factors()`` : Magnetic Ion j-values
8
+ * ``periodic_table()`` : Periodic table values
9
+ * ``scattering_lengths()`` : Neutron scattering lengths
10
+ * ``symmetry()`` : Space group information
11
+ * ``JOULES_TO_MEV`` : Joules-to-meV conversion factor
12
+ * ``BOLTZMANN_IN_MEV_K`` : Boltzmann constant in meV/K
13
+ * ``N_A`` : Avogadro constant
14
+ * ``neutron_mass`` : Mass of a neutron in grams
15
+ * ``e`` : Electric charge of an electron in Coulombs
16
+ """
17
+
18
+
19
+ import json
20
+ import os
21
+
22
+ def magnetic_ion_j():
23
+ #Loads j values for Magnetic ions.
24
+ #Returns: ion_j values : dict
25
+ with open(os.path.join(os.path.dirname(__file__),
26
+ "database/magnetic_form_factors.json"), 'r') as infile:
27
+ return json.load(infile)
28
+
29
+ def periodic_table():
30
+ #Loads periodic table database. mass, and long-form name.
31
+ #Returns atom information dict, including mass, atomic number, density, mass, and name
32
+ with open(os.path.join(os.path.dirname(__file__),
33
+ "database/periodic_table.json"), 'r') as infile:
34
+ return json.load(infile)
35
+
36
+ def scattering_lengths():
37
+ #Loads neutron scattering lengths.
38
+ #Returns: scattering_lengths : dict
39
+
40
+ with open(os.path.join(os.path.dirname(__file__),
41
+ "database/scattering_lengths.json"), 'r') as infile:
42
+ return json.load(infile)
43
+
44
+ def symmetry():
45
+ #Loads crystal lattice space groups.
46
+ #Returns lattice_space_groups : dict Database of 230 crystal lattice space groups and their generators
47
+ with open(os.path.join(os.path.dirname(__file__),
48
+ "database/symmetry.json"), 'r') as infile:
49
+ return json.load(infile)
50
+
51
+
52
+ JOULES_TO_MEV = 1. / 1.6021766208e-19 * 1.e3 # Joules to meV
53
+ BOLTZMANN_IN_MEV_K = 8.6173303e-05 * 1.e3 # Boltzmann constant in meV/K
54
+ N_A = 6.022140857e+23
55
+ neutron_mass = 1.674927211e-24 # mass of a neutron in grams
56
+ hbar = 1.054571628e-34 # hbar in m2 kg / s
57
+ e = 1.602176487e-19 # coulombs
@@ -0,0 +1,7 @@
1
+ from .atom import Atom, MagneticAtom
2
+ from .lattice import Lattice
3
+ from .material import Material
4
+ from .sample import Sample
5
+ from .symmetry import SpaceGroup
6
+ from .structure_factors import MagneticFormFactor, MagneticStructureFactor, NuclearStructureFactor
7
+ from . import symmetry
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is adapted from neutronpy
3
+
4
+
5
+ import numpy as np
6
+ from ..constants import periodic_table, scattering_lengths
7
+
8
+
9
+ class Atom(object):
10
+ #Class for adding atoms to the Material class.
11
+
12
+ def __init__(self, ion, pos, occupancy=1., Mcell=None, massNorm=False, Uiso=0, Uaniso=np.zeros((3, 3))):
13
+ self.ion = ion
14
+ self.pos = np.array(pos)
15
+ self.occupancy = occupancy
16
+ self.Mcell = Mcell
17
+ self.Uiso = Uiso
18
+ self.Uaniso = np.matrix(Uaniso)
19
+
20
+ if isinstance(scattering_lengths()[ion]['Coh b'], list):
21
+ b = complex(*scattering_lengths()[ion]['Coh b'])
22
+ else:
23
+ b = scattering_lengths()[ion]['Coh b']
24
+
25
+ if massNorm is True:
26
+ self.mass = periodic_table()[ion]['mass']
27
+
28
+ self.b = (b * self.occupancy * self.Mcell / np.sqrt(self.mass))
29
+ else:
30
+ self.b = b / 10.
31
+
32
+ self.coh_xs = scattering_lengths()[ion]['Coh xs']
33
+ self.inc_xs = scattering_lengths()[ion]['Inc xs']
34
+ self.abs_xs = scattering_lengths()[ion]['Abs xs']
35
+
36
+ def __repr__(self):
37
+ return "Atom('{0}')".format(self.ion)
38
+
39
+
40
+ class MagneticAtom(object):
41
+ #Class for adding magnetic atoms to the Material class.
42
+
43
+
44
+ def __init__(self, ion, pos, moment, occupancy):
45
+ self.ion = ion
46
+ self.pos = np.array(pos)
47
+ self.moment = moment
48
+ self.occupancy = occupancy
49
+
50
+ def __repr__(self):
51
+ return "MagneticAtom('{0}')".format(self.ion, self.pos, self.moment, self.occupancy)
@@ -0,0 +1,244 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is adapted from neutronpy
3
+
4
+ # Handles lattice geometries to find rotations and transformations
5
+
6
+ import numpy as np
7
+
8
+ class Lattice(object):
9
+ #Class to describe a generic lattice system defined by lattice six parameters.
10
+
11
+
12
+ def __init__(self, a, b, c, alpha, beta, gamma):
13
+ self.abc = [a, b, c]
14
+ self.abg = [alpha, beta, gamma]
15
+
16
+ def __repr__(self):
17
+ return "Lattice({0}, {1}, {2}, {3}, {4}, {5})".format(self.a, self.b, self.c, self.alpha, self.beta, self.gamma)
18
+
19
+ @property
20
+ def a(self):
21
+
22
+ return self.abc[0]
23
+
24
+ @a.setter
25
+ def a(self, a):
26
+ self.abc[0] = a
27
+
28
+ @property
29
+ def b(self):
30
+
31
+ return self.abc[1]
32
+
33
+ @b.setter
34
+ def b(self, b):
35
+ self.abc[1] = b
36
+
37
+ @property
38
+ def c(self):
39
+
40
+ return self.abc[2]
41
+
42
+ @c.setter
43
+ def c(self, c):
44
+ self.abc[2] = c
45
+
46
+ @property
47
+ def alpha(self):
48
+
49
+ return self.abg[0]
50
+
51
+ @alpha.setter
52
+ def alpha(self, alpha):
53
+ self.abg[0] = alpha
54
+
55
+ @property
56
+ def beta(self):
57
+
58
+ return self.abg[1]
59
+
60
+ @beta.setter
61
+ def beta(self, beta):
62
+ self.abg[1] = beta
63
+
64
+ @property
65
+ def gamma(self):
66
+
67
+ return self.abg[2]
68
+
69
+ @gamma.setter
70
+ def gamma(self, gamma):
71
+ self.abg[2] = gamma
72
+
73
+ @property
74
+ def alpha_rad(self):
75
+
76
+ return self.abg_rad[0]
77
+
78
+ @property
79
+ def beta_rad(self):
80
+
81
+ return self.abg_rad[1]
82
+
83
+ @property
84
+ def gamma_rad(self):
85
+
86
+ return self.abg_rad[2]
87
+
88
+ @property
89
+ def astar(self):
90
+
91
+ return self.b * self.c * np.sin(self.alpha_rad) / self.volume * 2 * np.pi
92
+
93
+ @property
94
+ def bstar(self):
95
+
96
+ return self.a * self.c * np.sin(self.beta_rad) / self.volume * 2 * np.pi
97
+
98
+ @property
99
+ def cstar(self):
100
+
101
+ return self.a * self.b * np.sin(self.gamma_rad) / self.volume * 2 * np.pi
102
+
103
+ @property
104
+ def alphastar_rad(self):
105
+
106
+ return np.arccos((np.cos(self.beta_rad) * np.cos(self.gamma_rad) -
107
+ np.cos(self.alpha_rad)) /
108
+ (np.sin(self.beta_rad) * np.sin(self.gamma_rad)))
109
+
110
+ @property
111
+ def betastar_rad(self):
112
+
113
+ return np.arccos((np.cos(self.alpha_rad) *
114
+ np.cos(self.gamma_rad) -
115
+ np.cos(self.beta_rad)) /
116
+ (np.sin(self.alpha_rad) * np.sin(self.gamma_rad)))
117
+
118
+ @property
119
+ def gammastar_rad(self):
120
+
121
+ return np.arccos((np.cos(self.alpha_rad) * np.cos(self.beta_rad) -
122
+ np.cos(self.gamma_rad)) /
123
+ (np.sin(self.alpha_rad) * np.sin(self.beta_rad)))
124
+
125
+ @property
126
+ def alphastar(self):
127
+
128
+ return np.rad2deg(self.alphastar_rad)
129
+
130
+ @property
131
+ def betastar(self):
132
+
133
+ return np.rad2deg(self.betastar_rad)
134
+
135
+ @property
136
+ def gammastar(self):
137
+
138
+ return np.rad2deg(self.gammastar_rad)
139
+
140
+ @property
141
+ def reciprocal_abc(self):
142
+
143
+ return [self.astar, self.bstar, self.cstar]
144
+
145
+ @property
146
+ def reciprocal_abg(self):
147
+
148
+ return [self.alphastar, self.betastar, self.gammastar]
149
+
150
+ @property
151
+ def reciprocal_abg_rad(self):
152
+
153
+ return [self.alphastar_rad, self.betastar_rad, self.gammastar_rad]
154
+
155
+ @property
156
+ def abg_rad(self):
157
+
158
+ return np.deg2rad(self.abg)
159
+
160
+ @property
161
+ def lattice_type(self):
162
+
163
+ if len(np.unique(self.abc)) == 3 and len(np.unique(self.abg)) == 3:
164
+ return 'triclinic'
165
+ elif len(np.unique(self.abc)) == 3 and self.abg[1] != 90 and np.all(np.array(self.abg)[:3:2] == 90):
166
+ return 'monoclinic'
167
+ elif len(np.unique(self.abc)) == 3 and np.all(np.array(self.abg) == 90):
168
+ return 'orthorhombic'
169
+ elif len(np.unique(self.abc)) == 1 and len(np.unique(self.abg)) == 1 and np.all(
170
+ np.array(self.abg) < 120) and np.all(np.array(self.abg) != 90):
171
+ return 'rhombohedral'
172
+ elif len(np.unique(self.abc)) == 2 and self.abc[0] == self.abc[1] and np.all(np.array(self.abg) == 90):
173
+ return 'tetragonal'
174
+ elif len(np.unique(self.abc)) == 2 and self.abc[0] == self.abc[1] and np.all(np.array(self.abg)[0:2] == 90) and \
175
+ self.abg[2] == 120:
176
+ return 'hexagonal'
177
+ elif len(np.unique(self.abc)) == 1 and np.all(np.array(self.abg) == 90):
178
+ return 'cubic'
179
+ else:
180
+ raise ValueError('Provided lattice constants and angles do not resolve to a valid Bravais lattice')
181
+
182
+ @property
183
+ def volume(self):
184
+
185
+ return np.sqrt(np.linalg.det(self.G))
186
+
187
+ @property
188
+ def reciprocal_volume(self):
189
+
190
+ return np.sqrt(np.linalg.det(self.Gstar))
191
+
192
+ @property
193
+ def G(self):
194
+ #Metric tensor of the real space lattice
195
+
196
+
197
+ a, b, c = self.abc
198
+ alpha, beta, gamma = self.abg_rad
199
+
200
+ return np.matrix([[a ** 2, a * b * np.cos(gamma), a * c * np.cos(beta)],
201
+ [a * b * np.cos(gamma), b ** 2, b * c * np.cos(alpha)],
202
+ [a * c * np.cos(beta), b * c * np.cos(alpha), c ** 2]], dtype=float)
203
+
204
+ @property
205
+ def Gstar(self):
206
+ #Metric tensor of the reciprocal lattice
207
+
208
+ return np.linalg.inv(self.G) * 4 * np.pi ** 2
209
+
210
+ @property
211
+ def Bmatrix(self):
212
+ #Cartesian basis matrix in reciprocal units such that Bmatrix*Bmatrix.T = Gstar
213
+
214
+
215
+ return np.matrix([[self.astar, self.bstar * np.cos(self.gammastar_rad), self.cstar * np.cos(self.betastar_rad)],
216
+ [0, self.bstar * np.sin(self.gammastar_rad), -self.cstar * np.sin(self.betastar_rad) * np.cos(self.alpha_rad)],
217
+ [0, 0, self.cstar * np.sin(self.betastar_rad) * np.sin(self.alphastar_rad)]], dtype=float)
218
+
219
+ def get_d_spacing(self, hkl):
220
+ #Returns the d-spacing of a given reciprocal lattice vector.
221
+
222
+ hkl = np.array(hkl)
223
+
224
+ return float(1 / np.sqrt(np.dot(np.dot(hkl, self.Gstar / 4 / np.pi ** 2), hkl)))
225
+
226
+ def get_angle_between_planes(self, v1, v2):
227
+ #Returns the angle :math:`\phi` between two reciprocal lattice vectors
228
+
229
+ v1, v2 = np.array(v1), np.array(v2)
230
+
231
+ return float(np.rad2deg(np.arccos(np.inner(np.inner(v1, self.Gstar), v2) /
232
+ np.sqrt(np.inner(np.inner(v1, self.Gstar), v1)) /
233
+ np.sqrt(np.inner(np.inner(v2, self.Gstar), v2)))))
234
+
235
+ def get_two_theta(self, hkl, wavelength):
236
+ #Returns the detector angle for a given reciprocal lattice vector and incident wavelength.
237
+
238
+ return 2 * np.rad2deg(np.arcsin(wavelength / 2 /
239
+ self.get_d_spacing(hkl)))
240
+
241
+ def get_q(self, hkl):
242
+ #Returns the magnitude of *Q* for a given reciprocal lattice
243
+
244
+ return 2 * np.pi / self.get_d_spacing(hkl)