Pymatgen - how to visualize a crystal structure?

Hi,

I have been trying to visualize a crystal structure obtained from ICSD database (cif file) using
pymatgen.vis.structure_vtk.StructureVis

Following is my code snippet.

from pymatgen.vis.structure_vtk import StructureVis
from pymatgen import Lattice, Structure

structure = Structure.from_file('cif/ICSD_CollCode54150.cif')
vis = StructureVis(structure)
vis.show()

However, this opens up an empty window. Alternatively, I have tried to visualize the structure as follows, but still getting an empty window. I have the VTK package installed.

lattice = mg.Lattice.cubic(4.2)
comp = mg.Composition("Fe2O3")

structure = Structure(lattice, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
vis = StructureVis(structure)
vis.show()

Am I doing something wrong or is visualization not supported at the moment?

Thanks in advance!

Hi @Achintha,

Yes, viewing via “structure_vtk” is deprecated, we’ll be announcing a replacement shortly which includes inline viewing inside a Jupyter notebook.

For now, a quick solution is to us structure.to(filename="my_structure.json"), and drag and drop it into Crystal Toolkit. The advantage of Crystal Toolkit is that you can use pymatgen’s in-built bonding algorithms etc. to view your structure exactly as pymatgen understands it.

You can also drag-and-drop a CIF file directly into Crystal Toolkit over the “Load a file from your computer” box.

The new Crystal Toolkit is still under active development.

Best,

Matt

1 Like