Skip to content

Commit

Permalink
don't import/export/extend vec: import & extend parent
Browse files Browse the repository at this point in the history
  • Loading branch information
thchr committed Oct 14, 2021
1 parent 55ccce2 commit 8ce35d8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Crystalline"
uuid = "ae5e2be0-a263-11e9-351e-f94dad1eb351"
authors = ["Thomas Christensen <tchr@mit.edu>"]
version = "0.4.9"
version = "0.4.10"

[deps]
Bravais = "ada6cbde-b013-4edf-aa94-f6abe8bd6e6b"
Expand Down
2 changes: 1 addition & 1 deletion build/crawl_and_write_wyckpos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function _write_wyckpos_3d(sgnum::Integer)
wps = crawl_wyckpos_3d(sgnum)
open((@__DIR__)*"/../data/wyckpos/3d/"*string(sgnum)*".csv", "w+") do io
for (idx, wp) in enumerate(wps)
qstr = strip(string(vec(wp)), ('[',']'))
qstr = strip(string(parent(wp)), ('[',']'))
for repl in ('α'=>'x', 'β'=>'y', 'γ'=>'z', " "=>"")
qstr = replace(qstr, repl)
end
Expand Down
8 changes: 4 additions & 4 deletions build/setup_2d_band_representations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ function reduce_orbits!(orbits::Vector{WyckPos{D}}, cntr::Char,
orbits′ = primitivize.(orbits, cntr)
i = 2 # start from second element
while i length(orbits)
wp′ = vec(orbits′[i])
wp′ = parent(orbits′[i])
was_removed = false
for j in 1:i-1
δᵢⱼ = wp′ - vec(orbits′[j])
δᵢⱼ = wp′ - parent(orbits′[j])
if (iszero(free(δᵢⱼ)) &&
all(x->abs(rem(x, 1.0, RoundNearest)) < DEFAULT_ATOL, constant(δᵢⱼ)))
# -> means it's equivalent to a previously "greenlit" orbit
Expand All @@ -122,7 +122,7 @@ function reduce_cosets!(ops::Vector{SymOperation{D}}, wp::WyckPos{D},
while i length(ops) && i length(orbits)
wpᵢ = orbits[i]
opᵢ = ops[i]
if ops[i]*vec(wp) wpᵢ
if ops[i]*parent(wp) wpᵢ
i += 1 # then ops[i] is indeed a "generator" of wpᵢ
else
deleteat!(ops, i)
Expand Down Expand Up @@ -158,7 +158,7 @@ function induce_bandrep(siteir::SiteIrrep{D}, h::SymOperation{D}, kv::KVec{D}) w
# sum over all the (non-centering-equivalent) wyckoff positions/cosets in the orbit
χᴳₖ = zero(ComplexF64)
for (wpα′, gα′) in zip(orbits, gαs)
tα′α′ = constant(vec(h*wpα′) - vec(wpα′)) # TODO: <-- explain why we only need constant part here?
tα′α′ = constant(parent(h*wpα′) - parent(wpα′)) # TODO: <-- explain why we only need constant part here?
opᵗ = SymOperation(-tα′α′)

gα′⁻¹ = inv(gα′)
Expand Down
8 changes: 4 additions & 4 deletions src/Crystalline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import Base: getindex, setindex!, # → iteration/AbstractArray interface
IndexStyle, size, copy, #
iterate,
string, isapprox, zero,
readuntil, vec, show, summary,
readuntil, show, summary,
*, +, -, ==, ImmutableDict,
isone, one,
convert
convert, parent
import LinearAlgebra: inv


Expand Down Expand Up @@ -65,7 +65,7 @@ export SymOperation, # types
israyrep, kvec, # ::LGIrrep
isspecial, translations,
dim, parts, # ::KVec & RVec
vec, irreplabels, klabels, kvecs, # ::BandRep & ::BandRepSet
irreplabels, klabels, kvecs, # ::BandRep & ::BandRepSet
isspinful

include("show.jl") # custom printing for structs defined in src/types.jl
Expand All @@ -88,7 +88,7 @@ export classes, is_abelian

include("wyckoff.jl") # wyckoff positions and site symmetry groups
export get_wycks, WyckPos,
multiplicity, vec,
multiplicity,
SiteGroup, orbit, cosets, wyck,
findmaximal

Expand Down
22 changes: 12 additions & 10 deletions src/wyckoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ struct WyckPos{D} <: AbstractVec{D}
letter :: Char
qv :: RVec{D} # associated with a single representative
end
vec(wp::WyckPos) = wp.qv
free(wp::WyckPos) = free(vec(wp))
constant(wp::WyckPos) = constant(vec(wp))
parent(wp::WyckPos) = wp.qv
free(wp::WyckPos) = free(parent(wp))
constant(wp::WyckPos) = constant(parent(wp))

multiplicity(wp::WyckPos) = wp.mult
label(wp::WyckPos) = string(multiplicity(wp), wp.letter)
transform(wp::WyckPos, P::AbstractMatrix{<:Real}) = typeof(wp)(wp.mult, wp.letter, transform(vec(wp), P))
function transform(wp::WyckPos, P::AbstractMatrix{<:Real})
return typeof(wp)(wp.mult, wp.letter, transform(parent(wp), P))
end

function show(io::IO, ::MIME"text/plain", wp::WyckPos)
print(io, wp.mult, wp.letter, ": ")
show(io, MIME"text/plain"(), vec(wp))
show(io, MIME"text/plain"(), parent(wp))
end

# Site symmetry groups
Expand Down Expand Up @@ -49,7 +51,7 @@ wyck(g::SiteGroup) = g.wp

function summary(io::IO, g::SiteGroup)
print(io, typeof(g), " #", num(g), " at ", label(wyck(g)), " = ")
show(io, MIME"text/plain"(), vec(wyck(g)))
show(io, MIME"text/plain"(), parent(wyck(g)))
print(io, " with ", length(g), " operations")
end

Expand Down Expand Up @@ -115,7 +117,7 @@ function compose(op::SymOperation{D}, qv::RVec{D}) where D
return RVec{D}(cnst′, free′)
end
function compose(op::SymOperation{D}, wp::WyckPos{D}) where D
WyckPos{D}(multiplicity(wp), wp.letter, compose(op, vec(wp)))
WyckPos{D}(multiplicity(wp), wp.letter, compose(op, parent(wp)))
end

(*)(op::SymOperation{D}, qv::RVec{D}) where D = compose(op, qv)
Expand Down Expand Up @@ -195,7 +197,7 @@ function SiteGroup(sg::SpaceGroup{D}, wp::WyckPos{D}) where D
siteops = Vector{SymOperation{D}}(undef, Nsite)
cosets = Vector{SymOperation{D}}(undef, Ncoset)
orbitqvs = Vector{RVec{D}}(undef, Ncoset)
qv = vec(wp)
qv = parent(wp)

# both cosets and site symmetry group contains the identity operation, and the orbit
# automatically contains qv; add them outside loop
Expand Down Expand Up @@ -312,7 +314,7 @@ function findmaximal(sitegs::AbstractVector{SiteGroup{D}}) where D
maximal = Int[]
for (idx, g) in enumerate(sitegs)
wp = wyck(g)
v = vec(wp)
v = parent(wp)
N = order(g)

# if `wp` is "special" (i.e. has no "free" parameters), then it must
Expand All @@ -331,7 +333,7 @@ function findmaximal(sitegs::AbstractVector{SiteGroup{D}}) where D

wp′_orbit = orbit(g′) # must check for all orbits of wp′ in general
for wp′′ in wp′_orbit
v′ = vec(wp′′)
v′ = parent(wp′′)
if _can_intersect(v, v′) # `wp′` can "intersect" `wp` and is higher order
has_higher_sym_nearby = true
break
Expand Down
2 changes: 1 addition & 1 deletion test/wyckoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using Crystalline: constant, free
g = SiteGroup(sg, wp)
@test g isa SiteGroup

qv = vec(wp)
qv = parent(wp)
# test that ops in `g` leave the Wyckoff position `wp` invariant
for op in g
qv′ = op*qv
Expand Down

0 comments on commit 8ce35d8

Please sign in to comment.