Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/abinit/abipy into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Feb 18, 2024
2 parents 3c133dc + 63c26c9 commit 4e2b6ba
Show file tree
Hide file tree
Showing 75 changed files with 58,021 additions and 431 deletions.
25 changes: 6 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ in the form of pre-compiled packages that can be easily installed with e.g.::

Create a new conda_ environment (let's call it ``abienv``) with::

conda create --name abienv
conda create --name abienv python=3.11

and activate it with::

Expand All @@ -106,7 +106,10 @@ in the `anaconda howto <http://abinit.github.io/abipy/installation#anaconda-howt
Developmental version
---------------------

Getting the developmental version of AbiPy is easy.
To install the developmental version of AbiPy with pip, use::

pip install git+https://github.com/abinit/abipy.git@develop

Clone the `github repository <https://github.com/abinit/abipy>`_ with::

git clone https://github.com/abinit/abipy
Expand All @@ -118,7 +121,7 @@ For pip, use::

If you are using conda_ (see `Installing conda`_ to install conda itself), create a new environment (``abienv``) with::

conda create -n abienv
conda create -n abienv python=3.11
source activate abienv

Add ``conda-forge``, and ``abinit`` to your channels with::
Expand All @@ -143,22 +146,6 @@ or alternately::
to install the package in developmental mode.
This is the recommended approach, especially if you are planning to implement new features.

Note, however, that the developmental version of AbiPy is kept in sync with the
developmental version of pymatgen thus ```python setup.py develop``` may
try to download new versions from the PyPi portal and then fail with e.g. the error message::

...
processing dependencies for abipy==0.6.0.dev0
error: scipy 1.0.0 is installed but scipy>=1.0.1 is required by {'pymatgen'}

due to inconsistent dependencies.
To solve the problem, use conda to update scipy to a version >= 1.0.1 with::

conda install "scipy>=1.0.1"

then issue again python setup.py develop. If this fails, supposing you were upgrading abipy inside
an already existing conda environment, try to restart by creating from scratch a fresh conda environment, see above.

Also note that the BLAS/Lapack libraries provided by conda have multithreading support activated by default.
Each process will try to use all of the cores on your machine, which quickly overloads things
if there are multiple processes running.
Expand Down
1 change: 1 addition & 0 deletions abipy/abio/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ def minimal_scf_input(structure: Structure, pseudos) -> AbinitInput:
inp["nband"] = 1
inp["chkprim"] = 0
inp["chksymbreak"] = 0
inp["maxnsym"] = 100000 # to be able to deal with supercells
inp["charge"] = structure.num_valence_electrons(inp.pseudos) - 1
inp["boxcutmin"] = 1.2
return inp
Expand Down
2 changes: 1 addition & 1 deletion abipy/abio/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ def set_autospinat(self, default=0.6) -> dict:
for site in self.structure:
if hasattr(site, 'magmom'):
spinat.append((0., 0., site.magmom))
elif hasattr(site.specie, 'spin'):
elif hasattr(site.specie, 'spin') and site.specie.spin:
spinat.append((0., 0., site.specie.spin))
elif str(site.specie) in magmom_mp_conf:
spinat.append((0., 0., magmom_mp_conf.get(str(site.specie))))
Expand Down
8 changes: 7 additions & 1 deletion abipy/abio/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,13 @@ def pop_stack():
if dtidx is None:
vars_global[key] = value
else:
vars_dataset[dtidx][key] = value
try:
vars_dataset[dtidx][key] = value
except KeyError:
if dtidx==0:
vars_global[key] = value
else:
raise Exception("dataset index != 0 but still not found in vars_dataset")

for line in lines:
if not line: continue
Expand Down
38 changes: 6 additions & 32 deletions abipy/abio/robots.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,36 +817,6 @@ def close(self) -> None:
print("Exception while closing: ", abifile.filepath)
print(exc)

#@classmethod
#def open(cls, obj, nids=None, **kwargs):
# """
# Flexible constructor. obj can be a :class:`Flow` or a string with the directory containing the Flow.
# `nids` is an optional list of :class:`Node` identifiers used to filter the set of :class:`Task` in the Flow.
# """
# has_dirpath = False
# if is_string(obj):
# try:
# from abipy.flowtk import Flow
# obj = Flow.pickle_load(obj)
# except:
# has_dirpath = True

# if not has_dirpath:
# # We have a Flow. smeth is the name of the Task method used to open the file.
# items = []
# smeth = "open_" + cls.EXT.lower()
# for task in obj.iflat_tasks(nids=nids): #, status=obj.S_OK):
# open_method = getattr(task, smeth, None)
# if open_method is None: continue
# abifile = open_method()
# if abifile is not None: items.append((task.pos_str, abifile))
# return cls(*items)

# else:
# # directory --> search for files with the appropriate extension and open it with abiopen.
# if nids is not None: raise ValueError("nids cannot be used when obj is a directory.")
# return cls.from_dir(obj)

#def get_attributes(self, attr_name, obj=None, retdict=False):
# od = OrderedDict()
# for label, abifile in self.items():
Expand Down Expand Up @@ -1241,10 +1211,14 @@ def get_baserobot_code_cells(self, title=None) -> list:
@staticmethod
def get_yvals_item_abifiles(item: Any, abifiles: list) -> np.ndarray:
"""Extract values for a list of Abinit files."""
def _float(obj):
if obj is None: return obj
return float(obj)

if callable(item):
return np.array([float(item(a)) for a in abifiles])
return np.array([_float(item(a)) for a in abifiles])
else:
return np.array([float(duck.getattrd(a, item)) for a in abifiles])
return np.array([_float(duck.getattrd(a, item)) for a in abifiles])

@staticmethod
def plot_xvals_or_xstr_ax(ax, xs, yvals, fontsize, **kwargs) -> list:
Expand Down
16 changes: 8 additions & 8 deletions abipy/abio/tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_helper_functions(self):
assert inp["ndivsm"] == 3 and inp["iscf"] == -2 and len(inp["kptbounds"]) == 12

inp.set_kpath(ndivsm=-20)
assert inp["nkpt"] == 156 and inp["iscf"] == -2
assert inp["nkpt"] in (156, 157) and inp["iscf"] == -2

inp.set_qpath(ndivsm=3, qptbounds=None)
assert len(inp["ph_qpath"]) == 12 and inp["ph_nqpath"] == 12 and inp["ph_ndivsm"] == 3
Expand Down Expand Up @@ -344,9 +344,9 @@ def test_new_with_structure_2(self):
abi_kwargs=abi_kwargs)

