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

The Crystal Toolkit looks amazing! Are there any updates integrating it with jupyter notebooks?

Hi Tian, good to see you here!

Yes, it should work now! pip install crystal-toolkit should be sufficient as long as you’re on JupyterLab 3.x+, but please let me know if you run into issues–we did have a bug recently where a blank box was shown rather than the crystal structure but this should have been fixed.

There are also some minimal docs here, the most important thing is that you need to import crystal_toolkit in your notebook to enable the functionality, and then you can return e.g. a Structure object from a cell to visualize it. The get_scene() methods allow more advanced customization.

Hope this helps :slight_smile:

Best,

Matt

Hi Matt,

I tried what you said in your post, but I just see a bunch of blank space under my cell when I either have structure or structure.get_scene() in my jupyterlab cell.

Hi @salil91, is version 0.6.0 or above of crystaltoolkit-extension installed? If yes, can you tell us if there are any error messages in your web browser’s JavaScript console? (If you don’t know how to do this, no worries, we will investigate further.)

So it looks like version 0.4.0 was installed when I ran pip install crystal-toolkit --upgrade last week. I updated to 0.6.0 now, and it works. Thank you!

I did get the following error, however:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
crystal-toolkit 2022.2.11.1 requires crystaltoolkit-extension<0.5.0,>=0.4.0, but you have crystaltoolkit-extension 0.6.0 which is incompatible.

Glad to hear it @salil91! And thanks, aware of that error, will have to push a new release to remove it but it’s otherwise harmless.

@mkhorton, can crystal-toolkit generate movie/gif from XDATCAR/vasprun.xml obtained from MD calculation?

Hi @thienbinh92,

Apologies for the slower response, it’s been a busy week. The short answer is not right now, but there are plans.

If you need to generate a movie for a MD calculation I can highly recommend OVITO. They also host their forum here on matsci.org, so you can ask them questions. This would be a good solution if you need something right away.

In the future, Crystal Toolkit does have some rudimentary support for animations, and we’re planning on adding the ability to add animated visualizations (eg for structural relaxations, phonon vibrations, etc. to the MP website). However, Crystal Toolkit really has smaller system sizes in mind in its design, so might be a good solution for AIMD but not for larger classical MD visualizations.

Hope this helps!

Matt

Dear Sir,

I calculate ionconductivity of Li3InCl6 from AIMD simulation
I am running VASP by input file “INCAR”, KPOINT", POSCAR, “POSCAR”. After run VASP, I got vasprun.xml, XDATCAR, and other outcar files
so, how can I create MSD-t and arrhenius plot from vasprun.xml file by pymatgen code,

Thank you so much for helping!

Thread closed due to inactivity, please open a new thread to address related issues.