Since we do not have all the files specific to your calculation such as the INCAR, POTCAR, POSCAR, KPQINTS and vaspout.h5, I will demonstrate how to save a viewer3d structure to a PNG image using a sample viewer3d structure.
From py4vasp source code, we can see that the viewer is a: NGLWidget
All the following code are written on a Google Colab notebook:
from google.colab import output
output.enable_custom_widget_manager()
import nglview as nv
import ipywidgets as w
import time
import threading
from pathlib import Path
view = nv.demo()
view
type(view)
>> nglview.widget.NGLWidget # This matches with what we get from py4vasp
The viewer3d structure looks like this:
The following code saves the viewer3d as a PNG image.
output_path = "/content/drive/MyDrive/output/img.png"
def save_image(view):
img = view.render_image()
while not img.value:
time.sleep(0.1)
with open(output_path, "wb") as f:
f.write(img.value)
Path(output_path).unlink(missing_ok=True)
thread = threading.Thread(target=save_image, args=(view, ), daemon=False)
thread.start()
The PNG image is now saved at the output path.
calc = Calculation.from_path(".")
$\endgroup$