Skip to content

Commit

Permalink
Correctly calculate S(Q,w) with energy bin size
Browse files Browse the repository at this point in the history
commit 96f8dcc
Author: Rebecca Fair <[email protected]>
Date:   Mon Jul 12 16:51:22 2021 +0100

    Add missing test file

commit 3184517
Author: Rebecca Fair <[email protected]>
Date:   Mon Jul 12 16:29:13 2021 +0100

    Update test files

commit 1651407
Author: Rebecca Fair <[email protected]>
Date:   Mon Jul 12 15:46:34 2021 +0100

    Update changelog

commit 1a9c285
Author: Rebecca Fair <[email protected]>
Date:   Mon Jul 12 15:07:05 2021 +0100

    Account for ebin size in calculate_sqw_map
  • Loading branch information
rebeccafair committed Jul 13, 2021
1 parent 61f62c1 commit 9455993
Show file tree
Hide file tree
Showing 17 changed files with 70,850 additions and 70,965 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
`Unreleased <https://github.com/pace-neutrons/Euphonic/compare/v0.6.0...HEAD>`_
----------

- Bug fixes:

- The scaling of S(Q,w) as produced by ``StructureFactor.calculate_sqw_map``
was incorrect, and did not correctly scale with energy bin size (given its
units are now ``length**2/energy``). This has been fixed, and S(Q,w) scale
has changed by a factor of (hartee to energy bin unit conversion)/(energy
bin width magnitude). e.g. if using an energy bin width of 0.1 meV, the new
S(Q,w) will be scaled by 2.72e4/0.1 = 2.72e5. The original structure factors
can now be correctly recovered by multiplying S(Q,w) by the energy bin width.

`v0.6.0 <https://github.com/pace-neutrons/Euphonic/compare/v0.5.2...0.6.0>`_
------

Expand Down
5 changes: 5 additions & 0 deletions euphonic/structure_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def _bose_corrected_structure_factor(self, e_bins: Quantity,
np.tile(range(self.n_qpts), (3*self.crystal.n_atoms, 1)))
np.add.at(sqw_map, (first_index, p_bin), p_intensity)
np.add.at(sqw_map, (first_index, n_bin), n_intensity)
# Account for bin widths
bin_widths = np.ones(sqw_map.shape)
bin_widths[:, 1:-1] = np.tile(np.diff(e_bins_internal)[np.newaxis, :],
(self.n_qpts, 1))
sqw_map /= bin_widths
# Exclude values outside ebin range
sqw_map = sqw_map[:, 1:-1]
# Avoid issues in converting when energy is in cm^-1
Expand Down
90 changes: 45 additions & 45 deletions tests_and_analysis/test/data/script_data/intensity-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -1753,15 +1753,15 @@
"data_1": [
0.0,
0.0,
1.910046787603372e-31,
4.965648221904206e-27,
0.0,
3.3022923914276934e-30,
3.335834130111605e-05,
8.585141708636422e-26,
0.8672341915529949,
0.0,
0.0,
0.0,
0.0,
5.5995216275008715e-33,
1.4557368329182363e-28,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -1855,8 +1855,8 @@
0.0,
0.0,
0.0,
1.4208192127335206e-37,
8.323814193018447e-14,
3.693777787616434e-33,
2.1639853753994255e-09,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -1936,7 +1936,7 @@
0.0,
0.0,
0.0,
8.100880178994279e-38,
2.1060280574150785e-33,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -1976,15 +1976,15 @@
0.0,
0.0,
0.0,
3.312500736635406e-37,
2.6530355836422666e-36,
1.3916365231259326e-36,
8.611680875927013e-33,
6.897234933753515e-32,
3.617910027883633e-32,
0.0,
0.0,
0.0,
0.0,
0.0,
1.695040968507659e-05,
0.4406686383785358,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2076,18 +2076,18 @@
0.0,
0.0,
0.0,
1.9345231912280533e-05,
0.5029280804585545,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
9.1853085991284e-37,
1.539009720557996e-36,
1.5989790527202533e-36,
3.7707752625003375e-38,
2.3879525679123894e-32,
4.001043813157597e-32,
4.1569492127284314e-32,
9.803081054851692e-34,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2151,14 +2151,14 @@
0.0,
0.0,
0.0,
1.9356461157747485e-10,
2.5476642774169297e-10,
5.032200130077893e-06,
6.623295654991611e-06,
0.0,
0.0,
0.0,
0.0,
0.0,
1.6987017718767695e-05,
0.4416203565175126,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2250,7 +2250,7 @@
0.0,
0.0,
0.0,
1.9399042940996047e-05,
0.5043270338286722,
0.0,
0.0,
0.0,
Expand All @@ -2259,8 +2259,8 @@
0.0,
0.0,
0.0,
1.153293863690975e-11,
5.905625722471298e-12,
2.99827818917243e-07,
1.5353163104877042e-07,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2324,15 +2324,15 @@
"data_1": [
0.0,
0.0,
5.8785865389299496e-30,
1.5282867929625357e-25,
0.0,
5.0000763487604064e-29,
0.0004579894424086163,
1.2998959183487368e-24,
11.906590325993065,
0.0,
0.0,
0.0,
0.0,
3.779337005832797e-32,
9.825339465395022e-28,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2426,8 +2426,8 @@
0.0,
0.0,
0.0,
2.758205360650252e-37,
1.0487235807442378e-13,
7.170650286501513e-33,
2.7264213723926165e-09,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2507,7 +2507,7 @@
0.0,
0.0,
0.0,
8.600087358640515e-38,
2.235809550730358e-33,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2547,15 +2547,15 @@
0.0,
0.0,
0.0,
4.22638813899609e-37,
3.388434597154034e-36,
1.779515486780818e-36,
1.0987561605135242e-32,
8.809090092242473e-32,
4.6262991933677097e-32,
0.0,
0.0,
0.0,
0.0,
0.0,
2.160698551353598e-05,
0.5617280680889707,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2647,18 +2647,18 @@
0.0,
0.0,
0.0,
2.468404353435372e-05,
0.6417239498073527,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.1755438113056181e-36,
1.9674306311132863e-36,
2.0414655267408218e-36,
4.809532366508667e-38,
3.056122538079058e-32,
5.114831991820366e-32,
5.307304370098081e-32,
1.2503592058030512e-33,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2722,14 +2722,14 @@
0.0,
0.0,
0.0,
2.454012524005314e-10,
3.2352995310516923e-10,
6.379824308726786e-06,
8.410976876567586e-06,
0.0,
0.0,
0.0,
0.0,
0.0,
2.1521086069035152e-05,
0.5594948954430622,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -2821,7 +2821,7 @@
0.0,
0.0,
0.0,
2.4604727792443716e-05,
0.639661937110383,
0.0,
0.0,
0.0,
Expand All @@ -2830,8 +2830,8 @@
0.0,
0.0,
0.0,
1.4675046967553063e-11,
7.510167048164069e-12,
3.8151484745682423e-07,
1.952457284866418e-07,
0.0,
0.0,
0.0,
Expand Down Expand Up @@ -8046,4 +8046,4 @@
2.0473330625824127
]
}
}
}
Loading

0 comments on commit 9455993

Please sign in to comment.