Wednesday, May 11, 2016

OCTAVE: read/write VASP POSCAR, CHGCAR

Here you can find several functions that will help you to read and write VASP POSCAR and CHCAR files in Octave. The files are commented and fairly easy to understand. Current version of the read_POSCAR handles the old and the new POSCAR  format (the new format contains labels for the species). All gathered information is stored in one object "Structure". This makes extremely easy the addition of any new properties. Note hat it read_CHGCAR reads only the total density. If you need the difference, please change the code or the data.

Test example:
#!/usr/bin/octave -q

# Read CHGCAR file
Struct = read_CHGCAR("CHGCAR");

# Print all gathered values
Struct

# Do something
# Struct.Dens=circshift(Struct.Dens,[0 0 20]);

# Write the new Density
write_CHGCAR("CHGCAR-new",Struct);


The function that reads the CHGCAR calls read_POSCAR and uses the same file stream "fid", so if you only want to read the POSACR you have to close the "fid":

[Structure,fid]= read_POSCAR(filename);
fclose(fid);

If you read the CHGCAR be calling read_CHGCAR as in the example at the top of the page, you will get the data in the Structure object as this:

Struct.Dens       Struct.coordsys   Struct.label      Struct.ny         Struct.scale
Struct.Ntypes     Struct.flags      Struct.nat        Struct.nz         Struct.typesN
Struct.Vol        Struct.h          Struct.nx         Struct.positions  Struct.ver


Here is a list of the functions that could be called:
function [Structure,fid]= read_POSCAR(filename)
function [Structure]= read_CHGCAR(filename)

function fid = write_POSCAR(filename,Structure)
function write_CHGCAR(filename,Structure)
function write_PARCHG(filename,Structure)

Add the files in your project folder in order to use them. octave-vasp.tgz

No comments:

Post a Comment