cleared up repository

class-solution
Daniel Pozsar 3 months ago
parent e49d306bd4
commit bcd9456bff

6
.gitignore vendored

@ -7,6 +7,7 @@ dist
# VSCode settings # VSCode settings
.vscode .vscode
.venv
.conda .conda
.pytest_cache .pytest_cache
@ -19,3 +20,8 @@ docs/source/api/generated
# Debug # Debug
tmp* tmp*
.coverage
test.ipynb
# Mac stuff
*.DS_Store*

@ -1,15 +1,15 @@
# See https://pre-commit.com for more information # See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks # See https://pre-commit.com/hooks.html for more hooks
repos: repos:
- repo: https://github.com/adrybakov/pre-commit-hooks #- repo: https://github.com/adrybakov/pre-commit-hooks
rev: 0.2.0 # rev: 0.2.0
hooks: # hooks:
- id: license-headers # - id: license-headers
args: # args:
- --license-file # - --license-file
- L-HEADER # - L-HEADER
- --update-year # - --update-year
- --verbose # - --verbose
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 rev: v4.6.0
hooks: hooks:
@ -26,12 +26,12 @@ repos:
rev: 24.4.2 rev: 24.4.2
hooks: hooks:
- id: black - id: black
language_version: python3.11 language_version: python3.12
- repo: local - repo: local
hooks: hooks:
- id: pytest-check - id: pytest-check
name: pytest-check name: pytest-check
entry: pytest entry: ./.venv/bin/pytest
language: system language: system
pass_filenames: false pass_filenames: false
always_run: true always_run: true

@ -1 +1,13 @@
# Relativistic magnetic interactions from non-orthogonal basis sets # Relativistic magnetic interactions from non-orthogonal basis sets
# TODO
- Definition of magnetic entities:
* Through simple sequence o forbitals in the unit cell
* Through atom specification
* Through atom and orbital specification
- Separation of TR and TRB components of the Hamiltonian, Identification of the exchange field.
- Definition of commutator expressions, old projection matrix elements
- Efficient calculation of Green's functions
- Calculation of energy and momentum resolved derivatives
- Parallel BZ and serial energy integral

@ -1,4 +1,3 @@
sphinx sphinx
sphinx_rtd_theme sphinx_rtd_theme
numpydoc numpydoc
doctest

@ -21,6 +21,7 @@ dependencies = [
"numpy", "numpy",
"scipy", "scipy",
"sisl", "sisl",
"openmpi",
"mpi4py", "mpi4py",
"argparse", "argparse",
] ]
@ -43,11 +44,11 @@ Repository = "https://github.com/me/spam.git"
Issues = "https://github.com/pypa/sampleproject/issues" Issues = "https://github.com/pypa/sampleproject/issues"
[tool.pytest.ini_options] [tool.pytest.ini_options]
pythonpath = [
"src/grogu/"
]
addopts = [ addopts = [
"--import-mode=importlib", "--import-mode=importlib",
# "--cov", # "--cov",
"--doctest-modules", "--doctest-modules",
] ]
pythonpath = [
"src/grogu/",
]

@ -6,13 +6,12 @@ twine
# code-linters # code-linters
black black
license-headers #license-headers
# dev-tools # dev-tools
pre-commit pre-commit
pytest pytest
pytest-randomly pytest-randomly
pytest-cov pytest-cov
doctest isort
sphinx sphinx
git

@ -1,6 +1,8 @@
# Package dependencies # Package dependencies
numpy argparse
scipy numpy>=1.13
scipy>=0.18
sisl sisl
netcdf4
openmpi
mpi4py mpi4py
argparse

@ -17,6 +17,3 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
from jij import *
from useful import *

