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 Brehm.
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
*****************************************************************************/
25
#include "globalvar.h"
26
#include "maintools.h"
37
m_baDataEnabled = NULL;
46
void CXDF::ParseDeriv()
52
else m_iDeriv = AskUnsignedInteger(" Use values (0), 1st time derivative (1), or 2nd time derivative (2) of the values? [0] ",0);
57
m_bDerivAbs = AskYesNo(" Take the absolute values of the derivatives (y/n)? [no] ",false);
58
m_bACF = AskYesNo(" Autocorrelate derived values (y/n)? [no] ",false);
61
eprintf("\n This feature is not working yet.\n\n");
66
m_iACFDepth = AskUnsignedInteger(" Enter depth of the autocorrelation in time steps: [10000] ",10000);
67
ti = CalcFFTSize(m_iACFDepth,false);
68
if (m_iACFDepth != ti)
70
mprintf(WHITE,"\nThe next \"fast\" size for autocorrelation is %d. Using this instead of %d as depth.\n",ti,m_iACFDepth);
74
m_bACFFFT = AskYesNo(" Calculate the fourier transform of the autocorrelation (y/n)? [yes] ",true);
77
m_bWindowFunction = AskYesNo(" Apply window function (Cos^2) to Autocorrelation function (y/n)? [yes] ",true);
78
m_fSpecWaveNumber = AskFloat(" Calculate spectrum up to which wave number (cm^-1) (0=full spectrum)? [4000cm^-1] ",4000.0);
79
m_iMirror = AskUnsignedInteger(" No mirroring (0), short-time enhancing (1) or long-time enhancing (2)? [0] ",0);
80
m_iZeroPadding = AskUnsignedInteger(" Zero Padding: How many zeros to insert? [%d] ",m_iACFDepth*3,m_iACFDepth*3);
82
ti = CalcFFTSize(m_iACFDepth+m_iZeroPadding,false);
83
if (m_iACFDepth+m_iZeroPadding != ti)
85
mprintf(WHITE,"\nThe next \"fast\" size for FFT is %d. Using %d zeros for zero padding.\n",ti,ti-m_iACFDepth);
86
m_iZeroPadding = ti-m_iACFDepth;
89
m_bACF_DB = AskYesNo(" Convert intensity axis of spectrum to decibel (y/n)? [no] ",false);
96
void CXDF::InitDeriv()
101
try { m_pfaDerivBuffer = new CxDoubleArray*[3]; } catch(...) { m_pfaDerivBuffer = NULL; }
102
if (m_pfaDerivBuffer == NULL) NewException((double)3*sizeof(CxDoubleArray*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
106
try { m_pfaDerivBuffer[z2] = new CxDoubleArray("CXDF::m_pfaDerivBuffer[z2]"); } catch(...) { m_pfaDerivBuffer[z2] = NULL; }
107
if (m_pfaDerivBuffer[z2] == NULL) NewException((double)sizeof(CxDoubleArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
110
m_pfaDerivBuffer[z2]->SetSize(((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations);
111
else m_pfaDerivBuffer[z2]->SetSize(((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations);
118
try { m_pfaACFBuffer = new CxFloatArray*[((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations]; } catch(...) { m_pfaACFBuffer = NULL; }
119
if (m_pfaACFBuffer == NULL) NewException((double)((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations*sizeof(CxFloatArray*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
121
for (z2=0;z2<((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations;z2++)
123
try { ptfa = new CxFloatArray("CXDF::InitDeriv():ptfa"); } catch(...) { ptfa = NULL; }
124
if (ptfa == NULL) NewException((double)sizeof(CxFloatArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
126
if (g_iTrajSteps != -1)
128
ptfa->SetMaxSize((long)(g_iTrajSteps*1.1));
129
ptfa->SetGrow((long)(g_iTrajSteps*0.1));
130
} else ptfa->SetGrow(1000);
131
m_pfaACFBuffer[z2] = ptfa;
135
try { m_pfaACFBuffer = new CxFloatArray*[((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations]; } catch(...) { m_pfaACFBuffer = NULL; }
136
if (m_pfaACFBuffer == NULL) NewException((double)((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations*sizeof(CxFloatArray*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
138
for (z2=0;z2<((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations;z2++)
140
try { ptfa = new CxFloatArray("CXDF::InitDeriv():ptfa"); } catch(...) { ptfa = NULL; }
141
if (ptfa == NULL) NewException((double)sizeof(CxFloatArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
143
if (g_iTrajSteps != -1)
145
ptfa->SetMaxSize((long)(g_iTrajSteps*1.1));
146
ptfa->SetGrow((long)(g_iTrajSteps*0.1));
147
} else ptfa->SetGrow(1000);
148
m_pfaACFBuffer[z2] = ptfa;
155
void CXDF::Autocorrelate()
159
CAutoCorrelation *ac;
163
n = ((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations;
164
else n = ((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations;
167
mprintf(" Autocorrelating cached values...\n");
170
try { ptfa = new CxFloatArray("CXDF::Autocorrelate():ptfa"); } catch(...) { ptfa = NULL; }
171
if (ptfa == NULL) NewException((double)sizeof(CxFloatArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
173
ptfa->SetSize(m_pfaACFBuffer[0]->GetSize());
175
try { ac = new CAutoCorrelation(); } catch(...) { ac = NULL; }
176
if (ac == NULL) NewException((double)sizeof(CAutoCorrelation),__FILE__,__LINE__,__PRETTY_FUNCTION__);
178
ac->Init(m_pfaACFBuffer[0]->GetSize(),m_iACFDepth,true);
179
m_faACF.SetSize(m_iACFDepth);
180
for (z=0;z<m_iACFDepth;z++)
184
if (fmod(z,tfs) < 1.0)
187
ac->AutoCorrelate(m_pfaACFBuffer[z],ptfa);
188
for (z2=0;z2<m_iACFDepth;z2++)
189
m_faACF[z2] += (double)(*ptfa)[z2];
193
for (z=1;z<m_iACFDepth;z++)
194
m_faACF[z] /= m_faACF[0];
196
mprintf(WHITE,"]\n");
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 Brehm.
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
*****************************************************************************/
25
#include "globalvar.h"
26
#include "maintools.h"
37
m_baDataEnabled = NULL;
46
void CXDF::ParseDeriv()
52
else m_iDeriv = AskUnsignedInteger(" Use values (0), 1st time derivative (1), or 2nd time derivative (2) of the values? [0] ",0);
57
m_bDerivAbs = AskYesNo(" Take the absolute values of the derivatives (y/n)? [no] ",false);
58
m_bACF = AskYesNo(" Autocorrelate derived values (y/n)? [no] ",false);
61
eprintf("\n This feature is not working yet.\n\n");
66
m_iACFDepth = AskUnsignedInteger(" Enter depth of the autocorrelation in time steps: [10000] ",10000);
67
ti = CalcFFTSize(m_iACFDepth,false);
68
if (m_iACFDepth != ti)
70
mprintf(WHITE,"\nThe next \"fast\" size for autocorrelation is %d. Using this instead of %d as depth.\n",ti,m_iACFDepth);
74
m_bACFFFT = AskYesNo(" Calculate the fourier transform of the autocorrelation (y/n)? [yes] ",true);
77
m_bWindowFunction = AskYesNo(" Apply window function (Cos^2) to Autocorrelation function (y/n)? [yes] ",true);
78
m_fSpecWaveNumber = AskFloat(" Calculate spectrum up to which wave number (cm^-1) (0=full spectrum)? [4000cm^-1] ",4000.0);
79
m_iMirror = AskUnsignedInteger(" No mirroring (0), short-time enhancing (1) or long-time enhancing (2)? [0] ",0);
80
m_iZeroPadding = AskUnsignedInteger(" Zero Padding: How many zeros to insert? [%d] ",m_iACFDepth*3,m_iACFDepth*3);
82
ti = CalcFFTSize(m_iACFDepth+m_iZeroPadding,false);
83
if (m_iACFDepth+m_iZeroPadding != ti)
85
mprintf(WHITE,"\nThe next \"fast\" size for FFT is %d. Using %d zeros for zero padding.\n",ti,ti-m_iACFDepth);
86
m_iZeroPadding = ti-m_iACFDepth;
89
m_bACF_DB = AskYesNo(" Convert intensity axis of spectrum to decibel (y/n)? [no] ",false);
96
void CXDF::InitDeriv()
101
try { m_pfaDerivBuffer = new CxDoubleArray*[3]; } catch(...) { m_pfaDerivBuffer = NULL; }
102
if (m_pfaDerivBuffer == NULL) NewException((double)3*sizeof(CxDoubleArray*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
106
try { m_pfaDerivBuffer[z2] = new CxDoubleArray("CXDF::m_pfaDerivBuffer[z2]"); } catch(...) { m_pfaDerivBuffer[z2] = NULL; }
107
if (m_pfaDerivBuffer[z2] == NULL) NewException((double)sizeof(CxDoubleArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
110
m_pfaDerivBuffer[z2]->SetSize(((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations);
111
else m_pfaDerivBuffer[z2]->SetSize(((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations);
118
try { m_pfaACFBuffer = new CxFloatArray*[((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations]; } catch(...) { m_pfaACFBuffer = NULL; }
119
if (m_pfaACFBuffer == NULL) NewException((double)((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations*sizeof(CxFloatArray*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
121
for (z2=0;z2<((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations;z2++)
123
try { ptfa = new CxFloatArray("CXDF::InitDeriv():ptfa"); } catch(...) { ptfa = NULL; }
124
if (ptfa == NULL) NewException((double)sizeof(CxFloatArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
126
if (g_iTrajSteps != -1)
128
ptfa->SetMaxSize((long)(g_iTrajSteps*1.1));
129
ptfa->SetGrow((long)(g_iTrajSteps*0.1));
130
} else ptfa->SetGrow(1000);
131
m_pfaACFBuffer[z2] = ptfa;
135
try { m_pfaACFBuffer = new CxFloatArray*[((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations]; } catch(...) { m_pfaACFBuffer = NULL; }
136
if (m_pfaACFBuffer == NULL) NewException((double)((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations*sizeof(CxFloatArray*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
138
for (z2=0;z2<((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations;z2++)
140
try { ptfa = new CxFloatArray("CXDF::InitDeriv():ptfa"); } catch(...) { ptfa = NULL; }
141
if (ptfa == NULL) NewException((double)sizeof(CxFloatArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
143
if (g_iTrajSteps != -1)
145
ptfa->SetMaxSize((long)(g_iTrajSteps*1.1));
146
ptfa->SetGrow((long)(g_iTrajSteps*0.1));
147
} else ptfa->SetGrow(1000);
148
m_pfaACFBuffer[z2] = ptfa;
155
void CXDF::Autocorrelate()
159
CAutoCorrelation *ac;
163
n = ((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*m_iCombinations;
164
else n = ((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()*((CMolecule*)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex.GetSize()*m_iCombinations;
167
mprintf(" Autocorrelating cached values...\n");
170
try { ptfa = new CxFloatArray("CXDF::Autocorrelate():ptfa"); } catch(...) { ptfa = NULL; }
171
if (ptfa == NULL) NewException((double)sizeof(CxFloatArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
173
ptfa->SetSize(m_pfaACFBuffer[0]->GetSize());
175
try { ac = new CAutoCorrelation(); } catch(...) { ac = NULL; }
176
if (ac == NULL) NewException((double)sizeof(CAutoCorrelation),__FILE__,__LINE__,__PRETTY_FUNCTION__);
178
ac->Init(m_pfaACFBuffer[0]->GetSize(),m_iACFDepth,true);
179
m_faACF.SetSize(m_iACFDepth);
180
for (z=0;z<m_iACFDepth;z++)
184
if (fmod(z,tfs) < 1.0)
187
ac->AutoCorrelate(m_pfaACFBuffer[z],ptfa);
188
for (z2=0;z2<m_iACFDepth;z2++)
189
m_faACF[z2] += (double)(*ptfa)[z2];
193
for (z=1;z<m_iACFDepth;z++)
194
m_faACF[z] /= m_faACF[0];
196
mprintf(WHITE,"]\n");