Skip to content

Commit cfde869

Browse files
authored
Merge pull request #896 from zerothi/873-bdg-final
fixed and finalized BdG spin configuration
2 parents af036e0 + 7afbefb commit cfde869

23 files changed

Lines changed: 937 additions & 814 deletions

changes/896.change.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Changed ``hermitian => conjugate``
2+
3+
Now one should use ``H.transpose(conjugate=True, ...)``
4+
instead. The Hermitian argument did not make sense, since
5+
the transpose was implicit of the function name.
6+
7+
It is now also more obvious how ``conjugate=..., spin=...``
8+
works together.
9+
10+
Also, all arguments to this method are forced keywords.
11+
12+
A ``len(H) == H.no * 4`` for Nambu spin configuration.
13+
14+
The diagonalization of the Hamiltonian will return
15+
an eigenvalue symmetric spectrum (about E=0).
16+
Hence this one will be dependent on the shift of the
17+
spectrum.

changes/896.feat.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Added Nambu spin configuration
2+
3+
Allowed `sisl` to operate with the Nambu spin-configuration.
4+
This spin-configuration is made for spin-orbit +
5+
super-conductivity.
6+
7+
Nearly all functionality that is available for SOC is also
8+
availiable for BdG (Nambu) spin configuration.
9+
10+
This goes in line with the recent additions to the Siesta
11+
code with superconductivity.

changes/896.fix.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Non-collinear transposing was buggy
2+
3+
The code for transposing + conjugating (adjoint operator)
4+
was wrong for non-collinear matrices.
5+
This is now finally fixed, and checked for.
6+
7+
Fixed documentation in ``trs`` method for matrices.
8+
9+
Fixed overlap conjugation for transpose when complex
10+
numbers are used.

changes/orphan.14.change.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

