Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
correlation::core::Cell Class Reference

Represents the simulation cell (periodic box). More...

#include <Cell.hpp>

Collaboration diagram for correlation::core::Cell:

Public Member Functions

Constructors
 Cell ()=default
 Cell (const math::Vector3< real_t > &vec_a, const math::Vector3< real_t > &vec_b, const math::Vector3< real_t > &vec_c)
 Constructs a Cell from three lattice vectors.
 Cell (const std::array< real_t, 6 > &params)
 Constructs a Cell from lattice parameters {a, b, c, alpha, beta, gamma}.
 Cell (Cell &&other) noexcept=default
 Move constructor. Transfers ownership of lattice vectors and atom data.
Cell & operator= (Cell &&other) noexcept=default
 Move assignment operator.
 Cell (const Cell &other)=default
 Copy constructor.
Cell & operator= (const Cell &other)=default
 Copy assignment operator.
 ~Cell ()=default
 Destructor.
Accessors
const std::array< real_t, 6 > & latticeParameters () const noexcept
 Gets the lattice parameters (a, b, c, alpha, beta, gamma).
void setLatticeParameters (const std::array< real_t, 6 > &params)
const math::Matrix3< real_t > & latticeVectors () const noexcept
 Gets the lattice vectors as a 3x3 matrix.
const math::Matrix3< real_t > & inverseLatticeVectors () const noexcept
 Gets the inverse lattice vectors as a 3x3 matrix. Useful for converting Cartesian coordinates to fractional coordinates.
const real_t & volume () const noexcept
 Gets the volume of the simulation cell.
const std::vector< Atom > & atoms () const noexcept
 Gets the list of atoms in the cell.
std::vector< Atom > & atoms () noexcept
 Gets a mutable list of atoms in the cell.
std::span< const Atom > atomSpan () const noexcept
 Gets an immutable span view over the atoms in the cell.
std::span< Atom > atomSpan () noexcept
 Gets a mutable span view over the atoms in the cell.
bool hasVelocities () const noexcept
 Checks whether lazy per-atom velocities have been allocated for this cell.
const std::vector< math::Vector3< real_t > > & velocities () const noexcept
 Gets the contiguous lazy velocity buffer (empty if velocities were never set).
math::Vector3< real_t > atomVelocity (size_t atom_idx) const noexcept
 Gets the velocity of a specific atom, returning {0, 0, 0} if unallocated.
void setAtomVelocity (size_t atom_idx, const math::Vector3< real_t > &vel)
 Sets the velocity of a specific atom, lazily allocating velocities_ on first write.
void ensureVelocities ()
 Ensures the lazy velocity buffer is sized to match atomCount().
const std::vector< Element > & elements () const noexcept
 Gets the list of unique chemical elements in the cell.
std::span< const Element > elementSpan () const noexcept
 Gets an immutable span view over unique chemical elements in the cell.
size_t atomCount () const noexcept
 Gets the total number of atoms in the cell.
bool isEmpty () const noexcept
 Checks whether the cell contains no atoms.
std::optional< Element > findElement (std::string_view symbol) const
 Finds the Element properties for a given element symbol.
bool renameElement (std::string_view old_symbol, std::string_view new_symbol)
 Renames an existing element species in-place across all atoms in the cell.
Methods
math::Vector3< real_t > minimumImage (const math::Vector3< real_t > &distance) const
 Applies the minimum image convention to a distance vector.
Atom & addAtom (std::string_view symbol, const math::Vector3< real_t > &position)
 Adds a new atom to the cell. The atom's element type is automatically registered if it's the first mention of this symbol.
void wrapPositions ()
 Applies periodic boundary conditions to all atom positions. Wraps all atoms back into the primary simulation cell [0, 1) in fractional coordinates.
std::array< real_t, 3 > perpendicularWidths () const noexcept
 Computes the perpendicular widths (interplanar spacing) between opposing cell faces.
Cell replicate (int rep_a, int rep_b, int rep_c) const
 Replicates the simulation cell na x nb x nc times along lattice vectors.
Cell autoSupercell (real_t r_cut, int max_replication=10, real_t max_radius=correlation::math::MAX_CUTOFF_RADIUS) const
 Automatically expands the cell to satisfy the Minimum Image Convention for cutoff r_cut.
void setEnergy (real_t energy) noexcept
 Sets the energy of the cell frame.
real_t getEnergy () const noexcept
 Gets the energy of the cell frame.
void reserveAtoms (std::size_t count)
 Reserves capacity for atom storage to minimize reallocations.
void updateLattice (const math::Matrix3< real_t > &new_lattice)
 Updates lattice vectors and recomputes volume, inverse matrix, and scalar parameters.

Private Member Functions