n_val = inp.num_valence_electrons
n_cond = round(10)
n_cond = round(10)

spin_up_gs = f"\n{int((n_val - 3) / 2)}*1 1 1 1 {n_cond}*0"
spin_up_gs = f"\n{int((n_val - 3) / 2)}*1 1 1 1 {n_cond}*0"
spin_dn_gs = f"\n{int((n_val - 3) / 2)}*1 1 0 0 {n_cond}*0"

nsppol = 2
Expand All @@ -359,13 +359,13 @@ def test_new_with_structure_2(self):

new_inp = inp.new_with_structure(new_structure=sc_stru,
scdims=[2,1,1],verbose=0)
assert new_inp["nband"] == '*276'
#self.abivalidate_input(new_inp)
assert new_inp["nband"] == '*276'
#self.abivalidate_input(new_inp)
# Not valid now because occ should be rewritten as well
# TODO
# go from
# go from
# occ='125*1 1 1 1 10*0'
# to
# to
# occ='125*1 1 1 1 125*1 1 1 1 10*0 10*0 '
# if size is doubled.

Expand Down Expand Up @@ -573,7 +573,7 @@ def test_dfpt_methods(self):
self.abivalidate_input(nscf_inp)

# Test make_ebands_input with nband = "*91" (occopt 2)
gs_occopt2 = gs_inp.new_with_vars(nband="*91", occopt=2)
gs_occopt2 = gs_inp.new_with_vars(nband="*91", occopt=2, paral_kgb=0)
nscf_inp = gs_occopt2.make_ebands_input(nb_extra=10)
assert nscf_inp["nband"] == "*101"
self.abivalidate_input(nscf_inp)
Expand Down
6 changes: 5 additions & 1 deletion abipy/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def from_mpid(cls, material_id: str, final=True, api_key=None, endpoint=None) ->
from abipy.core import restapi
with restapi.get_mprester(api_key=api_key, endpoint=endpoint) as rest:
new = rest.get_structure_by_material_id(material_id, final=final)
#new = rest.get_structure_by_material_id(material_id)
return cls.as_structure(new)

