I used py4vasp to calculate structure from data and then I displayed them in a structure viewer (Viewer3d) by this line: calc.structure[:].plot(). It returns a visualization of the structures as a 3d figure.

How I can save this 3d figure?

Also, If I read the structural information into a dictionary by this: calc.structure[:].read(), how I can plot the structures?

Here is the code which I used in the Jupyter notebook:

from py4vasp import Calculation
calc = Calculation.from_path(".")
  • $\begingroup$ I gave my +1 long ago. Is this account also yours? Can we merge them so that your profile here is connected to the rest of your SE network profile? If you tried to remove the second part of the question, was that because you've solved that part and are still in need of an answer to the first part? $\endgroup$ Jan 23, 2023 at 1:19
  • $\begingroup$ @Aaryan Could you please add a link to a folder with all the necessary input files such as INCAR, POTCAR, POSCAR, KPQINTS and output file : vaspout.h5 ? These files are required to run the line : calc = Calculation.from_path(".") $\endgroup$ Feb 23, 2023 at 19:08

1 Answer 1


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

import nglview as nv
import ipywidgets as w
import time
import threading
from pathlib import Path
view = nv.demo()

>> nglview.widget.NGLWidget # This matches with what we get from py4vasp

The viewer3d structure looks like this:

enter image description here

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:
    with open(output_path, "wb") as f:


thread = threading.Thread(target=save_image, args=(view, ), daemon=False)


The PNG image is now saved at the output path.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .