23#include <boost/algorithm/string.hpp>
24#include <boost/lexical_cast.hpp>
44 throw std::ios_base::failure(
"Error on open topology file: " + file);
58 throw std::ios_base::failure(
"Error on open trajectory file: " + file);
75 boost::algorithm::trim(line);
77 if (line.substr(0, 5) !=
"ITEM:") {
78 throw std::ios_base::failure(
"unexpected line in lammps file:\n" + line);
80 if (line.substr(6, 8) ==
"TIMESTEP") {
82 }
else if (line.substr(6, 15) ==
"NUMBER OF ATOMS") {
84 }
else if (line.substr(6, 10) ==
"BOX BOUNDS") {
86 }
else if (line.substr(6, 5) ==
"ATOMS") {
92 throw std::ios_base::failure(
"unknown item lammps file : " +
96 boost::algorithm::trim(line);
99 cout <<
"WARNING: topology created from .dump file, masses, charges, "
100 "types, residue names are wrong!\n";
109 boost::algorithm::trim(s);
110 top.
setStep(boost::lexical_cast<Index>(s));
111 cout <<
"Reading frame, timestep " << top.
getStep() << endl;
117 Eigen::Matrix3d m = Eigen::Matrix3d::Zero();
119 for (
Index i = 0; i < 3; ++i) {
121 boost::algorithm::trim(s);
124 throw std::ios_base::failure(
"invalid box format");
126 m(i, i) = v[1] - v[0];
134 boost::algorithm::trim(s);
135 natoms_ = boost::lexical_cast<Index>(s);
137 std::runtime_error(
"number of beads in topology and trajectory differ");
157 vector<string> fields;
164 if (*i ==
"x" || *i ==
"y" || *i ==
"z") {
166 }
else if (*i ==
"xu" || *i ==
"yu" || *i ==
"zu") {
168 }
else if (*i ==
"xs" || *i ==
"ys" || *i ==
"zs") {
170 }
else if (*i ==
"vx" || *i ==
"vy" || *i ==
"vz") {
172 }
else if (*i ==
"fx" || *i ==
"fy" || *i ==
"fz") {
174 }
else if (*i ==
"id") {
180 throw std::runtime_error(
181 "error, id not found in any column of the atoms section");
187 boost::algorithm::trim(s);
189 throw std::runtime_error(
"Error: unexpected end of lammps file '" +
191 boost::lexical_cast<string>(i) +
" atoms of " +
192 boost::lexical_cast<string>(
natoms_) +
" read.");
197 vector<string> fields2 = tok.
ToVector();
199 Index atom_id = boost::lexical_cast<Index>(fields2[
id]);
201 throw std::runtime_error(
202 "Error: found atom with id " + boost::lexical_cast<string>(atom_id) +
203 " but only " + boost::lexical_cast<string>(
natoms_) +
204 " atoms defined in header of file '" +
fname_ +
"'");
210 Eigen::Matrix3d m = top.
getBox();
212 for (
size_t j = 0; itok != tok.
end(); ++itok, ++j) {
213 if (j == fields.size()) {
214 throw std::runtime_error(
215 "error, wrong number of columns in atoms section");
216 }
else if (fields[j] ==
"x") {
218 }
else if (fields[j] ==
"y") {
220 }
else if (fields[j] ==
"z") {
222 }
else if (fields[j] ==
"xu") {
224 }
else if (fields[j] ==
"yu") {
226 }
else if (fields[j] ==
"zu") {
228 }
else if (fields[j] ==
"xs") {
229 b->
Pos().x() = stod(*itok) * m(0, 0);
230 }
else if (fields[j] ==
"ys") {
231 b->
Pos().y() = stod(*itok) * m(1, 1);
232 }
else if (fields[j] ==
"zs") {
233 b->
Pos().z() = stod(*itok) * m(2, 2);
234 }
else if (fields[j] ==
"vx") {
236 }
else if (fields[j] ==
"vy") {
238 }
else if (fields[j] ==
"vz") {
240 }
else if (fields[j] ==
"fx") {
242 }
else if (fields[j] ==
"fy") {
244 }
else if (fields[j] ==
"fz") {
246 }
else if ((fields[j] ==
"type") &&
topology_) {
virtual Eigen::Vector3d & Pos()
virtual void setType(const std::string &type) noexcept
bool HasPos() const noexcept
bool HasF() const noexcept
bool HasVel() const noexcept
void ReadAtoms(Topology &top, std::string itemline)
void ReadNumAtoms(Topology &top)
void ReadBox(Topology &top)
bool ReadTopology(std::string file, Topology &top) override
open a topology file
bool NextFrame(Topology &top) override
read in the next frame
void ReadTimestep(Topology &top)
bool Open(const std::string &file) override
open a trejectory file
bool FirstFrame(Topology &top) override
read in the first frame
topology of the whole system
Residue & CreateResidue(std::string name)
Create a new resiude.
void setBox(const Eigen::Matrix3d &box, BoundaryCondition::eBoxtype boxtype=BoundaryCondition::typeAuto)
void Cleanup()
Cleans up all the stored data.
bool BeadTypeExist(std::string type) const
Determine if a bead type exists.
const Eigen::Matrix3d & getBox() const
Bead * CreateBead(Bead::Symmetry symmetry, std::string name, std::string type, Index resnr, double m, double q)
Creates a new Bead.
void RegisterBeadType(std::string type)
Register the bead type with the topology object.
Bead * getBead(const Index i)
Returns a pointer to the bead with index i.
base class for all analysis tools