53#include "utils/Constants.hpp"
54#include "utils/simError.h"
58SphericalHarmonic::SphericalHarmonic() {}
60ComplexType SphericalHarmonic::getValueAt(RealType costheta, RealType phi) {
64 p = Ptilde(L, M, costheta);
65 ComplexType phase(0.0, (RealType)M * phi);
67 return exp(phase) * (ComplexType)p;
72RealType SphericalHarmonic::LegendreP(
int l,
int m, RealType x) {
76 printf(
"LegendreP: x out of range: l = %d\tm = %d\tx = %lf\n", l, m, x);
77 return std::numeric_limits<RealType>::quiet_NaN();
81 printf(
"LegendreP: m > l: l = %d\tm = %d\tx = %lf\n", l, m, x);
82 return std::numeric_limits<RealType>::quiet_NaN();
86 printf(
"LegendreP: m < 0: l = %d\tm = %d\tx = %lf\n", l, m, x);
87 return std::numeric_limits<RealType>::quiet_NaN();
89 RealType temp1, temp2(0.0), temp3, temp4, temp5;
93 temp1 = sqrt(1.0 - pow(x, 2));
95 for (
int i = 1; i <= m; ++i) {
96 temp3 *= -temp5 * temp1;
103 temp4 = x * (2. * m + 1.) * temp3;
107 for (
int ll = (m + 2); ll <= l; ++ll) {
108 temp2 = (x * (2. * ll - 1.) * temp4 - (ll + m - 1.) * temp3) /
123RealType SphericalHarmonic::Legendre(
int l,
int m, RealType x) {
125 if (m > l || m < -l) {
126 printf(
"Legendre got a bad argument: l = %d\tm = %d\tx = %lf\n", l, m, x);
127 return std::numeric_limits<RealType>::quiet_NaN();
129 result = LegendreP(l, m, x);
132 result = mpow(-m) * Fact(l + m) / Fact(l - m) * LegendreP(l, -m, x);
140RealType SphericalHarmonic::Ptilde(
int l,
int m, RealType x) {
142 if (m > l || m < -l) {
145 RealType y = (RealType)(2. * l + 1.) * Fact(l - m) / Fact(l + m);
146 result = mpow(m) * sqrt(y) * Legendre(l, m, x) / sqrt(4.0 * Constants::PI);
153RealType SphericalHarmonic::mpow(
int m) {
165static RealType factorial_list[171] = {1.,
186 5.109094217170944e19,
187 1.1240007277776077e21,
188 2.585201673888498e22,
189 6.204484017332394e23,
190 1.5511210043330986e25,
191 4.0329146112660565e26,
192 1.0888869450418352e28,
193 3.0488834461171387e29,
194 8.841761993739702e30,
195 2.6525285981219107e32,
196 8.222838654177922e33,
197 2.631308369336935e35,
198 8.683317618811886e36,
199 2.9523279903960416e38,
200 1.0333147966386145e40,
201 3.7199332678990125e41,
202 1.3763753091226346e43,
203 5.230226174666011e44,
204 2.0397882081197444e46,
205 8.159152832478977e47,
206 3.345252661316381e49,
208 6.041526306337383e52,
209 2.658271574788449e54,
210 1.1962222086548019e56,
211 5.502622159812089e57,
212 2.5862324151116818e59,
213 1.2413915592536073e61,
214 6.082818640342675e62,
215 3.0414093201713376e64,
216 1.5511187532873822e66,
217 8.065817517094388e67,
218 4.2748832840600255e69,
219 2.308436973392414e71,
220 1.2696403353658276e73,
221 7.109985878048635e74,
222 4.0526919504877214e76,
223 2.3505613312828785e78,
224 1.3868311854568984e80,
226 5.075802138772248e83,
227 3.146997326038794e85,
229 1.2688693218588417e89,
230 8.247650592082472e90,
231 5.443449390774431e92,
232 3.647111091818868e94,
233 2.4800355424368305e96,
234 1.711224524281413e98,
235 1.1978571669969892e100,
236 8.504785885678623e101,
237 6.1234458376886085e103,
238 4.4701154615126844e105,
239 3.307885441519386e107,
240 2.48091408113954e109,
241 1.8854947016660504e111,
242 1.4518309202828587e113,
243 1.1324281178206297e115,
244 8.946182130782976e116,
245 7.156945704626381e118,
246 5.797126020747368e120,
247 4.753643337012842e122,
248 3.945523969720659e124,
249 3.314240134565353e126,
250 2.81710411438055e128,
251 2.4227095383672734e130,
252 2.107757298379528e132,
253 1.8548264225739844e134,
254 1.650795516090846e136,
255 1.4857159644817615e138,
256 1.352001527678403e140,
257 1.2438414054641308e142,
258 1.1567725070816416e144,
259 1.087366156656743e146,
260 1.032997848823906e148,
261 9.916779348709496e149,
262 9.619275968248212e151,
263 9.426890448883248e153,
264 9.332621544394415e155,
265 9.332621544394415e157,
266 9.42594775983836e159,
267 9.614466715035127e161,
268 9.90290071648618e163,
269 1.0299016745145628e166,
270 1.081396758240291e168,
271 1.1462805637347084e170,
272 1.226520203196138e172,
273 1.324641819451829e174,
274 1.4438595832024937e176,
275 1.588245541522743e178,
276 1.7629525510902446e180,
277 1.974506857221074e182,
278 2.2311927486598138e184,
279 2.5435597334721877e186,
280 2.925093693493016e188,
281 3.393108684451898e190,
282 3.969937160808721e192,
283 4.684525849754291e194,
284 5.574585761207606e196,
285 6.689502913449127e198,
286 8.094298525273444e200,
287 9.875044200833601e202,
288 1.214630436702533e205,
289 1.506141741511141e207,
290 1.882677176888926e209,
291 2.372173242880047e211,
292 3.0126600184576594e213,
293 3.856204823625804e215,
294 4.974504222477287e217,
295 6.466855489220474e219,
296 8.47158069087882e221,
297 1.1182486511960043e224,
298 1.4872707060906857e226,
299 1.9929427461615188e228,
300 2.6904727073180504e230,
301 3.659042881952549e232,
302 5.012888748274992e234,
303 6.917786472619489e236,
304 9.615723196941089e238,
305 1.3462012475717526e241,
306 1.898143759076171e243,
307 2.695364137888163e245,
308 3.854370717180073e247,
309 5.5502938327393044e249,
310 8.047926057471992e251,
311 1.1749972043909107e254,
312 1.727245890454639e256,
313 2.5563239178728654e258,
314 3.80892263763057e260,
315 5.713383956445855e262,
316 8.62720977423324e264,
317 1.3113358856834524e267,
318 2.0063439050956823e269,
319 3.0897696138473508e271,
320 4.789142901463394e273,
321 7.471062926282894e275,
322 1.1729568794264145e278,
323 1.853271869493735e280,
324 2.9467022724950384e282,
325 4.7147236359920616e284,
326 7.590705053947219e286,
327 1.2296942187394494e289,
328 2.0044015765453026e291,
329 3.287218585534296e293,
330 5.423910666131589e295,
331 9.003691705778438e297,
332 1.503616514864999e300,
333 2.5260757449731984e302,
334 4.269068009004705e304,
335 7.257415615307999e306};
340RealType SphericalHarmonic::Fact(
int j) {
341 if (j <= 170 && j >= 0)
return factorial_list[j];
343 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
"Fact(j) for j >= 171\n");
344 painCave.isFatal = 0;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.