Custom pressure compute for use in fix nph

I have a simulation of spheres or ellipsoids. The default pressure compute includes the rotational kinetic energy, which I do not want. I know how to compute pressure just using translational kinetic energy, since it is described in the documentation of compute stress/atom. How do I turn this quantity, which currently is a variable, into a compute that can be fed into my fix nph barostat? Ideally, this compute should be able to give both the scalar and the vector (tensor) pressure, because sometimes I barostat only along some dimensions.

# Computing my custom pressure
compute        temp_null all temp
compute        peratom_null all stress/atom NULL
compute        p_null all reduce sum c_peratom_null[1] c_peratom_null[2] c_peratom_null[3] c_peratom_null[4] c_peratom_null[5] c_peratom_null[6]
variable       press_scal_null equal -(c_p_null[1]+c_p_null[2]+c_p_null[3])/(3*vol)
variable       press_vec_null vector -c_p_null/vol
fix      fNPH         all     nph/asphere x ${my_press} ${my_press} ${my_Pdamp}
# Cannot do this, because my pressure is a variable and not a compute
fix_modify fNPH temp temp_null press press_vec_null

Thank you.


The easiest option is to compute the pressure directly with a compute and use it to replace the default pressure:

compute        temp_null all temp
compute        press_trasl all pressure temp_null

fix      fNPH         all     nph/asphere x ${my_press} ${my_press} ${my_Pdamp}
fix_modify fNPH press press_trasl

Note that this topic has already been discussed in the forum and mailing list. You find a list of all the various contributions in this thread: Pressure for atom_style ellipsoid (probably a bug)

Thank you very much for the answer. It works as it should. However, I would also like to compute my pressure using only a subset of atoms (I know that the volume in that case is not well defined etc. but I still believe that it is the correct thing to do in my case) However, the pressure compute does not allow any group but all. Is there any way to solve the original problem such that this can be done? Perhaps by defining a new compute using the stress/atom compute? Thank you.

hi you may check fix modify press and see whether it works for your case.
i used this to exclude some part when calculating p’