developments/spin.ipynb

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "158426a6-f7f2-40b4-96fc-087a3035af30",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from sympy import *\n",
11+
"\n",
12+
"init_printing(use_unicode=False, use_latex=False)"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": null,
18+
"id": "e15cb269-f88e-4055-b714-bf8b48269d79",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"# Create the Pauli matrices\n",
23+
"\n",
24+
"sigma_x = Matrix([[0, 1], [1, 0]])\n",
25+
"sigma_y = Matrix([[0, -I], [I, 0]])\n",
26+
"sigma_z = Matrix([[1, 0], [0, -1]])\n",
27+
"\n",
28+
"assert sigma_x**2 == eye(2)\n",
29+
"assert sigma_y**2 == eye(2)\n",
30+
"assert sigma_z**2 == eye(2)"
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"id": "606b36c4-83b6-4188-a5fe-76555d258a3c",
36+
"metadata": {},
37+
"source": [
38+
"## Spin configurations\n",
39+
"\n",
40+
"Here we'll show different spin-configurations, and do various operations. First we'll define some generic operators that we'll apply.\n",
41+
"Then comes the different spin sections."
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"id": "ac6a0b74-47e9-49b4-bafa-44b82753a652",
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"def equal(M1, M2):\n",
52+
" return Eq(M1, M2).doit()\n",
53+
"\n",
54+
"\n",
55+
"def trs(H):\n",
56+
" return sympify(sigma_y * H.conjugate() * sigma_y)\n",
57+
"\n",
58+
"\n",
59+
"def make_trs(H):\n",
60+
" H_trs = sympify(H + trs(H))\n",
61+
" return MatMul(H_trs, \"1/2\", evaluate=False)\n",
62+
"\n",
63+
"\n",
64+
"def do_trs(H):\n",
65+
" H_trs = make_trs(H)\n",
66+
" assert equal(H_trs, trs(H_trs))\n",
67+
" return trs(H)"
68+
]
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"id": "89f80956-a8d3-4b6c-9340-334c76d092a7",
73+
"metadata": {},
74+
"source": [
75+
"### Non-collinear"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"id": "e3b2d4e9-f8e4-4c50-b409-057926887d5b",
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"uu, dd, ud = symbols(\"m0 m1 m2\")\n",
86+
"H_nc = Matrix([[uu, ud], [ud.conjugate(), dd]])\n",
87+
"do_trs(H_nc)"
88+
]
89+
},
90+
{
91+
"cell_type": "markdown",
92+
"id": "82080cf9-bf53-4b4d-af96-7ae53c0b3079",
93+
"metadata": {},
94+
"source": [
95+
"### Spin-orbit"
96+
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"execution_count": null,
101+
"id": "8bcf161a-0be1-493f-b6d5-806a0a00360f",
102+
"metadata": {},
103+
"outputs": [],
104+
"source": [
105+
"uu, dd, ud, du = symbols(\"m0 m1 m2 m3\")\n",
106+
"H_soc = Matrix([[uu, ud], [du, dd]])\n",
107+
"do_trs(H_soc)"
108+
]
109+
},
110+
{
111+
"cell_type": "markdown",
112+
"id": "e762a0d9-98f8-4c35-b2d3-8fd7053b74bc",
113+
"metadata": {},
114+
"source": [
115+
"### Nambu (Delta matrix)"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"id": "d12089c2-7b11-41bc-92f1-b8cbbc4137b9",
122+
"metadata": {},
123+
"outputs": [],
124+
"source": [
125+
"S, T0, Tu, Td = symbols(\"S T0 Tu Td\")\n",
126+
"Delta = Matrix([[Tu, S + T0], [-S + T0, Td]])\n",
127+
"do_trs(Delta)"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": null,
133+
"id": "fc6fb8bf-44b6-4a7f-ab8d-f76e0cfe4f21",
134+
"metadata": {},
135+
"outputs": [],
136+
"source": []
137+
}
138+
],
139+
"metadata": {
140+
"kernelspec": {
141+
"display_name": "Python 3 (ipykernel)",
142+
"language": "python",
143+
"name": "python3"
144+
},
145+
"language_info": {
146+
"codemirror_mode": {
147+
"name": "ipython",
148+
"version": 3
149+
},
150+
"file_extension": ".py",
151+
"mimetype": "text/x-python",
152+
"name": "python",
153+
"nbconvert_exporter": "python",
154+
"pygments_lexer": "ipython3",
155+
"version": "3.11.7"
156+
}
157+
},
158+
"nbformat": 4,
159+
"nbformat_minor": 5
160+
}

src/sisl/_core/sparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ def sub(self, indices):
17831783

17841784
return csr
17851785

1786-
def transpose(self, sort=True):
1786+
def transpose(self, sort: bool = True):
17871787
"""Create the transposed sparse matrix
17881788
17891789
Parameters

src/sisl/conftest.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
""" Global sisl fixtures """
77
import logging
88
import os
9+
from functools import partial
910
from pathlib import Path
1011

1112
import numpy as np
@@ -166,7 +167,35 @@ def _path(*files):
166167
def sisl_tolerance():
167168
r32 = (1e-6, 1e-11)
168169
r64 = (1e-9, 1e-15)
169-
return {np.float32: r32, np.float64: r64, np.complex64: r32, np.complex128: r64}
170+
return {
171+
np.float32: r32,
172+
np.float32(0).dtype: r32,
173+
np.float64: r64,
174+
np.float64(0).dtype: r64,
175+
np.complex64: r32,
176+
np.complex64(0).dtype: r32,
177+
np.complex128: r64,
178+
np.complex128(0).dtype: r64,
179+
None: r64,
180+
}
181+
182+
183+
@pytest.fixture(scope="session")
184+
def sisl_allclose(sisl_tolerance):
185+
def factory(dtype):
186+
atol, rtol = sisl_tolerance[dtype]
187+
return partial(np.allclose, atol=atol, rtol=rtol)
188+
189+
return {key: factory(key) for key in sisl_tolerance.keys()}
190+
191+
192+
@pytest.fixture(scope="session")
193+
def sisl_isclose(sisl_tolerance):
194+
def factory(dtype):
195+
atol, rtol = sisl_tolerance[dtype]
196+
return partial(np.isclose, atol=atol, rtol=rtol)
197+
198+
return {key: factory(key) for key in sisl_tolerance.keys()}
170199

171200

172201
@pytest.fixture(scope="session", params=[np.float32, np.float64])

src/sisl/io/ham.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def write_hamiltonian(
274274
if hermitian:
275275
herm_acc = kwargs.get("herm_acc", 1e-6)
276276

277-
h_ht = H - H.transpose(hermitian=True)
277+
h_ht = H - H.transpose(conjugate=True, spin=True)
278278
amax = np.abs(h_ht._csr._D).max()
279279
if amax > herm_acc:
280280
warn(

src/sisl/io/siesta/_help.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ def _csr_from(col_from, csr):
101101
def _mat_siesta2sisl(M) -> None:
102102
"""Conversion of Siesta spin matrices to sisl spin matrices
103103
104-
The matrices from Siesta are given in a format adheering to the following
104+
The matrices from Siesta are given in a format adhering to the following
105105
concept.
106106
107107
There are two cases:
108108
109-
1. A non-colinear calculation:
109+
1. A non-collinear calculation:
110110
111111
Siesta uses this convention:
112112
@@ -123,7 +123,7 @@ def _mat_siesta2sisl(M) -> None:
123123
H12 == H[:, 2] + 1j H[:, 3] # spin-box Hermitian
124124
H21 == H[:, 2] - 1j H[:, 3]
125125
126-
2. A spin-orbit calculation:
126+
2. A spin-orbit calculation + Nambu:
127127
128128
Siesta uses this convention:
129129

src/sisl/physics/_matrix_ddk.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ from sisl._core._dtypes cimport floats_st
1111
from ._matrix_phase3 import *
1212
from ._phase import *
1313

14-
__all__ = ["matrix_ddk", "matrix_ddk_nc", "matrix_ddk_diag",
14+
__all__ = [
15+
"matrix_ddk",
16+
"matrix_ddk_nc",
17+
"matrix_ddk_diag",
1518
"matrix_ddk_so",
1619
"matrix_ddk_nambu"
1720
]

0 commit comments

Comments
 (0)