Skip to content

Commit ff2bc7a

Browse files
committed
option integer hkl
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
1 parent 55e7b55 commit ff2bc7a

File tree

13 files changed

+296
-164
lines changed

13 files changed

+296
-164
lines changed

Dans_Diffraction/README.md

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ xtl.Cell.gamma
4646

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

112112
Each atom has properties:
113113

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

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

179-
| Name | Explanation |
180-
| ---- | ----------- |
181-
| 'xray' | X-Ray diffraction, using atomic form factors |
182-
| 'neutron' | Neutron difraction, using neutron scattering lengths. |
183-
| 'neutron magnetic' | Magnetic neutron diffraction |
184-
| 'xray magnetic' | Non-resonant x-ray magnetic diffraction |
185-
| 'xray resonant' | Resonant x-ray magnetic diffraction |
179+
| Name | Explanation |
180+
|--------------------|----------------------------------------------------------|
181+
| 'xray' | X-Ray diffraction, using atomic form factors |
182+
| 'neutron' | Neutron difraction, using neutron scattering lengths. |
183+
| 'neutron magnetic' | Magnetic neutron diffraction |
184+
| 'xray magnetic' | Non-resonant x-ray magnetic diffraction |
185+
| 'xray resonant' | Resonant x-ray magnetic diffraction |
186+
| 'xray dispersion' | X-Ray diffraction using energy dispersive form factors |
186187

187188
Functions calculate the complex structure factor based on the equation:
188189

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

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

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

209218

210219
Selected functions (see internal documentation for more):

Dans_Diffraction/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
3030
By Dan Porter, PhD
3131
Diamond
32-
2017
32+
2017-2025
3333
34-
Version 3.3.2
35-
Last updated: 20/11/2024
34+
Version 3.3.3
35+
Last updated: 06/02/2025
3636
3737
Version History:
3838
02/03/18 1.0 Version History started.
@@ -83,7 +83,7 @@
8383
26/09/24 3.3.0 Added complex neutron scattering lengths for isotopes from package periodictable. Thanks thamnos!
8484
06/11/24 3.3.1 Fixed incorrect cell basis for triclinic cells. Added functions_lattice.py and tests. Thanks LeeRichter!
8585
20/11/24 3.3.2 Added alternate option for neutron scattering lengths
86-
23/12/24 3.3.3 Added scattering options for polarised neutron and x-ray scattering. Thanks dragonyanglong!
86+
06/02/25 3.3.3 Added scattering options for polarised neutron and x-ray scattering. Thanks dragonyanglong!
8787
8888
Acknoledgements:
8989
2018 Thanks to Hepesu for help with Python3 support and ideas about breaking up calculations
@@ -166,7 +166,7 @@
166166

167167

168168
__version__ = '3.3.3'
169-
__date__ = '2024/12/23'
169+
__date__ = '2025/02/06'
170170

171171

172172
# Build

Dans_Diffraction/classes_crystal.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
Diamond
2525
2017
2626
27-
Version 3.2.4
28-
Last updated: 22/05/23
27+
Version 3.3.0
28+
Last updated: 06/02/25
2929
3030
Version History:
3131
27/07/17 1.0 Version History started.
@@ -49,6 +49,7 @@
4949
15/11/21 3.2.2 Added Cell.orientation, updated Cell.UV()
5050
12/01/21 3.2.3 Added Symmetry.axial_vector
5151
22/05/23 3.2.4 Added Symmetry.wyckoff_label(), Symmetry.spacegroup_dict
52+
06/05/25 3.3.0 Symmetry.from_cif now loads operations from find_spacegroup if not already loaded
5253
5354
@author: DGPorter
5455
"""
@@ -67,7 +68,7 @@
6768
from .classes_multicrystal import MultiCrystal
6869
from .classes_plotting import Plotting, PlottingSuperstructure
6970

70-
__version__ = '3.2.4'
71+
__version__ = '3.3.0'
7172

7273

7374
class Crystal:
@@ -227,13 +228,13 @@ def write_cif(self, filename=None, comments=None):
227228
else:
228229
fc.write_cif(cifvals, filename, comments)
229230

230-
def new_cell(self, lattice_parameters=(), *args, **kwargs):
231+
def new_cell(self, *lattice_parameters, **kwargs):
231232
"""
232233
Replace the lattice parameters
233234
:param lattice_parameters: [a,b,c,alpha,beta,gamma]
234235
:return: None
235236
"""
236-
self.Cell.latt(lattice_parameters, *args, **kwargs)
237+
self.Cell.latt(*lattice_parameters, **kwargs)
237238

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

11631165
keys = cifvals.keys()
@@ -1718,7 +1720,11 @@ def fromcif(self, cifvals):
17181720
else:
17191721
self.spacegroup_dict = fc.spacegroup(1)
17201722

1721-
self.generate_matrices()
1723+
if len(self.symmetry_operations) == 1:
1724+
# use found spacegroup as none provided by CIF
1725+
self.load_spacegroup(sg_dict=self.spacegroup_dict)
1726+
else:
1727+
self.generate_matrices()
17221728

17231729
def update_cif(self, cifvals):
17241730
"""

0 commit comments

Comments
 (0)