From 14a4e39053fa71b3026ad8dd7022e3f8ecdbd3cd Mon Sep 17 00:00:00 2001 From: Adrian Henle Date: Fri, 28 Jun 2024 16:06:48 -0700 Subject: [PATCH] update Project.toml (#196) * update Project.toml * JuliaFormatter Action Bot (#197) Co-authored-by: eahenle * fix compats * atomsbase interface and printing fix * fix --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: eahenle --- Project.toml | 16 ++++++++-------- src/crystal.jl | 46 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Project.toml b/Project.toml index a089534..e793e84 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Xtals" uuid = "ede5f01d-793e-4c47-9885-c447d1f18d6d" authors = ["SimonEnsemble "] -version = "0.5.0" +version = "0.5.1" [deps] AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" @@ -20,17 +20,17 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] Aqua = "0.5" -AtomsBase = "0.2.0" -Bio3DView = "0.1" +AtomsBase = "0.2, 0.3, 0.4" +Bio3DView = "0.1, 1, 2" CSV = "0.10" -DataFrames = "1.0" +DataFrames = "1" Graphs = "1.4" JLD2 = "0.4" MetaGraphs = "0.7" -PeriodicTable = "1.1" -PrecompileSignatures = "3.0" -StaticArrays = "1.3" -Unitful = "1.11" +PeriodicTable = "1" +PrecompileSignatures = "3" +StaticArrays = "1" +Unitful = "1" julia = "1.6" [extras] diff --git a/src/crystal.jl b/src/crystal.jl index 01bc5f2..55be594 100644 --- a/src/crystal.jl +++ b/src/crystal.jl @@ -1,3 +1,7 @@ +# AtomsBase interface things +import Base: position, length, getindex, keys, display, show, print, println +import AtomsBase: velocity, bounding_box, boundary_conditions, atomic_symbol, species_type, atomic_number + """ SymmetryInfo(symmetry, space_group, is_p1) @@ -157,7 +161,7 @@ function Crystal( # Make sure the space group is P1 if line[1] == "_symmetry_space_group_name_H-M" || - line[1] == "_space_group_name_Hall" || + line[1] == "_space_group_name_Hall" || line[1] == "_space_group_name_H-M_alt" # use anonymous function to combine all terms past the first # to extract space group name @@ -1194,7 +1198,31 @@ crystal and adding new ones...\n", return new_crystal end -function Base.show(io::IO, crystal::Crystal) +function Base.show(io::IO, mime::MIME"text/plain", system::Crystal) + print(io, system) +end + +print(xtal::Crystal) = show(xtal) + +print(io::IO, xtal::Crystal) = show(io, xtal) + +function println(xtal::Crystal) + println("") + show(xtal) +end + +function println(io::IO, xtal::Crystal) + println(io, "") + show(io, xtal) +end + +display(xtal::Crystal) = show(xtal) + +display(io::IO, xtal::Crystal) = show(io, xtal) + +show(xtal::Crystal) = show(stdout, xtal) + +function show(io::IO, crystal::Crystal) println(io, "Name: ", crystal.name) println(io, crystal.box) @printf(io, "\t# atoms = %d\n", crystal.atoms.n) @@ -1329,13 +1357,11 @@ function Base.:+( return crystal end -# AtomsBase interface things -import Base.position -import AtomsBase.velocity -import AtomsBase.bounding_box -import AtomsBase.boundary_conditions -import Base.length, Base.getindex -import AtomsBase.atomic_symbol +keys(xtal::Crystal) = 1:xtal.atoms.n + +atomic_number(xtal::Crystal) = [elements[x].number for x in xtal.atoms.species] + +species_type(xtal::Crystal) = xtal.atoms.species length(xtal::Crystal) = xtal.atoms.n @@ -1343,6 +1369,8 @@ getindex(xtal::Crystal, index::Int) = xtal.atoms[index] atomic_symbol(atom::Atoms) = atom.species[1] +atomic_symbol(xtal::Crystal) = xtal.atoms.species + function position(crystal::Crystal) pos = Cart(crystal.atoms.coords, crystal.box).x return [pos[:, i] for i in 1:size(pos, 2)] * u"Å"