AttributeError: module 'pymatgen' has no attribute 'Element'

I have installed jupyter notebook and pymatgen in conda environment. While running the following codes on jupyter notebook I got the error mentioned below:

#########Code:##########
for item in elements:
data_youngs_modulus.append(pymat.Element(item).youngs_modulus)

#########Error##########
AttributeError Traceback (most recent call last)
Input In [12], in
28 data_CTE = []
30 for item in elements:
—> 31 data_youngs_modulus.append(pymat.Element(item).youngs_modulus)
32 data_lattice_constant.append(mendel.element(item).lattice_constant)
33 data_melting_point.append(mendel.element(item).melting_point)

AttributeError: module ‘pymatgen’ has no attribute ‘Element’

Hello,
I would guess that at the beginning of your file, you have
import pymatgen as pymat

However, typing pymat.Element only looks one level down from the top of the Pymatgen hierarchy, so it does not find Element. You will have to do something like

from pymatgen.core.periodic_table import Element

at the start, and then you can just do

data_youngs_modulus.append(Element(item).youngs_modulus)

because now the Python interpreter will know which Element you are talking about. It might help to look up a few Pymatgen example scripts on the internet, they will show how to use imports correctly.

1 Like

Thanks Steven Hartman, it works. Can you please share few basic pymatgen examples/tutorials links (or video lectures if available) ??

Here’s an example of using Pymatgen to plot electronic properties.
http://home.ustc.edu.cn/~lipai/scripts/vasp_scripts/python_plot_dos_band.html

and a lot of the PyCDT code also used Pymatgen to do basic data management tasks.

Hi @erneelgupta,

Videos from the 2021 Materials Project Workshop are available on youtube. Here is one of the lessons on pymatgen: