From e3f32147270ee7aebfd3220e2a53adf0ddf36465 Mon Sep 17 00:00:00 2001 From: Nick Papior Date: Thu, 10 Oct 2024 22:42:44 +0200 Subject: [PATCH] chore: refactored layouts of code Signed-off-by: Nick Papior --- src/sisl/io/tbtrans/pht.py | 2 ++ src/sisl/io/tbtrans/tbt.py | 2 +- src/sisl/physics/_brillouinzone_apply.py | 18 ++++++------------ src/sisl/physics/brillouinzone.py | 21 +++++++++++---------- src/sisl/physics/densitymatrix.py | 2 +- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/sisl/io/tbtrans/pht.py b/src/sisl/io/tbtrans/pht.py index 40f4479d5..842c80e75 100644 --- a/src/sisl/io/tbtrans/pht.py +++ b/src/sisl/io/tbtrans/pht.py @@ -55,6 +55,8 @@ def kT(self, elec: ElecType) -> float: "shot_noise", "noise_power", ): + # TODO change this such that the intrinsic details + # are separated. setattr(phtncSilePHtrans, _name, None) setattr(phtavncSilePHtrans, _name, None) diff --git a/src/sisl/io/tbtrans/tbt.py b/src/sisl/io/tbtrans/tbt.py index 6b08381cd..f5f13c0a9 100644 --- a/src/sisl/io/tbtrans/tbt.py +++ b/src/sisl/io/tbtrans/tbt.py @@ -117,7 +117,7 @@ class tbtncSileTBtrans(_devncSileTBtrans): are in fortran indexing (1-based), everything is returned as Python indexing (0-based) when using Python scripts. - The mathematical notation described in :ref:`this document ` + The mathematical notation described :ref:`here ` will be used throughout. A word on DOS normalization: diff --git a/src/sisl/physics/_brillouinzone_apply.py b/src/sisl/physics/_brillouinzone_apply.py index 64a103e56..53dec1b3c 100644 --- a/src/sisl/physics/_brillouinzone_apply.py +++ b/src/sisl/physics/_brillouinzone_apply.py @@ -12,15 +12,9 @@ from itertools import zip_longest import numpy as np +import xarray from numpy import cross, pi -try: - import xarray - - _has_xarray = True -except ImportError: - _has_xarray = False - try: import pathos @@ -196,6 +190,8 @@ def __getattr__(self, key): @set_module("sisl.physics") class IteratorApply(BrillouinZoneParentApply): + """Iterator for calculations *while iterating*.""" + def __str__(self, message="iter"): return super().__str__(message) @@ -280,7 +276,6 @@ def dispatch(self, method): def func(*args, **kwargs): for _ in iter_func(*args, **kwargs): pass - return None return func @@ -303,7 +298,7 @@ def func(*args, **kwargs): @wraps(method) def func(*args, **kwargs): - return [v for v in iter_func(*args, **kwargs)] + return list(iter_func(*args, **kwargs)) return func @@ -602,9 +597,8 @@ def func(*args, coords=None, dims=None, name=method.__name__, **kwargs): apply_dispatch.register("none", NoneApply) apply_dispatch.register("list", ListApply) apply_dispatch.register("oplist", OpListApply) -if _has_xarray: - apply_dispatch.register("dataarray", XArrayApply) - apply_dispatch.register("xarray", XArrayApply) +apply_dispatch.register("dataarray", XArrayApply) +apply_dispatch.register("xarray", XArrayApply) # Remove refernce del apply_dispatch diff --git a/src/sisl/physics/brillouinzone.py b/src/sisl/physics/brillouinzone.py index da3fa8545..4c7ad1711 100644 --- a/src/sisl/physics/brillouinzone.py +++ b/src/sisl/physics/brillouinzone.py @@ -266,15 +266,23 @@ class BrillouinZone: Parameters ---------- - parent : object or array_like + parent : object or array-like An object with associated ``parent.cell`` and ``parent.rcell`` or an array of floats which may be turned into a `Lattice` - k : array_like, optional + k : array-like, optional k-points that this Brillouin zone represents - weight : scalar or array_like, optional + weight : scalar or array-like, optional weights for the k-points. + """ + apply = BrillouinZoneDispatcher( + "apply", + # Do not allow class dispatching + type_dispatcher=None, + obj_getattr=lambda obj, key: getattr(obj.parent, key), + ) + def __init__(self, parent, k=None, weight=None): self.set_parent(parent) # define a bz_attr as though it has not been set @@ -291,13 +299,6 @@ def __init__(self, parent, k=None, weight=None): weight = 1.0 / len(self._k) self._w[:] = weight - apply = BrillouinZoneDispatcher( - "apply", - # Do not allow class dispatching - type_dispatcher=None, - obj_getattr=lambda obj, key: getattr(obj.parent, key), - ) - def set_parent(self, parent) -> None: """Update the parent associated to this object diff --git a/src/sisl/physics/densitymatrix.py b/src/sisl/physics/densitymatrix.py index 87b216e41..eddab3586 100644 --- a/src/sisl/physics/densitymatrix.py +++ b/src/sisl/physics/densitymatrix.py @@ -370,7 +370,7 @@ def spin_align(self, vec: SeqFloat, atoms: AtomsIndex = None): def mulliken(self, projection: Literal["orbital", "atom"] = "orbital"): r""" Calculate Mulliken charges from the density matrix - See :ref:`this document ` for details on the mathematical notation. + See :ref:`here ` for details on the mathematical notation. Matrices :math:`\boldsymbol\rho` and :math:`\mathbf S` are density and overlap matrices, respectively.