MDStressLab++
Loading...
Searching...
No Matches
BoxConfiguration Class Reference

Represents a particle configuration including simulation box information. More...

#include <BoxConfiguration.h>

Inheritance diagram for BoxConfiguration:
Collaboration diagram for BoxConfiguration:

Public Member Functions

 BoxConfiguration (int numberOfParticles, int referenceAndFinal)
 Constructs a BoxConfiguration with a given number of particles.
 
ConfigurationgetConfiguration (double padding) const
 This function returns a padded configuration by adding padding atoms originating due to pbcs.
 
void read (std::string configFileName, int referenceAndFinal)
 A function to read the properties of atoms from a file in a MDStressLab format.
 
void readLMP (const std::string &, const ConfigType &configType)
 Reads a configuration from an LAMMPS-style dump file.
 
void readLMP (const std::string &currentConfigFileName, const std::string &referenceConfigFileName)
 Reads both current and reference configurations from LAMMPS-style dump files.
 
void lmpParser (std::ifstream &, const ConfigType &)
 Parses a LAMMPS dump file to populate configuration data.
 
virtual ~BoxConfiguration ()
 
- Public Member Functions inherited from Configuration
 Configuration (int, int)
 Constructs a Configuration object.
 
virtual ~Configuration ()
 
ConfigurationgetLocalConfiguration (const std::set< int > &localParticleList) const
 can be deleted
 

Public Attributes

Matrix3d box
 The current and reference box vectors stored as columns of respective matrices.
 
Matrix3d reference_box
 
Vector3i pbc
 Periodic boundary conditions. pbc=(1,0,1) implies periodicity along the \(x\) and \(z\)-directions.
 
- Public Attributes inherited from Configuration
int numberOfParticles
 Total number of particles in the configuration.
 
std::vector< std::string > species
 Species names for each particle (size equals numberOfParticles).
 
std::map< ConfigType, MatrixXdcoordinates
 Map from configuration type (Reference or Current) to coordinate matrices.
 
MatrixXd velocities
 Velocities of particles.
 

Detailed Description

Represents a particle configuration including simulation box information.

This class extends the base Configuration class by adding storage for simulation box vectors (both Current and Reference) and periodic boundary conditions. It provides functionality to read configurations from MDStressLab and LAMMPS dump-style files, manage padding due to periodicity, and access box geometry details.

The box vectors are stored as columns in 3×3 matrices (box and reference_box), and periodic boundary conditions are represented as a 3D integer vector indicating periodicity along each Cartesian axis.

This class supports reading atomic configurations from two file formats:

  • MDStressLab custom format with explicit box vectors and particle data.
  • LAMMPS dump files with box bounds, masses, and atom coordinates.

It also allows extracting padded configurations to accommodate atoms near periodic boundaries, facilitating simulations requiring extended neighbor lists or replicas.

Examples
crack/main.cpp, testLDADLJ.cpp, testLJ.cpp, and testMls.cpp.

Definition at line 33 of file BoxConfiguration.h.

Constructor & Destructor Documentation

◆ BoxConfiguration()

BoxConfiguration::BoxConfiguration ( int  numberOfParticles,
int  referenceAndFinal 
)

Constructs a BoxConfiguration with a given number of particles.

Parameters
[in]numberOfParticlesThe number of particles in the configuration.
[in]referenceAndFinalFlag indicating which configurations to allocate:
  • 0: Only Current configuration
  • 1: Both Reference and Current configurations

Definition at line 16 of file BoxConfiguration.cpp.

◆ ~BoxConfiguration()

BoxConfiguration::~BoxConfiguration ( )
virtual

Definition at line 322 of file BoxConfiguration.cpp.

Member Function Documentation

◆ getConfiguration()

Configuration * BoxConfiguration::getConfiguration ( double  padding) const

This function returns a padded configuration by adding padding atoms originating due to pbcs.

Parameters
padding- thickness of the padding region
Returns
- a pointer to an allocated padded configuration

Definition at line 275 of file BoxConfiguration.cpp.

◆ lmpParser()

void BoxConfiguration::lmpParser ( std::ifstream &  file,
const ConfigType configType 
)

Parses a LAMMPS dump file to populate configuration data.

This function reads atomic configuration data, box dimensions, masses, and species information from a LAMMPS-style dump file stream, filling the relevant members of the BoxConfiguration object according to the specified configuration type.

The expected file format includes sections for:

  • Number of atoms
  • Number of atom types
  • Box bounds (xlo xhi, ylo yhi, zlo zhi)
  • Optional tilt factors (not currently handled explicitly)
  • Masses section mapping atom types to species names
  • Atoms section with atomic coordinates and optional image flags for periodicity

Coordinates are adjusted for periodic boundary conditions using image flags. The function ensures species consistency between reference and current configurations.

Parameters
[in,out]fileInput file stream positioned at the beginning of the LAMMPS dump file.
[in]configTypeThe type of configuration to read (e.g., Current or Reference).
Exceptions
MY_ERRORIf the number of atoms in the file does not match the expected number, or if coordinate parsing fails for any particle.

