Skip to content

Commit

Permalink
aggregate commit to BandGraphs utility: myriad changes, fixes, impr…
Browse files Browse the repository at this point in the history
…ovements, and new functionality
  • Loading branch information
thchr committed Oct 18, 2024
1 parent 54e109e commit 89950fc
Show file tree
Hide file tree
Showing 34 changed files with 2,076 additions and 202 deletions.
2 changes: 2 additions & 0 deletions BandGraphs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Crystalline = "ae5e2be0-a263-11e9-351e-f94dad1eb351"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
GraphsMatching = "c3af3a8c-b79e-4b01-bf44-c718d7e0e0d6"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LayeredLayouts = "f4a74d36-062a-4d48-97cd-1356bad1de4e"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
Expand Down
4 changes: 3 additions & 1 deletion BandGraphs/build/connections_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ CONNECTIONSD_2D[9] = C2[
C2(LK2(, "0, 0"), LK2(, "2α, 0")), # Γ = [0, 0] ↓ Σ = [2α, 0]
C2(LK2(:Y, "1, 0"), LK2(, "2α, 0")), # Y = [1, 0] ↓ Σ = [2α, 0]
C2(LK2(:S, "1, 2"), LK2(, "α, β")), # S = [1, 2] ↓ Ω = [α, β] (manual addition)
C2(LK2(, "0, 0"), LK2(, "α, β")), # Γ = [0, 0] ↓ Ω = [α, β] (manual addition)
]

# Plane group 10 (p4)
Expand Down Expand Up @@ -157,6 +158,7 @@ CONNECTIONSD_2D[14] = C2[
C2(LK2(, "0, 0"), LK2(, "α, 0")), # Γ = [0, 0] ↓ Σ = [α, 0]
C2(LK2(:M, "1/2, 0"), LK2(, "α, 0")), # M = [1/2, 0] ↓ Σ = [α, 0]
C2(LK2(:K, "1/3, 1/3"), LK2(, "α, β")), # K = [1/3, 1/3] ↓ Ω = [α, β] (manual addition)
C2(LK2(, "0, 0"), LK2(, "α, β")), # Γ = [0, 0] ↓ Ω = [α, β] (manual addition)
]