void updateLatticeParametersFromVectors ()
 Internal helper to synchronize scalar parameters with vector matrix.
const Element & getOrRegisterElement (std::string_view symbol)
 Registers an element symbol if not already present and returns its Element reference.

Private Attributes

math::Matrix3< real_t > lattice_vectors_
 Basis vectors of the box.
math::Matrix3< real_t > inverse_lattice_vectors_
 Inverse matrix for fractional mapping.
std::array< real_t, 6 > lattice_parameters_ {}
 {a, b, c, alpha, beta, gamma}.
real_t volume_ {0.0}
 Cached volume in Angstroms^3.
real_t energy_ {0.0}
 Potential energy of this specific coordinate set.
std::vector< Atom > atoms_
 Collection of atoms in the cell.
std::vector< Element > elements_
 Unique elements present in the system.
std::vector< math::Vector3< real_t > > velocities_
 Lazy per-atom velocities/forces (0 B when unused).

Detailed Description

Represents the simulation cell (periodic box).

This class handles the lattice vectors, periodic boundary conditions, and stores the atoms contained within the cell.

Constructor & Destructor Documentation

◆ Cell() [1/5]

correlation::core::Cell::Cell ( )
explicitdefault
Here is the caller graph for this function:

◆ Cell() [2/5]

correlation::core::Cell::Cell ( const math::Vector3< real_t > & vec_a,
const math::Vector3< real_t > & vec_b,
const math::Vector3< real_t > & vec_c )
explicit

Constructs a Cell from three lattice vectors.

Parameters
vec_aThe first lattice vector.
vec_bThe second lattice vector.
vec_cThe third lattice vector.
Here is the call graph for this function:

◆ Cell() [3/5]

correlation::core::Cell::Cell ( const std::array< real_t, 6 > & params)
explicit

Constructs a Cell from lattice parameters {a, b, c, alpha, beta, gamma}.

Parameters
paramsAn array containing the six lattice parameters:
  • params[0]: a (length of vector a in Angstroms)
  • params[1]: b (length of vector b in Angstroms)
  • params[2]: c (length of vector c in Angstroms)
  • params[3]: alpha (angle between b and c in degrees)
  • params[4]: beta (angle between a and c in degrees)
  • params[5]: gamma (angle between a and b in degrees)
Here is the call graph for this function:

◆ Cell() [4/5]

correlation::core::Cell::Cell ( Cell && other)
defaultnoexcept

Move constructor. Transfers ownership of lattice vectors and atom data.

Parameters
otherCell object to move from.
Here is the call graph for this function:

◆ Cell() [5/5]

correlation::core::Cell::Cell ( const Cell & other)
default

Copy constructor.

Parameters
otherCell object to copy from.
Here is the call graph for this function:

◆ ~Cell()

correlation::core::Cell::~Cell ( )
default

Destructor.

Member Function Documentation

◆ addAtom()

Atom & correlation::core::Cell::addAtom ( std::string_view symbol,
const math::Vector3< real_t > & position )

Adds a new atom to the cell. The atom's element type is automatically registered if it's the first mention of this symbol.

Parameters
symbolThe chemical element symbol (e.g. "Fe").
positionThe Cartesian position [x, y, z] in Angstroms.
Returns
A reference to the newly created Atom.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ atomCount()

size_t correlation::core::Cell::atomCount ( ) const
inlinenodiscardnoexcept

Gets the total number of atoms in the cell.

Returns
The number of atoms.
Here is the caller graph for this function:

◆ atoms() [1/2]

const std::vector< Atom > & correlation::core::Cell::atoms ( ) const
inlinenodiscardnoexcept

Gets the list of atoms in the cell.

Returns
Constant reference to the vector of atoms.
Here is the caller graph for this function:

◆ atoms() [2/2]

std::vector< Atom > & correlation::core::Cell::atoms ( )
inlinenodiscardnoexcept

Gets a mutable list of atoms in the cell.

Returns
Reference to the vector of atoms.

◆ atomSpan() [1/2]

std::span< const Atom > correlation::core::Cell::atomSpan ( ) const
inlinenodiscardnoexcept

Gets an immutable span view over the atoms in the cell.

Returns
Const span of Atom elements.

◆ atomSpan() [2/2]

std::span< Atom > correlation::core::Cell::atomSpan ( )
inlinenodiscardnoexcept

Gets a mutable span view over the atoms in the cell.

Returns
Mutable span of Atom elements.

◆ atomVelocity()

math::Vector3< real_t > correlation::core::Cell::atomVelocity ( size_t atom_idx) const
inlinenodiscardnoexcept

Gets the velocity of a specific atom, returning {0, 0, 0} if unallocated.

