# Integration of g(r)

**URL:** <https://gromacs.bioexcel.eu/t/integration-of-g-r/739>\
**Category:** User discussions\
**Created:** [August 30, 2020, 11:13pm UTC](https://gromacs.bioexcel.eu/t/integration-of-g-r/739 "2020-08-30T23:13:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![isimuly](https://avatars.discourse-cdn.com/v4/letter/i/d6d6ee/32.png) [@isimuly](https://gromacs.bioexcel.eu/u/isimuly)\
**Post date:** [August 30, 2020, 11:13pm UTC](https://gromacs.bioexcel.eu/t/integration-of-g-r/739/1 "2020-08-30T23:13:39Z")

</div>

GROMACS version: 2018  
GROMACS modification: No  
Here post your question

Hi everyone,

Recently, I am confused by the result of integration of g®. In the manul, the definition of g®\_AB is g®\_AB = pho®/ pho\_local, the r\_max for pho\_local is the half of box.

Based on the definition, the integration from zero to rmax of g®\_AB\*pho\_local will be the number of B (smaller than total number of B) in the sphere with radius r\_max.

However, when I calculated the integration, I found that the result is bigger than the total number of B.

For example, if there are 26 A monomers and 26 B monomers in the system, the integration of g\_AB_pho\_local will smaller than 26. But I got the value larger than 46.  
The pho\_local = average\_number/(4.0/3_pi_rmax_rmax\*rmax), here average\_number is accumulate number of B at distance rmax got from the output file using gmx rdf -cn

## the integration script i used:

```
double dr = rr[1]-rr[0];
sumb = 0;
double psv = 0.0,rri;
for(i = 0; i < ri; i ++){
    rri = (i + 0.5) * dr;
    double sv = (4.0 / 3.0) * PI * rri * rri * rri;
    double dsv = sv-psv;
    sumb += (gr[i])*(dsv);
    psv = sv;
    cout<<"sumb = "<<sumb<<endl;
}
double pho_local = 24.8/((4.0 / 3.0) * PI * rri * rri * rri);
cout<<"total monomer number ~: "<<sumb*pho_local<<endl;;

```

* * *

I do not find anything wrong in my script. So could anyone help me to explain why the result is unexpected. Is there some misunderstanding of the definition of g® that GROMACS used to analyze data?

Thanks in advance

Best

isimuly

---

<div class="post-metadata">

**Author:** ![cblau](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/cblau/32/5_2.png) [@cblau](https://gromacs.bioexcel.eu/u/cblau)\
**Post date:** [October 22, 2020, 4:20pm UTC](https://gromacs.bioexcel.eu/t/integration-of-g-r/739/2 "2020-10-22T16:20:42Z")

</div>

Hi isimuly,

purely following the math of (5.388) in the manual ([http://manual.gromacs.org/2021-beta1/manual-2021-beta1.pdf](http://manual.gromacs.org/2021-beta1/manual-2021-beta1.pdf)) and using A=B you would obtain the number of particles from the distribution function by integrating the following way:

\langle \rho\_{local}\rangle \int dr 4\pi r^2 g\_{AA}(r) = 1/N\_A \int d r \sum\_{i\in A}\sum\_{j\in A}\delta(r\_{ij}-r) = N\_A^2/N\_A = N\_A

(the integral on the right hand side over the delta function just counts the A,A pairs)

I agree that it’s a bit counter-intuitive to use 4\pi r^2 instead of the difference of the sphere volumes; it might help to think in terms of the continuous integral first and then approximate. There, you see that you obtain the factor by integrating in spherical coordinates over the complete angle range for \phi, \psi for a volume element r^2 \sin\phi \,\mathrm{d}\phi \,\mathrm{d}\psi \,\mathrm{d}r
