Keyerror in EspressoProfile

Hello ase developers and users

I wanted to do a calculatin via quantum espresso and ase and to do this I have used the below command :

from ase.calculators.espresso import Espresso,EspressoProfile
calc=Espresso(profile=EspressoProfile(“mpirun -np 2 pw.x” ,pseudo_dir))

I have Pb species in my pseudopotentials and I faced the keyError:‘Pb’
Could you please guide me to solve the problem?

This is the complete error massage:

KeyError Traceback (most recent call last)
Cell In[10], line 7
5 sc = StructureContainer(cs)
6 rattled_structures = generate_rattled_structures(supercell, 1, 0.05)
----> 7 rattled_structures = prepare_structures(rattled_structures, supercell, calc)
9 for structure in rattled_structures:
10 sc.add_structure(structure)

File ~/.local/lib/python3.10/site-packages/hiphive/utilities.py:180, in prepare_structures(structures, atoms_ideal, calc, check_permutation)
133 def prepare_structures(structures: List[Atoms],
134 atoms_ideal: Atoms,
135 calc: SinglePointCalculator = None,
136 check_permutation: bool = True) → List[Atoms]:
137 “”“Prepares a set of structures in the format suitable for adding them to
138 a :class:StructureContainer <hiphive.StructureContainer>.
139
(…)
178 list of prepared structures with forces and displacements as arrays
179 “””
→ 180 return [prepare_structure(s, atoms_ideal, calc, check_permutation) for s in structures]

File ~/.local/lib/python3.10/site-packages/hiphive/utilities.py:180, in (.0)
133 def prepare_structures(structures: List[Atoms],
134 atoms_ideal: Atoms,
135 calc: SinglePointCalculator = None,
136 check_permutation: bool = True) → List[Atoms]:
137 “”“Prepares a set of structures in the format suitable for adding them to
138 a :class:StructureContainer <hiphive.StructureContainer>.
139
(…)
178 list of prepared structures with forces and displacements as arrays
179 “””
→ 180 return [prepare_structure(s, atoms_ideal, calc, check_permutation) for s in structures]

File ~/.local/lib/python3.10/site-packages/hiphive/utilities.py:116, in prepare_structure(atoms, atoms_ideal, calc, check_permutation)
92 “”“Prepare a structure in the format suitable for a
93 :class:StructureContainer <hiphive.StructureContainer>.
94
(…)
113 prepared ASE atoms object with forces and displacements as arrays
114 “””
115 # get forces
→ 116 forces = _get_forces_from_atoms(atoms, calc=calc)
118 # setup new atoms
119 if check_permutation:

File ~/.local/lib/python3.10/site-packages/hiphive/utilities.py:63, in _get_forces_from_atoms(atoms, calc)
61 atoms_tmp = atoms.copy()
62 atoms_tmp.calc = calc
—> 63 forces_calc = atoms_tmp.get_forces()
64 if ‘forces’ in atoms.arrays:
65 if not np.allclose(forces_calc, atoms.get_array(‘forces’)):

File ~/.local/lib/python3.10/site-packages/ase/atoms.py:812, in Atoms.get_forces(self, apply_constraint, md)
810 if self._calc is None:
811 raise RuntimeError(‘Atoms object has no calculator.’)
→ 812 forces = self._calc.get_forces(self)
814 if apply_constraint:
815 # We need a special md flag here because for MD we want
816 # to skip real constraints but include special “constraints”
817 # Like Hookean.
818 for constraint in self.constraints:

File ~/.local/lib/python3.10/site-packages/ase/calculators/abc.py:30, in GetPropertiesMixin.get_forces(self, atoms)
29 def get_forces(self, atoms=None):
—> 30 return self.get_property(‘forces’, atoms)

File ~/.local/lib/python3.10/site-packages/ase/calculators/calculator.py:538, in BaseCalculator.get_property(self, name, atoms, allow_calculation)
535 if self.use_cache:
536 self.atoms = atoms.copy()
→ 538 self.calculate(atoms, [name], system_changes)
540 if name not in self.results:
541 # For some reason the calculator was not able to do what we want,
542 # and that is OK.
543 raise PropertyNotImplementedError(
544 '{} not present in this ’ ‘calculation’.format(name)
545 )

