Skip to content

Commit

Permalink
Version 3.3.3
Browse files Browse the repository at this point in the history
functions_scattering.py
 - Added function scattering_factors
 - changed 'neutron magnetic' to point to 'neutron polarised', same for 'x-ray magnetic'
  • Loading branch information
DanPorter committed Feb 5, 2025
1 parent c2c866e commit 55e7b55
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: pipx run build

- name: Upload sdist and wheel as artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
Expand All @@ -35,7 +35,7 @@ jobs:

steps:
# download sdist and wheel from dist job
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4

# publish to PyPI using trusted publishing
- name: Publish to PyPI
Expand Down
30 changes: 11 additions & 19 deletions Dans_Diffraction/classes_scattering.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,22 +480,14 @@ def structure_factor(self, hkl=None, scattering_type=None, int_hkl=True, **kwarg
print(' Starting %2.0f/%2.0f: %d:%d' % (n + 1, n_arrays, ls, ls + len(_q)))
qmag = fg.mag(_q) # q magnitude
# Scattering factors
if scattering_type in fs.SCATTERING_TYPES['neutron']:
if self._use_sears_scattering_lengths:
ff = fc.neutron_scattering_length(atom_type, 'Sears')
else:
# ff = fc.atom_properties(atom_type, 'Coh_b')
ff = fc.neutron_scattering_length(atom_type)
elif scattering_type in fs.SCATTERING_TYPES['electron']:
ff = fc.electron_scattering_factor(atom_type, qmag)
elif scattering_type in fs.SCATTERING_TYPES['xray fast']:
ff = fc.atom_properties(atom_type, 'Z')
elif scattering_type in fs.SCATTERING_TYPES['xray dispersion']:
ff = fc.xray_scattering_factor_resonant(atom_type, qmag, enval)
elif self._use_waaskirf_scattering_factor:
ff = fc.xray_scattering_factor_WaasKirf(atom_type, qmag)
else:
ff = fc.xray_scattering_factor(atom_type, qmag)
ff = fs.scattering_factors(
scattering_type=scattering_type,
atom_type=atom_type,
qmag=qmag,
enval=enval,
use_sears=self._use_sears_scattering_lengths,
use_wasskirf=self._use_waaskirf_scattering_factor
)

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

def print_atomic_contributions(self,HKL):
def print_atomic_contributions(self, HKL):
"""
Prints the atomic contributions to the structure factor
"""
Expand Down Expand Up @@ -2308,7 +2300,7 @@ def print_atomic_contributions(self,HKL):
outstr+= '(%2.0f,%2.0f,%2.0f) %9.2f %s\n' % (HKL[n,0],HKL[n,1],HKL[n,2],I[n],ss)
return outstr

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

def find_close_reflections(self,HKL,energy_kev=None,max_twotheta=2,max_angle=10):
def find_close_reflections(self, HKL, energy_kev=None, max_twotheta=2, max_angle=10):
"""
Find and print list of reflections close to the given one
"""
Expand Down
39 changes: 34 additions & 5 deletions Dans_Diffraction/functions_scattering.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def sf_magnetic_neutron(q, r, moment, magnetic_formfactor=None, occ=None, debye
# sf[n] = np.dot(sfm, incident_polarisation_vector)
# sf[n] = np.dot(sfm, sfm) # maximum possible
# average polarisation
sf[n] = (np.dot(sfm, [1, 0, 0]) + np.dot(sfm, [0, 1, 0]) + np.dot(sfm, [0, 0, 1])) / 3
# sf[n] = (np.dot(sfm, [1, 0, 0]) + np.dot(sfm, [0, 1, 0]) + np.dot(sfm, [0, 0, 1])) / 3
return sf


Expand Down Expand Up @@ -818,16 +818,16 @@ def get_scattering_function(scattering_type):
if scattering_type in SCATTERING_TYPES['electron']:
return sf_atom
if scattering_type in SCATTERING_TYPES['xray magnetic']:
return sf_magnetic_xray
return sf_magnetic_xray_polarised
if scattering_type in SCATTERING_TYPES['neutron magnetic']:
return sf_magnetic_neutron
return sf_magnetic_neutron_polarised
if scattering_type in SCATTERING_TYPES['neutron polarised']:
return sf_magnetic_neutron_polarised
if scattering_type in SCATTERING_TYPES['xray polarised']:
return sf_magnetic_xray_polarised
if scattering_type in SCATTERING_TYPES['xray resonant']:
return sf_magnetic_xray_resonant
raise(Exception('Scattering name %s not recognised' % scattering_type))
raise Exception('Scattering name %s not recognised' % scattering_type)


def options(occ=None, debyewaller=None, scattering_factor=None,
Expand All @@ -853,10 +853,39 @@ def options(occ=None, debyewaller=None, scattering_factor=None,
return locals()


def scattering_factors(scattering_type, atom_type, qmag, enval,
use_sears=False, use_wasskirf=False):
"""
Return an array of scattering factors based on the radiation
:param scattering_type: str radiation, see "get_scattering_function()"
:param atom_type: [nx1] str array of element symbols
:param qmag: [mx1] or None, float array of wavevector magnitudes for reflections
:param enval: [ox1] or None, float array of energies in keV
:param use_sears: if True, use neutron scattering lengths from ITC Vol. C, By V. F. Sears
:param use_wasskirf: if True, use x-ray scattering factors from Waasmaier and Kirfel
:return: [nxmxo] array of scattering factors
"""
if scattering_type in SCATTERING_TYPES['neutron']:
if use_sears:
return fc.neutron_scattering_length(atom_type, 'Sears')
else:
return fc.neutron_scattering_length(atom_type)
elif scattering_type in SCATTERING_TYPES['electron']:
return fc.electron_scattering_factor(atom_type, qmag)
elif scattering_type in SCATTERING_TYPES['xray fast']:
return fc.atom_properties(atom_type, 'Z')
elif scattering_type in SCATTERING_TYPES['xray dispersion']:
return fc.xray_scattering_factor_resonant(atom_type, qmag, enval)
elif use_wasskirf:
return fc.xray_scattering_factor_WaasKirf(atom_type, qmag)
else:
return fc.xray_scattering_factor(atom_type, qmag)


def autostructurefactor(scattering_type, q, r, *args, **kwargs):
"""
Choose a scattering type can calcuate the structure factor
:param scattering_type:
:param scattering_type: str radiation, see "get_scattering_function()"
:param q: array [n,3] reflection positions in A^-1
:param r: array [m,3] atomic positions in A
:param args: additional arguments to pass to choosen scattering function
Expand Down
2 changes: 1 addition & 1 deletion tests/test_structure_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ def test_magnetic_mno():
scattering_type='neutron polarised',
polarisation_vector=[1, 0, 0]
)
assert xtl.Scatter.intensity([1, 1, 1]) > 0.1, 'missing polarised neutron intensity'
assert abs(xtl.Scatter.intensity([1, 1, 1]) - 4332.39) < 0.01, 'incorrect polarised neutron intensity'

0 comments on commit 55e7b55

Please sign in to comment.