-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathshow.jl
111 lines (101 loc) · 3.82 KB
/
show.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using Printf
"""
Suggested function to print AbstractSystem objects to screen
"""
function show_system(io::IO, system::AbstractSystem{D}) where {D}
bc = boundary_conditions(system)
print(io, typeof(system).name.name, "($(chemical_formula(system))")
if isinfinite(system)
print(io, ", infinite")
else
perstr = [p ? "T" : "F" for p in periodicity(system)]
print(io, ", periodic = ", join(perstr, ""))
end
if !isinfinite(system)
box_str = ["[" * join(ustrip.(bvector), ", ") * "]"
for bvector in bounding_box(system)]
bunit = unit(eltype(first(bounding_box(system))))
print(io, ", bounding_box = [", join(box_str, ", "), "]u\"$bunit\"")
end
print(io, ")")
end
function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) where {D}
bc = boundary_conditions(system)
box = bounding_box(system)
print(io, typeof(system).name.name, "($(chemical_formula(system))")
if isinfinite(system)
print(io, ", infinite")
else
perstr = [p ? "T" : "F" for p in periodicity(system)]
print(io, ", periodic = ", join(perstr, ""))
end
println(io, "):")
extra_line = false
if !isinfinite(system)
extra_line = true
box = bounding_box(system)
bunit = unit(eltype(first(bounding_box(system))))
for (i, bvector) in enumerate(box)
if i == 1
@printf io " %-17s : [" "bounding_box"
else
print(io, " "^25)
end
boxstr = [(@sprintf "%8.6g" ustrip(b)) for b in bvector]
print(io, join(boxstr, " "))
println(io, i == D ? "]u\"$bunit\"" : ";")
end
end
for (k, v) in pairs(system)
k in (:bounding_box, :boundary_conditions) && continue
extra_line = true
@printf io " %-17s : %s\n" string(k) string(v)
end
if length(system) < 10
extra_line && println(io)
for atom in system
println(io, " ", atom)
end
extra_line = true
end
ascii_string = ascii_structure(system)
if !isempty(ascii_string)
extra_line && println(io)
println(io, " ", replace(ascii_string, "\n" => "\n "))
end
end
Base.show(io::IO, system::AbstractSystem) = show_system(io, system)
function Base.show(io::IO, mime::MIME"text/plain", system::AbstractSystem)
show_system(io, mime, system)
end
function show_atom(io::IO, at)
pos = [(@sprintf "%8.6g" ustrip(p)) for p in position(at)]
posunit = unit(eltype(position(at)))
print(io, typeof(at).name.name, "(")
print(io, (@sprintf "%-3s" (string(atomic_symbol(at))) * ","), " [",
join(pos, ", "), "]u\"$posunit\"")
if ismissing(velocity(at)) || iszero(velocity(at))
print(io, ")")
else
vel = [(@sprintf "%8.6g" ustrip(p)) for p in velocity(at)]
velunit = unit(eltype(velocity(at)))
print(io, ", [", join(vel, ", "), "]u\"$velunit\")")
end
end
function show_atom(io::IO, ::MIME"text/plain", at)
print(io, typeof(at).name.name, "(")
println(io, atomic_symbol(at), ", atomic_number = ", atomic_number(at),
", atomic_mass = ", atomic_mass(at), "):")
pos = [(@sprintf "%.8g" ustrip(p)) for p in position(at)]
posunit = unit(eltype(position(at)))
@printf io " %-17s : [%s]u\"%s\"\n" "position" join(pos, ",") string(posunit)
if !ismissing(velocity(at)) && !iszero(velocity(at))
vel = [(@sprintf "%.8g" ustrip(p)) for p in velocity(at)]
velunit = unit(eltype(velocity(at)))
@printf io " %-17s : [%s]u\"%s\"\n" "velocity" join(vel, ",") string(velunit)
end
for (k, v) in pairs(at)
k in (:atomic_number, :atomic_mass, :atomic_symbol, :position, :velocity) && continue
@printf io " %-17s : %s\n" string(k) string(v)
end
end