SMTG-Bham / ShakeNBreak

Defect structure-searching employing chemically-guided bond distortions
https://shakenbreak.readthedocs.io
MIT License
84 stars 18 forks source link

[Solved] write_epsresso_files not working #79

Closed Walser52 closed 1 month ago

Walser52 commented 1 month ago

Edit: Solved. Apparently pip install was downloading a lower version. Creating a new conda environment and updating to the latest snb version solved the issue.


I'm following the Defects Generation tutorial for doped which uses shakenbreak. I want to generate espresso files.

Steps to Reproduce

from pymatgen.core.structure import Structure
from doped.generation import DefectsGenerator
from ase.calculators.espresso import EspressoProfile
from shakenbreak.input import Distortions

struct = Structure.from_file('../../_data/cif/CsPbBr3.cif')
defect_gen = DefectsGenerator(struct)

Dist = Distortions(defect_entries = defect_gen) 

defects_dict, distortion_metadata = Dist.write_espresso_files(#pseudopotentials = {"Br": "Br.UPF", "Cs": "Cs.UPF", "Pb": "Pb.UPF"},
                                                              output_path = '../../_out/distort/', 
                                                              # profile = EspressoProfile(command="pw.x", pseudo_dir="."),
                                                              #write_structures_only = True
                                                             )

snb passes this to ase. As per the documentation, pseudopotentials are optional. But this as it is led to:


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

Attempts at Solution I managed to bypass that by giving a dictionary of pseudopotentials but then ran into a profile error:

File ~/anaconda3/envs/py38mats/lib/python3.8/site-packages/ase/calculators/genericfileio.py:274, in GenericFileIOCalculator.__init__(self, template, profile, directory, parameters)
    272 if profile is None:
    273     if template.name not in self.cfg.parser:
--> 274         raise BadConfiguration(f'No configuration of {template.name}')
    275     try:
    276         profile = template.load_profile(self.cfg)

BadConfiguration: No configuration of espresso

Apparently this is a newer ase issue. However the source code for snb shows that write_espresso_files does try to check whether the ase version is old_ase or not.

Nevertheless I passed profile but this time got: TypeError: write_espresso_files() got an unexpected keyword argument 'profile'

The documentation has a profile argument for write_espresso_files but it is not there when I do ?Dist.write_espresso_files:

image

I checked if there was an issue with version. It turned out that the version conda lists is 3.2.3 but the version in shakenbreak/__init__.py which is given by __version__ is 1.0.2.

Other info ase version: 3.23.0 doped version: 2.1.0 shakenbreak version: 3.2.3

ireaml commented 1 month ago

Great, thanks for posting the solution!