GMX-DENSITY(1)

πŸ’– GMX-DENSITY(1) β€” the gmx-density page, GROMACS edition πŸ’–

okay bestie, sit down, hydrate, because we're learning gmx-density β€” it's the GROMACS tool that calculates the density of the system 🌸. This is section 1 of the manual, so it's a command you run in a shell, not a function you call, kay? ✨


🌈 NAME 🌈

gmx-density β€” calculate the density of the system πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

gmx density [-f [<.xtc/.trr/...>]] [-n [<.ndx>]] [-s [<.tpr>]]
            [-ei [<.dat>]] [-o [<.xvg>]] [-b <time>] [-e <time>]
            [-dt <time>] [-[no]w] [-xvg <enum>] [-d <string>]
            [-sl <int>] [-dens <enum>] [-ng <int>] [-[no]center]
            [-[no]symm]

like. look at her. so many little flags. each one is doing something, and we're gonna cover every single one, no skipping, periodt πŸ‘‘


✨ DESCRIPTION ✨

So gmx density computes partial densities across the box, using an index file. That's the whole vibe. It's giving "slice the box up and tell me how much stuff is in each slice" 🍰

⚠️ For the total density of NPT simulations, use gmx energy instead. Not this one. Different tool, bestie, don't mix them up πŸ™ˆ

Okay now the spicy parts, the options that change how the binning actually works:

-center performs the histogram binning relative to the center of an arbitrary group, in absolute box coordinates. Let's say you're calculating profiles along the Z axis box dimension bZ β€” then the output would go from -bZ/2 to bZ/2 if you center based on the entire system. 🌸

πŸ’€ IMPORTANT LORE: this behaviour changed in GROMACS 5.0. Earlier versions merely performed a static binning in (0,bZ) and shifted the output. Now we compute the center for each frame and bin in (-bZ/2,bZ/2). so if you're reading ancient forum posts, that's why nothing matches, iykyk 😭

-symm symmetrizes the output around the center. This will automatically turn on -center too β€” package deal, they come together 🫢. The binning is now always performed in relative coordinates to account for changing box dimensions with pressure coupling, with the output scaled to the average box dimension along the output axis.

Densities are in kg/m^3, and number densities or electron densities can also be calculated. For electron densities, a file describing the number of electrons for each type of atom should be provided using -ei. It should look like:

2
atomname = nrelectrons
atomname = nrelectrons

The first line contains the number of lines to read from the file. There should be one line for each unique atom name in your system. The number of electrons for each atom is modified by its atomic partial charge. ⚑


🧚 IMPORTANT CONSIDERATIONS FOR BILAYERS 🧚

okay so this is like. the most common usage scenario and also the one that will humble you, so pay attention 🌈

Pretty much everyone's first rodeo with this tool is calculating the density of various groups across a lipid bilayer, typically with the z axis being the normal direction. For short simulations, small systems, and fixed box sizes this will work fine β€” but for the more general case, lipid bilayers can be complicated. 😭

Problem number one: while both proteins and lipids have low volume compressibility, lipids have quite high area compressibility. What does that mean for you? It means the shape of the box (thickness and area/lipid) will fluctuate substantially even for a fully relaxed system. And since GROMACS places the box between the origin and positive coordinates, this in turn means that a bilayer centered in the box will move a bit up/down due to these fluctuations, and smear out your profile. πŸ™ˆ

The easiest way to fix this (if you want pressure coupling) is to use the -center option that calculates the density profile with respect to the center of the box. And note β€” you can still center on the bilayer part even if you have a complex non-symmetric system with a bilayer and, say, membrane proteins. In that case our output will simply have more values on one side of the (center) origin reference. slay, asymmetry is fine πŸ’…

Problem number two: finally, large bilayers that are not subject to a surface tension will exhibit undulatory fluctuations, where there are 'waves' forming in the system. This is a fundamental property of the biological system, and if you are comparing against experiments you likely want to include the undulation smearing effect. 🌊


πŸ’… OPTIONS πŸ’…

πŸ“ Options to specify input files:

  • -f [<.xtc/.trr/...>] (traj.xtc) β€” Trajectory: xtc trr cpt gro g96 pdb tng h5md
  • -n [<.ndx>] (index.ndx) (Optional) β€” Index file
  • -s [<.tpr>] (topol.tpr) β€” Portable xdr run input file ✨
  • -ei [<.dat>] (electrons.dat) (Optional) β€” Generic data file (this is your electron-count file, bestie, the one from up there πŸ‘†)

πŸ¦‹ Options to specify output files:

  • -o [<.xvg>] (density.xvg) β€” xvgr/xmgr file πŸ“ˆ

πŸ‘‘ Other options:

  • -b <time> (0) β€” Time of first frame to read from trajectory (default unit ps)
  • -e <time> (0) β€” Time of last frame to read from trajectory (default unit ps)
  • -dt <time> (0) β€” Only use frame when t MOD dt = first time (default unit ps)
  • -[no]w (no) β€” View output .xvg, .xpm, .eps and .pdb files πŸ‘€
  • -xvg <enum> (xmgrace) β€” xvg plot formatting: xmgrace, xmgr, none
  • -d <string> (Z) β€” Take the normal on the membrane in direction X, Y or Z. 🧭
  • -sl <int> (50) β€” Divide the box in this number of slices. 🍰
  • -dens <enum> (mass) β€” Density: mass, number, charge, electron
  • -ng <int> (1) β€” Number of groups of which to compute densities.
  • -[no]center (no) β€” Perform the binning relative to the center of the (changing) box. Useful for bilayers. πŸ’–
  • -[no]symm (no) β€” Symmetrize the density along the axis, with respect to the center. Useful for bilayers. πŸ’–

πŸ’€ KNOWN ISSUES πŸ’€

  • When calculating electron densities, atomnames are used instead of types. This is bad. 😭 no further notes, that's it, that's the issue. she's honest at least.

🌟 SEE ALSO 🌟


2026, GROMACS development team πŸ‘‘


okay that's the whole page, you read it all, I'm so proud of you πŸŽ€πŸ§šπŸ’œ β€” and for the cute sign-off: this is from GROMACS 2026.4, dated Oct 02, 2026, and it lives in the GMX-DENSITY(1) corner of the manual universe. go compute some densities bestie, ily, bye βœ¨πŸ’–

πŸ“¦ where this page comes from