Simpatico  v1.10
ddMd/analyzers/trajectory/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 <ddMd/simulation/Simulation.h>
10 #include <ddMd/communicate/AtomCollector.h>
11 #include <ddMd/chemistry/Atom.h>
12 #include <util/archives/BinaryFileOArchive.h>
13 #include <util/format/Dbl.h>
14 #include <util/space/Vector.h>
15 
16 namespace DdMd
17 {
18 
19  using namespace Util;
20 
21  /*
22  * Constructor.
23  */
25  : TrajectoryWriter(simulation)
26  { setClassName("LammpsDumpWriter"); }
27 
28  /*
29  * Destructor.
30  */
32  {}
33 
34  /*
35  * Write a configuration snapshot.
36  */
37  void LammpsDumpWriter::writeFrame(std::ofstream &file, long iStep)
38  {
39 
40  // Compute total number of atoms
41  atomStorage().computeNAtomTotal(domain().communicator());
42  if (domain().isMaster()) {
43  nAtom_ = atomStorage().nAtomTotal();
44  }
45 
46  if (domain().isMaster()) {
47  file << "ITEM: TIMESTEP" << "\n";
48  file << iStep << "\n";
49 
50  file << "ITEM: NUMBER OF ATOMS" << "\n";
51  file << nAtom_ << "\n";
52 
53  file << "ITEM: BOX BOUNDS pp pp pp" << "\n";
54  Vector lengths = boundary().lengths();
55  file << Dbl(0.0) << Dbl(lengths[0]) << "\n";
56  file << Dbl(0.0) << Dbl(lengths[1]) << "\n";
57  file << Dbl(0.0) << Dbl(lengths[2]) << "\n";
58 
59  Vector r;
60  int id;
61  int typeId;
62  int shift = 0;
63  int molId = 1;
64  bool isCartesian = atomStorage().isCartesian();
65 
66  file << "ITEM: ATOMS id type mol x y z" << "\n";
67  atomCollector().setup();
68  Atom* atomPtr = atomCollector().nextPtr();
69  while (atomPtr) {
70  id = atomPtr->id();
71  typeId = atomPtr->typeId();
72  if (isCartesian) {
73  r = atomPtr->position();
74  } else {
75  boundary().transformGenToCart(atomPtr->position(), r);
76  }
77  file << id + 1<< " ";
78  file << typeId + 1 << " ";
79  file << molId << " ";
80  for (int i=0; i < Util::Dimension; ++i) {
81  file << Dbl(atomPtr->position()[i], 13) << " ";
82  }
83  for (int i=0; i < Util::Dimension; ++i) {
84  file << shift << " ";
85  }
86  file << "\n";
87  atomPtr = atomCollector().nextPtr();
88  }
89 
90  } else {
91  atomCollector().send();
92  }
93 
94  }
95 
96 }
Base class to write a trajectory to a single file.
int typeId() const
Get atom type index.
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
Domain & domain()
Get the Domain by reference.
A Vector is a Cartesian vector.
Definition: Vector.h:75
int nAtomTotal() const
Get total number of atoms on all processors.
const Vector & lengths() const
Get Vector of unit cell lengths by const reference.
Vector & position()
Get position Vector by reference.
void send()
Send all atoms to the master.
LammpsDumpWriter(Simulation &simulation)
Constructor.
Wrapper for a double precision number, for formatted ostream output.
Definition: Dbl.h:39
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
int id() const
Get unique global index for this atom.
void writeFrame(std::ofstream &file, long iStep)
Read a single frame.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Atom * nextPtr()
Return a pointer to the next available atom, or null.
void transformGenToCart(const Vector &Rg, Vector &Rc) const
Transform Vector of generalized coordinates to Cartesian Vector.
void computeNAtomTotal(MPI::Intracomm &communicator)
Compute the total number of local atoms on all processors.
AtomCollector & atomCollector()
Get the AtomCollector by reference.
bool isCartesian() const
Are atom coordinates Cartesian (true) or generalized (false)?
void setClassName(const char *className)
Set class name string.
void setup()
Setup master processor for receiving.
Boundary & boundary()
Get Boundary by reference.
AtomStorage & atomStorage()
Get AtomStorage by reference.