Readers.h

Readers for parsing LAMMPS dumpfiles and datafiles.

struct InputStream
#include <Readers.h>

Convenience wrapper around ifstream.

Public Functions

InputStream()
InputStream(string _filename)

Open the stream upon instantiation.

~InputStream()

Close the stream.

void open(string _filename)

Open the stream and call verifyStream.

void verifyStream()

Check whether stream is good().

void skipLines(int numLines)

Skip numLines lines forward in the file.

void skipWhitespace()

Consume consecutive whitespace following the cursor.

bool search(string term)

Search for line containing term.

Move the ifstream cursor to the beginning of the first line containing term. (the matching line will not be consumed) Returns whether the line was found

string search(vector<string> terms)

Search for line containing an element of terms.

Move the ifstream cursor one line past the first line containing one of the strings in terms. (the matching line will be consumed) Returns the line found

bool searchLine(string term)

Skip past line containing term.

Move the ifstream cursor one line past the first line exactly equal to term. (the matching line will be consumed) Returns whether the line was found.

string searchLine(vector<string> terms)

Skip past line containing an element of terms.

bool nextLineBlank()

Whether the next line is blank.

string peekLine()

Read the next line and return the cursor to its previous position.

Public Members

unsigned long int lineNum

Line number (starting from 1).

unsigned long int pos

Byte offset in file.

string filename

Path to file.

ifstream stream

Actual ifstream object.

class HeaderReader
#include <Readers.h>

Reads the header from a LAMMPS dumpfile.

Read the timestep and box bounds.

Note
Could also (but currently does not) read the number of atoms.
See
TimestepReader.

Public Functions

void setContext(Options options, InputStream *_inputStreamPtr, SimData *_simDataPtr, Timestep *_timestepPtr, int *_lineNumPtr, BoxBounds *_boundsPtr)

Copy options and save pointers to relevant quantities.

Called by TimestepReader::setContext.

void readHeader()

Public Members

int *lineNumPtr

Private Members

Options options
InputStream *inputStreamPtr
Timestep *timestepPtr
BoxBounds *boundsPtr
SimData *simDataPtr
class LineReader
#include <Readers.h>

Reads one line at a time of atom positions from LAMMPS dumpfile.

Reads scaled positions and calculates unitful positions.

See
TimestepReader.

Public Functions

void setContext(Options options, InputStream *_inputStreamPtr, int *_atomNumPtr, int *_lineNumPtr, BoxBounds *_boundsPtr)

Copy options and save pointers to relevant quantities.

Called by TimestepReader::setContext.

void readLine()

Read the line and store data in atom.

Public Members

Atom atom

Private Members

Options options
string line
string input
int *atomNumPtr
int *lineNumPtr
InputStream *inputStreamPtr
BoxBounds *boundsPtr
class TimestepReader
#include <Readers.h>

Read one timestep at a time from a LAMMP dumpfile.

Reads both the header and position lines.

See
FrameReader.

Public Functions

TimestepReader()
void setContext(Options _options, InputStream *_inputStreamPtr, AtomArray *_atomArrayPtr, Timestep *_timestepPtr, SimData *_simDataPtr)

Copy options and save pointers to relevant quantities.

Called by FrameReader::setContext.

void resetAtomCounter()

Set atomNum = 0.

void readTimestep(int stepInFrame)

Read one timestep.

stepInFrame is necessary to determine the index to store atom position in atomArrayPtr.

Public Members

int atomNum
int lineNum

Private Members

Options options
LineReader lineReader
HeaderReader headerReader
Timestep *timestepPtr
AtomArray *atomArrayPtr
InputStream *inputStreamPtr
SimData *simDataPtr
BoxBounds timestepBounds
double xlo
double xhi
double ylo
double yhi
double zlo
double zhi
class FrameReader
#include <Readers.h>

Read one frame, containing multiple timesteps from a LAMMP dumpfile.

The size of a frame is determined by Options::stepsPerFrame (although the last frame may be a different size).

See
Frame::stepsThisFrame.
See
LastFrame::numSteps.
See
DumpfileReader.

Public Functions

FrameReader()
FrameReader(Options options, AtomArray *_atomArrayPtr, SimData *_simDataPtr)
void setContext(Options options, AtomArray *_atomArrayPtr, SimData *_simDataPtr)

Copy options and save pointers to relevant quantities.

Called by DumpfileReader::DumpfileReader.

void openStream()

Open inputStream with Options::dumpfile.

void updateFrame()

Set frame variables from first timestep in frame.

Timestep::stepNum -> Frame::frameStep Timestep::time -> Frame::time

void readFrame()

Read one frame.

Read first timestep separately to set frame variables to those of the first timestep in the frame.

void countAtoms()

Count the number of atoms in the simulation (in one timestep).

void countSteps()

Count the number of timesteps in the dumpfile.

Called by DumpfileReader::DumpfileReader.

Public Members

Options options
TimestepReader timestepReader
AtomArray *atomArrayPtr
Timestep timestep
SimData *simDataPtr
InputStream inputStream
Frame frame
int stepsPerFrame
class DatafileReader
#include <Readers.h>

Read a LAMMPS Datafile.

Reads box dimensions, number of atoms, masses of each type, and water bonds (useful if water molecule orientation is desired).

Note
Water bonds are not currently utilized.

Public Functions

DatafileReader(SimData &simData)
void openStream()

Open Options::datafile for reading.

void read()

Read the whole datafile.

Private Functions

void readNumAtoms()
void readMasses()
void readWaterBonds()

Assume that O atom comes first in bond, then H.

void readBoxBounds()

Private Members

Options options
InputStream inputStream
vector<int> liquidTypes
int HType

Atom type of water hydrogen atoms.

int OType

Atom type of water oxygen atoms.

ifstream *streamPtr
SimData *simDataPtr
int numAtoms
struct DumpfileReader
#include <Readers.h>

Read a LAMMPS Dumpfile one frame at a time.

Public Functions

DumpfileReader(AtomArray &atomArray)
void countAtoms()

Count the number of water atoms in the first timestep.

Note
This method is not currently called anywhere.

void countSteps()
void readFrame()
bool good()

Whether another frame can be read.

Compare frame numbers to see if this is the end.

Public Members

Options options
FrameReader frameReader
SimData *simDataPtr
AtomArray *atomArrayPtr
int frameNum

Index of current frame.

See
Frame::frameNum.