我不确定究竟在哪里提出这个问题 - 我似乎无法找到合适的平台,我觉得我可以正确地问这个......它一直困扰着我很长时间,我似乎无法掌握概念图。
我是Python的新手,因此学习非常慢。如果我说任何被认为是愚蠢或不合适的事,我道歉。我正在学习
我的问题是计算径向分布函数。
我在GitHub上找到了这个代码来计算3D系统的RDF:
def pairCorrelationFunction_3D(x, y, z, S, rMax, dr):
"""Compute the three-dimensional pair correlation function for a set of
spherical particles contained in a cube with side length S. This simple
function finds reference particles such that a sphere of radius rMax drawn
around the particle will fit entirely within the cube, eliminating the need
to compensate for edge effects. If no such particles exist, an error is
returned. Try a smaller rMax...or write some code to handle edge effects! ;)
Arguments:
x an array of x positions of centers of particles
y an array of y positions of centers of particles
z an array of z positions of centers of particles
S length of each side of the cube in space
rMax outer diameter of largest spherical shell
dr increment for increasing radius of spherical shell
Returns a tuple: (g, radii, interior_indices)
g(r) a numpy array containing the correlation function g(r)
radii a numpy array containing the radii of the
spherical shells used to compute g(r)
reference_indices indices of reference particles
"""
from numpy import zeros, sqrt, where, pi, mean, arange, histogram
# Find particles which are close enough to the cube center that a sphere of radius
# rMax will not cross any face of the cube
bools1 = x > rMax
bools2 = x < (S - rMax)
bools3 = y > rMax
bools4 = y < (S - rMax)
bools5 = z > rMax
bools6 = z < (S - rMax)
interior_indices, = where(bools1 * bools2 * bools3 * bools4 * bools5 * bools6)
num_interior_particles = len(interior_indices)
if num_interior_particles < 1:
raise RuntimeError ("No particles found for which a sphere of radius rMax\
will lie entirely within a cube of side length S. Decrease rMax\
or increase the size of the cube.")
edges = arange(0., rMax + 1.1 * dr, dr)
num_increments = len(edges) - 1
g = zeros([num_interior_particles, num_increments])
radii = zeros(num_increments)
numberDensity = len(x) / S**3
# Compute pairwise correlation for each interior particle
for p in range(num_interior_particles):
index = interior_indices[p]
d = sqrt((x[index] - x)**2 + (y[index] - y)**2 + (z[index] - z)**2)
d[index] = 2 * rMax
(result, bins) = histogram(d, bins=edges, normed=False)
g[p,:] = result / numberDensity
# Average g(r) for all interior particles and compute radii
g_average = zeros(num_increments)
for i in range(num_increments):
radii[i] = (edges[i] + edges[i+1]) / 2.
rOuter = edges[i + 1]
rInner = edges[i]
g_average[i] = mean(g[:, i]) / (4.0 / 3.0 * pi * (rOuter**3 - rInner**3))
return (g_average, radii, interior_indices)
# Number of particles in shell/total number of particles/volume of shell/number density
# shell volume = 4/3*pi(r_outer**3-r_inner**3)
这似乎是一个非常简单的代码,但我在一方面非常困惑:
bools1 = x > rMax
bools2 = x < (S - rMax)
bools3 = y > rMax
bools4 = y < (S - rMax)
bools5 = z > rMax
bools6 = z < (S - rMax)
我能理解bools1 = x > rMax
这意味着x坐标大于rMax
值的粒子的坐标。在RDF中,我们正在寻找在给定球体/半径范围内的粒子。
然而,下一个是抓住我的人,为了我的生活,我似乎无法正确理解它的重要性:bools2 = x < (S - rMax)
。
bools2是指rMax
内的内部粒子吗?如果是这样,为什么它只能指定x < rMax
?从多维数据集的边长rMax
中减去S
有什么意义?我似乎无法理解从rMax
...
S
的概念意义
答案 0 :(得分:1)
我认为这是因为rmax是壳的半径(不是变量说明中所述的直径)。假设我们有一个立方体框30x30x30(x,y,z),因此S = 30,因此框中心= 15x15x15,输入rmax为10.
如果你考虑粒子在(19,15,15)那么你在x方向的边界内,因此评估bool1 x > rmax
(19> 10)是真的。
如果你在同一点(19 <10)考虑bool2 x < rmax
的建议,那么bool2会失败,尽管粒子是有效的。但是,如果你考虑x < (S - rmax)
(19 <(30 - 10)=真),那么布尔就是真的。条件的要点是粒子在封闭球体的直径内。
如果选择相反方向的粒子:
粒子在(14,15,15)然后你在x方向的边界内,因此评估bool1 x > rmax
(14> 10)是真的。
再一次,你对bool2 x < rmax
的建议在同一点(14&lt; 10)然后bool2将失败。现在考虑x < (S - rmax)
(14 <(30 - 10)=真),布尔是真的。
如果我们在(26,15,15)拍摄粒子: bool1 = x&gt; rmax:(26> 10)为真 bool2 = x&lt; (S-rmax):( 26 <(30-10))假 在np中防止包含该粒子。其中乘法将评估为0
如果我们在(9,15,15)拍摄粒子: bool1 = x&gt; rmax:(9> 10)假 bool2 = x&lt; (s-rmax):( 9 <(30-10))为真 在np中防止包含该粒子。其中乘法将评估为0
我认为这是这条线背后的原因,希望它有所帮助。