Calculation of 1D and 2D densities in VMD: A flexible and easy-to-use code

Yuxiang Wang, Alper Kiziltas, Patrick Blanchard, Tiffany R. Walsh

Research output: Contribution to journalArticleResearchpeer-review

14 Citations (Scopus)


Characterization of structural information at the atomistic level in molecular dynamics (MD) simulations is a necessary task for researchers in the fields of materials modeling and simulation. Visualization of the density distribution is typically one of the most important properties in structural characterization. Visual Molecular Dynamics (VMD) is a widely used molecular visualization package that can not only visualize complex molecular systems but also perform analysis by integrating special plugins or by running in-house generated TCL scripts. However, a density analysis is still not an in-built feature of VMD. This work presents a flexible and easy-to-use TCL code to be used in VMD, that can perform both 1D and 2D density calculations over any specified local areas of a given system. By using the built-in commands of VMD, the code can access and process trajectory files in any formats that are supported by VMD, as produced by mainstream simulation packages, i.e., LAMMPS, GROMACS, NAMD, and CHARMM, etc. This work introduces the calculation method, code, and usages in detail to provide a quick start for users in their density analysis work. Program summary: Program title: DensityCalculator CPC Library link to program files: Developer's repository link: Licensing provisions: GPLv3 Programming language: TCL/TK External routines: VMD (version 1.9.3, Nature of problem: Calculate mass or number density distribution from trajectory files in VMD, and project the density along a specified 1D axis or onto a specified 2D plane. Solution method: The 1D or 2D density distribution is calculated through the following steps: slice the concerned area with specified resolutions in X, Y, and Z directions; then the mass or atom number in each unit slice (or cuboid in 2D case) is calculated; if there are multiple frames, average the mass or atom number by the frame number; finally, density in each unit is divided by the slice volume to get the density. Additional comments including restrictions and unusual features: The code must be run with VMD as a platform, the current version only can only calculate mass or number density. The code can calculate both 1D and 2D density distributions in any specified local or global areas of the system.

Original languageEnglish
Article number108032
Number of pages8
JournalComputer Physics Communications
Publication statusPublished - Sept 2021
Externally publishedYes


  • 1D and 2D projections
  • Density distribution
  • Molecular dynamics
  • VMD

Cite this