-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsites.cpp
More file actions
174 lines (138 loc) · 5.02 KB
/
sites.cpp
File metadata and controls
174 lines (138 loc) · 5.02 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "pch.h"
#include "IO.h"
#include "sites.h"
site::site(double x, double y, double z, double charge) : pos(x, y, z), charge(charge) {}
double ToBohr(double angs) { return angs * 1.8897259886; }
bool sites_xyz::BuildSiteList(char* xyz_file)
{
list.clear();
// Use contents of .xyz file to populate site vector
// First 3 columns should be formatted as: x (float), y (float), z (float). Other columns are ignored.
std::ifstream in;
in.open(xyz_file);
if (!in)
{
std::cout << "***ERROR***: Couldn't open file '" << xyz_file << "'\n";
return false;
}
std::string line;
int linenum = 0;
while (std::getline(in, line))
{
linenum++;
std::stringstream linestream(line);
double x, y, z;
linestream >> x >> y >> z;
if (linestream.fail())
{
std::cout << "***ERROR***: Unexpected formatting of .xyz file at line " << linenum << ". Expected at least 3 columns with value type float.\n";
in.close();
return false;
}
// .xyz file contains no charge/occupancy data, just defualt to 0.
list.push_back(site(ToBohr(x), ToBohr(y), ToBohr(z), 0.0));
}
in.close();
return true;
}
bool sites_mesout::BuildSiteList(char* mesout_file)
{
list.clear();
std::ifstream in;
in.open(mesout_file);
if (!in)
{
std::cout << "***ERROR***: Couldn't open file '" << mesout_file << "'\n";
return false;
}
std::string line;
int linenum = 0;
while (std::getline(in, line))
{
linenum++;
std::stringstream linestream(line);
// Look for the start of the occupation densities data block
if (line.find("Occupation densities") != std::string::npos)
{
double x, y, z, o;
// Now start reading in site data until we reach a blank line, indicating we have reached the end of the block.
std::getline(in, line);
while (!line.empty())
{
linestream >> x >> y >> z >> o;
if (linestream.fail())
{
std::cout << "***ERROR***: Unexpected formatting of occupation densities block file at line " << linenum << ". Expected at least 4 columns with value type float.\n";
in.close();
return false;
}
// multiply occupation probability by -1.0 to get charge.
list.push_back(site(ToBohr(x), ToBohr(y), ToBohr(z), o * -1.0));
std::getline(in, line);
}
in.close();
return true;
}
}
// If we reached this point, then the occupation densities data block was never found
std::cout << "***ERROR***: Reached EOF without finding 'Occupation densities' header. Perhaps this file contained no solutions?\n";
in.close();
return false;
}
bool sites_tofetout::BuildSiteList(char* tofetout_file)
{
list.clear();
std::ifstream in;
in.open(tofetout_file);
if (!in)
{
std::cout << "***ERROR***: Couldn't open file '" << tofetout_file << "'\n";
return false;
}
std::string line;
int linenum = 0;
while (std::getline(in, line))
{
linenum++;
std::stringstream linestream(line);
// Look for the start of the occupation densities data block
if (line.find("TOTAL OCCUPATION TIMES AND TIMES VISITED") != std::string::npos)
{
// Skip the next line, which contains column headers
std::getline(in, line);
double x, y, z, o;
// Now start reading in site data until we reach EOF or a blank line, indicating we have reached the end of the block.
std::getline(in, line);
while (!linestream.eof() && !line.empty())
{
linestream >> x >> y >> z >> o;
if (linestream.fail())
{
std::cout << "***ERROR***: Unexpected formatting of occupation densities block file at line " << linenum << ". Expected at least 4 columns with value type float.\n";
in.close();
return false;
}
// multiply occupation probability by -1.0 to get charge.
list.push_back(site(ToBohr(x), ToBohr(y), ToBohr(z), o * -1.0));
std::getline(in, line);
}
in.close();
return true;
}
}
// If we reached this point, then the occupation densities data block was never found
std::cout << "***ERROR***: Reached EOF without finding occupation densities header.\n";
in.close();
return false;
}
std::ostream& operator<<(std::ostream& os, const site& st)
{
os << fss::Int(1) << fss::Dec(st.charge) << fss::Dec(st.pos.X) << fss::Dec(st.pos.Y) << fss::Dec(st.pos.Z);
return os;
}
std::ostream& operator<<(std::ostream& os, const sites& sts)
{
for (int i = 0; i < sts.list.size(); i++)
os << sts.list[i] << "\n";
return os;
}