estimate_pressure_tensor¶
- mdhelper.openmm.system.estimate_pressure_tensor(context: Context, dh: float = 1e-05, *, diag: bool = False) ndarray[float] [source]¶
Computes the estimated pressure tensor using a central finite difference for the virial contribution.
The pressure tensor is given by
\[\mathbf{p}=\frac{1}{V}\left( \sum_{i=1}^N m_i\mathbf{v}_i^\mathsf{T}\mathbf{v}_i +\mathbf{h}^\mathsf{T}\frac{dU}{d\mathbf{h}}\right)\]where \(V\) is the volume, \(m_i\) and \(\mathbf{v}_i\) are the mass and velocity vector of particle \(i\), \(\mathbf{h}\) is a \(3\times 3\) matrix where the rows contain the box vectors, and \(U\) is the total pairwise potential energy.
To evaluate \(dU/d\mathbf{h}\), the box vectors are perturbed by dh in each of the six “directions” and the positions are updated accordingly. Then, OpenMM reevaluates the potential energy based on the new periodic box vectors and particle positions, and the difference in potential energy is used in the central finite difference formula to estimate the derivative.
- Parameters:
- contextopenmm.Context
OpenMM simulation context.
- dhfloat, default:
1e-5
Finite difference step size.
- diagbool, keyword-only, default:
False
Determines whether only the values in the main diagonal of the pressure tensor (i.e., the values that, when summed, gives the system pressure) are calculated.
- Returns:
- presnumpy.ndarray
Estimated pressure tensor (or diagonal components).
Shape: \((3,)\) or \((3,\,3)\).
Reference unit: \(\mathrm{atm}\).