Skip to content

Commit b24d74e

Browse files
committed
correct superstructure scale
Fix for issue #30 classes_crystal.py - updated scale parameter of Superstructure() so it doesn't give zero. classes_plotting.py - updates to plotting of superstructure intensity cuts functions_crystallography.py - change calc_vol to always give positive volume
1 parent f322ebd commit b24d74e

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

Dans_Diffraction/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
Diamond
3232
2017-2025
3333
34-
Version 3.3.3
35-
Last updated: 06/02/2025
34+
Version 3.3.4
35+
Last updated: 12/04/2025
3636
3737
Version History:
3838
02/03/18 1.0 Version History started.
@@ -84,6 +84,7 @@
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
8686
06/02/25 3.3.3 Added scattering options for polarised neutron and x-ray scattering. Thanks dragonyanglong!
87+
12/04/25 3.3.4 Improved superstructure calculations by fixing scale parameter
8788
8889
Acknoledgements:
8990
2018 Thanks to Hepesu for help with Python3 support and ideas about breaking up calculations
@@ -113,7 +114,7 @@
113114
Dec 2024 Thanks to dragonyanglong for pointing out the error with magnetic neutron scattering
114115
115116
-----------------------------------------------------------------------------
116-
Copyright 2024 Diamond Light Source Ltd.
117+
Copyright 2018-2025 Diamond Light Source Ltd.
117118
118119
Licensed under the Apache License, Version 2.0 (the "License");
119120
you may not use this file except in compliance with the License.

Dans_Diffraction/classes_crystal.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
Diamond
2525
2017
2626
27-
Version 3.3.0
28-
Last updated: 06/02/25
27+
Version 3.3.1
28+
Last updated: 06/04/25
2929
3030
Version History:
3131
27/07/17 1.0 Version History started.
@@ -49,7 +49,8 @@
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
52+
06/05/24 3.3.0 Symmetry.from_cif now loads operations from find_spacegroup if not already loaded
53+
06/04/25 3.3.1 scale parameter of superlattice improved
5354
5455
@author: DGPorter
5556
"""
@@ -68,7 +69,7 @@
6869
from .classes_multicrystal import MultiCrystal
6970
from .classes_plotting import Plotting, PlottingSuperstructure
7071

71-
__version__ = '3.3.0'
72+
__version__ = '3.3.1'
7273

7374

7475
class Crystal:
@@ -2386,7 +2387,7 @@ def __init__(self, Parent, P):
23862387
self.Parent = Parent
23872388
newUV = Parent.Cell.calculateR(P)
23882389
self.new_cell(fl.basis2latpar(newUV))
2389-
parent_cells_in_supercell = np.prod(np.sqrt(np.sum(np.square(P), axis=1)))
2390+
parent_cells_in_supercell = fc.calc_vol(P)
23902391
self.scale = Parent.scale * parent_cells_in_supercell
23912392

23922393
# Add exta functions

Dans_Diffraction/functions_crystallography.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
PENGFILE = os.path.join(datadir, 'peng.dat')
7373
NSLFILE = os.path.join(datadir, 'neutron_isotope_scattering_lengths.dat')
7474
NSLFILE_SEARS = os.path.join(datadir, 'neutron_isotope_scattering_lengths_sears.dat')
75+
ASFFILE = os.path.join(datadir, 'atomic_scattering_factors.npy')
7576

7677
# List of Elements in order sorted by length of name
7778
ELEMENT_LIST = [
@@ -1236,8 +1237,7 @@ def atomic_scattering_factor(element, energy_kev=None):
12361237
:param energy_kev: float or list energy in keV (None to return original, uninterpolated list)
12371238
:return: f1, f2, shape dependent on shapes of element and energy_kev: float, or [ene] or [ele, ene]
12381239
"""
1239-
asf_file = os.path.join(datadir, 'atomic_scattering_factors.npy')
1240-
asf = np.load(asf_file, allow_pickle=True)
1240+
asf = np.load(ASFFILE, allow_pickle=True)
12411241
asf = asf.item()
12421242

12431243
element = np.asarray(element, dtype=str).reshape(-1)
@@ -1295,8 +1295,7 @@ def xray_dispersion_corrections(elements, energy_kev=None):
12951295
:param energy_kev: float or list energy in keV (None to return original, uninterpolated list)
12961296
:return: f', f" with shape (len(energy), len(elements))
12971297
"""
1298-
asf_file = os.path.join(datadir, 'atomic_scattering_factors.npy')
1299-
asf = np.load(asf_file, allow_pickle=True)
1298+
asf = np.load(ASFFILE, allow_pickle=True)
13001299
asf = asf.item()
13011300

13021301
energy_kev = np.asarray(energy_kev, dtype=float).reshape(-1)
@@ -3446,7 +3445,7 @@ def group_intensities(q_values, intensity, min_overlap=0.01):
34463445
def calc_vol(UV):
34473446
"""Calculate volume in Angstrom^3 from unit vectors"""
34483447
a, b, c = UV
3449-
return np.dot(a, np.cross(b, c))
3448+
return np.abs(np.dot(a, np.cross(b, c)))
34503449

34513450

34523451
def cif2table(cif):

Examples/example_supercell.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Build a supercell from multiple unit cells and simulate the diffraction pattern
44
"""
55

6-
import sys,os
6+
import sys, os
77
import numpy as np
8-
import matplotlib.pyplot as plt # Plotting
8+
import matplotlib.pyplot as plt # Plotting
99
cf = os.path.dirname(__file__)
10-
sys.path.insert(0,os.path.join(cf,'..'))
10+
sys.path.insert(0, os.path.join(cf, '..'))
1111
import Dans_Diffraction as dif
1212

1313

@@ -23,8 +23,8 @@
2323
#sup = xtl.generate_superstructure(P)
2424

2525
# Set discrete occupancies for average structure
26-
xtl.Atoms.occupancy[2]=0
27-
xtl.Atoms.occupancy[3]=1
26+
xtl.Atoms.occupancy[2] = 0
27+
xtl.Atoms.occupancy[3] = 1
2828
xtl.generate_structure()
2929

3030
# Generate the superstructure, repeating the parent/average structure to fill the supercell

0 commit comments

Comments
 (0)