Skip to content

Commit 23da7cf

Browse files
committed
for pxrd profiling, enabled peak integration (instead of just sampling at grid points)
1 parent b5e2e86 commit 23da7cf

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎pyxtal/XRD.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
from monty.serialization import loadfn
1111
from scipy.interpolate import interp1d
12-
12+
from scipy.special import erf
1313
from pyxtal.database.element import Element
1414

1515
with importlib.resources.as_file(
@@ -603,8 +603,13 @@ def get_profile(self, two_thetas, intensities, min2theta, max2theta):
603603
# print(two_theta, intensity)
604604
if self.method == "gaussian":
605605
fwhm = self.kwargs["FWHM"]
606-
dtheta2 = ((px - two_theta) / fwhm) ** 2
607-
tmp = np.exp(-4 * np.log(2) * dtheta2)
606+
bin_edges = np.concatenate([px - self.res/2, [px[-1] + self.res/2]])
607+
tmp = np.zeros_like(px)
608+
for i in range(len(px)):
609+
left, right = bin_edges[i], bin_edges[i+1]
610+
tmp[i] = gaussian_integrated(left, right, two_theta, fwhm)
611+
#dtheta2 = ((px - two_theta) / fwhm) ** 2
612+
#tmp = np.exp(-4 * np.log(2) * dtheta2)
608613
# tmp = gaussian(two_theta, px, fwhm)
609614

610615
elif self.method == "lorentzian":
@@ -925,6 +930,12 @@ def get_all_intensity_par(cpu, queue, cycles, Start, End, hkl_per_proc, position
925930
queue.put((cpu, Start, End, Is))
926931

927932

933+
def gaussian_integrated(bin_left, bin_right, center, fwhm):
934+
sigma = fwhm / (2 * np.sqrt(2 * np.log(2)))
935+
# Integrate the normalized Gaussian over [bin_left, bin_right]
936+
return 0.5 * (erf((bin_right - center) / (np.sqrt(2) * sigma)) -
937+
erf((bin_left - center) / (np.sqrt(2) * sigma)))
938+
928939
def pxrd_refine(xtal, ref_pxrd, thetas, steps=50):
929940
"""
930941
Improve the lattice w.r.t the reference PXRD

0 commit comments

Comments
 (0)