BattModels / asimtools

Optimized workflow management and script handling for atomistic simulations
MIT License
2 stars 0 forks source link

Running espresso #40

Open kianpu34593 opened 3 months ago

kianpu34593 commented 3 months ago

Hi,

It seems like ase has updated their EspressoProfile. The current implementation in asimtools doesn't work anymore.

The current implementation:

def load_espresso_profile(calc_params):
    """Load Qunatum Espresso Calculator for ASE>3.22.1. If using older versions
    such as the ones available on PyPI or conda-forge, just load it as an ASE
    calculator. Until the new ASE version becomes an official release, we will
    have to have both for compatibility. The interface however remains that of 
    ASE <=3.22.1 within ASIMTools for consistency using the `command` keyword

    https://wiki.fysik.dtu.dk/ase/releasenotes.html

    :param calc_params: args to pass to loader
    :type calc_params: Dict
    :return: Espresso calculator
    :rtype: :class:`ase.calculators.espresso.Espresso`
    """
    from ase.calculators.espresso import Espresso, EspressoProfile

    if 'command' in calc_params['args']:
        command = calc_params['args'].pop('command')
        command = command.split()
        progind = command.index('pw.x')
        argv = command[:progind+1]
    else:
        argv = ['pw.x']

    try:
        calc = Espresso(
            **calc_params['args'],
            profile=EspressoProfile(argv=argv)
        )
    except Exception:
        logging.error("Failed to load MACE-OFF with parameters:\n %s", calc_params)
        raise

    return calc

The source of the bug is here:

calc = Espresso(
    **calc_params['args'],
    profile=EspressoProfile(argv=argv)
)

My attempt of fixing it:

if 'command' in calc_params['args']:
    command = calc_params['args'].pop('command')
    command = command.split()
    progind = command.index('pw.x')
    argv = command[:progind]
    it = iter(argv)
    argv = dict(zip(it, it))
else:
    argv = ['pw.x']
try:
    binary = calc_params['args'].pop("binary")
    pseudo_dir = calc_params['args'].pop("pseudo_dir")
    calc = Espresso(
        **calc_params['args'],
        profile=EspressoProfile(parallel_info=argv,binary=binary, pseudo_dir=pseudo_dir)
    )

Summary:

mkphuthi commented 3 months ago

I would say fall back to a previous version of ASE for now. The espresso calculator is under active development in ASE and changes every now and then. Do you have use cases where you know the conda/PyPI version breaks?