Visualization of Charge Density

by M. Arai (arai.masao [at]

** Caution **

This tiny script was created more than 15 years ago when WIEN2k was not able to create 3D charge densities directly. With current version of WIEN2k, 3ddens can create 3D densities. So, you don't need to use this script.


I made a small python script "" to visualize charge densities obtained by WIEN2k. It generates input data for VENUS and VESTA.

The WIEN2k includes the program "lapw5" which can generate charge densities on two-dimensional planes. The script "" executes "lapw5" automatically on different planes and collects output data into an input file for
the VENUS program.



Save the as "" and executes following command;
   % chmod +x
You must put "" in a directory included in PATH.


After you finish the SCF calculation by WIEN2k, you must execute following command in the directory with case.struct and case.clmsum.

    % 50 50 50

    % python 50 50 50

Command line options "50 50 50" indicate the numbers of grid points along conventional primitive vectors.  change these number appropriately.

For other options, please see output of " -h"

ust mThe generates "case.rho3d" which can be used as an input file for VESTA. (For VENUS, you must rename case.rho3d to case.rho)

How does the script work?

It would be desirable to modify "lapw5" so that it can output three-dimensional charge densities. But it is beyond my ability. So, I make a python script "". The script makes three-dimensional charge densities by executing "lapw5" sequentially.

The generates input file "case.in5" and executes lapw5 on different two-dimensional planes. The input files and charge densities files are renamed to case.in5.0000, case.in5.0001, case.in5.0002, ..., and case.rho.0000, case.rho.0001, case.rho.0002 ...

After the series of executions finish, the charge densities in case.rho.* are collected into a file "case.rho" which can be used as a input file of VENUS. The case.in5.* and case.rho.* is removed. If you put "-p" option on command line, the intermediate files "case.rho.*" will be preserved.

Format of output file

The format of generated charge density file "case.rho" is as follows.

line 1 : keyword "cell" to indicate that the charge densities are generated for a conventional primitive cell.
line 2: lattice constatns a b c
line 3: lattice angle alpha, beta, gamma
line 4: number of grid points (npx, npy, npz), and a b c (same with first three data in line 2)
line 5- : charge densities with the format like
write(*,*) (((charge(i,j,k),k = 1, npz), j=1,npy,i=1,npx)



Bug fix for complex version. Coordinate transformation for trigonal rhombhedral case was updated. (Thanks to Dr. Martin Kroeker for providing a patch). Modification to run with Python3.


The "val" was not defined if no options are specified.


New option "-t" for trigonal(rhombhedral) lattice.


I would like to thank developers of WIEN2k and VENUS/VESTA for providing us such great programs. I thank Dr. Martin Kroeker for providing me command line interface to treat potnetial.


[1] WIEN2k: P. Blaha, K. Schwarz, G. K. H. Madsen, D. Kvasnicka and J. Luiz: WIEN2k, An Augumented Plane Wave + Local Orbitals Program for Calculating Crystal Properteis (Karlheinz Schwarz, Tech, Universitat Wien, Austria) 2001. ISBN 3-9501031-1-2.

[2] VESTA: a three-dimensional visualization system for electronic and structural analysis, K. Momma and F. Izumi, J. Appl. Crystallogr., 41 (2008) 653-658.