Spatials
Utilities
AbstractBond
Point
Bond
AbstractLattice
Lattice
SuperLattice
Cylinder
Bonds
Manual
QuantumLattices.Essentials.Spatials.acrossbonds
— Constantacrossbonds
Indicate that bonds across the unitcell are inquired, which are in fact those across the periodic boundaries.
QuantumLattices.Essentials.Spatials.allbonds
— Constantallbonds
Indicate that all bonds are inquired.
QuantumLattices.Essentials.Spatials.insidebonds
— Constantinsidebonds
Indicate that bonds inside the unitcell are inquired, which do not contain those across the periodic boundaries.
QuantumLattices.Essentials.Spatials.interbonds
— Constantinterbonds
Indicate that bonds inter the sublattices are inquired.
These bonds do not contain those accorss the periodic boundaries.
QuantumLattices.Essentials.Spatials.intrabonds
— Constantintrabonds
Indicate that bonds intra the sublattices are inquired.
These bonds do not contain those accorss the periodic boundaries.
QuantumLattices.Essentials.Spatials.zerothbonds
— Constantzerothbonds
Indicate that zeroth bonds, i.e. the points are inquired.
QuantumLattices.Essentials.Spatials.AbstractBond
— TypeAbstractBond{N, P<:PID, R}
Abstract bond.
QuantumLattices.Essentials.Spatials.AbstractLattice
— TypeAbstractLattice{P<:PID, N}
Abstract type for all lattices.
It should have the following contents:
name::String
: the name of the latticepids::Vector{P}
: the pids of the latticercoords::Matrix{Float}
: the rcoords of the latticeicoords::Matrix{Float}
: the icoords of the latticevectors::Vector{SVector{N, Float}}
: the translation vectors of the latticereciprocals::Vector{SVector{N, Float}}
: the reciprocals of the latticeneighbors::Dict{Int, Float}
: the order-distance map of the nearest neighbors of the lattice
QuantumLattices.Essentials.Spatials.Bond
— TypeBond(neighbor::Int, spoint::Point, epoint::Point)
A bond in a lattice.
QuantumLattices.Essentials.Spatials.Bonds
— TypeBonds{T, L}(bonds::Tuple{Vararg{Vector{<:AbstractBond}}}) where {T, L<:AbstractLattice}
Bonds(lattice::AbstractLattice, types::LatticeBonds...)
A set of lattice bonds.
Bonds
itself is an AbstractVector
of AbstractBond
. The need for such a struct is to ensure the type stability during the iteration over a set of different concrete bonds. Although the default iterate
function does not achieve this goal, users can get it with the generated function trick. Besides, it provides a high level of management of different categories of bonds based on the LatticeBonds
system.
QuantumLattices.Essentials.Spatials.BrillouinZone
— TypeBrillouinZone(reciprocals::AbstractVector{<:AbstractVector}, momenta::AbelianNumbers{<:Momentum})
The Brillouin zone of a lattice.
QuantumLattices.Essentials.Spatials.Cylinder
— TypeCylinder{P}(name::String, block::AbstractMatrix{<:Real}, translation::SVector{N, <:Real};
vector::Union{AbstractVector{<:Real}, Nothing}=nothing,
neighbors::Union{Dict{Int, <:Real}, Int}=1
) where {P<:PID, N}
Cylinder of 1d and quasi 2d lattices.
QuantumLattices.Essentials.Spatials.Cylinder
— Method(cylinder::Cylinder)(scopes::Any...; coordination::Int=8) -> Lattice
Construct a lattice from a cylinder with the assigned scopes.
QuantumLattices.Essentials.Spatials.Lattice
— TypeLattice{N}(name::String,
pids::Vector{<:PID}, rcoords::AbstractMatrix{<:Real}, icoords::AbstractMatrix{<:Real},
vectors::AbstractVector{<:AbstractVector{<:Real}},
neighbors::Union{Dict{Int, <:Real}, Int}=1;
coordination::Int=8
) where N
Lattice(name::String,
points::AbstractVector{<:Point};
vectors::AbstractVector{<:AbstractVector{<:Real}}=SVector{0, SVector{points|>eltype|>dimension, Float}}(),
neighbors::Union{Dict{Int, <:Real}, Int}=1,
coordination::Int=8
)
Lattice(name::String,
sublattices::AbstractVector{<:AbstractLattice};
vectors::AbstractVector{<:AbstractVector{<:Real}}=SVector{0, SVector{sublattices|>eltype|>dimension, Float}}(),
neighbors::Union{Dict{Int, <:Real}, Int}=1,
coordination::Int=8
)
Simplest lattice.
A simplest lattice can be construted from its contents, i.e. pids, rcoords and icoords, or from a couple of points, or from a couple of sublattices.
QuantumLattices.Essentials.Spatials.LatticeIndex
— TypeLatticeIndex{Kind}(index::Union{PID, Int}) where Kind
Lattice index.
Kind
must be one of the followings:
- 'R': for getting the rcoord of a lattice
- 'I': for getting the icoord of a lattice
- 'P': for getting the point of a lattice
QuantumLattices.Essentials.Spatials.PID
— TypePID(scope, site::Int)
PID(site::Int)
PID(; scope="tz", site::Int=1)
The id of a point.
QuantumLattices.Essentials.Spatials.Point
— TypePoint(pid::PID, rcoord::SVector{N, <:Real}, icoord::SVector{N, <:Real}) where N
Point(pid::PID, rcoord::NTuple{N, <:Real}, icoord::NTuple{N, <:Real}=ntuple(i->0.0, N)) where N
Point(pid::PID, rcoord::AbstractVector{<:Real}, icoord::AbstractVector{<:Real}=zero(SVector{length(rcoord), Float}))
Point{N}(pid::PID, rcoord::AbstractVector{<:Real}, icoord::AbstractVector{<:Real}=zero(SVector{N, Float})) where N
Labeled point.
QuantumLattices.Essentials.Spatials.SuperLattice
— TypeSuperLattice(name::String,
sublattices::AbstractVector{<:AbstractLattice};
vectors::AbstractVector{<:AbstractVector{<:Real}}=SVector{0, SVector{sublattices|>eltype|>dimension, Float}}(),
neighbors::Dict{Int, <:Real}=Dict{Int, Float}()
)
SuperLattice that is composed of serveral sublattices.
Base.:==
— Method==(b1::AbstractBond, b2::AbstractBond) -> Bool
Overloaded equivalent operator.
Base.:==
— Method==(lattice1::AbstractLattice, lattice2::AbstractLattice) -> Bool
Overloaded equivalent operator.
Base.:==
— Method==(bonds1::Bonds, bonds2::Bonds) -> Bool
Overloaded equivalent operator.
Base.eltype
— Methodeltype(bond::AbstractBond)
eltype(::Type{<:AbstractBond{N, P}}) where {N, P<:PID}
Get the eltype of a bond.
Base.empty!
— Methodempty!(bs::Bonds) -> Bonds
Empty a set of lattice bonds.
Base.empty
— Methodempty(bs::Bonds) -> Bonds
Get an empty copy of a set of lattice bonds.
Base.filter
— Functionfilter(lbs::LatticeBonds, bs::Bonds, choice::Union{Val{:include}, Val{:exclude}}=Val(:include)) -> Bonds
filter(lbs::Tuple{Vararg{LatticeBonds}}, bs::Bonds, choice::Union{Val{:include}, Val{:exclude}}=Val(:include)) -> Bonds
Get a subset of a set of lattice bonds.
When choice=Val(:include)
, the lattice bonds indicated by lbs
will be selected; When choice=Val(:exclude)
, the lattice bonds not indicated by lbs
will be selected.
Base.filter
— Methodfilter(select::Function, bs::Bonds) -> Bonds
Get a filtered set of bonds by a select function.
Base.getindex
— Methodgetindex(lattice::AbstractLattice, i::LatticeIndex{'R'}) -> SVector
getindex(lattice::AbstractLattice, i::LatticeIndex{'I'}) -> SVector
getindex(lattice::AbstractLattice, i::LatticeIndex{'P'}) -> Point
Get a rcoord, an icoord or a point of a lattice according to the type of the input index.
Base.getindex
— Methodgetindex(bond::Bond, i::Integer) -> Point
Get the ith point of a bond.
Base.getindex
— Methodgetindex(bs::Bonds, i::Int) -> eltype(bs)
Get the ith bond in the set.
Base.getindex
— Methodgetindex(p::Point, i::Integer) -> Point
Get the ith point of a point, which by definition i should only be 1 and the result is the point itself.
Base.insert!
— Methodinsert!(cylinder::Cylinder, ps::S...; cut=length(cylinder)÷2+1, scopes::Union{<:AbstractVector{S}, Nothing}=nothing, coordination=8) where S -> Cylinder
Insert a couple of blocks into a cylinder.
The position of the cut of the cylinder is specified by the keyword argument cut
, which is the center of the cylinder by default. All pids corresponding to a same newly inserted block share the same scope, which is specified by the parameter ps
. Optionally, the scopes of the old pids in the cylinder can be replaced if the parameter scopes
is assigned other than nothing
. Note the length of ps
is equal to the number of newly inserted blocks, while that of scopes
should be equal to the old length of the cylinder.
Base.isequal
— Methodisequal(b1::AbstractBond, b2::AbstractBond) -> Bool
Overloaded equivalent function.
Base.isequal
— Methodisequal(lattice1::AbstractLattice, lattice2::AbstractLattice) -> Bool
Overloaded equivalent function.
Base.isequal
— Methodisequal(bonds1::Bonds, bonds2::Bonds) -> Bool
Overloaded equivalent function.
Base.iterate
— Functioniterate(bs::Bonds, state=(1, 0))
Iterate over the lattice bonds in the set.
Base.iterate
— Functioniterate(bond::AbstractBond, state=1)
Iterate over the points in a bond.
Base.keytype
— Methodkeytype(lattice::AbstractLattice)
keytype(::Type{<:AbstractLattice{N, P} where N}) where {P<:PID}
Get the pid type of the lattice.
Base.length
— Methodlength(bond::AbstractBond) -> Int
length(::Type{<:AbstractBond{N, <:PID, R} where N}) where R -> Int
Get the number of points of a bond.
Base.length
— Methodlength(lattice::AbstractLattice) -> Int
Get the number of points contained in a lattice.
Base.reverse
— Methodreverse(bond::Bond) -> Bond
Get the reversed bond.
Base.show
— Methodshow(io::IO, lattice::AbstractLattice)
Show a lattice.
Base.show
— Methodshow(io::IO, bond::Bond)
Show a bond.
Base.show
— Methodshow(io::IO, p::Point)
Show a labeled point.
Base.size
— Methodsize(bs::Bonds) -> Tuple{Int}
Get the size of the set of lattice bonds.
Base.summary
— Methodsummary(io::IO, bs::Bonds)
Print the brief description of a set of lattice bonds to an io.
Base.valtype
— Methodvaltype(lattice::AbstractLattice)
valtype(::Type{<:AbstractLattice{N, P}}) where {N, P<:PID}
Get the point type of the lattice.
QuantumLattices.Essentials.Spatials.azimuth
— Methodazimuth(v::AbstractVector{<:Real}) -> Float
Get the azimuth angle in radians of a vector.
QuantumLattices.Essentials.Spatials.azimuthd
— Methodazimuthd(v::AbstractVector{<:Real}) -> Float
Get the azimuth angle in degrees of a vector.
QuantumLattices.Essentials.Spatials.bonds!
— Methodbonds!(bonds::Vector, lattice::AbstractLattice, inquiries::LatticeBonds...) -> Vector
bonds!(bonds::Vector, lattice::AbstractLattice, ::Val{zerothbonds}) -> Vector
bonds!(bonds::Vector, lattice::AbstractLattice, ::Val{insidebonds}) -> Vector
bonds!(bonds::Vector, lattice::AbstractLattice, ::Val{acrossbonds}) -> Vector
Generate the required bonds of a lattice and append them to the input bonds.
QuantumLattices.Essentials.Spatials.bonds!
— Methodbonds!(bonds::Vector, lattice::SuperLattice, ::Val{intrabonds}) -> Vector
bonds!(bonds::Vector, lattice::SuperLattice, ::Val{interbonds}) -> Vector
Generate the required bonds of a superlattice and append them to the input bonds.
QuantumLattices.Essentials.Spatials.bonds
— Methodbonds(lattice::AbstractLattice, inquiry=allbonds) -> Vector{eltype(lattice|>typeof, inquiry)}
bonds(lattice::AbstractLattice, inquiries...) -> Vector{mapreduce(inquiry->eltype(lattice|>typeof, inquiry), typejoin, inquiries)}
Generate the required bonds of a lattice.
QuantumLattices.Essentials.Spatials.bondtypes
— Methodbondtypes(bs::Bonds) -> Tuple{Vararg{LatticeBonds}}
bondtypes(::Type{<:Bonds{T}}) where T -> Tuple{Vararg{LatticeBonds}}
Get the bondtypes of a set of lattice bonds.
QuantumLattices.Essentials.Spatials.distance
— Methoddistance(p₁::AbstractVector{<:Real}, p₂::AbstractVector{<:Real}) -> Float
Get the distance between two points.
Compared to norm(p₁-p₂)
, this function avoids the memory allocation for p₁-p₂
, thus is more efficient.
QuantumLattices.Essentials.Spatials.icoord
— Methodicoord(bond::Bond) -> SVector
Get the icoord of the bond.
QuantumLattices.Essentials.Spatials.interlinks
— Methodinterlinks(cluster1::AbstractMatrix{<:Real}, cluster2::AbstractMatrix{<:Real}, neighbors::Dict{Int, Float}) -> Vector{Tuple{Int, Int, Int}}
Use kdtree to get the intercluster nearest neighbors.
QuantumLattices.Essentials.Spatials.intralinks
— Methodintralinks(cluster::AbstractMatrix{<:Real}, vectors::AbstractVector{<:AbstractVector{<:Real}}, neighbors::Dict{Int, Float},
maxtranslations::NTuple{N, Int}=ntuple(i->length(neighbors), length(vectors))
) where N -> Vector{Tuple{Int, Int, Int, SubArray{<:Real, 1}}}
Use kdtree to get the intracluster nearest neighbors.
As is similar to minimumlengths
, when vectors
is nonempty, the cluster assumes periodic boundaries. neighbors
provides the map between the bond length and the order of nearest neighbors. Note only those with the lengths present in neighbors
will be included in the result. maxtranslations
determines the maximum number of translations along those directions specified by vectors
when the tiled supercluster is construted (See minimumlengths
for the explanation of the method for periodic lattices).
QuantumLattices.Essentials.Spatials.isintracell
— Methodisintracell(bond::Bond) -> Bool
Judge whether a bond is intra the unit cell of a lattice.
QuantumLattices.Essentials.Spatials.isintracell
— Methodisintracell(p::Point) -> Bool
Judge whether a point is intra the unitcell.
QuantumLattices.Essentials.Spatials.isintratriangle
— Methodisintratriangle(p::AbstractVector{<:Real}, p₁::AbstractVector{<:Real}, p₂::AbstractVector{<:Real}, p₃::AbstractVector{<:Real};
vertexes::NTuple{3, Bool}=(true, true, true), edges::NTuple{3, Bool}=(true, true, true), atol::Real=atol, rtol::Real=rtol
) -> Bool
Judge whether a point belongs to the interior of a triangle whose vertexes are p₁
, 'p₂' and p₃
with the give tolerance. vertexes
and edges
define whether the interior should contain the vertexes or edges, respectively.
- The vertexes are in the order (p₁, p₂, p₃) and the edges are in the order (p1p2, p2p3, p3p1).
- The edges do not contain the vertexes.
QuantumLattices.Essentials.Spatials.isonline
— Methodisonline(p::AbstractVector{<:Real}, p₁::AbstractVector{<:Real}, p₂::AbstractVector{<:Real};
ends::Tuple{Bool, Bool}=(true, true), atol::Real=atol, rtol::Real=rtol
) -> Bool
Judge whether a point is on a line segment whose end points are p₁
and p₂
with the given tolerance. ends
defines whether the line segment should contain its ends.
QuantumLattices.Essentials.Spatials.isparallel
— Methodisparallel(v₁::AbstractVector{<:Real}, v₂::AbstractVector{<:Real}; atol::Real=atol, rtol::Real=rtol) -> Int
Judge whether two vectors are parallel to each other with the given tolerance, 0
for not parallel, 1
for parallel and -1
for antiparallel.
QuantumLattices.Essentials.Spatials.issubordinate
— Methodissubordinate(rcoord::AbstractVector{<:Real}, vectors::AbstractVector{<:AbstractVector{<:Real}}; atol::Real=atol, rtol::Real=rtol) -> Bool
Judge whether a coordinate belongs to a lattice defined by vectors
with the given tolerance.
QuantumLattices.Essentials.Spatials.latticebondsstructure
— Methodlatticebondsstructure(::Type{<:AbstractLattice}) -> SimpleTree{LatticeBonds, Nothing}
The tree structure of the lattice bonds.
QuantumLattices.Essentials.Spatials.latticebondsstructure
— Methodlatticebondsstructure(::Type{<:SuperLattice}) -> SimpleTree{LatticeBonds, Nothing}
The tree structure of the lattice bonds.
QuantumLattices.Essentials.Spatials.latticetype
— Methodlatticetype(bs::Bonds)
latticetype(::Type{<:Bonds{T, L} where T}) where {L<:AbstractLattice}
QuantumLattices.Essentials.Spatials.latticetype
— Methodlatticetype(sl::SuperLattice)
latticetype(::Type{<:SuperLattice{L}}) where {L<:AbstractLattice}
Get the sublattice type of a superlattice.
QuantumLattices.Essentials.Spatials.minimumlengths
— Functionminimumlengths(cluster::AbstractMatrix{<:Real}, vectors::AbstractVector{<:AbstractVector{<:Real}}, nneighbor::Int=1; coordination::Int=8) -> Vector{Float}
Use kdtree to search the lowest several minimum bond lengths within a lattice translated by a cluster.
When the translation vectors are not empty, the lattice will be considered periodic in the corresponding directions. Otherwise the lattice will be open in all directions. To search for the bonds accorss the periodic boundaries, the cluster will be pretranslated to become a supercluster, which has open boundaries but is large enough to contain all the nearest neighbors within the required order. The coordination
parameter sets the average number of each order of nearest neighbors. If it is to small, larger bond lengths may not be searched, and the result will contain Inf
. This is a sign that you may need a larger coordination
. Another situation that Inf
appears in the result occurs when the minimum lengths are searched in open lattices. Indeed, the cluster may be too small so that the required order just goes beyond it. In this case the warning message can be safely ignored.
QuantumLattices.Essentials.Spatials.nneighbor
— Methodnneighbor(lattice::AbstractLattice) -> Int
Get the highest order of nearest neighbors.
QuantumLattices.Essentials.Spatials.pidtype
— Methodpidtype(bond::AbstractBond)
pidtype(::Type{<:AbstractBond{N, P} where N}) where {P<:PID}
Get the pid type of a concrete bond.
QuantumLattices.Essentials.Spatials.polar
— Methodpolar(v::AbstractVector{<:Real}) -> Float
Get the polar angle in radians of a vector.
QuantumLattices.Essentials.Spatials.polard
— Methodpolard(v::AbstractVector{<:Real}) -> Float
Get the polar angle in degrees of a vector.
QuantumLattices.Essentials.Spatials.rcoord
— Methodrcoord(bond::Bond) -> SVector
Get the rcoord of the bond.
QuantumLattices.Essentials.Spatials.reciprocals
— Methodreciprocals(vectors::AbstractVector{AbstractVector{<:Real}}) -> Vector{Vector{Float}}
Get the reciprocals dual to the input vectors.
QuantumLattices.Essentials.Spatials.rotate
— Methodrotate(cluster::AbstractMatrix{<:Real}, angle::Real; axis::Tuple{Union{AbstractVector{<:Real}, Nothing}, Tuple{<:Real, <:Real}}=(nothing, (0, 0))) -> Matrix{Float}
Get a rotated cluster of the original one by a certain angle around an axis.
The axis is determined by a point it gets through (nothing
can be used to denote the origin), and its polar as well as azimuth angles in radians. The default axis is the z axis.
- The result is given by the Rodrigues' rotation formula.
- Only 2 and 3 dimensional vectors can be rotated.
- When the input vectors are 2 dimensional, both the polar and azimuth of the axis must be 0.
QuantumLattices.Essentials.Spatials.tile
— Methodtile(cluster::AbstractMatrix{<:Real}, vectors::AbstractVector{<:AbstractVector{<:Real}}, translations::NTuple{M, NTuple{N, <:Real}}=()) where {N, M} -> Matrix{Float}
Tile a supercluster by translations of the input cluster.
Basically, the final supercluster is composed of several parts, each of which is a translation of the original cluster, with the translation vectors specified by vectors
and each set of the translation indices contained in translations
. When translation vectors are empty, a copy of the original cluster will be returned.
QuantumLattices.Essentials.Spatials.translate
— Methodtranslate(cluster::AbstractMatrix{<:Real}, vector::AbstractVector{<:Real}) -> Matrix{vector|>eltype}
Get the translated cluster of the original one by a vector.
QuantumLattices.Essentials.Spatials.volume
— Methodvolume(v₁::AbstractVector{<:Real}, v₂::AbstractVector{<:Real}, v₃::AbstractVector{<:Real}) -> Real
Get the volume spanned by three vectors.
QuantumLattices.Essentials.kind
— Methodkind(bond::Bond) -> Int
Get the bond kind of a bond.
QuantumLattices.Essentials.kind
— Methodkind(::Point) -> 0
kind(::Type{<:Point}) -> 0
Get the bond kind of a point, which is defined to be 0.
QuantumLattices.Essentials.reset!
— Methodreset!(bs::Bonds, lattice::AbstractLattice) -> Bonds
Reset a set of lattice bonds by a new lattice.
QuantumLattices.Interfaces.decompose
— Methoddecompose(v₀::AbstractVector{<:Real}, v₁::AbstractVector{<:Real}) -> Tuple{Float}
decompose(v₀::AbstractVector{<:Real}, v₁::AbstractVector{<:Real}, v₂::AbstractVector{<:Real}) -> Tuple{Float, Float}
decompose(v₀::AbstractVector{<:Real}, v₁::AbstractVector{<:Real}, v₂::AbstractVector{<:Real}, v₃::AbstractVector{<:Real}) -> Tuple{Float, Float, Float}
Decompose a vector with respect to input basis vectors.
QuantumLattices.Interfaces.dimension
— Methoddimension(bond::AbstractBond) -> Int
dimension(::Type{<:AbstractBond{N}}) where N -> Int
Get the space dimension of a concrete bond.
QuantumLattices.Interfaces.dimension
— Methoddimension(lattice::AbstractLattice) -> Int
dimension(::Type{<:AbstractLattice{N}}) where N -> Int
Get the space dimension of the lattice.
QuantumLattices.Interfaces.expand
— Methodexpand(::Type{L}, ::Val{VS}) where {L<:AbstractLattice, VS} -> Tuple
Expand the lattice bond types to the leaf level.
QuantumLattices.Interfaces.rank
— Methodrank(bond::AbstractBond) -> Int
rank(::Type{<:AbstractBond{N, <:PID, R} where N}) where R -> Int
Get the rank of a bond.
QuantumLattices.Interfaces.rank
— Methodrank(bs::Bonds) -> Int
rank(::Type{<:Bonds{T}}) where T -> Int
Get the rank of a set of lattice bonds.