From 446cd858413c5fa4d85a286c9af3b7b2a509733a Mon Sep 17 00:00:00 2001 From: Sam Quinn Date: Mon, 10 Jul 2023 11:27:54 -0400 Subject: [PATCH] Standardize pretty-printing of System and StructureFactor --- src/StructureFactors/StructureFactors.jl | 13 +++++++++++-- src/System/System.jl | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/StructureFactors/StructureFactors.jl b/src/StructureFactors/StructureFactors.jl index b98277e2d..e2fdfcb2d 100644 --- a/src/StructureFactors/StructureFactors.jl +++ b/src/StructureFactors/StructureFactors.jl @@ -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 @@ -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) diff --git a/src/System/System.jl b/src/System/System.jl index 384e01d08..2c2829ba2 100644 --- a/src/System/System.jl +++ b/src/System/System.jl @@ -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)" @@ -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