Proof of pressure of system in molecular dynamics I am studying barostatting algorithms, and I am seeing this equation quite a bit:
$$ PV = \frac{1}{3}\left[ \sum _i \left( \sum _{i<j} F_{ij} \cdot r_{ij} \right)+ \frac{|p_i|^2}{m_i}\right]$$ as seen here and here and here.
I am wondering about the proof of this equation. This equation looks an awful lot like the virial theorem, which states that
$$2\langle T \rangle = - \left\langle \sum_i F_i \cdot r_i \right\rangle $$
However, I don't see how we get to thermodynamic pressure from the above equation in the way they have written it above. I can see that average kinetic energy $$\langle T \rangle = \frac{3}{2}Nk_BT$$
That is all I know about how to delve into proving the statement for PV I have mentioned up above.
How do I go about proving it? I appreciate any advice you have for me.
 A: I am not aware of a derivation for this using Virial Theorem (I don't think you can derive the exact equation using Virial theorem, not that I have tried it), but I know of a derivation using standard ensemble theory.
Please take a look at this paper: 'On the calculation of specific heats, thermal pressure coefficients and compressibilities in molecular dynamics simulations', P. S. Y. CheungMol. Phys., 33:519–526, 1977
This paper is used as a preliminary on stimulating Molecular Dynamics using Monte Carlo or some other technique, and I was satisfied by that derivation.
Let me know whether this suits your need.
A: I try to prove this from the virial theorem.
$$2\langle T \rangle = - \left\langle \sum_i \vec{F}_i \cdot \vec{r}_i \right\rangle $$
I classify the force into (a) interaction force between constituent molecules and (b) force from the container.
Apparently, the pressure will come from the second category. Let's investigate (b) first:
The force from the container occurs for  $\vec{r}_k$ at the container surface. Where the gas exerts pressure $P$ to the surface perpendicular to the surface $ P d\vec{A}$, therefore the surface also renders the same force but in the opposite direction $d\vec{F} = - P d\vec{A}$. This force contributes to the virial term:
$$
\sum_{r_k \text{ at surface}} \vec{F}_k \cdot \vec{r}_k 
=- P \sum_{r_k \text{ at surface}} d\vec{A}_k \cdot \vec{r}_k = -P \unicode{x222f}_A  d\vec{A} \cdot \vec{r}.  
$$
We then turn the surface integral into volume integral by Divergence Theorem:
$$ \unicode{x222f}_A  \vec{V} \cdot d\vec{A} = \iiint \vec\nabla\cdot\vec{V} d^3 r$$
We then have:
$$
 \sum_{r_k \text{ at surface}} \vec{F}_k \cdot \vec{r}_k = -P \iiint \vec\nabla\cdot\vec{r} d^3r =  -3 P \iiint d^3r = -3 P V.
$$
Then the interaction term:
$$
\vec{F}_{ij}\cdot \vec{r}_i + \vec{F}_{ji}\cdot \vec{r}_i = \vec{F}_{ij}\cdot \left( \vec{r}_i - \vec{r}_j \right) = \vec{F}_{ij}\cdot  \vec{r}_{ij}. 
$$
Altogether, we have:
$$
   - 3 P V + \sum_i \sum_{j\ne i} \vec{F}_{ij}\cdot \vec{r}_{ij} + \sum_i \frac{p_i^2}{m_i} = 0 \\
 PV = \frac{1}{3} \left\{  \sum_i \sum_{j\ne i} \vec{F}_{ij}\cdot \vec{r}_{ij} + \sum_i \frac{p_i^2}{m_i} \right\}
$$
