Skip to content

Commit 843cab1

Browse files
committed
Fixes for #33
functions_scattering.py - added scattering_type function classes_scattering.py - added energy_mev to setup_scatter for neutron energy - setup_scatter option wavelength_a changed to check scatteing_type, now updates energy correctly for neutron and electron wavelengths. - new version of magnetic_form_factor function that includes elements with oxidations states TODO: - add test cases for magnetic form factors
1 parent 7c86d79 commit 843cab1

5 files changed

Lines changed: 39 additions & 9 deletions

File tree

Dans_Diffraction/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
Diamond
3232
2017-2025
3333
34-
Version 3.3.4
35-
Last updated: 12/04/2025
34+
Version 3.4.0
35+
Last updated: 05/08/2025
3636
3737
Version History:
3838
02/03/18 1.0 Version History started.
@@ -85,6 +85,7 @@
8585
20/11/24 3.3.2 Added alternate option for neutron scattering lengths
8686
06/02/25 3.3.3 Added scattering options for polarised neutron and x-ray scattering. Thanks dragonyanglong!
8787
12/04/25 3.3.4 Improved superstructure calculations by fixing scale parameter
88+
05/08/25 3.4.0 Added custom atomic form factors and dispersion corrections
8889
8990
Acknoledgements:
9091
2018 Thanks to Hepesu for help with Python3 support and ideas about breaking up calculations
@@ -112,6 +113,7 @@
112113
Sep 2024 Thanks to thamnos for suggestion to add complex neutron scattering lengths
113114
Oct 2024 Thanks to Lee Richter for pointing out the error in triclinic basis definition
114115
Dec 2024 Thanks to dragonyanglong for pointing out the error with magnetic neutron scattering
116+
May 2025 Thanks to vbhartiya for suggestions about magnetic neutron scattering
115117
116118
-----------------------------------------------------------------------------
117119
Copyright 2018-2025 Diamond Light Source Ltd.
@@ -166,8 +168,8 @@
166168
'Structures', 'Fdmnes', 'FdmnesAnalysis']
167169

168170

169-
__version__ = '3.3.3'
170-
__date__ = '2025/02/06'
171+
__version__ = '3.4.0'
172+
__date__ = '2025/08/05'
171173

172174

173175
# Build

Dans_Diffraction/classes_scattering.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def __str__(self):
182182
#out += ' use m1m1 approx.: %s\n' % self._resonant_approximation_m1m1
183183
return out
184184

185-
def setup_scatter(self, scattering_type=None, energy_kev=None, wavelength_a=None,
185+
def setup_scatter(self, scattering_type=None, energy_kev=None, energy_mev=None, wavelength_a=None,
186186
powder_units=None, powder_pixels=None, powder_lorentz=None, powder_overlap=None,
187187
int_hkl=None, specular=None, parallel=None, theta_offset=None,
188188
min_theta=None, max_theta=None, min_twotheta=None, max_twotheta=None,
@@ -217,13 +217,21 @@ def setup_scatter(self, scattering_type=None, energy_kev=None, wavelength_a=None
217217
"""
218218

219219
if scattering_type is not None:
220-
self._scattering_type = scattering_type
220+
self._scattering_type = fs.get_scattering_type(scattering_type)
221221

222222
if energy_kev is not None:
223223
self._energy_kev = energy_kev
224224

225+
if energy_mev is not None:
226+
self._energy_kev = energy_mev * 1e-6
227+
225228
if wavelength_a is not None:
226-
self._energy_kev = fc.wave2energy(wavelength_a)
229+
if 'neutron' in self._scattering_type:
230+
self._energy_kev = fc.neutron_energy(wavelength_a) * 1e-6 # meV
231+
elif 'electron' in self._scattering_type:
232+
self._energy_kev = fc.electron_energy(wavelength_a) * 1e-3 # eV
233+
else:
234+
self._energy_kev = fc.wave2energy(wavelength_a)
227235

228236
if powder_units is not None:
229237
self._powder_units = powder_units

Dans_Diffraction/functions_scattering.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@
3939
Diamond
4040
2018
4141
42-
Version 1.0
43-
Last updated: 06/02/25
42+
Version 1.1
43+
Last updated: 05/08/25
4444
4545
Version History:
4646
11/11/18 0.1 Version History started.
4747
13/07/21 0.9 Functions re-written and tested
4848
06/02/25 1.0 Removed refrences to unpolarised magnetic scattering due to incorrect averaging
49+
05/08/25 1.1 Added custom scattering option
4950
5051
@author: DGPorter
5152
"""
@@ -838,6 +839,15 @@ def scatteringvectors(q, energy_kev, azi_ref_q=(1, 0, 0), psi=0, polarisation='s
838839
########################################################################################################################
839840

840841

842+
def get_scattering_type(scattering_type):
843+
"""Return correct label for scattering type"""
844+
scattering_type = scattering_type.lower()
845+
for name, alt_names in SCATTERING_TYPES.items():
846+
if scattering_type in alt_names:
847+
return name
848+
raise Exception(f"Scattering type {scattering_type} not recognized")
849+
850+
841851
def get_scattering_function(scattering_type):
842852
"""
843853
Return function for given scattering type

tests/test_data_tables.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def test_old_new_functions():
5959
assert diff < 10, f"resonant scattering factors are incorrect"
6060

6161

62+
def test_magnetic_form_factor():
63+
# TODO: add tests
64+
assert True
65+
66+
6267
def test_custom_scattering_factor():
6368
coefs = (12.2841, 4.5791, 7.4409, 0.6784, 4.2034, 12.5359, 2.2488, 72.1692, 1.1118, 0.)
6469
table = np.array([

tests/test_structure_factors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,8 @@ def test_magnetic_mno():
9595
polarisation_vector=[1, 0, 0]
9696
)
9797
assert abs(xtl.Scatter.intensity([1, 1, 1]) - 4332.39) < 0.01, 'incorrect polarised neutron intensity'
98+
99+
100+
def test_magnetic_neutron():
101+
# TODO: test against SF from https://taro-nakajima.github.io/fcal-n/
102+
assert True

0 commit comments

Comments
 (0)