Molecular Dynamics Simulation  1.0
XYZWriter.cpp
Go to the documentation of this file.
1 #include "XYZWriter.h"
2 
3 #include <spdlog/fmt/bundled/core.h>
4 
5 #include <iomanip>
6 
7 const std::filesystem::path XYZWriter::writeFile(const SimulationParams& params, size_t iteration,
8  const std::vector<Particle>& particles) const {
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 }
Contains all parameters needed to run a simulation.
std::filesystem::path output_dir_path
Path to the directory in which to save the simulation output.
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.
Definition: XYZWriter.cpp:7