Skip to content

Commit

Permalink
atomsbase interface and printing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eahenle committed Jun 28, 2024
1 parent caacad8 commit eccb174
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/crystal.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1329,20 +1357,20 @@ 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

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""
Expand Down

0 comments on commit eccb174

Please sign in to comment.