Simpatico  v1.10
tools/analyzers/LammpsDumpWriter.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "LammpsDumpWriter.h"
9 #include <tools/storage/Configuration.h>
10 #include <tools/chemistry/Atom.h>
11 #include <tools/chemistry/Group.h>
12 
13 #include <util/archives/BinaryFileOArchive.h>
14 #include <util/format/Dbl.h>
15 #include <util/space/Vector.h>
16 
17 namespace Tools
18 {
19 
20  using namespace Util;
21 
22  /*
23  * Constructor.
24  */
26  : TrajectoryWriter(processor, false)
27  {}
28 
29  /*
30  * Constructor.
31  */
34  : TrajectoryWriter(configuration, fileMaster, false)
35  {}
36 
37  /*
38  * Destructor.
39  */
41  {}
42 
43  /*
44  * Write a configuration snapshot.
45  */
46  void LammpsDumpWriter::writeFrame(std::ofstream& file, long iStep)
47  {
48 
49  // Compute total number of atoms
50  nAtom_ = atoms().size();
51 
52  file << "ITEM: TIMESTEP" << "\n";
53  file << iStep << "\n";
54 
55  file << "ITEM: NUMBER OF ATOMS" << "\n";
56  file << nAtom_ << "\n";
57 
58  file << "ITEM: BOX BOUNDS pp pp pp" << "\n";
59  Vector lengths = boundary().lengths();
60  file << Dbl(0.0) << Dbl(lengths[0]) << "\n";
61  file << Dbl(0.0) << Dbl(lengths[1]) << "\n";
62  file << Dbl(0.0) << Dbl(lengths[2]) << "\n";
63 
64  Vector r;
65  int id;
66  int typeId;
67  int shift = 0;
68  int molId = 1;
69 
70  file << "ITEM: ATOMS id type mol x y z" << "\n";
72  atoms().begin(iter);
73  for ( ; iter.notEnd(); ++iter) {
74  id = iter->id;
75  typeId = iter->typeId;
76  file << id + 1<< " ";
77  file << typeId + 1 << " ";
78  file << molId << " ";
79  for (int i=0; i < Util::Dimension; ++i) {
80  file << Dbl(iter->position[i], 13) << " ";
81  }
82  for (int i=0; i < Util::Dimension; ++i) {
83  file << shift << " ";
84  }
85  file << "\n";
86  }
87 
88  }
89 
90 }
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
A Vector is a Cartesian vector.
Definition: Vector.h:75
LammpsDumpWriter(Processor &processor)
Constructor.
A post-processor for analyzing outputs of MD simulations.
Definition: Processor.h:30
bool notEnd() const
Is the current pointer not at the end of the array?
Definition: ArrayIterator.h:83
const Vector & lengths() const
Get Vector of unit cell lengths by const reference.
int size() const
Get number of atoms.
Wrapper for a double precision number, for formatted ostream output.
Definition: Dbl.h:39
An instantaneous molecular dynamics configuration.
Definition: Configuration.h:40
Boundary & boundary()
Get Boundary by reference.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Configuration & configuration()
Get the parent Configuration by reference.
Forward iterator for an Array or a C array.
Definition: ArrayIterator.h:39
Single-processor classes for pre- and post-processing MD trajectories.
void begin(Iterator &iter)
Initialize an iterator for atoms.
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:142
Based class for classes that write trajectories to a single file.
AtomStorage & atoms()
Get AtomStorage by reference.
FileMaster & fileMaster()
Get an associated FileMaster by reference.
void writeFrame(std::ofstream &file, long int iStep)
Read a single frame.