Simpatico  v1.10
tools/trajectory/DdMdTrajectoryReader.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 "DdMdTrajectoryReader.h"
9 #include <tools/storage/Configuration.h>
10 #include <simp/boundary/Boundary.h>
11 #include <util/archives/BinaryFileIArchive.h>
12 #include <util/space/Vector.h>
13 #include <util/misc/ioUtil.h>
14 
15 #include <climits>
16 
17 namespace Tools
18 {
19 
20  using namespace Util;
21  using namespace Simp;
22 
23  /*
24  * Constructor.
25  */
27  : TrajectoryReader(configuration, true)
28  { setClassName("DdMdTrajectoryReader"); }
29 
30  /*
31  * Destructor.
32  */
34  {}
35 
36  void DdMdTrajectoryReader::readHeader(std::ifstream &file)
37  {
38  BinaryFileIArchive ar(file);
39  ar >> nAtom_;
40  //std::cout << nAtom_ << std::endl;
41  }
42 
43  /*
44  * Read a frame.
45  */
46  bool DdMdTrajectoryReader::readFrame(std::ifstream& file)
47  {
48  BinaryFileIArchive ar(file);
49 
50  // Attempt to read iStep
51  long iStep = -1;
52  ar >> iStep;
53 
54  // Return false if read failed, indicating end of file.
55  if (file.eof()) {
56  return false;
57  }
58 
59  // Read boundary dimensions
60  Boundary& boundary = configuration().boundary();
61  ar >> boundary;
62 
63  // Loop over atoms, read atomic positions
64  AtomStorage* storagePtr = &configuration().atoms();
65  Atom* atomPtr;
66  Vector r;
67  double h = 1.0/(double(UINT_MAX) + 1.0);
68  int id, i, j;
69  unsigned int ir;
70  for (i = 0; i < nAtom_; ++i) {
71  ar >> id;
72  atomPtr = storagePtr->ptr(id);
73  if (atomPtr == 0) {
74  UTIL_THROW("Unknown atom");
75  }
76  for (j = 0; j < Dimension; ++j) {
77  ar >> ir;
78  r[j] = ir*h;
79  }
80  boundary.transformGenToCart(r, atomPtr->position);
81  }
82 
83  return true;
84  }
85 
86 }
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
A Vector is a Cartesian vector.
Definition: Vector.h:75
Container for a set of atoms.
An orthorhombic periodic unit cell.
Abstract trajectory file reader.
Atom * ptr(int id)
Get a pointer to an atom by global id.
virtual void readHeader(std::ifstream &file)
Read the header.
Classes used by all simpatico molecular simulations.
AtomStorage & atoms()
Get the AtomStorage.
An instantaneous molecular dynamics configuration.
Definition: Configuration.h:40
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
virtual bool readFrame(std::ifstream &file)
Read a frame.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Single-processor classes for pre- and post-processing MD trajectories.
A point particle in an MD simulation.
Saving archive for binary istream.
DdMdTrajectoryReader(Configuration &configuration)
Constructor.
Boundary & boundary()
Get the Boundary by non-const reference.
void setClassName(const char *className)
Set class name string.
Vector position
Atom position.
Configuration & configuration()
Return parent Configuraiton by reference.