1 /*
2
3 Copyright (C) 2007 Lucas K. Wagner
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 */
20
21 #include "Center_set.h"
22 #include "qmc_io.h"
23 #include "Basis_function.h"
24 #include "CBasis_function.h"
25 #include "Sample_point.h"
26
27 //----------------------------------------------------------------------
28
writeinput(string & indent,ostream & os)29 void Center_set::writeinput(string & indent, ostream & os)
30 {
31 if(usingatoms)
32 {
33 os << indent << "USEATOMS\n";
34 }
35 else if(usingsampcenters)
36 {
37 os << indent << "USEGLOBAL\n";
38 }
39 else
40 {
41 os << indent << "READ " << centerfile << endl;
42 }
43 }
44
45 /*!
46 \todo
47 Allow center specification inline in the input file, rather than
48 having to read an external file.
49 */
read(vector<string> & words,unsigned int pos,System * sys)50 void Center_set::read(vector <string> & words, unsigned int pos,
51 System * sys)
52 {
53
54 usingsampcenters=usingatoms=0;
55 int nelectrons=sys->nelectrons(0)+sys->nelectrons(1);
56 unsigned int startpos=pos;
57
58 if(readvalue(words,pos, centerfile, "READ"))
59 {
60
61 readcenterfile(centerfile);
62 }
63 else
64 {
65
66 pos=startpos;
67 if(haskeyword(words, pos,"USEATOMS"))
68 {
69 //cout << "using atoms " << endl;
70 usingatoms=1;
71 sys->getAtomicLabels(labels);
72 ncenters=labels.size();
73 //cout << "ncenters " << ncenters << endl;
74 }
75 else if(haskeyword(words, pos=0, "USEGLOBAL"))
76 {
77 usingsampcenters=1;
78 sys->getCenterLabels(labels);
79 ncenters=labels.size();
80
81 //cout << ncenters << " centers from system " << endl;
82 }
83 else
84 {
85 error("Couldn't find anything in center section");
86 }
87
88 }
89
90 if(usingsampcenters) {
91 sys->getEquivalentCenters(equiv_centers, ncenters_atom, centers_displacement);
92 }
93 else {
94 equiv_centers.Resize(ncenters,1);
95 ncenters_atom.Resize(ncenters);
96 centers_displacement.Resize(ncenters,3);
97 centers_displacement=0;
98 for(int cen=0; cen< ncenters; cen++) {
99 equiv_centers(cen,0)=cen;
100 ncenters_atom(cen)=1;
101 }
102 }
103
104
105 edist.Resize(nelectrons,ncenters, 5);
106 nbasis.Resize(ncenters);
107 nbasis=0;
108 }
109
110 //------------------------------------------------------------
111
assignBasis(Array1<Basis_function * > basisfunc)112 void Center_set::assignBasis(Array1 <Basis_function *> basisfunc)
113 {
114 int totbasis=basisfunc.GetDim(0);
115 basis.Resize(ncenters, totbasis);
116
117 for(int i=0; i< ncenters; i++)
118 {
119 int found=0;
120 for(int j=0; j < totbasis; j++)
121 {
122 if(basisfunc(j)->label() == labels[i])
123 {
124 appendbasis(j,i);
125 found=1;
126 //break;
127 }
128
129 }
130 if(!found)
131 {
132 cout << "\n****WARNING*****\n"
133 << "Couldn't find basis for atom " << labels[i]
134 << endl;
135 }
136 }
137 }
138
139 //------------------------------------------------------------
140
assignBasis(Array1<CBasis_function * > basisfunc)141 void Center_set::assignBasis(Array1 <CBasis_function *> basisfunc)
142 {
143 int totbasis=basisfunc.GetDim(0);
144 basis.Resize(ncenters, totbasis);
145
146 for(int i=0; i< ncenters; i++)
147 {
148 int found=0;
149 for(int j=0; j < totbasis; j++)
150 {
151 if(basisfunc(j)->label() == labels[i])
152 {
153 appendbasis(j,i);
154 found=1;
155 //break;
156 }
157
158 }
159 if(!found)
160 {
161 cout << "\n****WARNING*****\n"
162 << "Couldn't find basis for atom " << labels[i]
163 << endl;
164 }
165 }
166 }
167
168
169 //------------------------------------------------------------
170
updateDistance(int e,Sample_point * sample)171 void Center_set::updateDistance(int e, Sample_point * sample)
172 {
173 if(usingatoms)
174 {
175 Array1 <doublevar> R(5);
176 sample->updateEIDist();
177 for(int i=0; i< ncenters; i++ )
178 {
179 sample->getEIDist(e, i, R);
180 for(int d=0; d< 5; d++)
181 {
182 edist(e,i,d)=R(d);
183 }
184 }
185 }
186 else if(usingsampcenters) {
187 Array1 <doublevar> R(5);
188 sample->updateECDist();
189 for(int i=0; i< ncenters; i++ )
190 {
191 sample->getECDist(e, i, R);
192 for(int d=0; d< 5; d++)
193 {
194 edist(e,i,d)=R(d);
195 }
196 }
197 }
198 else
199 {
200 Array1 <doublevar> r(3);
201 sample->getElectronPos(e, r);
202 for(int i=0; i< ncenters; i++)
203 {
204 edist(e,i,1)=0;
205 for(int d=0; d< 3; d++)
206 {
207 edist(e,i,d+2)=r(d)-position(i,d);
208 //cout << "positions " << position(i,d) << " dist " << edist(e,i,d+2) << endl;
209 edist(e,i,1)+=edist(e,i,d+2)*edist(e,i,d+2);
210 }
211 }
212 for(int i=0; i< ncenters; i++)
213 {
214 edist(e,i,0)=sqrt(edist(e,i,1));
215 }
216
217 }
218 }
219
220 /*!
221 Uses flat file of form:
222 ncenters
223 Label x y z
224 Label x y z
225 ...
226 */
readcenterfile(string & filename)227 void Center_set::readcenterfile(string & filename)
228 {
229 assert(!usingatoms);
230 ifstream centin(filename.c_str());
231 if(!centin) error("Couldn't open ", filename);
232 centin >> ncenters;
233 position.Resize(ncenters,3);
234 string labeltemp;
235 for(int i=0; i< ncenters; i++)
236 {
237 centin >> labeltemp;
238 labels.push_back(labeltemp);
239 for(int d=0; d< 3; d++)
240 {
241 centin >> position(i,d);
242 }
243 }
244 centin.close();
245 }
246
247
248
249 //--------------------------------------------------------------------------
250