From PR #313 review (non-blocking comment by @cortner):
The _compute_virial function in src/et_models/et_calculators.jl computes the virial tensor from edge gradients:
function _compute_virial(G::ET.ETGraph, ∂G)
# V = -∑ (∂E/∂𝐫ij) ⊗ 𝐫ij
V = zeros(SMatrix{3,3,Float64,9})
for (edge, ∂edge) in zip(G.edge_data, ∂G.edge_data)
V -= ∂edge.𝐫 * edge.𝐫'
end
return V
end
This is essentially the pullback of the graph construction with respect to the cell vectors, and would be better placed in the EquivariantTensors atoms extension alongside forces_from_edge_grads.
Reference: #313 (comment)