45 |
|
* Phys Rev B, 28,784,1983 |
46 |
|
* |
47 |
|
*/ |
48 |
< |
|
48 |
> |
|
49 |
|
#include "applications/staticProps/BondOrderParameter.hpp" |
50 |
|
#include "utils/simError.h" |
51 |
|
#include "io/DumpReader.hpp" |
52 |
|
#include "primitives/Molecule.hpp" |
53 |
|
#include "utils/NumericConstant.hpp" |
54 |
< |
#include "math/RealSphericalHarmonic.hpp" |
54 |
> |
#include "math/SphericalHarmonic.hpp" |
55 |
> |
|
56 |
|
namespace oopse { |
57 |
|
|
58 |
+ |
BondOrderParameter::BondOrderParameter(SimInfo* info, |
59 |
+ |
const std::string& filename, |
60 |
+ |
const std::string& sele, |
61 |
+ |
double rCut, int lNumber, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){ |
62 |
+ |
|
63 |
+ |
setOutputName(getPrefix(filename) + ".bo"); |
64 |
|
|
65 |
< |
BondOrderParameter::BondOrderParameter(SimInfo* info, const std::string& filename, const std::string& sele1, |
66 |
< |
const std::string& sele2, double rCut, int lNumber) |
67 |
< |
: StaticAnalyser(info, filename), |
61 |
< |
selectionScript1_(sele1), evaluator1_(info), |
62 |
< |
seleMan1_(info){ |
63 |
< |
|
64 |
< |
setOutputName(getPrefix(filename) + ".obo"); |
65 |
< |
|
66 |
< |
evaluator1_.loadScriptString(sele1); |
67 |
< |
evaluator2_.loadScriptString(sele2); |
68 |
< |
|
69 |
< |
if (!evaluator1_.isDynamic()) { |
70 |
< |
seleMan1_.setSelectionSet(evaluator1_.evaluate()); |
71 |
< |
}else { |
72 |
< |
sprintf( painCave.errMsg, |
73 |
< |
"--sele1 must be static selection\n"); |
74 |
< |
painCave.severity = OOPSE_ERROR; |
75 |
< |
painCave.isFatal = 1; |
76 |
< |
simError(); |
65 |
> |
evaluator_.loadScriptString(sele); |
66 |
> |
if (!evaluator_.isDynamic()) { |
67 |
> |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
68 |
|
} |
69 |
|
|
70 |
< |
/* Set up cutoff radius and type of order parameter we are calcuating*/ |
70 |
> |
// Set up cutoff radius and order of the Legendre Polynomial: |
71 |
> |
|
72 |
|
lNumber_ = lNumber; |
73 |
|
rCut_ = rCut; |
74 |
< |
mSize_ = 2*lNumber_+1; |
74 |
> |
mSize_ = 2*lNumber_+1; |
75 |
> |
} |
76 |
|
|
77 |
< |
int i; |
78 |
< |
int j; |
86 |
< |
StuntDouble* sd1; |
87 |
< |
StuntDouble* sd2; |
88 |
< |
for (sd1 = seleMan1_.beginSelected(i), sd2 = seleMan1_.beginSelected(j); |
89 |
< |
sd1 != NULL && sd2 != NULL; |
90 |
< |
sd1 = seleMan1_.nextSelected(i), sd2 = seleMan2_.nextSelected(j)) { |
91 |
< |
for (sd2 = seleMan1_.beginSelected(j),sd2 |
92 |
< |
sdPairs_.push_back(std::make_pair(sd1, sd2)); |
93 |
< |
} |
77 |
> |
BondOrderParameter::~BondOrderParameter() { |
78 |
> |
} |
79 |
|
|
80 |
+ |
void BondOrderParameter::process() { |
81 |
+ |
Molecule* mol; |
82 |
+ |
Atom* atom; |
83 |
+ |
RigidBody* rb; |
84 |
+ |
int myIndex; |
85 |
+ |
SimInfo::MoleculeIterator mi; |
86 |
+ |
Molecule::RigidBodyIterator rbIter; |
87 |
+ |
Molecule::AtomIterator ai; |
88 |
+ |
StuntDouble* sd; |
89 |
+ |
Vector3d vec; |
90 |
+ |
RealType costheta; |
91 |
+ |
RealType phi; |
92 |
+ |
RealType r; |
93 |
+ |
RealType dist; |
94 |
+ |
std::map<int,ComplexType> QBar_lm; |
95 |
+ |
RealType QSq_l; |
96 |
+ |
RealType Q_l; |
97 |
+ |
ComplexType W_l; |
98 |
+ |
ComplexType W_l_hat; |
99 |
+ |
int nBonds; |
100 |
+ |
SphericalHarmonic sphericalHarmonic; |
101 |
+ |
int i, j; |
102 |
+ |
// Make arrays for Wigner3jm |
103 |
+ |
double* THRCOF = new double[mSize_]; |
104 |
+ |
// Variables for Wigner routine |
105 |
+ |
double l_ = (double)lNumber_; |
106 |
+ |
double m1Pass, m2Min, m2Max; |
107 |
+ |
int error, m1, m2, m3; |
108 |
|
|
109 |
< |
} |
109 |
> |
// Set the l for the spherical harmonic, it doesn't change |
110 |
> |
sphericalHarmonic.setL(lNumber_); |
111 |
|
|
112 |
< |
void BondOrderParameter::process |
113 |
< |
() { |
114 |
< |
Molecule* mol; |
101 |
< |
RigidBody* rb; |
102 |
< |
SimInfo::MoleculeIterator mi; |
103 |
< |
Molecule::RigidBodyIterator rbIter; |
104 |
< |
RealType theta; |
105 |
< |
RealType phi; |
106 |
< |
RealType r; |
107 |
< |
RealType dist; |
108 |
< |
RealType* QBar_lm; |
109 |
< |
RealType QSq_l; |
110 |
< |
int nBonds; |
111 |
< |
int m, m_index; |
112 |
< |
RealSphericalHarmonic sphericalHarmonic; |
112 |
> |
DumpReader reader(info_, dumpFilename_); |
113 |
> |
int nFrames = reader.getNFrames(); |
114 |
> |
frameCounter_ = 0; |
115 |
|
|
116 |
+ |
for (int istep = 0; istep < nFrames; istep += step_) { |
117 |
+ |
reader.readFrame(istep); |
118 |
+ |
frameCounter_++; |
119 |
+ |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
120 |
+ |
|
121 |
+ |
if (evaluator_.isDynamic()) { |
122 |
+ |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
123 |
+ |
} |
124 |
|
|
125 |
< |
DumpReader reader(info_, dumpFilename_); |
116 |
< |
int nFrames = reader.getNFrames(); |
125 |
> |
// update the positions of atoms which belong to the rigidbodies |
126 |
|
|
127 |
< |
/*Set the l for the spherical harmonic, it doesn't change*/ |
128 |
< |
sphericalHarmonic.setL(lNumber_); |
129 |
< |
|
130 |
< |
for (int i = 0; i < nFrames; i += step_) { |
131 |
< |
reader.readFrame(i); |
132 |
< |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
133 |
< |
nBonds = 0; |
134 |
< |
|
135 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
136 |
< |
//change the positions of atoms which belong to the rigidbodies |
137 |
< |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
138 |
< |
rb->updateAtoms(); |
130 |
< |
} |
131 |
< |
|
132 |
< |
} |
133 |
< |
|
134 |
< |
|
135 |
< |
/* Setup QBar */ |
136 |
< |
QBar_lm = new double[mSize_]; |
137 |
< |
|
138 |
< |
/* Calculate "bonds" and build Q_lm(r) where Q_lm = Y_lm(theta(r),phi(r)) */ |
139 |
< |
for (std::vector<std::pair<StuntDouble*, StuntDouble*> >::iterator j = sdPairs_.begin(); j != sdPairs_.end(); ++j) { |
140 |
< |
Vector3d vec = j->first->getPos() - j->second->getPos(); |
141 |
< |
currentSnapshot_->wrapVector(vec); |
142 |
< |
/* The spherical harmonics are wrt any arbitray coordiate sysetm, |
143 |
< |
* we choose standard spherical coordinates */ |
144 |
< |
r = sqrt(pow(vec.x(),2)+pow(vec.y(),2)+pow(vec.z(),2)); |
145 |
< |
|
146 |
< |
/* Check to see if neighbor is in bond cuttoff*/ |
147 |
< |
if (r<rCut_){ |
148 |
< |
theta = atan(vec.y()/vec.x()); |
149 |
< |
phi = acos(vec.z()/r); |
150 |
< |
for(int m_index = 0; m_index < mSize_; m_index++){ |
151 |
< |
sphericalHarmonic.setM(m_index-lNumber_); |
152 |
< |
QBar_lm(m_index) += sphericalHarmonic.getValueAt(theta,phi); |
153 |
< |
} |
154 |
< |
nBonds++; |
155 |
< |
} |
156 |
< |
} |
157 |
< |
|
158 |
< |
/*Normalize Qbar by number of Bonds*/ |
159 |
< |
for ( int m_index = 0;m_index < mSize_; m_index++){ |
160 |
< |
QBar_lm(m_index) = QBar_lm(m_index)/nBonds; |
161 |
< |
} |
162 |
< |
|
163 |
< |
|
127 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
128 |
> |
mol = info_->nextMolecule(mi)) { |
129 |
> |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
130 |
> |
rb = mol->nextRigidBody(rbIter)) { |
131 |
> |
rb->updateAtoms(); |
132 |
> |
} |
133 |
> |
} |
134 |
> |
|
135 |
> |
nBonds = 0; |
136 |
> |
|
137 |
> |
for (int m = -lNumber_; m <= lNumber_; m++) { |
138 |
> |
QBar_lm[m] = 0.0; |
139 |
|
} |
140 |
+ |
|
141 |
+ |
// outer loop is over the selected StuntDoubles: |
142 |
|
|
143 |
< |
/*Normalize by number of frames*/ |
144 |
< |
for ( int m_index = 0;m_index < mSize_; m_index++){ |
168 |
< |
QBar_lm(m_index) = QBar_lm(m_index)/nFrames; |
169 |
< |
} |
143 |
> |
for (sd = seleMan_.beginSelected(i); sd != NULL; |
144 |
> |
sd = seleMan_.nextSelected(i)) { |
145 |
|
|
146 |
+ |
myIndex = sd->getGlobalIndex(); |
147 |
+ |
|
148 |
+ |
// inner loop is over all other atoms in the system: |
149 |
+ |
|
150 |
+ |
for (mol = info_->beginMolecule(mi); mol != NULL; |
151 |
+ |
mol = info_->nextMolecule(mi)) { |
152 |
+ |
for (atom = mol->beginAtom(ai); atom != NULL; |
153 |
+ |
atom = mol->nextAtom(ai)) { |
154 |
|
|
155 |
+ |
if (atom->getGlobalIndex() != myIndex) { |
156 |
|
|
157 |
< |
/* Find second order invariant Q_l*/ |
157 |
> |
vec = sd->getPos() - atom->getPos(); |
158 |
> |
currentSnapshot_->wrapVector(vec); |
159 |
> |
|
160 |
> |
// Calculate "bonds" and build Q_lm(r) where |
161 |
> |
// Q_lm = Y_lm(theta(r),phi(r)) |
162 |
> |
// The spherical harmonics are wrt any arbitrary coordinate |
163 |
> |
// system, we choose standard spherical coordinates |
164 |
> |
|
165 |
> |
r = vec.length(); |
166 |
> |
|
167 |
> |
// Check to see if neighbor is in bond cutoff |
168 |
> |
|
169 |
> |
if (r < rCut_) { |
170 |
> |
costheta = vec.z() / r; |
171 |
> |
phi = atan2(vec.y(), vec.x()); |
172 |
> |
|
173 |
> |
for(int m = -lNumber_; m <= lNumber_; m++){ |
174 |
> |
sphericalHarmonic.setM(m); |
175 |
> |
QBar_lm[m] += sphericalHarmonic.getValueAt(costheta, phi); |
176 |
> |
} |
177 |
> |
nBonds++; |
178 |
> |
} |
179 |
> |
} |
180 |
> |
} |
181 |
> |
} |
182 |
> |
} |
183 |
> |
} |
184 |
|
|
185 |
< |
for (int m_index = 0 ;m_index <= sizeM_; m++){ |
186 |
< |
QSq_l += pow(QBar_lm(m),2); |
185 |
> |
// Normalize Qbar2 |
186 |
> |
for (int m = -lNumber_;m <= lNumber_; m++){ |
187 |
> |
QBar_lm[m] /= nBonds; |
188 |
> |
} |
189 |
> |
|
190 |
> |
// Find second order invariant Q_l |
191 |
> |
|
192 |
> |
QSq_l = 0.0; |
193 |
> |
for (int m = -lNumber_; m <= lNumber_; m++){ |
194 |
> |
QSq_l += norm(QBar_lm[m]); |
195 |
> |
} |
196 |
> |
|
197 |
> |
std::cout << "qsl = " << QSq_l << "\n"; |
198 |
> |
Q_l = sqrt(QSq_l * 4.0 * NumericConstant::PI / (RealType)(2*lNumber_ + 1)); |
199 |
> |
|
200 |
> |
// Find Third Order Invariant W_l |
201 |
> |
|
202 |
> |
W_l = 0.0; |
203 |
> |
for (int m1 = -lNumber_; m1 <= lNumber_; m1++) { |
204 |
> |
// Zero work array |
205 |
> |
for (int ii = 0; ii < mSize_; ii++){ |
206 |
> |
THRCOF[ii] = 0.0; |
207 |
|
} |
208 |
< |
Q_l_ = sqrt((4*NumericConstant::PI/lNumber_+1)*QSq_l); |
209 |
< |
|
210 |
< |
/* Find Third Order Invariant W_l*/ |
211 |
< |
|
212 |
< |
/* Make arrays for Wigner3jm */ |
213 |
< |
double* THRCOF = new double[mSize_]; |
214 |
< |
/* Variables for Wigner routine */ |
215 |
< |
double l_ = (double)lNumber_; |
216 |
< |
double m2Min; |
217 |
< |
double m2Max; |
218 |
< |
int error; |
189 |
< |
int m1; |
190 |
< |
int m2; |
191 |
< |
int m3; |
192 |
< |
|
193 |
< |
for (int m1 = -lNumber_;m <= lNumber_;m1++){ |
194 |
< |
/* Zero work array */ |
195 |
< |
for (i=0; i<mSize_;i++){ |
196 |
< |
THRCOF[i] = 0.0; |
197 |
< |
} |
198 |
< |
/* Get wigner coefficients */ |
199 |
< |
Wigner3jm(&l_,&l_,&l_,&(double)m1,&m2Min,&m2Max&,THRCOF,&mSize_,&error); |
200 |
< |
for (m_index=1; i<(m2Max-M2Min-1.0);m_index++){ |
201 |
< |
m2 = floor(m2Min) + m_index - 1; |
202 |
< |
m3 = -m1-m2; |
203 |
< |
W_l_ += THRCOF(m_index)*QBar_lm(m1+lNumber_)*QBar_lm(m2+lNumber_)*QBar_lm(m3+lNumber_); |
204 |
< |
} |
208 |
> |
// Get Wigner coefficients |
209 |
> |
m1Pass = (double)m1; |
210 |
> |
|
211 |
> |
Wigner3jm(&l_, &l_, &l_, |
212 |
> |
&m1Pass, &m2Min, &m2Max, |
213 |
> |
THRCOF, &mSize_, &error); |
214 |
> |
|
215 |
> |
for (int mmm = 0; mmm < (int)(m2Max - m2Min); mmm++) { |
216 |
> |
m2 = (int)floor(m2Min) + mmm; |
217 |
> |
m3 = -m1-m2; |
218 |
> |
W_l += THRCOF[mmm] * QBar_lm[m1] * QBar_lm[m2] * QBar_lm[m3]; |
219 |
|
} |
206 |
– |
|
207 |
– |
|
208 |
– |
writeOrderParameter(); |
209 |
– |
|
220 |
|
} |
221 |
+ |
|
222 |
+ |
W_l_hat = W_l / pow(QSq_l, 1.5); |
223 |
+ |
|
224 |
+ |
writeOrderParameter(Q_l, real(W_l_hat)); |
225 |
+ |
} |
226 |
|
|
227 |
|
|
228 |
< |
void BondOrderParameter::writeOrderParameter() { |
228 |
> |
void BondOrderParameter::writeOrderParameter(RealType ql, RealType Wlhat) { |
229 |
|
|
230 |
< |
std::ofstream os(getOutputFileName().c_str()); |
216 |
< |
os << "#radial distribution function\n"; |
217 |
< |
os<< "#selection1: (" << selectionScript1_ << ")\t"; |
218 |
< |
os << "selection2: (" << selectionScript2_ << ")\n"; |
219 |
< |
os << "#p2\tdirector_x\tdirector_y\tdiretor_z\tangle(degree)\n"; |
230 |
> |
std::ofstream os(getOutputFileName().c_str()); |
231 |
|
|
232 |
< |
for (std::size_t i = 0; i < orderParams_.size(); ++i) { |
233 |
< |
os << orderParams_[i].p2 << "\t" |
234 |
< |
<< orderParams_[i].director[0] << "\t" |
235 |
< |
<< orderParams_[i].director[1] << "\t" |
236 |
< |
<< orderParams_[i].director[2] << "\t" |
237 |
< |
<< orderParams_[i].angle << "\n"; |
232 |
> |
if (os.is_open()) { |
233 |
> |
|
234 |
> |
os << "# Bond Order Parameters\n"; |
235 |
> |
os << "# selection: (" << selectionScript_ << ")\n"; |
236 |
> |
os << "# \n"; |
237 |
> |
os << "# <Q_" << lNumber_ << ">: " << ql << "\n"; |
238 |
> |
os << "# <W_" << lNumber_ << ">: " << Wlhat << "\n"; |
239 |
> |
os.close(); |
240 |
|
|
241 |
< |
} |
242 |
< |
|
241 |
> |
} else { |
242 |
> |
sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", |
243 |
> |
getOutputFileName().c_str()); |
244 |
> |
painCave.isFatal = 1; |
245 |
> |
simError(); |
246 |
|
} |
231 |
– |
|
247 |
|
} |
248 |
< |
|
248 |
> |
} |