1 | //
|
---|
2 | // extent.cc
|
---|
3 | //
|
---|
4 |
|
---|
5 | #ifdef __GNUC__
|
---|
6 | #pragma implementation
|
---|
7 | #endif
|
---|
8 |
|
---|
9 | #include <util/misc/formio.h>
|
---|
10 | #include <chemistry/qc/basis/extent.h>
|
---|
11 |
|
---|
12 | using namespace std;
|
---|
13 | using namespace sc;
|
---|
14 |
|
---|
15 | ShellExtent::ShellExtent()
|
---|
16 | {
|
---|
17 | contributing_shells_ = 0;
|
---|
18 | n_[0] = n_[1] = n_[2] = 0;
|
---|
19 | }
|
---|
20 |
|
---|
21 | ShellExtent::~ShellExtent()
|
---|
22 | {
|
---|
23 | delete[] contributing_shells_;
|
---|
24 | }
|
---|
25 |
|
---|
26 | std::vector<ExtentData> &
|
---|
27 | ShellExtent::data(int x, int y, int z)
|
---|
28 | {
|
---|
29 | if (x>=n_[0] || y>=n_[1] || z>= n_[2] || x<0 || y<0 || z<0) {
|
---|
30 | ExEnv::outn() << "ShellExtent::data: out of bounds" << endl;
|
---|
31 | abort();
|
---|
32 | }
|
---|
33 | return contributing_shells_[z + n_[2]*(y + n_[1]*x)];
|
---|
34 | }
|
---|
35 |
|
---|
36 | std::vector<ExtentData> &
|
---|
37 | ShellExtent::data(int *b)
|
---|
38 | {
|
---|
39 | return data(b[0],b[1],b[2]);
|
---|
40 | }
|
---|
41 |
|
---|
42 | double
|
---|
43 | ShellExtent::distance(double loc, int axis, int origin, int point)
|
---|
44 | {
|
---|
45 | if (point < origin)
|
---|
46 | return loc - (lower_[axis]+resolution_*(point+1));
|
---|
47 | else if (point == origin)
|
---|
48 | return 0.0;
|
---|
49 | else
|
---|
50 | return loc - (lower_[axis]+resolution_*point);
|
---|
51 | }
|
---|
52 |
|
---|
53 | void
|
---|
54 | ShellExtent::init(const Ref<GaussianBasisSet>&gbs,
|
---|
55 | double resolution, double tolerance)
|
---|
56 | {
|
---|
57 | int i,j,k,l,m,n;
|
---|
58 |
|
---|
59 | Ref<Molecule> mol = gbs->molecule();
|
---|
60 | resolution_ = resolution;
|
---|
61 |
|
---|
62 | delete[] contributing_shells_;
|
---|
63 | n_[0] = n_[1] = n_[2] = 0;
|
---|
64 | for (i=0; i<3; i++) lower_[i] = 0.0;
|
---|
65 | contributing_shells_ = 0;
|
---|
66 | if (mol->natom() == 0) return;
|
---|
67 |
|
---|
68 | double upper[3];
|
---|
69 |
|
---|
70 | for (i=0; i<3; i++) upper[i] = lower_[i] = mol->r(0,i);
|
---|
71 |
|
---|
72 | for (i=0; i<mol->natom(); i++) {
|
---|
73 | for (j=0; j<gbs->nshell_on_center(i); j++) {
|
---|
74 | double r = gbs->shell(gbs->shell_on_center(i, j)).extent(tolerance);
|
---|
75 | for (k=0; k<3; k++) {
|
---|
76 | if (lower_[k]>mol->r(i,k)-r) lower_[k] = mol->r(i,k)-r;
|
---|
77 | if (upper [k]<mol->r(i,k)+r) upper [k] = mol->r(i,k)+r;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | for (i=0; i<3; i++) {
|
---|
83 | double l;
|
---|
84 | l = upper[i]-lower_[i];
|
---|
85 | n_[i] = int(l/resolution_);
|
---|
86 | if (n_[i]*resolution_ + lower_[i] < upper[i]) n_[i]++;
|
---|
87 | }
|
---|
88 |
|
---|
89 | contributing_shells_ = new std::vector<ExtentData>[n_[0]*n_[1]*n_[2]];
|
---|
90 |
|
---|
91 | for (i=0; i<mol->natom(); i++) {
|
---|
92 | //ExEnv::outn() << indent << "working on atom " << i << endl;
|
---|
93 | //ExEnv::outn() << incindent;
|
---|
94 | for (j=0; j<gbs->nshell_on_center(i); j++) {
|
---|
95 | int ishell = gbs->shell_on_center(i,j);
|
---|
96 | const GaussianShell &shell = gbs->shell(ishell);
|
---|
97 | double r = shell.extent(tolerance);
|
---|
98 | int ir = int(r/resolution_);
|
---|
99 | if (ir*resolution_ < r) ir++;
|
---|
100 | int atom_block[3];
|
---|
101 | for (l=0; l<3; l++) {
|
---|
102 | atom_block[l] = int((mol->r(i,l)-lower_[l])/resolution_);
|
---|
103 | }
|
---|
104 | int block[3];
|
---|
105 | //ExEnv::outn() << indent << "working on shell " << ishell << endl;
|
---|
106 | //ExEnv::outn() << incindent;
|
---|
107 | for (k=atom_block[0]-ir; k<=atom_block[0]+ir; k++) {
|
---|
108 | block[0] = k;
|
---|
109 | for (l=atom_block[1]-ir; l<=atom_block[1]+ir; l++) {
|
---|
110 | block[1] = l;
|
---|
111 | for (m=atom_block[2]-ir; m<=atom_block[2]+ir; m++) {
|
---|
112 | block[2] = m;
|
---|
113 | //ExEnv::outn() << indent
|
---|
114 | // << "working on block " << block[0]
|
---|
115 | // << " " << block[1]
|
---|
116 | // << " " << block[2] << endl;
|
---|
117 | // find the distance to the atom from this block
|
---|
118 | double dist = 0.0;
|
---|
119 | for (n=0; n<3; n++) {
|
---|
120 | double r
|
---|
121 | = distance(mol->r(i,n),n,atom_block[n],block[n]);
|
---|
122 | dist += r*r;
|
---|
123 | }
|
---|
124 | dist = sqrt(dist);
|
---|
125 | double bound = shell.monobound(dist);
|
---|
126 | //ExEnv::outn() << indent
|
---|
127 | // << "dist = " << dist
|
---|
128 | // << " bound = " << bound << endl;
|
---|
129 | if (bound < tolerance) continue;
|
---|
130 | data(block).push_back(ExtentData(ishell, bound));
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 | //ExEnv::outn() << decindent;
|
---|
135 | }
|
---|
136 | //ExEnv::outn() << decindent;
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | const std::vector<ExtentData> &
|
---|
141 | ShellExtent::contributing_shells(double x, double y, double z)
|
---|
142 | {
|
---|
143 | int i, block[3];
|
---|
144 | block[0] = int((x-lower_[0])/resolution_);
|
---|
145 | block[1] = int((y-lower_[1])/resolution_);
|
---|
146 | block[2] = int((z-lower_[2])/resolution_);
|
---|
147 | for (i=0; i<3; i++) {
|
---|
148 | if (block[i] < 0 || block[i] >= n_[i]) return null_;
|
---|
149 | }
|
---|
150 | return data(block);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void
|
---|
154 | ShellExtent::print(ostream &o)
|
---|
155 | {
|
---|
156 | int i,j,k,l;
|
---|
157 |
|
---|
158 | o
|
---|
159 | << indent << "ShellExent:" << endl;
|
---|
160 |
|
---|
161 | o << incindent;
|
---|
162 |
|
---|
163 | o
|
---|
164 | << indent << "n = " << n_[0] << " " << n_[1] << " " << n_[2] << endl;;
|
---|
165 |
|
---|
166 | o << indent << "resolution = " << resolution_ << endl;
|
---|
167 |
|
---|
168 | o << indent
|
---|
169 | << "lower = " << lower_[0]
|
---|
170 | << " " << lower_[1]
|
---|
171 | << " " << lower_[2] << endl;;
|
---|
172 |
|
---|
173 | o << indent
|
---|
174 | << "upper = " << lower_[0] + n_[0] * resolution_
|
---|
175 | << " " << lower_[1] + n_[1] * resolution_
|
---|
176 | << " " << lower_[2] + n_[2] * resolution_ << endl;;
|
---|
177 |
|
---|
178 | for (i=0; i<n_[0]; i++) {
|
---|
179 | for (j=0; j<n_[1]; j++) {
|
---|
180 | for (k=0; k<n_[2]; k++) {
|
---|
181 | const std::vector<ExtentData> &d = data(i,j,k);
|
---|
182 | if (d.size()) {
|
---|
183 | o << indent
|
---|
184 | << i << " " << j << " " << k << ":" << endl;
|
---|
185 | for (l=0; l<d.size(); l++) {
|
---|
186 | o << indent
|
---|
187 | << " " << d[l].shell << " " << d[l].bound << endl;
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | o << decindent;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /////////////////////////////////////////////////////////////////////////////
|
---|
198 |
|
---|
199 | // Local Variables:
|
---|
200 | // mode: c++
|
---|
201 | // c-file-style: "CLJ"
|
---|
202 | // End:
|
---|