@ -23,23 +23,7 @@ from itertools import permutations, product
import numpy as np import numpy as np
from scipy.special import roots_legendre from scipy.special import roots_legendre
# define some useful functions # define some useful functions
def hsk(dh, k=(0, 0, 0)):
"""
One way to speed up Hk and Sk generation
"""
k = np.asarray(k, np.float64) # this two conversion lines
k.shape = (-1,) # are from the sisl source
# this generates the list of phases
phases = np.exp(-1j * np.dot(np.dot(np.dot(dh.rcell, k), dh.cell), dh.sc.sc_off.T))
HKU = np.einsum("abc,c->ab", dh.hup, phases)
HKD = np.einsum("abc,c->ab", dh.hdo, phases)
SK = np.einsum("abc,c->ab", dh.sov, phases)
return HKU, HKD, SK
def make_contour(emin=-20, emax=0.0, enum=42, p=150): def make_contour(emin=-20, emax=0.0, enum=42, p=150):
@ -96,72 +80,120 @@ def make_kset(dirs="xyz", NUMK=20):
return kset return kset
def make_atran(nauc, dirs="xyz", dist=1): # Pauli matrices
""" tau_x = np.array([[0, 1], [1, 0]])
Simple pair generator. Depending on the value of the dirs tau_y = np.array([[0, -1j], [1j, 0]])
argument sampling in 1,2 or 3 dimensions is generated. tau_z = np.array([[1, 0], [0, -1]])
If dirs argument does not contain either of x,y or z tau_0 = np.array([[1, 0], [0, 1]])
a single pair is returend.
"""
if not (sum([d in dirs for d in "xyz"])):
return (0, 0, [1, 0, 0])
dran = len(dirs) * [np.arange(-dist, dist + 1)]
mg = np.meshgrid(*dran)
dirsdict = dict()
for d in enumerate(dirs): def comm(a, b):
dirsdict[d[1]] = mg[d[0]].flatten() "Shorthand for commutator"
for d in "xyz": return a @ b - b @ a
if not (d in dirs):
dirsdict[d] = 0 * dirsdict[dirs[0]]
ucran = np.array([dirsdict[d] for d in "xyz"]).T
atran = []
for i, j in list(product(range(nauc), repeat=2)):
for u in ucran:
if (abs(i - j) + sum(abs(u))) > 0:
atran.append((i, j, list(u)))
return atran def tau_u(u):
"""
Pauli matrix in direction u.
"""
u = u / np.linalg.norm(u) # u is force to be of unit length
return u[0] * tau_x + u[1] * tau_y + u[2] * tau_z
def add(x, y): #
"""The sum of two numbers for testing. def crossM(u):
"""
Definition for the cross-product matrix.
Acting as a crossproduct with vector u.
"""
return np.array([[0, -u[2], u[1]], [u[2], 0, -u[0]], [-u[1], u[0], 0]])
This function adds to numbers together. I only created this for testing documentation and examples.
Parameters def RotM(theta, u, eps=1e-10):
---------- """
x : float Definition of rotation matrix with angle theta around direction u.
First number """
y : float u = u / np.linalg.norm(u)
Second number added to `x`
Returns M = (
------- np.cos(theta) * np.eye(3)
sum : int + np.sin(theta) * crossM(u)
The sum of the inputs + (1 - np.cos(theta)) * np.outer(u, u)
)
M[abs(M) < eps] = 0.0 # kill off small numbers
return M
See Also
--------
numpy.add : Adds more than two numbers.
Notes def RotMa2b(a, b, eps=1e-10):
----- """
We can create some latex notes here [1]_ : Definition of rotation matrix rotating unit vector a to unit vector b.
Function returns array R such that R@a = b holds.
"""
v = np.cross(a, b)
c = a @ b
M = np.eye(3) + crossM(v) + crossM(v) @ crossM(v) / (1 + c)
M[abs(M) < eps] = 0.0 # kill off small numbers
return M
.. math:: a + b = c def spin_tracer(M):
"""
Spin tracer utility.
This akes an operator with the orbital-spin sequence:
orbital 1 up,
orbital 1 down,
orbital 2 up,
orbital 2 down,
that is in the SPIN-BOX representation,
and extracts orbital dependent Pauli traces.
"""
References M11 = M[0::2, 0::2]
---------- M12 = M[0::2, 1::2]
.. [1] https://numpydoc.readthedocs.io/en/latest/format.html M21 = M[1::2, 0::2]
M22 = M[1::2, 1::2]
M_o = dict()
M_o["x"] = M12 + M21
M_o["y"] = 1j * (M12 - M21)
M_o["z"] = M11 - M22
M_o["c"] = M11 + M22
return M_o
Examples
--------
>>> add(1, 2)
3
def parse_magnetic_entity(dh, atom=None, l=None, **kwargs):
"""
Function to define orbital indeces of a given magnetic entity.
dh: a sisl Hamiltonian object
atom: an integer or list of integers, defining atom (or atoms) in the unicell forming the magnetic entity
l: integer, defining the angular momentum channel
"""
# case where we deal with more than one atom defining the magnetic entity
if type(atom) == list:
dat = []
for a in atom:
a_orb_idx = dh.geometry.a2o(a, all=True)
if (
type(l) == int
): # if specified we restrict to given l angular momentum channel inside each atom
a_orb_idx = a_orb_idx[[o.l == l for o in dh.geometry.atoms[a].orbitals]]
dat.append(a_orb_idx)
orbital_indeces = np.hstack(dat)
# case where we deal with a singel atom magnetic entity
elif type(atom) == int:
orbital_indeces = dh.geometry.a2o(atom, all=True)
if (
type(l) == int
): # if specified we restrict to given l angular momentum channel
orbital_indeces = orbital_indeces[
[o.l == l for o in dh.geometry.atoms[atom].orbitals]
]
return orbital_indeces # numpy array containing integers labeling orbitals associated to a magnetic entity.
def blow_up_orbindx(orb_indices):
"""
Function to blow up orbital indeces to make SPIN BOX indices.
""" """
return x + y return np.array([[2 * o, 2 * o + 1] for o in orb_indices]).flatten()

@ -19,11 +19,27 @@
# SOFTWARE. # SOFTWARE.
import pytest import pytest
from useful import add from useful import *
@pytest.mark.parametrize( @pytest.mark.parametrize(
"a, b, c, expected_out", [(1, 2, 3, True), (6, 7, 13, True), (1, 2, 10, False)] "a, b, c",
[
(tau_x, tau_y, tau_z),
(tau_z, tau_x, tau_y),
(tau_y, tau_z, tau_x),
(tau_z, tau_y, -tau_x),
],
) )
def test_add(a, b, c, expected_out): def test_comm(a, b, c):
assert (add(a, b) == c) == expected_out assert (comm(a, b) == 2j * c).all()
@pytest.mark.parametrize(
"dirs, NUMK, out",
[
("", 10, np.array([[0, 0, 0]])),
],
)
def test_make_kset(dirs, NUMK, out):
assert (make_kset(dirs, NUMK) == out).all()

Loading…
Cancel
Save