hello everyone, here is the code, idk how to use new API to do such things, and I didn’t find the way to solve it in the doc.
I want to get lattice constant, atomic radius, atomic number for several elements.
could you help me to find the errors? thx!!!
from mp_api.client import MPRester
from pymatgen.core.periodic_table import Element
import pandas as pd
api_key = "xxx"
elements = [
"Cs", "Rb", "K", "Ba", "Sr", "Eu", "Yb", "Ca", "La", "Na",
"Sm", "Nd", "Pr", "Ho", "Li", "Er", "Tm", "Gd", "Ce", "Tb",
"Dy", "Y", "Lu", "Sc", "Ti", "Hf", "Mg", "Zr", "In", "Ga",
"Zn", "Al", "Bi", "Sn", "V", "Cr", "Mo", "Nb", "Ta", "Sb",
"Fe", "Mn", "Ge", "As", "W", "Te", "Co", "Cu", "B", "Si",
"Be", "Ni", "O"
]
mpr = MPRester(api_key)
lattice_constants = []
atomic_radii = []
atomic_numbers = []
for element in elements:
result = mpr.summary.search(chemsys= element, properties= structure)
structure = result[0]["structure"]
lattice_constants.append(structure.lattice.a)
element_obj = Element(element)
atomic_radii.append(element_obj.atomic_radius)
atomic_numbers.append(element_obj.atomic_number)
df = pd.DataFrame({
"Element": elements,
"Lattice Constants": lattice_constants,
"Atomic Radii": atomic_radii,
"Atomic Numbers": atomic_numbers
})
df.head()
csv_file_path = 'materials_data_with_properties.csv'
df.to_csv(csv_file_path, index=False)
print(f'Data with lattice constants, atomic radii, and atomic numbers saved to {csv_file_path}')