# [gmx-users] Getting the virial for each individual atom.

Timothy Sirk tsirk at vt.edu
Mon Jan 21 22:47:14 CET 2013

```Zach,

Do you have periodic system with charges? For PBC, you might try one of the
forms in J. Chem. Phys. 131 154107 (2009). Electrostatics are more work...
For Ewald sum and PPPM contribution, you could check refs in
lammps.sandia.gov/doc/PDF/kspace.pdf

We have an upcoming paper that explains in more detail how to do this with
PPPM and gives an example with heat flux. Maybe something similar could be
done in GROMACS with PME.

best,

Tim

On Mon, Jan 21, 2013 at 1:06 PM, Marcin, Zachary
<zachary.marcin at wilkes.edu>wrote:

> Berk,
> Here is where I think I might be able to:
> In calcvir.c there is a method called calc_vir which takes, among other
> things, int nxf(no idea what this does), rvec x[], and revec f[].  It then
> does dvxx+= x[i][xx] *f[i][XX];.
> This is the same as the formula that I am trying to solve for (Vi*Pi +
> .5*SUM(Rij * Fij)).
> What I figured I could do is create another array to calculate the virials
> for, thus giving me an index position per atom, and then use that somehow.
>
> I also know that I can use R(ij) * F(ij), or the distance between atoms i
> and j times the Forces between atoms i and j.  If anyone has any insight on
> getting these, that could also work.
> I know how to get the individual positions, but I don't know how I would go
> about the forces aspect of that.
>
> Thanks,
> Zach
>
> On Mon, Jan 21, 2013 at 12:44 PM, Berk Hess <gmx3 at hotmail.com> wrote:
>
> >
> > Hi,
> >
> > The virial has no meaning per atom.
> > And you can't get the virial per atom out of Gromacs, it is never
> > calculated in that way (see the manual for details).
> > A special local pressure version of Gromacs exists, but even there you
> > won't get a virial per atom.
> >
> > Cheers,
> >
> > Berk
> >
> > ----------------------------------------
> > > Date: Mon, 21 Jan 2013 12:35:04 -0500
> > > From: zachary.marcin at wilkes.edu
> > > To: gmx-users at gromacs.org
> > > Subject: [gmx-users] Getting the virial for each individual atom.
> > >
> > > Hello,
> > > For the research I'm working with, I need to get the virial for each
> > > individual atom in the system. I've been tracing all of the calls made
> in
> > > the methods related to virials(Version 4.5.5) and this is the call
> stack
> > > that I think has what I need.
> > > mdrun.c -> do_md in md.c -> do_force in sim_util.c -> calcvir.c
> > >
> > > I have a few questions that I was wondering if anyone could answer.
> > >
> > > 1. In sim_util.c, there is a comment that says "Total virial computed
> in
> > > global_stat, called from do_md". I cannot find where this is called in
> > > do_md. Was this changed at any point and the comment was still left in
> > the
> > > code?
> > >
> > > 2. If I change the codes in calcvir.c to find the virials for each
> > > individual atom, say by piping the atom numbers and forces and
> everything
> > > needed into another program so it doesn't effect the way that gromacs
> > runs
> > > and will still allow everything to do what it needs, will this be
> screwed
> > > up by/screw up the domain decomposition/the mpi stuff?
> > >
> > > Basically, I'm looking for advice on a method to output the individual
> > > virials for each atom for each frame, instead of just the final output
> of
> > > the average virial on the entire system.
> > > Thanks,
> > > Zach Marcin
> > > Wilkes University
> > > --
> > > gmx-users mailing list gmx-users at gromacs.org
> > > http://lists.gromacs.org/mailman/listinfo/gmx-users
> > > * Please search the archive at
> > http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
> > > * Please don't post (un)subscribe requests to the list. Use the
> > > www interface or send it to gmx-users-request at gromacs.org.
> > > * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
> >                                           --
> > gmx-users mailing list    gmx-users at gromacs.org
> > http://lists.gromacs.org/mailman/listinfo/gmx-users
> > * Please search the archive at
> > http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
> > * Please don't post (un)subscribe requests to the list. Use the
> > www interface or send it to gmx-users-request at gromacs.org.
> > * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
> >
> --
> gmx-users mailing list    gmx-users at gromacs.org
> http://lists.gromacs.org/mailman/listinfo/gmx-users
> * Please search the archive at
> http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
> * Please don't post (un)subscribe requests to the list. Use the
> www interface or send it to gmx-users-request at gromacs.org.
> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>

```