# Plane group 15 (p31m)
Expand Down Expand Up @@ -206,7 +208,7 @@ for sgnum in 1:MAX_SGNUM[2]
lgirsd = lgirreps(sgnum, Val(2))
sg = spacegroup(sgnum, Val(2))
for timereversal in (false, true)
timereversal && (lgirsd = Dict(klab => realify(lgirs) for (klab, lgirs) in lgirsd))
timereversal && (lgirsd = realify(lgirsd))
subts = SubductionTable{2}[]
for c in cs
push!(subts, SubductionTable(c, sg, lgirsd))
Expand Down
Binary file modified BandGraphs/data/connections/2d/connections-tr.jld2
Binary file not shown.
Binary file modified BandGraphs/data/connections/2d/connections.jld2
Binary file not shown.
Binary file modified BandGraphs/data/connections/2d/subductions-tr.jld2
Binary file not shown.
Binary file modified BandGraphs/data/connections/2d/subductions.jld2
Binary file not shown.
Binary file modified BandGraphs/data/connections/3d/connections-tr.jld2
Binary file not shown.
Binary file modified BandGraphs/data/connections/3d/connections.jld2
Binary file not shown.
Binary file modified BandGraphs/data/connections/3d/subductions-tr.jld2
Binary file not shown.
Binary file modified BandGraphs/data/connections/3d/subductions.jld2
Binary file not shown.
23 changes: 20 additions & 3 deletions BandGraphs/ext/BandGraphsGraphMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import BandGraphs: plot_flattened_bandgraph, make_vertices_dragable! # exported
## Unfolding a band graph `g` via `kg_trail`
function plot_flattened_bandgraph(
n::SymVector{D},
lgirsd::Dict{String, Vector{LGIrrep{D}}};
lgirsd::Dict{String, <:AbstractVector{LGIrrep{D}}};
timereversal=true
) where D
# TODO: take a `SubductionTable` as input?
Expand Down Expand Up @@ -66,7 +66,8 @@ function plot_flattened_bandgraph(
# manifolds (lines/planes, etc)
if isnothing(xys)
force_equal_layers = find_equal_maximal_layers(klabs_trail, bandg.partitions)
xs, ys, _ = solve_positions(Zarate(), g_trail; force_equal_layers)
force_layer = assign_layer_indices(g_trail)
xs, ys, _ = solve_positions(Zarate(), g_trail; force_layer, force_equal_layers)
ys = linearize_nonmaximal_y_coordinates(g_trail, ys)
else
xs, ys = xys
Expand All @@ -75,6 +76,12 @@ function plot_flattened_bandgraph(
plot_flattened_bandgraph(g_trail, klabs_trail, xs, ys)
end

function assign_layer_indices(g_trail)
# the x-layer of the vertices should equal the trail index of the vertex
vs = vertices(g_trail)
return vs .=> [g_trail[label_for(g_trail, i)].trailidx for i in vs]
end

function plot_flattened_bandgraph(
g_trail :: MetaGraph, # ::IsDirected
klabs_trail :: AbstractVector{<:AbstractString},
Expand Down Expand Up @@ -158,6 +165,11 @@ function find_equal_maximal_layers(klabs_trail, partitions)
# don't need to process k-label if already discovered
i seen && continue

# if this is a transition point between disconnected components (`kidx == -1` which
# maps to `klabs_trail[trailidx] = klab = ""`), there's nothing to enforce and we
# just go to the next vertex
isempty(klab) && continue

# also, check if this is a maximal manifold: if not, continue
pidx = something(findfirst(p->p.klab == klab, partitions))
partitions[pidx].maximal || continue
Expand Down Expand Up @@ -260,7 +272,12 @@ function make_vertices_dragable_bandgraph!(ax, p, g_trail)

# find related irreps, their vertex indices, and change their y-coordinates as well
vert_id = label_for(g_trail, idx)[1:2]
related_vert_idxs = findall(l->l[1:2]==(vert_id), g_trail.vertex_labels)
irlab, irmul = vert_id
irlab_normalized = replace(irlab, ""=>"") # to also move monodromy-related verts
related_vert_idxs = findall(g_trail.vertex_labels) do l
irlab′, irmul′ = l
irlab_normalized == replace(irlab′, ""=>"") && irmul == irmul′
end
for idx′ in related_vert_idxs
prev_r′ = p[:node_pos][][idx′]
p[:node_pos][][idx′] = Makie.Point(prev_r′[1], mouse_r[2])
Expand Down
54 changes: 46 additions & 8 deletions BandGraphs/src/BandGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ using BlockArrays: BlockArray, Block # for `assemble_adjacency`
# EXPORTS

export
Connection,
SubductionTable,
SymVector,
Partition,
SubGraph,
Expand All @@ -28,43 +30,76 @@ export
split_nonmaximal_nodes,
permute_subgraphs,
subduction_tables,
plot_flattened_bandgraph
plot_flattened_bandgraph,
findall_separable_vertices

# ---------------------------------------------------------------------------------------- #

# TODO: improve sharing of types between `BandGraphs` & `build/crawl_and_write_bandpaths.jl`
include("subduction-types.jl")
include("subduction-table.jl")

# ---------------------------------------------------------------------------------------- #
# DATA

const SUBDUCTIONSD_TR = Dict{Int, Vector{SubductionTable{3}}}() # `timereversal = true`
const SUBDUCTIONSD = Dict{Int, Vector{SubductionTable{3}}}() # `timereversal = false`
const SUBDUCTIONSD_TR_3D = Dict{Int, Vector{SubductionTable{3}}}() # `timereversal = true`
const SUBDUCTIONSD_3D = Dict{Int, Vector{SubductionTable{3}}}() # `timereversal = false`
const SUBDUCTIONSD_TR_2D = Dict{Int, Vector{SubductionTable{2}}}() # `timereversal = true`
const SUBDUCTIONSD_2D = Dict{Int, Vector{SubductionTable{2}}}() # `timereversal = false`
function __init__()
# TODO: Fix the awfulness here: the loading below only works if the dataset is created
# with the types from BandGraphs first - not a good circular thing to have...
datapath = joinpath(dirname(@__DIR__), "data/connections/3d/subductions-tr.jld2")
JLD2.jldopen(datapath, "r") do jldfile
for (k,v) in jldfile["subductionsd"]
SUBDUCTIONSD_TR[k] = v
SUBDUCTIONSD_TR_3D[k] = v
end
end
datapath = joinpath(dirname(@__DIR__), "data/connections/3d/subductions.jld2")
JLD2.jldopen(datapath, "r") do jldfile
for (k,v) in jldfile["subductionsd"]
SUBDUCTIONSD[k] = v
SUBDUCTIONSD_3D[k] = v
end
end
datapath = joinpath(dirname(@__DIR__), "data/connections/2d/subductions-tr.jld2")
JLD2.jldopen(datapath, "r") do jldfile
for (k,v) in jldfile["subductionsd"]
SUBDUCTIONSD_TR_2D[k] = v
end
end
datapath = joinpath(dirname(@__DIR__), "data/connections/2d/subductions.jld2")
JLD2.jldopen(datapath, "r") do jldfile
for (k,v) in jldfile["subductionsd"]
SUBDUCTIONSD_2D[k] = v
end
end
end

"""
subduction_tables(sgnum; timereversal=true) --> Vector{SubductionTable{3}}
subduction_tables(sgnum, ::Val{D}; timereversal=true) --> Vector{SubductionTable{D}}
Return a vector of `SubductionTable`s from stored tabulations, with (`timereversal = true`)
or without (`timereversal = false`) time-reversal symmetry in space group `sgnum`.
"""
function subduction_tables(sgnum; timereversal::Bool=true)
(timereversal ? SUBDUCTIONSD_TR[sgnum] : SUBDUCTIONSD[sgnum])::Vector{SubductionTable{3}}
function subduction_tables(sgnum::Integer, ::Val{D}=Val(3); timereversal::Bool=true) where D
if D == 3
if timereversal
return SUBDUCTIONSD_TR_3D[sgnum]::Vector{SubductionTable{3}}
else
return SUBDUCTIONSD_3D[sgnum]::Vector{SubductionTable{3}}
end
elseif D == 2
if timereversal
return SUBDUCTIONSD_TR_2D[sgnum]::Vector{SubductionTable{2}}
else
return SUBDUCTIONSD_2D[sgnum]::Vector{SubductionTable{2}}
end
else
throw(DomainError(D, "dimension must be 1, 2, or 3"))
end
end
function subduction_tables(sgnum::Integer, D::Integer; timereversal::Bool=true)
return subduction_tables(sgnum, Val(D); timereversal)
end

# ---------------------------------------------------------------------------------------- #
Expand All @@ -76,6 +111,9 @@ include("graphs.jl")
include("subgraph-permutations.jl")
include("graph_routing.jl")
include("unfold.jl")
include("complete-split.jl")
include("subsetsum.jl")
include("separable.jl")

# ---------------------------------------------------------------------------------------- #
# EXTENSIONS: loaded via Requires.jl on Julia versions <v1.9; otherwise via the Pkg
Expand Down
Loading

0 comments on commit 89950fc

Please sign in to comment.