Hello world,
I preface by indicating that I am not a computational scientist, and have a bare minimum Python literacy (enough to be dangerous, I suppose …).
I am hoping to query from mp-api the CHGCAR charge density files for a small number of archetypical structures for educational purposes (i.e., creating my own charge density contour maps, etc.), and am getting stuck figuring out how to properly write the objects in a format suitable for visualization in VESTA.
I am able to query the database using code provided by users on this forum, but cannot use pickle to dump the file to a readable format. Here is my code:
from mp_api.client import MPRester
with MPRester("<my key is here>", monty_decode=False) as mpr:
chgcar, task_doc = mpr.get_charge_density_from_material_id("mp-149", inc_task_doc=True)
poscar = task_doc.orig_inputs.poscar
import pickle
fileObj = open('CHGCAR_mp-149.vasp', 'wb')
pickle.dump(chgcar,fileObj)
fileObj.close()
The resulting file ‘CHGCAR_mp-149.vasp’ is written to my home directory (3381 kb in present case), but is not able to be read by VESTA or any other visualization software. I suspect the issue is not with VESTA, but rather in the formatting for the object output. My understanding is that pickle simply outputs a single long string, which is probably not what I want.
I cannot seem to find anything in the documentation to guide me as to what to do with the data object sitting in my workspace once it has been pulled via api. Any helpful tips would be most appreciated!
Thanks,
Dave