votca 2024.2-dev
Loading...
Searching...
No Matches
lammpsdatareader.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18// Standard includes
19#include <cstddef>
20#include <iterator>
21#include <set>
22#include <stdexcept>
23#include <string>
24#include <utility>
25#include <vector>
26
27// VOTCA includes
30#include <votca/tools/getline.h>
31
32// Third party includes
33#include <boost/algorithm/string.hpp>
34
35// Local VOTCA includes
36#include "votca/csg/molecule.h"
37#include "votca/csg/topology.h"
38
39// Local private VOTCA includes
40#include "lammpsdatareader.h"
41
42namespace votca {
43namespace csg {
44using namespace std;
45
46/*****************************************************************************
47 * Internal Helper Functions *
48 *****************************************************************************/
49std::vector<std::string> TrimCommentsFrom_(std::vector<std::string> fields) {
50 std::vector<std::string> tempFields;
51 for (const auto &field : fields) {
52 if (field.at(0) == '#') {
53 break;
54 }
55 tempFields.push_back(field);
56 }
57 return tempFields;
58}
59
60/*****************************************************************************
61 * Public Facing Methods *
62 *****************************************************************************/
63
64// Data file should follow this format:
65// https://lammps.sandia.gov/doc/2001/data_format.html
67
68 cout << endl;
69 cout << "WARNING: The votca lammps data reader is only able to read ";
70 cout << "lammps files formatted in the following styles:" << endl;
71 cout << "angle" << endl;
72 cout << "atom" << endl;
73 cout << "bond" << endl;
74 cout << "full" << endl;
75 cout << "molecule" << endl;
76 cout << endl;
77 cout << "These styles use the following formats in the atom block:" << endl;
78 cout << "atom-ID molecule-ID atom-type charge x y z" << endl;
79 cout << "atom-ID molecule-ID atom-type charge x y z nx ny nz" << endl;
80 cout << "atom-ID molecule-ID atom-type x y z" << endl;
81 cout << "atom-ID molecule-ID atom-type x y z nx ny nz" << endl;
82 cout << "atom-ID atom-type x y z" << endl;
83 cout << "atom-ID atom-type x y z nx ny nz" << endl;
84 cout << endl;
85
86 topology_ = true;
87 top.Cleanup();
88 fl_.open(file);
89 if (!fl_.is_open()) {
90 throw std::ios_base::failure("Error on open topology file: " + file);
91 }
92
93 fname_ = file;
94
95 NextFrame(top);
96
97 fl_.close();
98
100
101 return true;
102}
103
104bool LAMMPSDataReader::Open(const string &file) {
105 fl_.open(file);
106 if (!fl_.is_open()) {
107 throw std::ios_base::failure("Error on open trajectory file: " + file);
108 }
109 fname_ = file;
110 return true;
111}
112
113void LAMMPSDataReader::Close() { fl_.close(); }
114
116 topology_ = false;
117 NextFrame(top);
118 return true;
119}
120
122
123 string header;
124 tools::getline(fl_, header);
125 string line;
126 tools::getline(fl_, line);
127 while (!fl_.eof()) {
128
129 std::vector<std::string> fields =
130 TrimCommentsFrom_(tools::Tokenizer(line, " ").ToVector());
131 // If not check the size of the vector and parse according
132 // to the number of fields
133 if (fields.size() == 1) {
134 MatchOneFieldLabel_(fields, top);
135 } else if (fields.size() == 2) {
136 MatchTwoFieldLabels_(fields, top);
137 } else if (fields.size() == 3) {
139 } else if (fields.size() == 4) {
140 MatchFourFieldLabels_(fields, top);
141 } else if (fields.size() != 0) {
142 string err = "Unrecognized line in lammps .data file:\n" + line;
143 throw std::runtime_error(err);
144 }
145 tools::getline(fl_, line);
146 }
147 return !fl_.eof();
148}
149
150/*****************************************************************************
151 * Private Facing Methods *
152 *****************************************************************************/
153
154std::pair<std::string, std::string> getNames(const Molecule &mol) {
155
156 std::string longname = "";
157 std::map<std::string, Index> molname_map;
158 for (const Bead *atom : mol.Beads()) {
159 std::string atomname = atom->getName();
160 std::string element = atomname.substr(0, 1);
161 if (std::islower(atomname[1])) {
162 element += atomname[1];
163 }
164 longname += element;
165 molname_map[element]++;
166 }
167
168 // We compress the molecule into its chemical composition + an index
169 std::string shortname = "";
170 for (auto const &pair : molname_map) {
171 shortname += pair.first + std::to_string(pair.second);
172 }
173 return std::make_pair(shortname, longname);
174}
175
177
178 std::map<std::string, std::set<std::string>> shortname_longnames;
179 // create compressed and long names for each molecule
180 for (const auto &mol : molecules) {
181 if (mol.getName() == "UNKNOWN") {
182 auto names = getNames(mol);
183 shortname_longnames[names.first].insert(names.second);
184 }
185 }
186
187 for (auto &mol : molecules) {
188 if (mol.getName() == "UNKNOWN") {
189 auto names = getNames(mol);
190 // if only one longname exists for a shortname, just use the shortname
191 if (shortname_longnames[names.first].size() == 1) {
192 mol.setName(names.first);
193 } else {
194 // if more than one longname exists for a shortname, sort the longnames
195 // alphabetically and just append the index to the short name
196 // e.g. if you have CCCH and CHCC they will compress to C3H-0 and C3H-1
197 // respectively
198 ptrdiff_t i =
199 std::distance(shortname_longnames[names.first].begin(),
200 shortname_longnames[names.first].find(names.second));
201 mol.setName(names.first + "-" + std::to_string(i));
202 }
203 }
204 }
205}
206
207bool LAMMPSDataReader::MatchOneFieldLabel_(std::vector<std::string> fields,
208 Topology &top) {
209
210 if (fields.at(0) == "Masses") {
211 SortIntoDataGroup_("Masses");
213 } else if (fields.at(0) == "Atoms") {
214 ReadAtoms_(top);
215 } else if (fields.at(0) == "Bonds") {
216 ReadBonds_(top);
217 } else if (fields.at(0) == "Angles") {
218 ReadAngles_(top);
219 } else if (fields.at(0) == "Dihedrals") {
220 ReadDihedrals_(top);
221 } else if (fields.at(0) == "Impropers") {
222 cout << endl;
223 cout << "WARNING Impropers are not currently supported, skipping." << endl;
224 cout << endl;
225 // Impropers are not yet supported
227 } else {
228 return false;
229 }
230 return true;
231}
232
233bool LAMMPSDataReader::MatchTwoFieldLabels_(std::vector<std::string> fields,
234 Topology &top) {
235
236 string label = fields.at(0) + " " + fields.at(1);
237
238 if (fields.at(1) == "atoms") {
239 ReadNumOfAtoms_(fields, top);
240 } else if (fields.at(1) == "bonds") {
241 ReadNumOfBonds_(fields);
242 } else if (fields.at(1) == "angles") {
243 ReadNumOfAngles_(fields);
244 } else if (fields.at(1) == "dihedrals") {
245 ReadNumOfDihedrals_(fields);
246 } else if (fields.at(1) == "impropers") {
247 ReadNumOfImpropers_(fields);
248 } else if (label == "Pair Coeffs") {
249 SortIntoDataGroup_("Pair Coeffs");
250 } else if (label == "Bond Coeffs") {
251 SortIntoDataGroup_("Bond Coeffs");
252 } else if (label == "Angle Coeffs") {
253 SortIntoDataGroup_("Angle Coeffs");
254 } else if (label == "Improper Coeffs") {
255 SortIntoDataGroup_("Improper Coeffs");
256 } else {
257 return false;
258 }
259 return true;
260}
261
262bool LAMMPSDataReader::MatchThreeFieldLabels_(std::vector<std::string> fields) {
263 string label = fields.at(1) + " " + fields.at(2);
264 if (label == "atom types") {
265 ReadNumTypes_(fields, "atom");
266 } else if (label == "bond types") {
267 ReadNumTypes_(fields, "bond");
268 } else if (label == "angle types") {
269 ReadNumTypes_(fields, "angle");
270 } else if (label == "dihedral types") {
271 ReadNumTypes_(fields, "Dihedral");
272 } else if (label == "improper types") {
273 ReadNumTypes_(fields, "Improper");
274 } else {
275 return false;
276 }
277 return true;
278}
279
280bool LAMMPSDataReader::MatchFourFieldLabels_(std::vector<std::string> fields,
281 Topology &top) {
282 string label = fields.at(2) + " " + fields.at(3);
283 if (label == "xlo xhi") {
284 ReadBox_(fields, top);
285 } else {
286 return false;
287 }
288 return true;
289}
290
292 if (!data_.count("Masses")) {
293 throw runtime_error(
294 "Masses must first be parsed before the atoms can be read.");
295 }
296
297 Index index = 0;
298 tools::Elements elements;
299 for (const auto &mass : data_["Masses"]) {
300 // Determine the mass associated with the atom
301 double mass_atom_bead = std::stod(mass.at(1));
302 string baseName;
303 if (elements.isMassAssociatedWithElement(mass_atom_bead, 0.01)) {
304 baseName = elements.getEleShortClosestInMass(mass_atom_bead, 0.01);
305 } else {
306 baseName = "Bead";
307 cout << "Unable to associate mass " << mass.at(1)
308 << " with element assuming pseudo atom, assigning name "
309 << "Bead" << mass.at(0) << " ." << endl;
310 }
311 atomtypes_[index] = baseName + mass.at(0);
312 ++index;
313 }
314}
315
316void LAMMPSDataReader::ReadBox_(std::vector<std::string> fields,
317 Topology &top) {
318 Eigen::Matrix3d m = Eigen::Matrix3d::Zero();
319 m(0, 0) = std::stod(fields.at(1)) - std::stod(fields.at(0));
320
321 for (Index i = 1; i < 3; ++i) {
322 string line;
323 tools::getline(fl_, line);
324 fields = tools::Tokenizer(line, " ").ToVector();
325 if (fields.size() != 4) {
326 throw runtime_error("invalid box format in the lammps data file");
327 }
328
329 m(i, i) = std::stod(fields.at(1)) - std::stod(fields.at(0));
330 }
332}
333
335 std::string line;
336 tools::getline(fl_, line);
337 tools::getline(fl_, line);
338
339 std::vector<std::vector<std::string>> group;
340 while (!line.empty()) {
341 group.push_back(tools::Tokenizer(line, " ").ToVector());
342 tools::getline(fl_, line);
343 }
344
345 data_[tag] = group;
346}
347
348void LAMMPSDataReader::ReadNumTypes_(std::vector<std::string> fields,
349 string type) {
350 numberOfDifferentTypes_[type] = std::stoi(fields.at(0));
351}
352
353void LAMMPSDataReader::ReadNumOfAtoms_(std::vector<std::string> fields,
354 Topology &top) {
355 numberOf_["atoms"] = stoi(fields.at(0));
356 if (!topology_ && numberOf_["atoms"] != top.BeadCount()) {
357 std::runtime_error("Number of beads in topology and trajectory differ");
358 }
359}
360
361void LAMMPSDataReader::ReadNumOfBonds_(std::vector<std::string> fields) {
362 numberOf_["bonds"] = stoi(fields.at(0));
363}
364
365void LAMMPSDataReader::ReadNumOfAngles_(std::vector<std::string> fields) {
366 numberOf_["angles"] = stoi(fields.at(0));
367}
368
369void LAMMPSDataReader::ReadNumOfDihedrals_(std::vector<std::string> fields) {
370 numberOf_["dihedrals"] = stoi(fields.at(0));
371}
372
373void LAMMPSDataReader::ReadNumOfImpropers_(std::vector<std::string> fields) {
374 numberOf_["impropers"] = stoi(fields.at(0));
375}
376
378 string line) {
379
380 std::vector<std::string> fields = tools::Tokenizer(line, " ").ToVector();
381 lammps_format format;
382 if (fields.size() == 5 || fields.size() == 8) {
383 format = style_atomic;
384 } else if (fields.size() == 6 || fields.size() == 9) {
386 } else if (fields.size() == 7 || fields.size() == 10) {
387 format = style_full;
388 } else {
389 throw runtime_error(
390 "You have submitted a lammps data file with an "
391 "unsupported format.");
392 }
393 return format;
394}
395
397
398 if (data_.count("Masses") == 0) {
399 throw runtime_error(
400 "You are attempting to read in the atom block before the masses, or "
401 "you have failed to include the masses in the data file.");
402 }
403
404 string line;
405 tools::getline(fl_, line);
406 tools::getline(fl_, line);
407
409 bool chargeRead = false;
410 bool moleculeRead = false;
411 if (format == style_angle_bond_molecule) {
412 moleculeRead = true;
413 }
414 if (format == style_full) {
415 moleculeRead = true;
416 chargeRead = true;
417 }
418
419 std::map<Index, string> sorted_file;
420 Index startingIndex;
421 Index startingIndexMolecule = 0;
422 std::istringstream issfirst(line);
423 issfirst >> startingIndex;
424 if (moleculeRead) {
425 issfirst >> startingIndexMolecule;
426 }
427 sorted_file[startingIndex] = line;
428 tools::getline(fl_, line);
429 boost::trim(line);
430
431 Index atomId = 0;
432 Index moleculeId = 0;
433 while (!line.empty()) {
434 std::istringstream iss(line);
435 iss >> atomId;
436 if (moleculeRead) {
437 iss >> moleculeId;
438 }
439 sorted_file[atomId] = line;
440 tools::getline(fl_, line);
441 boost::trim(line);
442 if (atomId < startingIndex) {
443 startingIndex = atomId;
444 }
445 if (moleculeId < startingIndexMolecule) {
446 startingIndexMolecule = moleculeId;
447 }
448 }
449
450 for (Index atomIndex = startingIndex;
451 static_cast<size_t>(atomIndex - startingIndex) < sorted_file.size();
452 ++atomIndex) {
453
454 Index atomTypeId;
455 double charge = 0;
456 double x, y, z;
457
458 istringstream iss(sorted_file[atomIndex]);
459 iss >> atomId;
460 if (moleculeRead) {
461 iss >> moleculeId;
462 } else {
463 moleculeId = atomId;
464 }
465 iss >> atomTypeId;
466 if (chargeRead) {
467 iss >> charge;
468 }
469 iss >> x;
470 iss >> y;
471 iss >> z;
472
473 // Exclusion list assumes beads start with ids of 0
474 --atomId;
475 --atomTypeId;
476 moleculeId -= startingIndexMolecule;
477
478 // We want to start with an index of 0 not 1
479 // atomId;
480 Bead *b;
481 if (topology_) {
482
483 atomIdToIndex_[atomId] = atomIndex - startingIndex;
484 atomIdToMoleculeId_[atomId] = moleculeId;
485 Molecule *mol;
486 if (!molecules_.count(moleculeId)) {
487 mol = top.CreateMolecule("UNKNOWN");
488 molecules_[moleculeId] = mol;
489 } else {
490 mol = molecules_[moleculeId];
491 }
492
493 double mass = std::stod(data_["Masses"].at(atomTypeId).at(1));
494
495 if (Index(data_.at("Masses").size()) <= atomTypeId) {
496 std::string err =
497 "The atom block contains an atom of type " +
498 std::to_string(atomTypeId) +
499 " however, the masses are only specified for atoms up to type " +
500 std::to_string(data_.at("Masses").size() - 1);
501 throw runtime_error(err);
502 }
503
504 Index residue_index = moleculeId;
505 if (residue_index >= top.ResidueCount()) {
506 while ((residue_index - 1) >= top.ResidueCount()) {
507 top.CreateResidue("DUM");
508 }
509 top.CreateResidue("DUM");
510 }
511
512 if (atomtypes_.count(atomTypeId) == 0) {
513 throw runtime_error(
514 "Unrecognized atomTypeId, the atomtypes map "
515 "may be uninitialized");
516 }
517
518 string bead_type_name = atomtypes_[atomTypeId];
519 if (!top.BeadTypeExist(bead_type_name)) {
520 top.RegisterBeadType(bead_type_name);
521 }
522
523 b = top.CreateBead(Bead::spherical, bead_type_name, bead_type_name,
524 residue_index, mass, charge);
525
526 mol->AddBead(b, bead_type_name);
527 b->setMoleculeId(mol->getId());
528
529 } else {
530 b = top.getBead(atomIndex - startingIndex);
531 }
532
533 Eigen::Vector3d xyz_pos(x, y, z);
534 b->setPos(xyz_pos * tools::conv::ang2nm);
535 }
536
537 if (top.BeadCount() != numberOf_["atoms"]) {
538 string err =
539 "The number of atoms read in is not equivalent to the "
540 "number of atoms indicated to exist in the lammps data file. \n"
541 "Number of atoms that should exist " +
542 to_string(numberOf_["atoms"]) + "\nNumber of atoms that were read in " +
543 to_string(top.BeadCount()) + "\n";
544 throw runtime_error(err);
545 }
546}
547
549 string line;
550 tools::getline(fl_, line);
551 tools::getline(fl_, line);
552 boost::trim(line);
553
554 Index bondId;
555 Index bondTypeId;
556 Index atom1Id, atom2Id;
557
558 Index bond_count = 0;
559 while (!line.empty()) {
560
561 if (topology_) {
562 istringstream iss(line);
563 iss >> bondId;
564 iss >> bondTypeId;
565 iss >> atom1Id;
566 iss >> atom2Id;
567
568 --atom1Id;
569 --atom2Id;
570 --bondTypeId;
571 --bondId;
572
573 Index atom1Index = atomIdToIndex_[atom1Id];
574 Index atom2Index = atomIdToIndex_[atom2Id];
575 if (atomIdToMoleculeId_[atom1Index] != atomIdToMoleculeId_[atom2Index]) {
576 std::cout << "WARNING: Lammps Atoms " + std::to_string(atom1Id + 1) +
577 " and " + std::to_string(atom2Id + 1) +
578 " belong to different molecules (" +
579 std::to_string(atomIdToMoleculeId_[atom1Index] + 1) +
580 ":" +
581 std::to_string(atomIdToMoleculeId_[atom2Index] + 1) +
582 ")"
583 << std::endl;
584 }
585
586 Interaction *ic = new IBond(atom1Index, atom2Index);
587 ic->setGroup("BONDS");
588 ic->setIndex(bondId);
589 auto b = top.getBead(atom1Index);
590 auto mi = top.getMolecule(b->getMoleculeId());
591 ic->setMolecule(atomIdToMoleculeId_[atom1Index]);
592 top.AddBondedInteraction(ic);
593 mi->AddInteraction(ic);
594 }
595
596 ++bond_count;
597 tools::getline(fl_, line);
598 boost::trim(line);
599 }
600
601 if (bond_count != numberOf_["bonds"]) {
602 std::string err =
603 "The number of bonds read in is not equivalent to the "
604 "number of bonds indicated to exist in the lammps data file. \n"
605 "Number of bonds that should exist " +
606 std::to_string(numberOf_["bonds"]) +
607 "\nNumber of bonds that were read in " + std::to_string(bond_count) +
608 "\n";
609 throw runtime_error(err);
610 }
611}
612
614 std::string line;
615 tools::getline(fl_, line);
616 tools::getline(fl_, line);
617 boost::trim(line);
618
619 Index angleId;
620 Index angleTypeId;
621 Index atom1Id, atom2Id, atom3Id;
622
623 Index angle_count = 0;
624
625 while (!line.empty()) {
626
627 if (topology_) {
628 std::istringstream iss(line);
629 iss >> angleId;
630 iss >> angleTypeId;
631 iss >> atom1Id;
632 iss >> atom2Id;
633 iss >> atom3Id;
634
635 --angleId;
636 --atom1Id;
637 --atom2Id;
638 --atom3Id;
639 --angleTypeId;
640
641 Index atom1Index = atomIdToIndex_[atom1Id];
642 Index atom2Index = atomIdToIndex_[atom2Id];
643 Index atom3Index = atomIdToIndex_[atom3Id];
644
645 Interaction *ic = new IAngle(atom1Index, atom2Index, atom3Index);
646 ic->setGroup("ANGLES");
647 ic->setIndex(angleId);
648 auto b = top.getBead(atom1Index);
649 auto mi = top.getMolecule(b->getMoleculeId());
650 ic->setMolecule(atomIdToMoleculeId_[atom1Index]);
651 top.AddBondedInteraction(ic);
652 mi->AddInteraction(ic);
653 }
654
655 ++angle_count;
656
657 tools::getline(fl_, line);
658 boost::trim(line);
659 }
660
661 if (angle_count != numberOf_["angles"]) {
662 string err =
663 "The number of angles read in is not equivalent to the "
664 "number of angles indicated to exist in the lammps data file. \n"
665 "Number of angles that should exist " +
666 to_string(numberOf_["angles"]) +
667 "\nNumber of angles that were read in " + to_string(angle_count) + "\n";
668 throw runtime_error(err);
669 }
670}
671
673 string line;
674 tools::getline(fl_, line);
675 tools::getline(fl_, line);
676 while (!line.empty()) {
677 tools::getline(fl_, line);
678 }
679}
680
682 string line;
683 tools::getline(fl_, line);
684 tools::getline(fl_, line);
685 boost::trim(line);
686
687 Index dihedralId;
688 Index dihedralTypeId;
689 Index atom1Id, atom2Id, atom3Id, atom4Id;
690
691 Index dihedral_count = 0;
692 while (!line.empty()) {
693
694 if (topology_) {
695 istringstream iss(line);
696 iss >> dihedralId;
697 iss >> dihedralTypeId;
698 iss >> atom1Id;
699 iss >> atom2Id;
700 iss >> atom3Id;
701 iss >> atom4Id;
702
703 --dihedralId;
704 --atom1Id;
705 --atom2Id;
706 --atom3Id;
707 --atom4Id;
708 --dihedralTypeId;
709
710 Index atom1Index = atomIdToIndex_[atom1Id];
711 Index atom2Index = atomIdToIndex_[atom2Id];
712 Index atom3Index = atomIdToIndex_[atom3Id];
713 Index atom4Index = atomIdToIndex_[atom4Id];
714
715 Interaction *ic =
716 new IDihedral(atom1Index, atom2Index, atom3Index, atom4Index);
717 ic->setGroup("DIHEDRALS");
718 ic->setIndex(dihedralId);
719 auto b = top.getBead(atom1Index);
720 auto mi = top.getMolecule(b->getMoleculeId());
721 ic->setMolecule(atomIdToMoleculeId_[atom1Index]);
722 top.AddBondedInteraction(ic);
723 mi->AddInteraction(ic);
724 }
725 ++dihedral_count;
726 tools::getline(fl_, line);
727 boost::trim(line);
728 }
729
730 if (dihedral_count != numberOf_["dihedrals"]) {
731 string err =
732 "The number of dihedrals read in is not equivalent to the "
733 "number of dihedrals indicated to exist in the lammps data file. \n"
734 "Number of dihedrals that should exist " +
735 to_string(numberOf_["dihedrals"]) +
736 "\nNumber of dihedrals that were read in " + to_string(dihedral_count) +
737 "\n";
738 throw runtime_error(err);
739 }
740}
741} // namespace csg
742} // namespace votca
virtual void setPos(const Eigen::Vector3d &bead_position)
Definition basebead.h:161
void setMoleculeId(const Index &molecule_id) noexcept
assign the bead to a molecule with the provided id
Definition basebead.h:68
information about a bead
Definition bead.h:50
angle interaction
bond interaction
dihedral interaction
base class for all interactions
Definition interaction.h:40
void setGroup(const std::string &group)
Definition interaction.h:49
void setIndex(const Index &index)
Definition interaction.h:67
void setMolecule(const Index &mol)
Definition interaction.h:76
void ReadNumOfAtoms_(std::vector< std::string > fields, Topology &top)
lammps_format determineDataFileFormat_(std::string line)
void ReadNumOfDihedrals_(std::vector< std::string > fields)
void InitializeAtomAndBeadTypes_()
Determines atom and bead types based on masses in lammps files.
void ReadNumOfAngles_(std::vector< std::string > fields)
bool MatchFourFieldLabels_(std::vector< std::string > fields, Topology &top)
void RenameMolecules(MoleculeContainer &molecules) const
std::map< std::string, Index > numberOfDifferentTypes_
bool ReadTopology(std::string file, Topology &top) override
open, read and close topology file
void Close() override
close the topology file
void ReadBox_(std::vector< std::string > fields, Topology &top)
void ReadNumOfImpropers_(std::vector< std::string > fields)
void SortIntoDataGroup_(std::string tag)
void ReadDihedrals_(Topology &top)
bool FirstFrame(Topology &top) override
read in the first frame of trajectory file
std::map< std::string, std::vector< std::vector< std::string > > > data_
std::map< std::string, Index > numberOf_
bool NextFrame(Topology &top) override
read in the next frame of trajectory file
std::map< Index, Index > atomIdToIndex_
void ReadNumTypes_(std::vector< std::string > fields, std::string type)
bool MatchOneFieldLabel_(std::vector< std::string > fields, Topology &top)
std::map< Index, Molecule * > molecules_
std::map< Index, std::string > atomtypes_
void ReadNumOfBonds_(std::vector< std::string > fields)
bool MatchThreeFieldLabels_(std::vector< std::string > fields)
std::map< Index, Index > atomIdToMoleculeId_
bool Open(const std::string &file) override
open a trajectory file
bool MatchTwoFieldLabels_(std::vector< std::string > fields, Topology &top)
information about molecules
Definition molecule.h:45
void AddBead(Bead *bead, const std::string &name)
Add a bead to the molecule.
Definition molecule.cc:29
Index getId() const
get the molecule ID
Definition molecule.h:48
const std::vector< Bead * > & Beads() const
Definition molecule.h:67
topology of the whole system
Definition topology.h:81
Residue & CreateResidue(std::string name)
Create a new resiude.
Definition topology.h:462
void setBox(const Eigen::Matrix3d &box, BoundaryCondition::eBoxtype boxtype=BoundaryCondition::typeAuto)
Definition topology.h:272
void Cleanup()
Cleans up all the stored data.
Definition topology.cc:49
Index ResidueCount() const
Definition topology.h:156
bool BeadTypeExist(std::string type) const
Determine if a bead type exists.
Definition topology.cc:210
Bead * CreateBead(Bead::Symmetry symmetry, std::string name, std::string type, Index resnr, double m, double q)
Creates a new Bead.
Definition topology.h:441
void AddBondedInteraction(Interaction *ic)
Definition topology.cc:188
Index BeadCount() const
Definition topology.h:150
Molecule * getMolecule(const Index i)
Definition topology.h:231
void RegisterBeadType(std::string type)
Register the bead type with the topology object.
Definition topology.cc:214
Molecule * CreateMolecule(std::string name)
Creates a new molecule.
Definition topology.h:449
Bead * getBead(const Index i)
Returns a pointer to the bead with index i.
Definition topology.h:227
MoleculeContainer & Molecules()
Definition topology.h:182
information about an element
Definition elements.h:42
bool isMassAssociatedWithElement(double mass, double tolerance)
Definition elements.cc:170
std::string getEleShortClosestInMass(double mass, double tolerance)
Definition elements.cc:178
break string into words
Definition tokenizer.h:72
std::vector< T > ToVector()
store all words in a vector of type T, does type conversion.
Definition tokenizer.h:109
STL namespace.
std::vector< std::string > TrimCommentsFrom_(std::vector< std::string > fields)
reduced_edge_to_edges_map::value_type element
boost::container::deque< Molecule, void, block_molecule_4x_t > MoleculeContainer
Definition topology.h:67
std::pair< std::string, std::string > getNames(const Molecule &mol)
const double ang2nm
Definition constants.h:51
std::istream & getline(std::istream &is, std::string &str)
Wrapper for a getline function.
Definition getline.h:35
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26