Page 1 of 1

CHGCAR file

Posted: Wed Sep 14, 2016 3:49 pm
by rinochek
Hello all,
I know that question was disscussed several times.
I would like to make a modification in CHGCAR file based on the simulations from other method.
I need to understand how charge density is written.
If I have NGX, NGY, NGZ - 52 112 64
Does it mean that first 36 lines will be related to charge density at NGY from 1 to 112 and NGZ from 1 to 64, where NGX=1?
And then the same with NGY=1 and NGZ=1.
Did I understand it correctly?


Thank you!

Re: CHGCAR file

Posted: Wed Sep 14, 2016 5:05 pm
by graeme
Here is the description from the vasp guys:

In VASP, the density is written using the following commands in Fortran:

WRITE(IU,FORM) (((C(NX,NY,NZ),NX=1,NGXC),NY=1,NGYZ),NZ=1,NGZC)

The x index is the fastest index, and the z index the slowest index. The file can be read format-free, because at least in new versions, it is guaranteed that spaces separate each number. Please do not forget to divide by the volume before visualizing the file!

Re: CHGCAR file

Posted: Thu Sep 15, 2016 11:28 am
by rinochek
Thank you, but I did not fully understand this description.
Could you explain what is C(NX,NY,NZ)?

Thank you very much!

Re: CHGCAR file

Posted: Thu Sep 15, 2016 11:59 am
by graeme
C(NX,NY,NZ) is a 3d fortran array containing the charge density values C at points NX,NY,NZ

Re: CHGCAR file

Posted: Tue Sep 20, 2016 12:04 pm
by rinochek
Thank you very much!

Re: CHGCAR file

Posted: Tue Jun 22, 2021 7:33 am
by pranoy
May I ask what is the pattern in which the data is stored? I understand that it is a 3D Fortran array but why are there 5 columns wrt NX, NY and NZ? Shouldn't there be 3 columns? What are the 2 extra columns for? I know this might be a dumb question, but I request you to please help me with it.

Also, is there any definite methodology to better understand the data we get in a CHGCAR file? I know that Vesta helps us visualize the electron clouds present, but is there any way to better process the 5-column data we get in a CHGCAR file for compact handling and eventually better understanding? For example, I have a CHGCAR file on a 64x64x64 grid. But it is a 5 column dataset as shown in the attached picture. Is there any other way to convert this data into a 3D Matrix of shape (64,64,64)?

Re: CHGCAR file

Posted: Tue Jun 22, 2021 3:48 pm
by graeme
If you look at my previous posts in the thread, you can see the format by which this data is written. It is a 64x64x64 data set written with 5 values per line. You could make a 64x64x64 array and read the values back in using the same type of format statement. But generally we read this data into a program such as vesta and visualize the change density, or process it with a program like the bader charge analysis to see how much charge there is on each atom.

Re: CHGCAR file

Posted: Tue Jun 22, 2021 7:10 pm
by pranoy
Thank you for your reply. That info was very beneficial. But how does VESTA rearrange the data for visualization? I am just trying to understand the ground reality of post processing the CHGCAR data, and will be personally looking for methods to improve it.

Re: CHGCAR file

Posted: Tue Jun 22, 2021 7:21 pm
by graeme
There is no post process or rearranging. A statement such as:

READ(IU,FORM) (((C(NX,NY,NZ),NX=1,NGXC),NY=1,NGYZ),NZ=1,NGZC)

will load all the data into the 64x64x64 array C.

Vesta will show either isosurfaces of the data or contour plot slices through the dataset.