Skip to content

Commit

Permalink
chore: refactored layouts of code
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Papior <nickpapior@gmail.com>
  • Loading branch information
zerothi committed Oct 10, 2024
1 parent 1ee7547 commit e3f3214
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/sisl/io/tbtrans/pht.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/sisl/io/tbtrans/tbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math_convention>`
The mathematical notation described :ref:`here <math_convention>`
will be used throughout.
A word on DOS normalization:
Expand Down
18 changes: 6 additions & 12 deletions src/sisl/physics/_brillouinzone_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down Expand Up @@ -280,7 +276,6 @@ def dispatch(self, method):
def func(*args, **kwargs):
for _ in iter_func(*args, **kwargs):
pass
return None

return func

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions src/sisl/physics/brillouinzone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/physics/densitymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math_convention>` for details on the mathematical notation.
See :ref:`here <math_convention>` for details on the mathematical notation.
Matrices :math:`\boldsymbol\rho` and :math:`\mathbf S` are density
and overlap matrices, respectively.
Expand Down

0 comments on commit e3f3214

Please sign in to comment.