@classmethod
Expand Down Expand Up @@ -1801,7 +1802,10 @@ def convert(self, fmt: str = "cif", **kwargs) -> str:
# Don't call super for poscar because we need more significant_figures to
# avoid problems with abinit space group routines where the default numerical tolerance is tight.
from pymatgen.io.vasp import Poscar
return Poscar(self).get_string(significant_figures=12)
try:
return Poscar(self).get_str(significant_figures=12)
except AttributeError:
return Poscar(self).get_string(significant_figures=12)
else:
return super().to(fmt=fmt, **kwargs)

Expand Down
5 changes: 5 additions & 0 deletions abipy/core/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ def skip_if_abinit_not_ge(self, version: str) -> None:
if not self.has_abinit(version, op=op):
raise unittest.SkipTest("This test requires Abinit version %s %s" % (op, version))

@staticmethod
def test_mprester():
"""Skip MP rester tests."""
raise unittest.SkipTest("MPRester tests have been disabled")

@staticmethod
def has_matplotlib(version: Optional[str] = None, op: str = ">=") -> bool:
return has_matplotlib(version=version, op=op)
Expand Down
21 changes: 11 additions & 10 deletions abipy/core/tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,17 @@ def test_utils(self):
self.assert_almost_equal(mgb2.lattice.angles, (90.0, 90.0, 120.00000000000001))
self.assert_almost_equal(mgb2.lattice.volume * abu.Ang_Bohr ** 3, 196.07928976151663)

si = Structure.from_mpid("mp-149")
assert si.formula == "Si2"
with self.assertRaises(ValueError):
Structure.from_mpid("foobar")

# Test abiget_spginfo
d = si.abiget_spginfo(tolsym=None, pre="abi_")
assert d["abi_spg_symbol"] == "Fd-3m"
assert d["abi_spg_number"] == 227
assert d["abi_bravais"] == "Bravais cF (face-center cubic)"
if self.test_mprester():
si = Structure.from_mpid("mp-149")
assert si.formula == "Si2"
with self.assertRaises(ValueError):
Structure.from_mpid("foobar")

# Test abiget_spginfo
d = si.abiget_spginfo(tolsym=None, pre="abi_")
assert d["abi_spg_symbol"] == "Fd-3m"
assert d["abi_spg_number"] == 227
assert d["abi_bravais"] == "Bravais cF (face-center cubic)"

llzo = Structure.from_file(abidata.cif_file("LLZO_oxi.cif"))
assert llzo.is_ordered
Expand Down
83 changes: 83 additions & 0 deletions abipy/data/lruj_data/lruj.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

.Version 9.11.6 of LRUJ
.(MPI version, prepared for a x86_64_linux_intel18.0 computer)

