Skip to content

Commit

Permalink
Standardize pretty-printing of System and StructureFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazersmoke committed Jul 10, 2023
1 parent df82f4c commit 446cd85
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/StructureFactors/StructureFactors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ struct StructureFactor{N}
processtraj! :: Function # Function to perform post-processing on sample trajectories
end

function Base.show(io::IO, ::MIME"text/plain", sf::StructureFactor)
function Base.show(io::IO, sf::StructureFactor{N}) where N
observable_names = SortedDict(value => key for (key, value) in sf.observable_ixs)
modename = N == 0 ? "Dipole" : "SU($(N))"
print(io,"StructureFactor{$modename}")
print(io,[v for v in values(observable_names)])
end

function Base.show(io::IO, ::MIME"text/plain", sf::StructureFactor{N}) where N
printstyled(io, "StructureFactor";bold=true, color=:underline)
modename = N == 0 ? "Dipole" : "SU($(N))"
print(io," ($(Base.format_bytes(Base.summarysize(sf))))\n")
print(io,"[")
if size(sf.data)[7] == 1
Expand All @@ -34,7 +42,8 @@ function Base.show(io::IO, ::MIME"text/plain", sf::StructureFactor)
print(io," | $(sf.nsamples[1]) sample")
(sf.nsamples[1] > 1) && print(io,"s")
print(io,"]\n")
print(io,"$(size(sf.data)[1]) correlations on $(sf.latsize) lattice:\n")
println(io,"Lattice: $(sf.latsize)×$(natoms(sf.crystal))")
print(io,"$(size(sf.data)[1]) correlations in $modename mode:\n")

# Reverse the dictionary
observable_names = Dict(value => key for (key, value) in sf.observable_ixs)
Expand Down
18 changes: 17 additions & 1 deletion src/System/System.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ function System(crystal::Crystal, latsize::NTuple{3,Int}, infos::Vector{SpinInfo
return ret
end

function Base.show(io::IO, sys::System{N}) where N
modename = if sys.mode==:SUN
"SU($N)"
elseif sys.mode==:dipole
"Dipole"
elseif sys.mode==:large_S
"Large-S"
else
error("Unreachable")
end
print(io,"System{$modename}[$(sys.latsize)×$(natoms(sys.crystal))]")
if !isnothing(sys.origin)
print(io,"[Reshape = $(cell_dimensions(sys))]")
end
end

function Base.show(io::IO, ::MIME"text/plain", sys::System{N}) where N
modename = if sys.mode==:SUN
"SU($N)"
Expand All @@ -86,7 +102,7 @@ function Base.show(io::IO, ::MIME"text/plain", sys::System{N}) where N
error("Unreachable")
end
printstyled(io, "System [$modename]\n"; bold=true, color=:underline)
println(io, "Cell size $(natoms(sys.crystal)), Lattice size $(sys.latsize)")
println(io, "Lattice: $(sys.latsize)×$(natoms(sys.crystal))")
if !isnothing(sys.origin)
println(io, "Reshaped cell geometry $(cell_dimensions(sys))")
end
Expand Down

0 comments on commit 446cd85

Please sign in to comment.