-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic printing for atomic structures (#39)
- Loading branch information
Showing
9 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export chemical_formula | ||
|
||
|
||
""" | ||
Returns the chemical formula of an AbstractSystem as a string. | ||
""" | ||
function chemical_formula(symbols::AbstractVector{Symbol}) | ||
parts = map(collect(Set(symbols))) do sym | ||
sym_count = count(isequal(sym), symbols) | ||
sym_count < 2 && return string(sym) | ||
|
||
str_count = string(sym_count) | ||
for i in 0:9 | ||
str_count = replace(str_count, ('0' + i) => ('₀' + i)) # Make subscripts | ||
end | ||
string(sym) * str_count | ||
end | ||
join(sort(parts)) | ||
end | ||
chemical_formula(system) = chemical_formula(atomic_symbol(system)) | ||
|
||
|
||
function show_system(io::IO, system::AbstractSystem{D}) where {D} | ||
print(io, "($(chemical_formula(system)), ") | ||
bc = boundary_conditions(system) | ||
if all(isequal(bc[1]), bc) | ||
print(io, typeof(bc[1]), ", ") | ||
end | ||
box = bounding_box(system) | ||
if box != infinite_box(D) | ||
box_str = ["[" * join(ustrip.(bvector), ", ") * "]" for bvector in box] | ||
print(io, "box=[", join(box_str, ", "), "]u\"$(unit(box[1][1]))\"") | ||
else | ||
print(io, "box=infinite") | ||
end | ||
print(io, ")") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using AtomsBase | ||
using Unitful | ||
using Test | ||
|
||
@testset "Printing atomic systems" begin | ||
at = Atom(:Si, zeros(3) * u"m", extradata=42) | ||
println(at) | ||
|
||
atoms = [:Si => [0.0, -0.125, 0.0], | ||
:C => [0.125, 0.0, 0.0]] | ||
box = [[10, 0.0, 0.0], [0.0, 5, 0.0], [0.0, 0.0, 7]]u"Å" | ||
system = periodic_system(atoms, box; fractional=true) | ||
println(system) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using AtomsBase | ||
using Test | ||
|
||
@testset "Chemical formula" begin | ||
@test chemical_formula([:H]) == "H" | ||
@test chemical_formula([:H, :H]) == "H₂" | ||
@test chemical_formula([:H, :O, :H]) == "H₂O" | ||
@test chemical_formula([:O, :H, :O, :H]) == "H₂O₂" | ||
@test chemical_formula([:Ga, :N, :O, :H, :H]) == "GaH₂NO" | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f9ec6af
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
f9ec6af
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/57083
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: