# Visualizing MD generated electron density cubes as trajectories

During an ab-inito MD simulation one can generate the electron density cube file which basically provides the electronic density data in a standard volumetric format as shown here. The file consists of a header which includes the atom information and the size as well as orientation of the volumetric data. This is followed by the volumetric data, one scalar per data element in 3D.

In case of a MD xyz trajectory, the file consists of xyz coordinates as snapshots with respect to time, which one can visualize using any common software like VMD or MOLDEN. One can save multiple fragments of the trajectory, concatenating or pruning them for relevant atoms. So my question is there a way to visualize a series of electronic density cubes same way as an MD xyz trajectory?

I am looking for open-source software solutions with which this might be possible to do so, for ex: Jmol. I understand that one might need to preset isosurfaces and visualization settings and might need to have low resolution cube files for this task, but does anyone here have any experience in dealing with this issue or have any ideas about it?

## 1 Answer

Jmol is completely capable to do what you want. It reads cube file format and works with scripts. Take a look at this link related to making movies.

The idea is:

1. Your filenames must consist of a combination of text and a sequence of ordered numbers (e.g. myfiles_0001.cube, myfiles_0002.cube, etc.),
2. Make a loop, and inside it:
3. Load each file,
4. Plot the property you want,
5. Export as an image (JPG, PNG),
6. Combine the images in order to create the film.

In each step you are in control of:

• the quality of the property been plotted,
• the quality of the exported image,
• the quality of the movie created.

Here is an example I used with MOPAC. In this case, the files have a root name (test_) together with the number representing each step of my simulation (going from 1 to 999). In my case, the file with the property information is in MGF format:

#!/bin/bash
clear

name_root="test_"
for i in {1..999}
do
echo $$i fname_in="$$name_root$$i.mgf" fname_out="$$name_root$$i.jpg" jmol$$fname_in --nosplash --silent --nodisplay --script MEP_export -q85 --write JPG:\$fname_out
done

convert -limit memory 0 -limit map 0 *.jpg movie.gif
convert -limit memory 0 -limit map 0 *.jpg movie.mpg


The code --script MEP_export calls the MEP export options used by Jmol to generate the electrostatic potential:

color background white
axes
rotate y 45
isosurface resolution 6 solvent map mep translucent;


Here is another (more compact) script with the same idea (this script is for Jmol)

fname = "test_1.mgf";
nFrames = 100;
thisFrame = 0;
width = 640;
height = 480;

background white;

message loop;
load @fname;
isosurface resolution 6 solvent map mep translucent;
refresh;
write image @width @height @fileName;
thisFrame = thisFrame + 1;
fname = name.replace("1","" + (thisFrame)[-4][0]);

if (thisFrame < nFrames);goto loop;endif;


A final GIF:

• Thanks for your answer! If possible can you link to a possible documentation or any other relevant links for Jmol? I am unable to render electron density using your scripts and I couldn't find any proper documentation for Jmol for electron density render.
– mykd
Dec 11 '20 at 2:45