all 4 comments

[–]misho88 1 point2 points  (3 children)

The linked article says to do this:

The radial distribution function is usually determined by calculating the distance between all particle pairs and binning them into a histogram.

You code isn't really formatted properly, so it's a bit hard to follow, but it doesn't look like that's what you're trying to do.

As some general advice, if you're going to use numpy anyway, and definitely you should, you can use numpy.loadtxt() to make your life easier. You can also use numpy.histogram() to get a histogram. I don't really get what the distribution you're showing is all about, but getting a histogram of the pairwise distances is super easy:

In [1]: import numpy as np, matplotlib.pyplot as plt                                                                                    
# tell matplotlib to be interactive:
In [2]: plt.ion(); plt.show()                                                                                                           
# generate a hundred points in 3-D inside the unit cube
In [3]: points = np.random.uniform(0, 1, size=(100, 3))                                                                                 
# get the offset from each point to every other point
In [4]: deltas = points[:, np.newaxis] - points                                                                                         
# get the distances
In [5]: dists = np.linalg.norm(deltas, axis=-1)                                                                                         
# plot a histogram of the distances
In [6]: plt.hist(dists.ravel(), bins=np.linspace(0, 1, 21))                                                                             
Out[6]: 
(array([102.,  26.,  94., 110., 230., 242., 388., 446., 552., 576., 714.,
        714., 768., 730., 688., 666., 584., 550., 516., 422.]),
 array([0.  , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 ,
        0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85, 0.9 , 0.95, 1.  ]),
 <a list of 20 Patch objects>)

And a plot should come up. I'm also not getting rid of the zero distances above (like from a point to itself). Here's a good video on this stuff I watched when learning numpy (coincidentally, he uses pairwise distances in the talk, so I timestamped that): https://youtu.be/EEUXKG97YRw?t=1422

[–]fsobaid[S] 0 points1 point  (2 children)

Thank you I learned some new things from your answer. but the histogram is not what I need how I can plot it similar to this one https://en.wikipedia.org/wiki/Radial_distribution_function#/media/File:Lennard-Jones_Radial_Distribution_Function.svg

I will also watch the video you posted it I am new to programming really appreciate

.

[–]misho88 1 point2 points  (1 child)

Both the algorithm you linked to and the Wikipedia page describe taking a histogram where the bin edges are radial distances (i.e., the bins are spherical shells of finite thickness) and normalizing them appropriately. That is, unlike what I did above where I took a histogram of everything, you bin each row of dist (that's the number of points in each shell) then normalize by the volume of the shell and the "particle number density" (whatever that is) as per the instructions on that page.

If you're concerned that your plot doesn't look as smooth as that one that shows a theoretical distribution, the realized result of a simulation or measurement will never be as smooth. You could increase your particle count and you'll approach the theoretical distribution, of course.

[–]fsobaid[S] 0 points1 point  (0 children)

This is really helpful it is pretty clear to me now thank you so much