Skip to content

Commit

Permalink
option integer hkl
Browse files Browse the repository at this point in the history
classes_scattering.py
 - added option for _integer_hkl, used in all scattering code.

classes_crystal.py
 - Symmetry now loads space group operations from tables if not in CIF

functions_general.py
 - change to norm, use np.squeeze on output

Tests
 - added tests for CIF output
 - all tests pass
  • Loading branch information
DanPorter committed Feb 6, 2025
1 parent 55e7b55 commit ff2bc7a
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 164 deletions.
71 changes: 40 additions & 31 deletions Dans_Diffraction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ xtl.Cell.gamma

Selected functions (see internal documentation for more):
```python
xtl.Cell.latt([2.85,2.85,10.8,90,90,120]) # Define the lattice parameters from a list
xtl.Cell.latt([2.85,2.85,10.8,90,90,120]) # Define the lattice parameters from a list or subset
xtl.Cell.tth([0,0,12],energy_kev=8.0) # Calculate the two-theta of a reflection
xtl.Cell.lp() # Returns the current lattice parameters
xtl.Cell.volume() # Returns the calculated volume in A^3
Expand Down Expand Up @@ -111,16 +111,16 @@ xtl.Structrue contains all atomic positions in the unit cell.

Each atom has properties:

| Property | |
| ------------- | ------------- |
| u | Fractional atomic coordinates along direction of **a** |
| v | Fractional atomic coordinates along direction of **b** |
| w | Fractional atomic coordinates along direction of **c** |
| type | element species, given as element name, e.g. 'Fe' |
| label | Name of atomic position, e.g. 'Fe1' |
| occupancy | Occupancy of this atom at this atomic position |
| uiso | atomic displacement factor (ADP) <u^2> |
| mxmymz | magnetic moment direction [x,y,z] |
| Property | |
|-----------|----------------------------------------------------------|
| u | Fractional atomic coordinates along direction of **a** |
| v | Fractional atomic coordinates along direction of **b** |
| w | Fractional atomic coordinates along direction of **c** |
| type | element species, given as element name, e.g. 'Fe' |
| label | Name of atomic position, e.g. 'Fe1' |
| occupancy | Occupancy of this atom at this atomic position |
| uiso | atomic displacement factor (ADP) <u^2> |
| mxmymz | magnetic moment direction [x,y,z] |

Functions available:
```python
Expand Down Expand Up @@ -176,13 +176,14 @@ xtl.Plot.tensor_scattering_stokes # Return tensor scattering intensities for non
### Scattering
Simulate diffraction from the crystal structure, for various scattering types, including:

| Name | Explanation |
| ---- | ----------- |
| 'xray' | X-Ray diffraction, using atomic form factors |
| 'neutron' | Neutron difraction, using neutron scattering lengths. |
| 'neutron magnetic' | Magnetic neutron diffraction |
| 'xray magnetic' | Non-resonant x-ray magnetic diffraction |
| 'xray resonant' | Resonant x-ray magnetic diffraction |
| Name | Explanation |
|--------------------|----------------------------------------------------------|
| 'xray' | X-Ray diffraction, using atomic form factors |
| 'neutron' | Neutron difraction, using neutron scattering lengths. |
| 'neutron magnetic' | Magnetic neutron diffraction |
| 'xray magnetic' | Non-resonant x-ray magnetic diffraction |
| 'xray resonant' | Resonant x-ray magnetic diffraction |
| 'xray dispersion' | X-Ray diffraction using energy dispersive form factors |

Functions calculate the complex structure factor based on the equation:

