Molecular Dynamics Simulation  1.0
Public Member Functions | List of all members
XYZWriter Class Reference

Class to write particle data to a .xyz file. More...

#include <XYZWriter.h>

Inheritance diagram for XYZWriter:
Inheritance graph
Collaboration diagram for XYZWriter:
Collaboration graph

Public Member Functions

const std::filesystem::path writeFile (const SimulationParams &params, size_t iteration, const std::vector< Particle > &particles) const override
 Writes the data of the given ParticleContainer to a .xyz file. More...
 
- Public Member Functions inherited from FileWriter
virtual ~FileWriter ()=default
 virtual destructor for correct cleanup of derived classes More...
 

Detailed Description

Class to write particle data to a .xyz file.

Definition at line 13 of file XYZWriter.h.

Member Function Documentation

◆ writeFile()

const std::filesystem::path XYZWriter::writeFile ( const SimulationParams params,
size_t  iteration,
const std::vector< Particle > &  particles 
) const
overridevirtual

Writes the data of the given ParticleContainer to a .xyz file.

Parameters
paramsSimulationParams object which provides the output directory path
iterationThe current iteration
particlesA vector of particles to write to the file
Returns
The path to the written file

Implements FileWriter.

Definition at line 7 of file XYZWriter.cpp.

8  {
9  auto file_name = params.output_dir_path / fmt::format("MD_XYZ_{:04d}.xyz", iteration);
10 
11  std::ofstream file;
12 
13  file.open(file_name);
14  file << particles.size() << std::endl;
15  file << "Generated by MolSim. See http://openbabel.org/wiki/XYZ_(format) for file format doku." << std::endl;
16 
17  for (auto& p : particles) {
18  std::array<double, 3> x = p.getX();
19  file << "Ar ";
20  file.setf(std::ios_base::showpoint);
21 
22  for (auto& xi : x) {
23  file << xi << " ";
24  }
25 
26  file << std::endl;
27  }
28 
29  file.close();
30 
31  return file_name;
32 }
std::filesystem::path output_dir_path
Path to the directory in which to save the simulation output.

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