Parameters
[in]atom_idxZero-based atom index.
Returns
Velocity vector in Angstroms/fs (or force vector for MLIP dataset readers).
Here is the caller graph for this function:

◆ autoSupercell()

Cell correlation::core::Cell::autoSupercell ( real_t r_cut,
int max_replication = 10,
real_t max_radius = correlation::math::MAX_CUTOFF_RADIUS ) const
nodiscard

Automatically expands the cell to satisfy the Minimum Image Convention for cutoff r_cut.

Computes minimal replication factors along each axis such that every perpendicular width satisfies w_k >= 2 * r_cut, up to safety limits.

Parameters
r_cutInteraction or evaluation cutoff radius in Angstroms.
max_replicationMaximum allowable replication factor per axis (default: 10).
max_radiusMaximum allowable cutoff radius ceiling (default: 50.0 Angstroms).
Returns
A minimally replicated supercell satisfying w_perp >= 2 * r_cut, or *this if already large enough.
Exceptions
std::invalid_argumentIf r_cut > max_radius or required replication exceeds max_replication.
Here is the call graph for this function:

◆ elements()

const std::vector< Element > & correlation::core::Cell::elements ( ) const
inlinenodiscardnoexcept

Gets the list of unique chemical elements in the cell.

Returns
Constant reference to the vector of elements.
Here is the caller graph for this function:

◆ elementSpan()

std::span< const Element > correlation::core::Cell::elementSpan ( ) const
inlinenodiscardnoexcept

Gets an immutable span view over unique chemical elements in the cell.

Returns
Const span of Element instances.
Here is the caller graph for this function:

◆ ensureVelocities()

void correlation::core::Cell::ensureVelocities ( )
inline

Ensures the lazy velocity buffer is sized to match atomCount().

◆ findElement()

std::optional< Element > correlation::core::Cell::findElement ( std::string_view symbol) const
nodiscard

Finds the Element properties for a given element symbol.

Parameters
symbolThe element symbol (e.g., "Si").
Returns
An optional containing the Element struct if found, otherwise std::nullopt.

◆ getEnergy()

real_t correlation::core::Cell::getEnergy ( ) const
inlinenodiscardnoexcept

Gets the energy of the cell frame.

Returns
The energy value.
Here is the caller graph for this function:

◆ getOrRegisterElement()

const Element & correlation::core::Cell::getOrRegisterElement ( std::string_view symbol)
private

Registers an element symbol if not already present and returns its Element reference.

Parameters
symbolElement symbol (e.g. "O").
Returns
Reference to the registered Element.
Here is the caller graph for this function:

◆ hasVelocities()

bool correlation::core::Cell::hasVelocities ( ) const
inlinenodiscardnoexcept

Checks whether lazy per-atom velocities have been allocated for this cell.

Returns
True if velocities are present.
Here is the caller graph for this function:

◆ inverseLatticeVectors()

const math::Matrix3< real_t > & correlation::core::Cell::inverseLatticeVectors ( ) const
inlinenodiscardnoexcept

Gets the inverse lattice vectors as a 3x3 matrix. Useful for converting Cartesian coordinates to fractional coordinates.

Returns
Constant reference to the inverse lattice vectors matrix.
Here is the caller graph for this function:

◆ isEmpty()

bool correlation::core::Cell::isEmpty ( ) const
inlinenodiscardnoexcept

Checks whether the cell contains no atoms.

Returns
True if empty, false otherwise.
Here is the caller graph for this function:

◆ latticeParameters()

const std::array< real_t, 6 > & correlation::core::Cell::latticeParameters ( ) const
inlinenodiscardnoexcept

Gets the lattice parameters (a, b, c, alpha, beta, gamma).

Returns
Array of 6 real_t containing the parameters.
Here is the caller graph for this function:

◆ latticeVectors()

const math::Matrix3< real_t > & correlation::core::Cell::latticeVectors ( ) const
inlinenodiscardnoexcept

Gets the lattice vectors as a 3x3 matrix.

Returns
Constant reference to the lattice vectors matrix.
Here is the caller graph for this function:

◆ minimumImage()

math::Vector3< real_t > correlation::core::Cell::minimumImage ( const math::Vector3< real_t > & distance) const
nodiscard

Applies the minimum image convention to a distance vector.

Finds the shortest distance vector between two points under periodic boundary conditions.

Parameters
distanceThe Cartesian distance vector to wrap.
Returns
The minimum image Cartesian distance vector.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

Cell & correlation::core::Cell::operator= ( Cell && other)
defaultnoexcept

Move assignment operator.

Parameters
otherCell object to move from.
Returns
Reference to this cell.
Here is the call graph for this function:

◆ operator=() [2/2]

Cell & correlation::core::Cell::operator= ( const Cell & other)
default

Copy assignment operator.

