MDAnalysis线性密度模块的bug修复 - Bug fix for the MDAnalysis linear density module
MDAnalysis的线性密度模块有bug:模拟一盒Lammps模拟的均匀的水分子,计算出来的线性密度有一些向上突起的尖峰,如图所示:
There is a bug in the MDAnalysis linear density module: when calculating the linear density of a uniformly simulated box of water molecules using LAMMPS, the result includes some sharp upward spikes, as shown below.
其bug位于lineardensity.py
中,LinearDensity
类的__init__
function,第218行:
The bug is located in the lineardensity.py
file, within
the __init__
function of the LinearDensity
class, at line 218:
1 | bins = (self.dimensions // self.binsize).astype(int) |
当self.dimensions
为numpy([20., 20., 20.])
且self.binsize
为0.1
时,由于浮点精度误差bins
不是200, 200, 200
,而是199, 199, 199
。这会导致后续np.histogram
函数计算出现错误。
可将其替换为:
When self.dimensions
is
numpy([20., 20., 20.])
and self.binsize
is
0.1
, due to floating-point precision errors,
bins
becomes 199, 199, 199
instead of
200, 200, 200
. This causes incorrect calculations in the
subsequent np.histogram
function.
This can be fixed by replacing the line with:
1 | bins = np.round(self.dimensions / self.binsize).astype(int) |
有关于这个问题的详细讨论在这个github issue中
For more detailed discussion on this issue, please refer to this GitHub issue.