Skip to content

Commit ae919ca

Browse files
committed
expand tests of symmetry analysis
1 parent 8cfbd1f commit ae919ca

2 files changed

Lines changed: 86 additions & 14 deletions

File tree

src/symmetry_analysis.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ and are otherwise initialized by the function.
8383
8484
The symmetry eigenvalues are returned as a matrix, with rows running over the elements of
8585
`ops` and columns running over the bands of `ptbm`.
86+
87+
!!! note
88+
The inputs `ops`, `k`, and `lg` must be provided in a primitive setting. See
89+
Crystalline.jl's `primitivize`.
8690
"""
8791
function symmetry_eigenvalues(
8892
ptbm::ParameterizedTightBindingModel{D},
@@ -112,7 +116,7 @@ function symmetry_eigenvalues(
112116
Θᴳ = reciprocal_translation_phase(orbital_positions(ptbm), G) # TODO: preallocate & fill
113117
ρ = sgrep(k)
114118
for (n, v) in enumerate(eachcol(vs))
115-
v_kpG = Θᴳ * v # correct the phase factor
119+
v_kpG = Θᴳ * v # incorporate phase factor
116120
symeigs[j, n] = dot(v_kpG, ρ, v)
117121
# TODO: preallocate and `mul!` the `Θᴳ * v` term to avoid allocations
118122
end
@@ -123,10 +127,9 @@ end
123127
function symmetry_eigenvalues(
124128
ptbm::ParameterizedTightBindingModel{D},
125129
lg::LittleGroup{D},
126-
sgreps::AbstractVector{SiteInducedSGRepElement{D}} = sgrep_induced_by_siteir.(
127-
Ref(ptbm.tbm.cbr),
128-
lg,
129-
),
130+
sgreps::AbstractVector{SiteInducedSGRepElement{D}} = begin
131+
sgrep_induced_by_siteir.(Ref(ptbm.tbm.cbr), lg)
132+
end,
130133
) where D
131134
kv = position(lg)
132135
isspecial(kv) || error("input k-point has free parameters")

test/symmetry_analysis.jl

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,92 @@
11
using Test
2-
using SymmetricTightBinding, Crystalline
2+
using SymmetricTightBinding
3+
using Crystalline
4+
using Crystalline: free
35

4-
@testset "Symmetry analysis" begin
6+
@testset "Symmetry analysis (documentation example)" begin
7+
# Example 1
8+
sgnum = 17 # plane group p6mm
9+
brs = calc_bandreps(sgnum, Val(2)) # band representations
10+
cbr = @composite brs[5] # (2b|A₁) EBR
11+
tbm = tb_hamiltonian(cbr) # tight-binding model (nearest neigbors)
12+
ptbm = tbm([0, 1]) # zero self-energy, nonzero nearest-neighbor hopping
13+
ns = collect_compatible(ptbm)
14+
@test only(ns) == SymmetryVector(cbr) == SymmetryVector(CompositeBandRep(ptbm))
15+
16+
# Example 2
17+
cbr′ = @composite brs[3] + brs[5] # (2a|A₁) + (3c|B₂)
18+
tbm′ = tb_hamiltonian(cbr′)
19+
ptbm′ = tbm′([2.5, 0, 0.2, 0, -1, 0])
20+
ns′ = collect_compatible(ptbm′)
21+
@test length(ns′) == 1 # bands are overlapping and not separable
22+
@test only(ns′) == SymmetryVector(cbr′)
23+
24+
ptbm′′ = tbm′([2.5, 0, 0.2, 0, -1, .5]) # turn on hybridization and split bands
25+
ns′′ = collect_compatible(ptbm′′)
26+
@test length(ns′′) == 2 # bands are overlapping and not separable
27+
@test ns′′[1] brs[[3, 5]]
28+
@test ns′′[2] brs[[3, 5]]
29+
@test sum(ns′′) == SymmetryVector(cbr′)
30+
end
31+
32+
@testset "Symmetry analysis (full scan over EBRs)" begin
33+
# construct a tb-model for every EBR and verify that `collect_compatible` returns a set
34+
# of symmetry vectors whose sum is equal to the underlying EBR's: note that we cannot
35+
# generally require that `collect_compatible` returns a _single_ symmetry vector
36+
# equaling the EBR's symmetry vector, since the EBR might be decomposable (either into
37+
# fragile or genuinely topological EBRs): i.e., we don't know if the model is a single
38+
# connected band or not, only what the "sum" of symmetry vectors will be
539
for D in 1:3
6-
for sgnum in MAX_SGNUM[D]
7-
@testset "Space group $sgnum in dimension $D" begin
40+
αβγ = D == 1 ? [.1] : D == 2 ? [.1, .2] : [.1, .2, .3] # for `pin_free!`
41+
println("--- D = $D ---")
42+
for sgnum in 1:MAX_SGNUM[D]
43+
showed_sgnum = false
44+
#@testset "Space group $sgnum in dimension $D" begin
845
brs = calc_bandreps(sgnum, Val(D))
946
for i in eachindex(brs)
1047
coefs = zeros(length(brs))
1148
coefs[i] = 1
1249
cbr = CompositeBandRep(coefs, brs)
13-
ptbm = tb_hamiltonian(cbr)(randn(length(cbr)))
1450

15-
v = SymmetryVector(cbr)
16-
v_model = collect_compatible(ptbm)
51+
# if the EBR had any free parameters associated with its Wyckoff
52+
# position, we must pin them, using `pin_free!`
53+
iszero(free(position(brs[i]))) || pin_free!(brs, i=>αβγ)
54+
55+
# build a random tight-binding model for the `i`th EBR
56+
tbm = try
57+
tb_hamiltonian(cbr)
58+
catch e
59+
showed_sgnum || (showed_sgnum = true; println("#$sgnum"))
60+
println(" brs[$i] = $cbr:\t`tb_hamiltonian` error")
61+
continue
62+
end
63+
ptbm = tbm(randn(length(tbm)))
1764

18-
@test v == v_model[1] # check that the symmetry vector is compatible with the model
65+
# check that the symmetry vector returned by `collect_compatible` is
66+
# what we started with (i.e. equal to `cbr`)
67+
try
68+
ns = collect_compatible(ptbm)
69+
if length(ns) == 0
70+
showed_sgnum || (showed_sgnum = true; println("#$sgnum:"))
71+
println(" brs[$i] = $cbr:\tfailed to collect any compatible symmetry vectors")
72+
else
73+
cond = sum(ns) == SymmetryVector(cbr)
74+
if !cond
75+
showed_sgnum || (showed_sgnum = true; println("#$sgnum:"))
76+
println(" brs[$i] = $cbr:\tsymmetry vector discrepancy")
77+
println(" n = $(sum(ns))\n cbr = $(SymmetryVector(cbr))")
78+
end
79+
end
80+
catch e
81+
showed_sgnum || (showed_sgnum = true; println("#$sgnum:"))
82+
println(" brs[$i] = $cbr:\t`collect_compatible` error")
83+
println(" ", e)
84+
continue
85+
end
86+
#@test cbr == only(collect_compatible(ptbm))
1987
end # for br in brs
20-
end # @testset "Space group $sgnum in dimension $D"
88+
#end # @testset "Space group $sgnum in dimension $D"
2189
end # for sgnum in MAX_SGNUM[D]
90+
println()
2291
end # for D in 1:3
2392
end # @testset "Symmetry analysis"

0 commit comments

Comments
 (0)