Page 1 of 1

CHGCAR unit?

Posted: Mon Nov 06, 2006 1:31 am
by bandy
I am curious to know what is the unit of charges written out
in CHGCAR file. For e.g. for bcc Fe CHGCAR,
-------------------
bcc Fe
10.0000000000000000
1.000000 .000000 .000000
.000000 1.000000 .000000
.000000 .000000 1.000000
1 1
Direct
.000000 .000000 .057102
.000000 .000000 .942898

84 84 84
.41098271954E+04 .38580593547E+04 .32056173636E+04 .23907855172E+04 .16323134731E+04
.10440737881E+04 .64952106325E+03 .40394464342E+03 .25149651632E+03 .15428370958E+03
.92653834837E+02 .55483939720E+02 .34042823873E+02 .21474147940E+02 .13548327933E+02
……….
-------------------------------------------
after NGXF, NGYF, NGZF(84x84x84) what is the unit of the value .41098271954E+04? If it is in e(electron), then if we sum up
all charges at each 3D grid point, the number becomes huge, many times the nu,ber of electrons in the system.

Thanks for any help

CHGCAR unit?

Posted: Mon Nov 06, 2006 8:46 pm
by Danny
It contains the density times the Volume so you need to devide those values by the volume(in your case that is 1000A³)

VASP manual 2005-->CHGCAR file

Danny 8)
<span class='smallblacktext'>[ Edited Mon Nov 06 2006, 09:49PM ]</span>

CHGCAR unit?

Posted: Tue Nov 07, 2006 12:34 am
by bandy
Hi Danny, Thanks.

But I am sorry still it is not clear to me.
charge density(r) * Vcell is CHGCAR. Then it is charge at position r i.e. charge(r). Then if I sum all charges at all r(all space over the 3D grid) I should get Total charge in the system. Am I not right?

CHGCAR unit?

Posted: Tue Nov 07, 2006 9:49 am
by Danny
yes that should do the trick(unless I misinterpreted what the meant by Volume...if so please let me know)

Danny

CHGCAR unit?

Posted: Tue Nov 07, 2006 12:26 pm
by Danny
Ok i did a quick check on one of my calculations and it seems like what you get are actually the charges inside a gridcube of your system.

so in your case you have a total volume of 1000A^ 3 and 592704 gridpoints(or gridcubes) so each gridcube has a volume: 1.687e-3 A^3.

Multiplying the values of your charges with this you can sum them and find the total charge.

