Spatials

Utilities

AbstractBond

Point

Bond

AbstractLattice

Lattice

SuperLattice

Cylinder

Bonds

Manual

QuantumLattices.Essentials.Spatials.AbstractLatticeType
AbstractLattice{P<:PID, N}

Abstract type for all lattices.

It should have the following contents:

  • name::String: the name of the lattice
  • pids::Vector{P}: the pids of the lattice
  • rcoords::Matrix{Float}: the rcoords of the lattice
  • icoords::Matrix{Float}: the icoords of the lattice
  • vectors::Vector{SVector{N, Float}}: the translation vectors of the lattice
  • reciprocals::Vector{SVector{N, Float}}: the reciprocals of the lattice
  • neighbors::Dict{Int, Float}: the order-distance map of the nearest neighbors of the lattice
source
QuantumLattices.Essentials.Spatials.BondsType
Bonds{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.

source
QuantumLattices.Essentials.Spatials.CylinderType
Cylinder{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.

source
QuantumLattices.Essentials.Spatials.LatticeType
Lattice{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.

source
QuantumLattices.Essentials.Spatials.LatticeIndexType
LatticeIndex{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
source
QuantumLattices.Essentials.Spatials.PointType
Point(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.

source
QuantumLattices.Essentials.Spatials.SuperLatticeType
SuperLattice(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.

source
Base.:==Method
==(b1::AbstractBond, b2::AbstractBond) -> Bool

Overloaded equivalent operator.

source
Base.:==Method
==(lattice1::AbstractLattice, lattice2::AbstractLattice) -> Bool

Overloaded equivalent operator.

source
Base.:==Method
==(bonds1::Bonds, bonds2::Bonds) -> Bool

Overloaded equivalent operator.

source
Base.eltypeMethod
eltype(bond::AbstractBond)
eltype(::Type{<:AbstractBond{N, P}}) where {N, P<:PID}

Get the eltype of a bond.

source
Base.emptyMethod
empty(bs::Bonds) -> Bonds

Get an empty copy of a set of lattice bonds.

source
Base.filterFunction
filter(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.

source
Base.filterMethod
filter(select::Function, bs::Bonds) -> Bonds

Get a filtered set of bonds by a select function.

source
Base.getindexMethod
getindex(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.

source
Base.getindexMethod
getindex(bond::Bond, i::Integer) -> Point

Get the ith point of a bond.

source
Base.getindexMethod
getindex(bs::Bonds, i::Int) -> eltype(bs)

Get the ith bond in the set.

source
Base.getindexMethod
getindex(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.

source
Base.insert!Method
insert!(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.

source
Base.isequalMethod
isequal(b1::AbstractBond, b2::AbstractBond) -> Bool

Overloaded equivalent function.

source
Base.isequalMethod
isequal(lattice1::AbstractLattice, lattice2::AbstractLattice) -> Bool

Overloaded equivalent function.

source
Base.isequalMethod
isequal(bonds1::Bonds, bonds2::Bonds) -> Bool

Overloaded equivalent function.

source
Base.iterateFunction
iterate(bs::Bonds, state=(1, 0))

Iterate over the lattice bonds in the set.

source
Base.iterateFunction
iterate(bond::AbstractBond, state=1)

Iterate over the points in a bond.

source
Base.keytypeMethod
keytype(lattice::AbstractLattice)
keytype(::Type{<:AbstractLattice{N, P} where N}) where {P<:PID}

Get the pid type of the lattice.

source
Base.lengthMethod
length(bond::AbstractBond) -> Int
length(::Type{<:AbstractBond{N, <:PID, R} where N}) where R -> Int

Get the number of points of a bond.

source
Base.lengthMethod
length(lattice::AbstractLattice) -> Int

Get the number of points contained in a lattice.

source
Base.showMethod
show(io::IO, lattice::AbstractLattice)

Show a lattice.

source
Base.sizeMethod
size(bs::Bonds) -> Tuple{Int}

Get the size of the set of lattice bonds.

source
Base.summaryMethod
summary(io::IO, bs::Bonds)

Print the brief description of a set of lattice bonds to an io.

source
Base.valtypeMethod
valtype(lattice::AbstractLattice)
valtype(::Type{<:AbstractLattice{N, P}}) where {N, P<:PID}

Get the point type of the lattice.

source
QuantumLattices.Essentials.Spatials.bonds!Method
bonds!(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.

source
QuantumLattices.Essentials.Spatials.bonds!Method
bonds!(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.

source
QuantumLattices.Essentials.Spatials.bondsMethod
bonds(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.

source
QuantumLattices.Essentials.Spatials.distanceMethod
distance(p₁::AbstractVector{<:Real}, p₂::AbstractVector{<:Real}) -> Float

Get the distance between two points.

Note

Compared to norm(p₁-p₂), this function avoids the memory allocation for p₁-p₂, thus is more efficient.

source
QuantumLattices.Essentials.Spatials.intralinksMethod
intralinks(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).

source
QuantumLattices.Essentials.Spatials.isintratriangleMethod
isintratriangle(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.

Note
  1. The vertexes are in the order (p₁, p₂, p₃) and the edges are in the order (p1p2, p2p3, p3p1).
  2. The edges do not contain the vertexes.
source
QuantumLattices.Essentials.Spatials.isonlineMethod
isonline(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.

source
QuantumLattices.Essentials.Spatials.isparallelMethod
isparallel(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.

source
QuantumLattices.Essentials.Spatials.issubordinateMethod
issubordinate(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.

source
QuantumLattices.Essentials.Spatials.minimumlengthsFunction
minimumlengths(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.

source
QuantumLattices.Essentials.Spatials.rotateMethod
rotate(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.

Note
  1. The result is given by the Rodrigues' rotation formula.
  2. Only 2 and 3 dimensional vectors can be rotated.
  3. When the input vectors are 2 dimensional, both the polar and azimuth of the axis must be 0.
source
QuantumLattices.Essentials.Spatials.tileMethod
tile(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.

source
QuantumLattices.Interfaces.decomposeMethod
decompose(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.

source