-
Notifications
You must be signed in to change notification settings - Fork 0
/
molecule.h
129 lines (105 loc) · 3.71 KB
/
molecule.h
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
//
// Created by lurker on 2/10/17.
//
#ifndef MOLECULE_H
#define MOLECULE_H
#include "ls_point.h"
class Molecule {
public:
vector<ls_point> centers;
vector<scalar_t > radii;
vector<scalar_t > charges;
vector<vector<index_t >> adjacent;
ls_point center;
scalar_t radius;
index_t N;
void load(std::string fileName) {
std::ifstream pdbFile;
std::string line;
pdbFile.open(fileName);
if (pdbFile.is_open()) {
// read each line
while (getline(pdbFile, line)) {
if (line.find("ATOM") == 0) {
std::stringstream ss(line);
std::string buf;
vector<std::string> tokens;
while (ss >> buf) {
tokens.push_back(buf);
}
centers.push_back(ls_point(
std::stod(tokens[5]),
std::stod(tokens[6]),
std::stod(tokens[7])
));
radii.push_back(std::stod(tokens[9]));
charges.push_back(std::stod(tokens[8]));
}
}
pdbFile.close();
N = (index_t) centers.size();
getCenter();
}
}
void getAdjacent(scalar_t probe) {
adjacent.resize(N);
for (int i = 0; i < N; ++i) {
scalar_t ri = radii[i] + probe;
for (int j = 0; j < i; ++j) {
// check if intersected.
scalar_t d = norm(centers[i] - centers[j]);
scalar_t rj = radii[j] + probe;
if (d < ri + rj) {
adjacent[i].push_back(j);
adjacent[j].push_back(i);
}
}
}
}
void getCenter() {
assert(N > 0);
ls_point minP = {
centers[0].data[0] - radii[0],
centers[0].data[1] - radii[0],
centers[0].data[2] - radii[0]};
ls_point maxP = {
centers[0].data[0] + radii[0],
centers[0].data[1] + radii[0],
centers[0].data[2] + radii[0]};
for (int i = 1; i < N; ++i) {
ls_point current_max_P = {
centers[i].data[0] + radii[i],
centers[i].data[1] + radii[i],
centers[i].data[2] + radii[i]
};
ls_point current_min_P = {
centers[i].data[0] - radii[i],
centers[i].data[1] - radii[i],
centers[i].data[2] - radii[i]
};
for (int j = 0; j < 3; ++j) {
if (maxP.data[j] <= current_max_P.data[j]) {maxP.data[j] = current_max_P.data[j];}
if (minP.data[j] >= current_min_P.data[j]) {minP.data[j] = current_min_P.data[j];}
}
}
this->center = (minP + maxP) * 0.5;
this->radius = std::max(
0.5 * (maxP.data[0] - minP.data[0]),
std::max(
0.5 * (maxP.data[1] - minP.data[1]),
0.5 * (maxP.data[2] - minP.data[2]))
);
}
scalar_t centralize(float range) {
scalar_t s = range / radius;
for (index_t i = 0; i < (index_t)centers.size(); ++i) {
centers[i].data[0] = s * (centers[i].data[0] - center.data[0]);
centers[i].data[1] = s * (centers[i].data[1] - center.data[1]);
centers[i].data[2] = s * (centers[i].data[2] - center.data[2]);
radii[i] = s * radii[i];
}
std::cout << std::setw(15)<< "ATOMS" << " " << std::setw(8) << N <<std::endl;
return s;
}
};
#endif //MOLECULE_H