ASE-Workshop-2023 / tutorial

Tutorial site for the 2023 workshop "Open Science with the Atomic Simulation Environment"
https://ase-workshop-2023.github.io/tutorial
Other
2 stars 4 forks source link

QE bandstructure calc TypeError `bands_calc.calculate(si_fcc)` #3

Closed lucydot closed 1 year ago

lucydot commented 1 year ago

Hi @pietrodelugas,

Using: ase-3.21.1 , qe-7.1

I'm running through the tutorial script you sent across.

I've adapted it slightly to use profiles. The scf runs as expected:

from ase import Atoms
from ase.lattice import FCC
from ase.visualize import  view
from ase.calculators.espresso import Espresso, EspressoProfile

si_fcc = Atoms(symbols='Si2',
               cell = FCC(a=10.20 * 0.529177).tocell(),
               scaled_positions=[(0.0, 0.0, 0.0),
                                 (0.25, 0.25, 0.25)],
               pbc=True)

pseudo_dir = '/Users/lucy/Code/QE/SSSP_1.2.1_PBE_efficiency/'
control = {'calculation': "scf",
           'prefix': "si_fcc",
           'pseudo_dir': pseudo_dir,
           'tprnfor': True,
           'tstress': True}
system = {'ecutwfc': 35.00}
electrons = {'diagonalization':'davidson',
             'conv_thr': 1.e-8}
atomic_species = {'Si': 'Si.pbe-n-rrkjus_psl.1.0.0.UPF'}
kpts = [8,8,8] #8X8X8 MP k-point mesh 
koffset = [0,0,0] 

profile = EspressoProfile(['mpirun', 'pw.x'])

scf_calc = Espresso(profile=profile,
                input_data={'control': control,
                            'system': system,
                            'electrons': electrons},
                pseudopotentials=atomic_species,
                kpts=kpts,
                koffset=koffset)

si_fcc.calc = scf_calc
si_fcc.get_properties(['energy'])

kpointpath = si_fcc.cell.bandpath(path='LGXWKG', density=20)
kpointpath.special_points

However when I try to calculate the bandstructure:

bands_calc.calculate(si_fcc)

I get an error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[40], line 1
----> 1 bands_calc.calculate(si_fcc)
      2 bands_structure = bands_calc.band_structure()
      3 bands_structure._reference = si_fcc.calc.get_fermi_level() 

TypeError: GenericFileIOCalculator.calculate() missing 2 required positional arguments: 'properties' and 'system_changes'
pietrodelugas commented 1 year ago

Hi Lucy,@lucydot, I am updating the script; almost done. The bands should be working. There is still an issue with the DOS. It's a bug in this temporary ASE version; @ajjackson has already submitted the fix; you may try using his branch.

git fetch "https://gitlab.com/ajjackson/ase.git" 'mixin-eigenvalues'
git checkout -b 'ase-mixin-eigenvalues' FETCH_HEAD

Hopefully, it will be merged in hours, and we can use ASE's master branch directly.

pietrodelugas commented 1 year ago

@lucydot, in this new version, the calculate method expects three arguments, the Atoms object with the system description, in this case, si_fcc, the properties you want to calculate, and the system_changes, these are lists that may also be left empty. e.g.

nscf_calc.calculate(si_fcc, properties=[], system_changes=[])

Just for coherence with what I am doing, I put properties=['eigenvalues']

ajjackson commented 1 year ago

I think in my draft Calculator tutorial I showed how instead of calling .calculate() (which is a rather stateful procedural kind of programming...) one can use atoms.get_properties() to request the results directly. This triggers the calculation, so belongs more to a functional / lazy-evaluation programming style. It may not work as expected with every calculator yet, though...

Not saying we have to do it one way or the other, there are use-cases for both at the moment.

pietrodelugas commented 1 year ago

get_properties work, at least for the SCF, and I use it also in this part. For the bands and nscf calculation, though, I am not sure because, being non-self-consistent most of the properties are not computed and so not reported in the output, and the espresso calculator looks for all of them.

P.S. I checked atoms.get_properties works without problem, I have updated the pull request for chapter 9

lucydot commented 1 year ago

I've just installed the latest master branch from ASE and can confirm that I can get a bandstructure and DOS on my laptop 👍 - thanks @pietrodelugas and @ajjackson .

I was upgrading from previous ASE and weirdly I found I had to use --force-reinstall when getting the latest from master: pip install git+https://gitlab.com/ase/ase.git@master --force-reinstall, as an FYI.

It makes sense to be consistent and use the atoms.get_properties() throughout where we can. Will also add a note in the tutorial about the alternative .calculate() method as seems a useful teaching point which could open up a nice discussion on various programming paradigms.