aiidateam / aiida-quantumespresso

The official AiiDA plugin for Quantum ESPRESSO
https://aiida-quantumespresso.readthedocs.io
Other
52 stars 77 forks source link

Protocols: Add `aiida-pseudo` install command to `ValueError` #931

Open mbercx opened 1 year ago

mbercx commented 1 year ago

When a user tries to use a pseudopotential family that isn't installed, e.g.:

from aiida import orm, load_profile
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain

load_profile('dev')

structure = orm.load_node(15151) # Si
code = orm.load_code('qe-7.2-pw@localhost')

builder = PwBaseWorkChain.get_builder_from_protocol(
    structure=structure,
    code=code,
    overrides={'pseudo_family': 'SSSP/1.1/PBEsol/precision'}
)

The get_builder_from_protocol() command returns a ValueError:

ValueError                                Traceback (most recent call last)
Cell In[15], line 9
      6 structure = orm.load_node(15151) # Si
      7 code = orm.load_code('qe-7.2-pw@localhost')
----> 9 builder = PwBaseWorkChain.get_builder_from_protocol(
     10     structure=structure,
     11     code=code,
     12     overrides={'pseudo_family': 'SSSP[/1.1/PBEsol/precision](https://vscode-remote+ssh-002dremote-002btheos-002dpc.vscode-resource.vscode-cdn.net/1.1/PBEsol/precision)'}
     13 )
...
    166     ) from exception
    168 try:
    169     cutoff_wfc, cutoff_rho = pseudo_family.get_recommended_cutoffs(structure=structure, unit='Ry')

ValueError: required pseudo family `SSSP/1.1/PBEsol/precision` is not installed. Please use `aiida-pseudo install` toinstall it.

Besides the absence of a space between toinstall, we could add specific instructions to install the family the user requested. I.e. in this case:

aiida-pseudo install sssp -v 1.1 -x PBEsol -p precision 

To do this properly, we'd need a utility method that converts the pseudo configuration (specified via the label) into the corresponding aiida-pseudo install command (perhaps also considering the defaults). This should probably be implemented in aiida-pseudo and used here.

The utility command can then also immediately do a check to see if the configuration exists at all. I was inclined to have the error message indicate that it's not a valid aiida-pseudo configuration, but of course users can also install custom families with recommended cutoffs. So it should probably say something along the lines of:

ValueError: required pseudo family `best-pseudos-ever-yo` is not installed.
Since it is not an "established" configuration, use `aiida-pseudo install family` to install it from a suitably formatted archive.