If you would write this out entirely you'll see that the volume the actually use seems to be the number of gridcells (ie: I misinterpreted) so the easy way of doing it is just divide the values you find in the CHGCAR file by the total number of gridpoints. Then you can sum over all of them and find the correct charge.
(If you want chargedensity in realspace(ie cubic Angstrom) you'll need to convert them)

Hmm I hope this was somewhat clear?
(I reread this post once more it isn't really clear)
Conclusion:
Vgrid=NGX*NGY*NGZ (ie the 3 integers you find above the set of "chargevalues" in CHGCAR)
in your case Vgrid=592704
Vreal=x*y*z (realspace volume in A³)
in your case Vreal=1000A³

If you want the exact chargedensity at a point:
--> divide the values of the CHGCAR file by Vreal.
the values you get should be in (e/A³)

integrating over your grid will give you the total charge inside your cell, be carefull this is not just summing over your gridpoints

If you want the exact charge at a point:
(ie: the charge in a gridcube)
---> divide the values of the CHGCAR by Vgrid.
If you sum these values over the entire grid you will get the total charge.


Danny
%-6
<span class='smallblacktext'>[ Edited Tue Nov 07 2006, 07:46PM ]</span>

CHGCAR unit?

Posted: Wed Nov 08, 2006 2:54 am
by bandy
Thanks Danny for your reply.

I am better in understanding about CHGCAR, but not fully.
According to you, elements chgcar(i,j,k), when
divided by Vreal, then integrated over all real space will give
total charge; similarly chgcar(i,j,k) elements divided by Vgrid and then summed to give total charge.

Would it be possible for anybody in the forum including Danny to send a complete simple example to my email address. indra1966in@yahoo.co.in

Thanks a lot,

CHGCAR unit?

Posted: Fri Nov 10, 2006 12:02 am
by bandy
Hi Danny, I am willing to send complete CHGCAR file via email.
Would it be possibe to find total charge from that using your
utility program? Thanks alot

CHGCAR unit?

Posted: Fri Nov 10, 2006 12:46 am
by Danny
As it is my code doesn't give you the entire charge(the best I can do is give you a contourplot of a specific plane of the planeaveraged valus along a line.

I do not know which programming language you use but if you want to calculate the total charge you could use following algo(some pseudo fortran)

Code: Select all

integer :: nr,nrx,nry,nrz,maxx,maxy,maxz,maxatom
single ::totC, x,y,z, lx,ly,lz,vol,scale
character(len=255) :: line
single,allocatable ::CHgrid(:,:,:) ! dynamic 3D matrix

open(unit=100,file='CHGCAR',action='read')
read(10,*)str !reads title string
read(10,*) scale 
read(10,*) x,y,z
lx= sqrt(x*x + y*y + z*z)
read(10,*) x,y,z
ly= sqrt(x*x + y*y + z*z)
read(10,*) x,y,z
lz= sqrt(x*x + y*y + z*z)
vol=lx*ly*lz*scale*scale*scale


read(10,'(A255)')str
getatmnr(str,maxatom) !subroutine to transform this string to 1 number
do nr=0,maxatom ! read the line with direct or cartesian + the list of atomcoordinates
    read(10,*)str
end do
! the next empty line does not exsist for FORTRAN, you need to check if it exsists if you use a different language --> eg PASCAL will probably find a line
read(10,*) maxx,maxy,maxz
totC=0.0

allocate(CHGrid(0:maxx,0:maxy,0:maxz))
read(10,*) (((CHGrid(nrx,nry,nrz),nrx=0,maxx-1),nry=0,maxy-1),nrz=0,maxz-1) !this reads the entire dataset of charges.

do nrx=0, maxx-1
   do nry=0,maxy-1
      do nrz=0,maxz-1
      totC=totC+CHgrid(nrx,nry,nrz) 
     end do
   end do
end do

write(*,*) 'The volume of the cell is: ', Vol
write(*,*) 'The total chargedensity*Volume=', totC
write(*,*) 'The total charge=', totC/(maxx*maxy*maxz)



this is a subroutine whish is very handy to get the total number of atoms without need for another file

Code: Select all

subroutine get_atomnr(line,atomnr) 
             character(len=255),intent(IN):: line 
             integer,intent(OUT) ::atomnr 
  
       integer :: ios,nratoms,atnr,atnrpos 
       character(len=255):: line2,atl 
  
       !a little bit more complex...read it as a line and sum till it crashes 
       ios=0 
       nratoms=0 
       line2=line 
       do while (ios==0) 
             read(line2,*,IOSTAT=ios) atnr 
             if (ios==0) then 
                  nratoms=nratoms+atnr 
                  write(atl,*) atnr 
                  atl=ADJUSTL(atl)!remove leading blanks 
                  atnrpos=Index(line2,trim(atl))+len_trim(atl) 
                  line2=" " 
                  line2(atnrpos:255)=line(atnrpos:255) 
                  if (len_trim(line2)<=0) then 
                        ios=10 
                  end if 
             end if 
       end do 
       atomnr=nratoms 
  
       end subroutine 



this should give you the charge(should be the same as the number of (valence)electrons in your system)

let me know how it turns out ;) (it should work on the CHGCAR you posted in the first post.

greetings
Danny


<span class='smallblacktext'>[ Edited Fri Nov 10 2006, 01:50AM ]</span>

CHGCAR unit?

Posted: Fri Nov 10, 2006 5:31 am
by bandy
Danny, your code works perfectly fine for the CO molecule whose CHGCAR I gave here. Thanks a lot. This was ISPIN=1 case. Now I will check some ISPIN=2 cases and want to check alpha-beta CHGCAR part whether total charge comes out to be unpaired electrons i.e. N_e(alpha)-N_e(beta)=NUPDOWN. It works fine with ISPIN=2 cases too. Thanks.

Thanks a lot,



<span class='smallblacktext'>[ Edited Fri Nov 10 2006, 10:27AM ]</span>

CHGCAR unit?

Posted: Fri Nov 10, 2006 7:25 am
by Danny
Glad to hear this :D

CHGCAR unit?

Posted: Mon Nov 13, 2006 5:05 pm
by bandy
One more question. In some cases, I am getting say magnetization 2.71 for collinear calculation. How to explain this as magnetization (=n(alpha)-n(beta)) should be integers. Am I not right?