|
9 | 9 | import numpy as np |
10 | 10 | from monty.serialization import loadfn |
11 | 11 | from scipy.interpolate import interp1d |
12 | | - |
| 12 | +from scipy.special import erf |
13 | 13 | from pyxtal.database.element import Element |
14 | 14 |
|
15 | 15 | with importlib.resources.as_file( |
@@ -603,8 +603,13 @@ def get_profile(self, two_thetas, intensities, min2theta, max2theta): |
603 | 603 | # print(two_theta, intensity) |
604 | 604 | if self.method == "gaussian": |
605 | 605 | 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) |
608 | 613 | # tmp = gaussian(two_theta, px, fwhm) |
609 | 614 |
|
610 | 615 | elif self.method == "lorentzian": |
@@ -925,6 +930,12 @@ def get_all_intensity_par(cpu, queue, cycles, Start, End, hkl_per_proc, position |
925 | 930 | queue.put((cpu, Start, End, Is)) |
926 | 931 |
|
927 | 932 |
|
| 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 | + |
928 | 939 | def pxrd_refine(xtal, ref_pxrd, thetas, steps=50): |
929 | 940 | """ |
930 | 941 | Improve the lattice w.r.t the reference PXRD |
|
0 commit comments