Skip to content

Commit

Permalink
also load generators via reference to ROTATIONS_... and `TRANSLA…
Browse files Browse the repository at this point in the history
…TIONS_...`

 - additionally, structure a few things more consistently in the encoding of operations & also rename some stuff
  • Loading branch information
thchr committed Jan 11, 2024
1 parent 69a187b commit 76c7af9
Show file tree
Hide file tree
Showing 948 changed files with 985 additions and 277 deletions.
4 changes: 2 additions & 2 deletions build/crawl_and_write_generators_pgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let D = 3
gens_str = crawl_pg_generators_xyzt(pgnum, D, pgiuc)
end

unmangled_pgiuc = Crystalline.unmangle_pgiuclab(pgiuc)
unmangled_pgiuc = Crystalline._unmangle_pgiuclab(pgiuc)
filename = (@__DIR__)*"/../data/generators/pgs/$(D)d/$(unmangled_pgiuc).csv"
open(filename; write=true, create=true, truncate=true) do io
first = true
Expand All @@ -85,7 +85,7 @@ let D = 2
for (pgnum, pgiuc) in enumerate(Crystalline.PG_IUCs[D])
gens_str = crawl_pg_generators_xyzt(pgnum, D)

unmangled_pgiuc = Crystalline.unmangle_pgiuclab(pgiuc)
unmangled_pgiuc = Crystalline._unmangle_pgiuclab(pgiuc)
filename = (@__DIR__)*"/../data/generators/pgs/$(D)d/$(unmangled_pgiuc).csv"
open(filename; write=true, create=true, truncate=true) do io
first = true
Expand Down
2 changes: 1 addition & 1 deletion build/crawl_and_write_pgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function __crawl_and_write_3d_pgirreps()
# "test/data/xyzt-operations/pgs/..."; note that we explicitly checked the
# sorting and # equivalence of operations when pgirs was crawled above (cf. flag
# `consistency_checks=true`)
unmangled_pgiuc = Crystalline.unmangle_pgiuclab(pgiuc) # replace '/'s by '_slash_'s
unmangled_pgiuc = Crystalline._unmangle_pgiuclab(pgiuc) # replace '/'s by '_slash_'s
irreps_file[unmangled_pgiuc*"/matrices"] = matrices
irreps_file[unmangled_pgiuc*"/realities"] = Integer.(realities)
irreps_file[unmangled_pgiuc*"/cdmls"] = cdmls
Expand Down
2 changes: 1 addition & 1 deletion data/misc/ISOTROPY/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ISOTROPY ISO-IR dataset
These file `CIR_data.txt` and `PIR_data.txt` are sourced from the
The files `CIR_data.txt` and `PIR_data.txt` are sourced from the
[ISOTROPY software's ISO-IR dataset](https://stokes.byu.edu/iso/irtables.php)
and contain data needed to generate *space group* irreps.
In ISOTROPY, the data files are extracted in Fortran using associated files
Expand Down
33 changes: 20 additions & 13 deletions src/Crystalline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export SymOperation, # types
SpaceGroup, PointGroup, LittleGroup,
CharacterTable,
# operations on ...
matrix, xyzt, # ::SymOperation
getindex, rotation, translation,
issymmorph,
matrix, xyzt, # ::AbstractOperation
rotation, translation,
issymmorph, # ::SymOperation
num, order, operations, # ::AbstractGroup
klabel, characters, # ::AbstractIrrep
classcharacters,
Expand All @@ -83,16 +83,24 @@ include("magnetic/types.jl")
export MSymOperation, MSpaceGroup

include("tables/rotation_translation.jl")
include("tables/pointgroup.jl")
include("tables/spacegroup.jl")
include("tables/subperiodicgroup.jl")
include("tables/mspacegroup.jl")
include("tables/groups/pointgroup.jl")
include("tables/groups/spacegroup.jl")
include("tables/groups/subperiodicgroup.jl")
include("tables/groups/mspacegroup.jl")
include("tables/generators/pointgroup.jl")
include("tables/generators/spacegroup.jl")
include("tables/generators/subperiodicgroup.jl")

include("assembly/groups/pointgroup.jl")
include("assembly/groups/spacegroup.jl")
include("assembly/groups/subperiodicgroup.jl")
include("assembly/groups/mspacegroup.jl")
export pointgroup, spacegroup, subperiodicgroup, mspacegroup

include("group-assembly/assemble_pointgroup.jl")
include("group-assembly/assemble_spacegroup.jl")
include("group-assembly/assemble_subperiodicgroup.jl")
include("group-assembly/assemble_mspacegroup.jl")
include("assembly/generators/pointgroup.jl")
include("assembly/generators/spacegroup.jl")
include("assembly/generators/subperiodicgroup.jl")
export generate, generators

include("show.jl") # custom printing for structs defined in src/types.jl

Expand All @@ -102,8 +110,7 @@ include("symops.jl") # symmetry operations for space, plane, and line groups
export @S_str, compose,
issymmorph, littlegroup, orbit,
reduce_ops,
issubgroup, isnormal,
generate, generators
issubgroup, isnormal

include("conjugacy.jl") # construction of conjugacy classes
export classes, is_abelian
Expand Down
17 changes: 17 additions & 0 deletions src/assembly/generators/pointgroup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function generators(iuclab::String, ::Type{PointGroup{D}}=PointGroup{3}) where D
@boundscheck _check_valid_pointgroup_label(iuclab, D)
codes = PG_GENS_CODES_Ds[D][iuclab]

# convert `codes` to `SymOperation`s and add to `operations`
operations = Vector{SymOperation{D}}(undef, length(codes))
for (n, code) in enumerate(codes)
op = SymOperation{D}(get_indexed_rotation(code, Val{D}()), zero(SVector{D,Float64}))
operations[n] = op
end

return operations
end
function generators(pgnum::Integer, ::Type{PointGroup{D}}, setting::Integer=1) where D
iuclab = pointgroup_num2iuc(pgnum, Val(D), setting)
return generators(iuclab, PointGroup{D})
end
93 changes: 93 additions & 0 deletions src/assembly/generators/spacegroup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""
generators(num::Integer, T::Type{AbstractGroup{D}}[, optargs])
generators(pgiuc::String, T::PointGroup{D}}) --> Vector{SymOperation{D}}
Return the generators of the group type `T` which may be a `SpaceGroup{D}` or a
`PointGroup{D}` parameterized by its dimensionality `D`. Depending on `T`, the group is
determined by inputting as the first argument:
- `SpaceGroup{D}`: the space group number `num::Integer`.
- `PointGroup{D}`: the point group IUC label `pgiuc::String` (see also
[`pointgroup(::String)`) or the canonical point group number `num::Integer`, which can
optionally be supplemented by an integer-valued setting choice `setting::Integer` (see
also [`pointgroup(::Integer, ::Integer, ::Integer)`](@ref)]).
- `SubperiodicGroup{D}`: the subperiodic group number `num::Integer`.
Setting choices match those in [`spacegroup`](@ref), [`pointgroup`](@ref), and
[`subperiodicgroup`](@ref).
Iterated composition of the returned symmetry operations will generate all operations of the
associated space or point group (see [`generate`](@ref)).
As an example, `generate(generators(num, `SpaceGroup{D}))` and `spacegroup(num, D)` return
identical operations (with different sorting typically); and similarly so for point and
subperiodic groups.
## Example
Generators of space group 200:
```jldoctest
julia> generators(200, SpaceGroup{3})
4-element Vector{SymOperation{3}}:
2₀₀₁
2₀₁₀
3₁₁₁⁺
-1
```
Generators of point group m-3m:
```jldoctest
julia> generators("2/m", PointGroup{3})
2-element Vector{SymOperation{3}}:
2₀₁₀
-1
```
Generators of the Frieze group 𝓅2mg:
```jldoctest
julia> generators(7, SubperiodicGroup{2, 1})
2-element Vector{SymOperation{2}}:
2
{m₁₀|½,0}
```
## Citing
Please cite the original data sources if used in published work:
- Space groups:
[Aroyo et al., Z. Kristallogr. Cryst. Mater. **221**, 15
(2006)](https://doi.org/10.1524/zkri.2006.221.1.15);
- Point group: Bilbao Crystallographic Server's
[2D and 3D GENPOS](https://www.cryst.ehu.es/cryst/get_point_genpos.html);
- Subperiodic groups: Bilbao Crystallographic Server's
[SUBPERIODIC GENPOS](https://www.cryst.ehu.es/subperiodic/get_sub_gen.html).
## Extended help
Note that the returned generators are not guaranteed to be the smallest possible set of
generators; i.e., there may exist other generators with fewer elements (an example is space
group 168 (P6), for which the returned generators are `[2₀₀₁, 3₀₀₁⁺]` even though the group
could be generated by just `[6₀₀₁⁺]`).
The returned generators, additionally, are not guaranteed to be
[minimal](https://en.wikipedia.org/wiki/Generating_set_of_a_module), i.e., they may include
proper subsets that generate the group themselves (e.g., in space group 75 (P4), the
returned generators are `[2₀₀₁, 4₀₀₁⁺]` although the subset `[4₀₀₁⁺]` is sufficient to
generate the group).
The motivation for this is to expose as similar generators as possible for similar crystal
systems (see e.g. Section 8.3.5 of the International Tables of Crystallography, Vol. A,
Ed. 5 (ITA) for further background).
Note also that, contrary to conventions in ITA, the identity operation is excluded among the
returned generators (except in space group 1) since it composes trivially and adds no
additional context.
"""
function generators(sgnum::Integer, ::Type{SpaceGroup{D}}=SpaceGroup{3}) where D
@boundscheck _check_valid_sgnum_and_dim(sgnum, D)
codes = SG_GENS_CODES_Vs[D][sgnum]

# convert `codes` to `SymOperation`s and add to `operations`
operations = Vector{SymOperation{D}}(undef, length(codes))
_include_symops_from_codes!(operations, codes; add_identity=false)

return operations
end
32 changes: 32 additions & 0 deletions src/assembly/generators/subperiodicgroup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
generators(num::Integer, ::Type{SubperiodicGroup{D,P}}) --> ::Vector{SymOperation{D}}
Return a canonical set of generators for the subperiodic group `num` of embedding dimension
`D` and periodicity dimension `P`. See also [`subperiodicgroup`](@ref).
See also [`generators(::Integer, ::Type{SpaceGroup})`](@ref) and information therein.
## Example
```jldoctest
julia> generators(7, SubperiodicGroup{2, 1})
2-element Vector{SymOperation{2}}:
2
{m₁₀|½,0}
```
## Data sources
The generators returned by this function were originally retrieved from the [Bilbao
Crystallographic Database, SUBPERIODIC GENPOS](https://www.cryst.ehu.es/subperiodic/get_sub_gen.html).
"""
function generators(num::Integer, ::Type{SubperiodicGroup{D,P}}) where {D,P}
@boundscheck _check_valid_subperiodic_num_and_dim(num, D, P)
codes = SUBG_GENS_CODES_Vs[(D,P)][num]

# convert `codes` to `SymOperation`s and add to `operations`
operations = Vector{SymOperation{D}}(undef, length(codes))
_include_symops_from_codes!(operations, codes; add_identity=false)

return operations
end
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ end
end

function _pointgroup(iuclab::String, pgnum::Integer, Dᵛ::Val{D}) where D
codes = D == 3 ? PG_CODES_3D_D[iuclab] :
D == 2 ? PG_CODES_2D_D[iuclab] :
PG_CODES_1D_D[iuclab]
codes = PG_CODES_Ds[D][iuclab]

Nop = (length(codes)+1) # number of operations
operations = Vector{SymOperation{D}}(undef, Nop)
operations[1] = one(SymOperation{D})
for (n, code) in enumerate(codes)
op = SymOperation{D}(get_indexed_rotation(code[1], Dᵛ),
op = SymOperation{D}(get_indexed_rotation(code, Dᵛ),
zero(SVector{D,Float64}))
operations[n+1] = op
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


"""
spacegroup(sgnum::Integer, ::Val{D}=Val(3))
spacegroup(sgnum::Integer, D::Integer) --> SpaceGroup{D}
Expand Down Expand Up @@ -32,11 +30,7 @@ The associated citation is: ([Aroyo et al., Z. Kristallogr. Cryst. Mater. **221*
"""
function spacegroup(sgnum, Dᵛ::Val{D}=Val(3)) where D
@boundscheck _check_valid_sgnum_and_dim(sgnum, D)

codes = D == 3 ? SG_CODES_3D_V[sgnum] :
D == 2 ? SG_CODES_2D_V[sgnum] :
D == 1 ? SG_CODES_1D_V[sgnum] :
error("unreachable; D is invalid but boundscheck assumed valid")
codes = SG_CODES_Vs[D][sgnum]

cntr = centering(sgnum, D)
Ncntr = centering_volume_fraction(cntr, Dᵛ)
Expand All @@ -56,12 +50,16 @@ function spacegroup(sgnum, Dᵛ::Val{D}=Val(3)) where D
end
spacegroup(sgnum::Integer, D::Integer) = spacegroup(sgnum, Val(D))

function _include_symops_from_codes!(operations::Vector{SymOperation{D}}, codes) where D
operations[1] = one(SymOperation{D}) # add trivial identity op separately and manually
function _include_symops_from_codes!(
operations::Vector{SymOperation{D}}, codes;
add_identity::Bool = true) where D
if add_identity # add trivial identity operation separately and manually
operations[1] = one(SymOperation{D})
end
for (n, code) in enumerate(codes)
op = SymOperation{D}(get_indexed_rotation(code[1], Val{D}()),
get_indexed_translation(code[2], Val{D}()))
operations[n+1] = op
operations[n+add_identity] = op
end
return operations
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ Crystallographic Database, SUBPERIODIC GENPOS](https://www.cryst.ehu.es/subperio
"""
function subperiodicgroup(num::Integer, Dᵛ::Val{D}=Val(3), Pᵛ::Val{P}=Val(2)) where {D, P}
@boundscheck _check_valid_subperiodic_num_and_dim(num, D, P)

codes = D == 3 && P == 2 ? LAYER_CODES_V[num] :
D == 3 && P == 1 ? ROD_CODES_V[num] :
D == 2 && P == 1 ? FRIEZE_CODES_V[num] :
error("unreachable; (D,P) input is invalid but boundscheck assumed valid")
codes = SUBG_CODES_Vs[(D,P)][num]

cntr = centering(num, D, P)
Ncntr = centering_volume_fraction(cntr, Dᵛ, Pᵛ)
Expand Down
27 changes: 3 additions & 24 deletions src/pointgroup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,6 @@ schoenflies(pg::PointGroup) = PG_IUC2SCHOENFLIES[iuc(pg)]
return @inbounds iucs[setting]
end

# --- Point group generators ---
unmangle_pgiuclab(iuclab) = replace(iuclab, "/"=>"_slash_")

function read_pggens_xyzt(iuclab::String, D::Integer)
@boundscheck D (1,2,3) && _throw_invalid_dim(D)
@boundscheck iuclab PG_IUCs[D] && throw(DomainError(iuclab, "iuc label not found in database (see possible labels in PG_IUCs[D])"))

filepath = joinpath(DATA_DIR, "generators/pgs/"*string(D)*"d/"*unmangle_pgiuclab(iuclab)*".csv")

return readlines(filepath)
end

function generators(iuclab::String, ::Type{PointGroup{D}}=PointGroup{3}) where D
ops_str = read_pggens_xyzt(iuclab, D)
return SymOperation{D}.(ops_str)
end
function generators(pgnum::Integer, ::Type{PointGroup{D}}, setting::Integer=1) where D
iuclab = pointgroup_num2iuc(pgnum, Val(D), setting)
ops_str = read_pggens_xyzt(iuclab, D)

return SymOperation{D}.(ops_str)
end

# --- POINT GROUPS VS SPACE & LITTLE GROUPS ---
function find_parent_pointgroup(g::AbstractGroup{D}) where D
# Note: this method will only find parent point groups with the same setting (i.e.
Expand All @@ -109,9 +86,11 @@ function find_parent_pointgroup(g::AbstractGroup{D}) where D
end

# --- POINT GROUP IRREPS ---
_unmangle_pgiuclab(iuclab) = replace(iuclab, "/"=>"_slash_")

# loads 3D point group data from the .jld2 file opened in `PGIRREPS_JLDFILE`
function _load_pgirreps_data(iuclab::String)
jldgroup = PGIRREPS_JLDFILE[][unmangle_pgiuclab(iuclab)]
jldgroup = PGIRREPS_JLDFILE[][_unmangle_pgiuclab(iuclab)]
matrices::Vector{Vector{Matrix{ComplexF64}}} = jldgroup["matrices"]
realities::Vector{Int8} = jldgroup["realities"]
cdmls::Vector{String} = jldgroup["cdmls"]
Expand Down
Loading

2 comments on commit 76c7af9

@thchr
Copy link
Owner Author

@thchr thchr commented on 76c7af9 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/98714

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 76c7af9adefa8a376cb78a01ae0cdbf00a9d986e
git push origin v0.5.0

Please sign in to comment.