-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtomTypeMap.cpp
More file actions
128 lines (98 loc) · 2.73 KB
/
Copy pathAtomTypeMap.cpp
File metadata and controls
128 lines (98 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "AtomTypeMap.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
AtomTypeMap::AtomTypeMap()
{
}
void
AtomTypeMap::read(std::string filename)
{
std::fstream file {filename};
if (not file)
{
std::stringstream msg;
msg << "Opening atom type file fails: " << filename;
THROW_EXCEPT(msg.str());
}
int numTypes = 0;
file >> numTypes;
if (not file)
THROW_EXCEPT("No number of types in atom type file");
mCharges.resize(numTypes);
for (int i = 0; i < numTypes; ++i)
{
int index {};
std::string name {};
GReal charge {};
file >> index >> name >> charge;
if (not file)
THROW_EXCEPT("Invalid format in atom type file");
if (index < 0)
THROW_EXCEPT("Negative index in atom type");
if (mNameToIndexMap.count(name) != 0)
{
std::stringstream msg;
msg << "Multiple definition of atom name exists!: " << name;
THROW_EXCEPT(msg.str());
}
mNameToIndexMap[name] = index;
if (mIndexToNameMap.count(index) != 0)
{
std::stringstream msg;
msg << "Multiple definition of atom index exists!: " << index;
THROW_EXCEPT(msg.str());
}
mIndexToNameMap[index] = name;
if (index >= numTypes)
THROW_EXCEPT("Out of range in atom index");
mCharges[index] = charge;
}
}
void
AtomTypeMap::print()
{
using namespace std;
int size = mCharges.size();
auto& nameMap = mIndexToNameMap;
cout << setw(80) << setfill('=') << "" << setfill(' ') << endl;
cout << setw(10) << "Index" <<
setw(10) << "Name" <<
setw(10) << "Charge" << endl;
cout << setw(80) << setfill('=') << "" << setfill(' ') << endl;
for (int i = 0; i < size; ++i)
{
std::cout << std::setw(10) << i <<
std::setw(10) << nameMap[i] <<
std::setw(10) << mCharges[i] <<
std::endl;
}
}
int
AtomTypeMap::getIndex(std::string atomName)
{
if (mNameToIndexMap.count(atomName) == 0)
{
std::stringstream msg;
msg << "Invalid atom name: " << atomName;
THROW_EXCEPT(msg.str());
}
return mNameToIndexMap[atomName];
}
std::string
AtomTypeMap::getName(int index)
{
if (mIndexToNameMap.count(index) == 0)
{
std::stringstream msg;
msg << "Invalid atom index: " << index;
THROW_EXCEPT(msg.str());
}
return mIndexToNameMap[index];
}
int
AtomTypeMap::getNumTypes()
{
return mNameToIndexMap.size();
}