8 #include "HoomdConfigReader.h" 10 #include <tools/chemistry/Atom.h> 11 #include <tools/chemistry/Group.h> 12 #include <tools/chemistry/Species.h> 14 #include <tools/storage/Configuration.h> 16 #include <util/space/Vector.h> 17 #include <util/xmltag/XmlXmlTag.h> 18 #include <util/xmltag/XmlStartTag.h> 19 #include <util/xmltag/XmlAttribute.h> 20 #include <util/xmltag/XmlEndTag.h> 21 #include <util/misc/ioUtil.h> 42 std::stringstream line;
48 atomTypeMap_.
read(file);
55 bondTypeMap_.
read(file);
62 angleTypeMap_.
read(file);
74 if (!file.is_open()) {
78 UTIL_THROW(
"Error: A type map file must be read before config");
88 if (!xmlTag.
match(line, 0)) {
99 if (attribute.
label() ==
"version") {
100 attribute.
value() >> version;
103 UTIL_THROW(
"Unknown attribute of hoomd_xml tag");
115 if (attribute.
label() ==
"time_step") {
116 attribute.
value() >> timestep;
118 if (attribute.
label() ==
"dimensions") {
119 attribute.
value() >> dimensions;
120 if (dimensions != 3) {
121 UTIL_THROW(
"hoomd_xml dimensions attribute not equal to 3");
124 if (attribute.
label() ==
"natoms") {
125 attribute.
value() >> natoms;
127 if (attribute.
label() ==
"vizsigma") {
128 attribute.
value() >> vizsigma;
131 UTIL_THROW(
"Unknown attribute of hoomd_xml tag");
145 if (end.
match(line, 0)) {
147 if (end.
label() !=
"configuration") {
149 UTIL_THROW(
"Incorrect configuration end tag label");
156 name = start.
label();
162 readBox(start, file);
164 if (name ==
"position") {
165 readPosition(start, file);
167 if (name ==
"velocity") {
168 readVelocity(start, file);
170 if (name ==
"type") {
171 readType(start, file);
173 if (name ==
"mass") {
174 readAtomIgnore(start, file);
176 if (name ==
"charge") {
177 readAtomIgnore(start, file);
179 if (name ==
"diameter") {
180 readAtomIgnore(start, file);
182 if (name ==
"body") {
183 readAtomIgnore(start, file);
185 if (name ==
"bond") {
190 else if (name ==
"angle") {
196 else if (name ==
"dihedral") {
199 }
else if (name ==
"improper") {
211 UTIL_THROW(
"Expected data node start tag or configuration end tag");
219 end.
match(
"hoomd_xml", line, 0);
246 if (attribute.
label() ==
"lx") {
247 attribute.
value() >> lengths[0];
249 if (attribute.
label() ==
"ly") {
250 attribute.
value() >> lengths[1];
252 if (attribute.
label() ==
"lz") {
253 attribute.
value() >> lengths[2];
255 if (attribute.
label() ==
"xy") {
256 attribute.
value() >> xy;
258 if (attribute.
label() ==
"xz") {
259 attribute.
value() >> xz;
261 if (attribute.
label() ==
"yz") {
262 attribute.
value() >> yz;
281 if (attribute.
label() ==
"num") {
283 attribute.
value() >> num;
284 if (nAtom > 0 && num != nAtom) {
302 void HoomdConfigReader::endTag(std::istream& file,
const std::string& name)
307 end.
match(name, line, 0);
318 int nAtom = storage.
size();
319 int n = readNumberAttribute(start, nAtom);
323 for (
int i = 0; i < n; ++i) {
324 atomPtr = storage.
ptr(i);
332 for (
int i = 0; i < n; ++i) {
333 atomPtr = storage.
newPtr();
340 endTag(file,
"position");
350 int nAtom = storage.
size();
351 int n = readNumberAttribute(start, nAtom);
355 for (
int i = 0; i < n; ++i) {
356 atomPtr = storage.
ptr(i);
363 for (
int i = 0; i < n; ++i) {
364 atomPtr = storage.
newPtr();
370 endTag(file,
"velocity");
380 int nAtom = storage.
size();
381 int n = readNumberAttribute(start, nAtom);
383 std::string typeName;
387 for (
int i = 0; i < n; ++i) {
388 atomPtr = storage.
ptr(i);
393 typeId = atomTypeMap_.
id(typeName);
397 for (
int i = 0; i < n; ++i) {
398 atomPtr = storage.
newPtr();
401 typeId = atomTypeMap_.
id(typeName);
406 endTag(file,
"type");
416 int nAtom = storage.
size();
417 int n = readNumberAttribute(start, nAtom);
420 for (
int i = 0; i < n; ++i) {
424 endTag(file, start.
label());
429 if (!end.match(line, 0)) {
442 int nGroup = storage.
size();
446 int n = readNumberAttribute(start, nGroup);
448 std::string typeName;
452 for (i = 0; i < n; ++i) {
453 groupPtr = storage.
newPtr();
456 typeId = bondTypeMap_.
id(typeName);
457 groupPtr->
typeId = typeId;
458 for (j = 0; j < 2; ++j) {
462 endTag(file, start.
label());
474 int nGroup = storage.
size();
478 int n = readNumberAttribute(start, nGroup);
480 std::string typeName;
485 for (i = 0; i < n; ++i) {
486 groupPtr = storage.
newPtr();
489 typeId = map.
id(typeName);
490 groupPtr->
typeId = typeId;
491 for (j = 0; j < 2; ++j) {
496 endTag(file, start.
label());
bool matchLabel(const std::string &string, int begin)
Match opening bracket and any label.
int size() const
Return logical size of this array (i.e., number of elements).
bool matchAttribute(XmlAttribute &attribute)
Attempt to match an attribute.
Parser for an XML start tag.
A Vector is a Cartesian vector.
std::stringstream & value()
Return value string, without quotes.
void setOrthorhombic(const Vector &lengths)
Set unit cell dimensions for orthorhombic boundary.
An orthorhombic periodic unit cell.
Parser for an XML attribute.
Parser for an XML file declaration tag (first line in file).
const std::string & label()
Return label string.
bool getNextLine(std::istream &in, std::string &line)
Read the next non-empty line into a string, strip trailing whitespace.
const std::string label()
Label string.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
bool match(const std::string &string, int begin)
Attempt to match entire xml tag.
Parser for an XML end tag.
Utility classes for scientific computation.
void shift(Vector &r) const
Shift Cartesian Vector r to its primary image.
void checkString(std::istream &in, const std::string &expected)
Extract string from stream, and compare to expected value.
const std::string label()
Label string.
static std::ostream & file()
Get log ostream by reference.
void setClassName(const char *className)
Set class name string.
void finish()
Check if end bracket was found.
bool match(const std::string &string, int begin)
Attempt to match any end tag.