From 4d4ecdc21dfa6f1d2cbcf7a62436350b2884b905 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Wed, 23 Oct 2024 08:48:36 +0200 Subject: [PATCH 1/7] Super basic idea --- Project.toml | 2 ++ src/utils/show.jl | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 8886d3c..c70d6a6 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "0.4.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" PeriodicTable = "7b2266bf-644c-5ea3-82d8-af4bbd25a884" +Preferences = "21216c6a-2e73-6563-6e65-726566657250" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Requires = "ae029012-a4dd-5104-9daa-d747884805df" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" @@ -14,6 +15,7 @@ UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a" [compat] PeriodicTable = "1" +Preferences = "1.4" Requires = "1" StaticArrays = "1" Unitful = "1" diff --git a/src/utils/show.jl b/src/utils/show.jl index 7d09841..809a633 100644 --- a/src/utils/show.jl +++ b/src/utils/show.jl @@ -55,8 +55,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher extra_line = true end - # TODO We will make this configurable in a follow-up PR - show_ascii = false + show_ascii = length(system) > @load_preference("system_visualize_ascii_max_atoms", 10) if show_ascii ascii = visualize_ascii(system) if !isempty(ascii) From 4b3087f54afb3531c98c5b55b2c156bcd5269ed8 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Thu, 31 Oct 2024 08:56:29 +0100 Subject: [PATCH 2/7] Add preference system for show --- Project.toml | 9 ++++++++- ext/AtomsBaseAtomsViewExt.jl | 8 ++++++++ src/AtomsBase.jl | 14 -------------- src/utils/show.jl | 34 ++++++++++++++++++++++++++++++---- 4 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 ext/AtomsBaseAtomsViewExt.jl diff --git a/Project.toml b/Project.toml index c70d6a6..9092fbb 100644 --- a/Project.toml +++ b/Project.toml @@ -13,14 +13,21 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a" +[weakdeps] +AtomsView = "ee286e10-dd2d-4ff2-afcb-0a3cd50c8041" + +[extensions] +AtomsBaseAtomsViewExt = "AtomsView" + [compat] +AtomsView = "0.1" PeriodicTable = "1" Preferences = "1.4" Requires = "1" StaticArrays = "1" Unitful = "1" UnitfulAtomic = "1" -julia = "1.6" +julia = "1.9" [extras] Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" diff --git a/ext/AtomsBaseAtomsViewExt.jl b/ext/AtomsBaseAtomsViewExt.jl new file mode 100644 index 0000000..31773f7 --- /dev/null +++ b/ext/AtomsBaseAtomsViewExt.jl @@ -0,0 +1,8 @@ +module AtomsBaseAtomsViewExt + using AtomsBase + using AtomsView + + function Base.show(io::IO, mime::MIME"text/html", system::AbstractSystem) + write(io, AtomsView.visualize_structure(system, mime)) + end +end diff --git a/src/AtomsBase.jl b/src/AtomsBase.jl index 76d3d75..a732abc 100644 --- a/src/AtomsBase.jl +++ b/src/AtomsBase.jl @@ -18,24 +18,10 @@ include("utils/visualize_ascii.jl") include("utils/show.jl") include("utils/atomview.jl") - # prototype implementations include("implementation/atom.jl") include("implementation/flexible_system.jl") include("implementation/fast_system.jl") include("implementation/utils.jl") - -# TODO: -# - this should be converted to an extension -# - should work for AbstractSystem -function __init__() - @require AtomsView="ee286e10-dd2d-4ff2-afcb-0a3cd50c8041" begin - function Base.show(io::IO, mime::MIME"text/html", system::FlexibleSystem) - write(io, AtomsView.visualize_structure(system, mime)) - end - end -end - - end diff --git a/src/utils/show.jl b/src/utils/show.jl index 809a633..b962220 100644 --- a/src/utils/show.jl +++ b/src/utils/show.jl @@ -1,4 +1,31 @@ using Printf +using Preferences + +""" +Configures the default printing behaviour of `show_system`, which is invoked when a rich `text/htmal` +display of an `AbstractSystem` is requested. This is for example the case in a Julia REPL. +The following options can be configured: + +- `max_species_list`: Maximal number of species in a system to trigger a listing of every species + along with its Cartesian positions. Default 10 +- `max_species_visualize_ascii`: Maximal number of species in a system to trigger a representation + in the form of an ascii cartoon using `visualize_ascii`. Default 0, i.e. diseabled. +""" +function set_show_preferences!(; max_species_list=nothing, max_species_visualize_ascii=nothing) + if !isnothing(max_species_list) + @set_preference!("max_species_list", max_species_list) + end + if !isnothing(max_species_visualize_ascii) + @set_preference!("max_species_visualize_ascii", max_species_visualize_ascii) + end + show_preferences() +end +function show_preferences() + (; max_species_list=@load_preference("max_species_list", 10), + max_species_visualize_ascii=@load_preference("max_species_visualize_ascii", 0)) +end + + """ Suggested function to print AbstractSystem objects to screen @@ -26,7 +53,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher println(io, "):") extra_line = false - if any(pbc) + if any(pbc) extra_line = true box = bounding_box(system) bunit = unit(eltype(first(bounding_box(system)))) @@ -47,7 +74,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher extra_line = true @printf io " %-17s : %s\n" string(k) string(v) end - if length(system) < 10 + if length(system) < show_preferences().max_species_list extra_line && println(io) for atom in system println(io, " ", atom) @@ -55,8 +82,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher extra_line = true end - show_ascii = length(system) > @load_preference("system_visualize_ascii_max_atoms", 10) - if show_ascii + if length(system) < show_preferences().max_species_visualize_ascii ascii = visualize_ascii(system) if !isempty(ascii) extra_line && println(io) From 21f2cc5c4042a0e79e0b67b4368a69268e9e1421 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Thu, 31 Oct 2024 09:45:10 +0100 Subject: [PATCH 3/7] up --- src/utils/show.jl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/utils/show.jl b/src/utils/show.jl index b962220..7e445a0 100644 --- a/src/utils/show.jl +++ b/src/utils/show.jl @@ -2,7 +2,7 @@ using Printf using Preferences """ -Configures the default printing behaviour of `show_system`, which is invoked when a rich `text/htmal` +Configures the printing behaviour of `show_system`, which is invoked when a rich `text/htmal` display of an `AbstractSystem` is requested. This is for example the case in a Julia REPL. The following options can be configured: @@ -13,13 +13,18 @@ The following options can be configured: """ function set_show_preferences!(; max_species_list=nothing, max_species_visualize_ascii=nothing) if !isnothing(max_species_list) - @set_preference!("max_species_list", max_species_list) + @set_preferences!("max_species_list" => max_species_list) end if !isnothing(max_species_visualize_ascii) - @set_preference!("max_species_visualize_ascii", max_species_visualize_ascii) + @set_preferences!("max_species_visualize_ascii" => max_species_visualize_ascii) end show_preferences() end + +""" +Display the current printing behaviour of `show_system`. +See [`set_show_preferences!](@ref) for more details on the keys. +""" function show_preferences() (; max_species_list=@load_preference("max_species_list", 10), max_species_visualize_ascii=@load_preference("max_species_visualize_ascii", 0)) @@ -74,7 +79,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher extra_line = true @printf io " %-17s : %s\n" string(k) string(v) end - if length(system) < show_preferences().max_species_list + if length(system) ≤ show_preferences().max_species_list extra_line && println(io) for atom in system println(io, " ", atom) @@ -82,7 +87,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher extra_line = true end - if length(system) < show_preferences().max_species_visualize_ascii + if length(system) ≤ show_preferences().max_species_visualize_ascii ascii = visualize_ascii(system) if !isempty(ascii) extra_line && println(io) From 53da7c32e83e785e42d2ba96081218e523be3c47 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Thu, 31 Oct 2024 09:55:06 +0100 Subject: [PATCH 4/7] up --- .github/workflows/CI.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6d824aa..50cda27 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -18,14 +18,13 @@ jobs: fail-fast: false matrix: version: - - '1.6' - '1.9' - '1.10' - - 'nightly' + - 'latest' group: - Core - AtomsBaseTesting - continue-on-error: ${{ matrix.version == 'nightly' }} + continue-on-error: ${{ matrix.version == 'latest' }} steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 From 870be92c2e84ca5080dc13f8864c99240c296496 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Thu, 31 Oct 2024 09:57:03 +0100 Subject: [PATCH 5/7] up --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 50cda27..3d42086 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -20,11 +20,11 @@ jobs: version: - '1.9' - '1.10' - - 'latest' + - 'nightly' group: - Core - AtomsBaseTesting - continue-on-error: ${{ matrix.version == 'latest' }} + continue-on-error: ${{ matrix.version == 'nightly' }} steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 From 10d1eecd328cb3c3e95140d2f603edb8f7caa863 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Thu, 31 Oct 2024 16:28:43 +0100 Subject: [PATCH 6/7] Update show.jl --- src/utils/show.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/show.jl b/src/utils/show.jl index 7e445a0..1c8f49c 100644 --- a/src/utils/show.jl +++ b/src/utils/show.jl @@ -2,12 +2,12 @@ using Printf using Preferences """ -Configures the printing behaviour of `show_system`, which is invoked when a rich `text/htmal` +Configures the printing behaviour of `show_system`, which is invoked when a rich `text/plain` display of an `AbstractSystem` is requested. This is for example the case in a Julia REPL. The following options can be configured: -- `max_species_list`: Maximal number of species in a system to trigger a listing of every species - along with its Cartesian positions. Default 10 +- `max_species_list`: Maximal number of species in a system (`length(system)`) to trigger a + listing of every species along with its Cartesian positions. Default 10 - `max_species_visualize_ascii`: Maximal number of species in a system to trigger a representation in the form of an ascii cartoon using `visualize_ascii`. Default 0, i.e. diseabled. """ From dee34339f218c3d0473d27dbb4f95cf935c88398 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Sat, 2 Nov 2024 17:59:07 +0100 Subject: [PATCH 7/7] Move to species --- src/utils/show.jl | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/utils/show.jl b/src/utils/show.jl index 1c8f49c..a2664ed 100644 --- a/src/utils/show.jl +++ b/src/utils/show.jl @@ -6,17 +6,18 @@ Configures the printing behaviour of `show_system`, which is invoked when a rich display of an `AbstractSystem` is requested. This is for example the case in a Julia REPL. The following options can be configured: -- `max_species_list`: Maximal number of species in a system (`length(system)`) to trigger a - listing of every species along with its Cartesian positions. Default 10 -- `max_species_visualize_ascii`: Maximal number of species in a system to trigger a representation - in the form of an ascii cartoon using `visualize_ascii`. Default 0, i.e. diseabled. +- `max_particles_list`: Maximal number of particles in a system until `show_system` + includes a listing of every particle. Default: 10 +- `max_particles_visualize_ascii`: Maximal number of particles in a system + until `show_system` includes a representation of the system in the form of + an ascii cartoon using `visualize_ascii`. Default 0, i.e. disabled. """ -function set_show_preferences!(; max_species_list=nothing, max_species_visualize_ascii=nothing) - if !isnothing(max_species_list) - @set_preferences!("max_species_list" => max_species_list) +function set_show_preferences!(; max_particles_list=nothing, max_particles_visualize_ascii=nothing) + if !isnothing(max_particles_list) + @set_preferences!("max_particles_list" => max_particles_list) end - if !isnothing(max_species_visualize_ascii) - @set_preferences!("max_species_visualize_ascii" => max_species_visualize_ascii) + if !isnothing(max_particles_visualize_ascii) + @set_preferences!("max_particles_visualize_ascii" => max_particles_visualize_ascii) end show_preferences() end @@ -26,12 +27,10 @@ Display the current printing behaviour of `show_system`. See [`set_show_preferences!](@ref) for more details on the keys. """ function show_preferences() - (; max_species_list=@load_preference("max_species_list", 10), - max_species_visualize_ascii=@load_preference("max_species_visualize_ascii", 0)) + (; max_particles_list=@load_preference("max_particles_list", 10), + max_particles_visualize_ascii=@load_preference("max_particles_visualize_ascii", 0)) end - - """ Suggested function to print AbstractSystem objects to screen """ @@ -79,7 +78,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher extra_line = true @printf io " %-17s : %s\n" string(k) string(v) end - if length(system) ≤ show_preferences().max_species_list + if length(system) ≤ show_preferences().max_particles_list extra_line && println(io) for atom in system println(io, " ", atom) @@ -87,7 +86,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher extra_line = true end - if length(system) ≤ show_preferences().max_species_visualize_ascii + if length(system) ≤ show_preferences().max_particles_visualize_ascii ascii = visualize_ascii(system) if !isempty(ascii) extra_line && println(io)