Parameters
otherCell object to copy from.
Returns
Reference to this cell.
Here is the call graph for this function:

◆ perpendicularWidths()

std::array< real_t, 3 > correlation::core::Cell::perpendicularWidths ( ) const
nodiscardnoexcept

Computes the perpendicular widths (interplanar spacing) between opposing cell faces.

For lattice vectors a, b, c with volume V, returns {V / ||b x c||, V / ||a x c||, V / ||a x b||}. If volume is non-positive or vectors are degenerate, returns {0, 0, 0}.

Returns
Array containing {w_a, w_b, w_c} in Angstroms.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ renameElement()

bool correlation::core::Cell::renameElement ( std::string_view old_symbol,
std::string_view new_symbol )

Renames an existing element species in-place across all atoms in the cell.

Parameters
old_symbolExisting element symbol (e.g., "1").
new_symbolReplacement element symbol (e.g., "Cu").
Returns
True if the element was found and renamed, false otherwise.
Here is the caller graph for this function:

◆ replicate()

Cell correlation::core::Cell::replicate ( int rep_a,
int rep_b,
int rep_c ) const
nodiscard

Replicates the simulation cell na x nb x nc times along lattice vectors.

Parameters
rep_aReplication factor along lattice vector a (>= 1).
rep_bReplication factor along lattice vector b (>= 1).
rep_cReplication factor along lattice vector c (>= 1).
Returns
Replicated supercell with expanded lattice vectors and translated atoms.
Exceptions
std::invalid_argumentIf any factor is < 1 or total atom count exceeds 50,000.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reserveAtoms()

void correlation::core::Cell::reserveAtoms ( std::size_t count)
inline

Reserves capacity for atom storage to minimize reallocations.

Parameters
countExpected number of atoms.
Here is the caller graph for this function:

◆ setAtomVelocity()

void correlation::core::Cell::setAtomVelocity ( size_t atom_idx,
const math::Vector3< real_t > & vel )
inline

Sets the velocity of a specific atom, lazily allocating velocities_ on first write.

Parameters
[in]atom_idxZero-based atom index.
[in]velVelocity vector.
Here is the caller graph for this function:

◆ setEnergy()

void correlation::core::Cell::setEnergy ( real_t energy)
inlinenoexcept

Sets the energy of the cell frame.

Parameters
energyThe energy value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLatticeParameters()

void correlation::core::Cell::setLatticeParameters ( const std::array< real_t, 6 > & params)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateLattice()

void correlation::core::Cell::updateLattice ( const math::Matrix3< real_t > & new_lattice)

Updates lattice vectors and recomputes volume, inverse matrix, and scalar parameters.

Parameters
new_latticeNew 3x3 lattice matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateLatticeParametersFromVectors()

void correlation::core::Cell::updateLatticeParametersFromVectors ( )
private

Internal helper to synchronize scalar parameters with vector matrix.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ velocities()

const std::vector< math::Vector3< real_t > > & correlation::core::Cell::velocities ( ) const
inlinenodiscardnoexcept

Gets the contiguous lazy velocity buffer (empty if velocities were never set).

Returns
Const reference to velocity vectors.

◆ volume()

const real_t & correlation::core::Cell::volume ( ) const
inlinenodiscardnoexcept

Gets the volume of the simulation cell.

Returns
The volume value in cubic Angstroms (typically).
Here is the caller graph for this function:

◆ wrapPositions()

void correlation::core::Cell::wrapPositions ( )

Applies periodic boundary conditions to all atom positions. Wraps all atoms back into the primary simulation cell [0, 1) in fractional coordinates.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ atoms_

std::vector<Atom> correlation::core::Cell::atoms_
private

Collection of atoms in the cell.

◆ elements_

std::vector<Element> correlation::core::Cell::elements_
private

Unique elements present in the system.

◆ energy_

real_t correlation::core::Cell::energy_ {0.0}
private

Potential energy of this specific coordinate set.

◆ inverse_lattice_vectors_

math::Matrix3<real_t> correlation::core::Cell::inverse_lattice_vectors_
private

Inverse matrix for fractional mapping.

◆ lattice_parameters_

std::array<real_t, 6> correlation::core::Cell::lattice_parameters_ {}
private

{a, b, c, alpha, beta, gamma}.

◆ lattice_vectors_

math::Matrix3<real_t> correlation::core::Cell::lattice_vectors_
private

Basis vectors of the box.

◆ velocities_

std::vector<math::Vector3<real_t> > correlation::core::Cell::velocities_
private

Lazy per-atom velocities/forces (0 B when unused).

◆ volume_

real_t correlation::core::Cell::volume_ {0.0}
private

Cached volume in Angstroms^3.


The documentation for this class was generated from the following files: