# A How to calculate RDF (Radial Distribution Function)

1. Mar 31, 2017

### Auteng

Dear friends
How can i calculate RDF(radial distribution function)?
Thanks

2. Mar 31, 2017

### mathman

What are you starting with?

3. Apr 1, 2017

### Auteng

I attache my RDF plot
is it true?
Why it is not smooth?
27 particles in 3.8nm*3.8nm*3.8nm
my formula:
g=(h(n)*l_x^3)/(n_p*4*pi*((n-0.5)*delta_r)^2*delta_r);
h(n):number of particles in bin
n_p:total number of particles

But this RDF figure form Wikipedia is very smooth:
and my first peak is very more than this figure...

Last edited: Apr 1, 2017
4. Apr 1, 2017

### BvU

What are the particle sizes in your simulation ? And in the Wiki figure ?
Purely statistics. Instead of a cube, take a sphere and use a higher number of particles. You should realize that 8 particles in a bin is $\pm\sqrt8$ ! If you want a noise band of 1%, make sure that even in the higher $r$ bins there are at least 10000 particles per bin !

5. Apr 1, 2017

### Auteng

Should i average RDF on all particles?

Or RDF is for one particle?

6. Apr 1, 2017

### BvU

From where you nicked the picture .
In order not to bias the result: take a few of the particles near the center of your sphere (which should have a radius well exceeding your $r/\sigma$ scale)

7. Apr 2, 2017

### Auteng

I write the RDF formula:

$$g(r)=\frac{\frac{particle at each bin} {4 \pi r^2}} {\frac{total number of atoms} {V total}}$$

But i don't understand why the following link two times divided it by N. I think we should divide by N one time according to the formula that i have wrote...
http://www.physics.emory.edu/faculty/weeks//idl/gofr2.html

8. Apr 3, 2017

### Auteng

What is the meaning of $\delta (r-r_{ij})$ in the following equation?

Before all what is the meaning of $\delta$?

9. Apr 3, 2017

### BvU

Kronecker delta: (integer argument) $\delta_{ij} = 1$ if $i = j$ and for all other values of the argument it is 0.
But what you have here is the Dirac delta function (real number as argument) which -- for beginning physicists -- is a kind of limit of a 'spike at zero', such that the function is zero for all arguments $\ne 0$ but $\displaystyle \int_{-\infty}^{+\infty} \delta(x) \, dx = 1$ nevertheless.

You get away with it because in fact you don't plot/calculate $g(r)$ but $\int g(r) \, dV$ with $dV = 4\pi r^2 dr$, the bin width of your histogram.

10. Apr 3, 2017

### Auteng

11. Apr 3, 2017

### BvU

Can't read it. What is the dimension of particleateachbin ?

the 2N occurs because you encounter each pair twice, e.g. 34 as 3,4 and as 4,3

 no, that's corny. If you change particleateachbin to numberofparticlesineachbin I'd be happy.

12. Apr 3, 2017

### Auteng

particleateachbin=particle at each bin(particles between r , r+dr)
totalnumberofatoms=total number of atoms(N)

13. Apr 3, 2017

### BvU

And remember: that is $g(r)dr$, not $g(r)$ -- check dimensions

14. Apr 3, 2017

### Auteng

Yes i forgot dr in denominator

But the formula that i write is not math with #8
My formula has one N but that formula have two N one in denominator and one in $\rho_0=N/V$

15. Apr 3, 2017

### Auteng

I think i should take average over all of particles...??!!

What i write is for one particle...???!!!

Is it true?

16. Apr 3, 2017

### Auteng

I think for example if we have 3 particles:
first we look at bin 1 for all three particles:
bin 1 for particle 1: 1 atom
bin 1 for particle 2: 1 atom
bin 1 for particle 3: 0 atom

And so on...

we have $\frac{2} {3} = 0.67$ for bin 1 in histogram?

17. Apr 3, 2017

### BvU

Hmm, I think I'm making a mess of this. Misunderstood the two N for 2N.
$g(r)$ is dimensionless and should go to 1 for $r>>\sigma$ (because by then density shouldn't depend on $r$ any more).
So I think #8 (where did that come from?) is something else than #7. (or it has something to do with this dirac delta)

Your denominator in #7 is $\rho$. Your numerator goes toward $\rho$ so I think you are OK: the number of particles between $r$ and $r+dr$ is $g(r) \rho \, 4\pi r^2 \, dr$ so $g(r)$ gives the ratio between what you expect from ideal gas (see quote) and what you count.

(same as post #5). Do you expect a difference ?
Is that a question ? After all, it's your calculation: you should know that better than anyone else

Back to post #4: You haven't described what you actually do for your calculation, but one can imagine there is a simulation going on of a volume with particles that obey this potential function. So you have a bunch of positions.

If you take the particle closest to the center of your volume, you get some statistics that can be improved by taking some more particles near the center and repeat. But the further you get from the center, the more asymmetric and biased things become: for a particle at the boundary of your volume the average distance is considerably bigger that for the original particle at the center.

It's a tradeoff; I suppose you are reasonably OK as long as your total volume radius $>>$ the maximum $r/\sigma$ of your $g(r)$ plot and the radius of the sphere you use for counting is $<$ than that maximum. The translation from $>>$ to a number is up to you (you simply look at the results).