Definition at line 125 of file BoxConfiguration.cpp.

◆ read()

void BoxConfiguration::read ( std::string  configFileName,
int  referenceAndFinal 
)

A function to read the properties of atoms from a file in a MDStressLab format.

Parameters
configFileName- Name of the configuration file to read
referenceAndFinalFlag indicating which data to read:
  • 0: Only Current configuration
  • 1: Both Reference and Current configurations

The MDStressLab format of the configuration file is described below

  • Line 1: Number of particles (integer)
  • Lines 2–4: Reference box vectors as columns of a 3×3 matrix
  • Lines 5–7: Current box vectors as columns of a 3×3 matrix
  • Line 8: Periodic boundary conditions (3 integers, typically 0 or 1)
  • Line 9 onward: Per-particle data in 10 columns:
    • Column 1: Species code (e.g., Ar)
    • Columns 2–4: Current coordinates (x, y, z)
    • Columns 5–7: Velocities (vx, vy, vz)
    • Columns 8–10: Reference coordinates (X, Y, Z)

📄 Example:

   2
   52.9216036151419047 0.0 0.0
   0.0  52.9216036151419047 0.0
   0.0  0.0 52.9216036151419047
   52.9216036151419047 0.0 0.0
   0.0  53.4508196512933154 0.0
   0.0  0.0 52.9216036151419047
   1 1 1
   Ar  0.0000000000000000 0.0000000000000000 0.0000000000000000  0.0000000000000000 0.0000000000000000 0.0000000000000000  0.0000000000000000 0.0000000000000000 0.0000000000000000
   Ar  0.0000000000000000 2.6725409825646658 2.6460801807570951  0.0000000000000000 0.0000000000000000 0.0000000000000000  0.0000000000000000 2.6460801807570951 2.6460801807570951
* 
Examples
crack/main.cpp, testLDADLJ.cpp, testLJ.cpp, and testMls.cpp.

Definition at line 33 of file BoxConfiguration.cpp.

◆ readLMP() [1/2]

void BoxConfiguration::readLMP ( const std::string &  configFileName,
const ConfigType configType 
)

Reads a configuration from an LAMMPS-style dump file.

Opens the specified file and reads the atomic configuration data for the given configuration type (e.g., Reference or Current). This function supports only files with the .lmp extension and delegates detailed parsing to the private method lmpParser.

On failure to open the file or if the file extension is not .lmp, this function prints an error message and terminates the program.

Parameters
[in]filenameThe name of the LAMMPS dump file.
[in]configTypeSpecifies which configuration type to read (e.g., Reference or Current).

The expected file format is a LAMMPS dump file with the following structure:

  • A header line with an optional comment (e.g., crystal orientation)
  • Line indicating the number of atoms (e.g., 24480 atoms)
  • Line indicating the number of atom types (e.g., 3 atom types)
  • Box bounds:
    xlo xhi
    ylo yhi
    zlo zhi
    Optionally followed by xy xz yz tilt factors (for triclinic cells)
  • A Masses section listing:
    <atom type> <mass> #<element symbol>
  • An Atoms section:
    Atoms # atomic
    <atom ID> <atom type> <x> <y> <z> <ix> <iy> <iz>
    where ix, iy, iz are image flags used to unwrap atom positions.

Example snippet:

# Bcc oriented X=[-111] Y=[101] Z=[12-1].
24480 atoms
3 atom types
-95.18727654954 95.18727654954 xlo xhi
-45.71769755913 45.71769755913 ylo yhi
-11.877806246622 11.877806246622 zlo zhi
0 0 0 xy xz yz
Masses
1 92.908 #Nb
2 180.95 #Ta
3 50.941 #V
Atoms # atomic
1 1 -95.15 -45.68 11.86 0 0 -1
24003 3 -35.46 -2.29 5.25 0 0 0
3 1 -94.28 -45.69 -6.59 0 0 0
...

Definition at line 88 of file BoxConfiguration.cpp.

◆ readLMP() [2/2]

void BoxConfiguration::readLMP ( const std::string &  currentConfigFileName,
const std::string &  referenceConfigFileName 
)

Reads both current and reference configurations from LAMMPS-style dump files.

Parameters
[in]currentConfigFileNameThe name of the file containing the current configuration.
[in]referenceConfigFileNameThe name of the file containing the reference configuration.

Definition at line 116 of file BoxConfiguration.cpp.

Member Data Documentation

◆ box

Matrix3d BoxConfiguration::box

The current and reference box vectors stored as columns of respective matrices.

Definition at line 38 of file BoxConfiguration.h.

◆ pbc

Vector3i BoxConfiguration::pbc

Periodic boundary conditions. pbc=(1,0,1) implies periodicity along the \(x\) and \(z\)-directions.

Definition at line 43 of file BoxConfiguration.h.

◆ reference_box

Matrix3d BoxConfiguration::reference_box

Definition at line 38 of file BoxConfiguration.h.


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