Skip to content

Commit

Permalink
Fix deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Sep 12, 2023
1 parent 66f18a1 commit ddd8ed9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 44 deletions.
2 changes: 1 addition & 1 deletion abipy/abio/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 6 additions & 17 deletions abipy/examples/_runflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion abipy/flowtk/abiphonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion abipy/iotools/xsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
1 change: 1 addition & 0 deletions abipy/ml/ml_relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions abipy/panels/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 15 additions & 22 deletions dev_scripts/mlrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
from __future__ import annotations


import sys
import os
import click
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ddd8ed9

Please sign in to comment.