1 |
/* |
2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
* |
4 |
* The University of Notre Dame grants you ("Licensee") a |
5 |
* non-exclusive, royalty free, license to use, modify and |
6 |
* redistribute this software in source and binary code form, provided |
7 |
* that the following conditions are met: |
8 |
* |
9 |
* 1. Redistributions of source code must retain the above copyright |
10 |
* notice, this list of conditions and the following disclaimer. |
11 |
* |
12 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
* notice, this list of conditions and the following disclaimer in the |
14 |
* documentation and/or other materials provided with the |
15 |
* distribution. |
16 |
* |
17 |
* This software is provided "AS IS," without a warranty of any |
18 |
* kind. All express or implied conditions, representations and |
19 |
* warranties, including any implied warranty of merchantability, |
20 |
* fitness for a particular purpose or non-infringement, are hereby |
21 |
* excluded. The University of Notre Dame and its licensors shall not |
22 |
* be liable for any damages suffered by licensee as a result of |
23 |
* using, modifying or distributing the software or its |
24 |
* derivatives. In no event will the University of Notre Dame or its |
25 |
* licensors be liable for any lost revenue, profit or data, or for |
26 |
* direct, indirect, special, consequential, incidental or punitive |
27 |
* damages, however caused and regardless of the theory of liability, |
28 |
* arising out of the use of or inability to use software, even if the |
29 |
* University of Notre Dame has been advised of the possibility of |
30 |
* such damages. |
31 |
* |
32 |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
* research, please cite the appropriate papers when you publish your |
34 |
* work. Good starting points are: |
35 |
* |
36 |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
* [4] , Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). * |
41 |
* Created by J. Daniel Gezelter on 09/26/06. |
42 |
* @author J. Daniel Gezelter |
43 |
* @version $Id$ |
44 |
* |
45 |
*/ |
46 |
|
47 |
#include "applications/staticProps/BOPofR.hpp" |
48 |
#include "utils/simError.h" |
49 |
#include "io/DumpReader.hpp" |
50 |
#include "primitives/Molecule.hpp" |
51 |
#include "utils/NumericConstant.hpp" |
52 |
#include "math/Wigner3jm.hpp" |
53 |
#include "brains/Thermo.hpp" |
54 |
|
55 |
using namespace MATPACK; |
56 |
namespace OpenMD { |
57 |
|
58 |
BOPofR::BOPofR(SimInfo* info, const std::string& filename, |
59 |
const std::string& sele, double rCut, int nbins, |
60 |
RealType len) : StaticAnalyser(info, filename), |
61 |
selectionScript_(sele), |
62 |
evaluator_(info), seleMan_(info) { |
63 |
|
64 |
setOutputName(getPrefix(filename) + ".bo"); |
65 |
|
66 |
evaluator_.loadScriptString(sele); |
67 |
if (!evaluator_.isDynamic()) { |
68 |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
69 |
} |
70 |
|
71 |
// Set up cutoff radius and order of the Legendre Polynomial: |
72 |
|
73 |
rCut_ = rCut; |
74 |
nBins_ = nbins; |
75 |
len_ = len; |
76 |
|
77 |
deltaR_ = len_/nBins_; |
78 |
RCount_.resize(nBins_); |
79 |
WofR_.resize(nBins_); |
80 |
QofR_.resize(nBins_); |
81 |
|
82 |
for (int i = 0; i < nBins_; i++){ |
83 |
RCount_[i] = 0; |
84 |
WofR_[i] = 0; |
85 |
QofR_[i] = 0; |
86 |
} |
87 |
|
88 |
// Make arrays for Wigner3jm |
89 |
RealType* THRCOF = new RealType[2*lMax_+1]; |
90 |
// Variables for Wigner routine |
91 |
RealType lPass, m1Pass, m2m, m2M; |
92 |
int error, mSize; |
93 |
mSize = 2*lMax_+1; |
94 |
|
95 |
for (int l = 0; l <= lMax_; l++) { |
96 |
lPass = (RealType)l; |
97 |
for (int m1 = -l; m1 <= l; m1++) { |
98 |
m1Pass = (RealType)m1; |
99 |
|
100 |
std::pair<int,int> lm = std::make_pair(l, m1); |
101 |
|
102 |
// Zero work array |
103 |
for (int ii = 0; ii < 2*l + 1; ii++){ |
104 |
THRCOF[ii] = 0.0; |
105 |
} |
106 |
|
107 |
// Get Wigner coefficients |
108 |
Wigner3jm(lPass, lPass, lPass, |
109 |
m1Pass, m2m, m2M, |
110 |
THRCOF, mSize, error); |
111 |
|
112 |
m2Min[lm] = (int)floor(m2m); |
113 |
m2Max[lm] = (int)floor(m2M); |
114 |
|
115 |
for (int mmm = 0; mmm <= (int)(m2M - m2m); mmm++) { |
116 |
w3j[lm].push_back(THRCOF[mmm]); |
117 |
} |
118 |
} |
119 |
} |
120 |
|
121 |
delete [] THRCOF; |
122 |
THRCOF = NULL; |
123 |
|
124 |
} |
125 |
|
126 |
BOPofR::~BOPofR() { |
127 |
/* |
128 |
std::cerr << "Freeing stuff" << std::endl; |
129 |
for (int l = 0; l <= lMax_; l++) { |
130 |
for (int m = -l; m <= l; m++) { |
131 |
w3j[std::make_pair(l,m)].clear(); |
132 |
} |
133 |
} |
134 |
std::cerr << "w3j made free...." << std::endl; |
135 |
for (int bin = 0; bin < nBins_; bin++) { |
136 |
QofR_[bin].clear(); |
137 |
WofR_[bin].clear(); |
138 |
RCount_[bin].clear(); |
139 |
} |
140 |
std::cout << "R arrays made free...." << std::endl; |
141 |
w3j.clear(); |
142 |
m2Min.clear(); |
143 |
m2Max.clear(); |
144 |
RCount_.clear(); |
145 |
WofR_.clear(); |
146 |
QofR_.clear(); |
147 |
*/ |
148 |
} |
149 |
|
150 |
|
151 |
void BOPofR::initializeHistogram() { |
152 |
for (int i = 0; i < nBins_; i++){ |
153 |
RCount_[i] = 0; |
154 |
WofR_[i] = 0; |
155 |
QofR_[i] = 0; |
156 |
} |
157 |
} |
158 |
|
159 |
|
160 |
void BOPofR::process() { |
161 |
Molecule* mol; |
162 |
Atom* atom; |
163 |
RigidBody* rb; |
164 |
int myIndex; |
165 |
SimInfo::MoleculeIterator mi; |
166 |
Molecule::RigidBodyIterator rbIter; |
167 |
Molecule::AtomIterator ai; |
168 |
StuntDouble* sd; |
169 |
Vector3d vec; |
170 |
RealType costheta; |
171 |
RealType phi; |
172 |
RealType r; |
173 |
Vector3d rCOM; |
174 |
RealType distCOM; |
175 |
Vector3d pos; |
176 |
Vector3d CenterOfMass; |
177 |
std::map<std::pair<int,int>,ComplexType> q; |
178 |
std::vector<RealType> q_l; |
179 |
std::vector<RealType> q2; |
180 |
std::vector<ComplexType> w; |
181 |
std::vector<ComplexType> w_hat; |
182 |
std::vector<RealType> Q2; |
183 |
std::vector<RealType> Q; |
184 |
std::vector<ComplexType> W; |
185 |
std::vector<ComplexType> W_hat; |
186 |
int nBonds; |
187 |
SphericalHarmonic sphericalHarmonic; |
188 |
int i; |
189 |
|
190 |
DumpReader reader(info_, dumpFilename_); |
191 |
int nFrames = reader.getNFrames(); |
192 |
frameCounter_ = 0; |
193 |
|
194 |
Thermo thermo(info_); |
195 |
|
196 |
q_l.resize(lMax_+1); |
197 |
q2.resize(lMax_+1); |
198 |
w.resize(lMax_+1); |
199 |
w_hat.resize(lMax_+1); |
200 |
|
201 |
Q2.resize(lMax_+1); |
202 |
Q.resize(lMax_+1); |
203 |
W.resize(lMax_+1); |
204 |
W_hat.resize(lMax_+1); |
205 |
|
206 |
for (int istep = 0; istep < nFrames; istep += step_) { |
207 |
reader.readFrame(istep); |
208 |
frameCounter_++; |
209 |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
210 |
CenterOfMass = thermo.getCom(); |
211 |
if (evaluator_.isDynamic()) { |
212 |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
213 |
} |
214 |
|
215 |
// update the positions of atoms which belong to the rigidbodies |
216 |
|
217 |
for (mol = info_->beginMolecule(mi); mol != NULL; |
218 |
mol = info_->nextMolecule(mi)) { |
219 |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
220 |
rb = mol->nextRigidBody(rbIter)) { |
221 |
rb->updateAtoms(); |
222 |
} |
223 |
} |
224 |
|
225 |
// outer loop is over the selected StuntDoubles: |
226 |
|
227 |
for (sd = seleMan_.beginSelected(i); sd != NULL; |
228 |
sd = seleMan_.nextSelected(i)) { |
229 |
|
230 |
myIndex = sd->getGlobalIndex(); |
231 |
|
232 |
nBonds = 0; |
233 |
|
234 |
for (int l = 0; l <= lMax_; l++) { |
235 |
for (int m = -l; m <= l; m++) { |
236 |
q[std::make_pair(l,m)] = 0.0; |
237 |
} |
238 |
} |
239 |
pos = sd->getPos(); |
240 |
rCOM = CenterOfMass - pos; |
241 |
if (usePeriodicBoundaryConditions_) |
242 |
currentSnapshot_->wrapVector(rCOM); |
243 |
distCOM = rCOM.length(); |
244 |
|
245 |
// inner loop is over all other atoms in the system: |
246 |
|
247 |
for (mol = info_->beginMolecule(mi); mol != NULL; |
248 |
mol = info_->nextMolecule(mi)) { |
249 |
for (atom = mol->beginAtom(ai); atom != NULL; |
250 |
atom = mol->nextAtom(ai)) { |
251 |
|
252 |
if (atom->getGlobalIndex() != myIndex) { |
253 |
vec = pos - atom->getPos(); |
254 |
|
255 |
if (usePeriodicBoundaryConditions_) |
256 |
currentSnapshot_->wrapVector(vec); |
257 |
|
258 |
// Calculate "bonds" and build Q_lm(r) where |
259 |
// Q_lm = Y_lm(theta(r),phi(r)) |
260 |
// The spherical harmonics are wrt any arbitrary coordinate |
261 |
// system, we choose standard spherical coordinates |
262 |
|
263 |
r = vec.length(); |
264 |
|
265 |
// Check to see if neighbor is in bond cutoff |
266 |
|
267 |
if (r < rCut_) { |
268 |
costheta = vec.z() / r; |
269 |
phi = atan2(vec.y(), vec.x()); |
270 |
|
271 |
for (int l = 0; l <= lMax_; l++) { |
272 |
sphericalHarmonic.setL(l); |
273 |
for(int m = -l; m <= l; m++){ |
274 |
sphericalHarmonic.setM(m); |
275 |
q[std::make_pair(l,m)] += sphericalHarmonic.getValueAt(costheta, phi); |
276 |
} |
277 |
} |
278 |
nBonds++; |
279 |
} |
280 |
} |
281 |
} |
282 |
} |
283 |
|
284 |
|
285 |
for (int l = 0; l <= lMax_; l++) { |
286 |
q2[l] = 0.0; |
287 |
for (int m = -l; m <= l; m++){ |
288 |
q[std::make_pair(l,m)] /= (RealType)nBonds; |
289 |
q2[l] += norm(q[std::make_pair(l,m)]); |
290 |
} |
291 |
q_l[l] = sqrt(q2[l] * 4.0 * NumericConstant::PI / (RealType)(2*l + 1)); |
292 |
} |
293 |
|
294 |
// Find Third Order Invariant W_l |
295 |
|
296 |
for (int l = 0; l <= lMax_; l++) { |
297 |
w[l] = 0.0; |
298 |
for (int m1 = -l; m1 <= l; m1++) { |
299 |
std::pair<int,int> lm = std::make_pair(l, m1); |
300 |
for (int mmm = 0; mmm <= (m2Max[lm] - m2Min[lm]); mmm++) { |
301 |
int m2 = m2Min[lm] + mmm; |
302 |
int m3 = -m1-m2; |
303 |
w[l] += w3j[lm][mmm] * q[lm] * |
304 |
q[std::make_pair(l,m2)] * q[std::make_pair(l,m3)]; |
305 |
} |
306 |
} |
307 |
|
308 |
w_hat[l] = w[l] / pow(q2[l], RealType(1.5)); |
309 |
} |
310 |
|
311 |
collectHistogram(q_l, w_hat, distCOM); |
312 |
|
313 |
// printf( "%s %18.10g %18.10g %18.10g %18.10g \n", sd->getType().c_str(),pos[0],pos[1],pos[2],real(w_hat[6])); |
314 |
|
315 |
} |
316 |
} |
317 |
|
318 |
writeOrderParameter(); |
319 |
} |
320 |
|
321 |
|
322 |
|
323 |
IcosahedralOfR::IcosahedralOfR(SimInfo* info, const std::string& filename, |
324 |
const std::string& sele, double rCut, |
325 |
int nbins, RealType len) : BOPofR(info, |
326 |
filename, |
327 |
sele, rCut, |
328 |
nbins, len) { |
329 |
} |
330 |
|
331 |
void IcosahedralOfR::collectHistogram(std::vector<RealType> q, |
332 |
std::vector<ComplexType> what, |
333 |
RealType distCOM) { |
334 |
|
335 |
if ( distCOM < len_){ |
336 |
// Figure out where this distance goes... |
337 |
int whichBin = int(distCOM / deltaR_); |
338 |
RCount_[whichBin]++; |
339 |
|
340 |
if(real(what[6]) < -0.15){ |
341 |
WofR_[whichBin]++; |
342 |
} |
343 |
if(q[6] > 0.5){ |
344 |
QofR_[whichBin]++; |
345 |
} |
346 |
} |
347 |
} |
348 |
|
349 |
FCCOfR::FCCOfR(SimInfo* info, const std::string& filename, |
350 |
const std::string& sele, double rCut, |
351 |
int nbins, RealType len) : BOPofR(info, filename, sele, rCut, |
352 |
nbins, len) {} |
353 |
|
354 |
|
355 |
void FCCOfR::collectHistogram(std::vector<RealType> q, |
356 |
std::vector<ComplexType> what, |
357 |
RealType distCOM) { |
358 |
|
359 |
if ( distCOM < len_){ |
360 |
// Figure out where this distance goes... |
361 |
int whichBin = int(distCOM / deltaR_); |
362 |
RCount_[whichBin]++; |
363 |
|
364 |
if(real(what[4]) < -0.12){ |
365 |
WofR_[whichBin]++; |
366 |
} |
367 |
} |
368 |
} |
369 |
|
370 |
void IcosahedralOfR::writeOrderParameter() { |
371 |
|
372 |
std::ofstream osq((getOutputFileName() + "qr").c_str()); |
373 |
|
374 |
if (osq.is_open()) { |
375 |
|
376 |
// Normalize by number of frames and write it out: |
377 |
|
378 |
for (int i = 0; i < nBins_; ++i) { |
379 |
RealType Rval = (i + 0.5) * deltaR_; |
380 |
osq << Rval; |
381 |
if (RCount_[i] == 0){ |
382 |
osq << "\t" << 0; |
383 |
osq << "\n"; |
384 |
}else{ |
385 |
osq << "\t" << (RealType)QofR_[i]/(RealType)RCount_[i]; |
386 |
osq << "\n"; |
387 |
} |
388 |
} |
389 |
|
390 |
osq.close(); |
391 |
|
392 |
} else { |
393 |
sprintf(painCave.errMsg, "BOPofR: unable to open %s\n", |
394 |
(getOutputFileName() + "q").c_str()); |
395 |
painCave.isFatal = 1; |
396 |
simError(); |
397 |
} |
398 |
|
399 |
std::ofstream osw((getOutputFileName() + "wr").c_str()); |
400 |
|
401 |
if (osw.is_open()) { |
402 |
// Normalize by number of frames and write it out: |
403 |
for (int i = 0; i < nBins_; ++i) { |
404 |
RealType Rval = deltaR_ * (i + 0.5); |
405 |
osw << Rval; |
406 |
if (RCount_[i] == 0){ |
407 |
osw << "\t" << 0; |
408 |
osw << "\n"; |
409 |
}else{ |
410 |
osw << "\t" << (RealType)WofR_[i]/(RealType)RCount_[i]; |
411 |
osw << "\n"; |
412 |
} |
413 |
} |
414 |
|
415 |
osw.close(); |
416 |
} else { |
417 |
sprintf(painCave.errMsg, "BOPofR: unable to open %s\n", |
418 |
(getOutputFileName() + "w").c_str()); |
419 |
painCave.isFatal = 1; |
420 |
simError(); |
421 |
|
422 |
} |
423 |
|
424 |
} |
425 |
void FCCOfR::writeOrderParameter() { |
426 |
|
427 |
std::ofstream osw((getOutputFileName() + "wr").c_str()); |
428 |
|
429 |
if (osw.is_open()) { |
430 |
// Normalize by number of frames and write it out: |
431 |
for (int i = 0; i < nBins_; ++i) { |
432 |
RealType Rval = deltaR_ * (i + 0.5); |
433 |
osw << Rval; |
434 |
if (RCount_[i] == 0){ |
435 |
osw << "\t" << 0; |
436 |
osw << "\n"; |
437 |
}else{ |
438 |
osw << "\t" << (RealType)WofR_[i]/(RealType)RCount_[i]; |
439 |
osw << "\n"; |
440 |
} |
441 |
} |
442 |
|
443 |
osw.close(); |
444 |
} else { |
445 |
sprintf(painCave.errMsg, "BOPofR: unable to open %s\n", |
446 |
(getOutputFileName() + "w").c_str()); |
447 |
painCave.isFatal = 1; |
448 |
simError(); |
449 |
|
450 |
} |
451 |
|
452 |
} |
453 |
} |