Fix_modify pressure with variable?

Hello,

I would like to define a pressure based on number of molecules using fix_modify.

Something like this:

compute peratom all stress/atom NULL
compute p all reduce sum c_peratom[1] c_peratom[2] c_peratom[3]
variable myPress equal -((c_p[1]+c_p[2]+c_p[3])/(3*vol))*${num_mols}
fix_modify my_npt press myPress

My understanding is that fix_modify requires a compute and not a variable, what is the proper way to “cast” a variable to a compute?

Thanks,
Frank

You would have to write a suitable compute style in C++.

I don’t have my computer with me…would it be possible to use compute reduce with the variable?

variable myPress equal -((c_p[1]+c_p[2]+c_p[3])/(3*\vol))*${num_mols}
variable myPressVector vector [${myPress}]
compute newPress all reduce sum v_myPressVector
fix_modify my_npt press newPress

Would something like that work?

No. The compute has to flag that it is computing a pressure.