Skip to content

Commit 55e7b55

Browse files
committed
Version 3.3.3
functions_scattering.py - Added function scattering_factors - changed 'neutron magnetic' to point to 'neutron polarised', same for 'x-ray magnetic'
1 parent c2c866e commit 55e7b55

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

.github/workflows/pypi-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
run: pipx run build
1717

1818
- name: Upload sdist and wheel as artifacts
19-
uses: actions/upload-artifact@v3
19+
uses: actions/upload-artifact@v4
2020
with:
2121
name: dist
2222
path: dist
@@ -35,7 +35,7 @@ jobs:
3535

3636
steps:
3737
# download sdist and wheel from dist job
38-
- uses: actions/download-artifact@v3
38+
- uses: actions/download-artifact@v4
3939

4040
# publish to PyPI using trusted publishing
4141
- name: Publish to PyPI

Dans_Diffraction/classes_scattering.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,14 @@ def structure_factor(self, hkl=None, scattering_type=None, int_hkl=True, **kwarg
480480
print(' Starting %2.0f/%2.0f: %d:%d' % (n + 1, n_arrays, ls, ls + len(_q)))
481481
qmag = fg.mag(_q) # q magnitude
482482
# Scattering factors
483-
if scattering_type in fs.SCATTERING_TYPES['neutron']:
484-
if self._use_sears_scattering_lengths:
485-
ff = fc.neutron_scattering_length(atom_type, 'Sears')
486-
else:
487-
# ff = fc.atom_properties(atom_type, 'Coh_b')
488-
ff = fc.neutron_scattering_length(atom_type)
489-
elif scattering_type in fs.SCATTERING_TYPES['electron']:
490-
ff = fc.electron_scattering_factor(atom_type, qmag)
491-
elif scattering_type in fs.SCATTERING_TYPES['xray fast']:
492-
ff = fc.atom_properties(atom_type, 'Z')
493-
elif scattering_type in fs.SCATTERING_TYPES['xray dispersion']:
494-
ff = fc.xray_scattering_factor_resonant(atom_type, qmag, enval)
495-
elif self._use_waaskirf_scattering_factor:
496-
ff = fc.xray_scattering_factor_WaasKirf(atom_type, qmag)
497-
else:
498-
ff = fc.xray_scattering_factor(atom_type, qmag)
483+
ff = fs.scattering_factors(
484+
scattering_type=scattering_type,
485+
atom_type=atom_type,
486+
qmag=qmag,
487+
enval=enval,
488+
use_sears=self._use_sears_scattering_lengths,
489+
use_wasskirf=self._use_waaskirf_scattering_factor
490+
)
499491

500492
# Get Debye-Waller factor
501493
if self._use_isotropic_thermal_factor:
@@ -2260,7 +2252,7 @@ def print_symmetric_reflections(self, HKL):
22602252
outstr+= '(%5.3g,%5.3g,%5.3g)\n' % (symHKL[n,0],symHKL[n,1],symHKL[n,2])
22612253
return outstr
22622254

2263-
def print_atomic_contributions(self,HKL):
2255+
def print_atomic_contributions(self, HKL):
22642256
"""
22652257
Prints the atomic contributions to the structure factor
22662258
"""
@@ -2308,7 +2300,7 @@ def print_atomic_contributions(self,HKL):
23082300
outstr+= '(%2.0f,%2.0f,%2.0f) %9.2f %s\n' % (HKL[n,0],HKL[n,1],HKL[n,2],I[n],ss)
23092301
return outstr
23102302

2311-
def print_symmetry_contributions(self,HKL):
2303+
def print_symmetry_contributions(self, HKL):
23122304
"""
23132305
Prints the symmetry contributions to the structure factor for each atomic site
23142306
"""
@@ -2404,7 +2396,7 @@ def orientation_reflections(self, energy_kev, hkl_1=None):
24042396
hkl_2_options = (abs(angles - angles[idx]) < 1.) * (abs(tth_2 - tth_2[idx]) < 1.)
24052397
return hkl_1, hkl_2, next_refs[hkl_2_options]
24062398

2407-
def find_close_reflections(self,HKL,energy_kev=None,max_twotheta=2,max_angle=10):
2399+
def find_close_reflections(self, HKL, energy_kev=None, max_twotheta=2, max_angle=10):
24082400
"""
24092401
Find and print list of reflections close to the given one
24102402
"""

Dans_Diffraction/functions_scattering.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def sf_magnetic_neutron(q, r, moment, magnetic_formfactor=None, occ=None, debye
241241
# sf[n] = np.dot(sfm, incident_polarisation_vector)
242242
# sf[n] = np.dot(sfm, sfm) # maximum possible
243243
# average polarisation
244-
sf[n] = (np.dot(sfm, [1, 0, 0]) + np.dot(sfm, [0, 1, 0]) + np.dot(sfm, [0, 0, 1])) / 3
244+
# sf[n] = (np.dot(sfm, [1, 0, 0]) + np.dot(sfm, [0, 1, 0]) + np.dot(sfm, [0, 0, 1])) / 3
245245
return sf
246246

247247

@@ -818,16 +818,16 @@ def get_scattering_function(scattering_type):
818818
if scattering_type in SCATTERING_TYPES['electron']:
819819
return sf_atom
820820
if scattering_type in SCATTERING_TYPES['xray magnetic']:
821-
return sf_magnetic_xray
821+
return sf_magnetic_xray_polarised
822822
if scattering_type in SCATTERING_TYPES['neutron magnetic']:
823-
return sf_magnetic_neutron
823+
return sf_magnetic_neutron_polarised
824824
if scattering_type in SCATTERING_TYPES['neutron polarised']:
825825
return sf_magnetic_neutron_polarised
826826
if scattering_type in SCATTERING_TYPES['xray polarised']:
827827
return sf_magnetic_xray_polarised
828828
if scattering_type in SCATTERING_TYPES['xray resonant']:
829829
return sf_magnetic_xray_resonant
830-
raise(Exception('Scattering name %s not recognised' % scattering_type))
830+
raise Exception('Scattering name %s not recognised' % scattering_type)
831831

832832

833833
def options(occ=None, debyewaller=None, scattering_factor=None,
@@ -853,10 +853,39 @@ def options(occ=None, debyewaller=None, scattering_factor=None,
853853
return locals()
854854

855855

856+
def scattering_factors(scattering_type, atom_type, qmag, enval,
857+
use_sears=False, use_wasskirf=False):
858+
"""
859+
Return an array of scattering factors based on the radiation
860+
:param scattering_type: str radiation, see "get_scattering_function()"
861+
:param atom_type: [nx1] str array of element symbols
862+
:param qmag: [mx1] or None, float array of wavevector magnitudes for reflections
863+
:param enval: [ox1] or None, float array of energies in keV
864+
:param use_sears: if True, use neutron scattering lengths from ITC Vol. C, By V. F. Sears
865+
:param use_wasskirf: if True, use x-ray scattering factors from Waasmaier and Kirfel
866+
:return: [nxmxo] array of scattering factors
867+
"""
868+
if scattering_type in SCATTERING_TYPES['neutron']:
869+
if use_sears:
870+
return fc.neutron_scattering_length(atom_type, 'Sears')
871+
else:
872+
return fc.neutron_scattering_length(atom_type)
873+
elif scattering_type in SCATTERING_TYPES['electron']:
874+
return fc.electron_scattering_factor(atom_type, qmag)
875+
elif scattering_type in SCATTERING_TYPES['xray fast']:
876+
return fc.atom_properties(atom_type, 'Z')
877+
elif scattering_type in SCATTERING_TYPES['xray dispersion']:
878+
return fc.xray_scattering_factor_resonant(atom_type, qmag, enval)
879+
elif use_wasskirf:
880+
return fc.xray_scattering_factor_WaasKirf(atom_type, qmag)
881+
else:
882+
return fc.xray_scattering_factor(atom_type, qmag)
883+
884+
856885
def autostructurefactor(scattering_type, q, r, *args, **kwargs):
857886
"""
858887
Choose a scattering type can calcuate the structure factor
859-
:param scattering_type:
888+
:param scattering_type: str radiation, see "get_scattering_function()"
860889
:param q: array [n,3] reflection positions in A^-1
861890
:param r: array [m,3] atomic positions in A
862891
:param args: additional arguments to pass to choosen scattering function

tests/test_structure_factors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ def test_magnetic_mno():
9494
scattering_type='neutron polarised',
9595
polarisation_vector=[1, 0, 0]
9696
)
97-
assert xtl.Scatter.intensity([1, 1, 1]) > 0.1, 'missing polarised neutron intensity'
97+
assert abs(xtl.Scatter.intensity([1, 1, 1]) - 4332.39) < 0.01, 'incorrect polarised neutron intensity'

0 commit comments

Comments
 (0)