Skip to content

Commit

Permalink
Tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Oct 10, 2024
1 parent 89c0781 commit faa0804
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/Symmetry/Crystal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ function crystal_from_symops(latvecs::Mat3, positions::Vector{Vec3}, types::Vect
all_types = String[]
classes = Int[]

# Fill atom positions by applying all symops
# Fill atom positions by applying all symops. See crystallographic_orbit
# for similar logic.
for i = eachindex(positions)
for s = symops
x = wrap_to_unit_cell(transform(s, positions[i]); symprec)
Expand Down Expand Up @@ -455,11 +456,11 @@ end

function get_wyckoff(cryst::Crystal, i::Int)
(; classes, positions, sg_number, sg_setting, symprec) = cryst
c = classes[i]
rs = positions[findall(==(c), classes)]
rs_std = [transform(sg_setting, r) for r in rs]
wyckoff = find_wyckoff_for_orbit(sg_number, rs_std; symprec)
@assert wyckoff.multiplicity length(rs) / det(sg_setting.R)
isnothing(sg_number) || isnothing(sg_setting) && return nothing
r = transform(sg_setting, positions[i])
wyckoff = find_wyckoff_for_position(sg_number, r; symprec)
cell_multiplicity = count(==(classes[i]), classes)
@assert wyckoff.multiplicity cell_multiplicity / abs(det(sg_setting.R))
return wyckoff
end

Expand Down Expand Up @@ -777,7 +778,6 @@ function hyperkagome_crystal(; a=1.0)
# https://materials.springer.com/isp/crystallographic/docs/sd_1723194
x = 0.141
cryst = Crystal(latvecs, [[1/8, x, x+1/4]], 213)
@assert get_wyckoff(cryst, 1).letter = 'Z'
return cryst
end

Expand Down
18 changes: 18 additions & 0 deletions src/Symmetry/WyckoffData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ struct Wyckoff
sitesym :: String
end

function crystallographic_orbit(symops, r; symprec)
orbit = Vec3[]
for s in symops
r′ = transform(s, r)
if !any(is_periodic_copy.(orbit, Ref(r′); symprec))
push!(orbit, wrap_to_unit_cell(r′; symprec))
end
end
return orbit
end

function find_wyckoff_for_position(sg_number, r; symprec)
Rs, Ts = Spglib.get_symmetry_from_database(standard_setting[sg_number])
symops = SymOp.(Rs, Ts)
rs = crystallographic_orbit(symops, r; symprec)
return find_wyckoff_for_orbit(sg_number, rs; symprec)
end

function find_wyckoff_for_orbit(sg_number, rs; symprec)
for w in reverse(wyckoff_table[sg_number])
(mult, letter, sitesym, pos) = w
Expand Down
9 changes: 5 additions & 4 deletions test/test_symmetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,21 @@ end
# Inference of Wyckoff symbols
lat_vecs = lattice_vectors(1, 1, 1.2, 90, 90, 120)
cryst = Crystal(lat_vecs, [[0.2, 0.2, 1/2]], 164)
@test Sunny.get_wyckoff(cryst, 1) == Wyckoff(6, 'h', ".2.")
@test Sunny.get_wyckoff(cryst, 1) == Sunny.Wyckoff(6, 'h', ".2.")

### Check settings for monoclinic spacegroup

# Standard setting for monoclinic spacegroup 5
latvecs = lattice_vectors(1, 1.1, 1.2, 90, 100, 90)
cryst = Crystal(latvecs, [[0, 0.2, 1/2]], "C 1 2 1")
@test cryst.sg_label == "'C 2 = C 1 2 1' (5)"
@test Sunny.get_wyckoff(cryst, 1).letter == 'Z'
@test Sunny.get_wyckoff(cryst, 1) == Sunny.Wyckoff(2, 'b', "2")

# Alternative setting
latvecs2 = reduce(hcat, eachcol(latvecs)[[3, 1, 2]])
cryst2 = Crystal(latvecs2, [[1/2, 0, 0.2]], "A 1 1 2")
@test cryst2.sg_label == "'C 2 = A 1 1 2' (5)"
@test Sunny.get_wyckoff(cryst, 1).letter == 'Z'
@test Sunny.get_wyckoff(cryst, 1) == Sunny.Wyckoff(2, 'b', "2")

# Verify `cryst` is already in standard setting
@test cryst.sg_setting.R I
Expand Down Expand Up @@ -390,8 +390,9 @@ end
Modified reference frame! Transform using `rotate_operator(op, R)`.
"""

cryst = Sunny.hyperkagome_crystal()
@assert Sunny.get_wyckoff(cryst, 1) == Sunny.Wyckoff(12, 'd', "..2")
capt = IOCapture.capture() do
cryst = Sunny.hyperkagome_crystal()
print_suggested_frame(cryst, 2)
end
@test capt.output == """
Expand Down

0 comments on commit faa0804

Please sign in to comment.