.Copyright (C) 1998-2022 ABINIT group .
LRUJ comes with ABSOLUTELY NO WARRANTY.
It is free software, and you are welcome to redistribute it
under certain conditions (GNU General Public License,
see ~abinit/COPYING or http://www.gnu.org/copyleft/gpl.txt).

ABINIT is a project of the Universite Catholique de Louvain,
Corning Inc. and other collaborators, see ~abinit/doc/developers/contributors.txt .
Please read https://docs.abinit.org/theory/acknowledgments for suggested
acknowledgments of the ABINIT effort.
For more information, see https://www.abinit.org .

.Starting date : Wed 29 Nov 2023.
- ( at 15h33 )

Number of perturbations detected: 6
Including unperturbed state, we have 7 data points.
Hunds J determination, implemented by L. MacEnulty August 2021
Maximum degree of polynomials analyzed: 5
NOTE: Unlike the ujdet utility, lruj treats the
response functions as scalars, not matrices!
See lruj tutorial for more information.


*************************************************************************************************
************************************** Linear Response J **************************************

Total number of atoms: 4
Index of perturbed atom: 1
Value of macro_uj: 4
Value of dmatpuopt: 3
Mixing constant factored out of Chi0: 0.450
Percentage of AE orbital within the PAW sphere of perturbed subspace: 90.46723%

Perturbations Magnetizations
--------------- -----------------------------
beta [eV] Unscreened Screened
--------------- -----------------------------
-0.1500000676 1.3322568566 1.3664401054
-0.1000000451 1.3250447778 1.3485578255
-0.0500000225 1.3176770671 1.3298301923
0.0000000000 1.3101482092 1.3101482092
0.0500000225 1.3024514902 1.2893790961
0.1000000451 1.2945812190 1.2673571836
0.1500000676 1.2865306151 1.2438737113
RMS Errors
---------------------------------------
Regression Chi0 [eV^-1] Chi [eV^-1] J [eV] | Chi0 [eV^-1] Chi [eV^-1] J [eV]
--------------------------------------------------------|---------------------------------------
Linear: -0.3386211 -0.4075366 0.4993858 | 0.0006971 0.0020836 0.1364740
Quadratic: -0.3386211 -0.4075366 0.4993858 | 0.0000137 0.0001529 0.0322580
Cubic: -0.3383005 -0.4039797 0.4805799 | 0.0000002 0.0000120 0.0086817
Degree 4 : -0.3383005 -0.4039797 0.4805799 | 0.0000001 0.0000009 0.0025307
Degree 5 : -0.3383000 -0.4040198 0.4808302 | 0.0000001 0.0000000 0.0011046
*************************************************************************************************
*************************************************************************************************

Linear Response UJ (LRUJ) program complete. Live long and prosper. ~LMac


--- !LRUJ_Abipy_Plots
natom: 4
ndata: 7
pawujat: 1
macro_uj: 4
diem_token: diemixmag
diem: 4.50000000E-01
chi0_coefficients_degree1: [ 1.30981289E+00, -1.52379516E-01, ]
chi_coefficients_degree1: [ 1.30794090E+00, -4.07536646E-01, ]
chi0_coefficients_degree2: [ 1.31014818E+00, -1.52379516E-01, -3.35292571E-02, ]
chi_coefficients_degree2: [ 1.31016241E+00, -4.07536646E-01, -2.22150364E-01, ]
chi0_coefficients_degree3: [ 1.31014818E+00, -1.52235216E-01, -3.35292571E-02, -8.24572223E-03, ]
chi_coefficients_degree3: [ 1.31016241E+00, -4.03979653E-01, -2.22150364E-01, -2.03256604E-01, ]
chi0_coefficients_degree4: [ 1.31014812E+00, -1.52235216E-01, -3.35038810E-02, -8.24572223E-03, -1.06049292E-03, ]
chi_coefficients_degree4: [ 1.31014819E+00, -4.03979653E-01, -2.16856067E-01, -2.03256604E-01, -2.21254002E-01, ]
chi0_coefficients_degree5: [ 1.31014812E+00, -1.52234989E-01, -3.35038810E-02, -8.28815298E-03, -1.06049292E-03, 1.45476754E-03, ]
chi_coefficients_degree5: [ 1.31014819E+00, -4.04019800E-01, -2.16856067E-01, -1.95748183E-01, -2.21254002E-01, -2.57431330E-01, ]
...

Loading

0 comments on commit 4e2b6ba

Please sign in to comment.