From NSDL Materials Digital Library Wiki
For a given simulation, (e.g. NVE, NVT, NTP ) thermodynamic quantities can be calculated.
The following expression show how to calculate the average pressure of a closed volume. For derivations that show how to calculate the pressure as a local quantity, see . For pair-wise additive interactions in a NVT, Pressure can be calculated, using the virial theorem as
where d is the dimensionality of the system (i.e. usually 3), ρ is the number density N/V, f(rij) is the force between particle i and j at a distance rij, and where the temperature can be directly calculated as described in the temperature section below.
These expressions can also be modified to compute the entire pressure or stress tensor, for which the off-diagonal terms represent the shear, and formulated using the total resultant force on a particle. The Equation below only applies to systems that do not have periodic boundary conditions. Without periodic boundary conditions the force term on the right hand side is identical to the force term in first equation above. In perioidic boundary condition systems, the vector additions fail. ' The tensor element inβ and α coordinate direction is
where Fiβ is the β component of the total resultant force on particle i. Note that αi is the α component of the position vector for particle i. The scalar pressure is then the trace of the tensor divided by 3, or,
Note that this form is only appropriate for calculating the average pressure of a volume of particles. By using the two-body (or n-body) form, a more localized pressure can be calculated. Also note that the equation form above is technically defined for an NVE simulation as averages of different ensembles are slightly different. See  and  for more details. The error, however, is O(N − 1).
 Lebowitz, Percus, Verlet, "Ensemble Dependence of Fluctuations with Applications to Machine Computations", 1967 http://prola.aps.org/pdf/PR/v153/i1/p250_1
 M. P. Allen, D. J. Tildesley "Computer Simulation in Chemical Physics" 1993
 Heinz, Paul, Binder, Calculation of Local Pressure Tensors in system of Many Body Interactions, 2003, http://arxiv.org/pdf/cond-mat/0309014
 Frenkel, Smit "Understanding Molecular SImulations"
where f is the degree of freedom of the system.