From ddd8ed92b5aaee3d670e5b190dccaf8f1286b560 Mon Sep 17 00:00:00 2001 From: gmatteo Date: Tue, 12 Sep 2023 11:41:22 +0200 Subject: [PATCH] Fix deprecation warnings --- abipy/abio/inputs.py | 2 +- abipy/examples/_runflows.py | 23 ++++++----------------- abipy/flowtk/abiphonopy.py | 2 +- abipy/iotools/xsf.py | 2 +- abipy/ml/ml_relax.py | 1 + abipy/panels/viewers.py | 4 ++-- dev_scripts/mlrun.py | 37 +++++++++++++++---------------------- 7 files changed, 27 insertions(+), 44 deletions(-) diff --git a/abipy/abio/inputs.py b/abipy/abio/inputs.py index 471cae3bd..1ec67d9d6 100644 --- a/abipy/abio/inputs.py +++ b/abipy/abio/inputs.py @@ -1531,7 +1531,7 @@ def new_with_structure(self, new_structure, scdims=None, verbose=1) -> AbinitInp if scdims.shape != (3,): raise ValueError("Expecting 3 int in scdims but got %s" % str(scdims)) - numcells = np.product(scdims) + numcells = np.prod(scdims) if len(new_structure) != numcells * len(self.structure): errmsg = "Number of atoms in the input structure should be %d * %d but found %d" % ( numcells, len(self.structure), len(new_structure)) diff --git a/abipy/examples/_runflows.py b/abipy/examples/_runflows.py index 87418a64e..b56827701 100755 --- a/abipy/examples/_runflows.py +++ b/abipy/examples/_runflows.py @@ -9,17 +9,19 @@ import argparse import shutil import tempfile +import abipy.tools.cli_parsers as cli from subprocess import call from abipy import __version__ from abipy import flowtk + def main(): def str_examples(): examples = """ Usage example:\n\n - runall.py => Run all scripts. + _runflows.py => Run all scripts. """ return examples @@ -37,27 +39,14 @@ def show_examples_and_exit(err_msg=None, error_code=1): help="set the loglevel. Possible values: CRITICAL, ERROR (default), WARNING, INFO, DEBUG") parser.add_argument('-m', '--mode', type=str, default="sequential", help="execution mode. Default is sequential.") - parser.add_argument('-e', '--exclude', type=str, default="", help="Exclude scripts. Comma-separated names") - parser.add_argument('-x', '--execute', default=False, action="store_true", help="Execute flows.") - - parser.add_argument('--keep-dirs', action="store_true", default=False, - help="Do not remove flowdirectories.") - + parser.add_argument('--keep-dirs', action="store_true", default=False, help="Do not remove flow directories.") parser.add_argument('-b', '--bail-on-failure', default=False, help="Exit at the first error.") - #parser.add_argument("scripts", nargs="+",help="List of scripts to be executed") - options = parser.parse_args() - # loglevel is bound to the string value obtained from the command line argument. - # Convert to upper case to allow the user to specify --loglevel=DEBUG or --loglevel=debug - import logging - numeric_level = getattr(logging, options.loglevel.upper(), None) - if not isinstance(numeric_level, int): - raise ValueError('Invalid log level: %s' % options.loglevel) - logging.basicConfig(level=numeric_level) + cli.set_loglevel(options.loglevel) # Find scripts. if options.exclude: @@ -85,7 +74,7 @@ def show_examples_and_exit(err_msg=None, error_code=1): retcode += ret if ret != 0: - e = "python %s returned retcode !=0" % script + e = "python %s returned retcode != 0" % script print(e) errors.append(e) if options.bail_on_failure: diff --git a/abipy/flowtk/abiphonopy.py b/abipy/flowtk/abiphonopy.py index c90d154a3..513986d83 100644 --- a/abipy/flowtk/abiphonopy.py +++ b/abipy/flowtk/abiphonopy.py @@ -99,7 +99,7 @@ def from_gs_input(cls, gsinp, scdims, phonopy_kwargs=None, displ_kwargs=None) -> phonon.generate_displacements(**displ_kwargs) # distance=0.01, # Obtain supercells containing respective displacements (list of Atoms objects). - for atoms in phonon.get_supercells_with_displacements(): + for atoms in phonon.supercells_with_displacements: sc_struct = structure_from_atoms(atoms) sc_gsinp = gsinp.new_with_structure(sc_struct, scdims=new.scdims) sc_gsinp.pop_tolerances() diff --git a/abipy/iotools/xsf.py b/abipy/iotools/xsf.py index 6b7c1381c..ef15719a7 100644 --- a/abipy/iotools/xsf.py +++ b/abipy/iotools/xsf.py @@ -201,7 +201,7 @@ def bxsf_write(file, structure, nsppol, nband, ndivs, ucdata_sbk, fermie, unit=" ucdata_sbk = EnergyArray(ucdata_sbk, unit).to("Ha") fermie = Energy(fermie, unit).to("Ha") - ucdata_sbk = np.reshape(ucdata_sbk, (nsppol, nband, np.product(ndivs))) + ucdata_sbk = np.reshape(ucdata_sbk, (nsppol, nband, np.prod(ndivs))) close_it = False if not hasattr(file, "write"): diff --git a/abipy/ml/ml_relax.py b/abipy/ml/ml_relax.py index 94c231390..ef4168082 100644 --- a/abipy/ml/ml_relax.py +++ b/abipy/ml/ml_relax.py @@ -302,6 +302,7 @@ def run(self, workdir=None, prefix=None): if __name__ == "__main__": + # Get pseudos from abipy.flowtk.psrepos import get_oncvpsp_pseudos xc_name = "PBE" pseudos = get_oncvpsp_pseudos(xc_name=xc_name, version="0.4") diff --git a/abipy/panels/viewers.py b/abipy/panels/viewers.py index 8358bd303..bdff53a66 100644 --- a/abipy/panels/viewers.py +++ b/abipy/panels/viewers.py @@ -19,8 +19,8 @@ def __init__(self, filepath: str, theme="terminal", height=1200, **params): self.open_btn = pnw.Button(name=f"Open {basename}", button_type='primary') self.open_btn.on_click(self.open_ace_editor) - self.ace = pnw.Ace(language='text', readonly=True, theme=theme, - sizing_mode='stretch_width', height=height, visible=False) + self.ace = pnw.CodeEditor(language='text', readonly=True, theme=theme, + sizing_mode='stretch_width', height=height, visible=False) self.controls = pn.Card(self.ace.param.height, self.ace.param.theme, self.ace.param.visible, title="ACE controls", collapsed=True) diff --git a/dev_scripts/mlrun.py b/dev_scripts/mlrun.py index a058849fd..9d1724fa7 100755 --- a/dev_scripts/mlrun.py +++ b/dev_scripts/mlrun.py @@ -4,7 +4,6 @@ """ from __future__ import annotations - import sys import os import click @@ -13,7 +12,6 @@ from ase.atoms import Atoms from ase.build import bulk from abipy.core.structure import Structure -from abipy.flowtk.psrepos import get_repo_from_name from abipy.ml.aseml import get_atoms, ase_optimizer_cls, CORRALGO from abipy.ml.ml_relax import RelaxationProfiler @@ -70,28 +68,23 @@ def main(filepath, nn_name, corr_algo_str, warnings.simplefilter("ignore") # Get pseudos - repo_name = { - "PBE": "ONCVPSP-PBE-SR-PDv0.4", - "PBEsol": "ONCVPSP-PBEsol-SR-PDv0.4", - "LDA": "ONCVPSP-LDA-SR-PDv0.4", - }[xc_nane] - print(f"Using {repo_name=}") - pseudos = get_repo_from_name(repo_name).get_pseudos("standard") - #from abipy.flowtk.psrepos import get_repo_from_name get_oncvpsp_pseudos - #pseudos = get_oncvpsp_pseudos(xc_name=xc_name, version="0.4") - - # Get atoms + from abipy.flowtk.psrepos import get_oncvpsp_pseudos + pseudos = get_oncvpsp_pseudos(xc_name=xc_name, version="0.4") + if os.path.exists(filepath): + # Read structure from file. structure = Structure.from_file(filepath) - if abs(scale_volume - 1.0) > 0.0: - print(f"Scaling input volume by {scale_volume=}") - #print("before structure:\n", structure) - structure = structure.scale_lattice(scale_volume * structure.lattice.volume) - #print("after structure:\n", structure) - atoms = get_atoms(structure) - else: - raise ValueError(f"Cannot init Atoms from {filepath=}") - #atoms = bulk(filepath) + + elif filepath.startswith("__mp-"): + print(f"Fetching structure for mp-id {filepath[2:]} from the materials project database.") + structure = Structure.from_mpid(filepath[2:]) + + if abs(scale_volume - 1.0) > 0.0: + print(f"Scaling input volume by {scale_volume=}") + structure = structure.scale_lattice(scale_volume * structure.lattice.volume) + + # Convert to ASE atoms + atoms = get_atoms(structure) if rattle: print("Displacing atoms randomly with stdev=", rattle)