1
/*****************************************************************************
2
TRAVIS - Trajectory Analyzer and Visualizer
3
http://www.travis-analyzer.de/
5
Copyright (c) 2009-2013 Martin Brehm
6
2012-2013 Martin Thomas
8
This file written by Martin Thomas.
10
This program is free software: you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*****************************************************************************/
28
#include "globalvar.h"
29
#include "maintools.h"
33
#include "xfloatarray.h"
42
#include <sys/types.h>
47
static bool g_newRaman;
48
static char *g_ramanDir;
49
static bool g_orientAvg;
50
static float g_fieldStrength;
51
static int g_step = 0;
55
static char *g_inputTemplate;
56
static char *g_templateFieldPos;
57
static char *g_templatePolPos;
58
static char *g_templateCoordPos;
59
static char *g_templateStepsPos;
61
static CxObArray g_ramObserv;
63
static FILE *g_polFile[3];
64
static CTimeStep *g_timestep[3];
66
static FILE *g_reftrajFile;
67
static int g_steps = 0;
69
CRamanDyn::CRamanDyn(int showMol, bool global) {
73
m_iMolecules = g_oaSingleMolecules.GetSize();
76
m_iMolecules = ((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize();
79
/*** Set Names of dynamic arrays. By M. Brehm */
80
_dipole0.SetName("CRamanDyn::_dipole0");
82
for (int tz1=0;tz1<3;tz1++)
84
for (int tz2=0;tz2<3;tz2++)
86
sprintf(tbuf,"CRamanDyn::_polarizability[%d][%d]",tz1,tz2);
87
_polarizability[tz1][tz2].SetName(tbuf);
90
/* End of set names */
92
mprintf(YELLOW, ">>> Raman Spectrum >>>\n\n");
95
mprintf(" All atoms will be taken.\n\n");
97
mprintf(" All atoms will be taken from the OM %s.\n\n", ((CMolecule *)g_oaMolecules[m_iShowMol])->m_sName);
104
if(g_iTrajSteps != -1) {
105
int depth = (int)(g_iTrajSteps / g_stride * 0.75);
108
m_iDepth = AskUnsignedInteger(" Enter the resolution (=depth) of the ACF (in time steps): [%d] ", depth, depth);
110
m_iDepth = AskUnsignedInteger(" Enter the resolution (=depth) of the ACF (in time steps): [2000] ", 2000);
113
int size = CalcFFTSize(m_iDepth, false);
114
if(m_iDepth != size) {
115
mprintf(WHITE," The next \"fast\" size for FFT is %d. Using this instead of %d as depth.\n", size, m_iDepth);
122
_derivativeOrder = 1;
126
derive = AskYesNo(" Derive the vectors before autocorrelation (y/n)? [yes] ", true);
128
_derivativeOrder = AskRangeInteger(" Please enter degree of vector derivative (1-2): [1] ", 1, 2, 1);
129
window = AskYesNo(" Apply window function (Cos^2) to autocorrelation function (y/n)? [yes] ", true);
131
float possibleRange = 33356.41f / g_fTimestepLength / 2.0f / g_stride;
132
mprintf(" A time step length of %.2f fs with a stride of %d allows a spectral range up to %.2f cm^-1.\n", g_fTimestepLength, g_stride, possibleRange);
133
float specWaveNumber = AskRangeFloat("\n Calculate spectrum up to which wave number (cm^-1)? [%.2f cm^-1] ", 0, possibleRange, (possibleRange < 5000.0f) ? possibleRange : 5000.0f, (possibleRange < 5000.0f) ? possibleRange : 5000.0f);
135
int zeroPadding = m_iDepth * 3;
137
mirror = AskRangeInteger(" No mirroring (0) or short-time enhancing (1)? [1] ", 0, 1, 1);
138
zeroPadding = AskUnsignedInteger(" Zero Padding: How many zeros to insert? [%d] ", m_iDepth * 3, m_iDepth * 3);
141
size = CalcFFTSize(m_iDepth + zeroPadding, false);
142
if(m_iDepth + zeroPadding != size) {
143
mprintf(WHITE, " The next \"fast\" size for FFT is %d. Using %d zeros for zero padding.\n", size, size-m_iDepth);
144
zeroPadding = size-m_iDepth;
147
mprintf(" This results in a spectral resolution to %.2f cm^-1.\n\n", 33356.41 / g_fTimestepLength / 2.0f / size);
149
try { _isoACF = new CACF(); } catch(...) { _isoACF = NULL; }
150
if(_isoACF == NULL) NewException((double)sizeof(CACF), __FILE__, __LINE__, __PRETTY_FUNCTION__);
151
_isoACF->m_iSize = m_iDepth;
152
_isoACF->m_bSpectrum = true;
153
_isoACF->m_bDerivative = derive;
154
_isoACF->m_iDerivative = _derivativeOrder;
155
_isoACF->m_bWindowFunction = window;
156
_isoACF->m_fSpecWaveNumber = specWaveNumber;
157
_isoACF->m_iMirror = mirror;
158
_isoACF->m_iZeroPadding = zeroPadding;
159
_isoACF->m_bACF_DB = false;
161
try { _anisoACF = new CACF(); } catch(...) { _anisoACF = NULL; }
162
if(_anisoACF == NULL) NewException((double)sizeof(CACF), __FILE__, __LINE__, __PRETTY_FUNCTION__);
163
_anisoACF->m_iSize = m_iDepth;
164
_anisoACF->m_bSpectrum = true;
165
_anisoACF->m_bDerivative = derive;
166
_anisoACF->m_iDerivative = _derivativeOrder;
167
_anisoACF->m_bWindowFunction = window;
168
_anisoACF->m_fSpecWaveNumber = specWaveNumber;
169
_anisoACF->m_iMirror = mirror;
170
_anisoACF->m_iZeroPadding = zeroPadding;
171
_anisoACF->m_bACF_DB = false;
175
mprintf(YELLOW, "<<< End of Raman Spectrum <<<\n\n");
178
CRamanDyn::~CRamanDyn() {
181
for(i = 0; i < m_iMolecules; i++)
182
delete (CxFloatArray *)_dipole0[i];
183
for(i = 0; i < m_iMolecules; i++) {
184
for(j = 0; j < 3; j++) {
185
for(k = 0; k < (g_orientAvg ? 3 : 1); k++) {
186
delete (CxFloatArray *)_polarizability[j][k][i];
194
void CRamanDyn::initialize() {
200
if (g_iTrajSteps != -1)
201
mprintf(" Raman Cache: Trying to allocate %s of memory...\n", FormatBytes((double)m_iMolecules * g_iTrajSteps / g_iStride / g_stride * (g_orientAvg ? 9.9 : 3.3) * sizeof(float)));
203
mprintf(" Raman Cache: Trying to allocate %s of memory...\n", FormatBytes((double)m_iMolecules * 2000 / g_iStride /g_stride * (g_orientAvg ? 9.9 : 3.3) * sizeof(float)));
204
for(i = 0; i < m_iMolecules; i++) {
205
CxVector3 *dipoleVector;
206
try { dipoleVector = new CxVector3(); } catch(...) { dipoleVector = NULL; }
207
if(dipoleVector == NULL) NewException((double)sizeof(CxVector3), __FILE__, __LINE__, __PRETTY_FUNCTION__);
208
_dipole0.Add(dipoleVector);
210
for(i = 0; i < m_iMolecules; i++) {
211
for(j = 0; j < 3; j++) {
212
for(k = 0; k < (g_orientAvg ? 3 : 1); k++) {
213
CxFloatArray *floatArray;
214
try { floatArray = new CxFloatArray("CRamanDyn::initialize():floatArray"); } catch(...) { floatArray = NULL; }
215
if(floatArray == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
216
if(g_iTrajSteps != -1) {
217
floatArray->SetMaxSize((long)(g_iTrajSteps / g_iStride / g_stride * 1.1));
218
floatArray->SetGrow((long)(g_iTrajSteps / g_iStride / g_stride * 0.1));
220
floatArray->SetGrow(10000);
222
_polarizability[j][k].Add(floatArray);
228
void CRamanDyn::getDipole0() {
231
for(i = 0; i < m_iMolecules; i++) {
234
sm = (CSingleMolecule *)g_oaSingleMolecules[i];
236
sm = (CSingleMolecule *)g_oaSingleMolecules[((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex[i]];
237
*((CxVector3 *)_dipole0[i]) = sm->m_vDipole;
241
void CRamanDyn::calcPolarizability(int fieldDirection) {
244
for(i = 0; i < m_iMolecules; i++) {
247
sm = (CSingleMolecule *)g_oaSingleMolecules[i];
249
sm = (CSingleMolecule *)g_oaSingleMolecules[((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex[i]];
250
for(int j = 0; j < 3; j++) {
251
((CxFloatArray *)_polarizability[j][fieldDirection][i])->Add(((*((CxVector3 *)_dipole0[i]))[j] - sm->m_vDipole[j]) / g_fieldStrength * 0.393430f); // 0.393430 - Umrechnung von Debye in a.u.
256
void CRamanDyn::finalize() {
259
char filename[BUF_SIZE];
261
snprintf(filename, BUF_SIZE, "%s/polarizability_%s.dat", g_ramanDir, m_sName);
263
sprintf(filename, "%s/polarizability_%s.dat", g_ramanDir, m_sName);
265
mprintf(" Writing polarizabilities for first molecule to \"%s\"...\n", filename);
267
pol_file = OpenFileWrite(filename, false);
268
for(i = 0; i < ((CxFloatArray *)_polarizability[0][0][0])->GetSize(); i++) {
269
fprintf(pol_file, "%10.2f", i * g_fTimestepLength * g_iStride * g_stride);
270
for(j = 0; j < (g_orientAvg ? 3 : 1); j++) {
271
for(k = 0; k < 3; k++) {
272
fprintf(pol_file, " %14.8f", (*((CxFloatArray *)_polarizability[k][j][0]))[i]);
275
fprintf(pol_file, "\n");
280
switch(_derivativeOrder) {
282
mprintf(" Not deriving polarizabilities.\n");
285
mprintf(" Deriving polarizabilities (1st derivative)...\n");
286
mprintf(WHITE, " [");
287
step = m_iMolecules / 20.0f;
288
for(i = 0; i < m_iMolecules; i++) {
289
if(fmodf((float)i, step) < 1.0f)
291
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - 1; j++) {
292
for(k = 0; k < 3; k++) {
293
for(l = 0; l < (g_orientAvg ? 3 : 1); l++) {
294
(*((CxFloatArray *)_polarizability[k][l][i]))[j] = 0.5f * ((*((CxFloatArray *)_polarizability[k][l][i]))[j+1] - (*((CxFloatArray *)_polarizability[k][l][i]))[j]);
299
mprintf(WHITE, "]\n");
302
mprintf(" Deriving polarizabilities (2nd derivative)...\n");
303
mprintf(WHITE, " [");
304
step = m_iMolecules / 20.0f;
305
for(i = 0; i < m_iMolecules; i++) {
306
if(fmodf((float)i, step) < 1.0f)
308
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - 2; j++) {
309
for(k = 0; k < 3; k++) {
310
for(l = 0; l < (g_orientAvg ? 3 : 1); l++) {
311
(*((CxFloatArray *)_polarizability[k][l][i]))[j] = (*((CxFloatArray *)_polarizability[k][l][i]))[j+2] - 2.0f * (*((CxFloatArray *)_polarizability[k][l][i]))[j+1] + (*((CxFloatArray *)_polarizability[k][l][i]))[j];
316
mprintf(WHITE, "]\n");
319
mprintf(RED, "Higher derivatives not implemented.\n");
324
mprintf(" Processing polarizability tensor components...\n");
325
step = m_iMolecules / 20.0f;
327
CAutoCorrelation *autoCorrelation;
328
try { autoCorrelation = new CAutoCorrelation(); } catch(...) { autoCorrelation = NULL; }
329
if(autoCorrelation == NULL) NewException((double)sizeof(CAutoCorrelation), __FILE__, __LINE__, __PRETTY_FUNCTION__);
330
autoCorrelation->Init(((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder, m_iDepth, g_bACFFFT);
333
CxFloatArray *isotropyPol, *isotropyACF;
334
try { isotropyACF = new CxFloatArray("CRamanDyn::finalize():isotropyACF"); } catch(...) { isotropyACF = NULL; }
335
if(isotropyACF == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
336
isotropyACF->SetSize(m_iDepth);
337
try { isotropyPol = new CxFloatArray("CRamanDyn::finalize():isotropyPol"); } catch(...) { isotropyPol = NULL; }
338
if(isotropyPol == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
339
isotropyPol->SetSize(((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder);
341
mprintf(" Isotropic part...\n");
342
mprintf(WHITE, " [");
343
for(i = 0; i < m_iDepth; i++) {
344
_isoACF->m_pData[i] = 0.0f;
346
for(i = 0; i < m_iMolecules; i++) {
347
if(fmodf((float)i, step) < 1.0f)
349
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
350
(*isotropyPol)[j] = 0.0f;
351
for(k = 0; k < 3; k++) {
352
(*isotropyPol)[j] += (*((CxFloatArray *)_polarizability[k][k][i]))[j];
354
(*isotropyPol)[j] /= 3.0f;
356
autoCorrelation->AutoCorrelate(isotropyPol, isotropyACF);
357
for(j = 0; j < m_iDepth; j++) {
358
_isoACF->m_pData[j] += (*isotropyACF)[j];
361
for(i = 0; i < m_iDepth; i++) {
363
_isoACF->m_pData[i] /= g_iSteps / g_stride;
365
_isoACF->m_pData[i] /= g_iSteps / g_stride * m_iMolecules;
367
mprintf(WHITE, "]\n");
369
// #ifdef TARGET_LINUX
370
// snprintf(filename, BUF_SIZE, "%s/acf_iso_%s.dat", g_ramanDir, m_sName);
372
// sprintf(filename, "%s/acf_iso_%s.dat", g_ramanDir, m_sName);
374
// mprintf(" Saving ACF as %s...\n", filename);
375
// FILE *acf_file = OpenFileWrite(filename, false);
376
// for(i = 0; i < m_iDepth; i++)
377
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _isoACF->m_pData[i]);
380
if(_isoACF->m_iMirror != 0) {
381
mprintf(" Mirroring ACF...\n");
382
_isoACF->Mirror(_isoACF->m_iMirror);
384
if(_isoACF->m_bWindowFunction != 0) {
385
mprintf(" Applying window function to ACF...\n");
389
// #ifdef TARGET_LINUX
390
// snprintf(filename, BUF_SIZE, "%s/acf_iso_%s.mw.dat", g_ramanDir, m_sName);
392
// sprintf(filename, "%s/acf_iso_%s.mw.dat", g_ramanDir, m_sName);
394
// mprintf(" Saving ACF as %s...\n", filename);
395
// acf_file = OpenFileWrite(filename, false);
396
// for(i = 0; i < _isoACF->m_iSize; i++)
397
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _isoACF->m_pData[i]);
400
mprintf(" Performing Fourier transformation...\n");
402
try { fft = new CFFT(); } catch(...) { fft = NULL; }
403
if(fft == NULL) NewException((double)sizeof(CFFT), __FILE__, __LINE__, __PRETTY_FUNCTION__);
404
fft->PrepareFFT_C2C(_isoACF->m_iSize + _isoACF->m_iZeroPadding);
405
_isoACF->Transform(fft);
407
_isoACF->m_pSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
409
// #ifdef TARGET_LINUX
410
// snprintf(filename, BUF_SIZE, "%s/spectrum_iso_%s.dat", g_ramanDir, m_sName);
412
// sprintf(filename, "%s/spectrum_iso_%s.dat", g_ramanDir, m_sName);
414
// mprintf(" Saving spectrum as %s...\n", filename);
415
// _isoACF->m_pSpectrum->Write("", filename, "");
420
CxFloatArray *anisotropyPol, *anisotropyACF, *anisotropyACFSum;
421
try { anisotropyPol = new CxFloatArray("CRamanDyn::finalize():anisotropyPol"); } catch(...) { anisotropyPol = NULL; }
422
if(anisotropyPol == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
423
anisotropyPol->SetSize(((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder);
424
try { anisotropyACF = new CxFloatArray("CRamanDyn::finalize():anisotropyACF"); } catch(...) { anisotropyACF = NULL; }
425
if(anisotropyACF == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
426
anisotropyACF->SetSize(m_iDepth);
427
try { anisotropyACFSum = new CxFloatArray("CRamanDyn::finalize():anisotropyACFSum"); } catch(...) { anisotropyACFSum = NULL; }
428
if(anisotropyACFSum == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
429
anisotropyACFSum->SetSize(m_iDepth);
431
mprintf(" First anisotropic part...\n");
432
mprintf(WHITE, " [");
433
for(i = 0; i < m_iDepth; i++) {
434
_anisoACF->m_pData[i] = 0.0f;
436
for(i = 0; i < m_iMolecules; i++) {
437
if(fmodf((float)i, step) < 1.0f)
439
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
440
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[0][0][i]))[j];
441
(*anisotropyPol)[j] -= (*((CxFloatArray *)_polarizability[1][1][i]))[j];
443
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
444
for(int j = 0; j < m_iDepth; j++) {
445
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
448
for(i = 0; i < m_iDepth; i++) {
449
(*anisotropyACFSum)[i] = 0.5f * _anisoACF->m_pData[i];
451
mprintf(WHITE, "]\n");
453
mprintf(" Second anisotropic part...\n");
454
mprintf(WHITE, " [");
455
for(i = 0; i < m_iDepth; i++) {
456
_anisoACF->m_pData[i] = 0.0f;
458
for(i = 0; i < m_iMolecules; i++) {
459
if(fmodf((float)i, step) < 1.0f)
461
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
462
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[1][1][i]))[j];
463
(*anisotropyPol)[j] -= (*((CxFloatArray *)_polarizability[2][2][i]))[j];
465
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
466
for(j = 0; j < m_iDepth; j++) {
467
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
470
for(i = 0; i < m_iDepth; i++) {
471
(*anisotropyACFSum)[i] += 0.5f * _anisoACF->m_pData[i];
473
mprintf(WHITE, "]\n");
475
mprintf(" Third anisotropic part...\n");
476
mprintf(WHITE, " [");
477
for(i = 0; i < m_iDepth; i++) {
478
_anisoACF->m_pData[i] = 0.0f;
480
for(i = 0; i < m_iMolecules; i++) {
481
if(fmodf((float)i, step) < 1.0f)
483
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
484
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[2][2][i]))[j];
485
(*anisotropyPol)[j] -= (*((CxFloatArray *)_polarizability[0][0][i]))[j];
487
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
488
for(j = 0; j < m_iDepth; j++) {
489
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
492
for(i = 0; i < m_iDepth; i++) {
493
(*anisotropyACFSum)[i] += 0.5f * _anisoACF->m_pData[i];
495
mprintf(WHITE, "]\n");
497
mprintf(" Fourth anisotropic part...\n");
498
mprintf(WHITE, " [");
499
for(i = 0; i < m_iDepth; i++) {
500
_anisoACF->m_pData[i] = 0.0f;
502
for(i = 0; i < m_iMolecules; i++) {
503
if(fmodf((float)i, step) < 1.0f)
505
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
506
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[0][1][i]))[j];
507
(*anisotropyPol)[j] += (*((CxFloatArray *)_polarizability[1][0][i]))[j];
508
(*anisotropyPol)[j] *= 0.5f;
510
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
511
for(j = 0; j < m_iDepth; j++) {
512
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
515
for(i = 0; i < m_iDepth; i++) {
516
(*anisotropyACFSum)[i] += 3.0f * _anisoACF->m_pData[i];
518
mprintf(WHITE, "]\n");
520
mprintf(" Fifth anisotropic part...\n");
521
mprintf(WHITE, " [");
522
for(i = 0; i < m_iDepth; i++) {
523
_anisoACF->m_pData[i] = 0.0f;
525
for(i = 0; i < m_iMolecules; i++) {
526
if(fmodf((float)i, step) < 1.0f)
528
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
529
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[1][2][i]))[j];
530
(*anisotropyPol)[j] += (*((CxFloatArray *)_polarizability[2][1][i]))[j];
531
(*anisotropyPol)[j] *= 0.5f;
533
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
534
for(j = 0; j < m_iDepth; j++) {
535
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
538
for(i = 0; i < m_iDepth; i++) {
539
(*anisotropyACFSum)[i] += 3.0f * _anisoACF->m_pData[i];
541
mprintf(WHITE, "]\n");
543
mprintf(" Sixth anisotropic part...\n");
544
mprintf(WHITE, " [");
545
for(i = 0; i < m_iDepth; i++) {
546
_anisoACF->m_pData[i] = 0.0f;
548
for(i = 0; i < m_iMolecules; i++) {
549
if(fmodf((float)i, step) < 1.0f)
551
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
552
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[2][0][i]))[j];
553
(*anisotropyPol)[j] += (*((CxFloatArray *)_polarizability[0][2][i]))[j];
554
(*anisotropyPol)[j] *= 0.5f;
556
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
557
for(j = 0; j < m_iDepth; j++) {
558
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
561
for(i = 0; i < m_iDepth; i++) {
562
(*anisotropyACFSum)[i] += 3.0f * _anisoACF->m_pData[i];
564
mprintf(WHITE, "]\n");
566
for(i = 0; i < m_iDepth; i++) {
568
_anisoACF->m_pData[i] = (*anisotropyACFSum)[i] / g_iSteps * g_stride;
570
_anisoACF->m_pData[i] = (*anisotropyACFSum)[i] / g_iSteps * g_stride / m_iMolecules;
573
// #ifdef TARGET_LINUX
574
// snprintf(filename, BUF_SIZE, "%s/acf_aniso_%s.dat", g_ramanDir, m_sName);
576
// sprintf(filename, "%s/acf_aniso_%s.dat", g_ramanDirm_sName);
578
// mprintf(" Saving ACF as %s...\n", filename);
579
// acf_file = OpenFileWrite(filename, false);
580
// for(i = 0; i < m_iDepth; i++)
581
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _anisoACF->m_pData[i]);
584
if(_anisoACF->m_iMirror != 0) {
585
mprintf(" Mirroring ACF...\n");
586
_anisoACF->Mirror(_anisoACF->m_iMirror);
588
if(_anisoACF->m_bWindowFunction != 0) {
589
mprintf(" Applying window function to ACF...\n");
593
// #ifdef TARGET_LINUX
594
// snprintf(filename, BUF_SIZE, "%s/acf_aniso_%s.mw.dat", g_ramanDir, m_sName);
596
// sprintf(filename, "%s/acf_aniso_%s.mw.dat", g_ramanDir, m_sName);
598
// mprintf(" Saving ACF as %s...\n", filename);
599
// acf_file = OpenFileWrite(filename, false);
600
// for(i = 0; i < _anisoACF->m_iSize; i++)
601
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _anisoACF->m_pData[i]);
604
mprintf(" Performing Fourier transformation...\n");
605
try { fft = new CFFT(); } catch(...) { fft = NULL; }
606
if(fft == NULL) NewException((double)sizeof(CFFT), __FILE__, __LINE__, __PRETTY_FUNCTION__);
607
fft->PrepareFFT_C2C(_anisoACF->m_iSize + _anisoACF->m_iZeroPadding);
608
_anisoACF->Transform(fft);
610
_anisoACF->m_pSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
612
// #ifdef TARGET_LINUX
613
// snprintf(filename, BUF_SIZE, "%s/spectrum_aniso_%s.dat", g_ramanDir, m_sName);
615
// sprintf(filename, "%s/spectrum_aniso_%s.dat", g_ramanDir, m_sName);
617
// mprintf(" Saving spectrum as %s...\n", filename);
618
// _anisoACF->m_pSpectrum->Write("", filename, "");
620
int specSize = _isoACF->m_pSpectrum->m_iSize;
621
CSpectrum *paraSpectrum, *orthoSpectrum, *sumSpectrum, *depolSpectrum;
622
try { paraSpectrum = new CSpectrum(); } catch(...) { paraSpectrum = NULL; }
623
if(paraSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
624
paraSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
625
paraSpectrum->Create(specSize);
626
paraSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
627
try { orthoSpectrum = new CSpectrum(); } catch(...) { orthoSpectrum = NULL; }
628
if(orthoSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
629
orthoSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
630
orthoSpectrum->Create(specSize);
631
orthoSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
632
try { sumSpectrum = new CSpectrum(); } catch(...) { sumSpectrum = NULL; }
633
if(sumSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
634
sumSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
635
sumSpectrum->Create(specSize);
636
sumSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
637
try { depolSpectrum = new CSpectrum(); } catch(...) { depolSpectrum = NULL; }
638
if(depolSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
639
depolSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
640
depolSpectrum->Create(specSize);
641
depolSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
643
for(i = 0; i < specSize; i++) {
644
paraSpectrum->m_pData[i] = _isoACF->m_pSpectrum->m_pData[i] + 4.0f / 45.0f * _anisoACF->m_pSpectrum->m_pData[i];
647
// #ifdef TARGET_LINUX
648
// snprintf(filename, BUF_SIZE, "%s/spectrum_para_%s.dat", g_ramanDir, m_sName);
650
// sprintf(filename, "%s/spectrum_para_%s.dat", g_ramanDir, m_sName);
652
// mprintf(" Saving para spectrum as %s...\n", filename);
653
// paraSpectrum->Write("", filename, "");
655
for(i = 0; i < specSize; i++) {
656
orthoSpectrum->m_pData[i] = _anisoACF->m_pSpectrum->m_pData[i] / 15.0f;
659
// #ifdef TARGET_LINUX
660
// snprintf(filename, BUF_SIZE, "%s/spectrum_ortho_%s.dat", g_ramanDir, m_sName);
662
// sprintf(filename, "%s/spectrum_ortho_%s.dat", g_ramanDir, m_sName);
664
// mprintf(" Saving ortho spectrum as %s...\n", filename);
665
// orthoSpectrum->Write("", filename, "");
667
for(i = 0; i < specSize; i++) {
668
sumSpectrum->m_pData[i] = paraSpectrum->m_pData[i] + orthoSpectrum->m_pData[i];
671
// #ifdef TARGET_LINUX
672
// snprintf(filename, BUF_SIZE, "%s/spectrum_unpol_%s.dat", g_ramanDir, m_sName);
674
// sprintf(filename, "%s/spectrum_unpol_%s.dat", g_ramanDir, m_sName);
676
// mprintf(" Saving unpolarized spectrum as %s...\n", filename);
677
// sumSpectrum->Write("", filename, "");
679
for(i = 0; i < specSize; i++) {
680
float freq = i * paraSpectrum->m_fMaxRWL / paraSpectrum->m_iSize;
681
float crossSecFactor = powf(g_laser - freq, 4) / freq / (1 - expf(-1.438777f * freq / g_temp));
682
paraSpectrum->m_pData[i] *= crossSecFactor;
683
orthoSpectrum->m_pData[i] *= crossSecFactor;
684
sumSpectrum->m_pData[i] *= crossSecFactor;
687
for(i = 0; i < specSize; i++) {
688
depolSpectrum->m_pData[i] = orthoSpectrum->m_pData[i] / paraSpectrum->m_pData[i];
692
snprintf(filename, BUF_SIZE, "%s/spectrum_para_%s.csv", g_ramanDir, m_sName);
694
sprintf(filename, "%s/spectrum_para_%s.csv", g_ramanDir, m_sName);
696
mprintf(" Saving parallel spectrum as %s...\n", filename);
697
paraSpectrum->Write("", filename, "");
700
snprintf(filename, BUF_SIZE, "%s/spectrum_ortho_%s.csv", g_ramanDir, m_sName);
702
sprintf(filename, "%s/spectrum_ortho_%s.csv", g_ramanDir, m_sName);
704
mprintf(" Saving orthogonal spectrum as %s...\n", filename);
705
orthoSpectrum->Write("", filename, "");
708
snprintf(filename, BUF_SIZE, "%s/spectrum_unpol_%s.csv", g_ramanDir, m_sName);
710
sprintf(filename, "%s/spectrum_unpol_%s.csv", g_ramanDir, m_sName);
712
mprintf(" Saving unpolarized spectrum as %s...\n", filename);
713
sumSpectrum->Write("", filename, "");
716
snprintf(filename, BUF_SIZE, "%s/depol_ratio_%s.csv", g_ramanDir, m_sName);
718
sprintf(filename, "%s/depol_ratio_%s.csv", g_ramanDir, m_sName);
720
mprintf(" Saving depolarization ratio as %s...\n", filename);
721
depolSpectrum->Write("", filename, "");
723
delete anisotropyACFSum;
724
delete anisotropyACF;
725
delete anisotropyPol;
728
delete orthoSpectrum;
730
delete depolSpectrum;
733
try { ACF = new CxFloatArray("CRamanDyn::finalize():ACF"); } catch(...) { ACF = NULL; }
734
if(ACF == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
735
ACF->SetSize(m_iDepth);
737
mprintf(" Parallel part...\n");
738
mprintf(WHITE, " [");
739
for(i = 0; i < m_iDepth; i++) {
740
_isoACF->m_pData[i] = 0.0f;
742
for(i = 0; i < m_iMolecules; i++) {
743
if(fmodf((float)i, step) < 1.0f)
745
autoCorrelation->AutoCorrelate((CxFloatArray *)_polarizability[0][0][i], ACF);
746
for(int j = 0; j < m_iDepth; j++) {
747
_isoACF->m_pData[j] += (*ACF)[j];
750
for(i = 0; i < m_iDepth; i++) {
752
_isoACF->m_pData[i] /= g_iSteps / g_stride;
754
_isoACF->m_pData[i] /= g_iSteps / g_stride * m_iMolecules;
756
mprintf(WHITE, "]\n");
758
// #ifdef TARGET_LINUX
759
// snprintf(filename, BUF_SIZE, "%s/acf_para_%s.dat", g_ramanDir, m_sName);
761
// sprintf(filename, "%s/acf_para_%s.dat", g_ramanDir, m_sName);
763
// mprintf(" Saving ACF as %s...\n", filename);
764
// FILE *acf_file = OpenFileWrite(filename, false);
765
// for(i = 0; i < m_iDepth; i++)
766
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _isoACF->m_pData[i]);
769
if(_isoACF->m_iMirror != 0) {
770
mprintf(" Mirroring ACF...\n");
771
_isoACF->Mirror(_isoACF->m_iMirror);
773
if(_isoACF->m_bWindowFunction != 0) {
774
mprintf(" Applying window function to ACF...\n");
778
// #ifdef TARGET_LINUX
779
// snprintf(filename, BUF_SIZE, "%s/acf_para_%s.mw.dat", g_ramanDir, m_sName);
781
// sprintf(filename, "%s/acf_para_%s.mw.dat", g_ramanDir, m_sName);
783
// mprintf(" Saving ACF as %s...\n", filename);
784
// acf_file = OpenFileWrite(filename, false);
785
// for(i = 0; i < _isoACF->m_iSize; i++)
786
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _isoACF->m_pData[i]);
789
mprintf(" Performing Fourier transformation...\n");
791
try { fft = new CFFT(); } catch(...) { fft = NULL; }
792
if(fft == NULL) NewException((double)sizeof(CFFT), __FILE__, __LINE__, __PRETTY_FUNCTION__);
793
fft->PrepareFFT_C2C(_isoACF->m_iSize + _isoACF->m_iZeroPadding);
794
_isoACF->Transform(fft);
796
_isoACF->m_pSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
798
// #ifdef TARGET_LINUX
799
// snprintf(filename, BUF_SIZE, "%s/spectrum_para_%s.dat", g_ramanDir, m_sName);
801
// sprintf(filename, "%s/spectrum_para_%s.dat", g_ramanDir, m_sName);
803
// mprintf(" Saving spectrum as %s...\n", filename);
804
// _isoACF->m_pSpectrum->Write("", filename, "");
806
mprintf(" Orthogonal part...\n");
807
mprintf(WHITE, " [");
808
for(i = 0; i < m_iDepth; i++) {
809
_anisoACF->m_pData[i] = 0.0f;
811
for(i = 0; i < m_iMolecules; i++) {
812
if(fmodf((float)i, step) < 1.0f)
814
autoCorrelation->AutoCorrelate((CxFloatArray *)_polarizability[1][0][i], ACF);
815
for(int j = 0; j < m_iDepth; j++) {
816
_anisoACF->m_pData[j] += (*ACF)[j];
819
for(i = 0; i < m_iDepth; i++) {
821
_anisoACF->m_pData[i] /= g_iSteps / g_stride;
823
_anisoACF->m_pData[i] /= g_iSteps / g_stride * m_iMolecules;
825
mprintf(WHITE, "]\n");
827
// #ifdef TARGET_LINUX
828
// snprintf(filename, BUF_SIZE, "%s/acf_ortho_%s.dat", g_ramanDir, m_sName);
830
// sprintf(filename, "%s/acf_ortho_%s.dat", g_ramanDir, m_sName);
832
// mprintf(" Saving ACF as %s...\n", filename);
833
// acf_file = OpenFileWrite(filename, false);
834
// for(i = 0; i < m_iDepth; i++)
835
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _anisoACF->m_pData[i]);
838
if(_anisoACF->m_iMirror != 0) {
839
mprintf(" Mirroring ACF...\n");
840
_anisoACF->Mirror(_isoACF->m_iMirror);
842
if(_anisoACF->m_bWindowFunction != 0) {
843
mprintf(" Applying window function to ACF...\n");
847
// #ifdef TARGET_LINUX
848
// snprintf(filename, BUF_SIZE, "%s/acf_ortho_%s.mw.dat", g_ramanDir, m_sName);
850
// sprintf(filename, "%s/acf_ortho_%s.mw.dat", g_ramanDir, m_sName);
852
// mprintf(" Saving ACF as %s...\n", filename);
853
// acf_file = OpenFileWrite(filename, false);
854
// for(i = 0; i < _isoACF->m_iSize; i++)
855
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _anisoACF->m_pData[i]);
858
mprintf(" Performing Fourier transformation...\n");
859
try { fft = new CFFT(); } catch(...) { fft = NULL; }
860
if(fft == NULL) NewException((double)sizeof(CFFT), __FILE__, __LINE__, __PRETTY_FUNCTION__);
861
fft->PrepareFFT_C2C(_anisoACF->m_iSize + _anisoACF->m_iZeroPadding);
862
_anisoACF->Transform(fft);
864
_anisoACF->m_pSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
866
// #ifdef TARGET_LINUX
867
// snprintf(filename, BUF_SIZE, "%s/spectrum_ortho_%s.dat", g_ramanDir, m_sName);
869
// sprintf(filename, "%s/spectrum_ortho_%s.dat", g_ramanDir, m_sName);
871
// mprintf(" Saving spectrum as %s...\n", filename);
872
// _anisoACF->m_pSpectrum->Write("", filename, "");
876
int specSize = _isoACF->m_pSpectrum->m_iSize;
877
CSpectrum *sumSpectrum, *depolSpectrum;
878
try { sumSpectrum = new CSpectrum(); } catch(...) { sumSpectrum = NULL; }
879
if(sumSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
880
sumSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
881
sumSpectrum->Create(specSize);
882
sumSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
883
try { depolSpectrum = new CSpectrum(); } catch(...) { depolSpectrum = NULL; }
884
if(depolSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
885
depolSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
886
depolSpectrum->Create(specSize);
887
depolSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
889
for(i = 0; i < specSize; i++) {
890
sumSpectrum->m_pData[i] = _isoACF->m_pSpectrum->m_pData[i] + _anisoACF->m_pSpectrum->m_pData[i];
893
// #ifdef TARGET_LINUX
894
// snprintf(filename, BUF_SIZE, "%s/spectrum_unpol_%s.dat", g_ramanDir, m_sName);
896
// sprintf(filename, "%s/spectrum_unpol_%s.dat", g_ramanDir, m_sName);
898
// mprintf(" Saving unpolarized spectrum as %s...\n", filename);
899
// sumSpectrum->Write("", filename, "");
901
for(i = 0; i < specSize; i++) {
902
float freq = i * _isoACF->m_pSpectrum->m_fMaxRWL / _isoACF->m_pSpectrum->m_iSize;
903
float crossSecFactor = powf(g_laser - freq, 4) / freq / (1 - expf(-1.438777f * freq / g_temp));
904
_isoACF->m_pSpectrum->m_pData[i] *= crossSecFactor;
905
_anisoACF->m_pSpectrum->m_pData[i] *= crossSecFactor;
906
sumSpectrum->m_pData[i] *= crossSecFactor;
909
for(i = 0; i < specSize; i++) {
910
depolSpectrum->m_pData[i] = _anisoACF->m_pSpectrum->m_pData[i] / _isoACF->m_pSpectrum->m_pData[i];
914
snprintf(filename, BUF_SIZE, "%s/spectrum_para_%s.csv", g_ramanDir, m_sName);
916
sprintf(filename, "%s/spectrum_para_%s.csv", g_ramanDir, m_sName);
918
mprintf(" Saving parallel spectrum as %s...\n", filename);
919
_isoACF->m_pSpectrum->Write("", filename, "");
922
snprintf(filename, BUF_SIZE, "%s/spectrum_ortho_%s.csv", g_ramanDir, m_sName);
924
sprintf(filename, "%s/spectrum_ortho_%s.csv", g_ramanDir, m_sName);
926
mprintf(" Saving orthogonal spectrum as %s...\n", filename);
927
_anisoACF->m_pSpectrum->Write("", filename, "");
930
snprintf(filename, BUF_SIZE, "%s/spectrum_unpol_%s.csv", g_ramanDir, m_sName);
932
sprintf(filename, "%s/spectrum_unpol_%s.csv", g_ramanDir, m_sName);
934
mprintf(" Saving unpolarized spectrum as %s...\n", filename);
935
sumSpectrum->Write("", filename, "");
938
snprintf(filename, BUF_SIZE, "%s/depol_ratio_%s.csv", g_ramanDir, m_sName);
940
sprintf(filename, "%s/depol_ratio_%s.csv", g_ramanDir, m_sName);
942
mprintf(" Saving depolarization ratio as %s...\n", filename);
943
depolSpectrum->Write("", filename, "");
946
delete depolSpectrum;
949
delete autoCorrelation;
952
CRamanObservation::CRamanObservation(bool global) {
962
m_iShowMolCount = g_oaSingleMolecules.GetSize();
963
m_bObsCertain = false;
964
m_bDecompDist = false;
965
m_bDecompType = false;
969
size_t remaining = BUF_SIZE;
970
if(g_oaMolecules.GetSize() > 1) {
972
remaining -= snprintf(buf, remaining, " Which molecule should be observed (");
974
remaining -= sprintf(buf, " Which molecule should be observed (");
976
for(i = 0; i < g_oaMolecules.GetSize(); i++) {
980
size_t length = snprintf(buf2, remaining, "%s=%d", ((CMolecule *)g_oaMolecules[i])->m_sName, i+1);
982
size_t length = sprintf(buf2, "%s=%d", ((CMolecule *)g_oaMolecules[i])->m_sName, i+1);
984
strncat(buf, buf2, remaining - 1);
986
if(i < g_oaMolecules.GetSize() - 1) {
988
length = snprintf(buf2, remaining, ", ");
990
length = sprintf(buf2, ", ");
992
strncat(buf, buf2, remaining - 1);
996
strncat(buf, ")? ", remaining - 1);
997
m_iShowMol = AskRangeInteger_ND(buf, 1, g_oaMolecules.GetSize()) - 1;
1001
m_iShowMolCount = ((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize();
1002
m_bObsCertain = false;
1003
m_bDecompDist = false;
1004
m_bDecompType = false;
1008
try { _ramanDyn = new CRamanDyn(m_iShowMol, global); } catch(...) { _ramanDyn = NULL; }
1009
if(_ramanDyn == NULL) NewException((double)sizeof(CRamanDyn), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1012
CRamanObservation::~CRamanObservation() {
1016
void CRamanObservation::initialize() {
1017
_ramanDyn->initialize();
1020
void CRamanObservation::getDipole0() {
1021
_ramanDyn->getDipole0();
1024
void CRamanObservation::calcPolarizability(int fieldDirection) {
1025
_ramanDyn->calcPolarizability(fieldDirection);
1028
void CRamanObservation::finalize() {
1029
_ramanDyn->finalize();
1032
static bool parseSettings(FILE *settingsFile) {
1035
if(fgets(buf, BUF_SIZE, settingsFile) == NULL)
1038
if(sscanf(buf, "%d", &temp) < 1)
1041
g_orientAvg = false;
1047
if(fgets(buf, BUF_SIZE, settingsFile) == NULL)
1049
if(sscanf(buf, "%f", &g_fieldStrength) < 1)
1052
if(fgets(buf, BUF_SIZE, settingsFile) == NULL)
1054
if(sscanf(buf, "%d", &g_stride) < 1)
1060
bool gatherRaman() {
1061
#ifndef TARGET_LINUX
1062
mprintf(RED, "Raman calculations are currently possible only under Linux.\n");
1065
mprintf(" To calculate Raman spectra, polarizabilities have to be determined.\n");
1066
mprintf(" TRAVIS creates CP2K input files for numerical polarizabilities\n and will process the resulting data in a second run.\n\n");
1068
g_newRaman = AskYesNo(" Do you wish to create new CP2K input files (y) or process existing results (n)? [y] ", true);
1071
AskString(" Please enter a name for the directory to collect the data: [raman] ", buf, "raman");
1073
AskString(" Please enter the name of the directory to take the data from: [raman] ", buf, "raman");
1075
try { g_ramanDir = new char[strlen(buf)+1]; } catch(...) { g_ramanDir = NULL; }
1076
if(g_ramanDir == NULL) NewException((double)(strlen(buf)+1)*sizeof(char), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1077
strcpy(g_ramanDir, buf);
1080
g_bKeepOriginalCoords = true;
1081
if(FileExist(g_ramanDir)) {
1082
mprintf(RED, "A file or a directory \"%s\" already exists. Please remove it first.\n", g_ramanDir);
1085
if(mkdir(g_ramanDir, S_IRWXU) != 0) {
1086
mprintf(RED, "Directory \"%s\" could not be created: %s\n", g_ramanDir, strerror(errno));
1090
char filename[BUF_SIZE];
1091
snprintf(filename, BUF_SIZE, "%s/settings.dat", g_ramanDir);
1092
FILE *settingsFile = fopen(filename, "w");
1093
if(settingsFile == NULL) {
1094
mprintf(RED, "Could not open settings file \"%s\": %s\n", filename, strerror(errno));
1098
g_orientAvg = AskYesNo("\n Use orientational averaging? [no] ", false);
1100
fprintf(settingsFile, "%d\n", 1);
1102
fprintf(settingsFile, "%d\n", 0);
1104
g_fieldStrength = AskFloat(" Field strength in atomic units [5.0e-4] ", 5.0e-4);
1105
fprintf(settingsFile, "%.6E\n", g_fieldStrength);
1107
g_stride = AskInteger(" Calculate polarizability for every n-th timestep [1] ", 1);
1108
fprintf(settingsFile, "%d\n", g_stride);
1110
fclose(settingsFile);
1112
snprintf(filename, BUF_SIZE, "%s/1", g_ramanDir);
1113
if(mkdir(filename, S_IRWXU) != 0) {
1114
mprintf(RED, "Directory \"%s\" could not be created: %s\n", filename, strerror(errno));
1118
snprintf(filename, BUF_SIZE, "%s/2", g_ramanDir);
1119
if(mkdir(filename, S_IRWXU) != 0) {
1120
mprintf(RED, "Directory \"%s\" could not be created: %s\n", filename, strerror(errno));
1123
snprintf(filename, BUF_SIZE, "%s/3", g_ramanDir);
1124
if(mkdir(filename, S_IRWXU) != 0) {
1125
mprintf(RED, "Directory \"%s\" could not be created: %s\n", filename, strerror(errno));
1131
snprintf(filename, BUF_SIZE, "%s/template.inp", g_ramanDir);
1132
templateFile = fopen(filename, "w");
1133
if(templateFile == NULL) {
1134
mprintf(RED, "Could not open template file \"%s\": %s\n", filename, strerror(errno));
1137
fprintf(templateFile, "&GLOBAL\n");
1138
fprintf(templateFile, " PROJECT_NAME polarizability\n");
1139
fprintf(templateFile, " RUN_TYPE MD\n");
1140
fprintf(templateFile, " PRINT_LEVEL LOW\n");
1141
fprintf(templateFile, "&END\n");
1142
fprintf(templateFile, "&FORCE_EVAL\n");
1143
fprintf(templateFile, " &DFT\n");
1144
fprintf(templateFile, " BASIS_SET_FILE_NAME BASIS_MOLOPT\n");
1145
fprintf(templateFile, " POTENTIAL_FILE_NAME POTENTIAL\n");
1146
fprintf(templateFile, " &MGRID\n");
1147
fprintf(templateFile, " NGRIDS 5\n");
1148
fprintf(templateFile, " CUTOFF 280\n");
1149
fprintf(templateFile, " REL_CUTOFF 40\n");
1150
fprintf(templateFile, " &END\n");
1151
fprintf(templateFile, " &SCF\n");
1152
fprintf(templateFile, " SCF_GUESS ATOMIC\n");
1153
fprintf(templateFile, " MAX_SCF 200\n");
1154
fprintf(templateFile, " EPS_SCF 1.0E-5\n");
1155
fprintf(templateFile, " &OT\n");
1156
fprintf(templateFile, " MINIMIZER DIIS\n");
1157
fprintf(templateFile, " PRECONDITIONER FULL_SINGLE_INVERSE\n");
1158
fprintf(templateFile, " &END\n");
1159
fprintf(templateFile, " &END\n");
1160
fprintf(templateFile, " &XC\n");
1161
fprintf(templateFile, " &XC_FUNCTIONAL BLYP\n");
1162
fprintf(templateFile, " &END\n");
1163
fprintf(templateFile, " &XC_GRID\n");
1164
fprintf(templateFile, " XC_SMOOTH_RHO NN10\n");
1165
fprintf(templateFile, " XC_DERIV NN10_SMOOTH\n");
1166
fprintf(templateFile, " &END\n");
1167
fprintf(templateFile, " &VDW_POTENTIAL\n");
1168
fprintf(templateFile, " POTENTIAL_TYPE PAIR_POTENTIAL\n");
1169
fprintf(templateFile, " &PAIR_POTENTIAL\n");
1170
fprintf(templateFile, " TYPE DFTD3\n");
1171
fprintf(templateFile, " REFERENCE_FUNCTIONAL BLYP\n");
1172
fprintf(templateFile, " PARAMETER_FILE_NAME dftd3.dat\n");
1173
fprintf(templateFile, " &END\n");
1174
fprintf(templateFile, " &END\n");
1175
fprintf(templateFile, " &END\n");
1176
fprintf(templateFile, " &LOCALIZE\n");
1177
fprintf(templateFile, " METHOD CRAZY\n");
1178
fprintf(templateFile, " MAX_ITER 2000\n");
1179
fprintf(templateFile, " &PRINT\n");
1180
fprintf(templateFile, " &WANNIER_CENTERS\n");
1181
fprintf(templateFile, " IONS+CENTERS\n");
1182
fprintf(templateFile, " FILENAME =polarizability_wannier.xyz\n");
1183
fprintf(templateFile, " &END\n");
1184
fprintf(templateFile, " &END\n");
1185
fprintf(templateFile, " &END\n");
1186
fprintf(templateFile, " &PERIODIC_EFIELD\n");
1187
fprintf(templateFile, " INTENSITY ###!field strength will be put here###\n");
1188
fprintf(templateFile, " POLARISATION ###!polarisation vector will be put here###\n");
1189
fprintf(templateFile, " &END\n");
1190
fprintf(templateFile, " &END\n");
1191
fprintf(templateFile, " &SUBSYS\n");
1192
fprintf(templateFile, " &CELL\n");
1193
fprintf(templateFile, " ABC %.6f %.6f %.6f\n", g_fBoxX / 100.0f, g_fBoxY / 100.0f, g_fBoxZ / 100.0f);
1194
fprintf(templateFile, " &END\n");
1195
fprintf(templateFile, " &COORD\n");
1196
fprintf(templateFile, "###!coordinates will be put here###\n");
1197
fprintf(templateFile, " &END\n");
1198
fprintf(templateFile, " &KIND H\n");
1199
fprintf(templateFile, " BASIS_SET DZVP-MOLOPT-SR-GTH\n");
1200
fprintf(templateFile, " POTENTIAL GTH-BLYP-q1\n");
1201
fprintf(templateFile, " &END\n");
1202
fprintf(templateFile, " &KIND C\n");
1203
fprintf(templateFile, " BASIS_SET DZVP-MOLOPT-SR-GTH\n");
1204
fprintf(templateFile, " POTENTIAL GTH-BLYP-q4\n");
1205
fprintf(templateFile, " &END\n");
1206
fprintf(templateFile, " &KIND N\n");
1207
fprintf(templateFile, " BASIS_SET DZVP-MOLOPT-SR-GTH\n");
1208
fprintf(templateFile, " POTENTIAL GTH-BLYP-q5\n");
1209
fprintf(templateFile, " &END\n");
1210
fprintf(templateFile, " &KIND O\n");
1211
fprintf(templateFile, " BASIS_SET DZVP-MOLOPT-SR-GTH\n");
1212
fprintf(templateFile, " POTENTIAL GTH-BLYP-q6\n");
1213
fprintf(templateFile, " &END\n");
1214
fprintf(templateFile, " &END\n");
1215
fprintf(templateFile, "&END\n");
1216
fprintf(templateFile, "&MOTION\n");
1217
fprintf(templateFile, " &MD\n");
1218
fprintf(templateFile, " ENSEMBLE REFTRAJ\n");
1219
fprintf(templateFile, " STEPS ###!number of steps will be put here###\n");
1220
fprintf(templateFile, " TIMESTEP %f\n", g_fTimestepLength * g_stride);
1221
fprintf(templateFile, " &REFTRAJ\n");
1222
fprintf(templateFile, " EVAL_ENERGY_FORCES\n");
1223
fprintf(templateFile, " TRAJ_FILE_NAME ../polarizability_reftraj.xyz\n");
1224
fprintf(templateFile, " &END\n");
1225
fprintf(templateFile, " &END\n");
1226
fprintf(templateFile, " &PRINT\n");
1227
fprintf(templateFile, " &RESTART\n");
1228
fprintf(templateFile, " &EACH\n");
1229
fprintf(templateFile, " MD 1\n");
1230
fprintf(templateFile, " &END\n");
1231
fprintf(templateFile, " &END\n");
1232
fprintf(templateFile, " &END\n");
1233
fprintf(templateFile, "&END\n");
1234
fclose(templateFile);
1236
mprintf("\n An input template for the polarizability calculations has been written to \"%s/template.inp\"\n Please modify it according to your needs.\n Press any key when you are finished.\n", g_ramanDir);
1240
mprintf(" CP2K input files will be created in \"%s/1\", \"%s/2\", and \"%s/3\".\n", g_ramanDir, g_ramanDir, g_ramanDir);
1241
mprintf(" After TRAVIS has finished, please run them and make sure that the resulting trajectories \"polarizability_wannier.xyz\"\n are placed in the same directories before you execute TRAVIS for evaluation.\n\n");
1243
mprintf(" A CP2K input file will be created in \"%s/1\".\n", g_ramanDir);
1244
mprintf(" After TRAVIS has finished, please run it and make sure that the resulting trajectory \"polarizability_wannier.xyz\"\n is placed in the same directory before you run TRAVIS for evaluation.\n\n");
1247
if(!FileExist(g_ramanDir)) {
1248
mprintf(RED, "The directory \"%s\" was not found.\n", g_ramanDir);
1252
char filename[BUF_SIZE];
1253
snprintf(filename, BUF_SIZE, "%s/settings.dat", g_ramanDir);
1255
settingsFile = fopen(filename, "r");
1256
if(settingsFile == NULL) {
1257
mprintf(RED, "Could not open settings file \"%s\": %s\n", filename, strerror(errno));
1260
if(!parseSettings(settingsFile)) {
1261
mprintf(RED, "Could not parse settings file.\n");
1267
mprintf(" Using orientational averaging\n");
1269
mprintf(" Not using orientational averaging\n");
1270
mprintf(" Field strength: %.6e a. u.\n", g_fieldStrength);
1271
mprintf(" Using every %d%s timestep\n\n", g_stride, (g_stride == 1) ? "st" : ((g_stride == 2) ? "nd" : ((g_stride == 3) ? "rd" : "th")));
1273
g_laser = AskFloat(" Calculate scattering cross section for which laser frequency (cm^-1)? [20000.0] ", 20000.0f);
1274
g_temp = AskFloat(" Calculate scattering cross section for which temperature (K)? [300.0] ", 300.0f);
1276
if(AskYesNo(" Compute Raman spectrum of whole system (y/n)? [yes] ", true)) {
1277
mprintf(YELLOW, "\n>>> Global Raman Observation >>>\n\n");
1279
CRamanObservation *obs;
1280
try { obs = new CRamanObservation(true); } catch(...) { obs = NULL; }
1281
if(obs == NULL) NewException((double)sizeof(CRamanObservation), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1282
g_ramObserv.Add(obs);
1284
mprintf(YELLOW, "<<< End of Global Raman Observation <<<\n\n");
1287
if(AskYesNo(" Compute Raman spectra for certain molecule types (y/n)? [no] ", false)) {
1289
mprintf(YELLOW, "\n>>> Raman Observation %d >>>\n\n", g_ramObserv.GetSize() + 1);
1291
CRamanObservation *obs;
1292
try { obs = new CRamanObservation(); } catch(...) { obs = NULL; }
1293
if(obs == NULL) NewException((double)sizeof(CRamanObservation), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1294
g_ramObserv.Add(obs);
1296
mprintf(YELLOW, "<<< End of Raman Observation %d <<<\n\n", g_ramObserv.GetSize());
1298
if(!AskYesNo(" Add another observation (y/n)? [no] ", false))
1310
bool initializeRaman() {
1314
char filename[BUF_SIZE];
1316
snprintf(filename, BUF_SIZE, "%s/template.inp", g_ramanDir);
1318
sprintf(filename, "%s/template.inp", g_ramanDir);
1321
templateFile = fopen(filename, "r");
1322
if(templateFile == NULL) {
1323
mprintf(RED, "Could not open template file \"%s\": %s\n", filename, strerror(errno));
1326
fseek(templateFile, 0L, SEEK_END);
1327
long length = ftell(templateFile);
1329
mprintf(RED, "Could not determine size of template file: %s\n", strerror(errno));
1333
try { g_inputTemplate = new char[length + 1]; } catch(...) { g_inputTemplate = NULL; }
1334
if(g_inputTemplate == NULL) NewException((double)(length + 1)*sizeof(char), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1336
rewind(templateFile);
1337
if((long)fread(g_inputTemplate, sizeof(char), length, templateFile) < length) {
1338
mprintf(RED, "Could not read template file: %s\n", strerror(errno));
1341
g_inputTemplate[length] = '\0';
1343
fclose(templateFile);
1345
g_templateFieldPos = strstr(g_inputTemplate, "###!field strength will be put here###");
1346
if(g_templateFieldPos == NULL) {
1347
mprintf(RED, "Position mark for field strength missing in template.\n");
1350
g_templatePolPos = strstr(g_inputTemplate, "###!polarisation vector will be put here###");
1351
if(g_templatePolPos == NULL) {
1352
mprintf(RED, "Position mark for polarisation vector missing in template.\n");
1355
g_templateCoordPos = strstr(g_inputTemplate, "###!coordinates will be put here###");
1356
if(g_templateCoordPos == NULL) {
1357
mprintf(RED, "Position mark for coordinates missing in template.\n");
1360
g_templateStepsPos = strstr(g_inputTemplate, "###!number of steps will be put here###");
1361
if(g_templateStepsPos == NULL) {
1362
mprintf(RED, "Position mark for number of steps missing in template.\n");
1365
g_templateFieldPos[0] = '\0';
1366
g_templatePolPos[0] = '\0';
1367
g_templateCoordPos[0] = '\0';
1368
g_templateStepsPos[0] = '\0';
1371
snprintf(filename, BUF_SIZE, "%s/polarizability_reftraj.xyz", g_ramanDir);
1373
sprintf(filename, "%s/polarizability_reftraj.xyz", g_ramanDir);
1375
g_reftrajFile = fopen(filename, "w");
1376
if(g_reftrajFile == NULL) {
1377
mprintf(RED, "Could not open reference trajectory \"%s\": %s\n", filename, strerror(errno));
1381
for(i = 0; i < g_ramObserv.GetSize(); i++) {
1382
mprintf("Initializing Raman Observation %d...\n", i+1);
1383
CRamanObservation *obs = (CRamanObservation *)g_ramObserv[i];
1387
char filename[BUF_SIZE];
1388
for(i = 0; i < (g_orientAvg ? 3 : 1); i++) {
1390
snprintf(filename, BUF_SIZE, "%s/%d/polarizability_wannier.xyz", g_ramanDir, i + 1);
1392
sprintf(filename, "%s/%d/polarizability_wannier.xyz", g_ramanDir, i + 1);
1394
g_polFile[i] = fopen(filename, "r");
1395
if(g_polFile[i] == NULL) {
1396
mprintf(RED, "Could not open trajectory \"%s\": %s\n", filename, strerror(errno));
1401
for(i = 0; i < (g_orientAvg ? 3 : 1); i++) {
1402
try { g_timestep[i] = new CTimeStep(); } catch(...) { g_timestep[i] = NULL; }
1403
if(g_timestep[i] == NULL) NewException((double)sizeof(CTimeStep), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1410
void processRaman(CTimeStep *ts) {
1414
if(g_step % g_stride == 0) {
1417
for(i = 0; i < g_iGesAtomCount; i++)
1418
if(g_waAtomMolIndex[i] != 60000)
1420
fprintf(g_reftrajFile, "%d\nStep %d\n", numAtoms, g_step);
1421
for(i = 0; i < g_iGesAtomCount; i++) {
1422
if(g_waAtomMolIndex[i] == 60000)
1424
fprintf(g_reftrajFile, "%4s %14.10f %14.10f %14.10f\n", ((CAtom *)g_oaAtoms[g_waAtomRealElement[i]])->m_sName, ts->m_vaCoords_Original[i][0] / 100.0f, ts->m_vaCoords_Original[i][1] / 100.0f, ts->m_vaCoords_Original[i][2] / 100.0f);
1428
if(g_step % g_stride == 0) {
1429
for(i = 0; i < g_ramObserv.GetSize(); i++)
1430
((CRamanObservation *)g_ramObserv[i])->getDipole0();
1431
for(i = 0; i < (g_orientAvg ? 3 : 1); i++) {
1432
if(!g_timestep[i]->ReadTimestep(g_polFile[i], false)) {
1433
mprintf(RED, "Error while reading trajectory for polarizabilities.\n");
1436
if(!g_bSaveCoordsUnchanged) {
1437
g_timestep[i]->UniteMolecules(false);
1439
g_timestep[i]->CenterCOM();
1441
g_timestep[i]->CalcCenters();
1443
g_timestep[i]->ScanWannier(false);
1444
g_timestep[i]->CalcDipoles();
1445
for(j = 0; j < g_ramObserv.GetSize(); j++) {
1446
((CRamanObservation *)g_ramObserv[j])->calcPolarizability(i);
1453
void finalizeRaman() {
1456
fclose(g_reftrajFile);
1458
char filename[BUF_SIZE];
1460
for(i = 1; i < (g_orientAvg ? 4 : 2); i++) {
1462
snprintf(filename, BUF_SIZE, "%s/%d/polarizability.inp", g_ramanDir, i);
1464
sprintf(filename, "%s/%d/polarizability.inp", g_ramanDir, i);
1466
inputFile = fopen(filename, "w");
1467
if(inputFile == NULL) {
1468
mprintf(RED, "Could not open input file \"%s\": %s\n", filename, strerror(errno));
1472
fprintf(inputFile, "%s", g_inputTemplate);
1473
for(j = 0; j < 4; j++) {
1474
char *tempPos = g_inputTemplate;
1475
for(k = 0; k <= j; k++)
1476
tempPos = strchr(&tempPos[1], '\0');
1477
if(tempPos == g_templateFieldPos) {
1478
fprintf(inputFile, "%.6E", g_fieldStrength);
1479
fprintf(inputFile, "%s", &g_templateFieldPos[38]);
1480
} else if(tempPos == g_templatePolPos) {
1482
fprintf(inputFile, "1.0 0.0 0.0");
1484
fprintf(inputFile, "0.0 1.0 0.0");
1486
fprintf(inputFile, "0.0 0.0 1.0");
1487
fprintf(inputFile, "%s", &g_templatePolPos[43]);
1488
} else if(tempPos == g_templateCoordPos) {
1489
CTimeStep *ts = GetTimeStep(0);
1490
for(l = 0; l < g_iGesAtomCount; l++) {
1491
if(g_waAtomMolIndex[l] == 60000)
1493
fprintf(inputFile, " %s %14.10f %14.10f %14.10f\n", ((CAtom *)g_oaAtoms[g_waAtomRealElement[l]])->m_sName, ts->m_vaCoords_Original[l][0] / 100.0f, ts->m_vaCoords_Original[l][1] / 100.0f, ts->m_vaCoords_Original[l][2] / 100.0f);
1495
fprintf(inputFile, "%s", &g_templateCoordPos[36]);
1496
} else if(tempPos == g_templateStepsPos) {
1497
fprintf(inputFile, "%d", g_steps);
1498
fprintf(inputFile, "%s", &g_templateStepsPos[39]);
1500
mprintf(RED, "Unexpected error while processing the input template.\n");
1505
delete[] g_inputTemplate;
1507
for(i = 0; i < g_ramObserv.GetSize(); i++) {
1508
mprintf(YELLOW, ">>> Raman Observation %d >>>\n\n", i + 1);
1509
((CRamanObservation *)g_ramObserv[i])->finalize();
1510
mprintf(YELLOW, "\n<<< End of Raman Observation %d <<<\n\n", i + 1);
1513
for(i = 0; i < (g_orientAvg ? 3 : 1); i++)
1514
fclose(g_polFile[i]);
1515
for(i = 0; i < (g_orientAvg ? 3 : 1); i++)
1516
delete g_timestep[i];
1518
delete[] g_ramanDir;
1
/*****************************************************************************
2
TRAVIS - Trajectory Analyzer and Visualizer
3
http://www.travis-analyzer.de/
5
Copyright (c) 2009-2014 Martin Brehm
6
2012-2014 Martin Thomas
8
This file written by Martin Thomas.
10
This program is free software: you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*****************************************************************************/
28
#include "globalvar.h"
29
#include "maintools.h"
33
#include "xfloatarray.h"
42
#include <sys/types.h>
47
static bool g_newRaman;
48
static char *g_ramanDir;
49
static bool g_orientAvg;
50
static float g_fieldStrength;
51
static int g_step = 0;
55
static char *g_inputTemplate;
56
static char *g_templateFieldPos;
57
static char *g_templatePolPos;
58
static char *g_templateCoordPos;
59
static char *g_templateStepsPos;
61
static CxObArray g_ramObserv;
63
static FILE *g_polFile[3];
64
static CTimeStep *g_timestep[3];
66
static FILE *g_reftrajFile;
67
static int g_steps = 0;
69
CRamanDyn::CRamanDyn(int showMol, bool global) {
73
m_iMolecules = g_oaSingleMolecules.GetSize();
76
m_iMolecules = ((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize();
79
/*** Set Names of dynamic arrays. By M. Brehm */
80
_dipole0.SetName("CRamanDyn::_dipole0");
82
for (int tz1=0;tz1<3;tz1++)
84
for (int tz2=0;tz2<3;tz2++)
86
sprintf(tbuf,"CRamanDyn::_polarizability[%d][%d]",tz1,tz2);
87
_polarizability[tz1][tz2].SetName(tbuf);
90
/* End of set names */
92
mprintf(YELLOW, ">>> Raman Spectrum >>>\n\n");
95
mprintf(" All atoms will be taken.\n\n");
97
mprintf(" All atoms will be taken from the OM %s.\n\n", ((CMolecule *)g_oaMolecules[m_iShowMol])->m_sName);
104
if(g_iTrajSteps != -1) {
105
int depth = (int)(g_iTrajSteps / g_stride * 0.75);
108
m_iDepth = AskUnsignedInteger(" Enter the resolution (=depth) of the ACF (in time steps): [%d] ", depth, depth);
110
m_iDepth = AskUnsignedInteger(" Enter the resolution (=depth) of the ACF (in time steps): [2000] ", 2000);
113
int size = CalcFFTSize(m_iDepth, false);
114
if(m_iDepth != size) {
115
mprintf(WHITE," The next \"fast\" size for FFT is %d. Using this instead of %d as depth.\n", size, m_iDepth);
122
_derivativeOrder = 1;
126
derive = AskYesNo(" Derive the vectors before autocorrelation (y/n)? [yes] ", true);
128
_derivativeOrder = AskRangeInteger(" Please enter degree of vector derivative (1-2): [1] ", 1, 2, 1);
129
window = AskYesNo(" Apply window function (Cos^2) to autocorrelation function (y/n)? [yes] ", true);
131
float possibleRange = 33356.41f / g_fTimestepLength / 2.0f / g_stride;
132
mprintf(" A time step length of %.2f fs with a stride of %d allows a spectral range up to %.2f cm^-1.\n", g_fTimestepLength, g_stride, possibleRange);
133
float specWaveNumber = AskRangeFloat("\n Calculate spectrum up to which wave number (cm^-1)? [%.2f cm^-1] ", 0, possibleRange, (possibleRange < 5000.0f) ? possibleRange : 5000.0f, (possibleRange < 5000.0f) ? possibleRange : 5000.0f);
135
int zeroPadding = m_iDepth * 3;
137
mirror = AskRangeInteger(" No mirroring (0) or short-time enhancing (1)? [1] ", 0, 1, 1);
138
zeroPadding = AskUnsignedInteger(" Zero Padding: How many zeros to insert? [%d] ", m_iDepth * 3, m_iDepth * 3);
141
size = CalcFFTSize(m_iDepth + zeroPadding, false);
142
if(m_iDepth + zeroPadding != size) {
143
mprintf(WHITE, " The next \"fast\" size for FFT is %d. Using %d zeros for zero padding.\n", size, size-m_iDepth);
144
zeroPadding = size-m_iDepth;
147
mprintf(" This results in a spectral resolution to %.2f cm^-1.\n\n", 33356.41 / g_fTimestepLength / 2.0f / size);
149
try { _isoACF = new CACF(); } catch(...) { _isoACF = NULL; }
150
if(_isoACF == NULL) NewException((double)sizeof(CACF), __FILE__, __LINE__, __PRETTY_FUNCTION__);
151
_isoACF->m_iSize = m_iDepth;
152
_isoACF->m_bSpectrum = true;
153
_isoACF->m_bDerivative = derive;
154
_isoACF->m_iDerivative = _derivativeOrder;
155
_isoACF->m_bWindowFunction = window;
156
_isoACF->m_fSpecWaveNumber = specWaveNumber;
157
_isoACF->m_iMirror = mirror;
158
_isoACF->m_iZeroPadding = zeroPadding;
159
_isoACF->m_bACF_DB = false;
161
try { _anisoACF = new CACF(); } catch(...) { _anisoACF = NULL; }
162
if(_anisoACF == NULL) NewException((double)sizeof(CACF), __FILE__, __LINE__, __PRETTY_FUNCTION__);
163
_anisoACF->m_iSize = m_iDepth;
164
_anisoACF->m_bSpectrum = true;
165
_anisoACF->m_bDerivative = derive;
166
_anisoACF->m_iDerivative = _derivativeOrder;
167
_anisoACF->m_bWindowFunction = window;
168
_anisoACF->m_fSpecWaveNumber = specWaveNumber;
169
_anisoACF->m_iMirror = mirror;
170
_anisoACF->m_iZeroPadding = zeroPadding;
171
_anisoACF->m_bACF_DB = false;
175
mprintf(YELLOW, "<<< End of Raman Spectrum <<<\n\n");
178
CRamanDyn::~CRamanDyn() {
181
for(i = 0; i < m_iMolecules; i++)
182
delete (CxFloatArray *)_dipole0[i];
183
for(i = 0; i < m_iMolecules; i++) {
184
for(j = 0; j < 3; j++) {
185
for(k = 0; k < (g_orientAvg ? 3 : 1); k++) {
186
delete (CxFloatArray *)_polarizability[j][k][i];
194
void CRamanDyn::initialize() {
200
if (g_iTrajSteps != -1)
201
mprintf(" Raman Cache: Trying to allocate %s of memory...\n", FormatBytes((double)m_iMolecules * g_iTrajSteps / g_iStride / g_stride * (g_orientAvg ? 9.9 : 3.3) * sizeof(float)));
203
mprintf(" Raman Cache: Trying to allocate %s of memory...\n", FormatBytes((double)m_iMolecules * 2000 / g_iStride /g_stride * (g_orientAvg ? 9.9 : 3.3) * sizeof(float)));
204
for(i = 0; i < m_iMolecules; i++) {
205
CxVector3 *dipoleVector;
206
try { dipoleVector = new CxVector3(); } catch(...) { dipoleVector = NULL; }
207
if(dipoleVector == NULL) NewException((double)sizeof(CxVector3), __FILE__, __LINE__, __PRETTY_FUNCTION__);
208
_dipole0.Add(dipoleVector);
210
for(i = 0; i < m_iMolecules; i++) {
211
for(j = 0; j < 3; j++) {
212
for(k = 0; k < (g_orientAvg ? 3 : 1); k++) {
213
CxFloatArray *floatArray;
214
try { floatArray = new CxFloatArray("CRamanDyn::initialize():floatArray"); } catch(...) { floatArray = NULL; }
215
if(floatArray == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
216
if(g_iTrajSteps != -1) {
217
floatArray->SetMaxSize((long)(g_iTrajSteps / g_iStride / g_stride * 1.1));
218
floatArray->SetGrow((long)(g_iTrajSteps / g_iStride / g_stride * 0.1));
220
floatArray->SetGrow(10000);
222
_polarizability[j][k].Add(floatArray);
228
void CRamanDyn::getDipole0() {
231
for(i = 0; i < m_iMolecules; i++) {
234
sm = (CSingleMolecule *)g_oaSingleMolecules[i];
236
sm = (CSingleMolecule *)g_oaSingleMolecules[((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex[i]];
237
*((CxVector3 *)_dipole0[i]) = sm->m_vDipole;
241
void CRamanDyn::calcPolarizability(int fieldDirection) {
244
for(i = 0; i < m_iMolecules; i++) {
247
sm = (CSingleMolecule *)g_oaSingleMolecules[i];
249
sm = (CSingleMolecule *)g_oaSingleMolecules[((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex[i]];
250
for(int j = 0; j < 3; j++) {
251
((CxFloatArray *)_polarizability[j][fieldDirection][i])->Add(((*((CxVector3 *)_dipole0[i]))[j] - sm->m_vDipole[j]) / g_fieldStrength * 0.393430f); // 0.393430 - Umrechnung von Debye in a.u.
256
void CRamanDyn::finalize() {
259
char filename[BUF_SIZE];
261
snprintf(filename, BUF_SIZE, "%s/polarizability_%s.dat", g_ramanDir, m_sName);
263
sprintf(filename, "%s/polarizability_%s.dat", g_ramanDir, m_sName);
265
mprintf(" Writing polarizabilities for first molecule to \"%s\"...\n", filename);
267
pol_file = OpenFileWrite(filename, false);
268
for(i = 0; i < ((CxFloatArray *)_polarizability[0][0][0])->GetSize(); i++) {
269
fprintf(pol_file, "%10.2f", i * g_fTimestepLength * g_iStride * g_stride);
270
for(j = 0; j < (g_orientAvg ? 3 : 1); j++) {
271
for(k = 0; k < 3; k++) {
272
fprintf(pol_file, " %14.8f", (*((CxFloatArray *)_polarizability[k][j][0]))[i]);
275
fprintf(pol_file, "\n");
280
switch(_derivativeOrder) {
282
mprintf(" Not deriving polarizabilities.\n");
285
mprintf(" Deriving polarizabilities (1st derivative)...\n");
286
mprintf(WHITE, " [");
287
step = m_iMolecules / 20.0f;
288
for(i = 0; i < m_iMolecules; i++) {
289
if(fmodf((float)i, step) < 1.0f)
291
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - 1; j++) {
292
for(k = 0; k < 3; k++) {
293
for(l = 0; l < (g_orientAvg ? 3 : 1); l++) {
294
(*((CxFloatArray *)_polarizability[k][l][i]))[j] = 0.5f * ((*((CxFloatArray *)_polarizability[k][l][i]))[j+1] - (*((CxFloatArray *)_polarizability[k][l][i]))[j]);
299
mprintf(WHITE, "]\n");
302
mprintf(" Deriving polarizabilities (2nd derivative)...\n");
303
mprintf(WHITE, " [");
304
step = m_iMolecules / 20.0f;
305
for(i = 0; i < m_iMolecules; i++) {
306
if(fmodf((float)i, step) < 1.0f)
308
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - 2; j++) {
309
for(k = 0; k < 3; k++) {
310
for(l = 0; l < (g_orientAvg ? 3 : 1); l++) {
311
(*((CxFloatArray *)_polarizability[k][l][i]))[j] = (*((CxFloatArray *)_polarizability[k][l][i]))[j+2] - 2.0f * (*((CxFloatArray *)_polarizability[k][l][i]))[j+1] + (*((CxFloatArray *)_polarizability[k][l][i]))[j];
316
mprintf(WHITE, "]\n");
319
mprintf(RED, "Higher derivatives not implemented.\n");
324
mprintf(" Processing polarizability tensor components...\n");
325
step = m_iMolecules / 20.0f;
327
CAutoCorrelation *autoCorrelation;
328
try { autoCorrelation = new CAutoCorrelation(); } catch(...) { autoCorrelation = NULL; }
329
if(autoCorrelation == NULL) NewException((double)sizeof(CAutoCorrelation), __FILE__, __LINE__, __PRETTY_FUNCTION__);
330
autoCorrelation->Init(((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder, m_iDepth, g_bACFFFT);
333
CxFloatArray *isotropyPol, *isotropyACF;
334
try { isotropyACF = new CxFloatArray("CRamanDyn::finalize():isotropyACF"); } catch(...) { isotropyACF = NULL; }
335
if(isotropyACF == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
336
isotropyACF->SetSize(m_iDepth);
337
try { isotropyPol = new CxFloatArray("CRamanDyn::finalize():isotropyPol"); } catch(...) { isotropyPol = NULL; }
338
if(isotropyPol == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
339
isotropyPol->SetSize(((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder);
341
mprintf(" Isotropic part...\n");
342
mprintf(WHITE, " [");
343
for(i = 0; i < m_iDepth; i++) {
344
_isoACF->m_pData[i] = 0.0f;
346
for(i = 0; i < m_iMolecules; i++) {
347
if(fmodf((float)i, step) < 1.0f)
349
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
350
(*isotropyPol)[j] = 0.0f;
351
for(k = 0; k < 3; k++) {
352
(*isotropyPol)[j] += (*((CxFloatArray *)_polarizability[k][k][i]))[j];
354
(*isotropyPol)[j] /= 3.0f;
356
autoCorrelation->AutoCorrelate(isotropyPol, isotropyACF);
357
for(j = 0; j < m_iDepth; j++) {
358
_isoACF->m_pData[j] += (*isotropyACF)[j];
361
for(i = 0; i < m_iDepth; i++) {
363
_isoACF->m_pData[i] /= g_iSteps / g_stride;
365
_isoACF->m_pData[i] /= g_iSteps / g_stride * m_iMolecules;
367
mprintf(WHITE, "]\n");
369
// #ifdef TARGET_LINUX
370
// snprintf(filename, BUF_SIZE, "%s/acf_iso_%s.dat", g_ramanDir, m_sName);
372
// sprintf(filename, "%s/acf_iso_%s.dat", g_ramanDir, m_sName);
374
// mprintf(" Saving ACF as %s...\n", filename);
375
// FILE *acf_file = OpenFileWrite(filename, false);
376
// for(i = 0; i < m_iDepth; i++)
377
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _isoACF->m_pData[i]);
380
if(_isoACF->m_iMirror != 0) {
381
mprintf(" Mirroring ACF...\n");
382
_isoACF->Mirror(_isoACF->m_iMirror);
384
if(_isoACF->m_bWindowFunction != 0) {
385
mprintf(" Applying window function to ACF...\n");
389
// #ifdef TARGET_LINUX
390
// snprintf(filename, BUF_SIZE, "%s/acf_iso_%s.mw.dat", g_ramanDir, m_sName);
392
// sprintf(filename, "%s/acf_iso_%s.mw.dat", g_ramanDir, m_sName);
394
// mprintf(" Saving ACF as %s...\n", filename);
395
// acf_file = OpenFileWrite(filename, false);
396
// for(i = 0; i < _isoACF->m_iSize; i++)
397
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _isoACF->m_pData[i]);
400
mprintf(" Performing Fourier transformation...\n");
402
try { fft = new CFFT(); } catch(...) { fft = NULL; }
403
if(fft == NULL) NewException((double)sizeof(CFFT), __FILE__, __LINE__, __PRETTY_FUNCTION__);
404
fft->PrepareFFT_C2C(_isoACF->m_iSize + _isoACF->m_iZeroPadding);
405
_isoACF->Transform(fft);
407
_isoACF->m_pSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
409
// #ifdef TARGET_LINUX
410
// snprintf(filename, BUF_SIZE, "%s/spectrum_iso_%s.dat", g_ramanDir, m_sName);
412
// sprintf(filename, "%s/spectrum_iso_%s.dat", g_ramanDir, m_sName);
414
// mprintf(" Saving spectrum as %s...\n", filename);
415
// _isoACF->m_pSpectrum->Write("", filename, "");
420
CxFloatArray *anisotropyPol, *anisotropyACF, *anisotropyACFSum;
421
try { anisotropyPol = new CxFloatArray("CRamanDyn::finalize():anisotropyPol"); } catch(...) { anisotropyPol = NULL; }
422
if(anisotropyPol == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
423
anisotropyPol->SetSize(((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder);
424
try { anisotropyACF = new CxFloatArray("CRamanDyn::finalize():anisotropyACF"); } catch(...) { anisotropyACF = NULL; }
425
if(anisotropyACF == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
426
anisotropyACF->SetSize(m_iDepth);
427
try { anisotropyACFSum = new CxFloatArray("CRamanDyn::finalize():anisotropyACFSum"); } catch(...) { anisotropyACFSum = NULL; }
428
if(anisotropyACFSum == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
429
anisotropyACFSum->SetSize(m_iDepth);
431
mprintf(" First anisotropic part...\n");
432
mprintf(WHITE, " [");
433
for(i = 0; i < m_iDepth; i++) {
434
_anisoACF->m_pData[i] = 0.0f;
436
for(i = 0; i < m_iMolecules; i++) {
437
if(fmodf((float)i, step) < 1.0f)
439
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
440
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[0][0][i]))[j];
441
(*anisotropyPol)[j] -= (*((CxFloatArray *)_polarizability[1][1][i]))[j];
443
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
444
for(int j = 0; j < m_iDepth; j++) {
445
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
448
for(i = 0; i < m_iDepth; i++) {
449
(*anisotropyACFSum)[i] = 0.5f * _anisoACF->m_pData[i];
451
mprintf(WHITE, "]\n");
453
mprintf(" Second anisotropic part...\n");
454
mprintf(WHITE, " [");
455
for(i = 0; i < m_iDepth; i++) {
456
_anisoACF->m_pData[i] = 0.0f;
458
for(i = 0; i < m_iMolecules; i++) {
459
if(fmodf((float)i, step) < 1.0f)
461
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
462
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[1][1][i]))[j];
463
(*anisotropyPol)[j] -= (*((CxFloatArray *)_polarizability[2][2][i]))[j];
465
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
466
for(j = 0; j < m_iDepth; j++) {
467
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
470
for(i = 0; i < m_iDepth; i++) {
471
(*anisotropyACFSum)[i] += 0.5f * _anisoACF->m_pData[i];
473
mprintf(WHITE, "]\n");
475
mprintf(" Third anisotropic part...\n");
476
mprintf(WHITE, " [");
477
for(i = 0; i < m_iDepth; i++) {
478
_anisoACF->m_pData[i] = 0.0f;
480
for(i = 0; i < m_iMolecules; i++) {
481
if(fmodf((float)i, step) < 1.0f)
483
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
484
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[2][2][i]))[j];
485
(*anisotropyPol)[j] -= (*((CxFloatArray *)_polarizability[0][0][i]))[j];
487
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
488
for(j = 0; j < m_iDepth; j++) {
489
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
492
for(i = 0; i < m_iDepth; i++) {
493
(*anisotropyACFSum)[i] += 0.5f * _anisoACF->m_pData[i];
495
mprintf(WHITE, "]\n");
497
mprintf(" Fourth anisotropic part...\n");
498
mprintf(WHITE, " [");
499
for(i = 0; i < m_iDepth; i++) {
500
_anisoACF->m_pData[i] = 0.0f;
502
for(i = 0; i < m_iMolecules; i++) {
503
if(fmodf((float)i, step) < 1.0f)
505
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
506
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[0][1][i]))[j];
507
(*anisotropyPol)[j] += (*((CxFloatArray *)_polarizability[1][0][i]))[j];
508
(*anisotropyPol)[j] *= 0.5f;
510
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
511
for(j = 0; j < m_iDepth; j++) {
512
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
515
for(i = 0; i < m_iDepth; i++) {
516
(*anisotropyACFSum)[i] += 3.0f * _anisoACF->m_pData[i];
518
mprintf(WHITE, "]\n");
520
mprintf(" Fifth anisotropic part...\n");
521
mprintf(WHITE, " [");
522
for(i = 0; i < m_iDepth; i++) {
523
_anisoACF->m_pData[i] = 0.0f;
525
for(i = 0; i < m_iMolecules; i++) {
526
if(fmodf((float)i, step) < 1.0f)
528
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
529
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[1][2][i]))[j];
530
(*anisotropyPol)[j] += (*((CxFloatArray *)_polarizability[2][1][i]))[j];
531
(*anisotropyPol)[j] *= 0.5f;
533
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
534
for(j = 0; j < m_iDepth; j++) {
535
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
538
for(i = 0; i < m_iDepth; i++) {
539
(*anisotropyACFSum)[i] += 3.0f * _anisoACF->m_pData[i];
541
mprintf(WHITE, "]\n");
543
mprintf(" Sixth anisotropic part...\n");
544
mprintf(WHITE, " [");
545
for(i = 0; i < m_iDepth; i++) {
546
_anisoACF->m_pData[i] = 0.0f;
548
for(i = 0; i < m_iMolecules; i++) {
549
if(fmodf((float)i, step) < 1.0f)
551
for(j = 0; j < ((CxFloatArray *)_polarizability[0][0][0])->GetSize() - _derivativeOrder; j++) {
552
(*anisotropyPol)[j] = (*((CxFloatArray *)_polarizability[2][0][i]))[j];
553
(*anisotropyPol)[j] += (*((CxFloatArray *)_polarizability[0][2][i]))[j];
554
(*anisotropyPol)[j] *= 0.5f;
556
autoCorrelation->AutoCorrelate(anisotropyPol, anisotropyACF);
557
for(j = 0; j < m_iDepth; j++) {
558
_anisoACF->m_pData[j] += (*anisotropyACF)[j];
561
for(i = 0; i < m_iDepth; i++) {
562
(*anisotropyACFSum)[i] += 3.0f * _anisoACF->m_pData[i];
564
mprintf(WHITE, "]\n");
566
for(i = 0; i < m_iDepth; i++) {
568
_anisoACF->m_pData[i] = (*anisotropyACFSum)[i] / g_iSteps * g_stride;
570
_anisoACF->m_pData[i] = (*anisotropyACFSum)[i] / g_iSteps * g_stride / m_iMolecules;
573
// #ifdef TARGET_LINUX
574
// snprintf(filename, BUF_SIZE, "%s/acf_aniso_%s.dat", g_ramanDir, m_sName);
576
// sprintf(filename, "%s/acf_aniso_%s.dat", g_ramanDirm_sName);
578
// mprintf(" Saving ACF as %s...\n", filename);
579
// acf_file = OpenFileWrite(filename, false);
580
// for(i = 0; i < m_iDepth; i++)
581
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _anisoACF->m_pData[i]);
584
if(_anisoACF->m_iMirror != 0) {
585
mprintf(" Mirroring ACF...\n");
586
_anisoACF->Mirror(_anisoACF->m_iMirror);
588
if(_anisoACF->m_bWindowFunction != 0) {
589
mprintf(" Applying window function to ACF...\n");
593
// #ifdef TARGET_LINUX
594
// snprintf(filename, BUF_SIZE, "%s/acf_aniso_%s.mw.dat", g_ramanDir, m_sName);
596
// sprintf(filename, "%s/acf_aniso_%s.mw.dat", g_ramanDir, m_sName);
598
// mprintf(" Saving ACF as %s...\n", filename);
599
// acf_file = OpenFileWrite(filename, false);
600
// for(i = 0; i < _anisoACF->m_iSize; i++)
601
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _anisoACF->m_pData[i]);
604
mprintf(" Performing Fourier transformation...\n");
605
try { fft = new CFFT(); } catch(...) { fft = NULL; }
606
if(fft == NULL) NewException((double)sizeof(CFFT), __FILE__, __LINE__, __PRETTY_FUNCTION__);
607
fft->PrepareFFT_C2C(_anisoACF->m_iSize + _anisoACF->m_iZeroPadding);
608
_anisoACF->Transform(fft);
610
_anisoACF->m_pSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
612
// #ifdef TARGET_LINUX
613
// snprintf(filename, BUF_SIZE, "%s/spectrum_aniso_%s.dat", g_ramanDir, m_sName);
615
// sprintf(filename, "%s/spectrum_aniso_%s.dat", g_ramanDir, m_sName);
617
// mprintf(" Saving spectrum as %s...\n", filename);
618
// _anisoACF->m_pSpectrum->Write("", filename, "");
620
int specSize = _isoACF->m_pSpectrum->m_iSize;
621
CSpectrum *paraSpectrum, *orthoSpectrum, *sumSpectrum, *depolSpectrum;
622
try { paraSpectrum = new CSpectrum(); } catch(...) { paraSpectrum = NULL; }
623
if(paraSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
624
paraSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
625
paraSpectrum->Create(specSize);
626
paraSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
627
try { orthoSpectrum = new CSpectrum(); } catch(...) { orthoSpectrum = NULL; }
628
if(orthoSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
629
orthoSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
630
orthoSpectrum->Create(specSize);
631
orthoSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
632
try { sumSpectrum = new CSpectrum(); } catch(...) { sumSpectrum = NULL; }
633
if(sumSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
634
sumSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
635
sumSpectrum->Create(specSize);
636
sumSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
637
try { depolSpectrum = new CSpectrum(); } catch(...) { depolSpectrum = NULL; }
638
if(depolSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
639
depolSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
640
depolSpectrum->Create(specSize);
641
depolSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
643
for(i = 0; i < specSize; i++) {
644
paraSpectrum->m_pData[i] = _isoACF->m_pSpectrum->m_pData[i] + 4.0f / 45.0f * _anisoACF->m_pSpectrum->m_pData[i];
647
// #ifdef TARGET_LINUX
648
// snprintf(filename, BUF_SIZE, "%s/spectrum_para_%s.dat", g_ramanDir, m_sName);
650
// sprintf(filename, "%s/spectrum_para_%s.dat", g_ramanDir, m_sName);
652
// mprintf(" Saving para spectrum as %s...\n", filename);
653
// paraSpectrum->Write("", filename, "");
655
for(i = 0; i < specSize; i++) {
656
orthoSpectrum->m_pData[i] = _anisoACF->m_pSpectrum->m_pData[i] / 15.0f;
659
// #ifdef TARGET_LINUX
660
// snprintf(filename, BUF_SIZE, "%s/spectrum_ortho_%s.dat", g_ramanDir, m_sName);
662
// sprintf(filename, "%s/spectrum_ortho_%s.dat", g_ramanDir, m_sName);
664
// mprintf(" Saving ortho spectrum as %s...\n", filename);
665
// orthoSpectrum->Write("", filename, "");
667
for(i = 0; i < specSize; i++) {
668
sumSpectrum->m_pData[i] = paraSpectrum->m_pData[i] + orthoSpectrum->m_pData[i];
671
// #ifdef TARGET_LINUX
672
// snprintf(filename, BUF_SIZE, "%s/spectrum_unpol_%s.dat", g_ramanDir, m_sName);
674
// sprintf(filename, "%s/spectrum_unpol_%s.dat", g_ramanDir, m_sName);
676
// mprintf(" Saving unpolarized spectrum as %s...\n", filename);
677
// sumSpectrum->Write("", filename, "");
679
for(i = 0; i < specSize; i++) {
680
float freq = i * paraSpectrum->m_fMaxRWL / paraSpectrum->m_iSize;
681
float crossSecFactor = powf(g_laser - freq, 4) / freq / (1 - expf(-1.438777f * freq / g_temp));
682
paraSpectrum->m_pData[i] *= crossSecFactor;
683
orthoSpectrum->m_pData[i] *= crossSecFactor;
684
sumSpectrum->m_pData[i] *= crossSecFactor;
687
for(i = 0; i < specSize; i++) {
688
depolSpectrum->m_pData[i] = orthoSpectrum->m_pData[i] / paraSpectrum->m_pData[i];
692
snprintf(filename, BUF_SIZE, "%s/spectrum_para_%s.csv", g_ramanDir, m_sName);
694
sprintf(filename, "%s/spectrum_para_%s.csv", g_ramanDir, m_sName);
696
mprintf(" Saving parallel spectrum as %s...\n", filename);
697
paraSpectrum->Write("", filename, "");
700
snprintf(filename, BUF_SIZE, "%s/spectrum_ortho_%s.csv", g_ramanDir, m_sName);
702
sprintf(filename, "%s/spectrum_ortho_%s.csv", g_ramanDir, m_sName);
704
mprintf(" Saving orthogonal spectrum as %s...\n", filename);
705
orthoSpectrum->Write("", filename, "");
708
snprintf(filename, BUF_SIZE, "%s/spectrum_unpol_%s.csv", g_ramanDir, m_sName);
710
sprintf(filename, "%s/spectrum_unpol_%s.csv", g_ramanDir, m_sName);
712
mprintf(" Saving unpolarized spectrum as %s...\n", filename);
713
sumSpectrum->Write("", filename, "");
716
snprintf(filename, BUF_SIZE, "%s/depol_ratio_%s.csv", g_ramanDir, m_sName);
718
sprintf(filename, "%s/depol_ratio_%s.csv", g_ramanDir, m_sName);
720
mprintf(" Saving depolarization ratio as %s...\n", filename);
721
depolSpectrum->Write("", filename, "");
723
delete anisotropyACFSum;
724
delete anisotropyACF;
725
delete anisotropyPol;
728
delete orthoSpectrum;
730
delete depolSpectrum;
733
try { ACF = new CxFloatArray("CRamanDyn::finalize():ACF"); } catch(...) { ACF = NULL; }
734
if(ACF == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
735
ACF->SetSize(m_iDepth);
737
mprintf(" Parallel part...\n");
738
mprintf(WHITE, " [");
739
for(i = 0; i < m_iDepth; i++) {
740
_isoACF->m_pData[i] = 0.0f;
742
for(i = 0; i < m_iMolecules; i++) {
743
if(fmodf((float)i, step) < 1.0f)
745
autoCorrelation->AutoCorrelate((CxFloatArray *)_polarizability[0][0][i], ACF);
746
for(int j = 0; j < m_iDepth; j++) {
747
_isoACF->m_pData[j] += (*ACF)[j];
750
for(i = 0; i < m_iDepth; i++) {
752
_isoACF->m_pData[i] /= g_iSteps / g_stride;
754
_isoACF->m_pData[i] /= g_iSteps / g_stride * m_iMolecules;
756
mprintf(WHITE, "]\n");
758
// #ifdef TARGET_LINUX
759
// snprintf(filename, BUF_SIZE, "%s/acf_para_%s.dat", g_ramanDir, m_sName);
761
// sprintf(filename, "%s/acf_para_%s.dat", g_ramanDir, m_sName);
763
// mprintf(" Saving ACF as %s...\n", filename);
764
// FILE *acf_file = OpenFileWrite(filename, false);
765
// for(i = 0; i < m_iDepth; i++)
766
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _isoACF->m_pData[i]);
769
if(_isoACF->m_iMirror != 0) {
770
mprintf(" Mirroring ACF...\n");
771
_isoACF->Mirror(_isoACF->m_iMirror);
773
if(_isoACF->m_bWindowFunction != 0) {
774
mprintf(" Applying window function to ACF...\n");
778
// #ifdef TARGET_LINUX
779
// snprintf(filename, BUF_SIZE, "%s/acf_para_%s.mw.dat", g_ramanDir, m_sName);
781
// sprintf(filename, "%s/acf_para_%s.mw.dat", g_ramanDir, m_sName);
783
// mprintf(" Saving ACF as %s...\n", filename);
784
// acf_file = OpenFileWrite(filename, false);
785
// for(i = 0; i < _isoACF->m_iSize; i++)
786
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _isoACF->m_pData[i]);
789
mprintf(" Performing Fourier transformation...\n");
791
try { fft = new CFFT(); } catch(...) { fft = NULL; }
792
if(fft == NULL) NewException((double)sizeof(CFFT), __FILE__, __LINE__, __PRETTY_FUNCTION__);
793
fft->PrepareFFT_C2C(_isoACF->m_iSize + _isoACF->m_iZeroPadding);
794
_isoACF->Transform(fft);
796
_isoACF->m_pSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
798
// #ifdef TARGET_LINUX
799
// snprintf(filename, BUF_SIZE, "%s/spectrum_para_%s.dat", g_ramanDir, m_sName);
801
// sprintf(filename, "%s/spectrum_para_%s.dat", g_ramanDir, m_sName);
803
// mprintf(" Saving spectrum as %s...\n", filename);
804
// _isoACF->m_pSpectrum->Write("", filename, "");
806
mprintf(" Orthogonal part...\n");
807
mprintf(WHITE, " [");
808
for(i = 0; i < m_iDepth; i++) {
809
_anisoACF->m_pData[i] = 0.0f;
811
for(i = 0; i < m_iMolecules; i++) {
812
if(fmodf((float)i, step) < 1.0f)
814
autoCorrelation->AutoCorrelate((CxFloatArray *)_polarizability[1][0][i], ACF);
815
for(int j = 0; j < m_iDepth; j++) {
816
_anisoACF->m_pData[j] += (*ACF)[j];
819
for(i = 0; i < m_iDepth; i++) {
821
_anisoACF->m_pData[i] /= g_iSteps / g_stride;
823
_anisoACF->m_pData[i] /= g_iSteps / g_stride * m_iMolecules;
825
mprintf(WHITE, "]\n");
827
// #ifdef TARGET_LINUX
828
// snprintf(filename, BUF_SIZE, "%s/acf_ortho_%s.dat", g_ramanDir, m_sName);
830
// sprintf(filename, "%s/acf_ortho_%s.dat", g_ramanDir, m_sName);
832
// mprintf(" Saving ACF as %s...\n", filename);
833
// acf_file = OpenFileWrite(filename, false);
834
// for(i = 0; i < m_iDepth; i++)
835
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _anisoACF->m_pData[i]);
838
if(_anisoACF->m_iMirror != 0) {
839
mprintf(" Mirroring ACF...\n");
840
_anisoACF->Mirror(_isoACF->m_iMirror);
842
if(_anisoACF->m_bWindowFunction != 0) {
843
mprintf(" Applying window function to ACF...\n");
847
// #ifdef TARGET_LINUX
848
// snprintf(filename, BUF_SIZE, "%s/acf_ortho_%s.mw.dat", g_ramanDir, m_sName);
850
// sprintf(filename, "%s/acf_ortho_%s.mw.dat", g_ramanDir, m_sName);
852
// mprintf(" Saving ACF as %s...\n", filename);
853
// acf_file = OpenFileWrite(filename, false);
854
// for(i = 0; i < _isoACF->m_iSize; i++)
855
// fprintf(acf_file, "%10.2f %12.8f\n", i * g_fTimestepLength * g_iStride * g_stride, _anisoACF->m_pData[i]);
858
mprintf(" Performing Fourier transformation...\n");
859
try { fft = new CFFT(); } catch(...) { fft = NULL; }
860
if(fft == NULL) NewException((double)sizeof(CFFT), __FILE__, __LINE__, __PRETTY_FUNCTION__);
861
fft->PrepareFFT_C2C(_anisoACF->m_iSize + _anisoACF->m_iZeroPadding);
862
_anisoACF->Transform(fft);
864
_anisoACF->m_pSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
866
// #ifdef TARGET_LINUX
867
// snprintf(filename, BUF_SIZE, "%s/spectrum_ortho_%s.dat", g_ramanDir, m_sName);
869
// sprintf(filename, "%s/spectrum_ortho_%s.dat", g_ramanDir, m_sName);
871
// mprintf(" Saving spectrum as %s...\n", filename);
872
// _anisoACF->m_pSpectrum->Write("", filename, "");
876
int specSize = _isoACF->m_pSpectrum->m_iSize;
877
CSpectrum *sumSpectrum, *depolSpectrum;
878
try { sumSpectrum = new CSpectrum(); } catch(...) { sumSpectrum = NULL; }
879
if(sumSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
880
sumSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
881
sumSpectrum->Create(specSize);
882
sumSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
883
try { depolSpectrum = new CSpectrum(); } catch(...) { depolSpectrum = NULL; }
884
if(depolSpectrum == NULL) NewException((double)sizeof(CSpectrum), __FILE__, __LINE__, __PRETTY_FUNCTION__);
885
depolSpectrum->m_fWaveNumber = _isoACF->m_fSpecWaveNumber;
886
depolSpectrum->Create(specSize);
887
depolSpectrum->SetMaxRWL(1e15f/299792458.0f/100.0f/g_fTimestepLength/g_iStride/g_stride);
889
for(i = 0; i < specSize; i++) {
890
sumSpectrum->m_pData[i] = _isoACF->m_pSpectrum->m_pData[i] + _anisoACF->m_pSpectrum->m_pData[i];
893
// #ifdef TARGET_LINUX
894
// snprintf(filename, BUF_SIZE, "%s/spectrum_unpol_%s.dat", g_ramanDir, m_sName);
896
// sprintf(filename, "%s/spectrum_unpol_%s.dat", g_ramanDir, m_sName);
898
// mprintf(" Saving unpolarized spectrum as %s...\n", filename);
899
// sumSpectrum->Write("", filename, "");
901
for(i = 0; i < specSize; i++) {
902
float freq = i * _isoACF->m_pSpectrum->m_fMaxRWL / _isoACF->m_pSpectrum->m_iSize;
903
float crossSecFactor = powf(g_laser - freq, 4) / freq / (1 - expf(-1.438777f * freq / g_temp));
904
_isoACF->m_pSpectrum->m_pData[i] *= crossSecFactor;
905
_anisoACF->m_pSpectrum->m_pData[i] *= crossSecFactor;
906
sumSpectrum->m_pData[i] *= crossSecFactor;
909
for(i = 0; i < specSize; i++) {
910
depolSpectrum->m_pData[i] = _anisoACF->m_pSpectrum->m_pData[i] / _isoACF->m_pSpectrum->m_pData[i];
914
snprintf(filename, BUF_SIZE, "%s/spectrum_para_%s.csv", g_ramanDir, m_sName);
916
sprintf(filename, "%s/spectrum_para_%s.csv", g_ramanDir, m_sName);
918
mprintf(" Saving parallel spectrum as %s...\n", filename);
919
_isoACF->m_pSpectrum->Write("", filename, "");
922
snprintf(filename, BUF_SIZE, "%s/spectrum_ortho_%s.csv", g_ramanDir, m_sName);
924
sprintf(filename, "%s/spectrum_ortho_%s.csv", g_ramanDir, m_sName);
926
mprintf(" Saving orthogonal spectrum as %s...\n", filename);
927
_anisoACF->m_pSpectrum->Write("", filename, "");
930
snprintf(filename, BUF_SIZE, "%s/spectrum_unpol_%s.csv", g_ramanDir, m_sName);
932
sprintf(filename, "%s/spectrum_unpol_%s.csv", g_ramanDir, m_sName);
934
mprintf(" Saving unpolarized spectrum as %s...\n", filename);
935
sumSpectrum->Write("", filename, "");
938
snprintf(filename, BUF_SIZE, "%s/depol_ratio_%s.csv", g_ramanDir, m_sName);
940
sprintf(filename, "%s/depol_ratio_%s.csv", g_ramanDir, m_sName);
942
mprintf(" Saving depolarization ratio as %s...\n", filename);
943
depolSpectrum->Write("", filename, "");
946
delete depolSpectrum;
949
delete autoCorrelation;
952
CRamanObservation::CRamanObservation(bool global) {
962
m_iShowMolCount = g_oaSingleMolecules.GetSize();
963
m_bObsCertain = false;
964
m_bDecompDist = false;
965
m_bDecompType = false;
969
size_t remaining = BUF_SIZE;
970
if(g_oaMolecules.GetSize() > 1) {
972
remaining -= snprintf(buf, remaining, " Which molecule should be observed (");
974
remaining -= sprintf(buf, " Which molecule should be observed (");
976
for(i = 0; i < g_oaMolecules.GetSize(); i++) {
980
size_t length = snprintf(buf2, remaining, "%s=%d", ((CMolecule *)g_oaMolecules[i])->m_sName, i+1);
982
size_t length = sprintf(buf2, "%s=%d", ((CMolecule *)g_oaMolecules[i])->m_sName, i+1);
984
strncat(buf, buf2, remaining - 1);
986
if(i < g_oaMolecules.GetSize() - 1) {
988
length = snprintf(buf2, remaining, ", ");
990
length = sprintf(buf2, ", ");
992
strncat(buf, buf2, remaining - 1);
996
strncat(buf, ")? ", remaining - 1);
997
m_iShowMol = AskRangeInteger_ND(buf, 1, g_oaMolecules.GetSize()) - 1;
1001
m_iShowMolCount = ((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize();
1002
m_bObsCertain = false;
1003
m_bDecompDist = false;
1004
m_bDecompType = false;
1008
try { _ramanDyn = new CRamanDyn(m_iShowMol, global); } catch(...) { _ramanDyn = NULL; }
1009
if(_ramanDyn == NULL) NewException((double)sizeof(CRamanDyn), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1012
CRamanObservation::~CRamanObservation() {
1016
void CRamanObservation::initialize() {
1017
_ramanDyn->initialize();
1020
void CRamanObservation::getDipole0() {
1021
_ramanDyn->getDipole0();
1024
void CRamanObservation::calcPolarizability(int fieldDirection) {
1025
_ramanDyn->calcPolarizability(fieldDirection);
1028
void CRamanObservation::finalize() {
1029
_ramanDyn->finalize();
1032
static bool parseSettings(FILE *settingsFile) {
1035
if(fgets(buf, BUF_SIZE, settingsFile) == NULL)
1038
if(sscanf(buf, "%d", &temp) < 1)
1041
g_orientAvg = false;
1047
if(fgets(buf, BUF_SIZE, settingsFile) == NULL)
1049
if(sscanf(buf, "%f", &g_fieldStrength) < 1)
1052
if(fgets(buf, BUF_SIZE, settingsFile) == NULL)
1054
if(sscanf(buf, "%d", &g_stride) < 1)
1060
bool gatherRaman() {
1061
#ifndef TARGET_LINUX
1062
mprintf(RED, "Raman calculations are currently possible only under Linux.\n");
1065
mprintf(" To calculate Raman spectra, polarizabilities have to be determined.\n");
1066
mprintf(" TRAVIS creates CP2K input files for numerical polarizabilities\n and will process the resulting data in a second run.\n\n");
1068
g_newRaman = AskYesNo(" Do you wish to create new CP2K input files (y) or process existing results (n)? [y] ", true);
1071
AskString(" Please enter a name for the directory to collect the data: [raman] ", buf, "raman");
1073
AskString(" Please enter the name of the directory to take the data from: [raman] ", buf, "raman");
1075
try { g_ramanDir = new char[strlen(buf)+1]; } catch(...) { g_ramanDir = NULL; }
1076
if(g_ramanDir == NULL) NewException((double)(strlen(buf)+1)*sizeof(char), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1077
strcpy(g_ramanDir, buf);
1080
g_bKeepOriginalCoords = true;
1081
if(FileExist(g_ramanDir)) {
1082
mprintf(RED, "A file or a directory \"%s\" already exists. Please remove it first.\n", g_ramanDir);
1085
if(mkdir(g_ramanDir, S_IRWXU) != 0) {
1086
mprintf(RED, "Directory \"%s\" could not be created: %s\n", g_ramanDir, strerror(errno));
1090
char filename[BUF_SIZE];
1091
snprintf(filename, BUF_SIZE, "%s/settings.dat", g_ramanDir);
1092
FILE *settingsFile = fopen(filename, "w");
1093
if(settingsFile == NULL) {
1094
mprintf(RED, "Could not open settings file \"%s\": %s\n", filename, strerror(errno));
1098
g_orientAvg = AskYesNo("\n Use orientational averaging? [no] ", false);
1100
fprintf(settingsFile, "%d\n", 1);
1102
fprintf(settingsFile, "%d\n", 0);
1104
g_fieldStrength = AskFloat(" Field strength in atomic units [5.0e-4] ", 5.0e-4);
1105
fprintf(settingsFile, "%.6E\n", g_fieldStrength);
1107
g_stride = AskInteger(" Calculate polarizability for every n-th timestep [1] ", 1);
1108
fprintf(settingsFile, "%d\n", g_stride);
1110
fclose(settingsFile);
1112
snprintf(filename, BUF_SIZE, "%s/1", g_ramanDir);
1113
if(mkdir(filename, S_IRWXU) != 0) {
1114
mprintf(RED, "Directory \"%s\" could not be created: %s\n", filename, strerror(errno));
1118
snprintf(filename, BUF_SIZE, "%s/2", g_ramanDir);
1119
if(mkdir(filename, S_IRWXU) != 0) {
1120
mprintf(RED, "Directory \"%s\" could not be created: %s\n", filename, strerror(errno));
1123
snprintf(filename, BUF_SIZE, "%s/3", g_ramanDir);
1124
if(mkdir(filename, S_IRWXU) != 0) {
1125
mprintf(RED, "Directory \"%s\" could not be created: %s\n", filename, strerror(errno));
1131
snprintf(filename, BUF_SIZE, "%s/template.inp", g_ramanDir);
1132
templateFile = fopen(filename, "w");
1133
if(templateFile == NULL) {
1134
mprintf(RED, "Could not open template file \"%s\": %s\n", filename, strerror(errno));
1137
fprintf(templateFile, "&GLOBAL\n");
1138
fprintf(templateFile, " PROJECT_NAME polarizability\n");
1139
fprintf(templateFile, " RUN_TYPE MD\n");
1140
fprintf(templateFile, " PRINT_LEVEL LOW\n");
1141
fprintf(templateFile, "&END\n");
1142
fprintf(templateFile, "&FORCE_EVAL\n");
1143
fprintf(templateFile, " &DFT\n");
1144
fprintf(templateFile, " BASIS_SET_FILE_NAME BASIS_MOLOPT\n");
1145
fprintf(templateFile, " POTENTIAL_FILE_NAME POTENTIAL\n");
1146
fprintf(templateFile, " &MGRID\n");
1147
fprintf(templateFile, " NGRIDS 5\n");
1148
fprintf(templateFile, " CUTOFF 280\n");
1149
fprintf(templateFile, " REL_CUTOFF 40\n");
1150
fprintf(templateFile, " &END\n");
1151
fprintf(templateFile, " &SCF\n");
1152
fprintf(templateFile, " SCF_GUESS ATOMIC\n");
1153
fprintf(templateFile, " MAX_SCF 200\n");
1154
fprintf(templateFile, " EPS_SCF 1.0E-5\n");
1155
fprintf(templateFile, " &OT\n");
1156
fprintf(templateFile, " MINIMIZER DIIS\n");
1157
fprintf(templateFile, " PRECONDITIONER FULL_SINGLE_INVERSE\n");
1158
fprintf(templateFile, " &END\n");
1159
fprintf(templateFile, " &END\n");
1160
fprintf(templateFile, " &XC\n");
1161
fprintf(templateFile, " &XC_FUNCTIONAL BLYP\n");
1162
fprintf(templateFile, " &END\n");
1163
fprintf(templateFile, " &XC_GRID\n");
1164
fprintf(templateFile, " XC_SMOOTH_RHO NN10\n");
1165
fprintf(templateFile, " XC_DERIV NN10_SMOOTH\n");
1166
fprintf(templateFile, " &END\n");
1167
fprintf(templateFile, " &VDW_POTENTIAL\n");
1168
fprintf(templateFile, " POTENTIAL_TYPE PAIR_POTENTIAL\n");
1169
fprintf(templateFile, " &PAIR_POTENTIAL\n");
1170
fprintf(templateFile, " TYPE DFTD3\n");
1171
fprintf(templateFile, " REFERENCE_FUNCTIONAL BLYP\n");
1172
fprintf(templateFile, " PARAMETER_FILE_NAME dftd3.dat\n");
1173
fprintf(templateFile, " &END\n");
1174
fprintf(templateFile, " &END\n");
1175
fprintf(templateFile, " &END\n");
1176
fprintf(templateFile, " &LOCALIZE\n");
1177
fprintf(templateFile, " METHOD CRAZY\n");
1178
fprintf(templateFile, " MAX_ITER 2000\n");
1179
fprintf(templateFile, " &PRINT\n");
1180
fprintf(templateFile, " &WANNIER_CENTERS\n");
1181
fprintf(templateFile, " IONS+CENTERS\n");
1182
fprintf(templateFile, " FILENAME =polarizability_wannier.xyz\n");
1183
fprintf(templateFile, " &END\n");
1184
fprintf(templateFile, " &END\n");
1185
fprintf(templateFile, " &END\n");
1186
fprintf(templateFile, " &PERIODIC_EFIELD\n");
1187
fprintf(templateFile, " INTENSITY ###!field strength will be put here###\n");
1188
fprintf(templateFile, " POLARISATION ###!polarisation vector will be put here###\n");
1189
fprintf(templateFile, " &END\n");
1190
fprintf(templateFile, " &END\n");
1191
fprintf(templateFile, " &SUBSYS\n");
1192
fprintf(templateFile, " &CELL\n");
1193
fprintf(templateFile, " ABC %.6f %.6f %.6f\n", g_fBoxX / 100.0f, g_fBoxY / 100.0f, g_fBoxZ / 100.0f);
1194
fprintf(templateFile, " &END\n");
1195
fprintf(templateFile, " &COORD\n");
1196
fprintf(templateFile, "###!coordinates will be put here###\n");
1197
fprintf(templateFile, " &END\n");
1198
fprintf(templateFile, " &KIND H\n");
1199
fprintf(templateFile, " BASIS_SET DZVP-MOLOPT-SR-GTH\n");
1200
fprintf(templateFile, " POTENTIAL GTH-BLYP-q1\n");
1201
fprintf(templateFile, " &END\n");
1202
fprintf(templateFile, " &KIND C\n");
1203
fprintf(templateFile, " BASIS_SET DZVP-MOLOPT-SR-GTH\n");
1204
fprintf(templateFile, " POTENTIAL GTH-BLYP-q4\n");
1205
fprintf(templateFile, " &END\n");
1206
fprintf(templateFile, " &KIND N\n");
1207
fprintf(templateFile, " BASIS_SET DZVP-MOLOPT-SR-GTH\n");
1208
fprintf(templateFile, " POTENTIAL GTH-BLYP-q5\n");
1209
fprintf(templateFile, " &END\n");
1210
fprintf(templateFile, " &KIND O\n");
1211
fprintf(templateFile, " BASIS_SET DZVP-MOLOPT-SR-GTH\n");
1212
fprintf(templateFile, " POTENTIAL GTH-BLYP-q6\n");
1213
fprintf(templateFile, " &END\n");
1214
fprintf(templateFile, " &END\n");
1215
fprintf(templateFile, "&END\n");
1216
fprintf(templateFile, "&MOTION\n");
1217
fprintf(templateFile, " &MD\n");
1218
fprintf(templateFile, " ENSEMBLE REFTRAJ\n");
1219
fprintf(templateFile, " STEPS ###!number of steps will be put here###\n");
1220
fprintf(templateFile, " TIMESTEP %f\n", g_fTimestepLength * g_stride);
1221
fprintf(templateFile, " &REFTRAJ\n");
1222
fprintf(templateFile, " EVAL_ENERGY_FORCES\n");
1223
fprintf(templateFile, " TRAJ_FILE_NAME ../polarizability_reftraj.xyz\n");
1224
fprintf(templateFile, " &END\n");
1225
fprintf(templateFile, " &END\n");
1226
fprintf(templateFile, " &PRINT\n");
1227
fprintf(templateFile, " &RESTART\n");
1228
fprintf(templateFile, " &EACH\n");
1229
fprintf(templateFile, " MD 1\n");
1230
fprintf(templateFile, " &END\n");
1231
fprintf(templateFile, " &END\n");
1232
fprintf(templateFile, " &END\n");
1233
fprintf(templateFile, "&END\n");
1234
fclose(templateFile);
1236
mprintf("\n An input template for the polarizability calculations has been written to \"%s/template.inp\"\n Please modify it according to your needs.\n Press any key when you are finished.\n", g_ramanDir);
1240
mprintf(" CP2K input files will be created in \"%s/1\", \"%s/2\", and \"%s/3\".\n", g_ramanDir, g_ramanDir, g_ramanDir);
1241
mprintf(" After TRAVIS has finished, please run them and make sure that the resulting trajectories \"polarizability_wannier.xyz\"\n are placed in the same directories before you execute TRAVIS for evaluation.\n\n");
1243
mprintf(" A CP2K input file will be created in \"%s/1\".\n", g_ramanDir);
1244
mprintf(" After TRAVIS has finished, please run it and make sure that the resulting trajectory \"polarizability_wannier.xyz\"\n is placed in the same directory before you run TRAVIS for evaluation.\n\n");
1247
if(!FileExist(g_ramanDir)) {
1248
mprintf(RED, "The directory \"%s\" was not found.\n", g_ramanDir);
1252
char filename[BUF_SIZE];
1253
snprintf(filename, BUF_SIZE, "%s/settings.dat", g_ramanDir);
1255
settingsFile = fopen(filename, "r");
1256
if(settingsFile == NULL) {
1257
mprintf(RED, "Could not open settings file \"%s\": %s\n", filename, strerror(errno));
1260
if(!parseSettings(settingsFile)) {
1261
mprintf(RED, "Could not parse settings file.\n");
1267
mprintf(" Using orientational averaging\n");
1269
mprintf(" Not using orientational averaging\n");
1270
mprintf(" Field strength: %.6e a. u.\n", g_fieldStrength);
1271
mprintf(" Using every %d%s timestep\n\n", g_stride, (g_stride == 1) ? "st" : ((g_stride == 2) ? "nd" : ((g_stride == 3) ? "rd" : "th")));
1273
g_laser = AskFloat(" Calculate scattering cross section for which laser frequency (cm^-1)? [20000.0] ", 20000.0f);
1274
g_temp = AskFloat(" Calculate scattering cross section for which temperature (K)? [300.0] ", 300.0f);
1276
if(AskYesNo(" Compute Raman spectrum of whole system (y/n)? [yes] ", true)) {
1277
mprintf(YELLOW, "\n>>> Global Raman Observation >>>\n\n");
1279
CRamanObservation *obs;
1280
try { obs = new CRamanObservation(true); } catch(...) { obs = NULL; }
1281
if(obs == NULL) NewException((double)sizeof(CRamanObservation), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1282
g_ramObserv.Add(obs);
1284
mprintf(YELLOW, "<<< End of Global Raman Observation <<<\n\n");
1287
if(AskYesNo(" Compute Raman spectra for certain molecule types (y/n)? [no] ", false)) {
1289
mprintf(YELLOW, "\n>>> Raman Observation %d >>>\n\n", g_ramObserv.GetSize() + 1);
1291
CRamanObservation *obs;
1292
try { obs = new CRamanObservation(); } catch(...) { obs = NULL; }
1293
if(obs == NULL) NewException((double)sizeof(CRamanObservation), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1294
g_ramObserv.Add(obs);
1296
mprintf(YELLOW, "<<< End of Raman Observation %d <<<\n\n", g_ramObserv.GetSize());
1298
if(!AskYesNo(" Add another observation (y/n)? [no] ", false))
1310
bool initializeRaman() {
1314
char filename[BUF_SIZE];
1316
snprintf(filename, BUF_SIZE, "%s/template.inp", g_ramanDir);
1318
sprintf(filename, "%s/template.inp", g_ramanDir);
1321
templateFile = fopen(filename, "r");
1322
if(templateFile == NULL) {
1323
mprintf(RED, "Could not open template file \"%s\": %s\n", filename, strerror(errno));
1326
fseek(templateFile, 0L, SEEK_END);
1327
long length = ftell(templateFile);
1329
mprintf(RED, "Could not determine size of template file: %s\n", strerror(errno));
1333
try { g_inputTemplate = new char[length + 1]; } catch(...) { g_inputTemplate = NULL; }
1334
if(g_inputTemplate == NULL) NewException((double)(length + 1)*sizeof(char), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1336
rewind(templateFile);
1337
if((long)fread(g_inputTemplate, sizeof(char), length, templateFile) < length) {
1338
mprintf(RED, "Could not read template file: %s\n", strerror(errno));
1341
g_inputTemplate[length] = '\0';
1343
fclose(templateFile);
1345
g_templateFieldPos = strstr(g_inputTemplate, "###!field strength will be put here###");
1346
if(g_templateFieldPos == NULL) {
1347
mprintf(RED, "Position mark for field strength missing in template.\n");
1350
g_templatePolPos = strstr(g_inputTemplate, "###!polarisation vector will be put here###");
1351
if(g_templatePolPos == NULL) {
1352
mprintf(RED, "Position mark for polarisation vector missing in template.\n");
1355
g_templateCoordPos = strstr(g_inputTemplate, "###!coordinates will be put here###");
1356
if(g_templateCoordPos == NULL) {
1357
mprintf(RED, "Position mark for coordinates missing in template.\n");
1360
g_templateStepsPos = strstr(g_inputTemplate, "###!number of steps will be put here###");
1361
if(g_templateStepsPos == NULL) {
1362
mprintf(RED, "Position mark for number of steps missing in template.\n");
1365
g_templateFieldPos[0] = '\0';
1366
g_templatePolPos[0] = '\0';
1367
g_templateCoordPos[0] = '\0';
1368
g_templateStepsPos[0] = '\0';
1371
snprintf(filename, BUF_SIZE, "%s/polarizability_reftraj.xyz", g_ramanDir);
1373
sprintf(filename, "%s/polarizability_reftraj.xyz", g_ramanDir);
1375
g_reftrajFile = fopen(filename, "w");
1376
if(g_reftrajFile == NULL) {
1377
mprintf(RED, "Could not open reference trajectory \"%s\": %s\n", filename, strerror(errno));
1381
for(i = 0; i < g_ramObserv.GetSize(); i++) {
1382
mprintf("Initializing Raman Observation %d...\n", i+1);
1383
CRamanObservation *obs = (CRamanObservation *)g_ramObserv[i];
1387
char filename[BUF_SIZE];
1388
for(i = 0; i < (g_orientAvg ? 3 : 1); i++) {
1390
snprintf(filename, BUF_SIZE, "%s/%d/polarizability_wannier.xyz", g_ramanDir, i + 1);
1392
sprintf(filename, "%s/%d/polarizability_wannier.xyz", g_ramanDir, i + 1);
1394
g_polFile[i] = fopen(filename, "r");
1395
if(g_polFile[i] == NULL) {
1396
mprintf(RED, "Could not open trajectory \"%s\": %s\n", filename, strerror(errno));
1401
for(i = 0; i < (g_orientAvg ? 3 : 1); i++) {
1402
try { g_timestep[i] = new CTimeStep(); } catch(...) { g_timestep[i] = NULL; }
1403
if(g_timestep[i] == NULL) NewException((double)sizeof(CTimeStep), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1410
void processRaman(CTimeStep *ts) {
1414
if(g_step % g_stride == 0) {
1417
for(i = 0; i < g_iGesAtomCount; i++)
1418
if(g_waAtomMolIndex[i] != 60000)
1420
fprintf(g_reftrajFile, "%d\nStep %d\n", numAtoms, g_step);
1421
for(i = 0; i < g_iGesAtomCount; i++) {
1422
if(g_waAtomMolIndex[i] == 60000)
1424
fprintf(g_reftrajFile, "%4s %14.10f %14.10f %14.10f\n", ((CAtom *)g_oaAtoms[g_waAtomRealElement[i]])->m_sName, ts->m_vaCoords_Original[i][0] / 100.0f, ts->m_vaCoords_Original[i][1] / 100.0f, ts->m_vaCoords_Original[i][2] / 100.0f);
1428
if(g_step % g_stride == 0) {
1429
for(i = 0; i < g_ramObserv.GetSize(); i++)
1430
((CRamanObservation *)g_ramObserv[i])->getDipole0();
1431
for(i = 0; i < (g_orientAvg ? 3 : 1); i++) {
1432
if(!g_timestep[i]->ReadTimestep(g_polFile[i], false)) {
1433
mprintf(RED, "Error while reading trajectory for polarizabilities.\n");
1436
if(!g_bSaveCoordsUnchanged) {
1437
g_timestep[i]->UniteMolecules(false);
1439
g_timestep[i]->CenterCOM();
1441
g_timestep[i]->CalcCenters();
1443
g_timestep[i]->ScanWannier(false);
1444
g_timestep[i]->CalcDipoles();
1445
for(j = 0; j < g_ramObserv.GetSize(); j++) {
1446
((CRamanObservation *)g_ramObserv[j])->calcPolarizability(i);
1453
void finalizeRaman() {
1456
fclose(g_reftrajFile);
1458
char filename[BUF_SIZE];
1460
for(i = 1; i < (g_orientAvg ? 4 : 2); i++) {
1462
snprintf(filename, BUF_SIZE, "%s/%d/polarizability.inp", g_ramanDir, i);
1464
sprintf(filename, "%s/%d/polarizability.inp", g_ramanDir, i);
1466
inputFile = fopen(filename, "w");
1467
if(inputFile == NULL) {
1468
mprintf(RED, "Could not open input file \"%s\": %s\n", filename, strerror(errno));
1472
fprintf(inputFile, "%s", g_inputTemplate);
1473
for(j = 0; j < 4; j++) {
1474
char *tempPos = g_inputTemplate;
1475
for(k = 0; k <= j; k++)
1476
tempPos = strchr(&tempPos[1], '\0');
1477
if(tempPos == g_templateFieldPos) {
1478
fprintf(inputFile, "%.6E", g_fieldStrength);
1479
fprintf(inputFile, "%s", &g_templateFieldPos[38]);
1480
} else if(tempPos == g_templatePolPos) {
1482
fprintf(inputFile, "1.0 0.0 0.0");
1484
fprintf(inputFile, "0.0 1.0 0.0");
1486
fprintf(inputFile, "0.0 0.0 1.0");
1487
fprintf(inputFile, "%s", &g_templatePolPos[43]);
1488
} else if(tempPos == g_templateCoordPos) {
1489
CTimeStep *ts = GetTimeStep(0);
1490
for(l = 0; l < g_iGesAtomCount; l++) {
1491
if(g_waAtomMolIndex[l] == 60000)
1493
fprintf(inputFile, " %s %14.10f %14.10f %14.10f\n", ((CAtom *)g_oaAtoms[g_waAtomRealElement[l]])->m_sName, ts->m_vaCoords_Original[l][0] / 100.0f, ts->m_vaCoords_Original[l][1] / 100.0f, ts->m_vaCoords_Original[l][2] / 100.0f);
1495
fprintf(inputFile, "%s", &g_templateCoordPos[36]);
1496
} else if(tempPos == g_templateStepsPos) {
1497
fprintf(inputFile, "%d", g_steps);
1498
fprintf(inputFile, "%s", &g_templateStepsPos[39]);
1500
mprintf(RED, "Unexpected error while processing the input template.\n");
1505
delete[] g_inputTemplate;
1507
for(i = 0; i < g_ramObserv.GetSize(); i++) {
1508
mprintf(YELLOW, ">>> Raman Observation %d >>>\n\n", i + 1);
1509
((CRamanObservation *)g_ramObserv[i])->finalize();
1510
mprintf(YELLOW, "\n<<< End of Raman Observation %d <<<\n\n", i + 1);
1513
for(i = 0; i < (g_orientAvg ? 3 : 1); i++)
1514
fclose(g_polFile[i]);
1515
for(i = 0; i < (g_orientAvg ? 3 : 1); i++)
1516
delete g_timestep[i];
1518
delete[] g_ramanDir;