File ~/.local/lib/python3.10/site-packages/ase/calculators/genericfileio.py:385, in GenericFileIOCalculator.calculate(self, atoms, properties, system_changes)
384 def calculate(self, atoms, properties, system_changes):
→ 385 self.write_inputfiles(atoms, properties)
386 self.template.execute(self.directory, self.profile)
387 self.results = self.template.read_results(self.directory)

File ~/.local/lib/python3.10/site-packages/ase/calculators/genericfileio.py:376, in GenericFileIOCalculator.write_inputfiles(self, atoms, properties)
372 def write_inputfiles(self, atoms, properties):
373 # SocketIOCalculators like to write inputfiles
374 # without calculating.
375 self.directory.mkdir(exist_ok=True, parents=True)
→ 376 self.template.write_input(
377 profile=self.profile,
378 atoms=atoms,
379 parameters=self.parameters,
380 properties=properties,
381 directory=self.directory,
382 )

File ~/.local/lib/python3.10/site-packages/ase/calculators/espresso.py:80, in EspressoTemplate.write_input(self, profile, directory, atoms, parameters, properties)
76 input_data[“control”].setdefault(“pseudo_dir”, str(profile.pseudo_dir))
78 parameters[“input_data”] = input_data
—> 80 write(
81 dst,
82 atoms,
83 format=‘espresso-in’,
84 properties=properties,
85 **parameters,
86 )

File ~/.local/lib/python3.10/site-packages/ase/io/formats.py:693, in write(filename, images, format, parallel, append, **kwargs)
689 format = format or ‘json’ # default is json
691 io = get_ioformat(format)
→ 693 return _write(filename, fd, format, io, images,
694 parallel=parallel, append=append, **kwargs)

File ~/.local/lib/python3.10/site-packages/ase/parallel.py:271, in parallel_function..new_func(*args, **kwargs)
265 @functools.wraps(func)
266 def new_func(*args, **kwargs):
267 if (world.size == 1 or
268 args and getattr(args[0], ‘serial’, False) or
269 not kwargs.pop(‘parallel’, True)):
270 # Disable:
→ 271 return func(*args, **kwargs)
273 ex = None
274 result = None

File ~/.local/lib/python3.10/site-packages/ase/io/formats.py:729, in _write(filename, fd, format, io, images, parallel, append, **kwargs)
726 fd = open_with_compression(filename, mode)
727 # XXX remember to re-enable compressed open
728 # fd = io.open(filename, mode)
→ 729 return io.write(fd, images, **kwargs)
730 finally:
731 if open_new and fd is not None:

File ~/.local/lib/python3.10/site-packages/ase/io/formats.py:194, in IOFormat._write_wrapper(self, *args, **kwargs)
192 if function is None:
193 raise ValueError(f’Cannot write to {self.name}-format’)
→ 194 return function(*args, **kwargs)

File ~/.local/lib/python3.10/site-packages/ase/utils/init.py:577, in iofunction.call..iofunc(file, *args, **kwargs)
575 else:
576 fd = file
→ 577 obj = func(fd, *args, **kwargs)
578 return obj
579 finally:

File ~/.local/lib/python3.10/site-packages/ase/io/espresso.py:1297, in write_espresso_in(fd, atoms, input_data, pseudopotentials, kspacing, kpts, koffset, crystal_coordinates, additional_cards, **kwargs)
1293 species_info = {}
1294 for species in set(atoms.get_chemical_symbols()):
1295 # Look in all possible locations for the pseudos and try to figure
1296 # out the number of valence electrons
→ 1297 pseudo = pseudopotentials[species]
1298 species_info[species] = {‘pseudo’: pseudo}
1300 # Convert atoms into species.
1301 # Each different magnetic moment needs to be a separate type even with
1302 # the same pseudopotential (e.g. an up and a down for AFM).
1303 # if any magmom are > 0 or nspin == 2 then use species labels.
1304 # Rememeber: magnetisation uses 1 based indexes

KeyError: ‘Pb’

coulde you please show me how to solve the problem?

I think you need to use the pseudopotentials=... parameter to provide a dictionary that selects the exact pseudopotential files.
This is shown in the docs for the Espresso Calculator: Espresso — ASE documentation

Thanks. Using the examples and changing the parameters form in command helped me.