Expand All @@ -192,19 +193,27 @@ Scattering factors and scattering lengths for available elements are found in [d

Setup the scattering attributes with the *xtl.Scatter.setup_scatter(parameter)* function:

| Parameter | Explanation |
| ---------- | ----------- |
| type | 'xray','neutron','xray magnetic','neutron magnetic','xray resonant' |
| energy_kev | radiation energy in keV |
| wavelength_a | radiation wavelength in Angstrom |
| powder_units | units to use when displaying/ plotting ['twotheta', 'd',' 'q'] |
| min_twotheta | minimum detector (two-theta) angle |
| max_twotheta | maximum detector (two-theta) angle |
| min_theta | minimum sample angle = -opening angle |
| max_theta | maximum sample angle = opening angle |
| theta_offset | sample offset angle |
| specular | [h,k,l] : reflections normal to sample surface |
| parallel | [h,k,l] : reflections normal to sample surface |
| Parameter | Explanation |
|---------------------|-----------------------------------------------------------------------------------------|
| scattering_type | 'xray','neutron','xray magnetic','neutron magnetic','xray resonant', 'xray dispersion' |
| energy_kev | radiation energy in keV |
| wavelength_a | radiation wavelength in Angstrom |
| powder_units | units to use when displaying/ plotting ['twotheta', 'd',' 'q'] |
| min_twotheta | minimum detector (two-theta) angle |
| max_twotheta | maximum detector (two-theta) angle |
| min_theta | minimum sample angle = -opening angle |
| max_theta | maximum sample angle = opening angle |
| theta_offset | sample offset angle |
| specular | [h,k,l] : reflections normal to sample surface |
| parallel | [h,k,l] : reflections normal to sample surface |
| scattering_factors | xray scattering factor, either 'waaskirf' or 'itc' |
| scattering_lengths | neutron scattering lengths either 'sears' or 'default' |
| magnetic_formfactor | True/False magnetic form factor for magnetic SF |
| polarisation | beam polarisation setting ['ss', 'sp'*, 'sp', 'pp'] |
| polarisation_vector | [x,y,z] incident polarisation vector |
| azimuthal_reference | [h,k,l] direction of azimuthal zero angle |
| azimuth | azimuthal angle in deg |
| flm | Resonant settings (flm1, flm2, flm3) |


Selected functions (see internal documentation for more):
Expand Down
10 changes: 5 additions & 5 deletions Dans_Diffraction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
By Dan Porter, PhD
Diamond
2017
2017-2025
Version 3.3.2
Last updated: 20/11/2024
Version 3.3.3
Last updated: 06/02/2025
Version History:
02/03/18 1.0 Version History started.
Expand Down Expand Up @@ -83,7 +83,7 @@
26/09/24 3.3.0 Added complex neutron scattering lengths for isotopes from package periodictable. Thanks thamnos!
06/11/24 3.3.1 Fixed incorrect cell basis for triclinic cells. Added functions_lattice.py and tests. Thanks LeeRichter!
20/11/24 3.3.2 Added alternate option for neutron scattering lengths
23/12/24 3.3.3 Added scattering options for polarised neutron and x-ray scattering. Thanks dragonyanglong!
06/02/25 3.3.3 Added scattering options for polarised neutron and x-ray scattering. Thanks dragonyanglong!
Acknoledgements:
2018 Thanks to Hepesu for help with Python3 support and ideas about breaking up calculations
Expand Down Expand Up @@ -166,7 +166,7 @@


__version__ = '3.3.3'
__date__ = '2024/12/23'
__date__ = '2025/02/06'


# Build
Expand Down
22 changes: 14 additions & 8 deletions Dans_Diffraction/classes_crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
Diamond
2017
Version 3.2.4
Last updated: 22/05/23
Version 3.3.0
Last updated: 06/02/25
Version History:
27/07/17 1.0 Version History started.
Expand All @@ -49,6 +49,7 @@
15/11/21 3.2.2 Added Cell.orientation, updated Cell.UV()
12/01/21 3.2.3 Added Symmetry.axial_vector
22/05/23 3.2.4 Added Symmetry.wyckoff_label(), Symmetry.spacegroup_dict
06/05/25 3.3.0 Symmetry.from_cif now loads operations from find_spacegroup if not already loaded
@author: DGPorter
"""
Expand All @@ -67,7 +68,7 @@
from .classes_multicrystal import MultiCrystal
from .classes_plotting import Plotting, PlottingSuperstructure

__version__ = '3.2.4'
__version__ = '3.3.0'


class Crystal:
Expand Down Expand Up @@ -227,13 +228,13 @@ def write_cif(self, filename=None, comments=None):
else:
fc.write_cif(cifvals, filename, comments)

def new_cell(self, lattice_parameters=(), *args, **kwargs):
def new_cell(self, *lattice_parameters, **kwargs):
"""
Replace the lattice parameters
:param lattice_parameters: [a,b,c,alpha,beta,gamma]
:return: None
"""
self.Cell.latt(lattice_parameters, *args, **kwargs)
self.Cell.latt(*lattice_parameters, **kwargs)

def new_atoms(self, u=[0], v=[0], w=[0], type=None,
label=None, occupancy=None, uiso=None, mxmymz=None):
Expand Down Expand Up @@ -468,8 +469,9 @@ def info(self):
out += '{}\n'.format(self.name)
out += 'Formula: {}\n'.format(self.Properties.molname())
out += 'Magnetic: {}\n'.format(self.Structure.ismagnetic())
out += 'Spacegroup: %s\n' % repr(self.Symmetry)
out += self.Cell.info()
out += '\nDensity: %6.3f g/cm\n' % self.Properties.density()
out += 'Density: %6.3f g/cm\n\n' % self.Properties.density()
out += self.Structure.info()
out += '\n'
# print "To see the full list of structure positions, type Crystal.Structure.info()"
Expand Down Expand Up @@ -1157,7 +1159,7 @@ def fromcif(self, cifvals):
:return: none
"""
if not fc.cif_check(cifvals, self._required_cif):
warn('Atom site parameters cannot be read from cif')
warn('Atom site parameters cannot be read from cif') # TODO: provide more details
return

keys = cifvals.keys()
Expand Down Expand Up @@ -1718,7 +1720,11 @@ def fromcif(self, cifvals):
else:
self.spacegroup_dict = fc.spacegroup(1)

self.generate_matrices()
if len(self.symmetry_operations) == 1:
# use found spacegroup as none provided by CIF
self.load_spacegroup(sg_dict=self.spacegroup_dict)
else:
self.generate_matrices()

def update_cif(self, cifvals):
"""
Expand Down
Loading

0 comments on commit ff2bc7a

Please sign in to comment.