Skip to content

No wrapping of RuntimeError messages caused by parameters in vasp calculators with incorrect units

When setting up a VASP calculator, if:

  • The parameter of a keyword requires units, but they are NOT provided, or
  • The parameter does not require units, but they ARE provided, or
  • The parameter is given incorrect units

The corresponding run employing the run_model.py script will print the full RuntimeError message, intead of wrapping as DSL error indicating type of error, file, and line number.

The sample script:

calc = Calculator vasp == 5.4.4 (
        (algo: 'Fast'),
        (ediff: 1e-06) [eV],
        (ediffg: -0.01) [eV/angstrom],
        (encut: 400.0) [eV],
        (ibrion: 2), # if given a value of 5, then potim should have [angstrom] units
        (icharg: 2),
        (isif: 2),
        (ismear: 0),
        (ispin: 2),
        (istart: 0),
        (kpts: [5, 5, 1]),
        (lcharg: false),
        (lreal: 'Auto'),
        (lwave: false),
        (nelm: 250),
        (nsw: 1500),
        (potim: 0.1) [angstrom], #this parameter should be unit-less
        (prec: 'Normal'),
        (sigma: 0.1) [eV],
        (xc: 'PBE')
)

print('Calculator parameters:', calc.parameters)

Would print an output containing the following lines:

[...]
File "/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib64/python3.8/site-packages/pint/registry.py", line 1077, in _convert
 raise DimensionalityError(src, dst, src_dim, dst_dim)
pint.errors.DimensionalityError: Cannot convert from 'angstrom' ([length]) to 'dimensionless' (dimensionless)

The above exception was the direct cause of the following exception:
[...]
 File "/pfs/data5/home/kit/scc/an9294/vre-language/src/virtmat/language/utilities/amml.py", line 67, in get_params_magnitudes
 raise InvalidUnitError(msg) from err
virtmat.language.utilities.errors.InvalidUnitError: error with units of parameter potim

The above exception was the direct cause of the following exception:
[...]
 File "/pfs/data5/home/kit/scc/an9294/vre-language/src/virtmat/language/utilities/errors.py", line 96, in wrapper
    raise RuntimeError('non-handled exception') from err
RuntimeError: non-handled exception