CellBase.jl
Documentation for CellBase.jl
What is package does
Provide a basic low level interface for storing and handling crystal structure data. The target application is for small and periodic cells, with the emphasis on both ease to use as well as performance.
Guides
Lattice
type
The Lattice
type represents the lattice. The lattice vectors are stored as a matrix of column vectors. For example, the first lattice vector should be accessed as cellmat(lattice)[:, 1]
.
The reciprocal lattice is also stored for quick access, however, this means that whenever the matrix is directly modified, the store reciprocal lattice vectors should be updated as well. Hence, the set_cellmat!
function should be used for updating the cell matrix, which does this is automatically.
CellBase.Lattice
— TypeLattice{T}
The type represents a lattice in 3D space formed by three column lattice vectors.
CellBase.Lattice
— MethodLattice(matrix::Matrix{T}) where T
Construct a Lattice
from a matrix of column vectors.
CellBase.Lattice
— MethodLattice(a::T, b::T, c::T, α::T, β::T, γ::T) where T
Construct a Lattice
from lattice parameters.
CellBase.Lattice
— MethodLattice(a::T, b::T, c::T) where T <: Real
Construct a Lattice
with orthogonal lattice vectors.
CellBase.Lattice
— MethodLattice(va::Vector{T}, vb::Vector{T}, vc::Vector{T}) where T
Construct a Lattice
from three lattice vectors.
CellBase.Lattice
— MethodLattice(cellpar::Vector{T}) where T
Construct a Lattice
from a six-vector of lattice parameters.
CellBase.cellmat
— Methodcellmat(lattice::Lattice)
Return the matrix of column vectors.
CellBase.cellmat_row
— MethodGet a matrix of column vectors
CellBase.cellpar
— Methodcellpar(lattice::Lattice)
Return the lattice parameters as a six-vector.
CellBase.cellvecs
— MethodLattice vectors
CellBase.frac_pos
— MethodFraction positions of a site
CellBase.get_cellmat
— MethodReturn a copy of the cell matrix
CellBase.get_rec_cellmat
— MethodReturn a copy of the reciprocal cell matrix
CellBase.get_scaled_positions
— Methodget_scaled_positions(l::Lattice, v::AbstractVecOrMat) = reciprocal(l) * v
Return the scaled positions.
CellBase.mic
— Methodmic(l::Lattice, vec::AbstractVecOrMat)
Compute the minimum-image convention representation of a series of displacement vectors.
CellBase.mic_naive
— MethodCompute naive MIC representation of the vector(s)
Not safe for skewed cells. Requires
norm(length) < 0.5 * min(cellpar(l)[1:3])
See also:
- W. Smith, "The Minimum Image Convention in Non-Cubic MD Cells", 1989, http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.57.1696.
CellBase.mic_naive
— Method mic_safe(l::Lattice, v::AbstractVector)
Compute MIC representation of vectors using a safe approach based on Minkowski reduced cell
CellBase.mic_safe
— Method mic_safe(l::Lattice, v::AbstractMatrix)
Compute MIC representation of vectors using a safe approach based on Minkowski reduced cell
CellBase.mic_safe
— Method mic_safe(l::Lattice, v::AbstractVector)
Compute MIC representation of vectors using a safe approach based on Minkowski reduced cell
CellBase.random_vec
— MethodRandom displacement vector in a unit cell
CellBase.random_vec_in_cell
— Methodrandom_vec_in_cell(cell::Matrix{T}; scales::Vector=ones(size(cell)[1])) where T
Get an random vector within a unit cell. The cell is a matrix made of column vectors.
CellBase.rec_cellmat
— Methodrec_cellmat(l::Lattice)
Returns the matrix of reciprocal lattice vectors (without the $2\pi$ factor).
CellBase.reciprocal
— Methodreciprocal(l::Lattice)
Returns the matrix of reciprocal lattice vectors (without the $2\pi$ factor).
CellBase.scaled_positions
— FunctionAlias to get_scaled_positions
CellBase.set_cellmat!
— Methodset_cellmat!(lattice::Lattice, mat)
Set the cell matrix and update the reciprocal cell matrix.
CellBase.update_rec!
— Methodupdate_rec!(l::Lattice)
Update the reciprocal matrix - this should be called everytime cell is changed.
CellBase.volume
— MethodReturn the volume of the cell
CellBase.wrap!
— MethodWrap a site back into the box
CellBase.wrap_positions
— Methodwrap_positions(l::Lattice, v::AbstractVecOrMat)
Wrap positions back into the box defined by the cell vectors.
CellBase.max_shifts
— MethodCompute the require periodicities required to fill a cut off sphere of a certain radius
CellBase.shift_indices
— Methodshift_indices(lattice::AbstractArray, rc::Real)
Compute a vector containing shift indices
CellBase.shift_vectors
— Functionshift_vectors(lattice::AbstractMatrix, shift1, shift2, shift3)
Compute the shift vectors needed to include all parts of the lattice within a cut off radius.
CellBase.shift_vectors
— MethodCompute shift vectors given lattice matrix and cut off radius
Cell
type
The Cell
type represent a crystal structure combining the positions of atoms and the lattice vectors. It basically combines the Lattice
, the atomic positions and their identities. Internally, the formere is stored as an matrix of column vectors of the absolute positions (cartesian space).
For flexibility, any additional array like data can be stored in the arrays
property which is a dictionary with Symbol
keys. Additional metadata can be also be stored under metadata
, which is a Dict{Any, Any}
.
CellBase.Cell
— TypeA Cell represents a periodic structure in three-dimensional space.
Defined as:
mutable struct Cell{T}
lattice::Lattice{T} # Lattice of the structure
symbols::Vector{Symbol}
positions::Matrix{T}
arrays::Dict{Symbol, Any} # Any additional arrays
metadata::Dict{Symbol, Any}
end
CellBase.Cell
— MethodCell(lat::Lattice, numbers::Vector{Int}, positions::Vector)
Constructure the Cell type from lattice, positions and numbers
CellBase.Cell
— MethodCell(l::Lattice, symbols, positions) where T
Construct a Cell type from arrays
CellBase.Cell
— MethodCell(lat::Lattice, numbers::Vector{Int}, positions)
Constructure the Cell type from lattice, positions and numbers
Base.sort!
— MethodBase.sort!(cell::Cell)
In-place sort a Cell
with the positions sorted by the species kinds.
This will in-place-update all underlying Array - use with caution where the data is shared between multiple instances.
Base.sort
— MethodBase.sort(cell::Cell)
Sort a Cell
with the positions sorted by the species kinds.
CellBase._distance_matrix_mic
— Method_distance_matrix_mic(cell::Cell)
Compute the distance matrix for the given structure, using the minimum image convention (or not).
Note the returned matrix does not expand the cell. The distance matrix cannot be safety used for obtaining the minimum separations. For example, a structure with a single atom would be a distance matrix containing only zero.
CellBase._distance_matrix_no_mic
— Method_distance_matrix_no_mic(structure::Cell)
Compute the distnace matrix without minimum image convention, e.g. the PBC is not respected.
CellBase.array
— Methodarray(structure::Cell, arrayname::Symbol)
Return the additional array stored in the Cell
object.
CellBase.arraynames
— Methodarraynames(structure::Cell)
Return the names of additional arrays.
CellBase.atomic_numbers
— Methodatomic_numbers(structure::Cell)
Return a Vector of the atomic numbers.
CellBase.attachmetadata!
— Methodattachmetadata!(structure::Cell, metadata::Dict)
Replace metadata
with an existing dictionary.
CellBase.cellmat
— Methodcellmat(structure::Cell)
Return the matrix of lattice vectors.
CellBase.cellpar
— Methodcellpar(structure::Cell)
Return the lattice parameters.
CellBase.check_minsep
— Methodcheck_minsep(structure::Cell, minsep::Dict)
Check if the minimum separation constraints are satisfied. Minimum separations are supplied as an dictionary where the global version under the :global key. To supply the minimum separations between A and B, pass Dict((:A=>:B)=>1.0). Return true or false.
CellBase.clip
— Methodclip(s::Cell, mask::AbstractVector)
Clip a structure with a given indexing array
CellBase.compute_minsep_mat
— Methodminsep_matrix(structure::Cell, minsep::Dict)
Initialise the minimum separation matrix and species mapping. Returns the unique species, integer indexed species and the minimum separation matrix.
CellBase.distance_squared_between
— Methoddistance_squared_between(posmat::Matrix, i, j, svec::Matrix, ishift)
Return the squared distance between two positions stored in a matrix and shift vector.
CellBase.fingerprint
— Methodfingerprint(s::Cell; dmat=distance_matrix(s), weighted=true, cut_bl=3.0)
Computed the fingerprint vector based on simple sorted pair-wise distances. NOTE: Does not work for single atom cell!!
CellBase.fingerprint_distance
— Methodfingerprint_distance(f1::AbstractVector, f2::AbstractVector;lim=Inf)
Compute the deviation between two finger print vectors
Comparison is truncated by the size of the shortest vector of the two, or by the lim
key word.
CellBase.formula_and_factor
— Methodformula_and_factor(structure::Cell)
Return reduced formula and associated factor.
CellBase.get_cellmat
— Methodget_cellmat(structure::Cell)
Return the matrix of lattice vectors(copy).
CellBase.get_lattice
— Methodget_lattice(structure::Cell)
Return the Lattice
instance (copy).
CellBase.get_positions
— Methodget_positions(cell::Cell)
Return a copy of the positions (cartesian coordinates) of the atoms in a structure.
CellBase.get_scaled_positions
— Methodget_fraction_positions(cell::Cell)
Return fractional positions of the cell.
CellBase.get_species
— Methodget_species(structure::Cell)
Return a Vector (copy) of species names.
CellBase.lattice
— Methodlattice(structure::Cell)
Return the Lattice
instance.
CellBase.make_supercell
— Methodmake_supercell(structure::Cell, a, b, c)
Make a supercell
Currently only work with diagonal transform matrices. TODO: Write function for the general cases....
CellBase.metadata
— Methodmetadata(structure::Cell)
Return the metadata
dictionary.
CellBase.natoms
— Functionnatoms(cell::Cell)
Return number of atoms in a structure.
CellBase.nions
— Methodnions(cell::Cell)
Return number of atoms in a structure.
CellBase.num_fu
— Methodnum_fu(structure::Cell)
Return the number of formula units.
CellBase.positions
— Methodpositions(cell::Cell)
Return positions (cartesian coordinates) of the atoms in a structure.
CellBase.rattle!
— Methodrattle!(cell::Cell, amp)
Rattle the positions of the cell for a given maximum amplitude (uniform distribution).
CellBase.reduced_fu
— Methodreduced_fu(structure::Cell)
Return the reduced formula.
CellBase.set_cellmat!
— Methodset_cellmat!(cell::Cell, mat;scale_positions=true)
Update the Lattice
with a new matrix of lattice vectors. Scale of the existing postions if needed.
CellBase.set_positions!
— Methodset_positions!(cell::Cell, pos)
Set the positions of the Cell
with a new matrix.
CellBase.set_scaled_positions!
— Methodset_scaled_positions!(cell::Cell, scaled::Matrix)
Set scaled positions for a cell.
CellBase.sorted_symbols
— Methodsorted_symbols(symbols)
Return sorted symbols by atomic numbers.
CellBase.species
— Methodspecies(structure::Cell)
Return a Vector of species names.
CellBase.specindex
— Methodspecindex(structure::Cell)
Return the unique species and integer based indices for each atom.
CellBase.sposarray
— Methodsposarray(cell::Cell)
Return the positions as a Vector of static arrays. The returned array can provide improved performance for certain type of operations.
CellBase.volume
— Methodvolume(structure::Cell)
Return the volume of the cell.
CellBase.wrap!
— Methodwrap!(vec::AbstractVector, l::Lattice)
Wrap a vector back to the periodic box defined by the lattice vectors.
CellBase.wrap!
— Methodwrap!(cell::Cell)
Wrap an atom outside of the lattice back into the box defined by the lattice vectors.
CellBase.wrapped_spos
— Methodwrapped_spos(cell)
Return a static array of wrapped positons.
CellBase.write_cell
— Methodwrite_cell(fname, cell::Cell)
Spglib.jl interface
The routine in Spglib.jl
(which wraps the spglib libraray) can be used for finding symmetry and performing reduction of the Cell
type.
CellBase.Cell
— MethodCell(cell::SCell)
Return a Cell
object from Spglib.Cell
where the SCell.types
have been changed to 1-based index. This is useful when the Spglib._expand_cell
is called where the types
returned is re-indexed.
CellBase.Cell
— MethodCell(cell::SCell)
Return a Cell
object from Spglib.Cell
.
CellBase.SCell
— TypeAlias for Spglib.Cell
CellBase.SCell
— MethodSCell(cell::Cell)
Construct Spglib.Cell
from Cell
type.
CellBase.niggli_reduce_cell
— Functionniggli_reduce_cell(cell::Cell; wrap_pos=true)
Apply niggli reduction to the lattice using Spglib
Spglib.niggli_reduce
— Functionniggli_reduce(cell::Cell, symprec=1e-5;)
Apply niggli reduction to the lattice using Spglib. The positions are not wrapped.
CellBase.@extend_scell
— MacroMacro for extending the Spglib methods.
Usage:
@extend_scell get_dataset
will allow the get_dataset
method of Spglib to be used for Cell
type.
CellBase.@extend_scell_roundtrip
— MacroMacro for extending the Spglib methods and convert returned Spglib.Cell
to Cell
.
Usage:
@extend_scell_roundtrip standardize_cell
will allow the standardize_cell
method to be used and the returned Spglib.Cell
is converted to Cell
. This assumes the only changes made is on the Lattice and there is no change in the atomic positions/orders.
CellBase.@extend_scell_roundtrip_new
— MacroMacro for extending the Spglib methods and convert returned Spglib.Cell
to Cell
.
Usage:
@extend_scell_roundtrip_new find_primitive
will allow the standardize_cell
method to be used and the returned Spglib.Cell
is converted to Cell
.
Misc utils
Miscellaneous utility functions.
CellBase.reduction_gauss
— Method2D Gauss reduction
Works for column vectors instead of row vectors
CellBase.cellpar2mat
— Methodconvert cell parameters to column vectors
CellBase.isvalidcellpar
— MethodCheck if cell parameters are valid
CellBase.vec2cellpar
— MethodConvert cell vectors to cell parameters
Returns an static array of the cell parameters
CellBase.volume
— MethodCompute volume from cell parameters
Neighbour lists
Type and functions for handling neighbour lists.
CellBase.ExtendedPointArray
— TypeRepresent an array of points after expansion by periodic boundary
CellBase.ExtendedPointArray
— MethodExtendedPointArray(cell::Cell, rcut)
Constructed an ExtendedPointArray from a given structure. Implicitly, the positions are wrapped inside the unit cell, even if the actual in the original Cell is outside the unit cell. This ensures the correct neighbour list begin constructed.
CellBase.NLIterator
— TypeIterator interface for going through all neighbours
CellBase.NLIteratorWithVector
— TypeIterator interface for going through all neighbours
CellBase.NeighbourList
— TypeNeighbourList{T,N}
Type for representing a neighbour list
CellBase.NeighbourList
— MethodNeighbourList(ea::ExtendedPointArray, rcut, nmax=1000; savevec=false)
Construct a NeighbourList from an extended point array for the points in the original cell
CellBase._need_rebuild
— Method_need_rebuild(nl::NeighbourList)
Check if a full rebuild is needed for the NeighbourList if the skin
is used and if any atom has move more than the skin.
CellBase._update_ea_no_lattice_change
— Method_update_ea_no_lattice_change(ea, cell)
Update extended points without lattice shifts - apply displacements to all image points
CellBase._update_ea_with_lattice_change
— Method_update_ea_with_lattice_change(ea, cell)
Update extended points with lattice shifts - need to rebuild from scratch
CellBase.allzeros
— MethodCheck if a static vector only contains zeros
CellBase.eachneighbour
— MethodIterate the neighbours of a site in the original cell. Returns a tuple of (originalindex, extendedindex, distance) for each iteration
CellBase.eachneighbourvector
— MethodIterate the neighbours of a site in the original cell. Returns a tuple of (originalindex, extendedindex, distance, vector) for each iteration
CellBase.get_neighbour
— Methodget_neighbour(nl::NeighbourList, iorig::Int, idx::Int)
Return a single neighbour.
CellBase.get_neighbours
— Methodget_neighbours(nl::NeighbourList, iorig::Int)
Return a Vector of Neighbour objects
CellBase.nions_extended
— MethodNumber of ions in the extended cell
CellBase.nions_extended
— MethodNumber of ions in the extended cell
CellBase.nions_orig
— MethodNumber of ions in the original cell
CellBase.nions_orig
— MethodNumber of ions in the original cell
CellBase.num_neighbours
— MethodNumber of neighbours for a point
CellBase.rebuild!
— Methodrebuild!(ea::ExtendedPointArray, cell)
Rebuild the ExtendedPointArray for an existing cell
CellBase.rebuild!
— Methodrebuild(nl::NeighbourList, cell::Cell)
Perform a full rebuild of the NeighbourList with the latest geometry of the cell
CellBase.rebuild!
— Methodrebuild!(nl::NeighbourList, ea::ExtendedPointArray)
Perform a full rebuild of the neighbour list from scratch for a given ExtendedPointArray. Extended the neighbour storage space if necessary.
CellBase.update!
— Methodupdate!(nl::NeighbourList, cell::Cell)
Update the NeighbourList with the latest geometry of the Cell. No rebuilding is performed.
CellBase.update!
— MethodUpdate the calculated distances/vectors but do not rebuild the whole neighbour list
CellBase.update_nmax!
— Methodincrease_nmax!(nl::NeighbourList, nmax)
Increase the maximum number of neighbours storable in the neighbour list
IO
Code for read/writing file of crystal structures.
CellBase.read_res
— MethodRead an array containing the lines of the SHELX file
CellBase.read_res_many
— Methodread_res_many(s::AbstractString)
Read many SHELX files from a packed file.
CellBase.read_res_many
— Methodread_res_many(s::IO)
Read many SHELX files from an IO stream
CellBase.write_res
— Functionwrite_res(fname::AbstractString, structure::Cell, mode="w")
Write out SHELX format data to a file
CellBase.write_res
— Methodwrite_res(io::IO, structure::Cell)
Write out SHELX format data including additional information stored in structure.metadata
.
Supported keys: :label
, :pressure
, :volume
, :enthalpy
, :spin
, :abs_spin
, :symm
, :flag1
, flag2
, flag3
.
The following fields are also treated as the REM
line:
info
: If aDict
is supplied the key-value pairs will be written.comments
: Any additional comments to be written. Must be supplied as aVector{<:AbstractString}
.
The composition of the structure will be written as REM Composition: <E1> <N1> <E2> <N2>
.
CellBase._process_xyz_attr
— Method_process_xyz_attr(attr)
Process ExtXYZ attribute string.
CellBase.push_xyz!
— Methodxyz lines for a single frame
CellBase.read_xyz
— MethodRead XYZ file
NOTE: This is a pure julia implementation which may not work with all cases. In the future, better to use ExtXYZ.jl interface.
CellBase.write_xyz
— MethodWrite snapshots to a xyz file
CellBase.CellIO._parse_tagline
— MethodParse the tag line, return a dictionary of the tagline is in the form of <ionsetname> % KEY=VALUE KEY=VALUE
CellBase.CellIO.clean_lines
— MethodClean lines by removing new line symbols and comments
CellBase.CellIO.filter_block
— MethodGet rid of blocks
CellBase.CellIO.filter_block
— MethodFilter away block names contained in only
CellBase.CellIO.find_block
— MethodFind the block with given name, return a Vector of the lines Comments are skipped
CellBase.CellIO.parse_taglines
— MethodParse tag lines, return a vector of dictionary containing parsed tags
CellBase.CellIO.read_cell
— MethodRead a cell file
CellBase.CellIO.read_cell
— MethodRead content of a cell file
CellBase.CellIO.read_cellmat
— MethodRead cell related sections
CellBase.CellIO.read_num_block
— MethodRead a numerical block in the form of a vector of String
CellBase.CellIO.read_positions
— MethodRead positions related sections
CellBase.CellIO.read_seed
— MethodRead in cell
CellBase.CellIO.read_seed
— MethodRead seed with the label parsed. At this stage no explansions are done
CellBase.CellIO.separate_unit
— MethodSeparate the unit from the actual content of the block
CellBase.DotCastep.SnapShot
— TypeRepresentation of a snapshot
CellBase.DotCastep._get_nions
— MethodGet the number of ions
CellBase.DotCastep._read_snapshot
— FunctionRead the initial structure and its energy/forces
CellBase.DotCastep.read_castep
— Methodread_castep(fname::String)
Read a CASTEP file, return a Vector of the Snapshots
CellBase.DotCastep.read_coord_table!
— FunctionRead fractional coordinates (column vectors) from a table
CellBase.DotCastep.read_lattice
— MethodRead lattice vectors from the lines (column vectors)
CellBase.DotCastep.skip_to_header
— MethodSkip to the next header
CellBase.SheapIO.SheapOptions
— TypeCommandline options for SHEAP
CellBase.SheapIO._SheapDefaultOptions
— TypeRecord the default options of SHEAP commandline
CellBase.SheapIO.parse_sheap_output
— MethodPrase the output of SHEAP from an IO object
CellBase.SheapIO.run_sheap
— Methodrun_sheap(vecs, opt::SheapOptions;metadata=repeat([SheapMetadata()], length(vecs)), show_stderr=true)
Run SHEAP for a iterator of vectors with the given options.