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 a LAMMPS data 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 data 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, and their origins.
 
Matrix3d reference_box
 
Vector3d box_origin
 
Vector3d reference_box_origin
 
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).
 
VectorXd masses
 Mass of each particle.
 
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), with separate origins (box_origin and reference_box_origin). Periodic boundary conditions are represented as a 3D integer vector indicating periodicity along the box-vector directions.

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. Padding creates periodic images as needed but does not fold the original atoms or grid points back into the primary cell; preserving the supplied atom identity and reference/current correspondence is the caller's responsibility.

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

Definition at line 37 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 19 of file BoxConfiguration.cpp.

◆ ~BoxConfiguration()

BoxConfiguration::~BoxConfiguration ( )
virtual

Definition at line 457 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 396 of file BoxConfiguration.cpp.

◆ lmpParser()

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

Parses a LAMMPS data 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 (xy xz yz) for triclinic cells
  • 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. Atoms are not folded into the primary MDStressLab box after reading. 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 195 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)
  • Optional Line 2: Box origin, tagged as origin ox oy oz. If absent, both reference and current origins default to (0,0,0).
  • Next 3 lines: Reference box vectors as columns of a 3×3 matrix
  • Next 3 lines: Current box vectors as columns of a 3×3 matrix
  • Next line: Periodic boundary conditions (3 integers, typically 0 or 1)
  • Next line: Species-mass pairs:
    *   <species_1> <mass_1> <species_2> <mass_2> ...
    *   
  • Line 10 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
   origin 0.0 0.0 0.0
   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 39.948
   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, testLDADSWTriclinic.cpp, testLJ.cpp, and testMls.cpp.

Definition at line 38 of file BoxConfiguration.cpp.

◆ readLMP() [1/2]

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

Reads a configuration from a LAMMPS data 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]configFileNameThe name of the LAMMPS data file.
[in]configTypeSpecifies which configuration type to read (e.g., Reference or Current).

The expected file format is a LAMMPS data 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)
  • Orthogonal or triclinic box bounds:
    xlo xhi
    ylo yhi
    zlo zhi
    Optionally followed by xy xz yz tilt factors for triclinic cells. The parser stores the corresponding lower corner as the box origin and builds the box vectors from the LAMMPS bounds and tilt factors.
  • 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
...
Examples
testIdealGas.cpp.

Definition at line 158 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 186 of file BoxConfiguration.cpp.

Member Data Documentation

◆ box

Matrix3d BoxConfiguration::box

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

Definition at line 42 of file BoxConfiguration.h.

◆ box_origin

Vector3d BoxConfiguration::box_origin

Definition at line 43 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 48 of file BoxConfiguration.h.

◆ reference_box

Matrix3d BoxConfiguration::reference_box

Definition at line 42 of file BoxConfiguration.h.

◆ reference_box_origin

Vector3d BoxConfiguration::reference_box_origin

Definition at line 43 of file BoxConfiguration.h.


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