materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.51k stars 863 forks source link

Possible bug in Chgcar.write_file() #709

Closed mkhorton closed 7 years ago

mkhorton commented 7 years ago

System

Summary

Reading a CHGCAR and then writing that same CHGCAR results in a CHGCAR that can not be read by VASP.

Example code

Tested with an MPStaticSet and mpr.get_structures('NaCl')[0] as the input structure, vasp.5.4.1

Error message

CHGCAR reading fails with error:

RD_RHO_PAW: ion           1 data corrupt
 WARNING: PAW occupancies are missing on CHGCAR

Suggested solution (if any)

It looks like this information is missing from the end (and middle) of the CHGCAR:

augmentation occupancies   1  33
  0.2512469E-04  0.2601868E-21  0.1316082E-11 -0.3207091E-12  0.1861221E-11
 -0.1679365E-11  0.5137741E-04  0.5645359E-21  0.2691253E-11 -0.6558170E-12
[...]
augmentation occupancies   2  33
  0.6668695E-04 -0.1982265E-02  0.0000000E+00  0.0000000E+00  0.0000000E+00
  0.0000000E+00  0.0000000E+00  0.0000000E+00  0.1180570E-02  0.0000000E+00
[...]

However, manually adding this information to the pymatgen-generated file results in VASP getting stuck on reading the CHGCAR with this message:

magnetization density of overlapping atoms calculated

Not sure what's going on here, but we should fix it to make sure write_file does actually produce a VASP-readable CHGCAR.

shyuep commented 7 years ago

It is rare you want to write a Chgcar for VASP reading. The purpose of writefile is to generate volumetric data for reading by VESTA.

mkhorton commented 7 years ago

Admittedly a rare issue, but I encountered this today (it's a bit off-topic for this bug report, but I'm trying to find a suitable smaller file format so we can visualize CHGCARs interactively on the web, and was trying conversions to/from this alternative format to see how bad the information loss was, when I realized that even just loading/writing a Chgcar with no changes with pymatgen wasn't working).

mkhorton commented 7 years ago

Though the good news with the compression is that I'm getting compressed Chgcars of the order of 50-150 kB (100-1000x compression ratio), which will be more than good enough for visualization purposes. I very much doubt they'll be good enough for VASP inputs though but I was curious to try.

shyuep commented 7 years ago

What kind of compression? Honestly, if you want to compress CHGCARs, the easiest way is to reduce res. E.g., if you have a 40x40x40 resolution CHGCAR, you coarse grain it to 20x20x20. That will immediately gain 7/8 reduction.

mkhorton commented 7 years ago

Well, I was trying to find a format that would already work with NGL Viewer (or 3Dmol/JSmol etc.) to save any additional development time -- the author of NGL recommended an 8 bit per voxel binary format, which would be fine, ~ 1/2 MB or so, though we do lose a lot of information.



The problem with coarse-graining and visualization is that you already have to do interpolation/smoothing to construct a smooth iso-surface, and throwing away spatial resolution makes that a lot worse -- purely for visualization purposes, I think spatial resolution is more important, and voxel bit depth less so.