~ubuntu-branches/ubuntu/trusty/travis/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gather.cpp

  • Committer: Package Import Robot
  • Author(s): Daniel Leidert
  • Date: 2014-01-18 20:07:16 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140118200716-whsmcg7fa1eyqecq
Tags: 140117-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
    TRAVIS - Trajectory Analyzer and Visualizer
3
 
    http://www.travis-analyzer.de/
4
 
 
5
 
    Copyright (c) 2009-2013 Martin Brehm
6
 
                  2012-2013 Martin Thomas
7
 
 
8
 
    This file written by Martin Brehm.
9
 
 
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.
14
 
 
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.
19
 
 
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
 
*****************************************************************************/
23
 
 
24
 
 
25
 
#include "travis.h"
26
 
#include "tools.h"
27
 
#include "database.h"
28
 
#include "statistics.h"
29
 
#include "maintools.h"
30
 
#include "dacf.h"
31
 
#include "interface.h"
 
1
/*****************************************************************************
 
2
    TRAVIS - Trajectory Analyzer and Visualizer
 
3
    http://www.travis-analyzer.de/
 
4
 
 
5
    Copyright (c) 2009-2014 Martin Brehm
 
6
                  2012-2014 Martin Thomas
 
7
 
 
8
    This file written by Martin Brehm.
 
9
 
 
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.
 
14
 
 
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.
 
19
 
 
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
*****************************************************************************/
 
23
 
 
24
 
 
25
#include "travis.h"
 
26
#include "tools.h"
 
27
#include "database.h"
 
28
#include "statistics.h"
 
29
#include "maintools.h"
 
30
#include "dacf.h"
 
31
#include "interface.h"
32
32
#include "structurefactor.h"
33
 
 
34
 
 
35
 
bool GatherInfos()
36
 
{
37
 
        BTIN;
38
 
        char buf[4096], buf2[256];
39
 
        float tf, tf2;
40
 
        FILE *a;
41
 
        bool tb=false, tb2;
42
 
        int z, z0, z2, z3, z4, z5, z6, z7;
43
 
        int ti, ti2, ti3;
44
 
        unsigned char ty, rty, atom;
45
 
        unsigned char ty2, rty2, atom2;
46
 
        CVirtualAtom *va;
47
 
        CObservation *o;
48
 
        CMolecule *mol;
49
 
        CSingleMolecule *sm, *sm2;
50
 
        CAtomGroup *ag;
51
 
        CxWordArray tempwa;
52
 
        CMolecule *m, *m2;
53
 
        CAtom *at;
54
 
        CElement *el;
55
 
        CxIntArray *pia, ia;
56
 
 
57
 
        g_bKeepUnfoldedCoords = false;
58
 
        g_iDoubleBoxFactor = 1;
59
 
        g_bBondACF = false;
60
 
        g_bCombined = false;
61
 
        g_bRefEnvFix = false;
62
 
        g_bTimeDiff = false;
63
 
        g_bRemoveCOM = false;
64
 
        g_bSaveCoordsUnchanged = false;
65
 
        g_bSDFUniform = false;
66
 
        a = NULL;
67
 
        ti2 = -1;
68
 
 
69
 
        mprintf(YELLOW,"\n*** Interactive query of settings ***\n\n");
70
 
//      SAVEPOS;
71
 
 
72
 
        ti = 0;
73
 
        if (g_bUnknownElements)
74
 
        {
75
 
                tb2 = false;
76
 
_unkstart:
77
 
                tb = false;
78
 
                mprintf(WHITE,"Unrecognized atom types: ");
79
 
                for (z=0;z<g_oaAtoms.GetSize();z++)
80
 
                {
81
 
                        if (z == g_iVirtAtomType)
82
 
                                continue;
83
 
 
84
 
                        at = (CAtom*)g_oaAtoms[z];
85
 
                        while (at->m_pMergedTo != NULL)
86
 
                        {
87
 
//                              mprintf("%s merged to %s\n",at->m_sName,at->m_pMergedTo->m_sName);
88
 
                                at = at->m_pMergedTo;
89
 
                        }
90
 
                        if (at->m_pElement->m_fRadius != 0)
91
 
                                continue;
92
 
                        if (tb)
93
 
                                mprintf(", ");
94
 
                        tb = true;
95
 
                        mprintf("%s",at->m_sName);
96
 
                        ti++;
97
 
                        ti2 = z;
98
 
                }
99
 
                mprintf("\n\n");
100
 
 
101
 
                if ((ti == 1) && (mystricmp("X",((CAtom*)g_oaAtoms[ti2])->m_sName) == 0))
102
 
                {  // Only Wannier centers unrecognized.
103
 
                        mprintf("    Possibly, atom type \"X\" are Wannier centers. If so, do not assign data to them.\n\n");
104
 
                        tb2 = false; 
105
 
                } else tb2 = true;
106
 
 
107
 
                tb = false;
108
 
                if (AskYesNo("    Do you want to assign atom data to them (y/n)? [%s] ",tb2,tb2?"yes":"no"))
109
 
                {
110
 
                        if (tb2)
111
 
                        {
112
 
                                if (AskYesNo("    Automatically rename all atoms to corresponding elements (y/n)? [yes] ",true))
113
 
                                {
114
 
                                        mprintf("\n");
115
 
                                        tb2 = true;
116
 
                                        tb = false;
117
 
                                        for (z=0;z<g_oaAtoms.GetSize();z++)
118
 
                                        {
119
 
                                                if (z == g_iVirtAtomType)
120
 
                                                        continue;
121
 
 
122
 
                                                at = (CAtom*)g_oaAtoms[z];
123
 
                                                if (at->m_pElement->m_fRadius != 0)
124
 
                                                        continue;
125
 
 
126
 
                                                buf2[0] = at->m_sName[0];
127
 
                                                buf2[1] = at->m_sName[1];
128
 
                                                buf2[2] = 0;
129
 
                                                el = FindElement(buf2,true);
130
 
                                                if (el != NULL)
131
 
                                                {
132
 
                                                        if (el->m_fRadius == 0)
133
 
                                                                goto _unkX2;
134
 
                                                } else
135
 
                                                {
136
 
_unkX2:
137
 
                                                        buf2[1] = 0;
138
 
                                                        el = FindElement(buf2,true);
139
 
                                                        if (el != NULL)
140
 
                                                        {
141
 
                                                                if (el->m_fRadius == 0)
142
 
                                                                        goto _unkX3;
143
 
                                                        } else
144
 
                                                        {
145
 
_unkX3:
146
 
                                                                strcpy(buf2,at->m_sName);
147
 
                                                        }
148
 
                                                }
149
 
                                                if (el == NULL)
150
 
                                                {
151
 
                                                        mprintf("    - Skipping %s... (have no guess for atom type)\n",at->m_sName);
152
 
                                                        tb = true;
153
 
                                                        continue;
154
 
                                                }
155
 
 
156
 
                                                xAddAtom(buf2);
157
 
 
158
 
                                                mprintf("    - Renaming %s to %s...\n",at->m_sName,buf2);
159
 
                                                for (z2=0;z2<g_oaAtoms.GetSize();z2++)
160
 
                                                {
161
 
                                                        if (((CAtom*)g_oaAtoms[z2])->m_pElement == el)
162
 
                                                        {
163
 
                                                                at = (CAtom*)g_oaAtoms[z2];
164
 
                                                                el = at->m_pElement;
165
 
                                                                goto _unkX1;
166
 
                                                        }
167
 
                                                }
168
 
                                                eprintf("    Strange error ^^\n");
169
 
_unkX1:;
170
 
                                                for (z2=0;z2<(int)g_TimeStep.m_iGesAtomCount;z2++)
171
 
                                                {
172
 
                                                        strcpy(buf,(char*)g_TimeStep.m_paLabels[z2]);
173
 
                                                        ReplaceDigits(buf);
174
 
                                                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
175
 
                                                        {
176
 
                                                                at->m_iCount++;
177
 
                                                                ((CAtom*)g_oaAtoms[z])->m_iCount--;
178
 
                                                        }
179
 
                                                }
180
 
//                                              mprintf("\nmerging %s to %s.\n",((CAtom*)g_oaAtoms[z])->m_sName,at->m_sName);
181
 
                                                ((CAtom*)g_oaAtoms[z])->m_pMergedTo = at;
182
 
                                        }
183
 
                                        if (tb)
184
 
                                        {
185
 
                                                mprintf("\n");
186
 
                                                goto _unkstart;
187
 
                                        }
188
 
                                        tb = false;
189
 
                                        goto _unkdone;
190
 
                                }
191
 
                        }
192
 
                        ti = g_oaAtoms.GetSize();
193
 
                        for (z=0;z<ti;z++)
194
 
                        {
195
 
                                if (z == g_iVirtAtomType)
196
 
                                        continue;
197
 
 
198
 
                                at = (CAtom*)g_oaAtoms[z];
199
 
                                
200
 
                                while (at->m_pMergedTo != NULL)
201
 
                                {
202
 
//                                      mprintf("%s merged to %s\n",at->m_sName,at->m_pMergedTo->m_sName);
203
 
                                        at = at->m_pMergedTo;
204
 
                                }
205
 
 
206
 
                                if (at->m_pElement->m_fRadius != 0)
207
 
                                        continue;
208
 
                                mprintf(WHITE,"\n  * Element %s\n\n",at->m_sName);
209
 
 
210
 
                                buf2[0] = at->m_sName[0];
211
 
                                buf2[1] = at->m_sName[1];
212
 
                                buf2[2] = 0;
213
 
                                el = FindElement(buf2,true);
214
 
                                if (el != NULL)
215
 
                                {
216
 
                                        if (el->m_fRadius == 0)
217
 
                                                goto _unk2;
218
 
                                } else
219
 
                                {
220
 
_unk2:
221
 
                                        buf2[1] = 0;
222
 
                                        el = FindElement(buf2,true);
223
 
                                        if (el != NULL)
224
 
                                        {
225
 
                                                if (el->m_fRadius == 0)
226
 
                                                        goto _unk3;
227
 
                                        } else
228
 
                                        {
229
 
_unk3:
230
 
                                                strcpy(buf2,at->m_sName);
231
 
                                        }
232
 
                                }
233
 
 
234
 
                                if (AskYesNo("    Do you want to rename this element (y/n)? [yes] ",true))
235
 
                                {
236
 
_unk5:
237
 
                                        AskString("    Enter new name for %s: [%s] ",buf,buf2,at->m_sName,buf2);
238
 
                                        if (strlen(buf) > 7)
239
 
                                        {
240
 
                                                eprintf("Atom labels may have maximum length of 7 characters.\n");
241
 
                                                goto _unk5;
242
 
                                        }
243
 
                                        if (ContainsDigit(buf))
244
 
                                        {
245
 
                                                eprintf("Digits in element labels not allowed.\n");
246
 
                                                goto _unk5;
247
 
                                        }
248
 
                                        el = FindElement(buf,true);
249
 
                                        if (el != NULL)
250
 
                                        {
251
 
                                                xAddAtom(buf);
252
 
                                                if (AskYesNo("    Element %s is known. Merge %s atoms into %s (y/n)? [yes] ",true,buf,at->m_sName,buf))
253
 
                                                {
254
 
                                                        for (z2=0;z2<g_oaAtoms.GetSize();z2++)
255
 
                                                        {
256
 
                                                                if (((CAtom*)g_oaAtoms[z2])->m_pElement == el)
257
 
                                                                {
258
 
                                                                        at = (CAtom*)g_oaAtoms[z2];
259
 
                                                                        el = at->m_pElement;
260
 
                                                                        goto _unk1;
261
 
                                                                }
262
 
                                                        }
263
 
                                                        eprintf("    Strange error ^^\n");
264
 
_unk1:;
265
 
                                                }
266
 
                                        } else
267
 
                                        {
268
 
                                                mprintf("      Adding element %s...",buf);
269
 
 
270
 
                                                try { at = new CAtom(); } catch(...) { at = NULL; }
271
 
                                                if (at == NULL) NewException((double)sizeof(CAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
272
 
                                                
273
 
                                                at->m_iIndex = g_oaAtoms.GetSize();
274
 
                                                g_oaAtoms.Add(at);
275
 
 
276
 
                                                try { at->m_pElement = new CElement(); } catch(...) { at->m_pElement = NULL; }
277
 
                                                if (at->m_pElement == NULL) NewException((double)sizeof(CElement),__FILE__,__LINE__,__PRETTY_FUNCTION__);
278
 
                                                
279
 
                                                el = at->m_pElement;
280
 
                                                sprintf(at->m_sName,"%s",buf);
281
 
                                        }
282
 
                                        for (z2=0;z2<(int)g_TimeStep.m_iGesAtomCount;z2++)
283
 
                                        {
284
 
                                                strcpy(buf,(char*)g_TimeStep.m_paLabels[z2]);
285
 
                                                ReplaceDigits(buf);
286
 
                                                if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
287
 
                                                {
288
 
                                                        at->m_iCount++;
289
 
                                                        ((CAtom*)g_oaAtoms[z])->m_iCount--;
290
 
                                                }
291
 
                                        }
292
 
                                        ((CAtom*)g_oaAtoms[z])->m_pMergedTo = at;
293
 
                                        if (el->m_fRadius != 0)
294
 
                                                continue;
295
 
                                } // END IF RENAME
296
 
 
297
 
                                if (AskYesNo("    Do you want to copy the atom parameters from another element (y/n)? [yes] ",true))
298
 
                                {
299
 
_unk4:
300
 
                                        AskString("    Copy atom parameters from which element? [%s] ",buf,buf2,buf2);
301
 
                                        el = FindElement(buf,true);
302
 
                                        if (el == NULL)
303
 
                                        {
304
 
                                                eprintf("This element is not defined.\n");
305
 
                                                goto _unk4;
306
 
                                        }
307
 
                                        if (el->m_fRadius == 0)
308
 
                                        {
309
 
                                                if (!AskYesNo("    This element has a radius of 0 (will form no bonds). Use it anyway (y/n)? [yes] ",true))
310
 
                                                        goto _unk4;
311
 
                                        }
312
 
 
313
 
                                        mprintf(WHITE,"\n    A covalent radius of 0 pm hinders atoms of this kind from forming any bonds.\n\n");
314
 
 
315
 
                                        at->m_pElement->m_fRadius = AskFloat("    Please enter covalent radius in pm: [%.2f] ",el->m_fRadius,el->m_fRadius);
316
 
                                        at->m_pElement->m_fMass = AskFloat("    Please enter atom mass in u: [%.2f] ",el->m_fMass,el->m_fMass);
317
 
        
318
 
                                        if (!tb && (fabs(at->m_pElement->m_fMass-el->m_fMass) < 0.01))
319
 
                                        {
320
 
                                                tb = true;
321
 
                                                mprintf(RED,"\n    Warning: ");
322
 
                                                mprintf("Elements %s and %s keep their different labels, but will have\n",at->m_sName,buf);
323
 
                                                mprintf("             the same mass and therefore also the same atom codes. They will not\n");
324
 
                                                mprintf("             be distinguished in the molecule recognition!\n");
325
 
                                        }
326
 
//                                      mprintf("    Using mass=%.2fu, radius=%.2fpm, ord. number=%d.\n",at->m_pElement->m_fMass,el->m_fRadius,el->m_iOrd);
327
 
//                                      at->m_pElement->CopyData(el);
328
 
                                } else
329
 
                                {
330
 
                                        el = FindElement(buf2,true);
331
 
                                        mprintf(WHITE,"\n    A covalent radius of 0 pm hinders atoms of this kind from forming any bonds.\n\n");
332
 
                                        if (el != NULL)
333
 
                                        {
334
 
                                                mprintf("    (Default values are for %s)\n\n",buf2);
335
 
                                                at->m_pElement->m_fRadius = AskFloat("    Please enter covalent radius in pm: [%.2f] ",el->m_fRadius,el->m_fRadius);
336
 
                                                at->m_pElement->m_fMass = AskFloat("    Please enter atom mass in u: [%.2f] ",el->m_fMass,el->m_fMass);
337
 
                                        } else
338
 
                                        {
339
 
                                                at->m_pElement->m_fRadius = AskFloat("    Please enter covalent radius in pm: [100] ",100);
340
 
                                                at->m_pElement->m_fMass = AskFloat_ND("    Please enter atom mass in u: ");
341
 
                                        }
342
 
                                }
343
 
                        }
344
 
_unkdone:
345
 
                        mprintf("\n");
346
 
                        mprintf(WHITE,"%d atoms in the system: ",g_iGesAtomCount);
347
 
 
348
 
                        for (z=0;z<g_oaAtoms.GetSize();z++)
349
 
                        {
350
 
                                if (z == g_iVirtAtomType)
351
 
                                        continue;
352
 
                                if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
353
 
                                        continue;
354
 
                                mprintf("%dx %s",((CAtom*)g_oaAtoms[z])->m_iCount,((CAtom*)g_oaAtoms[z])->m_sName);
355
 
                                if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
356
 
                                        mprintf(" (merged to %s)",((CAtom*)g_oaAtoms[z])->m_pMergedTo->m_sName);
357
 
                                if (z < (int)g_oaAtoms.GetSize()-1)
358
 
                                        if (z+1 != g_iVirtAtomType)
359
 
                                                mprintf(", ");
360
 
                        }
361
 
                        mprintf("\n");
362
 
                } // END IF CHANGE UNKNOWN
363
 
                mprintf("\n");
364
 
        } // END IF UNKNOWN
365
 
 
366
 
        ia.RemoveAll();
367
 
        tb2 = false;
368
 
        for (z=0;z<g_oaAtoms.GetSize();z++)
369
 
        {
370
 
                tb = false;
371
 
                for (z3=0;z3<ia.GetSize();z3++)
372
 
                {
373
 
                        if (z == ia[z3])
374
 
                                goto _next;
375
 
                }
376
 
                if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
377
 
                        continue;
378
 
                if (z == g_iVirtAtomType)
379
 
                        continue;
380
 
                for (z2=z+1;z2<g_oaAtoms.GetSize();z2++)
381
 
                {
382
 
                        if (((CAtom*)g_oaAtoms[z2])->m_pMergedTo != NULL)
383
 
                                continue;
384
 
                        if (z2 == g_iVirtAtomType)
385
 
                                continue;
386
 
                        if (fabs(((CAtom*)g_oaAtoms[z])->m_pElement->m_fMass - ((CAtom*)g_oaAtoms[z2])->m_pElement->m_fMass) < 0.01)
387
 
                        {
388
 
                                if (!tb)
389
 
                                {
390
 
                                        tb = true;
391
 
                                        tb2 = true;
392
 
                                        mprintf(RED,"\n    Warning: ");
393
 
                                        mprintf("The following atoms have the same mass and will therefore not be\n");
394
 
                                        mprintf("             distinguished in the molecule recognition:\n\n");
395
 
                                        mprintf(WHITE,"      Mass=%.2f: %s, %s",((CAtom*)g_oaAtoms[z])->m_pElement->m_fMass,((CAtom*)g_oaAtoms[z])->m_sName,((CAtom*)g_oaAtoms[z2])->m_sName);
396
 
                                        ia.Add(z);
397
 
                                        ia.Add(z2);
398
 
                                } else
399
 
                                {
400
 
                                        mprintf(WHITE,", %s",((CAtom*)g_oaAtoms[z2])->m_sName);
401
 
                                }
402
 
                        }
403
 
                }
404
 
                if (tb)
405
 
                        mprintf("\n");
406
 
_next:;
407
 
        }
408
 
        if (tb2)
409
 
                mprintf("\n");
410
 
 
411
 
        mprintf("    The advanced mode includes some options which are quite powerful,\n    yet possibly weird or seldomly required. ");
412
 
        mprintf("This includes support for\n    NPT ensemble, non-periodic systems, user-definded virtual atoms, pseudomolecules, ...\n\n");
413
 
 
414
 
        g_bAdvanced1 = AskYesNo("    Use the advanced mode up to the function selection menu (y/n)? [no] ",false);
415
 
 
416
 
        mprintf("\n");
417
 
 
418
 
        if (g_bAdvanced1)
419
 
        {
420
 
                do
421
 
                {
422
 
                        mprintf("    Use periodic boundary conditions (0=no, x, y, z, xy, xz, xyz)? [xyz] ");
423
 
                        inpprintf("! Use periodic boundary conditions (0=no, x, y, z, xy, xz, xyz)? [xyz]\n");
424
 
                        myget(buf);
425
 
                } while (!ParsePeriodic(buf));
426
 
 
427
 
                if (!g_bPeriodic)
428
 
                {
429
 
/*                      if (AskYesNo("    Enter Box Size anyways (e.g. fo RDFs) (yes/no)? [yes] ",true))
430
 
                        {
431
 
                                goto _askbox;
432
 
                        } else
433
 
                        {
434
 
                                g_fBoxX = GuessBoxSize();
435
 
                                g_fBoxY = GuessBoxSize();
436
 
                                g_fBoxZ = GuessBoxSize();
437
 
                                mprintf("\nGuessed box size (for density 1.0 g/cm^3) is %.2f x %.2f x %.2f pm.\n\n",g_fBoxX,g_fBoxX,g_fBoxX);
438
 
                        }*/
439
 
//                      g_fBoxX = (g_TimeStep.m_vMax[0]-g_TimeStep.m_vMin[0])*10.0;
440
 
//                      g_fBoxY = (g_TimeStep.m_vMax[1]-g_TimeStep.m_vMin[1])*10.0;
441
 
//                      g_fBoxZ = (g_TimeStep.m_vMax[2]-g_TimeStep.m_vMin[2])*10.0;
442
 
//                      mprintf("\n    Using cell vector of %.2f x %.2f x %.2f pm to \"fake\" non-periodic box.\n\n",g_fBoxX,g_fBoxY,g_fBoxZ);
443
 
                }
444
 
        } else
445
 
                ParsePeriodic("xyz");
446
 
 
447
 
        if (g_bPeriodic)
448
 
        {
449
 
                tf = GuessBoxSize();
450
 
                mprintf("    A cell vector of %.2f pm would result in a density of 1.0 g/cm^3.\n\n",tf);
451
 
                if (g_bAdvanced1)
452
 
                {
453
 
                        g_bNPT = AskYesNo("    Use time-dependent cell vector (NPT ensemble) (y/n)? [no] ",false);
454
 
                        mprintf("\n");
455
 
                } else g_bNPT = false;
456
 
 
457
 
                if (g_bNPT)
458
 
                {
459
 
                        if (g_fBoxX != 0)
460
 
                        {
461
 
                                mprintf("    Your PDB file contains cell vector information.\n\n");
462
 
                        } else
463
 
                        {
464
 
                                mprintf("    The trajectory does not contain cell vector information.\n");
465
 
                                mprintf("    (supported: PDB file with \"CRYST1\" section, like written by GROMACS trjconv)\n");
466
 
                                mprintf("    You have to supply a plain text file which contains the cell vectors for each step.\n");
467
 
                                mprintf("    It should contain three space-separated floating point numbers (X, Y, Z vector) per line.\n");
468
 
                                mprintf("    These numbers need to be IN ANGSTROM! (1 angstrom = 100 pm)\n\n");
469
 
_nptfileagain:
470
 
                                AskString_ND("    Please enter cell vector text file name: ",g_sNPTFile);
471
 
                                if (!FileExist(g_sNPTFile))
472
 
                                {
473
 
                                        eprintf("Could not open file \"%s\" for reading.\n",g_sNPTFile);
474
 
                                        goto _nptfileagain;
475
 
                                }
476
 
                                g_fNPTFile = fopen(g_sNPTFile,"rt");
477
 
                                g_TimeStep.ReadCellVector(g_fNPTFile);
478
 
                                fclose(g_fNPTFile);
479
 
                                mprintf("\n");
480
 
                        }
481
 
                        mprintf("    The initial cell vector is ( %.2f pm | %.2f pm | %.2f pm ).\n",g_fBoxX,g_fBoxY,g_fBoxZ);
482
 
                        mprintf("    The initial box density is %.6f g/cm^3.\n\n",tf*tf*tf/g_fBoxX/g_fBoxY/g_fBoxZ);
483
 
                } else
484
 
                {
485
 
                        if (g_fBoxX != 0)
486
 
                        {
487
 
                                mprintf("    Cell vector found in trajectory file:\n");
488
 
                                mprintf("      X = %.2f pm,   Y = %.2f pm,   Z = %.2f pm\n\n",g_fBoxX,g_fBoxY,g_fBoxZ);
489
 
                                if (AskYesNo("    Use these values (y/n)? [yes] ",true))
490
 
                                        goto _celldone;
491
 
                        }
492
 
_askbox:
493
 
                        if (!AskYesNo("    Are the 3 cell vectors of the same size (yes/no)? [yes] ",true))
494
 
                        {
495
 
                                if (g_bPeriodicX)
496
 
                                        g_fBoxX = AskFloat_ND("    Enter length of X cell vector in pm: ");
497
 
                                if (g_bPeriodicY)
498
 
                                        g_fBoxY = AskFloat_ND("    Enter length of Y cell vector in pm: ");
499
 
                                if (g_bPeriodicZ)
500
 
                                        g_fBoxZ = AskFloat_ND("    Enter length of Z cell vector in pm: ");
501
 
                        } else
502
 
                        {
503
 
                                g_fBoxX = AskFloat_ND("    Enter length of cell vector in pm: ");
504
 
                                g_fBoxY = g_fBoxX;
505
 
                                g_fBoxZ = g_fBoxX;
506
 
                        }
507
 
                        if ((g_fBoxX <= 0) || (g_fBoxY <= 0) || (g_fBoxZ <= 0))
508
 
                        {
509
 
                                eprintf("Cell vector of length <= 0 is not allowed.\n");
510
 
                                goto _askbox;
511
 
                        }
512
 
_celldone:
513
 
                        if (g_bPeriodicX && g_bPeriodicY && g_bPeriodicZ)
514
 
                        {
515
 
                                mprintf("\n    The box size is %.2f x %.2f x %.2f pm.\n",g_fBoxX,g_fBoxY,g_fBoxZ);
516
 
                                mprintf("    The overall box density is %.6f g/cm^3.\n",tf*tf*tf/g_fBoxX/g_fBoxY/g_fBoxZ);
517
 
                                if (tf*tf*tf/g_fBoxX/g_fBoxY/g_fBoxZ > 15.0f)
518
 
                                {
519
 
                                        mprintf("\n");
520
 
                                        if (!AskYesNo("    The density of your box seems to be very high. Continue (y) or change input (n)? [n] ",false))
521
 
                                        {
522
 
                                                mprintf("\n");
523
 
                                                goto _askbox;
524
 
                                        }
525
 
                                        mprintf("\n");
526
 
                                }
527
 
                        }
528
 
                }
529
 
 
530
 
                if (g_bAdvanced1 && g_bPeriodic)
531
 
                {
532
 
                        mprintf("\n");
533
 
                        if (AskYesNo("    Should the periodic box be multiplied (y/n)? [no] ",false))
534
 
                        {
535
 
                                mprintf("\n");
536
 
                                g_bDoubleBox = true;
537
 
 
538
 
                                if (g_bPeriodicX)
539
 
                                        g_iDoubleBoxX = AskUnsignedInteger("    Replicate the box n times in x direction: [2] ",2);
540
 
                                                else g_iDoubleBoxX = 1;
541
 
 
542
 
                                if (g_bPeriodicY)
543
 
                                        g_iDoubleBoxY = AskUnsignedInteger("    Replicate the box n times in y direction: [2] ",2);
544
 
                                                else g_iDoubleBoxY = 1;
545
 
 
546
 
                                if (g_bPeriodicZ)
547
 
                                        g_iDoubleBoxZ = AskUnsignedInteger("    Replicate the box n times in z direction: [2] ",2);
548
 
                                                else g_iDoubleBoxZ = 1;
549
 
 
550
 
                                g_iDoubleBoxFactor = g_iDoubleBoxX * g_iDoubleBoxY * g_iDoubleBoxZ;
551
 
                                g_fBoxX *= g_iDoubleBoxX;
552
 
                                g_fBoxY *= g_iDoubleBoxY;
553
 
                                g_fBoxZ *= g_iDoubleBoxZ;
554
 
                                g_iGesAtomCount *= g_iDoubleBoxFactor;
555
 
                                g_iGesVirtAtomCount *= g_iDoubleBoxFactor;
556
 
                        } else g_bDoubleBox = false;
557
 
                } else g_bDoubleBox = false;
558
 
        } else g_bDoubleBox = false;
559
 
 
560
 
        try { g_pUniteTemp = new bool[g_iGesAtomCount]; } catch(...) { g_pUniteTemp = NULL; }
561
 
        if (g_pUniteTemp == NULL) NewException((double)g_iGesAtomCount*sizeof(bool),__FILE__,__LINE__,__PRETTY_FUNCTION__);
562
 
 
563
 
        if (!g_bPeriodic)
564
 
                g_bNPT = false;
565
 
 
566
 
        if (g_bPeriodic)
567
 
        {
568
 
                g_fMinPeriodic = 1e30f;
569
 
                if (g_bPeriodicX)
570
 
                        if (g_fMinPeriodic > g_fBoxX)
571
 
                                g_fMinPeriodic = g_fBoxX;
572
 
                if (g_bPeriodicY)
573
 
                        if (g_fMinPeriodic > g_fBoxY)
574
 
                                g_fMinPeriodic = g_fBoxY;
575
 
                if (g_bPeriodicZ)
576
 
                        if (g_fMinPeriodic > g_fBoxZ)
577
 
                                g_fMinPeriodic = g_fBoxZ;
578
 
        }
579
 
 
580
 
//      SAVEPOS;
581
 
_molbegin:
582
 
        if (!g_bStreamInput)
583
 
        {
584
 
                if (g_bAdvanced1)
585
 
                {
586
 
                        mprintf("\n");
587
 
                        g_iScanMolStep = AskInteger("    Execute molecule recognition for which time step (-1 = disable)? [0] ",0);
588
 
                } else g_iScanMolStep = 0;
589
 
 
590
 
                a = fopen(g_sInputTraj,"rb");
591
 
                if ((g_bNPT) && (g_sNPTFile[0] != 0))
592
 
                        g_fNPTFile = fopen(g_sNPTFile,"rt");
593
 
                if (g_iScanMolStep > 0)
594
 
                {
595
 
                        mprintf("    Fast-forwarding to step %d...\n",g_iScanMolStep);
596
 
                        mprintf(WHITE,"      [");
597
 
                        for (z=0;z<g_iScanMolStep;z++)
598
 
                        {
599
 
                                if ((g_bNPT) && (g_sNPTFile[0] != 0))
600
 
                                        fgets(buf,256,g_fNPTFile);
601
 
                                if (fmod(z,g_iScanMolStep/60.0) < 1.0)
602
 
                                        mprintf(WHITE,"#");
603
 
                                if (!g_TimeStep.SkipTimestep(a))
604
 
                                {
605
 
                                        eprintf("Error.\n",g_iScanMolStep);
606
 
                                        goto _skipfail;
607
 
                                }
608
 
                        }
609
 
                        mprintf(WHITE,"]\n");
610
 
                        g_iFastForwardPos = ftell(a);
611
 
                        mprintf("  Step %d begins at offset %lu (%.1f MB).\n\n",g_iScanMolStep+1,g_iFastForwardPos,g_iFastForwardPos/1024.0/1024.0);
612
 
                }
613
 
        _skipfail:;
614
 
                g_TimeStep.ReadTimestep(a,true);
615
 
                if (g_bNPT)
616
 
                {
617
 
                        if (g_sNPTFile[0] != 0)
618
 
                                g_TimeStep.ReadCellVector(g_fNPTFile);
619
 
                        mprintf("\n    NPT: Using a cell vector of ( %.2f pm | %.2f pm | %.2f pm ) for molecule recognition.\n",g_fBoxX,g_fBoxY,g_fBoxZ);
620
 
                }
621
 
        } else
622
 
        {
623
 
                g_iScanMolStep = 0;
624
 
                mprintf("\n    Stream input: Executing molecule recognition from first timestep...\n");
625
 
        }
626
 
 
627
 
        g_iCloseAtomCounter = 0;
628
 
 
629
 
        if (!g_TimeStep.ScanMolecules())
630
 
                return false;
631
 
 
632
 
        if (!g_bStreamInput)
633
 
        {
634
 
                fclose(a);
635
 
                if (g_sNPTFile[0] != 0)
636
 
                        fclose(g_fNPTFile);
637
 
        }
638
 
 
639
 
        if (g_bPeriodic)
640
 
        {
641
 
                mprintf("\n    Uniting molecules which have been broken by wrapping...\n");
642
 
                g_TimeStep.UniteMolecules(true);
643
 
        }
644
 
 
645
 
        mprintf(YELLOW,"\n*** The following %d kind%s of molecules ha%s been recognized:\n",g_oaMolecules.GetSize(),(g_oaMolecules.GetSize()>1)?"s":"",(g_oaMolecules.GetSize()>1)?"ve":"s");
646
 
        mprintf("    (ordered by molecular mass)\n\n");
647
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
648
 
        {
649
 
                mprintf(WHITE,"  - Molecule %d: %s ",z+1,((CMolecule*)g_oaMolecules[z])->m_sName);
650
 
                mprintf("(%d piece%s, %.2f g/mol)\n",((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize(),(((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize()>1)?"s":"",((CMolecule*)g_oaMolecules[z])->m_fMass);
651
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
652
 
                mprintf("      (%d noneq. atom%s, %d noneq. bond%s, %d noneq. angle%s)\n",sm->m_iAtomClasses,(sm->m_iAtomClasses==1)?"":"s",sm->m_oaBondGroups.GetSize(),(sm->m_oaBondGroups.GetSize()==1)?"":"s",sm->m_oaAngleGroups.GetSize(),(sm->m_oaAngleGroups.GetSize()==1)?"":"s");
653
 
                if (((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize() != 0)
654
 
                {
655
 
                        if (((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize() == 1)
656
 
                                mprintf(WHITE,"      Detected %d ring:\n",((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize());
657
 
                                        else mprintf(WHITE,"      Detected %d rings:\n",((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize());
658
 
                        for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize();z2++)
659
 
                        {
660
 
                                mprintf(WHITE,"        %2d.) %2d-ring: ",z2+1,((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize());
661
 
                                if (((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize() > 20)
662
 
                                {
663
 
                                        for (z3=0;z3<5;z3++)
664
 
                                        {
665
 
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[((CMolecule*)g_oaMolecules[z])->m_baAtomIndex[((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetAt(z3)+1);
666
 
                                                if (z3+1 < ((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize())
667
 
                                                        mprintf(" - ");
668
 
                                        }
669
 
                                        mprintf(RED,"...");
670
 
                                        mprintf(" - ");
671
 
                                        for (z3=((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize()-5;z3<((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize();z3++)
672
 
                                        {
673
 
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[((CMolecule*)g_oaMolecules[z])->m_baAtomIndex[((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetAt(z3)+1);
674
 
                                                if (z3+1 < ((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize())
675
 
                                                        mprintf(" - ");
676
 
                                        }
677
 
                                } else
678
 
                                {
679
 
                                        for (z3=0;z3<((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize();z3++)
680
 
                                        {
681
 
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[((CMolecule*)g_oaMolecules[z])->m_baAtomIndex[((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetAt(z3)+1);
682
 
                                                if (z3+1 < ((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize())
683
 
                                                        mprintf(" - ");
684
 
                                        }
685
 
                                }
686
 
                                mprintf("\n");
687
 
                                if (z2 >= 9)
688
 
                                {
689
 
                                        mprintf(RED,"\n    Showing only the first 10 rings.\n");
690
 
                                        break;
691
 
                                }
692
 
                        }
693
 
                }
694
 
 
695
 
                mprintf("\n");
696
 
        }
697
 
 
698
 
        if (g_oaMolecules.GetSize() == 0)
699
 
        {
700
 
                eprintf("You don't have any atom/molecule in your simulation. This is probably not what you wanted.\n");
701
 
                eprintf("Stopping execution.\n");
702
 
                return false;
703
 
        }
704
 
 
705
 
/*      if (g_bVerbose)
706
 
        {
707
 
                mprintf(WHITE,">>> Output of the molecule tree >>>\n");
708
 
                g_TimeStep.PrintMegaTree();
709
 
                mprintf(WHITE,"<<< Output of the molecule tree <<<\n\n");
710
 
        }*/
711
 
 
712
 
_matrixagain:
713
 
 
714
 
        mprintf("\n");
715
 
        if (!AskYesNo("    Accept these molecules (y) or change something (n)? [yes] ",true))
716
 
        {
717
 
                tb = false;
718
 
                mprintf("\n");
719
 
                mprintf("    If you want some atom types to form no bonds at all, assign covalent radius 0 to them.\n");
720
 
_modagain:
721
 
                mprintf(YELLOW,"\n    *** Modify Molecules ***\n\n");
722
 
                mprintf("    Your choices:\n\n");
723
 
 
724
 
                mprintf("    1.) Change covalent atom radii used for bond recognition\n");
725
 
                mprintf("    2.) Break specific bonds\n");
726
 
                mprintf("    3.) Rename elements\n");
727
 
 
728
 
                mprintf("\n");
729
 
                switch(AskRangeInteger("    Please select: [done] ",1,3,0))
730
 
                {
731
 
                        case 1:
732
 
                                mprintf("\n    These values have been used (covalent radii from literature multiplied with %.2f):\n\n",g_fBondFactor);
733
 
                                for (z=0;z<g_oaAtoms.GetSize()-1;z++)
734
 
                                        mprintf("      - %-2s    %5.1f pm\n",((CAtom*)g_oaAtoms[z])->m_sName,((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius*g_fBondFactor);
735
 
                                mprintf("\n");
736
 
        _arnew:
737
 
                                AskString("    Which radius do you want to change (RETURN=done)? ",buf,"");
738
 
                                if (strlen(buf) == 0)
739
 
                                        goto _ardone;
740
 
                                for (z=0;z<g_oaAtoms.GetSize()-1;z++)
741
 
                                {
742
 
                                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
743
 
                                        {
744
 
                                                ((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius = AskFloat("    Please enter new bond radius for %s in pm: [%.1f] ",((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius*g_fBondFactor,((CAtom*)g_oaAtoms[z])->m_sName,((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius*g_fBondFactor) / g_fBondFactor;
745
 
                                                if (((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius == 0)
746
 
                                                        mprintf("\n      Atom %s will form no bonds now.\n\n",((CAtom*)g_oaAtoms[z])->m_sName);
747
 
                                                mprintf("\n");
748
 
                                                tb = true;
749
 
                                                goto _arnew;
750
 
                                        }
751
 
                                }
752
 
                                eprintf("    Atom \"%s\" is not in the system.\n\n",buf);
753
 
                                goto _arnew;
754
 
        _ardone:
755
 
                                mprintf("\n");
756
 
                                break;
757
 
 
758
 
                        case 2:
759
 
        _breakagain:
760
 
                                mprintf("\n");
761
 
                                if (g_oaMolecules.GetSize() > 1)
762
 
                                {
763
 
        _breakmol:      ti = AskUnsignedInteger_ND("    Break bonds in which molecule (1-%d)? ",g_oaMolecules.GetSize())-1;
764
 
                                        if ((ti < 0) || (ti >= (int)g_oaMolecules.GetSize()))
765
 
                                        {
766
 
                                                eprintf("Wrong Input.\n\n");
767
 
                                                goto _breakmol;
768
 
                                        }
769
 
                                } else ti = 0;
770
 
                                mol = (CMolecule*)g_oaMolecules[ti];
771
 
                                tb = true;
772
 
                                if (AskYesNo("    Break all bonds within this molecule (y/n)? [no] ",false))
773
 
                                {
774
 
                                        for (z=0;z<mol->m_laSingleMolIndex.GetSize();z++)
775
 
                                        {
776
 
                                                sm = (CSingleMolecule*)g_oaSingleMolecules[mol->m_laSingleMolIndex[z]];
777
 
                                                g_laBondBlackList.Append(&sm->m_laBonds);
778
 
                                        }
779
 
                                } else
780
 
                                {
781
 
        _breaka1:               AskString_ND("    Enter 1st atom of the bond to break (e.g. O2): ",buf);
782
 
                                        if (!ParseAtom(buf,ti,ty,rty,atom))
783
 
                                                goto _breaka1;
784
 
        _breaka2:               AskString_ND("    Enter 2nd atom of the bond to break (e.g. O2): ",buf);
785
 
                                        if (!ParseAtom(buf,ti,ty2,rty2,atom2))
786
 
                                                goto _breaka2;
787
 
                                        for (z=0;z<mol->m_laSingleMolIndex.GetSize();z++)
788
 
                                        {
789
 
                                                sm = (CSingleMolecule*)g_oaSingleMolecules[mol->m_laSingleMolIndex[z]];
790
 
                                                g_laBondBlackList.Add(((CxIntArray*)sm->m_oaAtomOffset[ty])->GetAt(atom));
791
 
                                                g_laBondBlackList.Add(((CxIntArray*)sm->m_oaAtomOffset[ty2])->GetAt(atom2));
792
 
                                        }
793
 
                                }
794
 
                                if (AskYesNo("\n    Break another bond (y/n)? [no] ",false))
795
 
                                        goto _breakagain;
796
 
                                mprintf("\n");
797
 
                                break;
798
 
 
799
 
                        case 3:
800
 
/*********************************************************************************************************************/
801
 
_rennew:
802
 
                                mprintf("\n    The system contains the following atoms:\n\n    ");
803
 
                                tb2 = false;
804
 
                                for (z=0;z<g_oaAtoms.GetSize();z++)
805
 
                                {
806
 
                                        if (z == g_iVirtAtomType)
807
 
                                                continue;
808
 
                                        if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
809
 
                                                continue;
810
 
                                        if (tb2)
811
 
                                                mprintf(", ");
812
 
                                        tb2 = true;
813
 
                                        mprintf("%dx %s",((CAtom*)g_oaAtoms[z])->m_iCount,((CAtom*)g_oaAtoms[z])->m_sName);
814
 
                                }
815
 
                                mprintf("\n\n");
816
 
 
817
 
_renerr:
818
 
                                AskString("    Which element to rename: [done] ",buf,"");
819
 
 
820
 
                                if (strlen(buf) == 0)
821
 
                                        goto _rendone;
822
 
 
823
 
                                for (z=0;z<g_oaAtoms.GetSize();z++)
824
 
                                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
825
 
                                                goto _renfound;
826
 
                                eprintf("\n    Atom \"%s\" not in the system.\n\n",buf);
827
 
                                goto _renerr;
828
 
_renfound:
829
 
                                tb = true;
830
 
                                at = (CAtom*)g_oaAtoms[z];
831
 
                                
832
 
                                AskString_ND("    Enter new name for %s: ",buf2,buf);
833
 
                                if (strlen(buf2) > 7)
834
 
                                {
835
 
                                        eprintf("\n    Atom labels may have maximum length of 7 characters.\n\n");
836
 
                                        goto _renfound;
837
 
                                }
838
 
                                if (ContainsDigit(buf2))
839
 
                                {
840
 
                                        eprintf("\n    Digits in element labels not allowed.\n\n");
841
 
                                        goto _renfound;
842
 
                                }
843
 
                                el = FindElement(buf2,true);
844
 
                                if (el != NULL)
845
 
                                {
846
 
                                        xAddAtom(buf2);
847
 
                                        if (AskYesNo("    Element %s is known. Merge %s atoms into %s (y/n)? [yes] ",true,buf2,buf,buf2))
848
 
                                        {
849
 
                                                for (z2=0;z2<g_oaAtoms.GetSize();z2++)
850
 
                                                {
851
 
                                                        if (((CAtom*)g_oaAtoms[z2])->m_pElement == el)
852
 
                                                        {
853
 
                                                                at = (CAtom*)g_oaAtoms[z2];
854
 
                                                                at->m_iCount--;
855
 
                                                                el = at->m_pElement;
856
 
                                                                goto _ren1;
857
 
                                                        }
858
 
                                                }
859
 
                                                eprintf("\n    Strange error ^^\n");
860
 
_ren1:;
861
 
                                        }
862
 
                                } else
863
 
                                {
864
 
                                        mprintf("\n      Adding element %s...\n\n",buf2);
865
 
 
866
 
                                        try { at = new CAtom(); } catch(...) { at = NULL; }
867
 
                                        if (at == NULL) NewException((double)sizeof(CAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
868
 
                                        
869
 
                                        at->m_iIndex = g_oaAtoms.GetSize();
870
 
                                        g_oaAtoms.Add(at);
871
 
                                        at->m_iCount = 0;
872
 
 
873
 
                                        try { at->m_pElement = new CElement(); } catch(...) { at->m_pElement = NULL; }
874
 
                                        if (at->m_pElement == NULL) NewException((double)sizeof(CElement),__FILE__,__LINE__,__PRETTY_FUNCTION__);
875
 
                                        
876
 
                                        at->m_pElement->m_fRadius = AskFloat("    Please enter covalent radius in pm: [100.0] ",100.0f);
877
 
                                        at->m_pElement->m_fMass = AskFloat("    Please enter atom mass in u: [0] ",0);
878
 
                                        sprintf(at->m_sName,"%s",buf2);
879
 
                                }
880
 
                                for (z2=0;z2<(int)g_TimeStep.m_iGesAtomCount;z2++)
881
 
                                {
882
 
                                        strcpy(buf,(char*)g_TimeStep.m_paLabels[z2]);
883
 
                                        ReplaceDigits(buf);
884
 
                                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
885
 
                                        {
886
 
                                                at->m_iCount++;
887
 
                                                ((CAtom*)g_oaAtoms[z])->m_iCount--;
888
 
                                        }
889
 
                                }
890
 
                                ((CAtom*)g_oaAtoms[z])->m_pMergedTo = at;
891
 
                                mprintf("\n");
892
 
                                goto _rennew;
893
 
_rendone:;
894
 
                                mprintf("\n    The system contains the following atoms:\n\n    ");
895
 
                                tb2 = false;
896
 
                                for (z=0;z<g_oaAtoms.GetSize();z++)
897
 
                                {
898
 
                                        if (z == g_iVirtAtomType)
899
 
                                                continue;
900
 
                                        if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
901
 
                                                continue;
902
 
                                        if (tb2)
903
 
                                                mprintf(", ");
904
 
                                        tb2 = true;
905
 
                                        mprintf("%dx %s",((CAtom*)g_oaAtoms[z])->m_iCount,((CAtom*)g_oaAtoms[z])->m_sName);
906
 
                                }
907
 
                                mprintf("\n");
908
 
/*********************************************************************************************************************/
909
 
                                break;
910
 
 
911
 
                        default:
912
 
                                goto _fin;
913
 
                }
914
 
                goto _modagain;
915
 
_fin:
916
 
                if (tb)
917
 
                {
918
 
                        mprintf(WHITE,"\n    Going back to molecule recognition with changed settings.\n\n");
919
 
                        goto _molbegin;
920
 
                } else
921
 
                        mprintf(WHITE,"\n    Nothing was changed, not repeating molecule recognition.\n\n");
922
 
        }
923
 
                
924
 
        if (g_bAdvanced1)
925
 
        {
926
 
                g_bMegaMat = !AskYesNo("    Show bond matrices only for first representant of each molecule type (y/n)? [yes] ",true);
927
 
                g_bMatOnlyBind = AskYesNo("    Show only bonds in the bond matrices (y/n)? [yes] ",true);
928
 
        } else
929
 
        {
930
 
                g_bMegaMat = false;
931
 
                g_bMatOnlyBind = true;
932
 
        }
933
 
                        
934
 
        mprintf(WHITE,"\nOutput of bond matrices:\n");
935
 
        g_TimeStep.PrintMatrix(!g_bMegaMat,g_bMatOnlyBind);
936
 
 
937
 
        mprintf("\n");
938
 
        mprintf("    You can create images of the structural formulas with the atom labels for easier\n");
939
 
        mprintf("    identification of the atoms (requires installed GraphViz package - see www.graphviz.org).\n\n");
940
 
 
941
 
        if (AskYesNo("    Create images of the structural formulas (y/n)? [no] ",false))
942
 
        {
943
 
                if (g_bAdvanced1)
944
 
                        ti = AskUnsignedInteger("    How many iterations to perform for formula optimization? [10] ",10);
945
 
                                else ti = 10;
946
 
                RenderStructFormulas(ti);
947
 
        }
948
 
 
949
 
        mprintf(WHITE,"\n    The atoms are currently ordered by topological priority.\n");
950
 
 
951
 
        if (g_bAdvanced1)
952
 
        {
953
 
                mprintf("\n");
954
 
 
955
 
                // This block written @ Ballmer peak ;-P Try it out yourself.
956
 
                if (AskYesNo("    Change the atom ordering in some molecule (y/n)? [no] ",false))
957
 
                {
958
 
                        if (AskYesNo("    Order atoms like in the input file instead (y/n)? [no] ",false))
959
 
                        {
960
 
                                ReorderLikeInput(); // Crazy shit!! (Ballmer Peak)
961
 
                        } else
962
 
                        {
963
 
        _reordernext:
964
 
                                sprintf(buf,"    Change atom ordering in which of the molecules (");
965
 
                                for (z=0;z<g_oaMolecules.GetSize();z++)
966
 
                                {
967
 
                                        sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
968
 
                                        strcat(buf,buf2);
969
 
                                        if (z < g_oaMolecules.GetSize()-1)
970
 
                                                strcat(buf,", ");
971
 
                                }
972
 
                                strcat(buf,")? ");
973
 
                                ti = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize())-1;
974
 
                                mol = (CMolecule*)g_oaMolecules[ti];
975
 
                                mol->m_oaNewNumbers.SetSize(mol->m_baAtomIndex.GetSize());
976
 
                                for (z=0;z<mol->m_baAtomIndex.GetSize();z++)
977
 
                                {
978
 
                                        mprintf("* Atom type %s\n",((CAtom*)g_oaAtoms[mol->m_baAtomIndex[z]])->m_sName);
979
 
                                        if (mol->m_oaNewNumbers[z] != NULL)
980
 
                                                delete mol->m_oaNewNumbers[z];
981
 
 
982
 
                                        try { mol->m_oaNewNumbers[z] = new CxIntArray("gather():mol->m_oaNewNumbers[z]"); } catch(...) { mol->m_oaNewNumbers[z] = NULL; }
983
 
                                        if (mol->m_oaNewNumbers[z] == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
984
 
                                        
985
 
                                        for (z2=0;z2<mol->m_waAtomCount[z];z2++)
986
 
                                        {
987
 
                _renumberagain:
988
 
                                                ti2 = AskRangeInteger("    Which number should %s%d bear? [%d] ",1,mol->m_waAtomCount[z],z2+1,((CAtom*)g_oaAtoms[mol->m_baAtomIndex[z]])->m_sName,z2+1,z2+1);
989
 
                                                for (z3=0;z3<z2;z3++)
990
 
                                                        if (((CxIntArray*)mol->m_oaNewNumbers[z])->GetAt(z3) == ti2-1)
991
 
                                                        {
992
 
                                                                eprintf("This number already was chosen for %s%d!\n",((CAtom*)g_oaAtoms[mol->m_baAtomIndex[z]])->m_sName,z3+1);
993
 
                                                                goto _renumberagain;
994
 
                                                        }
995
 
                                                (*((CxIntArray*)mol->m_oaNewNumbers[z])).Add(ti2-1);
996
 
                                        }
997
 
                                }
998
 
                                mprintf("\n    Reordering atoms...");
999
 
                                ReorderAtoms(ti);
1000
 
                                mprintf("Done.\n\n");
1001
 
                                if (AskYesNo("    Change atom ordering of another molecule (y/n)? [no] ",false))
1002
 
                                        goto _reordernext;
1003
 
                                goto _matrixagain;
1004
 
                        } // End "this block"
1005
 
 
1006
 
                        mprintf(WHITE,"\n    Going back to molecule recognition with changed settings.\n\n");
1007
 
                        goto _molbegin;
1008
 
                } // END IF REORDER
1009
 
        } // END IF ADVANCED
1010
 
 
1011
 
        mprintf(WHITE,"\n    Defining virtual atom #1 as molecular Center of Geometry:\n");
1012
 
        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
1013
 
        {
1014
 
                mprintf("      - %s...\n",((CMolecule*)g_oaMolecules[z0])->m_sName);
1015
 
                va = AddVirtualAtom(z0);
1016
 
                va->m_iMode = 0;
1017
 
                va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
1018
 
                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
1019
 
                for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
1020
 
                        va->m_faWeight[z] = 1.0f;
1021
 
                va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
1022
 
        }
1023
 
 
1024
 
        mprintf(WHITE,"\n    Defining virtual atom #2 as molecular Center of Mass:\n");
1025
 
        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
1026
 
        {
1027
 
                mprintf("      - %s...\n",((CMolecule*)g_oaMolecules[z0])->m_sName);
1028
 
                va = AddVirtualAtom(z0);
1029
 
                va->m_iMode = 0;
1030
 
                va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
1031
 
                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
1032
 
                z3 = 0;
1033
 
                tf2 = 0;
1034
 
                for (z=0;z<va->m_oCenterAtoms.m_baAtomType.GetSize();z++)
1035
 
                {
1036
 
                        tf = ((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z]])->m_pElement->m_fMass;
1037
 
                        for (z2=0;z2<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z])->GetSize();z2++)
1038
 
                        {
1039
 
                                va->m_faWeight[z3] = tf;
1040
 
                                tf2 += tf;
1041
 
                                z3++;
1042
 
                        }
1043
 
                }
1044
 
                va->m_fGesWeight = tf2;
1045
 
                if (va->m_fGesWeight == 0)
1046
 
                {
1047
 
                        eprintf("        Molecule %s has total mass of zero. Defining #2 as Center of Geometry.\n",((CMolecule*)g_oaMolecules[z0])->m_sName);
1048
 
                        for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
1049
 
                                va->m_faWeight[z] = 1.0f;
1050
 
                        va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
1051
 
                }
1052
 
        }
1053
 
 
1054
 
        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
1055
 
        {
1056
 
                m = (CMolecule*)g_oaMolecules[z0];
1057
 
                if (m->m_oaRingAtoms.GetSize() != 0)
1058
 
                {
1059
 
                        mprintf(WHITE,"\n    Defining ring centers in %s:\n",m->m_sName);
1060
 
                        for (z=0;z<m->m_oaRingAtoms.GetSize();z++)
1061
 
                        {
1062
 
                                mprintf("      - Defining #%d as Center of Ring %d: ",z+3,z+1);
1063
 
                                for (z3=0;z3<((CxIntArray*)m->m_oaRingAtoms[z])->GetSize();z3++)
1064
 
                                {
1065
 
                                        mprintf("%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[((CxIntArray*)m->m_oaRingAtomTypes[z])->GetAt(z3)]])->m_sName,((CxIntArray*)m->m_oaRingAtoms[z])->GetAt(z3)+1);
1066
 
                                        if (z3+1 < ((CxIntArray*)m->m_oaRingAtoms[z])->GetSize())
1067
 
                                                mprintf(" - ");
1068
 
                                }
1069
 
                                mprintf("\n");
1070
 
                                va = AddVirtualAtom(z0);
1071
 
                                va->m_iMode = 0;
1072
 
                                va->m_oCenterAtoms.m_pMolecule = m;
1073
 
                                for (z3=0;z3<((CxIntArray*)m->m_oaRingAtoms[z])->GetSize();z3++)
1074
 
                                        va->m_oCenterAtoms.AddAtom(((CxIntArray*)m->m_oaRingAtomTypes[z])->GetAt(z3),((CxIntArray*)m->m_oaRingAtoms[z])->GetAt(z3),false);
1075
 
                                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
1076
 
                                for (z3=0;z3<va->m_oCenterAtoms.m_iAtomGes;z3++)
1077
 
                                        va->m_faWeight[z3] = 1.0f;
1078
 
                                va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
1079
 
                        }
1080
 
                }
1081
 
        }
1082
 
 
1083
 
        if (g_bAdvanced1)
1084
 
        {
1085
 
                mprintf("\n");
1086
 
                if (AskYesNo("\n    Define additional virtual atoms (y/n)? [no] ",false))
1087
 
                {
1088
 
        _vabeg:
1089
 
                        sprintf(buf,"    To which molecule shall the virtual atom belong (");
1090
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
1091
 
                        {
1092
 
                                sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
1093
 
                                strcat(buf,buf2);
1094
 
                                if (z < g_oaMolecules.GetSize()-1)
1095
 
                                        strcat(buf,", ");
1096
 
                        }
1097
 
                        strcat(buf,")? ");
1098
 
 
1099
 
                        z = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize());
1100
 
                        va = AddVirtualAtom(z-1);
1101
 
                        mprintf(WHITE,"\n*** Defining virtual atom #%d in %s\n",va->m_iMolVirtAtom+1,((CMolecule*)g_oaMolecules[va->m_iMolecule])->m_sName);
1102
 
                        va->m_iMode = AskRangeInteger("    Define v.a. as center (0) or through distance/angle/dihedral (1)? [center] ",0,1,0);
1103
 
                        if (va->m_iMode == 0)
1104
 
                        {
1105
 
        _vaatoms:
1106
 
                                mprintf("    Which atoms to use for center (e.g. \"C1,C3-5,H\")? [all] ");
1107
 
                                inpprintf("! Which atoms to use for center (e.g. \"C1,C3-5,H\")? [all]\n");
1108
 
                                myget(buf);
1109
 
                                if (strlen(buf)==0)
1110
 
                                        va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
1111
 
                                else if (!va->m_oCenterAtoms.ParseAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],buf))
1112
 
                                        goto _vaatoms;
1113
 
                                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
1114
 
        _vaweight:
1115
 
                                mprintf("    How shall these atoms be weightened (RETURN=equal, *=mass, #=manually)? [equal] ");
1116
 
                                inpprintf("! How shall these atoms be weightened (RETURN=equal, *=mass, #=manually)? [equal]\n");
1117
 
                                myget(buf);
1118
 
                                if (strlen(buf)==0)
1119
 
                                {
1120
 
                                        for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
1121
 
                                                va->m_faWeight[z] = 1.0f;
1122
 
                                        va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
1123
 
                                } else if (buf[0] == '*')
1124
 
                                {
1125
 
                                        z3 = 0;
1126
 
                                        tf2 = 0;
1127
 
                                        for (z=0;z<va->m_oCenterAtoms.m_baAtomType.GetSize();z++)
1128
 
                                        {
1129
 
                                                tf = ((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z]])->m_pElement->m_fMass;
1130
 
                                                for (z2=0;z2<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z])->GetSize();z2++)
1131
 
                                                {
1132
 
                                                        va->m_faWeight[z3] = tf;
1133
 
                                                        tf2 += tf;
1134
 
                                                        z3++;
1135
 
                                                }
1136
 
                                        }
1137
 
                                        va->m_fGesWeight = tf2;
1138
 
                                        if (va->m_fGesWeight == 0)
1139
 
                                        {
1140
 
                                                eprintf("\n    Molecule has total mass of zero. Weighting atoms equally.\n\n");
1141
 
                                                for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
1142
 
                                                        va->m_faWeight[z] = 1.0f;
1143
 
                                                va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
1144
 
                                        }
1145
 
                                } else if (buf[0] == '#')
1146
 
                                {
1147
 
_vawagain:
1148
 
                                        z3 = 0;
1149
 
                                        tf2 = 0;
1150
 
                                        mprintf("\n");
1151
 
                                        for (z=0;z<va->m_oCenterAtoms.m_baAtomType.GetSize();z++)
1152
 
                                        {
1153
 
                                                for (z2=0;z2<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z])->GetSize();z2++)
1154
 
                                                {
1155
 
                                                        tf = AskFloat("      Enter the weight for %s%d: [1] ",1.0f,((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z]])->m_pElement->m_sLabel, ((CxIntArray *)va->m_oCenterAtoms.m_oaAtoms[z])->GetAt(z2)+1);
1156
 
                                                        va->m_faWeight[z3] = tf;
1157
 
                                                        tf2 += tf;
1158
 
                                                        z3++;
1159
 
                                                }
1160
 
                                        }
1161
 
                                        mprintf("    The sum of weights is %.4f.\n\n",tf2);
1162
 
                                        va->m_fGesWeight = tf2;
1163
 
                                        if (va->m_fGesWeight == 0)
1164
 
                                        {
1165
 
                                                eprintf("Sum of weights may not be zero. Enter the weights again.\n\n");
1166
 
                                                goto _vawagain;
1167
 
                                        }
1168
 
                                } else
1169
 
                                {
1170
 
                                        eprintf("Wrong input.\n");
1171
 
                                        inpprintf("! Wrong input.\n");
1172
 
                                        goto _vaweight;
1173
 
                                }
1174
 
                        } else
1175
 
                        {
1176
 
        _vabond:
1177
 
                                mprintf("    Enter 2nd atom for distance #%d- (e.g. C2): ",va->m_iMolVirtAtom+1);
1178
 
                                inpprintf("! Enter 2nd atom for distance #%d- (e.g. C2):\n",va->m_iMolVirtAtom+1);
1179
 
                                myget(buf);
1180
 
                                if (!ParseAtom(buf,va->m_iMolecule,va->m_iAtomType[0],va->m_iRealAtomType[0],va->m_iAtom[0]))
1181
 
                                        goto _vabond;
1182
 
                                if ((va->m_iRealAtomType[0] == g_iVirtAtomType) && (va->m_iAtom[0] == va->m_iMolVirtAtom))
1183
 
                                {
1184
 
                                        eprintf("This atom was already chosen.\n");
1185
 
                                        goto _vabond;
1186
 
                                }
1187
 
        _vaangle:
1188
 
                                mprintf("    Enter 3rd atom for angle #%d-%s%d- (e.g. C2)? ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1);
1189
 
                                inpprintf("! Enter 3rd atom for angle #%d-%s%d- (e.g. C2)?\n",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1);
1190
 
                                myget(buf);
1191
 
                                if (!ParseAtom(buf,va->m_iMolecule,va->m_iAtomType[1],va->m_iRealAtomType[1],va->m_iAtom[1]))
1192
 
                                        goto _vaangle;
1193
 
                                if (((va->m_iRealAtomType[1] == g_iVirtAtomType) && (va->m_iAtom[1] == va->m_iMolVirtAtom)) || ((va->m_iRealAtomType[1] == va->m_iRealAtomType[0]) && (va->m_iAtom[1] == va->m_iAtom[0])))
1194
 
                                {
1195
 
                                        eprintf("This atom was already chosen.\n");
1196
 
                                        goto _vaangle;
1197
 
                                }
1198
 
        _vadihedral:
1199
 
                                mprintf("    Enter 4th atom for dihedral #%d-%s%d-%s%d- (e.g. C2)? ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1);
1200
 
                                inpprintf("! Enter 4th atom for dihedral #%d-%s%d-%s%d- (e.g. C2)?\n",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1);
1201
 
                                myget(buf);
1202
 
                                if (!ParseAtom(buf,va->m_iMolecule,va->m_iAtomType[2],va->m_iRealAtomType[2],va->m_iAtom[2]))
1203
 
                                        goto _vadihedral;
1204
 
                                if (((va->m_iRealAtomType[2] == g_iVirtAtomType) && (va->m_iAtom[2] == va->m_iMolVirtAtom)) || ((va->m_iRealAtomType[2] == va->m_iRealAtomType[0]) && (va->m_iAtom[2] == va->m_iAtom[0])) || ((va->m_iRealAtomType[2] == va->m_iRealAtomType[1]) && (va->m_iAtom[2] == va->m_iAtom[1])))
1205
 
                                {
1206
 
                                        eprintf("This atom was already chosen.\n");
1207
 
                                        goto _vadihedral;
1208
 
                                }
1209
 
                
1210
 
                                va->m_fValues[0] = AskFloat_ND("    Enter distance #%d-%s%d in pm: ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1);
1211
 
                                va->m_fValues[1] = AskFloat_ND("    Enter angle #%d-%s%d-%s%d in degree: ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1) * (float)Pi / 180.0f;
1212
 
                                va->m_fValues[2] = AskFloat_ND("    Enter dihedral #%d-%s%d-%s%d-%s%d in degree: ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[2]])->m_sName,va->m_iAtom[2]+1) * (float)Pi / 180.0f;
1213
 
                        }
1214
 
 
1215
 
                        if (AskYesNo("\n    Define further virtual atoms (y/n)? [no] ",false))
1216
 
                                goto _vabeg;
1217
 
                }
1218
 
 
1219
 
                mprintf("\n");
1220
 
                if (AskYesNo("    Do you want to define pseudo-molecules (y/n)? [no] ",false))
1221
 
                {
1222
 
                        tb2 = false;
1223
 
                        ti = 0;
1224
 
                        mprintf("\n    If you need the center of mass or center of geometry of the whole system, you should\n");
1225
 
                        mprintf("    define a pseudo-molecule over the whole system, and use its atoms #1 and #2.\n\n");
1226
 
                        if (AskYesNo("    Define a pseudo-molecule over the whole system (y/n)? [yes] ",true))
1227
 
                        {
1228
 
                                ti++;
1229
 
/************************************************************************/
1230
 
                                mprintf("\n");
1231
 
                                try { m2 = new CMolecule(); } catch(...) { m2 = NULL; }
1232
 
                                if (m2 == NULL) NewException((double)sizeof(CMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1233
 
                                
1234
 
                                try { sm2 = new CSingleMolecule(); } catch(...) { sm2 = NULL; }
1235
 
                                if (sm2 == NULL) NewException((double)sizeof(CSingleMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1236
 
                                
1237
 
                                m2->m_bPseudo = true;
1238
 
                                sm2->m_bPseudo = true;
1239
 
                                m2->m_iIndex = g_oaMolecules.GetSize();
1240
 
                                sm2->m_iMolType = g_oaMolecules.GetSize();
1241
 
                                sm2->m_iMolSMIndex = 0;
1242
 
                                m2->m_laSingleMolIndex.Add(g_oaSingleMolecules.GetSize());
1243
 
                                g_oaMolecules.Add(m2);
1244
 
                                g_oaSingleMolecules.Add(sm2);
1245
 
 
1246
 
                                mprintf(WHITE,"    >>> Pseudo-molecule %d (= molecule %d) >>>\n\n",ti,g_oaMolecules.GetSize());
1247
 
                                mprintf("    Adding all atoms from all molecules...\n");
1248
 
 
1249
 
                                for (z=0;z<g_oaMolecules.GetSize();z++)
1250
 
                                {
1251
 
                                        m = (CMolecule*)g_oaMolecules[z];
1252
 
                                        if (m->m_bPseudo)
1253
 
                                                continue;
1254
 
 
1255
 
                                        try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
1256
 
                                        if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1257
 
                                        
1258
 
                                        ag->AddAllAtoms(m,false);
1259
 
 
1260
 
                                        ia.RemoveAll();
1261
 
 
1262
 
                                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
1263
 
                                                ia.Add(z2);
1264
 
 
1265
 
                                        for (z2=0;z2<ag->m_baAtomType.GetSize();z2++)
1266
 
                                        {
1267
 
                                                m2->m_iAtomGes += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
1268
 
 
1269
 
                                                for (z4=0;z4<m2->m_baAtomIndex.GetSize();z4++)
1270
 
                                                {
1271
 
                                                        if (m2->m_baAtomIndex[z4] == ag->m_baRealAtomType[z2])
1272
 
                                                        {
1273
 
                                                                m2->m_waAtomCount[z4] += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
1274
 
                                                                pia = (CxIntArray*)sm2->m_oaAtomOffset[z4];
1275
 
                                                                goto _pmafound;
1276
 
                                                        }
1277
 
                                                }
1278
 
 
1279
 
                                                m2->m_baAtomIndex.Add(ag->m_baRealAtomType[z2]);
1280
 
                                                sm2->m_baAtomIndex.Add(ag->m_baRealAtomType[z2]);
1281
 
                                                m2->m_waAtomCount.Add(((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize());
1282
 
 
1283
 
                                                try { pia = new CxIntArray("gather():pia"); } catch(...) { pia = NULL; }
1284
 
                                                if (pia == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1285
 
 
1286
 
                                                sm2->m_oaAtomOffset.Add(pia);
1287
 
_pmafound:
1288
 
                                                for (z4=0;z4<((CxIntArray*)ag->m_oaAtoms[z2])->GetSize();z4++)
1289
 
                                                {
1290
 
                                                        for (z5=0;z5<ia.GetSize();z5++)
1291
 
                                                        {
1292
 
                                                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ia[z5]]];
1293
 
                                                                for (z6=0;z6<sm2->m_oaAtomOffset.GetSize();z6++)
1294
 
                                                                {
1295
 
                                                                        for (z7=0;z7<((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetSize();z7++)
1296
 
                                                                        {
1297
 
                                                                                if (((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetAt(z7) == ((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)))
1298
 
                                                                                {
1299
 
                                                                                        eprintf("Weird error: Atom %s%d from %s[%d] is already in the pseudo-molecule; skipping.\n",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)+1,m->m_sName,ia[z5]+1);
1300
 
                                                                                        m2->m_waAtomCount[m2->m_waAtomCount.GetSize()-1]--;
1301
 
                                                                                        abort();
1302
 
                                                                                }
1303
 
                                                                        }
1304
 
                                                                }
1305
 
                                                                pia->Add(((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
1306
 
                                                        }
1307
 
                                                }
1308
 
                                        }
1309
 
                                        delete ag;
1310
 
                                }
1311
 
                                mprintf("\n");
1312
 
/********************************************************************************/
1313
 
                                goto _nopseudomol;
1314
 
                        }
1315
 
        _pseudomolnext:
1316
 
                        ti++;
1317
 
 
1318
 
                        if (!tb2)
1319
 
                        {
1320
 
                                tb2 = true;
1321
 
                                mprintf("\n    You may define custom element labels. This enables keeping apart\n    atoms of the same type from different molecules/positions.\n\n");
1322
 
                                tb = AskYesNo("    Keep the standard element labels (y) or define custom labels (n)? [yes] ",true);
1323
 
                                mprintf("\n");
1324
 
                        }
1325
 
 
1326
 
                        try { m2 = new CMolecule(); } catch(...) { m2 = NULL; }
1327
 
                        if (m2 == NULL) NewException((double)sizeof(CMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1328
 
                        
1329
 
                        try { sm2 = new CSingleMolecule(); } catch(...) { sm2 = NULL; }
1330
 
                        if (sm2 == NULL) NewException((double)sizeof(CSingleMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1331
 
                        
1332
 
                        m2->m_bPseudo = true;
1333
 
                        sm2->m_bPseudo = true;
1334
 
                        m2->m_iIndex = g_oaMolecules.GetSize();
1335
 
                        sm2->m_iMolType = g_oaMolecules.GetSize();
1336
 
                        sm2->m_iMolSMIndex = 0;
1337
 
                        m2->m_laSingleMolIndex.Add(g_oaSingleMolecules.GetSize());
1338
 
                        g_oaMolecules.Add(m2);
1339
 
                        g_oaSingleMolecules.Add(sm2);
1340
 
 
1341
 
                        mprintf(WHITE,"    >>> Pseudo-molecule %d (= molecule %d) >>>\n\n",ti,g_oaMolecules.GetSize());
1342
 
        /*              if (ti == 1)
1343
 
                                mprintf(WHITE,"      You may define custom element labels. This enables keeping apart\n      atoms of the same type from different molecules/positions.\n\n");
1344
 
                        tb = AskYesNo("      Keep the standard element labels (y) or define custom labels (n)? [yes] ",true);
1345
 
                        mprintf("\n");
1346
 
*/
1347
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
1348
 
                        {
1349
 
                                m = (CMolecule*)g_oaMolecules[z];
1350
 
                                if (m->m_bPseudo)
1351
 
                                        continue;
1352
 
                                if (AskYesNo("    Use atoms from molecule %d (%s) (y/n)? [no] ",false,z+1,m->m_sName))
1353
 
                                {
1354
 
                                        mprintf("\n");
1355
 
                                        try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
1356
 
                                        if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1357
 
                                        
1358
 
                                        if (AskYesNo("      Use all atoms (y) from %s or only certain atoms (n)? [no] ",false,m->m_sName))
1359
 
                                        {
1360
 
                                                ag->AddAllAtoms(m,false);
1361
 
                                        } else
1362
 
                                        {
1363
 
        _pseudomolp1:
1364
 
                                                AskString_ND("      Please enter atoms from %s to use (e.g. C1-3,H,O4): ",buf,m->m_sName);
1365
 
                                                if (!ag->ParseAtoms(m,buf))
1366
 
                                                        goto _pseudomolp1;
1367
 
                                        }
1368
 
                                        ia.RemoveAll();
1369
 
                                        if (m->m_laSingleMolIndex.GetSize() > 1)
1370
 
                                        {
1371
 
                                                if (!AskYesNo("      Add selected atoms from all %s molecules (y), or only from certain molecules (n)? [yes] ",true,m->m_sName))
1372
 
                                                {
1373
 
        _pseudomolil:
1374
 
                                                        AskString_ND("      Enter the %s molecules to use (range 1-%d, e.g. 1,3-6,8): ",buf,m->m_sName,m->m_laSingleMolIndex.GetSize());
1375
 
                                                        ia.RemoveAll();
1376
 
                                                        if (!ParseIntList(buf,&ia))
1377
 
                                                                goto _pseudomolil;
1378
 
                                                        for (z2=0;z2<ia.GetSize();z2++)
1379
 
                                                        {
1380
 
                                                                if ((ia[z2] < 1) || (ia[z2] > m->m_laSingleMolIndex.GetSize()))
1381
 
                                                                {
1382
 
                                                                        eprintf("Invalid number: %d (should be between 1 and %d).\n",ia[z2],m->m_laSingleMolIndex.GetSize());
1383
 
                                                                        goto _pseudomolil;
1384
 
                                                                }
1385
 
                                                                ia[z2]--;
1386
 
                                                        }
1387
 
                                                } else
1388
 
                                                {
1389
 
                                                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
1390
 
                                                                ia.Add(z2);
1391
 
                                                }
1392
 
                                        } else ia.Add(0);
1393
 
 
1394
 
                                        if (!tb) // Custom Labels
1395
 
                                        {
1396
 
                                                for (z2=0;z2<ag->m_baAtomType.GetSize();z2++)
1397
 
                                                {
1398
 
        _pmlagain:
1399
 
                                                        AskString("      How should %s from %s be labeled? [%s] ",buf,((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,m->m_sName,((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName);
1400
 
                                                        if (ContainsDigit(buf))
1401
 
                                                        {
1402
 
                                                                eprintf("Digits in element labels not allowed.\n");
1403
 
                                                                goto _pmlagain;
1404
 
                                                        }
1405
 
                                                        for (z3=0;z3<g_oaAtoms.GetSize();z3++)
1406
 
                                                        {
1407
 
                                                                if (mystricmp(buf,((CAtom*)g_oaAtoms[z3])->m_sName) == 0)
1408
 
                                                                {
1409
 
                                                                        ti2 = z3;
1410
 
                                                                        goto _pseudomold1;
1411
 
                                                                }
1412
 
                                                        }
1413
 
                                                        if (strlen(buf) > 7)
1414
 
                                                        {
1415
 
                                                                mprintf("        Element labels may only have up to 7 characters; truncating.\n");
1416
 
                                                                buf[7] = 0;
1417
 
                                                        }
1418
 
                                                        mprintf("        Adding new element label \"%s\"...\n",buf);
1419
 
 
1420
 
                                                        try { at = new CAtom(); } catch(...) { at = NULL; }
1421
 
                                                        if (at == NULL) NewException((double)sizeof(CAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1422
 
                                                        
1423
 
                                                        at->m_iIndex = g_oaAtoms.GetSize();
1424
 
                                                        at->m_pElement = ((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_pElement;
1425
 
                                                        memcpy(at->m_sName,buf,8);
1426
 
                                                        at->m_iCount = ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
1427
 
                                                        ti2 = g_oaAtoms.GetSize();
1428
 
                                                        g_oaAtoms.Add(at);
1429
 
        _pseudomold1:
1430
 
                                                        m2->m_iAtomGes += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
1431
 
                                                        for (z3=0;z3<m2->m_baAtomIndex.GetSize();z3++)
1432
 
                                                        {
1433
 
                                                                if (m2->m_baAtomIndex[z3] == ti2)
1434
 
                                                                {
1435
 
                                                                        m2->m_waAtomCount[z3] += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
1436
 
                                                                        for (z4=0;z4<((CxIntArray*)ag->m_oaAtoms[z2])->GetSize();z4++)
1437
 
                                                                        {
1438
 
                                                                                for (z5=0;z5<ia.GetSize();z5++)
1439
 
                                                                                {
1440
 
                                                                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ia[z5]]];
1441
 
                                                                                        for (z6=0;z6<sm2->m_oaAtomOffset.GetSize();z6++)
1442
 
                                                                                        {
1443
 
                                                                                                for (z7=0;z7<((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetSize();z7++)
1444
 
                                                                                                {
1445
 
                                                                                                        if (((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetAt(z7) == ((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)))
1446
 
                                                                                                        {
1447
 
                                                                                                                eprintf("Atom %s%d from %s[%d] is already in the pseudo-molecule; skipping.\n",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)+1,m->m_sName,ia[z5]+1);
1448
 
                                                                                                                m2->m_waAtomCount[z3]--;
1449
 
                                                                                                                goto _pseudomolsk1;
1450
 
                                                                                                        }
1451
 
                                                                                                }
1452
 
                                                                                        }
1453
 
                                                        //                              mprintf("Molecule %d, SM %d, Type %d, Atom %d: Line %d.\n",z,ia[z5],((CxIntArray*)sm->m_oaAtomOffset[z2])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
1454
 
                                                                                        ((CxIntArray*)sm2->m_oaAtomOffset[z3])->Add(((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
1455
 
        _pseudomolsk1:;
1456
 
                                                                                }
1457
 
                                                                        }
1458
 
                                                                        goto _pseudomold2;
1459
 
                                                                }
1460
 
                                                        }
1461
 
                                                        m2->m_baAtomIndex.Add(ti2);
1462
 
                                                        sm2->m_baAtomIndex.Add(ti2);
1463
 
                                                        m2->m_waAtomCount.Add(((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize());
1464
 
 
1465
 
                                                        try { pia = new CxIntArray("gather():pia"); } catch(...) { pia = NULL; }
1466
 
                                                        if (pia == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1467
 
                                                        
1468
 
                                                        sm2->m_oaAtomOffset.Add(pia);
1469
 
                                                        for (z4=0;z4<((CxIntArray*)ag->m_oaAtoms[z2])->GetSize();z4++)
1470
 
                                                        {
1471
 
                                                                for (z5=0;z5<ia.GetSize();z5++)
1472
 
                                                                {
1473
 
                                                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ia[z5]]];
1474
 
                                                                        for (z6=0;z6<sm2->m_oaAtomOffset.GetSize();z6++)
1475
 
                                                                        {
1476
 
                                                                                for (z7=0;z7<((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetSize();z7++)
1477
 
                                                                                {
1478
 
                                                                                        if (((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetAt(z7) == ((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)))
1479
 
                                                                                        {
1480
 
                                                                                                eprintf("Atom %s%d from %s[%d] is already in the pseudo-molecule; skipping.\n",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)+1,m->m_sName,ia[z5]+1);
1481
 
                                                                                                m2->m_waAtomCount[m2->m_waAtomCount.GetSize()-1]--;
1482
 
                                                                                                goto _pseudomolsk2;
1483
 
                                                                                        }
1484
 
                                                                                }
1485
 
                                                                        }
1486
 
                                                                        pia->Add(((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
1487
 
        _pseudomolsk2:;
1488
 
                                                                }
1489
 
                                                        }
1490
 
        _pseudomold2:;
1491
 
                                                }
1492
 
                                        } else // If not custom labels
1493
 
                                        {
1494
 
                                                for (z2=0;z2<ag->m_baAtomType.GetSize();z2++)
1495
 
                                                {
1496
 
                                                        for (z4=0;z4<m2->m_baAtomIndex.GetSize();z4++)
1497
 
                                                        {
1498
 
                                                                if (m2->m_baAtomIndex[z4] == ag->m_baRealAtomType[z2])
1499
 
                                                                {
1500
 
                                                                        m2->m_waAtomCount[z4] += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
1501
 
                                                                        pia = (CxIntArray*)sm2->m_oaAtomOffset[z4];
1502
 
                                                                        goto _pmafound2;
1503
 
                                                                }
1504
 
                                                        }
1505
 
 
1506
 
                                                        m2->m_iAtomGes += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
1507
 
                                                        m2->m_baAtomIndex.Add(ag->m_baRealAtomType[z2]);
1508
 
                                                        sm2->m_baAtomIndex.Add(ag->m_baRealAtomType[z2]);
1509
 
                                                        m2->m_waAtomCount.Add(((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize());
1510
 
 
1511
 
                                                        try { pia = new CxIntArray("gather():pia"); } catch(...) { pia = NULL; }
1512
 
                                                        if (pia == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1513
 
 
1514
 
                                                        sm2->m_oaAtomOffset.Add(pia);
1515
 
_pmafound2:
1516
 
                                                        for (z4=0;z4<((CxIntArray*)ag->m_oaAtoms[z2])->GetSize();z4++)
1517
 
                                                        {
1518
 
                                                                for (z5=0;z5<ia.GetSize();z5++)
1519
 
                                                                {
1520
 
                                                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ia[z5]]];
1521
 
                                                                        for (z6=0;z6<sm2->m_oaAtomOffset.GetSize();z6++)
1522
 
                                                                        {
1523
 
                                                                                for (z7=0;z7<((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetSize();z7++)
1524
 
                                                                                {
1525
 
                                                                                        if (((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetAt(z7) == ((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)))
1526
 
                                                                                        {
1527
 
                                                                                                eprintf("Atom %s%d from %s[%d] is already in the pseudo-molecule; skipping.\n",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)+1,m->m_sName,ia[z5]+1);
1528
 
                                                                                                m2->m_waAtomCount[m2->m_waAtomCount.GetSize()-1]--;
1529
 
                                                                                                goto _pseudomolsk3;
1530
 
                                                                                        }
1531
 
                                                                                }
1532
 
                                                                        }
1533
 
                                                                        pia->Add(((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
1534
 
        _pseudomolsk3:;
1535
 
                                                                }
1536
 
                                                        }
1537
 
                                                }
1538
 
                                        }
1539
 
                                        delete ag;
1540
 
                                        if (AskYesNo("      Use another set of atoms from %s (y/n)? [no] ",false,m->m_sName))
1541
 
                                        {
1542
 
                                                try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
1543
 
                                                if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1544
 
                                                
1545
 
                                                goto _pseudomolp1;
1546
 
                                        }
1547
 
                                }
1548
 
                                mprintf("\n");
1549
 
                        }
1550
 
_nopseudomol:
1551
 
                        m2->BuildName();
1552
 
                        mprintf(WHITE,"    <<< Pseudo-molecule %d (= molecule %d) defined as %s <<<\n\n",ti,g_oaMolecules.GetSize(),m2->m_sName);
1553
 
                        if (AskYesNo("    Define another pseudo-molecule (y/n)? [no] ",false))
1554
 
                                goto _pseudomolnext;
1555
 
                        mprintf(WHITE,"\n    The following pseudo-molecules have been defined:\n");
1556
 
                        mprintf("      (note: pseudo-molecules start with a $ sign)\n\n");
1557
 
                        ti = 0;
1558
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
1559
 
                        {
1560
 
                                m = (CMolecule*)g_oaMolecules[z];
1561
 
                                if (m->m_bPseudo)
1562
 
                                {
1563
 
                                        ti++;
1564
 
                                        mprintf("      %d.) Molecule %d - %s\n",ti,z+1,m->m_sName);
1565
 
                                }
1566
 
                        }
1567
 
                        mprintf(WHITE,"\n    Defining virtual atom #1 as molecular Center of Geometry:\n");
1568
 
                        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
1569
 
                        {
1570
 
                                m = (CMolecule*)g_oaMolecules[z0];
1571
 
                                if (!m->m_bPseudo)
1572
 
                                        continue;
1573
 
                                mprintf("      - %s...\n",m->m_sName);
1574
 
                                va = AddVirtualAtom(z0);
1575
 
                                va->m_iMode = 0;
1576
 
                                va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
1577
 
                                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
1578
 
                                for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
1579
 
                                        va->m_faWeight[z] = 1.0f;
1580
 
                                va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
1581
 
                        }
1582
 
 
1583
 
                        mprintf(WHITE,"\n    Defining virtual atom #2 as molecular Center of Mass:\n");
1584
 
                        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
1585
 
                        {
1586
 
                                m = (CMolecule*)g_oaMolecules[z0];
1587
 
                                if (!m->m_bPseudo)
1588
 
                                        continue;
1589
 
                                mprintf("      - %s...\n",m->m_sName);
1590
 
                                va = AddVirtualAtom(z0);
1591
 
                                va->m_iMode = 0;
1592
 
                                va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
1593
 
                                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
1594
 
                                z3 = 0;
1595
 
                                tf2 = 0;
1596
 
                                for (z=0;z<va->m_oCenterAtoms.m_baAtomType.GetSize();z++)
1597
 
                                {
1598
 
                                        tf = ((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z]])->m_pElement->m_fMass;
1599
 
                                        for (z2=0;z2<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z])->GetSize();z2++)
1600
 
                                        {
1601
 
                                                va->m_faWeight[z3] = tf;
1602
 
                                                tf2 += tf;
1603
 
                                                z3++;
1604
 
                                        }
1605
 
                                }
1606
 
                                va->m_fGesWeight = tf2;
1607
 
                                if (va->m_fGesWeight == 0)
1608
 
                                {
1609
 
                                        eprintf("        Molecule %s has total mass of zero. Defining #2 as Center of Geometry.\n",m->m_sName);
1610
 
                                        for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
1611
 
                                                va->m_faWeight[z] = 1.0f;
1612
 
                                        va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
1613
 
                                }
1614
 
                        }
1615
 
                }
1616
 
        }
1617
 
 
1618
 
        mprintf(GREEN,"\n>>> %d virtual atoms have been defined: >>>\n",g_oaVirtualAtoms.GetSize());
1619
 
        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
1620
 
        {
1621
 
                for (z=0;z<((CMolecule*)g_oaMolecules[z0])->m_laVirtualAtoms.GetSize();z++)
1622
 
                {
1623
 
                        va = (CVirtualAtom*)g_oaVirtualAtoms[((CMolecule*)g_oaMolecules[z0])->m_laVirtualAtoms[z]];
1624
 
                        if (va->m_iMolVirtAtom < 2)
1625
 
                        {
1626
 
                                mprintf(WHITE,"\n    #%d in %s: %s.",va->m_iMolVirtAtom+1,((CMolecule*)g_oaMolecules[va->m_iMolecule])->m_sName,(va->m_iMolVirtAtom==0)?"Center of Geometry":"Center of Mass");
1627
 
                                if (va->m_iMolVirtAtom == 1)
1628
 
                                        mprintf("\n");
1629
 
                                continue;
1630
 
                        }
1631
 
                        mprintf(WHITE,"\n    #%d in %s - defined through %s\n",va->m_iMolVirtAtom+1,((CMolecule*)g_oaMolecules[va->m_iMolecule])->m_sName,(va->m_iMode==0)?"center:":"distance/angle/dihedral:");
1632
 
                        if (va->m_iMode == 0)
1633
 
                        {
1634
 
                                if (!((CMolecule*)g_oaMolecules[z0])->m_bPseudo || (z > 1))
1635
 
                                {
1636
 
                                        z4 = 0;
1637
 
                                        for (z2=0;z2<va->m_oCenterAtoms.m_baAtomType.GetSize();z2++)
1638
 
                                        {
1639
 
                                                for (z3=0;z3<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z2])->GetSize();z3++)
1640
 
                                                {
1641
 
                                                        mprintf("      - %2s%-3d  Weight %.2f%c\n",((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z2]])->m_sName,((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z2])->GetAt(z3)+1,va->m_faWeight[z4]/va->m_fGesWeight*100.0f,'%');
1642
 
                                                        z4++;
1643
 
                                                }
1644
 
                                        }
1645
 
                                } else mprintf("        (pseudo-molecule, skipping atoms)\n");
1646
 
                        } else
1647
 
                        {
1648
 
                                mprintf("      - Distance #%d-%s%d = %.2f pm\n",z+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,va->m_fValues[0]);
1649
 
                                mprintf("      - Angle #%d-%s%d-%s%d = %.2f degree\n",z+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1,va->m_fValues[1]*180.0/Pi);
1650
 
                                mprintf("      - Dihedral #%d-%s%d-%s%d-%s%d = %.2f degree\n",z+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[2]])->m_sName,va->m_iAtom[2]+1,va->m_fValues[2]*180.0/Pi);
1651
 
                        }
1652
 
                }
1653
 
        }
1654
 
        mprintf(GREEN,"\n<<< End of virtual atoms <<<\n\n");
1655
 
 
1656
 
        if (g_bPeriodic)
1657
 
                g_TimeStep.UniteMolecules(false);
1658
 
 
1659
 
        g_TimeStep.CalcCenters();
1660
 
        g_bFoldAtomwise = false;
1661
 
 
1662
 
        if (g_bPeriodic)
1663
 
                g_TimeStep.FoldMolecules();
1664
 
 
1665
 
        BuildAtomIndices();
1666
 
 
1667
 
//      g_TimeStep.WritePOV("step.pov");
1668
 
 
1669
 
        mprintf(WHITE,"\n>>> List of functions <<<\n\n");
1670
 
        DumpAnalyses();
1671
 
        
1672
 
        mprintf("   (You may specify multiple analyses at once, but\n");
1673
 
        mprintf("    the safe way is to perform only one kind of analysis at a time.)\n");
1674
 
_fncinput:
1675
 
        inpprintf("! Which functions to compute (comma separated)?\n");
1676
 
        mprintf("\n    Which functions to compute (comma separated)? ");
1677
 
        myget(buf);
1678
 
        mprintf("\n");
1679
 
        if (!ParseFunctions(buf))
1680
 
        {
1681
 
                eprintf("Wrong input.\n");
1682
 
                inpprintf("! Wrong input.\n");
1683
 
                goto _fncinput;
1684
 
        }
1685
 
        mprintf("\n");
1686
 
 
1687
 
        if (g_bRegionAnalysis)
1688
 
        {
1689
 
                if (!(g_bRDF || g_bSDF || g_bADF || g_bDDF || g_bCDF || g_bRevSDF || g_bDens))
1690
 
                {
1691
 
                        eprintf("    Region-specific analysis needs to be applied to some static analysis.\n\n");
1692
 
                        return false;
1693
 
                }
1694
 
                g_iaSMRegion.SetSize(g_oaSingleMolecules.GetSize());
1695
 
                for (z=0;z<g_oaSingleMolecules.GetSize();z++)
1696
 
                        g_iaSMRegion[z] = (rand()%2)+1;
1697
 
        }
1698
 
 
1699
 
        if (g_bVoro || g_bVoid || g_bSaveJustTraj || g_bSaveRefEnv || g_bCutCluster)
1700
 
                g_bNeedMoleculeWrap = true;
1701
 
 
1702
 
        if (g_bNPT && (g_bACF || g_bMSD))
1703
 
        {
1704
 
                mprintf(RED,"    Warning: ");
1705
 
                mprintf("When a variable cell vector is used, dynamical analyses (like spectra or MSDs)\n");
1706
 
                mprintf("             will give erroneous results.\n\n");
1707
 
        }
1708
 
 
1709
 
        mprintf(WHITE,"    The advanced mode includes some options which are quite powerful,\n    yet possibly weird or seldomly required.\n\n");
1710
 
 
1711
 
        g_bAdvanced2 = AskYesNo("    Use the advanced mode for the main part (y/n)? [no] ",false);
1712
 
        mprintf("\n");
1713
 
 
1714
 
        if (g_bThermo || g_bVDF || g_bRaman || g_bCombined || g_bBondACF || g_bVHDF || g_bACF || g_bUseVelocities || g_bUseForces || g_bMSD || g_bAggregation || g_bDLDisp || g_bDLDF || g_bDACF || g_bRDyn || g_bIRSpec || g_bIRSpec || g_bTimeDiff || g_bDeriv)
1715
 
        {
1716
 
                g_fTimestepLength = AskFloat("    Enter the length of one trajectory time step in fs: [0.5] ",0.5f);
1717
 
                mprintf("\n");
1718
 
        }
1719
 
 
1720
 
        /*********** Interface ***************/
1721
 
        if (!Interface_BeforeAnalysis())
1722
 
                return false;
1723
 
 
1724
 
        if (g_bCDF)
1725
 
        {
1726
 
                mprintf(YELLOW,"*** Combined Distribution Function\n\n");
1727
 
                g_iCDFChannels = AskUnsignedInteger("    How many channels should the Combined Distribution Function have? [2] ",2);
1728
 
 
1729
 
                try { g_iObsChannel = new int[g_iCDFChannels]; } catch(...) { g_iObsChannel = NULL; }
1730
 
                if (g_iObsChannel == NULL) NewException((double)g_iCDFChannels*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1731
 
                
1732
 
                mprintf("    Choose from these functions: rdf, adf, ddf, dip, vdf");
1733
 
                if (g_bBetaFeatures)
1734
 
                        mprintf(", pldf, lidf");
1735
 
                mprintf("\n");
1736
 
                for (z=0;z<g_iCDFChannels;z++)
1737
 
                {
1738
 
_entertype:
1739
 
                        AskString_ND("    Channel %d: Enter function type (e.g. rdf): ",buf,z+1);
1740
 
                        if (mystricmp(buf,"rdf")==0)
1741
 
                        {
1742
 
                                g_iObsChannel[z] = 0;
1743
 
                                g_bRDF = true;
1744
 
                        } else if (mystricmp(buf,"adf")==0)
1745
 
                        {
1746
 
                                g_iObsChannel[z] = 1;
1747
 
                                g_bADF = true;
1748
 
                        } else if (mystricmp(buf,"ddf")==0)
1749
 
                        {
1750
 
                                g_iObsChannel[z] = 2;
1751
 
                                g_bDDF = true;
1752
 
                        } else if (mystricmp(buf,"dip")==0)
1753
 
                        {
1754
 
                                g_iObsChannel[z] = 3;
1755
 
                                g_bDipDF = true;
1756
 
                        } else if (mystricmp(buf,"vdf")==0)
1757
 
                        {
1758
 
                                g_iObsChannel[z] = 4;
1759
 
                                g_bVDF = true;
1760
 
                        } else if ((mystricmp(buf,"pldf")==0) && g_bBetaFeatures)
1761
 
                        {
1762
 
                                g_iObsChannel[z] = 5;
1763
 
                                g_bPlDF = true;
1764
 
                        } else if ((mystricmp(buf,"lidf")==0) && g_bBetaFeatures)
1765
 
                        {
1766
 
                                g_iObsChannel[z] = 6;
1767
 
                                g_bLiDF = true;
1768
 
                        } else
1769
 
                        {
1770
 
                                eprintf("Wrong input.\n");
1771
 
                                inpprintf("! Wrong input.\n");
1772
 
                                goto _entertype;
1773
 
                        }
1774
 
                }
1775
 
        } else g_iCDFChannels = 1;
1776
 
 
1777
 
        if (g_bDipDF || g_bDipole)
1778
 
                ParseDipole();
1779
 
 
1780
 
        if (g_bVoro)
1781
 
        {
1782
 
                try { g_pVoroWrapper = new CVoroWrapper(); } catch(...) { g_pVoroWrapper = NULL; }
1783
 
                if (g_pVoroWrapper == NULL) NewException((double)sizeof(CVoroWrapper),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1784
 
                
1785
 
                g_pVoroWrapper->Parse();
1786
 
        }
1787
 
 
1788
 
/*      if (g_bSFac)
1789
 
        {
1790
 
                try { g_pSFac = new CStructureFactor(); } catch(...) { g_pSFac = NULL; }
1791
 
                if (g_pSFac == NULL) NewException((double)sizeof(CStructureFactor),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1792
 
                
1793
 
                g_pSFac->Parse();
1794
 
        }*/
1795
 
 
1796
 
        if (g_bResp)
1797
 
        {
1798
 
                try { g_pResp = new CResp(); } catch(...) { g_pResp = NULL; }
1799
 
                if (g_pResp == NULL) NewException((double)sizeof(CResp),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1800
 
                
1801
 
                g_pResp->m_pTimeStep = &g_TimeStep;
1802
 
                g_pResp->ParseResp();
1803
 
 
1804
 
                if (!g_bFFGen)
1805
 
                        return true;
1806
 
        }
1807
 
 
1808
 
        if (g_bFFGen)
1809
 
        {
1810
 
                try { g_pFFGen = new CFFGen(); } catch(...) { g_pFFGen = NULL; }
1811
 
                if (g_pFFGen == NULL) NewException((double)sizeof(CFFGen),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1812
 
                
1813
 
                g_pFFGen->Parse(&g_TimeStep);
1814
 
 
1815
 
                return true;
1816
 
        }
1817
 
 
1818
 
        if (g_bVoid)
1819
 
        {
1820
 
                try { g_pVoroWrapper = new CVoroWrapper(); } catch(...) { g_pVoroWrapper = NULL; }
1821
 
                if (g_pVoroWrapper == NULL) NewException((double)sizeof(CVoroWrapper),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1822
 
 
1823
 
                try { g_pVoroAnalysis = new CVoroAnalysis(); } catch(...) { g_pVoroAnalysis = NULL; }
1824
 
                if (g_pVoroAnalysis == NULL) NewException((double)sizeof(CVoroAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1825
 
                
1826
 
                g_pVoroAnalysis->Parse();
1827
 
        }
1828
 
 
1829
 
        if (g_bAggregation)
1830
 
        {
1831
 
                mprintf(WHITE,">>> Selection of Aggregation Functions >>>\n\n");
1832
 
 
1833
 
                g_bDACF = AskYesNo("    Compute Dimer Existence Autocorrelation Functions (DACFs) (y/n)? [yes] ",true);
1834
 
                g_bDLDF = AskYesNo("    Compute Dimer Lifetime Distribution Functions (DLDFs) (y/n)? [yes] ",true);
1835
 
                g_bDDisp = AskYesNo("    Compute Dimer Displacement Functions / Pair Diffusion (y/n)? [no] ",false);
1836
 
                if (g_bDDisp)
1837
 
                {
1838
 
                        g_bPairMSD = AskYesNo("    Compute Pair Mean Square Displacement (Pair Diffusion) (y/n)? [yes] ",true);
1839
 
                        g_bDLDisp = AskYesNo("    Compute combined Dimer Lifetime/Displacement Function (DLDisp) (y/n)? [yes] ",true);
1840
 
                } else
1841
 
                {
1842
 
                        g_bDLDisp = false;
1843
 
                        g_bPairMSD = false;
1844
 
                }
1845
 
 
1846
 
                mprintf(WHITE,"\n<<< Selection of Aggregation Functions <<<\n\n");
1847
 
        }
1848
 
 
1849
 
        if (g_bNbExchange)
1850
 
        {
1851
 
                mprintf(WHITE,">>> Selection of Neighborhood Exchange Functions >>>\n\n");
1852
 
                mprintf(WHITE,"\n<<< Selection of Neighborhood Exchange Functions <<<\n\n");
1853
 
        }
1854
 
        
1855
 
        if (g_bAdvanced2)
1856
 
        {
1857
 
                if (g_bRDyn || g_bIRSpec)
1858
 
                        g_bRDynCacheMode = AskYesNo("    Use RDyn cached mode (do this unless there are problems) (y/n)? [yes] ",true);
1859
 
 
1860
 
                if (g_bMSD)
1861
 
                        g_bMSDCacheMode = AskYesNo("    Use MSD cached mode (do this unless there are problems) (y/n)? [yes] ",true);
1862
 
        } else
1863
 
        {
1864
 
                g_bRDynCacheMode = true;
1865
 
                g_bMSDCacheMode = true;
1866
 
        }
1867
 
 
1868
 
        if (g_bClusterAnalysis)
1869
 
        {
1870
 
                try { g_pClusterAnalysis = new CClusterAnalysis(); } catch(...) { g_pClusterAnalysis = NULL; }
1871
 
                if (g_pClusterAnalysis == NULL) NewException((double)sizeof(CClusterAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1872
 
 
1873
 
                g_pClusterAnalysis->Parse();
1874
 
        }
1875
 
 
1876
 
        if (g_bMicroHet)
1877
 
        {
1878
 
                try { g_pMicroHet = new CMicroHet(); } catch(...) { g_pMicroHet = NULL; }
1879
 
                if (g_pMicroHet == NULL) NewException((double)sizeof(CMicroHet),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1880
 
 
1881
 
                g_pMicroHet->Parse();
1882
 
        }
1883
 
 
1884
 
        if (g_bThermo)
1885
 
        {
1886
 
                try { g_pThermoAnalysis = new CThermoAnalysis(); } catch(...) { g_pThermoAnalysis = NULL; }
1887
 
                if (g_pThermoAnalysis == NULL) NewException((double)sizeof(CThermoAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1888
 
 
1889
 
                g_pThermoAnalysis->Parse();
1890
 
        }
1891
 
 
1892
 
        if (g_bFESA)
1893
 
        {
1894
 
                try { g_pFESA = new CFESAnalysis(); } catch(...) { g_pFESA = NULL; }
1895
 
                if (g_pFESA == NULL) NewException((double)sizeof(CFESAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1896
 
 
1897
 
                g_pFESA->Parse();
1898
 
        }
1899
 
 
1900
 
        if (g_bACF)
1901
 
        {
1902
 
//              mprintf(YELLOW,">>> Select Autocorrelation Functions >>>\n\n");
1903
 
 
1904
 
                if (!g_bPowerSpec)
1905
 
                        g_bVACF = AskYesNo("    Calculate velocity autocorrelation function / power spectra (y/n)? [yes] ",true);
1906
 
                                else g_bVACF = true;
1907
 
 
1908
 
                if (g_bVACF)
1909
 
                        g_bUseVelocities = true;
1910
 
 
1911
 
/*              if (g_bBetaFeatures)
1912
 
                        g_bBondACF = AskYesNo("    Calculate bond vibration spectra (y/n)? [no] ",false);
1913
 
                                else*/ g_bBondACF = false;
1914
 
 
1915
 
/*              g_bDipACF = AskYesNo("    Calculate dipole autocorrelation function / IR spectra (y/n)? [no] ",false);
1916
 
                if (g_bDipACF)
1917
 
                        g_bDipole = true;*/
1918
 
 
1919
 
//              mprintf(YELLOW,"\n<<< End of Select Autocorrelation Functions <<<\n\n");
1920
 
        }
1921
 
        
1922
 
        if (g_bBondACF)
1923
 
        {
1924
 
                mprintf(WHITE,">>> Bond vibration spectra >>>\n\n");
1925
 
                if (g_iTrajSteps != -1)
1926
 
                        g_iBondACFDepth = AskUnsignedInteger("    Enter bond ACF depth in time steps: [%d] ",g_iTrajSteps/2,g_iTrajSteps/2);
1927
 
                                else g_iBondACFDepth = AskUnsignedInteger("    Enter bond ACF depth in time steps: [%d] ",4096,4096);
1928
 
                ti = CalcFFTSize(g_iBondACFDepth,false);
1929
 
                if (g_iBondACFDepth != ti)
1930
 
                {
1931
 
                        mprintf(WHITE,"\n    The next \"fast\" size for FFT is %d. Using this instead of %d as size.\n",ti,g_iBondACFDepth);
1932
 
                        g_iBondACFDepth = ti;
1933
 
                }
1934
 
                g_bBondACFNormalize = AskYesNo("    Normalize all bond ACFs (removes intensity info for the peaks) (y/n)? [no] ",false);
1935
 
                g_bBondACFSymmetrize = AskYesNo("    Symmetrize all bond ACFs (y/n)? [no] ",false);
1936
 
                g_bBondACFWindow = AskYesNo("    Apply window function to bond ACFs (y/n)? [yes] ",true);
1937
 
                g_bBondACFDebug = AskYesNo("    Write out bond ACF debug data (y/n)? [no] ",false);
1938
 
                mprintf(WHITE,"\n<<< End of Bond vibration spectra <<<\n\n");
1939
 
        }
1940
 
 
1941
 
        if (g_bRDyn || g_bIRSpec || g_bBondACF || g_bVACF)
1942
 
        {
1943
 
                if (g_bAdvanced2)
1944
 
                        g_bACFFFT = AskYesNo("    Use fourier transform for autocorrelation (much faster) (y/n)? [yes] ",true);
1945
 
                                else g_bACFFFT = true;
1946
 
        } else g_bACFFFT = true;
1947
 
 
1948
 
        if (g_bCDF || g_bDipDF || g_bRDF || g_bVHDF || g_bSDF || g_bPlDF || g_bLiDF || g_bVoidSDF || g_bRevSDF || g_bADF || g_bDDF || g_bSaveRefEnv || g_bCutCluster || g_bCond || g_bNbAnalysis)
1949
 
        {
1950
 
                if (g_oaMolecules.GetSize() > 1)
1951
 
                {
1952
 
                        sprintf(buf,"\n    Which of the molecules should be the reference molecule (");
1953
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
1954
 
                        {
1955
 
                                sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
1956
 
                                strcat(buf,buf2);
1957
 
                                if (z < g_oaMolecules.GetSize()-1)
1958
 
                                        strcat(buf,", ");
1959
 
                        }
1960
 
                        strcat(buf,")? ");
1961
 
                        g_iFixMol = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize()) - 1;
1962
 
                } else g_iFixMol = 0;
1963
 
                mprintf(WHITE,"\n    %s is the reference molecule.\n\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
1964
 
        } else g_iFixMol = -1;
1965
 
 
1966
 
        if (g_bSaveRefEnv)
1967
 
        {
1968
 
                mprintf(YELLOW,">>> Save environment of the reference molecule >>>\n\n");
1969
 
                g_bSaveRefWithEnv = AskYesNo("    Save the reference molecule itself (y/n)? [yes] ",true);
1970
 
                g_bRefEnvCenter = AskYesNo("    Center the reference molecule in the box (y/n)? [yes] ",true);
1971
 
                if (g_bRefEnvCenter)
1972
 
                {
1973
 
                        mprintf("\n    The first reference atom will be put into the middle of the box.\n\n");
1974
 
                        g_bRefEnvFix = AskYesNo("    Fix rotational freedom of the reference molecule (y/n)? [no] ",false);
1975
 
                        if (g_bRefEnvFix)
1976
 
                        {
1977
 
                                mprintf("\n    The 2nd reference atom will be put onto the positive X axis,\n");
1978
 
                                mprintf("    and the 3rd reference atom into the X-Y plane with positive Y values.\n\n");
1979
 
                        }
1980
 
                        mprintf(WHITE,"    You will be asked for the reference atom(s) lateron.\n\n");
1981
 
                }
1982
 
                if (((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize() > 1)
1983
 
                        g_iSaveRefMol = AskRangeInteger("    Which representative of the reference molecules to use (1-%d)? [1] ",1,((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize(),1,((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()) - 1;
1984
 
                                else g_iSaveRefMol = 0;
1985
 
                mprintf(WHITE,"\nPlease choose mode for neighborhood detection:\n\n");
1986
 
                inpprintf("! Please choose mode for neighborhood detection:\n");
1987
 
                mprintf("  1.) Search neighbors once in the beginning and always show those.\n");
1988
 
                mprintf("  2.) Search neighbors in every step and show the current neighbors.\n");
1989
 
                mprintf("      (Warning: Neighbor count differs from step to step - be aware.\n");
1990
 
                mprintf("  3.) Find the frequentiest neighbors over all steps and always show those.\n\n");
1991
 
                mprintf(WHITE,"    Please note: ");
1992
 
                mprintf("Programs such as VMD cannot handle variable atom count \n");
1993
 
                mprintf("    along a trajectory and will therefore not work properly with mode 2!\n\n");
1994
 
                g_iNbhMode = AskRangeInteger("    Choice (1-3): [3] ",1,3,3);
1995
 
                mprintf(YELLOW,"\n<<< End of Save environment of the reference molecule <<<\n\n");
1996
 
        }
1997
 
 
1998
 
        if (g_bCutCluster)
1999
 
        {
2000
 
                mprintf(WHITE,">>> Cut clusters >>>\n\n");
2001
 
                g_bSaveRefWithEnv = AskYesNo("    Show reference molecule itself (y/n)? [yes] ",true);
2002
 
                g_bRefEnvCenter = AskYesNo("    Center reference molecule in the box (y/n)? [yes] ",true);
2003
 
                if (g_bRefEnvCenter)
2004
 
                        g_bRefEnvFix = AskYesNo("    Fix rotational freedom of the reference molecule (y/n)? [no] ",false);
2005
 
_clustercount:
2006
 
                g_iClusterCount = AskUnsignedInteger("    How many clusters to create? [100] ",100);
2007
 
                g_iClusterSteps = AskUnsignedInteger("    How many time steps to use for cluster creation? [%d] ",g_iTrajSteps,g_iTrajSteps);
2008
 
                mprintf("\nCreating cluster distribution...");
2009
 
                for (z=0;z<g_iClusterCount;z++)
2010
 
                {
2011
 
                        if (fmod(z,g_iClusterCount/25.0) < 1.0)
2012
 
                                mprintf(".");
2013
 
                        z3=0;
2014
 
_clustagain:
2015
 
                        z3++;
2016
 
                        if (z3 > 500)
2017
 
                        {
2018
 
                                eprintf("Error: Too few molecules / time steps for requested cluster count.\n");
2019
 
                                goto _clustercount;
2020
 
                        }
2021
 
                        ti = ((((unsigned long)rand()%16384)+rand()*16384) % g_iClusterSteps) + 1;
2022
 
                        ti2 = rand()%((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize();
2023
 
                        for (z2=0;z2<g_iaClusterSteps.GetSize();z2++)
2024
 
                                if ((g_iaClusterSteps[z2] == ti) && (g_iaClusterMol[z2] == ti2))
2025
 
                                        goto _clustagain;
2026
 
                        g_iaClusterSteps.Add(ti);
2027
 
                        g_iaClusterMol.Add(ti2);
2028
 
                }
2029
 
                mprintf("Done.\n");
2030
 
                mprintf("Sorting cluster distribution...");
2031
 
                for (z=0;z<g_iClusterCount-1;z++)
2032
 
                {
2033
 
                        if (fmod(z,(g_iClusterCount-1)/25.0) < 1.0)
2034
 
                                mprintf(".");
2035
 
                        ti = 99999999;
2036
 
                        ti2 = 99999999;
2037
 
                        ti3 = -1;
2038
 
                        for (z2=z;z2<g_iClusterCount;z2++)
2039
 
                        {
2040
 
                                if (g_iaClusterSteps[z2] < ti)
2041
 
                                {
2042
 
                                        ti = g_iaClusterSteps[z2];
2043
 
                                        ti2 = g_iaClusterMol[z2];
2044
 
                                        ti3 = z2;
2045
 
                                } else if (g_iaClusterSteps[z2] == ti)
2046
 
                                {
2047
 
                                        if (g_iaClusterMol[z2] < ti2)
2048
 
                                        {
2049
 
                                                ti2 = g_iaClusterMol[z2];
2050
 
                                                ti3 = z2;
2051
 
                                        }
2052
 
                                }
2053
 
                        }
2054
 
                        if (ti3 == -1)
2055
 
                                abort();
2056
 
                        ti = g_iaClusterSteps[z];
2057
 
                        g_iaClusterSteps[z] = g_iaClusterSteps[ti3];
2058
 
                        g_iaClusterSteps[ti3] = ti;
2059
 
                        ti = g_iaClusterMol[z];
2060
 
                        g_iaClusterMol[z] = g_iaClusterMol[ti3];
2061
 
                        g_iaClusterMol[ti3] = ti;
2062
 
                }
2063
 
                mprintf("Done.\n\n");
2064
 
                mprintf("Writing cluster selection to \"cluster.csv\"...");
2065
 
                a = OpenFileWrite("cluster.csv",true);
2066
 
                mfprintf(a,"# Cluster;  Timestep;  Ref. Mol.\n");
2067
 
 
2068
 
                for (z=0;z<g_iClusterCount;z++)
2069
 
                        mfprintf(a,"%d;  %d;  %d\n",z+1,g_iaClusterSteps[z],g_iaClusterMol[z]+1);
2070
 
 
2071
 
                fclose(a);
2072
 
                mprintf("Done.\n\n");
2073
 
                mprintf(WHITE,"<<< End of Cut clusters <<<\n\n");
2074
 
        }
2075
 
 
2076
 
        if (g_bSDF || g_bVoidSDF || g_bAvg || ((g_bSaveRefEnv || g_bCutCluster) && g_bRefEnvFix)) // Nur fuer SDFs: Welche zwei weiteren Atome fixieren?
2077
 
        {
2078
 
                g_iRefSystemDim = 3;
2079
 
_ref3again:
2080
 
                mprintf("    Please enter three reference atoms (e.g. C1,H2,O1): ");
2081
 
                inpprintf("! Please enter three reference atoms (e.g. C1,H2,O1):\n");
2082
 
                myget(buf);
2083
 
                if (!ParseRefSystem(g_iFixMol,buf,3))
2084
 
                        goto _ref3again;
2085
 
                for (z=1;z<3;z++)
2086
 
                {
2087
 
                        for (z2=0;z2<z;z2++)
2088
 
                        {
2089
 
                                if ((g_iFixAtomType[z] == g_iFixAtomType[z2]) && (g_iFixAtom[z] == g_iFixAtom[z2]))
2090
 
                                {
2091
 
                                        eprintf("Please enter three different atoms.\n\n");
2092
 
                                        inpprintf("! Please enter three different atoms.\n");
2093
 
                                        goto _ref3again;
2094
 
                                }
2095
 
                        }
2096
 
                }
2097
 
                mprintf("\n");
2098
 
                mprintf(WHITE,"Reference plane: Fixing in %s the %d. %s-, the %d. %s- and the %d. %s atom.\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,g_iFixAtom[0]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[0]])->m_sName,g_iFixAtom[1]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[1]])->m_sName,g_iFixAtom[2]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[2]])->m_sName);
2099
 
                mprintf("\n");
2100
 
        } else if (g_bRevSDF)
2101
 
        {
2102
 
                g_iRefSystemDim = 2;
2103
 
_ref2again:
2104
 
                mprintf("    Please enter two reference atoms (e.g. C1,H3): ");
2105
 
                inpprintf("! Please enter two reference atoms (e.g. C1,H3):\n");
2106
 
                myget(buf);
2107
 
                if (!ParseRefSystem(g_iFixMol,buf,2))
2108
 
                        goto _ref2again;
2109
 
                if ((g_iFixAtomType[0] == g_iFixAtomType[1]) && (g_iFixAtom[0] == g_iFixAtom[1]))
2110
 
                {
2111
 
                        eprintf("Please enter two different atoms.\n\n");
2112
 
                        inpprintf("! Please enter two different atoms.\n");
2113
 
                        goto _ref2again;
2114
 
                }
2115
 
                mprintf("\n");
2116
 
                mprintf(WHITE,"Reference axis: Fixing in %s the %d. %s and the %d. %s atom.\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,g_iFixAtom[0]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[0]])->m_sName,g_iFixAtom[1]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[1]])->m_sName);
2117
 
                mprintf("\n");
2118
 
        } else if (g_bVHDF || g_bRDF || g_bADF || g_bPlDF || g_bLiDF || g_bDDF || g_bSaveRefEnv || g_bSaveRefEnv || g_bCutCluster) // Fuer Verteilungsfunktion: Welches Atom im Ursprung
2119
 
        {
2120
 
                g_iRefSystemDim = 1;
2121
 
                if (g_bAdvanced2)
2122
 
                {
2123
 
_ref1again:
2124
 
                        mprintf("    Please enter the atom to put into the box center (e.g. C3): [center of mass] ");
2125
 
                        inpprintf("! Please enter the atom to put into the box center (e.g. C3): [center of mass]\n");
2126
 
                        myget(buf);
2127
 
                        if (strlen(buf)==0)
2128
 
                        {
2129
 
                                if (!ParseRefSystem(g_iFixMol,"#2",1))
2130
 
                                {
2131
 
                                        eprintf("Weird error.\n");
2132
 
                                        inpprintf("! Weird error.\n");
2133
 
                                        abort();
2134
 
                                }
2135
 
                        } else if (!ParseRefSystem(g_iFixMol,buf,1))
2136
 
                                goto _ref1again;
2137
 
                        mprintf("\n");
2138
 
                        mprintf(WHITE,"Reference atom: Fixing in %s the %d. %s atom.\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,g_iFixAtom[0]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[0]])->m_sName);
2139
 
                        mprintf("\n");
2140
 
                } else
2141
 
                {
2142
 
                        if (!ParseRefSystem(g_iFixMol,"#2",1))
2143
 
                        {
2144
 
                                eprintf("Weird error.\n");
2145
 
                                inpprintf("! Weird error.\n");
2146
 
                                abort();
2147
 
                        }
2148
 
                }
2149
 
        } else if (g_iFixMol != -1)
2150
 
        {
2151
 
                g_iRefSystemDim = 1;
2152
 
                if (!ParseRefSystem(g_iFixMol,"#2",1))
2153
 
                {
2154
 
                        eprintf("Weird error.\n");
2155
 
                        abort();
2156
 
                }
2157
 
                mprintf("    Reference atom: Fixing in %s the %d. %s atom.\n\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,g_iFixAtom[0]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[0]])->m_sName);
2158
 
        }
2159
 
 
2160
 
        if (g_bSaveRefEnv || g_bCutCluster)
2161
 
        {
2162
 
                mprintf(WHITE,">>> Neighborhood Definition >>>\n\n");
2163
 
 
2164
 
                try { g_pNbSet = new CNbSet(); } catch(...) { g_pNbSet = NULL; }
2165
 
                if (g_pNbSet == NULL) NewException((double)sizeof(CNbSet),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2166
 
                
2167
 
                g_pNbSet->Parse(g_iFixMol);
2168
 
                mprintf(WHITE,"\n<<< End of Neighborhood Definition <<<\n\n");
2169
 
 
2170
 
                if (g_bSaveRefEnv)
2171
 
                {
2172
 
                        if (AskYesNo("    Create a temporal development overlay (TDO) plot (y/n)? [no] ",false))
2173
 
                        {
2174
 
                                g_bTDO = true;
2175
 
                                g_laTDOSteps.RemoveAll();
2176
 
                                if (AskYesNo("    Use equidistant intervals (y) or specify each point (n) (y/n)? [yes] ",true))
2177
 
                                {
2178
 
                                        g_bTDOEqui = true;
2179
 
                                        g_iTDOCount = AskUnsignedInteger("    Enter the overlay count: [5] ",5);
2180
 
                                        g_iTDOStart = AskUnsignedInteger("    Enter the starting timestep: [0] ",0);
2181
 
                                        g_iTDOStride = AskUnsignedInteger("    Enter the overlay distance in steps: [1000] ",1000);
2182
 
                                        for (z=0;z<g_iTDOCount;z++)
2183
 
                                                g_laTDOSteps.Add(g_iTDOStart+z*g_iTDOStride);
2184
 
                                } else
2185
 
                                {
2186
 
                                        g_bTDOEqui = false;
2187
 
                                        while (true)
2188
 
                                        {
2189
 
                                                ti = AskUnsignedInteger("    Enter timestep for %dth overlay: [done] ",999999,g_laTDOSteps.GetSize()+1);
2190
 
                                                if (ti == 999999)
2191
 
                                                        break;
2192
 
                                                g_laTDOSteps.Add(ti);
2193
 
                                        }
2194
 
                                }
2195
 
                                g_fTDOBleaching = AskRangeFloat("    Enter the TDO bleaching grade (0-1): [0.8] ",0.0f,1.0f,0.8f);
2196
 
                        } else g_bTDO = false;
2197
 
                }
2198
 
        }
2199
 
 
2200
 
        if (g_bAggregation || g_bNbAnalysis || g_bPlDF || g_bLiDF || g_bRDyn || g_bIRSpec || g_bDipDF || g_bMSD || g_bADF || g_bDDF || g_bVACF || g_bDipACF || g_bRevSDF || g_bSDF || g_bVHDF || g_bRDF || g_bDens || g_bVDF || g_bFDF || g_bCond) // Fuer Verteilungsfunktion: Welches Atom beobachten?
2201
 
        {
2202
 
                if (g_bVACF)
2203
 
                {
2204
 
                        if (g_bAdvanced2)
2205
 
                                g_bVACFCacheMode = AskYesNo("    Use VACF cached mode (do this unless there are problems) (y/n)? [yes] ",true);
2206
 
                                        else g_bVACFCacheMode = true;
2207
 
 
2208
 
                        if (g_bPowerSpec)
2209
 
                        {
2210
 
                                g_bGlobalVACF = AskYesNo("    Compute power spectrum of whole system (y/n)? [yes] ",true);
2211
 
 
2212
 
                                if (g_bGlobalVACF)
2213
 
                                        if (!AskYesNo("    Compute also power spectra for certain atoms/molecules (y/n)? [no] ",false))
2214
 
                                                goto _endobs;
2215
 
                        } else
2216
 
                        {
2217
 
                                g_bGlobalVACF = AskYesNo("    Compute global velocity ACF of whole system (y/n)? [yes] ",true);
2218
 
 
2219
 
                                if (g_bGlobalVACF)
2220
 
                                        if (!AskYesNo("    Compute also velocity ACFs for certain atoms/molecules (y/n)? [no] ",false))
2221
 
                                                goto _endobs;
2222
 
                        }
2223
 
                }
2224
 
 
2225
 
                if (g_bIRSpec)
2226
 
                {
2227
 
                        g_bGlobalIR = AskYesNo("    Compute IR spectrum of whole system (y/n)? [yes] ",true);
2228
 
                        if (g_bGlobalIR)
2229
 
                                if (!AskYesNo("    Compute also IR spectra for certain molecule types (y/n)? [no] ",false))
2230
 
                                        goto _endobs;
2231
 
                }
2232
 
 
2233
 
/*              if (g_bDipACF)
2234
 
                {
2235
 
                        g_bGlobalDipACF = AskYesNo("    Create global dipole ACF of all atoms (y/n)? [yes] ",true);
2236
 
                }*/
2237
 
_nextsdf:
2238
 
                mprintf(YELLOW,"\n>>> Observation %d >>>\n\n",g_oaObserv.GetSize()+1);
2239
 
 
2240
 
                try { o = new CObservation(); } catch(...) { o = NULL; }
2241
 
                if (o == NULL) NewException((double)sizeof(CObservation),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2242
 
                
2243
 
                o->m_pConditions = NULL;
2244
 
                g_oaObserv.Add(o);
2245
 
                o->m_bTimeDev = false;
2246
 
                if (g_bAggregation || g_bNbExchange)
2247
 
                {
2248
 
                        o->m_bSelf = false;
2249
 
                        o->m_bOthers = false;
2250
 
                } else if (g_bNbAnalysis)
2251
 
                {
2252
 
                        o->m_bSelf = false;
2253
 
                        o->m_bOthers = true;
2254
 
                        mprintf("    Performing this observation intermolecular.\n\n");
2255
 
                } else if (g_iFixMol != -1)
2256
 
                {
2257
 
                        if (AskRangeInteger("    Perform this observation intramolecular (within the reference molecule) (0) or intermolecular (1)? [1] ",0,1,1) == 1)
2258
 
                        {
2259
 
                                o->m_bSelf = false;
2260
 
                                o->m_bOthers = true;
2261
 
                        } else
2262
 
                        {
2263
 
                                o->m_bSelf = true;
2264
 
                                o->m_bOthers = false;
2265
 
                        }
2266
 
                        mprintf("\n");
2267
 
                } else 
2268
 
                {
2269
 
                        o->m_bSelf = false;
2270
 
                        o->m_bOthers = true;
2271
 
                }
2272
 
                if (o->m_bOthers)
2273
 
                {
2274
 
                        if (g_bCDF)
2275
 
                        {
2276
 
                                mprintf(WHITE,"    Please note: ");
2277
 
                                mprintf("Although you specified this observation to be intermolecular, you may of course\n");
2278
 
                                mprintf("                 choose atoms from RM only (or OM only), which will yield an intramolecular quantity.\n\n");
2279
 
                        }
2280
 
                        if (g_bCDF)
2281
 
                                o->m_bSecondShowMol = AskYesNo("    CDF: Perform a three-body analysis (y) or observe one molecule at a time (n)? [no] ",false);
2282
 
                                        else o->m_bSecondShowMol = false;
2283
 
                        if (o->m_bSecondShowMol)
2284
 
                        {
2285
 
                                mprintf(WHITE,"\n    You have to select two observed molecules (OMs):\n");
2286
 
                                mprintf("    The first CDF channel observes the 1st OM, the second channel observes the 2nd OM.\n\n");
2287
 
                        }
2288
 
                        if (g_oaMolecules.GetSize() > 1)
2289
 
                        {
2290
 
_obsmolagain:
2291
 
                                if (o->m_bSecondShowMol)
2292
 
                                        sprintf(buf,"    Which 1st molecule should be observed (");
2293
 
                                                else sprintf(buf,"    Which molecule should be observed (");
2294
 
                                for (z=0;z<g_oaMolecules.GetSize();z++)
2295
 
                                {
2296
 
                                        sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
2297
 
                                        strcat(buf,buf2);
2298
 
                                        if (z < g_oaMolecules.GetSize()-1)
2299
 
                                                strcat(buf,", ");
2300
 
                                }
2301
 
                                strcat(buf,")? ");
2302
 
                                o->m_iShowMol = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize()) - 1;
2303
 
                                if ((((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize() == 1) && (o->m_iShowMol == g_iFixMol))
2304
 
                                {
2305
 
                                        eprintf("Error: There is only 1 molecule of %s.\n--> Intermolecular observation between %s and %s not possible.\n\n",((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
2306
 
                                        goto _obsmolagain;
2307
 
                                }
2308
 
                        } else 
2309
 
                        {
2310
 
                                mprintf("    Only one molecule type, choosing %s as observed molecule (OM).\n",((CMolecule*)g_oaMolecules[0])->m_sName);
2311
 
                                o->m_iShowMol = 0;
2312
 
                        }
2313
 
                        o->m_iShowMolCount = ((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize();
2314
 
                        if (o->m_bSecondShowMol)
2315
 
                        {
2316
 
                                if (g_oaMolecules.GetSize() > 1)
2317
 
                                {
2318
 
_obsmol2again:
2319
 
                                        sprintf(buf,"    Which 2nd molecule should be observed (");
2320
 
                                        for (z=0;z<g_oaMolecules.GetSize();z++)
2321
 
                                        {
2322
 
                                                sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
2323
 
                                                strcat(buf,buf2);
2324
 
                                                if (z < g_oaMolecules.GetSize()-1)
2325
 
                                                        strcat(buf,", ");
2326
 
                                        }
2327
 
                                        strcat(buf,")? ");
2328
 
                                        o->m_iShowMol2 = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize()) - 1;
2329
 
                                        if ((((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_laSingleMolIndex.GetSize() == 1) && (o->m_iShowMol2 == g_iFixMol))
2330
 
                                        {
2331
 
                                                eprintf("Error: There is only 1 molecule of %s.\n  --> Intermolecular observation between %s and %s not possible.\n\n",((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName);
2332
 
                                                goto _obsmol2again;
2333
 
                                        }
2334
 
                                } else o->m_iShowMol2 = 0;
2335
 
                                o->m_iShowMol2Count = ((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_laSingleMolIndex.GetSize();
2336
 
                                if (o->m_iShowMol == o->m_iShowMol2)
2337
 
                                        o->m_bExclude1eq2 = AskYesNo("    Exclude the case \"1st OM = 2nd OM\" (y/n)? [yes] ",true);
2338
 
                                                else o->m_bExclude1eq2 = false;
2339
 
                        }
2340
 
                } else 
2341
 
                {
2342
 
                        o->m_iShowMol = -1;
2343
 
                        o->m_iShowMol2 = -1;
2344
 
                        o->m_bSecondShowMol = false;
2345
 
                        o->m_iShowMolCount = 1;
2346
 
                }
2347
 
 
2348
 
                buf[0] = 0;
2349
 
                if ((o->m_bSecondShowMol) && (o->m_iShowMol != o->m_iShowMol2))
2350
 
                        sprintf(buf," of %s / %s / %s",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName);
2351
 
                                else if ((o->m_iShowMol != -1) && (g_iFixMol != -1))
2352
 
                                        sprintf(buf," of %s / %s",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
2353
 
                                                else if (g_iFixMol != -1) sprintf(buf," of %s",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
2354
 
 
2355
 
                if (g_iFixMol != -1)
2356
 
                {
2357
 
                        if (g_bAdvanced2)
2358
 
                        {
2359
 
                                if (AskYesNo("    Observe only certain molecules%s (y/n)? [no] ",false,buf))
2360
 
                                {
2361
 
                                        o->m_bObsCertain = true;
2362
 
                                        if (!g_bCDF && (g_bRDF || g_bADF || g_bDDF || g_bDipDF))
2363
 
                                                o->m_bDecompDist = AskYesNo("    Decompose distribution functions into contributions from molecules (y/n)? [yes] ",true);
2364
 
                                        
2365
 
                                        if (((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize() > 1)
2366
 
                                        {
2367
 
                                                mprintf("    Which %s molecules (RM) to take into account (e.g. 1,3-7)? [all] ",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
2368
 
                                                inpprintf("! Which %s molecules (RM) to take into account (e.g. 1,3-7)? [all]\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
2369
 
                                                myget(buf);
2370
 
                                                if (strlen(buf)==0)
2371
 
                                                {
2372
 
                                                        for (z=0;z<((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize();z++)
2373
 
                                                                o->m_waObsRefList.Add(z);
2374
 
                                                } else
2375
 
                                                {
2376
 
                                                        ParseIntList(buf,&o->m_waObsRefList);
2377
 
                                                        for (z=0;z<o->m_waObsRefList.GetSize();z++)
2378
 
                                                                o->m_waObsRefList[z]--;
2379
 
                                                }
2380
 
                                        } else o->m_waObsRefList.Add(0);
2381
 
 
2382
 
                                //      mprintf("RefList[0] = %d\n",o->m_waObsRefList[0]);
2383
 
 
2384
 
                                        if (o->m_iShowMol != -1)
2385
 
                                        {
2386
 
                                                if (((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize() > 1)
2387
 
                                                {
2388
 
                                                        mprintf("    Which %s molecules (OM) to take into account (e.g. 1,3-7)? [all] ",((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
2389
 
                                                        inpprintf("! Which %s molecules (OM) to take into account (e.g. 1,3-7)? [all]\n",((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
2390
 
                                                        myget(buf);
2391
 
                                                        if (strlen(buf)==0)
2392
 
                                                        {
2393
 
                                                                for (z=0;z<((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize();z++)
2394
 
                                                                        o->m_waObsShowList.Add(z);
2395
 
                                                        } else
2396
 
                                                        {
2397
 
                                                                ParseIntList(buf,&o->m_waObsShowList);
2398
 
                                                                for (z=0;z<o->m_waObsShowList.GetSize();z++)
2399
 
                                                                        o->m_waObsShowList[z]--;
2400
 
                                                        }
2401
 
                                                } else o->m_waObsShowList.Add(0);
2402
 
                                        } else o->m_waObsShowList.Add(0); // Dummy
2403
 
 
2404
 
                                        if (o->m_bSecondShowMol)
2405
 
                                        {
2406
 
                                                if (o->m_iShowMol2 != -1)
2407
 
                                                {
2408
 
                                                        if (((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_laSingleMolIndex.GetSize() > 1)
2409
 
                                                        {
2410
 
                                                                mprintf("    Which %s molecules (2nd OM) to take into account (e.g. 1,3-7)? [all] ",((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName);
2411
 
                                                                inpprintf("! Which %s molecules (2nd OM) to take into account (e.g. 1,3-7)? [all]\n",((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName);
2412
 
                                                                myget(buf);
2413
 
                                                                if (strlen(buf)==0)
2414
 
                                                                {
2415
 
                                                                        for (z=0;z<((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_laSingleMolIndex.GetSize();z++)
2416
 
                                                                                o->m_waObsShow2List.Add(z);
2417
 
                                                                } else
2418
 
                                                                {
2419
 
                                                                        ParseIntList(buf,&o->m_waObsShow2List);
2420
 
                                                                        for (z=0;z<o->m_waObsShow2List.GetSize();z++)
2421
 
                                                                                o->m_waObsShow2List[z]--;
2422
 
                                                                }
2423
 
                                                        } else o->m_waObsShow2List.Add(0);
2424
 
                                                } else o->m_waObsShow2List.Add(0); // Dummy
2425
 
                                        }
2426
 
                                } else // if not onlysome
2427
 
                                {
2428
 
                                        o->m_bObsCertain = false;
2429
 
                                        o->m_bDecompDist = false;
2430
 
                                }
2431
 
                        } else // if not advanced
2432
 
                        {
2433
 
                                o->m_bObsCertain = false;
2434
 
                                o->m_bDecompDist = false;
2435
 
                        }
2436
 
                } else
2437
 
                {
2438
 
                        o->m_bObsCertain = false;
2439
 
                        o->m_bDecompDist = false;
2440
 
                }
2441
 
 
2442
 
                o->m_bDecompType = false;
2443
 
 
2444
 
                if ((!o->m_bObsCertain) && (!g_bCDF) && g_bAdvanced2 && (g_bRDF || g_bADF || g_bDDF || g_bDipDF))
2445
 
                {
2446
 
                        if (AskYesNo("    Decompose this observation into contributions from different elements (y/n)? [no] ",false))
2447
 
                        {
2448
 
                                o->m_bDecompType = true;
2449
 
                        }
2450
 
                }
2451
 
 
2452
 
                if (g_bRegionAnalysis)
2453
 
                {
2454
 
                        AskString("    Take reference molecules from which regions? [all] ",buf,"0");
2455
 
                        ParseIntList(buf,&o->m_iaRMRegions);
2456
 
        //              for (z6=0;z6<o->m_iaRMRegions.GetSize();z6++)
2457
 
        //                      if (o->m_iaRMRegions[z6] != 0)
2458
 
        //                              o->m_iaRMRegions[z6]--;
2459
 
 
2460
 
                        if (o->m_bOthers)
2461
 
                        {
2462
 
                                if (o->m_bSecondShowMol)
2463
 
                                {
2464
 
                                        AskString("    Take 1st observed molecules from which regions? [all] ",buf,"0");
2465
 
                                        ParseIntList(buf,&o->m_iaOM1Regions);
2466
 
                                //      for (z6=0;z6<o->m_iaOM1Regions.GetSize();z6++)
2467
 
                                //              if (o->m_iaOM1Regions[z6] != 0)
2468
 
                                //                      o->m_iaOM1Regions[z6]--;
2469
 
                                        AskString("    Take 2nd observed molecules from which regions? [all] ",buf,"0");
2470
 
                                        ParseIntList(buf,&o->m_iaOM2Regions);
2471
 
                                //      for (z6=0;z6<o->m_iaOM2Regions.GetSize();z6++)
2472
 
                                //              if (o->m_iaOM2Regions[z6] != 0)
2473
 
                                //                      o->m_iaOM2Regions[z6]--;
2474
 
                                } else
2475
 
                                {
2476
 
                                        AskString("    Take observed molecules from which regions? [all] ",buf,"0");
2477
 
                                        ParseIntList(buf,&o->m_iaOM1Regions);
2478
 
                                //      for (z6=0;z6<o->m_iaOM1Regions.GetSize();z6++)
2479
 
                                //              if (o->m_iaOM1Regions[z6] != 0)
2480
 
                                //                      o->m_iaOM1Regions[z6]--;
2481
 
                                }
2482
 
                        }
2483
 
                }
2484
 
 
2485
 
                if (g_bAggregation || g_bNbExchange)
2486
 
                {
2487
 
                        try { o->m_pDACF = new CDACF(); } catch(...) { o->m_pDACF = NULL; }
2488
 
                        if (o->m_pDACF == NULL) NewException((double)sizeof(CDACF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2489
 
                        
2490
 
                        o->m_pDACF->Parse();
2491
 
                }
2492
 
 
2493
 
                if (g_bRDyn)
2494
 
                {
2495
 
                        try { o->m_pRDyn = new CReorDyn(); } catch(...) { o->m_pRDyn = NULL; }
2496
 
                        if (o->m_pRDyn == NULL) NewException((double)sizeof(CReorDyn),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2497
 
                        
2498
 
                        o->m_pRDyn->m_iShowMol = o->m_iShowMol;
2499
 
                        o->m_pRDyn->Parse();
2500
 
                }
2501
 
 
2502
 
                if (g_bIRSpec)
2503
 
                {
2504
 
                        try { o->m_pIRSpec = new CReorDyn(); } catch(...) { o->m_pIRSpec = NULL; }
2505
 
                        if (o->m_pIRSpec == NULL) NewException((double)sizeof(CReorDyn),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2506
 
                        
2507
 
                        o->m_pIRSpec->m_iShowMol = o->m_iShowMol;
2508
 
                        o->m_pIRSpec->ParseSpec();
2509
 
                }
2510
 
 
2511
 
                if (g_bDens)
2512
 
                {
2513
 
                        try { o->m_pDensityDF = new CDensDF(); } catch(...) { o->m_pDensityDF = NULL; }
2514
 
                        if (o->m_pDensityDF == NULL) NewException((double)sizeof(CDensDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2515
 
                        
2516
 
                        o->m_pDensityDF->m_iShowMol = o->m_iShowMol;
2517
 
                        o->m_pDensityDF->Parse();
2518
 
                }
2519
 
                        
2520
 
                if (g_bSDF)
2521
 
                {
2522
 
                        try { o->m_pSDF = new CSDF(); } catch(...) { o->m_pSDF = NULL; }
2523
 
                        if (o->m_pSDF == NULL) NewException((double)sizeof(CSDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
33
#include "plproj.h"
 
34
 
 
35
 
 
36
bool GatherInfos()
 
37
{
 
38
        BTIN;
 
39
        char buf[4096], buf2[256];
 
40
        float tf, tf2;
 
41
        FILE *a;
 
42
        bool tb=false, tb2;
 
43
        int z, z0, z2, z3, z4, z5, z6, z7;
 
44
        int ti, ti2, ti3;
 
45
        unsigned char ty, rty, atom;
 
46
        unsigned char ty2, rty2, atom2;
 
47
        CVirtualAtom *va;
 
48
        CObservation *o;
 
49
        CMolecule *mol;
 
50
        CSingleMolecule *sm, *sm2;
 
51
        CAtomGroup *ag;
 
52
        CxWordArray tempwa;
 
53
        CMolecule *m, *m2;
 
54
        CAtom *at;
 
55
        CElement *el;
 
56
        CxIntArray *pia, ia;
 
57
 
 
58
        g_bKeepUnfoldedCoords = false;
 
59
        g_iDoubleBoxFactor = 1;
 
60
        g_bBondACF = false;
 
61
        g_bCombined = false;
 
62
        g_bRefEnvFix = false;
 
63
        g_bTimeDiff = false;
 
64
        g_bRemoveCOM = false;
 
65
        g_bSaveCoordsUnchanged = false;
 
66
        g_bSDFUniform = false;
 
67
        a = NULL;
 
68
        ti2 = -1;
 
69
 
 
70
        mprintf(YELLOW,"\n*** Interactive query of settings ***\n\n");
 
71
//      SAVEPOS;
 
72
 
 
73
        ti = 0;
 
74
        if (g_bUnknownElements)
 
75
        {
 
76
                tb2 = false;
 
77
_unkstart:
 
78
                tb = false;
 
79
                mprintf(WHITE,"Unrecognized atom types: ");
 
80
                for (z=0;z<g_oaAtoms.GetSize();z++)
 
81
                {
 
82
                        if (z == g_iVirtAtomType)
 
83
                                continue;
 
84
 
 
85
                        at = (CAtom*)g_oaAtoms[z];
 
86
                        while (at->m_pMergedTo != NULL)
 
87
                        {
 
88
//                              mprintf("%s merged to %s\n",at->m_sName,at->m_pMergedTo->m_sName);
 
89
                                at = at->m_pMergedTo;
 
90
                        }
 
91
                        if (at->m_pElement->m_fRadius != 0)
 
92
                                continue;
 
93
                        if (tb)
 
94
                                mprintf(", ");
 
95
                        tb = true;
 
96
                        mprintf("%s",at->m_sName);
 
97
                        ti++;
 
98
                        ti2 = z;
 
99
                }
 
100
                mprintf("\n\n");
 
101
 
 
102
                if ((ti == 1) && (mystricmp("X",((CAtom*)g_oaAtoms[ti2])->m_sName) == 0))
 
103
                {  // Only Wannier centers unrecognized.
 
104
                        mprintf("    Possibly, atom type \"X\" are Wannier centers. If so, do not assign data to them.\n\n");
 
105
                        tb2 = false; 
 
106
                } else tb2 = true;
 
107
 
 
108
                tb = false;
 
109
                if (AskYesNo("    Do you want to assign atom data to them (y/n)? [%s] ",tb2,tb2?"yes":"no"))
 
110
                {
 
111
                        if (tb2)
 
112
                        {
 
113
                                if (AskYesNo("    Automatically rename all atoms to corresponding elements (y/n)? [yes] ",true))
 
114
                                {
 
115
                                        mprintf("\n");
 
116
                                        tb2 = true;
 
117
                                        tb = false;
 
118
                                        for (z=0;z<g_oaAtoms.GetSize();z++)
 
119
                                        {
 
120
                                                if (z == g_iVirtAtomType)
 
121
                                                        continue;
 
122
 
 
123
                                                at = (CAtom*)g_oaAtoms[z];
 
124
                                                if (at->m_pElement->m_fRadius != 0)
 
125
                                                        continue;
 
126
 
 
127
                                                buf2[0] = at->m_sName[0];
 
128
                                                buf2[1] = at->m_sName[1];
 
129
                                                buf2[2] = 0;
 
130
                                                el = FindElement(buf2,true);
 
131
                                                if (el != NULL)
 
132
                                                {
 
133
                                                        if (el->m_fRadius == 0)
 
134
                                                                goto _unkX2;
 
135
                                                } else
 
136
                                                {
 
137
_unkX2:
 
138
                                                        buf2[1] = 0;
 
139
                                                        el = FindElement(buf2,true);
 
140
                                                        if (el != NULL)
 
141
                                                        {
 
142
                                                                if (el->m_fRadius == 0)
 
143
                                                                        goto _unkX3;
 
144
                                                        } else
 
145
                                                        {
 
146
_unkX3:
 
147
                                                                strcpy(buf2,at->m_sName);
 
148
                                                        }
 
149
                                                }
 
150
                                                if (el == NULL)
 
151
                                                {
 
152
                                                        mprintf("    - Skipping %s... (have no guess for atom type)\n",at->m_sName);
 
153
                                                        tb = true;
 
154
                                                        continue;
 
155
                                                }
 
156
 
 
157
                                                xAddAtom(buf2);
 
158
 
 
159
                                                mprintf("    - Renaming %s to %s...\n",at->m_sName,buf2);
 
160
                                                for (z2=0;z2<g_oaAtoms.GetSize();z2++)
 
161
                                                {
 
162
                                                        if (((CAtom*)g_oaAtoms[z2])->m_pElement == el)
 
163
                                                        {
 
164
                                                                at = (CAtom*)g_oaAtoms[z2];
 
165
                                                                el = at->m_pElement;
 
166
                                                                goto _unkX1;
 
167
                                                        }
 
168
                                                }
 
169
                                                eprintf("    Strange error ^^\n");
 
170
_unkX1:;
 
171
                                                for (z2=0;z2<(int)g_TimeStep.m_iGesAtomCount;z2++)
 
172
                                                {
 
173
                                                        strcpy(buf,(char*)g_TimeStep.m_paLabels[z2]);
 
174
                                                        ReplaceDigits(buf);
 
175
                                                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
 
176
                                                        {
 
177
                                                                at->m_iCount++;
 
178
                                                                ((CAtom*)g_oaAtoms[z])->m_iCount--;
 
179
                                                        }
 
180
                                                }
 
181
//                                              mprintf("\nmerging %s to %s.\n",((CAtom*)g_oaAtoms[z])->m_sName,at->m_sName);
 
182
                                                ((CAtom*)g_oaAtoms[z])->m_pMergedTo = at;
 
183
                                        }
 
184
                                        if (tb)
 
185
                                        {
 
186
                                                mprintf("\n");
 
187
                                                goto _unkstart;
 
188
                                        }
 
189
                                        tb = false;
 
190
                                        goto _unkdone;
 
191
                                }
 
192
                        }
 
193
                        ti = g_oaAtoms.GetSize();
 
194
                        for (z=0;z<ti;z++)
 
195
                        {
 
196
                                if (z == g_iVirtAtomType)
 
197
                                        continue;
 
198
 
 
199
                                at = (CAtom*)g_oaAtoms[z];
 
200
                                
 
201
                                while (at->m_pMergedTo != NULL)
 
202
                                {
 
203
//                                      mprintf("%s merged to %s\n",at->m_sName,at->m_pMergedTo->m_sName);
 
204
                                        at = at->m_pMergedTo;
 
205
                                }
 
206
 
 
207
                                if (at->m_pElement->m_fRadius != 0)
 
208
                                        continue;
 
209
                                mprintf(WHITE,"\n  * Element %s\n\n",at->m_sName);
 
210
 
 
211
                                buf2[0] = at->m_sName[0];
 
212
                                buf2[1] = at->m_sName[1];
 
213
                                buf2[2] = 0;
 
214
                                el = FindElement(buf2,true);
 
215
                                if (el != NULL)
 
216
                                {
 
217
                                        if (el->m_fRadius == 0)
 
218
                                                goto _unk2;
 
219
                                } else
 
220
                                {
 
221
_unk2:
 
222
                                        buf2[1] = 0;
 
223
                                        el = FindElement(buf2,true);
 
224
                                        if (el != NULL)
 
225
                                        {
 
226
                                                if (el->m_fRadius == 0)
 
227
                                                        goto _unk3;
 
228
                                        } else
 
229
                                        {
 
230
_unk3:
 
231
                                                strcpy(buf2,at->m_sName);
 
232
                                        }
 
233
                                }
 
234
 
 
235
                                if (AskYesNo("    Do you want to rename this element (y/n)? [yes] ",true))
 
236
                                {
 
237
_unk5:
 
238
                                        AskString("    Enter new name for %s: [%s] ",buf,buf2,at->m_sName,buf2);
 
239
                                        if (strlen(buf) > 7)
 
240
                                        {
 
241
                                                eprintf("Atom labels may have maximum length of 7 characters.\n");
 
242
                                                goto _unk5;
 
243
                                        }
 
244
                                        if (ContainsDigit(buf))
 
245
                                        {
 
246
                                                eprintf("Digits in element labels not allowed.\n");
 
247
                                                goto _unk5;
 
248
                                        }
 
249
                                        el = FindElement(buf,true);
 
250
                                        if (el != NULL)
 
251
                                        {
 
252
                                                xAddAtom(buf);
 
253
                                                if (AskYesNo("    Element %s is known. Merge %s atoms into %s (y/n)? [yes] ",true,buf,at->m_sName,buf))
 
254
                                                {
 
255
                                                        for (z2=0;z2<g_oaAtoms.GetSize();z2++)
 
256
                                                        {
 
257
                                                                if (((CAtom*)g_oaAtoms[z2])->m_pElement == el)
 
258
                                                                {
 
259
                                                                        at = (CAtom*)g_oaAtoms[z2];
 
260
                                                                        el = at->m_pElement;
 
261
                                                                        goto _unk1;
 
262
                                                                }
 
263
                                                        }
 
264
                                                        eprintf("    Strange error ^^\n");
 
265
_unk1:;
 
266
                                                }
 
267
                                        } else
 
268
                                        {
 
269
                                                mprintf("      Adding element %s...",buf);
 
270
 
 
271
                                                try { at = new CAtom(); } catch(...) { at = NULL; }
 
272
                                                if (at == NULL) NewException((double)sizeof(CAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
273
                                                
 
274
                                                at->m_iIndex = g_oaAtoms.GetSize();
 
275
                                                g_oaAtoms.Add(at);
 
276
 
 
277
                                                try { at->m_pElement = new CElement(); } catch(...) { at->m_pElement = NULL; }
 
278
                                                if (at->m_pElement == NULL) NewException((double)sizeof(CElement),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
279
                                                
 
280
                                                el = at->m_pElement;
 
281
                                                sprintf(at->m_sName,"%s",buf);
 
282
                                        }
 
283
                                        for (z2=0;z2<(int)g_TimeStep.m_iGesAtomCount;z2++)
 
284
                                        {
 
285
                                                strcpy(buf,(char*)g_TimeStep.m_paLabels[z2]);
 
286
                                                ReplaceDigits(buf);
 
287
                                                if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
 
288
                                                {
 
289
                                                        at->m_iCount++;
 
290
                                                        ((CAtom*)g_oaAtoms[z])->m_iCount--;
 
291
                                                }
 
292
                                        }
 
293
                                        ((CAtom*)g_oaAtoms[z])->m_pMergedTo = at;
 
294
                                        if (el->m_fRadius != 0)
 
295
                                                continue;
 
296
                                } // END IF RENAME
 
297
 
 
298
                                if (AskYesNo("    Do you want to copy the atom parameters from another element (y/n)? [yes] ",true))
 
299
                                {
 
300
_unk4:
 
301
                                        AskString("    Copy atom parameters from which element? [%s] ",buf,buf2,buf2);
 
302
                                        el = FindElement(buf,true);
 
303
                                        if (el == NULL)
 
304
                                        {
 
305
                                                eprintf("This element is not defined.\n");
 
306
                                                goto _unk4;
 
307
                                        }
 
308
                                        if (el->m_fRadius == 0)
 
309
                                        {
 
310
                                                if (!AskYesNo("    This element has a radius of 0 (will form no bonds). Use it anyway (y/n)? [yes] ",true))
 
311
                                                        goto _unk4;
 
312
                                        }
 
313
 
 
314
                                        mprintf(WHITE,"\n    A covalent radius of 0 pm hinders atoms of this kind from forming any bonds.\n\n");
 
315
 
 
316
                                        at->m_pElement->m_fRadius = AskFloat("    Please enter covalent radius in pm: [%.2f] ",el->m_fRadius,el->m_fRadius);
 
317
                                        at->m_pElement->m_fMass = AskFloat("    Please enter atom mass in u: [%.2f] ",el->m_fMass,el->m_fMass);
 
318
        
 
319
                                        if (!tb && (fabs(at->m_pElement->m_fMass-el->m_fMass) < 0.01))
 
320
                                        {
 
321
                                                tb = true;
 
322
                                                mprintf(RED,"\n    Warning: ");
 
323
                                                mprintf("Elements %s and %s keep their different labels, but will have\n",at->m_sName,buf);
 
324
                                                mprintf("             the same mass and therefore also the same atom codes. They will not\n");
 
325
                                                mprintf("             be distinguished in the molecule recognition!\n");
 
326
                                        }
 
327
//                                      mprintf("    Using mass=%.2fu, radius=%.2fpm, ord. number=%d.\n",at->m_pElement->m_fMass,el->m_fRadius,el->m_iOrd);
 
328
//                                      at->m_pElement->CopyData(el);
 
329
                                } else
 
330
                                {
 
331
                                        el = FindElement(buf2,true);
 
332
                                        mprintf(WHITE,"\n    A covalent radius of 0 pm hinders atoms of this kind from forming any bonds.\n\n");
 
333
                                        if (el != NULL)
 
334
                                        {
 
335
                                                mprintf("    (Default values are for %s)\n\n",buf2);
 
336
                                                at->m_pElement->m_fRadius = AskFloat("    Please enter covalent radius in pm: [%.2f] ",el->m_fRadius,el->m_fRadius);
 
337
                                                at->m_pElement->m_fMass = AskFloat("    Please enter atom mass in u: [%.2f] ",el->m_fMass,el->m_fMass);
 
338
                                        } else
 
339
                                        {
 
340
                                                at->m_pElement->m_fRadius = AskFloat("    Please enter covalent radius in pm: [100] ",100);
 
341
                                                at->m_pElement->m_fMass = AskFloat_ND("    Please enter atom mass in u: ");
 
342
                                        }
 
343
                                }
 
344
                        }
 
345
_unkdone:
 
346
                        mprintf("\n");
 
347
                        mprintf(WHITE,"%d atoms in the system: ",g_iGesAtomCount);
 
348
 
 
349
                        for (z=0;z<g_oaAtoms.GetSize();z++)
 
350
                        {
 
351
                                if (z == g_iVirtAtomType)
 
352
                                        continue;
 
353
                                if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
 
354
                                        continue;
 
355
                                mprintf("%dx %s",((CAtom*)g_oaAtoms[z])->m_iCount,((CAtom*)g_oaAtoms[z])->m_sName);
 
356
                                if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
 
357
                                        mprintf(" (merged to %s)",((CAtom*)g_oaAtoms[z])->m_pMergedTo->m_sName);
 
358
                                if (z < (int)g_oaAtoms.GetSize()-1)
 
359
                                        if (z+1 != g_iVirtAtomType)
 
360
                                                mprintf(", ");
 
361
                        }
 
362
                        mprintf("\n");
 
363
                } // END IF CHANGE UNKNOWN
 
364
                mprintf("\n");
 
365
        } // END IF UNKNOWN
 
366
 
 
367
        ia.RemoveAll();
 
368
        tb2 = false;
 
369
        for (z=0;z<g_oaAtoms.GetSize();z++)
 
370
        {
 
371
                tb = false;
 
372
                for (z3=0;z3<ia.GetSize();z3++)
 
373
                {
 
374
                        if (z == ia[z3])
 
375
                                goto _next;
 
376
                }
 
377
                if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
 
378
                        continue;
 
379
                if (z == g_iVirtAtomType)
 
380
                        continue;
 
381
                for (z2=z+1;z2<g_oaAtoms.GetSize();z2++)
 
382
                {
 
383
                        if (((CAtom*)g_oaAtoms[z2])->m_pMergedTo != NULL)
 
384
                                continue;
 
385
                        if (z2 == g_iVirtAtomType)
 
386
                                continue;
 
387
                        if (fabs(((CAtom*)g_oaAtoms[z])->m_pElement->m_fMass - ((CAtom*)g_oaAtoms[z2])->m_pElement->m_fMass) < 0.01)
 
388
                        {
 
389
                                if (!tb)
 
390
                                {
 
391
                                        tb = true;
 
392
                                        tb2 = true;
 
393
                                        mprintf(RED,"\n    Warning: ");
 
394
                                        mprintf("The following atoms have the same mass and will therefore not be\n");
 
395
                                        mprintf("             distinguished in the molecule recognition:\n\n");
 
396
                                        mprintf(WHITE,"      Mass=%.2f: %s, %s",((CAtom*)g_oaAtoms[z])->m_pElement->m_fMass,((CAtom*)g_oaAtoms[z])->m_sName,((CAtom*)g_oaAtoms[z2])->m_sName);
 
397
                                        ia.Add(z);
 
398
                                        ia.Add(z2);
 
399
                                } else
 
400
                                {
 
401
                                        mprintf(WHITE,", %s",((CAtom*)g_oaAtoms[z2])->m_sName);
 
402
                                }
 
403
                        }
 
404
                }
 
405
                if (tb)
 
406
                        mprintf("\n");
 
407
_next:;
 
408
        }
 
409
        if (tb2)
 
410
                mprintf("\n");
 
411
 
 
412
        mprintf("    The advanced mode includes some options which are quite powerful,\n    yet possibly weird or seldomly required. ");
 
413
        mprintf("This includes support for\n    NPT ensemble, non-periodic systems, user-definded virtual atoms, pseudomolecules, ...\n\n");
 
414
 
 
415
        g_bAdvanced1 = AskYesNo("    Use the advanced mode up to the function selection menu (y/n)? [no] ",false);
 
416
 
 
417
        mprintf("\n");
 
418
 
 
419
        if (g_bAdvanced1)
 
420
        {
 
421
                do
 
422
                {
 
423
                        mprintf("    Use periodic boundary conditions (0=no, x, y, z, xy, xz, xyz)? [xyz] ");
 
424
                        inpprintf("! Use periodic boundary conditions (0=no, x, y, z, xy, xz, xyz)? [xyz]\n");
 
425
                        myget(buf);
 
426
                } while (!ParsePeriodic(buf));
 
427
 
 
428
                if (!g_bPeriodic)
 
429
                {
 
430
/*                      if (AskYesNo("    Enter Box Size anyways (e.g. fo RDFs) (yes/no)? [yes] ",true))
 
431
                        {
 
432
                                goto _askbox;
 
433
                        } else
 
434
                        {
 
435
                                g_fBoxX = GuessBoxSize();
 
436
                                g_fBoxY = GuessBoxSize();
 
437
                                g_fBoxZ = GuessBoxSize();
 
438
                                mprintf("\nGuessed box size (for density 1.0 g/cm^3) is %.2f x %.2f x %.2f pm.\n\n",g_fBoxX,g_fBoxX,g_fBoxX);
 
439
                        }*/
 
440
//                      g_fBoxX = (g_TimeStep.m_vMax[0]-g_TimeStep.m_vMin[0])*10.0;
 
441
//                      g_fBoxY = (g_TimeStep.m_vMax[1]-g_TimeStep.m_vMin[1])*10.0;
 
442
//                      g_fBoxZ = (g_TimeStep.m_vMax[2]-g_TimeStep.m_vMin[2])*10.0;
 
443
//                      mprintf("\n    Using cell vector of %.2f x %.2f x %.2f pm to \"fake\" non-periodic box.\n\n",g_fBoxX,g_fBoxY,g_fBoxZ);
 
444
                }
 
445
        } else
 
446
                ParsePeriodic("xyz");
 
447
 
 
448
        if (g_bPeriodic)
 
449
        {
 
450
                tf = GuessBoxSize();
 
451
                mprintf("    A cell vector of %.2f pm would result in a density of 1.0 g/cm^3.\n\n",tf);
 
452
                if (g_bAdvanced1)
 
453
                {
 
454
                        g_bNPT = AskYesNo("    Use time-dependent cell vector (NPT ensemble) (y/n)? [no] ",false);
 
455
                        mprintf("\n");
 
456
                } else g_bNPT = false;
 
457
 
 
458
                if (g_bNPT)
 
459
                {
 
460
                        if (g_fBoxX != 0)
 
461
                        {
 
462
                                mprintf("    Your PDB file contains cell vector information.\n\n");
 
463
                        } else
 
464
                        {
 
465
                                mprintf("    The trajectory does not contain cell vector information.\n");
 
466
                                mprintf("    (supported: PDB file with \"CRYST1\" section, like written by GROMACS trjconv)\n");
 
467
                                mprintf("    You have to supply a plain text file which contains the cell vectors for each step.\n");
 
468
                                mprintf("    It should contain three space-separated floating point numbers (X, Y, Z vector) per line.\n");
 
469
                                mprintf("    These numbers need to be IN ANGSTROM! (1 angstrom = 100 pm)\n\n");
 
470
_nptfileagain:
 
471
                                AskString_ND("    Please enter cell vector text file name: ",g_sNPTFile);
 
472
                                if (!FileExist(g_sNPTFile))
 
473
                                {
 
474
                                        eprintf("Could not open file \"%s\" for reading.\n",g_sNPTFile);
 
475
                                        goto _nptfileagain;
 
476
                                }
 
477
                                g_fNPTFile = fopen(g_sNPTFile,"rt");
 
478
                                g_TimeStep.ReadCellVector(g_fNPTFile);
 
479
                                fclose(g_fNPTFile);
 
480
                                mprintf("\n");
 
481
                        }
 
482
                        mprintf("    The initial cell vector is ( %.2f pm | %.2f pm | %.2f pm ).\n",g_fBoxX,g_fBoxY,g_fBoxZ);
 
483
                        mprintf("    The initial box density is %.6f g/cm^3.\n\n",tf*tf*tf/g_fBoxX/g_fBoxY/g_fBoxZ);
 
484
                } else
 
485
                {
 
486
                        if (g_fBoxX != 0)
 
487
                        {
 
488
                                mprintf("    Cell vector found in trajectory file:\n");
 
489
                                mprintf("      X = %.2f pm,   Y = %.2f pm,   Z = %.2f pm\n\n",g_fBoxX,g_fBoxY,g_fBoxZ);
 
490
                                if (AskYesNo("    Use these values (y/n)? [yes] ",true))
 
491
                                        goto _celldone;
 
492
                        }
 
493
_askbox:
 
494
                        if (!AskYesNo("    Are the 3 cell vectors of the same size (yes/no)? [yes] ",true))
 
495
                        {
 
496
                                if (g_bPeriodicX)
 
497
                                        g_fBoxX = AskFloat_ND("    Enter length of X cell vector in pm: ");
 
498
                                if (g_bPeriodicY)
 
499
                                        g_fBoxY = AskFloat_ND("    Enter length of Y cell vector in pm: ");
 
500
                                if (g_bPeriodicZ)
 
501
                                        g_fBoxZ = AskFloat_ND("    Enter length of Z cell vector in pm: ");
 
502
                        } else
 
503
                        {
 
504
                                g_fBoxX = AskFloat_ND("    Enter length of cell vector in pm: ");
 
505
                                g_fBoxY = g_fBoxX;
 
506
                                g_fBoxZ = g_fBoxX;
 
507
                        }
 
508
                        if ((g_fBoxX <= 0) || (g_fBoxY <= 0) || (g_fBoxZ <= 0))
 
509
                        {
 
510
                                eprintf("Cell vector of length <= 0 is not allowed.\n");
 
511
                                goto _askbox;
 
512
                        }
 
513
_celldone:
 
514
                        if (g_bPeriodicX && g_bPeriodicY && g_bPeriodicZ)
 
515
                        {
 
516
                                mprintf("\n    The box size is %.2f x %.2f x %.2f pm.\n",g_fBoxX,g_fBoxY,g_fBoxZ);
 
517
                                mprintf("    The overall box density is %.6f g/cm^3.\n",tf*tf*tf/g_fBoxX/g_fBoxY/g_fBoxZ);
 
518
                                if (tf*tf*tf/g_fBoxX/g_fBoxY/g_fBoxZ > 15.0f)
 
519
                                {
 
520
                                        mprintf("\n");
 
521
                                        if (!AskYesNo("    The density of your box seems to be very high. Continue (y) or change input (n)? [n] ",false))
 
522
                                        {
 
523
                                                mprintf("\n");
 
524
                                                goto _askbox;
 
525
                                        }
 
526
                                        mprintf("\n");
 
527
                                }
 
528
                        }
 
529
                }
 
530
 
 
531
                if (g_bAdvanced1 && g_bPeriodic)
 
532
                {
 
533
                        mprintf("\n");
 
534
                        if (AskYesNo("    Should the periodic box be multiplied (y/n)? [no] ",false))
 
535
                        {
 
536
                                mprintf("\n");
 
537
                                g_bDoubleBox = true;
 
538
 
 
539
                                if (g_bPeriodicX)
 
540
                                        g_iDoubleBoxX = AskUnsignedInteger("    Replicate the box n times in x direction: [2] ",2);
 
541
                                                else g_iDoubleBoxX = 1;
 
542
 
 
543
                                if (g_bPeriodicY)
 
544
                                        g_iDoubleBoxY = AskUnsignedInteger("    Replicate the box n times in y direction: [2] ",2);
 
545
                                                else g_iDoubleBoxY = 1;
 
546
 
 
547
                                if (g_bPeriodicZ)
 
548
                                        g_iDoubleBoxZ = AskUnsignedInteger("    Replicate the box n times in z direction: [2] ",2);
 
549
                                                else g_iDoubleBoxZ = 1;
 
550
 
 
551
                                g_iDoubleBoxFactor = g_iDoubleBoxX * g_iDoubleBoxY * g_iDoubleBoxZ;
 
552
                                g_fBoxX *= g_iDoubleBoxX;
 
553
                                g_fBoxY *= g_iDoubleBoxY;
 
554
                                g_fBoxZ *= g_iDoubleBoxZ;
 
555
                                g_iGesAtomCount *= g_iDoubleBoxFactor;
 
556
                                g_iGesVirtAtomCount *= g_iDoubleBoxFactor;
 
557
                        } else g_bDoubleBox = false;
 
558
                } else g_bDoubleBox = false;
 
559
        } else g_bDoubleBox = false;
 
560
 
 
561
        try { g_pUniteTemp = new bool[g_iGesAtomCount]; } catch(...) { g_pUniteTemp = NULL; }
 
562
        if (g_pUniteTemp == NULL) NewException((double)g_iGesAtomCount*sizeof(bool),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
563
 
 
564
        if (!g_bPeriodic)
 
565
                g_bNPT = false;
 
566
 
 
567
        if (g_bPeriodic)
 
568
        {
 
569
                g_fMinPeriodic = 1e30f;
 
570
                if (g_bPeriodicX)
 
571
                        if (g_fMinPeriodic > g_fBoxX)
 
572
                                g_fMinPeriodic = g_fBoxX;
 
573
                if (g_bPeriodicY)
 
574
                        if (g_fMinPeriodic > g_fBoxY)
 
575
                                g_fMinPeriodic = g_fBoxY;
 
576
                if (g_bPeriodicZ)
 
577
                        if (g_fMinPeriodic > g_fBoxZ)
 
578
                                g_fMinPeriodic = g_fBoxZ;
 
579
        }
 
580
 
 
581
//      SAVEPOS;
 
582
_molbegin:
 
583
        if (!g_bStreamInput)
 
584
        {
 
585
                if (g_bAdvanced1)
 
586
                {
 
587
                        mprintf("\n");
 
588
                        g_iScanMolStep = AskInteger("    Execute molecule recognition for which time step (-1 = disable)? [0] ",0);
 
589
                } else g_iScanMolStep = 0;
 
590
 
 
591
                a = fopen(g_sInputTraj,"rb");
 
592
                if ((g_bNPT) && (g_sNPTFile[0] != 0))
 
593
                        g_fNPTFile = fopen(g_sNPTFile,"rt");
 
594
                if (g_iScanMolStep > 0)
 
595
                {
 
596
                        mprintf("    Fast-forwarding to step %d...\n",g_iScanMolStep);
 
597
                        mprintf(WHITE,"      [");
 
598
                        for (z=0;z<g_iScanMolStep;z++)
 
599
                        {
 
600
                                if ((g_bNPT) && (g_sNPTFile[0] != 0))
 
601
                                        fgets(buf,256,g_fNPTFile);
 
602
                                if (fmod(z,g_iScanMolStep/60.0) < 1.0)
 
603
                                        mprintf(WHITE,"#");
 
604
                                if (!g_TimeStep.SkipTimestep(a))
 
605
                                {
 
606
                                        eprintf("Error.\n",g_iScanMolStep);
 
607
                                        goto _skipfail;
 
608
                                }
 
609
                        }
 
610
                        mprintf(WHITE,"]\n");
 
611
                        g_iFastForwardPos = ftell(a);
 
612
                        mprintf("  Step %d begins at offset %lu (%.1f MB).\n\n",g_iScanMolStep+1,g_iFastForwardPos,g_iFastForwardPos/1024.0/1024.0);
 
613
                }
 
614
        _skipfail:;
 
615
                g_TimeStep.ReadTimestep(a,true);
 
616
                if (g_bNPT)
 
617
                {
 
618
                        if (g_sNPTFile[0] != 0)
 
619
                                g_TimeStep.ReadCellVector(g_fNPTFile);
 
620
                        mprintf("\n    NPT: Using a cell vector of ( %.2f pm | %.2f pm | %.2f pm ) for molecule recognition.\n",g_fBoxX,g_fBoxY,g_fBoxZ);
 
621
                }
 
622
        } else
 
623
        {
 
624
                g_iScanMolStep = 0;
 
625
                mprintf("\n    Stream input: Executing molecule recognition from first timestep...\n");
 
626
        }
 
627
 
 
628
        g_iCloseAtomCounter = 0;
 
629
 
 
630
        if (!g_TimeStep.ScanMolecules())
 
631
                return false;
 
632
 
 
633
        if (!g_bStreamInput)
 
634
        {
 
635
                fclose(a);
 
636
                if (g_sNPTFile[0] != 0)
 
637
                        fclose(g_fNPTFile);
 
638
        }
 
639
 
 
640
        if (g_bPeriodic)
 
641
        {
 
642
                mprintf("\n    Uniting molecules which have been broken by wrapping...\n");
 
643
                g_TimeStep.UniteMolecules(true);
 
644
        }
 
645
 
 
646
        mprintf(YELLOW,"\n*** The following %d kind%s of molecules ha%s been recognized:\n",g_oaMolecules.GetSize(),(g_oaMolecules.GetSize()>1)?"s":"",(g_oaMolecules.GetSize()>1)?"ve":"s");
 
647
        mprintf("    (ordered by molecular mass)\n\n");
 
648
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
649
        {
 
650
                mprintf(WHITE,"  - Molecule %d: %s ",z+1,((CMolecule*)g_oaMolecules[z])->m_sName);
 
651
                mprintf("(%d piece%s, %.2f g/mol)\n",((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize(),(((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize()>1)?"s":"",((CMolecule*)g_oaMolecules[z])->m_fMass);
 
652
                sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
 
653
                mprintf("      (%d noneq. atom%s, %d noneq. bond%s, %d noneq. angle%s)\n",sm->m_iAtomClasses,(sm->m_iAtomClasses==1)?"":"s",sm->m_oaBondGroups.GetSize(),(sm->m_oaBondGroups.GetSize()==1)?"":"s",sm->m_oaAngleGroups.GetSize(),(sm->m_oaAngleGroups.GetSize()==1)?"":"s");
 
654
                if (((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize() != 0)
 
655
                {
 
656
                        if (((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize() == 1)
 
657
                                mprintf(WHITE,"      Detected %d ring:\n",((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize());
 
658
                                        else mprintf(WHITE,"      Detected %d rings:\n",((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize());
 
659
                        for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms.GetSize();z2++)
 
660
                        {
 
661
                                mprintf(WHITE,"        %2d.) %2d-ring: ",z2+1,((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize());
 
662
                                if (((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize() > 20)
 
663
                                {
 
664
                                        for (z3=0;z3<5;z3++)
 
665
                                        {
 
666
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[((CMolecule*)g_oaMolecules[z])->m_baAtomIndex[((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetAt(z3)+1);
 
667
                                                if (z3+1 < ((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize())
 
668
                                                        mprintf(" - ");
 
669
                                        }
 
670
                                        mprintf(RED,"...");
 
671
                                        mprintf(" - ");
 
672
                                        for (z3=((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize()-5;z3<((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize();z3++)
 
673
                                        {
 
674
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[((CMolecule*)g_oaMolecules[z])->m_baAtomIndex[((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetAt(z3)+1);
 
675
                                                if (z3+1 < ((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize())
 
676
                                                        mprintf(" - ");
 
677
                                        }
 
678
                                } else
 
679
                                {
 
680
                                        for (z3=0;z3<((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize();z3++)
 
681
                                        {
 
682
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[((CMolecule*)g_oaMolecules[z])->m_baAtomIndex[((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetAt(z3)+1);
 
683
                                                if (z3+1 < ((CxIntArray*)((CMolecule*)g_oaMolecules[z])->m_oaRingAtoms[z2])->GetSize())
 
684
                                                        mprintf(" - ");
 
685
                                        }
 
686
                                }
 
687
                                mprintf("\n");
 
688
                                if (z2 >= 9)
 
689
                                {
 
690
                                        mprintf(RED,"\n    Showing only the first 10 rings.\n");
 
691
                                        break;
 
692
                                }
 
693
                        }
 
694
                }
 
695
 
 
696
                mprintf("\n");
 
697
        }
 
698
 
 
699
        if (g_oaMolecules.GetSize() == 0)
 
700
        {
 
701
                eprintf("You don't have any atom/molecule in your simulation. This is probably not what you wanted.\n");
 
702
                eprintf("Stopping execution.\n");
 
703
                return false;
 
704
        }
 
705
 
 
706
/*      if (g_bVerbose)
 
707
        {
 
708
                mprintf(WHITE,">>> Output of the molecule tree >>>\n");
 
709
                g_TimeStep.PrintMegaTree();
 
710
                mprintf(WHITE,"<<< Output of the molecule tree <<<\n\n");
 
711
        }*/
 
712
 
 
713
_matrixagain:
 
714
 
 
715
        mprintf("\n");
 
716
        if (!AskYesNo("    Accept these molecules (y) or change something (n)? [yes] ",true))
 
717
        {
 
718
                tb = false;
 
719
                mprintf("\n");
 
720
                mprintf("    If you want some atom types to form no bonds at all, assign covalent radius 0 to them.\n");
 
721
_modagain:
 
722
                mprintf(YELLOW,"\n    *** Modify Molecules ***\n\n");
 
723
                mprintf("    Your choices:\n\n");
 
724
 
 
725
                mprintf("    1.) Change covalent atom radii used for bond recognition\n");
 
726
                mprintf("    2.) Break specific bonds\n");
 
727
                mprintf("    3.) Rename elements\n");
 
728
 
 
729
                mprintf("\n");
 
730
                switch(AskRangeInteger("    Please select: [done] ",1,3,0))
 
731
                {
 
732
                        case 1:
 
733
                                mprintf("\n    These values have been used (covalent radii from literature multiplied with %.2f):\n\n",g_fBondFactor);
 
734
                                for (z=0;z<g_oaAtoms.GetSize()-1;z++)
 
735
                                        mprintf("      - %-2s    %5.1f pm\n",((CAtom*)g_oaAtoms[z])->m_sName,((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius*g_fBondFactor);
 
736
                                mprintf("\n");
 
737
        _arnew:
 
738
                                AskString("    Which radius do you want to change (RETURN=done)? ",buf,"");
 
739
                                if (strlen(buf) == 0)
 
740
                                        goto _ardone;
 
741
                                for (z=0;z<g_oaAtoms.GetSize()-1;z++)
 
742
                                {
 
743
                                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
 
744
                                        {
 
745
                                                ((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius = AskFloat("    Please enter new bond radius for %s in pm: [%.1f] ",((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius*g_fBondFactor,((CAtom*)g_oaAtoms[z])->m_sName,((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius*g_fBondFactor) / g_fBondFactor;
 
746
                                                if (((CAtom*)g_oaAtoms[z])->m_pElement->m_fRadius == 0)
 
747
                                                        mprintf("\n      Atom %s will form no bonds now.\n\n",((CAtom*)g_oaAtoms[z])->m_sName);
 
748
                                                mprintf("\n");
 
749
                                                tb = true;
 
750
                                                goto _arnew;
 
751
                                        }
 
752
                                }
 
753
                                eprintf("    Atom \"%s\" is not in the system.\n\n",buf);
 
754
                                goto _arnew;
 
755
        _ardone:
 
756
                                mprintf("\n");
 
757
                                break;
 
758
 
 
759
                        case 2:
 
760
        _breakagain:
 
761
                                mprintf("\n");
 
762
                                if (g_oaMolecules.GetSize() > 1)
 
763
                                {
 
764
        _breakmol:      ti = AskUnsignedInteger_ND("    Break bonds in which molecule (1-%d)? ",g_oaMolecules.GetSize())-1;
 
765
                                        if ((ti < 0) || (ti >= (int)g_oaMolecules.GetSize()))
 
766
                                        {
 
767
                                                eprintf("Wrong Input.\n\n");
 
768
                                                goto _breakmol;
 
769
                                        }
 
770
                                } else ti = 0;
 
771
                                mol = (CMolecule*)g_oaMolecules[ti];
 
772
                                tb = true;
 
773
                                if (AskYesNo("    Break all bonds within this molecule (y/n)? [no] ",false))
 
774
                                {
 
775
                                        for (z=0;z<mol->m_laSingleMolIndex.GetSize();z++)
 
776
                                        {
 
777
                                                sm = (CSingleMolecule*)g_oaSingleMolecules[mol->m_laSingleMolIndex[z]];
 
778
                                                g_laBondBlackList.Append(&sm->m_laBonds);
 
779
                                        }
 
780
                                } else
 
781
                                {
 
782
        _breaka1:               AskString_ND("    Enter 1st atom of the bond to break (e.g. O2): ",buf);
 
783
                                        if (!ParseAtom(buf,ti,ty,rty,atom))
 
784
                                                goto _breaka1;
 
785
        _breaka2:               AskString_ND("    Enter 2nd atom of the bond to break (e.g. O2): ",buf);
 
786
                                        if (!ParseAtom(buf,ti,ty2,rty2,atom2))
 
787
                                                goto _breaka2;
 
788
                                        for (z=0;z<mol->m_laSingleMolIndex.GetSize();z++)
 
789
                                        {
 
790
                                                sm = (CSingleMolecule*)g_oaSingleMolecules[mol->m_laSingleMolIndex[z]];
 
791
                                                g_laBondBlackList.Add(((CxIntArray*)sm->m_oaAtomOffset[ty])->GetAt(atom));
 
792
                                                g_laBondBlackList.Add(((CxIntArray*)sm->m_oaAtomOffset[ty2])->GetAt(atom2));
 
793
                                        }
 
794
                                }
 
795
                                if (AskYesNo("\n    Break another bond (y/n)? [no] ",false))
 
796
                                        goto _breakagain;
 
797
                                mprintf("\n");
 
798
                                break;
 
799
 
 
800
                        case 3:
 
801
/*********************************************************************************************************************/
 
802
_rennew:
 
803
                                mprintf("\n    The system contains the following atoms:\n\n    ");
 
804
                                tb2 = false;
 
805
                                for (z=0;z<g_oaAtoms.GetSize();z++)
 
806
                                {
 
807
                                        if (z == g_iVirtAtomType)
 
808
                                                continue;
 
809
                                        if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
 
810
                                                continue;
 
811
                                        if (tb2)
 
812
                                                mprintf(", ");
 
813
                                        tb2 = true;
 
814
                                        mprintf("%dx %s",((CAtom*)g_oaAtoms[z])->m_iCount,((CAtom*)g_oaAtoms[z])->m_sName);
 
815
                                }
 
816
                                mprintf("\n\n");
 
817
 
 
818
_renerr:
 
819
                                AskString("    Which element to rename: [done] ",buf,"");
 
820
 
 
821
                                if (strlen(buf) == 0)
 
822
                                        goto _rendone;
 
823
 
 
824
                                for (z=0;z<g_oaAtoms.GetSize();z++)
 
825
                                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
 
826
                                                goto _renfound;
 
827
                                eprintf("\n    Atom \"%s\" not in the system.\n\n",buf);
 
828
                                goto _renerr;
 
829
_renfound:
 
830
                                tb = true;
 
831
                                at = (CAtom*)g_oaAtoms[z];
 
832
                                
 
833
                                AskString_ND("    Enter new name for %s: ",buf2,buf);
 
834
                                if (strlen(buf2) > 7)
 
835
                                {
 
836
                                        eprintf("\n    Atom labels may have maximum length of 7 characters.\n\n");
 
837
                                        goto _renfound;
 
838
                                }
 
839
                                if (ContainsDigit(buf2))
 
840
                                {
 
841
                                        eprintf("\n    Digits in element labels not allowed.\n\n");
 
842
                                        goto _renfound;
 
843
                                }
 
844
                                el = FindElement(buf2,true);
 
845
                                if (el != NULL)
 
846
                                {
 
847
                                        xAddAtom(buf2);
 
848
                                        if (AskYesNo("    Element %s is known. Merge %s atoms into %s (y/n)? [yes] ",true,buf2,buf,buf2))
 
849
                                        {
 
850
                                                for (z2=0;z2<g_oaAtoms.GetSize();z2++)
 
851
                                                {
 
852
                                                        if (((CAtom*)g_oaAtoms[z2])->m_pElement == el)
 
853
                                                        {
 
854
                                                                at = (CAtom*)g_oaAtoms[z2];
 
855
                                                                at->m_iCount--;
 
856
                                                                el = at->m_pElement;
 
857
                                                                goto _ren1;
 
858
                                                        }
 
859
                                                }
 
860
                                                eprintf("\n    Strange error ^^\n");
 
861
_ren1:;
 
862
                                        }
 
863
                                } else
 
864
                                {
 
865
                                        mprintf("\n      Adding element %s...\n\n",buf2);
 
866
 
 
867
                                        try { at = new CAtom(); } catch(...) { at = NULL; }
 
868
                                        if (at == NULL) NewException((double)sizeof(CAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
869
                                        
 
870
                                        at->m_iIndex = g_oaAtoms.GetSize();
 
871
                                        g_oaAtoms.Add(at);
 
872
                                        at->m_iCount = 0;
 
873
 
 
874
                                        try { at->m_pElement = new CElement(); } catch(...) { at->m_pElement = NULL; }
 
875
                                        if (at->m_pElement == NULL) NewException((double)sizeof(CElement),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
876
                                        
 
877
                                        at->m_pElement->m_fRadius = AskFloat("    Please enter covalent radius in pm: [100.0] ",100.0f);
 
878
                                        at->m_pElement->m_fMass = AskFloat("    Please enter atom mass in u: [0] ",0);
 
879
                                        sprintf(at->m_sName,"%s",buf2);
 
880
                                }
 
881
                                for (z2=0;z2<(int)g_TimeStep.m_iGesAtomCount;z2++)
 
882
                                {
 
883
                                        strcpy(buf,(char*)g_TimeStep.m_paLabels[z2]);
 
884
                                        ReplaceDigits(buf);
 
885
                                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z])->m_sName) == 0)
 
886
                                        {
 
887
                                                at->m_iCount++;
 
888
                                                ((CAtom*)g_oaAtoms[z])->m_iCount--;
 
889
                                        }
 
890
                                }
 
891
                                ((CAtom*)g_oaAtoms[z])->m_pMergedTo = at;
 
892
                                mprintf("\n");
 
893
                                goto _rennew;
 
894
_rendone:;
 
895
                                mprintf("\n    The system contains the following atoms:\n\n    ");
 
896
                                tb2 = false;
 
897
                                for (z=0;z<g_oaAtoms.GetSize();z++)
 
898
                                {
 
899
                                        if (z == g_iVirtAtomType)
 
900
                                                continue;
 
901
                                        if (((CAtom*)g_oaAtoms[z])->m_pMergedTo != NULL)
 
902
                                                continue;
 
903
                                        if (tb2)
 
904
                                                mprintf(", ");
 
905
                                        tb2 = true;
 
906
                                        mprintf("%dx %s",((CAtom*)g_oaAtoms[z])->m_iCount,((CAtom*)g_oaAtoms[z])->m_sName);
 
907
                                }
 
908
                                mprintf("\n");
 
909
/*********************************************************************************************************************/
 
910
                                break;
 
911
 
 
912
                        default:
 
913
                                goto _fin;
 
914
                }
 
915
                goto _modagain;
 
916
_fin:
 
917
                if (tb)
 
918
                {
 
919
                        mprintf(WHITE,"\n    Going back to molecule recognition with changed settings.\n\n");
 
920
                        goto _molbegin;
 
921
                } else
 
922
                        mprintf(WHITE,"\n    Nothing was changed, not repeating molecule recognition.\n\n");
 
923
        }
 
924
                
 
925
        if (g_bAdvanced1)
 
926
        {
 
927
                g_bMegaMat = !AskYesNo("    Show bond matrices only for first representant of each molecule type (y/n)? [yes] ",true);
 
928
                g_bMatOnlyBind = AskYesNo("    Show only bonds in the bond matrices (y/n)? [yes] ",true);
 
929
        } else
 
930
        {
 
931
                g_bMegaMat = false;
 
932
                g_bMatOnlyBind = true;
 
933
        }
 
934
                        
 
935
        mprintf(WHITE,"\nOutput of bond matrices:\n");
 
936
        g_TimeStep.PrintMatrix(!g_bMegaMat,g_bMatOnlyBind);
 
937
 
 
938
        mprintf("\n");
 
939
        mprintf("    You can create images of the structural formulas with the atom labels for easier\n");
 
940
        mprintf("    identification of the atoms (requires installed GraphViz package - see www.graphviz.org).\n\n");
 
941
 
 
942
        if (AskYesNo("    Create images of the structural formulas (y/n)? [no] ",false))
 
943
        {
 
944
                if (g_bAdvanced1)
 
945
                        ti = AskUnsignedInteger("    How many iterations to perform for formula optimization? [10] ",10);
 
946
                                else ti = 10;
 
947
                RenderStructFormulas(ti);
 
948
        }
 
949
 
 
950
        mprintf(WHITE,"\n    The atoms are currently ordered by topological priority.\n");
 
951
 
 
952
        if (g_bAdvanced1)
 
953
        {
 
954
                mprintf("\n");
 
955
 
 
956
                // This block written @ Ballmer peak ;-P Try it out yourself.
 
957
                if (AskYesNo("    Change the atom ordering in some molecule (y/n)? [no] ",false))
 
958
                {
 
959
                        if (AskYesNo("    Order atoms like in the input file instead (y/n)? [no] ",false))
 
960
                        {
 
961
                                ReorderLikeInput(); // Crazy shit!! (Ballmer Peak)
 
962
                        } else
 
963
                        {
 
964
        _reordernext:
 
965
                                sprintf(buf,"    Change atom ordering in which of the molecules (");
 
966
                                for (z=0;z<g_oaMolecules.GetSize();z++)
 
967
                                {
 
968
                                        sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
 
969
                                        strcat(buf,buf2);
 
970
                                        if (z < g_oaMolecules.GetSize()-1)
 
971
                                                strcat(buf,", ");
 
972
                                }
 
973
                                strcat(buf,")? ");
 
974
                                ti = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize())-1;
 
975
                                mol = (CMolecule*)g_oaMolecules[ti];
 
976
                                mol->m_oaNewNumbers.SetSize(mol->m_baAtomIndex.GetSize());
 
977
                                for (z=0;z<mol->m_baAtomIndex.GetSize();z++)
 
978
                                {
 
979
                                        mprintf("* Atom type %s\n",((CAtom*)g_oaAtoms[mol->m_baAtomIndex[z]])->m_sName);
 
980
                                        if (mol->m_oaNewNumbers[z] != NULL)
 
981
                                                delete mol->m_oaNewNumbers[z];
 
982
 
 
983
                                        try { mol->m_oaNewNumbers[z] = new CxIntArray("gather():mol->m_oaNewNumbers[z]"); } catch(...) { mol->m_oaNewNumbers[z] = NULL; }
 
984
                                        if (mol->m_oaNewNumbers[z] == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
985
                                        
 
986
                                        for (z2=0;z2<mol->m_waAtomCount[z];z2++)
 
987
                                        {
 
988
                _renumberagain:
 
989
                                                ti2 = AskRangeInteger("    Which number should %s%d bear? [%d] ",1,mol->m_waAtomCount[z],z2+1,((CAtom*)g_oaAtoms[mol->m_baAtomIndex[z]])->m_sName,z2+1,z2+1);
 
990
                                                for (z3=0;z3<z2;z3++)
 
991
                                                        if (((CxIntArray*)mol->m_oaNewNumbers[z])->GetAt(z3) == ti2-1)
 
992
                                                        {
 
993
                                                                eprintf("This number already was chosen for %s%d!\n",((CAtom*)g_oaAtoms[mol->m_baAtomIndex[z]])->m_sName,z3+1);
 
994
                                                                goto _renumberagain;
 
995
                                                        }
 
996
                                                (*((CxIntArray*)mol->m_oaNewNumbers[z])).Add(ti2-1);
 
997
                                        }
 
998
                                }
 
999
                                mprintf("\n    Reordering atoms...");
 
1000
                                ReorderAtoms(ti);
 
1001
                                mprintf("Done.\n\n");
 
1002
                                if (AskYesNo("    Change atom ordering of another molecule (y/n)? [no] ",false))
 
1003
                                        goto _reordernext;
 
1004
                                goto _matrixagain;
 
1005
                        } // End "this block"
 
1006
 
 
1007
                        mprintf(WHITE,"\n    Going back to molecule recognition with changed settings.\n\n");
 
1008
                        goto _molbegin;
 
1009
                } // END IF REORDER
 
1010
        } // END IF ADVANCED
 
1011
 
 
1012
        mprintf(WHITE,"\n    Defining virtual atom #1 as molecular Center of Geometry:\n");
 
1013
        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
 
1014
        {
 
1015
                mprintf("      - %s...\n",((CMolecule*)g_oaMolecules[z0])->m_sName);
 
1016
                va = AddVirtualAtom(z0);
 
1017
                va->m_iMode = 0;
 
1018
                va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
 
1019
                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
 
1020
                for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
 
1021
                        va->m_faWeight[z] = 1.0f;
 
1022
                va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
 
1023
        }
 
1024
 
 
1025
        mprintf(WHITE,"\n    Defining virtual atom #2 as molecular Center of Mass:\n");
 
1026
        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
 
1027
        {
 
1028
                mprintf("      - %s...\n",((CMolecule*)g_oaMolecules[z0])->m_sName);
 
1029
                va = AddVirtualAtom(z0);
 
1030
                va->m_iMode = 0;
 
1031
                va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
 
1032
                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
 
1033
                z3 = 0;
 
1034
                tf2 = 0;
 
1035
                for (z=0;z<va->m_oCenterAtoms.m_baAtomType.GetSize();z++)
 
1036
                {
 
1037
                        tf = ((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z]])->m_pElement->m_fMass;
 
1038
                        for (z2=0;z2<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z])->GetSize();z2++)
 
1039
                        {
 
1040
                                va->m_faWeight[z3] = tf;
 
1041
                                tf2 += tf;
 
1042
                                z3++;
 
1043
                        }
 
1044
                }
 
1045
                va->m_fGesWeight = tf2;
 
1046
                if (va->m_fGesWeight == 0)
 
1047
                {
 
1048
                        eprintf("        Molecule %s has total mass of zero. Defining #2 as Center of Geometry.\n",((CMolecule*)g_oaMolecules[z0])->m_sName);
 
1049
                        for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
 
1050
                                va->m_faWeight[z] = 1.0f;
 
1051
                        va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
 
1052
                }
 
1053
        }
 
1054
 
 
1055
        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
 
1056
        {
 
1057
                m = (CMolecule*)g_oaMolecules[z0];
 
1058
                if (m->m_oaRingAtoms.GetSize() != 0)
 
1059
                {
 
1060
                        mprintf(WHITE,"\n    Defining ring centers in %s:\n",m->m_sName);
 
1061
                        for (z=0;z<m->m_oaRingAtoms.GetSize();z++)
 
1062
                        {
 
1063
                                mprintf("      - Defining #%d as Center of Ring %d: ",z+3,z+1);
 
1064
                                for (z3=0;z3<((CxIntArray*)m->m_oaRingAtoms[z])->GetSize();z3++)
 
1065
                                {
 
1066
                                        mprintf("%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[((CxIntArray*)m->m_oaRingAtomTypes[z])->GetAt(z3)]])->m_sName,((CxIntArray*)m->m_oaRingAtoms[z])->GetAt(z3)+1);
 
1067
                                        if (z3+1 < ((CxIntArray*)m->m_oaRingAtoms[z])->GetSize())
 
1068
                                                mprintf(" - ");
 
1069
                                }
 
1070
                                mprintf("\n");
 
1071
                                va = AddVirtualAtom(z0);
 
1072
                                va->m_iMode = 0;
 
1073
                                va->m_oCenterAtoms.m_pMolecule = m;
 
1074
                                for (z3=0;z3<((CxIntArray*)m->m_oaRingAtoms[z])->GetSize();z3++)
 
1075
                                        va->m_oCenterAtoms.AddAtom(((CxIntArray*)m->m_oaRingAtomTypes[z])->GetAt(z3),((CxIntArray*)m->m_oaRingAtoms[z])->GetAt(z3),false);
 
1076
                                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
 
1077
                                for (z3=0;z3<va->m_oCenterAtoms.m_iAtomGes;z3++)
 
1078
                                        va->m_faWeight[z3] = 1.0f;
 
1079
                                va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
 
1080
                        }
 
1081
                }
 
1082
        }
 
1083
 
 
1084
        if (g_bAdvanced1)
 
1085
        {
 
1086
                mprintf("\n");
 
1087
                if (AskYesNo("\n    Define additional virtual atoms (y/n)? [no] ",false))
 
1088
                {
 
1089
        _vabeg:
 
1090
                        sprintf(buf,"    To which molecule shall the virtual atom belong (");
 
1091
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1092
                        {
 
1093
                                sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
 
1094
                                strcat(buf,buf2);
 
1095
                                if (z < g_oaMolecules.GetSize()-1)
 
1096
                                        strcat(buf,", ");
 
1097
                        }
 
1098
                        strcat(buf,")? ");
 
1099
 
 
1100
                        z = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize());
 
1101
                        va = AddVirtualAtom(z-1);
 
1102
                        mprintf(WHITE,"\n*** Defining virtual atom #%d in %s\n",va->m_iMolVirtAtom+1,((CMolecule*)g_oaMolecules[va->m_iMolecule])->m_sName);
 
1103
                        va->m_iMode = AskRangeInteger("    Define v.a. as center (0) or through distance/angle/dihedral (1)? [center] ",0,1,0);
 
1104
                        if (va->m_iMode == 0)
 
1105
                        {
 
1106
        _vaatoms:
 
1107
                                mprintf("    Which atoms to use for center (e.g. \"C1,C3-5,H\")? [all] ");
 
1108
                                inpprintf("! Which atoms to use for center (e.g. \"C1,C3-5,H\")? [all]\n");
 
1109
                                myget(buf);
 
1110
                                if (strlen(buf)==0)
 
1111
                                        va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
 
1112
                                else if (!va->m_oCenterAtoms.ParseAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],buf))
 
1113
                                        goto _vaatoms;
 
1114
                                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
 
1115
        _vaweight:
 
1116
                                mprintf("    How shall these atoms be weightened (RETURN=equal, *=mass, #=manually)? [equal] ");
 
1117
                                inpprintf("! How shall these atoms be weightened (RETURN=equal, *=mass, #=manually)? [equal]\n");
 
1118
                                myget(buf);
 
1119
                                if (strlen(buf)==0)
 
1120
                                {
 
1121
                                        for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
 
1122
                                                va->m_faWeight[z] = 1.0f;
 
1123
                                        va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
 
1124
                                } else if (buf[0] == '*')
 
1125
                                {
 
1126
                                        z3 = 0;
 
1127
                                        tf2 = 0;
 
1128
                                        for (z=0;z<va->m_oCenterAtoms.m_baAtomType.GetSize();z++)
 
1129
                                        {
 
1130
                                                tf = ((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z]])->m_pElement->m_fMass;
 
1131
                                                for (z2=0;z2<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z])->GetSize();z2++)
 
1132
                                                {
 
1133
                                                        va->m_faWeight[z3] = tf;
 
1134
                                                        tf2 += tf;
 
1135
                                                        z3++;
 
1136
                                                }
 
1137
                                        }
 
1138
                                        va->m_fGesWeight = tf2;
 
1139
                                        if (va->m_fGesWeight == 0)
 
1140
                                        {
 
1141
                                                eprintf("\n    Molecule has total mass of zero. Weighting atoms equally.\n\n");
 
1142
                                                for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
 
1143
                                                        va->m_faWeight[z] = 1.0f;
 
1144
                                                va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
 
1145
                                        }
 
1146
                                } else if (buf[0] == '#')
 
1147
                                {
 
1148
_vawagain:
 
1149
                                        z3 = 0;
 
1150
                                        tf2 = 0;
 
1151
                                        mprintf("\n");
 
1152
                                        for (z=0;z<va->m_oCenterAtoms.m_baAtomType.GetSize();z++)
 
1153
                                        {
 
1154
                                                for (z2=0;z2<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z])->GetSize();z2++)
 
1155
                                                {
 
1156
                                                        tf = AskFloat("      Enter the weight for %s%d: [1] ",1.0f,((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z]])->m_pElement->m_sLabel, ((CxIntArray *)va->m_oCenterAtoms.m_oaAtoms[z])->GetAt(z2)+1);
 
1157
                                                        va->m_faWeight[z3] = tf;
 
1158
                                                        tf2 += tf;
 
1159
                                                        z3++;
 
1160
                                                }
 
1161
                                        }
 
1162
                                        mprintf("    The sum of weights is %.4f.\n\n",tf2);
 
1163
                                        va->m_fGesWeight = tf2;
 
1164
                                        if (va->m_fGesWeight == 0)
 
1165
                                        {
 
1166
                                                eprintf("Sum of weights may not be zero. Enter the weights again.\n\n");
 
1167
                                                goto _vawagain;
 
1168
                                        }
 
1169
                                } else
 
1170
                                {
 
1171
                                        eprintf("Wrong input.\n");
 
1172
                                        inpprintf("! Wrong input.\n");
 
1173
                                        goto _vaweight;
 
1174
                                }
 
1175
                        } else
 
1176
                        {
 
1177
        _vabond:
 
1178
                                mprintf("    Enter 2nd atom for distance #%d- (e.g. C2): ",va->m_iMolVirtAtom+1);
 
1179
                                inpprintf("! Enter 2nd atom for distance #%d- (e.g. C2):\n",va->m_iMolVirtAtom+1);
 
1180
                                myget(buf);
 
1181
                                if (!ParseAtom(buf,va->m_iMolecule,va->m_iAtomType[0],va->m_iRealAtomType[0],va->m_iAtom[0]))
 
1182
                                        goto _vabond;
 
1183
                                if ((va->m_iRealAtomType[0] == g_iVirtAtomType) && (va->m_iAtom[0] == va->m_iMolVirtAtom))
 
1184
                                {
 
1185
                                        eprintf("This atom was already chosen.\n");
 
1186
                                        goto _vabond;
 
1187
                                }
 
1188
        _vaangle:
 
1189
                                mprintf("    Enter 3rd atom for angle #%d-%s%d- (e.g. C2)? ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1);
 
1190
                                inpprintf("! Enter 3rd atom for angle #%d-%s%d- (e.g. C2)?\n",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1);
 
1191
                                myget(buf);
 
1192
                                if (!ParseAtom(buf,va->m_iMolecule,va->m_iAtomType[1],va->m_iRealAtomType[1],va->m_iAtom[1]))
 
1193
                                        goto _vaangle;
 
1194
                                if (((va->m_iRealAtomType[1] == g_iVirtAtomType) && (va->m_iAtom[1] == va->m_iMolVirtAtom)) || ((va->m_iRealAtomType[1] == va->m_iRealAtomType[0]) && (va->m_iAtom[1] == va->m_iAtom[0])))
 
1195
                                {
 
1196
                                        eprintf("This atom was already chosen.\n");
 
1197
                                        goto _vaangle;
 
1198
                                }
 
1199
        _vadihedral:
 
1200
                                mprintf("    Enter 4th atom for dihedral #%d-%s%d-%s%d- (e.g. C2)? ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1);
 
1201
                                inpprintf("! Enter 4th atom for dihedral #%d-%s%d-%s%d- (e.g. C2)?\n",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1);
 
1202
                                myget(buf);
 
1203
                                if (!ParseAtom(buf,va->m_iMolecule,va->m_iAtomType[2],va->m_iRealAtomType[2],va->m_iAtom[2]))
 
1204
                                        goto _vadihedral;
 
1205
                                if (((va->m_iRealAtomType[2] == g_iVirtAtomType) && (va->m_iAtom[2] == va->m_iMolVirtAtom)) || ((va->m_iRealAtomType[2] == va->m_iRealAtomType[0]) && (va->m_iAtom[2] == va->m_iAtom[0])) || ((va->m_iRealAtomType[2] == va->m_iRealAtomType[1]) && (va->m_iAtom[2] == va->m_iAtom[1])))
 
1206
                                {
 
1207
                                        eprintf("This atom was already chosen.\n");
 
1208
                                        goto _vadihedral;
 
1209
                                }
 
1210
                
 
1211
                                va->m_fValues[0] = AskFloat_ND("    Enter distance #%d-%s%d in pm: ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1);
 
1212
                                va->m_fValues[1] = AskFloat_ND("    Enter angle #%d-%s%d-%s%d in degree: ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1) * (float)Pi / 180.0f;
 
1213
                                va->m_fValues[2] = AskFloat_ND("    Enter dihedral #%d-%s%d-%s%d-%s%d in degree: ",va->m_iMolVirtAtom+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[2]])->m_sName,va->m_iAtom[2]+1) * (float)Pi / 180.0f;
 
1214
                        }
 
1215
 
 
1216
                        if (AskYesNo("\n    Define further virtual atoms (y/n)? [no] ",false))
 
1217
                                goto _vabeg;
 
1218
                }
 
1219
 
 
1220
                mprintf("\n");
 
1221
                if (AskYesNo("    Do you want to define pseudo-molecules (y/n)? [no] ",false))
 
1222
                {
 
1223
                        tb2 = false;
 
1224
                        ti = 0;
 
1225
                        mprintf("\n    If you need the center of mass or center of geometry of the whole system, you should\n");
 
1226
                        mprintf("    define a pseudo-molecule over the whole system, and use its atoms #1 and #2.\n\n");
 
1227
                        if (AskYesNo("    Define a pseudo-molecule over the whole system (y/n)? [yes] ",true))
 
1228
                        {
 
1229
                                ti++;
 
1230
/************************************************************************/
 
1231
                                mprintf("\n");
 
1232
                                try { m2 = new CMolecule(); } catch(...) { m2 = NULL; }
 
1233
                                if (m2 == NULL) NewException((double)sizeof(CMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1234
                                
 
1235
                                try { sm2 = new CSingleMolecule(); } catch(...) { sm2 = NULL; }
 
1236
                                if (sm2 == NULL) NewException((double)sizeof(CSingleMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1237
                                
 
1238
                                m2->m_bPseudo = true;
 
1239
                                sm2->m_bPseudo = true;
 
1240
                                m2->m_iIndex = g_oaMolecules.GetSize();
 
1241
                                sm2->m_iMolType = g_oaMolecules.GetSize();
 
1242
                                sm2->m_iMolSMIndex = 0;
 
1243
                                m2->m_laSingleMolIndex.Add(g_oaSingleMolecules.GetSize());
 
1244
                                g_oaMolecules.Add(m2);
 
1245
                                g_oaSingleMolecules.Add(sm2);
 
1246
 
 
1247
                                mprintf(WHITE,"    >>> Pseudo-molecule %d (= molecule %d) >>>\n\n",ti,g_oaMolecules.GetSize());
 
1248
                                mprintf("    Adding all atoms from all molecules...\n");
 
1249
 
 
1250
                                for (z=0;z<g_oaMolecules.GetSize();z++)
 
1251
                                {
 
1252
                                        m = (CMolecule*)g_oaMolecules[z];
 
1253
                                        if (m->m_bPseudo)
 
1254
                                                continue;
 
1255
 
 
1256
                                        try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
 
1257
                                        if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1258
                                        
 
1259
                                        ag->AddAllAtoms(m,false);
 
1260
 
 
1261
                                        ia.RemoveAll();
 
1262
 
 
1263
                                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
1264
                                                ia.Add(z2);
 
1265
 
 
1266
                                        for (z2=0;z2<ag->m_baAtomType.GetSize();z2++)
 
1267
                                        {
 
1268
                                                m2->m_iAtomGes += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
 
1269
 
 
1270
                                                for (z4=0;z4<m2->m_baAtomIndex.GetSize();z4++)
 
1271
                                                {
 
1272
                                                        if (m2->m_baAtomIndex[z4] == ag->m_baRealAtomType[z2])
 
1273
                                                        {
 
1274
                                                                m2->m_waAtomCount[z4] += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
 
1275
                                                                pia = (CxIntArray*)sm2->m_oaAtomOffset[z4];
 
1276
                                                                goto _pmafound;
 
1277
                                                        }
 
1278
                                                }
 
1279
 
 
1280
                                                m2->m_baAtomIndex.Add(ag->m_baRealAtomType[z2]);
 
1281
                                                sm2->m_baAtomIndex.Add(ag->m_baRealAtomType[z2]);
 
1282
                                                m2->m_waAtomCount.Add(((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize());
 
1283
 
 
1284
                                                try { pia = new CxIntArray("gather():pia"); } catch(...) { pia = NULL; }
 
1285
                                                if (pia == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1286
 
 
1287
                                                sm2->m_oaAtomOffset.Add(pia);
 
1288
_pmafound:
 
1289
                                                for (z4=0;z4<((CxIntArray*)ag->m_oaAtoms[z2])->GetSize();z4++)
 
1290
                                                {
 
1291
                                                        for (z5=0;z5<ia.GetSize();z5++)
 
1292
                                                        {
 
1293
                                                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ia[z5]]];
 
1294
                                                                for (z6=0;z6<sm2->m_oaAtomOffset.GetSize();z6++)
 
1295
                                                                {
 
1296
                                                                        for (z7=0;z7<((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetSize();z7++)
 
1297
                                                                        {
 
1298
                                                                                if (((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetAt(z7) == ((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)))
 
1299
                                                                                {
 
1300
                                                                                        eprintf("Weird error: Atom %s%d from %s[%d] is already in the pseudo-molecule; skipping.\n",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)+1,m->m_sName,ia[z5]+1);
 
1301
                                                                                        m2->m_waAtomCount[m2->m_waAtomCount.GetSize()-1]--;
 
1302
                                                                                        abort();
 
1303
                                                                                }
 
1304
                                                                        }
 
1305
                                                                }
 
1306
                                                                pia->Add(((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
 
1307
                                                        }
 
1308
                                                }
 
1309
                                        }
 
1310
                                        delete ag;
 
1311
                                }
 
1312
                                mprintf("\n");
 
1313
/********************************************************************************/
 
1314
                                goto _nopseudomol;
 
1315
                        }
 
1316
        _pseudomolnext:
 
1317
                        ti++;
 
1318
 
 
1319
                        if (!tb2)
 
1320
                        {
 
1321
                                tb2 = true;
 
1322
                                mprintf("\n    You may define custom element labels. This enables keeping apart\n    atoms of the same type from different molecules/positions.\n\n");
 
1323
                                tb = AskYesNo("    Keep the standard element labels (y) or define custom labels (n)? [yes] ",true);
 
1324
                                mprintf("\n");
 
1325
                        }
 
1326
 
 
1327
                        try { m2 = new CMolecule(); } catch(...) { m2 = NULL; }
 
1328
                        if (m2 == NULL) NewException((double)sizeof(CMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1329
                        
 
1330
                        try { sm2 = new CSingleMolecule(); } catch(...) { sm2 = NULL; }
 
1331
                        if (sm2 == NULL) NewException((double)sizeof(CSingleMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1332
                        
 
1333
                        m2->m_bPseudo = true;
 
1334
                        sm2->m_bPseudo = true;
 
1335
                        m2->m_iIndex = g_oaMolecules.GetSize();
 
1336
                        sm2->m_iMolType = g_oaMolecules.GetSize();
 
1337
                        sm2->m_iMolSMIndex = 0;
 
1338
                        m2->m_laSingleMolIndex.Add(g_oaSingleMolecules.GetSize());
 
1339
                        g_oaMolecules.Add(m2);
 
1340
                        g_oaSingleMolecules.Add(sm2);
 
1341
 
 
1342
                        mprintf(WHITE,"    >>> Pseudo-molecule %d (= molecule %d) >>>\n\n",ti,g_oaMolecules.GetSize());
 
1343
        /*              if (ti == 1)
 
1344
                                mprintf(WHITE,"      You may define custom element labels. This enables keeping apart\n      atoms of the same type from different molecules/positions.\n\n");
 
1345
                        tb = AskYesNo("      Keep the standard element labels (y) or define custom labels (n)? [yes] ",true);
 
1346
                        mprintf("\n");
 
1347
*/
 
1348
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1349
                        {
 
1350
                                m = (CMolecule*)g_oaMolecules[z];
 
1351
                                if (m->m_bPseudo)
 
1352
                                        continue;
 
1353
                                if (AskYesNo("    Use atoms from molecule %d (%s) (y/n)? [no] ",false,z+1,m->m_sName))
 
1354
                                {
 
1355
                                        mprintf("\n");
 
1356
                                        try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
 
1357
                                        if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1358
                                        
 
1359
                                        if (AskYesNo("      Use all atoms (y) from %s or only certain atoms (n)? [no] ",false,m->m_sName))
 
1360
                                        {
 
1361
                                                ag->AddAllAtoms(m,false);
 
1362
                                        } else
 
1363
                                        {
 
1364
        _pseudomolp1:
 
1365
                                                AskString_ND("      Please enter atoms from %s to use (e.g. C1-3,H,O4): ",buf,m->m_sName);
 
1366
                                                if (!ag->ParseAtoms(m,buf))
 
1367
                                                        goto _pseudomolp1;
 
1368
                                        }
 
1369
                                        ia.RemoveAll();
 
1370
                                        if (m->m_laSingleMolIndex.GetSize() > 1)
 
1371
                                        {
 
1372
                                                if (!AskYesNo("      Add selected atoms from all %s molecules (y), or only from certain molecules (n)? [yes] ",true,m->m_sName))
 
1373
                                                {
 
1374
        _pseudomolil:
 
1375
                                                        AskString_ND("      Enter the %s molecules to use (range 1-%d, e.g. 1,3-6,8): ",buf,m->m_sName,m->m_laSingleMolIndex.GetSize());
 
1376
                                                        ia.RemoveAll();
 
1377
                                                        if (!ParseIntList(buf,&ia))
 
1378
                                                                goto _pseudomolil;
 
1379
                                                        for (z2=0;z2<ia.GetSize();z2++)
 
1380
                                                        {
 
1381
                                                                if ((ia[z2] < 1) || (ia[z2] > m->m_laSingleMolIndex.GetSize()))
 
1382
                                                                {
 
1383
                                                                        eprintf("Invalid number: %d (should be between 1 and %d).\n",ia[z2],m->m_laSingleMolIndex.GetSize());
 
1384
                                                                        goto _pseudomolil;
 
1385
                                                                }
 
1386
                                                                ia[z2]--;
 
1387
                                                        }
 
1388
                                                } else
 
1389
                                                {
 
1390
                                                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
1391
                                                                ia.Add(z2);
 
1392
                                                }
 
1393
                                        } else ia.Add(0);
 
1394
 
 
1395
                                        if (!tb) // Custom Labels
 
1396
                                        {
 
1397
                                                for (z2=0;z2<ag->m_baAtomType.GetSize();z2++)
 
1398
                                                {
 
1399
        _pmlagain:
 
1400
                                                        AskString("      How should %s from %s be labeled? [%s] ",buf,((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,m->m_sName,((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName);
 
1401
                                                        if (ContainsDigit(buf))
 
1402
                                                        {
 
1403
                                                                eprintf("Digits in element labels not allowed.\n");
 
1404
                                                                goto _pmlagain;
 
1405
                                                        }
 
1406
                                                        for (z3=0;z3<g_oaAtoms.GetSize();z3++)
 
1407
                                                        {
 
1408
                                                                if (mystricmp(buf,((CAtom*)g_oaAtoms[z3])->m_sName) == 0)
 
1409
                                                                {
 
1410
                                                                        ti2 = z3;
 
1411
                                                                        goto _pseudomold1;
 
1412
                                                                }
 
1413
                                                        }
 
1414
                                                        if (strlen(buf) > 7)
 
1415
                                                        {
 
1416
                                                                mprintf("        Element labels may only have up to 7 characters; truncating.\n");
 
1417
                                                                buf[7] = 0;
 
1418
                                                        }
 
1419
                                                        mprintf("        Adding new element label \"%s\"...\n",buf);
 
1420
 
 
1421
                                                        try { at = new CAtom(); } catch(...) { at = NULL; }
 
1422
                                                        if (at == NULL) NewException((double)sizeof(CAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1423
                                                        
 
1424
                                                        at->m_iIndex = g_oaAtoms.GetSize();
 
1425
                                                        at->m_pElement = ((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_pElement;
 
1426
                                                        memcpy(at->m_sName,buf,8);
 
1427
                                                        at->m_iCount = ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
 
1428
                                                        ti2 = g_oaAtoms.GetSize();
 
1429
                                                        g_oaAtoms.Add(at);
 
1430
        _pseudomold1:
 
1431
                                                        m2->m_iAtomGes += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
 
1432
                                                        for (z3=0;z3<m2->m_baAtomIndex.GetSize();z3++)
 
1433
                                                        {
 
1434
                                                                if (m2->m_baAtomIndex[z3] == ti2)
 
1435
                                                                {
 
1436
                                                                        m2->m_waAtomCount[z3] += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
 
1437
                                                                        for (z4=0;z4<((CxIntArray*)ag->m_oaAtoms[z2])->GetSize();z4++)
 
1438
                                                                        {
 
1439
                                                                                for (z5=0;z5<ia.GetSize();z5++)
 
1440
                                                                                {
 
1441
                                                                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ia[z5]]];
 
1442
                                                                                        for (z6=0;z6<sm2->m_oaAtomOffset.GetSize();z6++)
 
1443
                                                                                        {
 
1444
                                                                                                for (z7=0;z7<((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetSize();z7++)
 
1445
                                                                                                {
 
1446
                                                                                                        if (((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetAt(z7) == ((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)))
 
1447
                                                                                                        {
 
1448
                                                                                                                eprintf("Atom %s%d from %s[%d] is already in the pseudo-molecule; skipping.\n",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)+1,m->m_sName,ia[z5]+1);
 
1449
                                                                                                                m2->m_waAtomCount[z3]--;
 
1450
                                                                                                                goto _pseudomolsk1;
 
1451
                                                                                                        }
 
1452
                                                                                                }
 
1453
                                                                                        }
 
1454
                                                        //                              mprintf("Molecule %d, SM %d, Type %d, Atom %d: Line %d.\n",z,ia[z5],((CxIntArray*)sm->m_oaAtomOffset[z2])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
 
1455
                                                                                        ((CxIntArray*)sm2->m_oaAtomOffset[z3])->Add(((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
 
1456
        _pseudomolsk1:;
 
1457
                                                                                }
 
1458
                                                                        }
 
1459
                                                                        goto _pseudomold2;
 
1460
                                                                }
 
1461
                                                        }
 
1462
                                                        m2->m_baAtomIndex.Add(ti2);
 
1463
                                                        sm2->m_baAtomIndex.Add(ti2);
 
1464
                                                        m2->m_waAtomCount.Add(((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize());
 
1465
 
 
1466
                                                        try { pia = new CxIntArray("gather():pia"); } catch(...) { pia = NULL; }
 
1467
                                                        if (pia == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1468
                                                        
 
1469
                                                        sm2->m_oaAtomOffset.Add(pia);
 
1470
                                                        for (z4=0;z4<((CxIntArray*)ag->m_oaAtoms[z2])->GetSize();z4++)
 
1471
                                                        {
 
1472
                                                                for (z5=0;z5<ia.GetSize();z5++)
 
1473
                                                                {
 
1474
                                                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ia[z5]]];
 
1475
                                                                        for (z6=0;z6<sm2->m_oaAtomOffset.GetSize();z6++)
 
1476
                                                                        {
 
1477
                                                                                for (z7=0;z7<((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetSize();z7++)
 
1478
                                                                                {
 
1479
                                                                                        if (((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetAt(z7) == ((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)))
 
1480
                                                                                        {
 
1481
                                                                                                eprintf("Atom %s%d from %s[%d] is already in the pseudo-molecule; skipping.\n",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)+1,m->m_sName,ia[z5]+1);
 
1482
                                                                                                m2->m_waAtomCount[m2->m_waAtomCount.GetSize()-1]--;
 
1483
                                                                                                goto _pseudomolsk2;
 
1484
                                                                                        }
 
1485
                                                                                }
 
1486
                                                                        }
 
1487
                                                                        pia->Add(((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
 
1488
        _pseudomolsk2:;
 
1489
                                                                }
 
1490
                                                        }
 
1491
        _pseudomold2:;
 
1492
                                                }
 
1493
                                        } else // If not custom labels
 
1494
                                        {
 
1495
                                                for (z2=0;z2<ag->m_baAtomType.GetSize();z2++)
 
1496
                                                {
 
1497
                                                        for (z4=0;z4<m2->m_baAtomIndex.GetSize();z4++)
 
1498
                                                        {
 
1499
                                                                if (m2->m_baAtomIndex[z4] == ag->m_baRealAtomType[z2])
 
1500
                                                                {
 
1501
                                                                        m2->m_waAtomCount[z4] += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
 
1502
                                                                        pia = (CxIntArray*)sm2->m_oaAtomOffset[z4];
 
1503
                                                                        goto _pmafound2;
 
1504
                                                                }
 
1505
                                                        }
 
1506
 
 
1507
                                                        m2->m_iAtomGes += ((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize();
 
1508
                                                        m2->m_baAtomIndex.Add(ag->m_baRealAtomType[z2]);
 
1509
                                                        sm2->m_baAtomIndex.Add(ag->m_baRealAtomType[z2]);
 
1510
                                                        m2->m_waAtomCount.Add(((CxIntArray*)ag->m_oaAtoms[z2])->GetSize() * ia.GetSize());
 
1511
 
 
1512
                                                        try { pia = new CxIntArray("gather():pia"); } catch(...) { pia = NULL; }
 
1513
                                                        if (pia == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1514
 
 
1515
                                                        sm2->m_oaAtomOffset.Add(pia);
 
1516
_pmafound2:
 
1517
                                                        for (z4=0;z4<((CxIntArray*)ag->m_oaAtoms[z2])->GetSize();z4++)
 
1518
                                                        {
 
1519
                                                                for (z5=0;z5<ia.GetSize();z5++)
 
1520
                                                                {
 
1521
                                                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ia[z5]]];
 
1522
                                                                        for (z6=0;z6<sm2->m_oaAtomOffset.GetSize();z6++)
 
1523
                                                                        {
 
1524
                                                                                for (z7=0;z7<((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetSize();z7++)
 
1525
                                                                                {
 
1526
                                                                                        if (((CxIntArray*)sm2->m_oaAtomOffset[z6])->GetAt(z7) == ((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)))
 
1527
                                                                                        {
 
1528
                                                                                                eprintf("Atom %s%d from %s[%d] is already in the pseudo-molecule; skipping.\n",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z2]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)+1,m->m_sName,ia[z5]+1);
 
1529
                                                                                                m2->m_waAtomCount[m2->m_waAtomCount.GetSize()-1]--;
 
1530
                                                                                                goto _pseudomolsk3;
 
1531
                                                                                        }
 
1532
                                                                                }
 
1533
                                                                        }
 
1534
                                                                        pia->Add(((CxIntArray*)sm->m_oaAtomOffset[ag->m_baAtomType[z2]])->GetAt(((CxIntArray*)ag->m_oaAtoms[z2])->GetAt(z4)));
 
1535
        _pseudomolsk3:;
 
1536
                                                                }
 
1537
                                                        }
 
1538
                                                }
 
1539
                                        }
 
1540
                                        delete ag;
 
1541
                                        if (AskYesNo("      Use another set of atoms from %s (y/n)? [no] ",false,m->m_sName))
 
1542
                                        {
 
1543
                                                try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
 
1544
                                                if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1545
                                                
 
1546
                                                goto _pseudomolp1;
 
1547
                                        }
 
1548
                                }
 
1549
                                mprintf("\n");
 
1550
                        }
 
1551
_nopseudomol:
 
1552
                        m2->BuildName();
 
1553
                        mprintf(WHITE,"    <<< Pseudo-molecule %d (= molecule %d) defined as %s <<<\n\n",ti,g_oaMolecules.GetSize(),m2->m_sName);
 
1554
                        if (AskYesNo("    Define another pseudo-molecule (y/n)? [no] ",false))
 
1555
                                goto _pseudomolnext;
 
1556
                        mprintf(WHITE,"\n    The following pseudo-molecules have been defined:\n");
 
1557
                        mprintf("      (note: pseudo-molecules start with a $ sign)\n\n");
 
1558
                        ti = 0;
 
1559
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1560
                        {
 
1561
                                m = (CMolecule*)g_oaMolecules[z];
 
1562
                                if (m->m_bPseudo)
 
1563
                                {
 
1564
                                        ti++;
 
1565
                                        mprintf("      %d.) Molecule %d - %s\n",ti,z+1,m->m_sName);
 
1566
                                }
 
1567
                        }
 
1568
                        mprintf(WHITE,"\n    Defining virtual atom #1 as molecular Center of Geometry:\n");
 
1569
                        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
 
1570
                        {
 
1571
                                m = (CMolecule*)g_oaMolecules[z0];
 
1572
                                if (!m->m_bPseudo)
 
1573
                                        continue;
 
1574
                                mprintf("      - %s...\n",m->m_sName);
 
1575
                                va = AddVirtualAtom(z0);
 
1576
                                va->m_iMode = 0;
 
1577
                                va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
 
1578
                                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
 
1579
                                for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
 
1580
                                        va->m_faWeight[z] = 1.0f;
 
1581
                                va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
 
1582
                        }
 
1583
 
 
1584
                        mprintf(WHITE,"\n    Defining virtual atom #2 as molecular Center of Mass:\n");
 
1585
                        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
 
1586
                        {
 
1587
                                m = (CMolecule*)g_oaMolecules[z0];
 
1588
                                if (!m->m_bPseudo)
 
1589
                                        continue;
 
1590
                                mprintf("      - %s...\n",m->m_sName);
 
1591
                                va = AddVirtualAtom(z0);
 
1592
                                va->m_iMode = 0;
 
1593
                                va->m_oCenterAtoms.AddAllAtoms((CMolecule*)g_oaMolecules[va->m_iMolecule],false);
 
1594
                                va->m_faWeight.SetSize(va->m_oCenterAtoms.m_iAtomGes);
 
1595
                                z3 = 0;
 
1596
                                tf2 = 0;
 
1597
                                for (z=0;z<va->m_oCenterAtoms.m_baAtomType.GetSize();z++)
 
1598
                                {
 
1599
                                        tf = ((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z]])->m_pElement->m_fMass;
 
1600
                                        for (z2=0;z2<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z])->GetSize();z2++)
 
1601
                                        {
 
1602
                                                va->m_faWeight[z3] = tf;
 
1603
                                                tf2 += tf;
 
1604
                                                z3++;
 
1605
                                        }
 
1606
                                }
 
1607
                                va->m_fGesWeight = tf2;
 
1608
                                if (va->m_fGesWeight == 0)
 
1609
                                {
 
1610
                                        eprintf("        Molecule %s has total mass of zero. Defining #2 as Center of Geometry.\n",m->m_sName);
 
1611
                                        for (z=0;z<va->m_oCenterAtoms.m_iAtomGes;z++)
 
1612
                                                va->m_faWeight[z] = 1.0f;
 
1613
                                        va->m_fGesWeight = (float)va->m_oCenterAtoms.m_iAtomGes;
 
1614
                                }
 
1615
                        }
 
1616
                }
 
1617
        }
 
1618
 
 
1619
        mprintf(GREEN,"\n>>> %d virtual atoms have been defined: >>>\n",g_oaVirtualAtoms.GetSize());
 
1620
        for (z0=0;z0<g_oaMolecules.GetSize();z0++)
 
1621
        {
 
1622
                for (z=0;z<((CMolecule*)g_oaMolecules[z0])->m_laVirtualAtoms.GetSize();z++)
 
1623
                {
 
1624
                        va = (CVirtualAtom*)g_oaVirtualAtoms[((CMolecule*)g_oaMolecules[z0])->m_laVirtualAtoms[z]];
 
1625
                        if (va->m_iMolVirtAtom < 2)
 
1626
                        {
 
1627
                                mprintf(WHITE,"\n    #%d in %s: %s.",va->m_iMolVirtAtom+1,((CMolecule*)g_oaMolecules[va->m_iMolecule])->m_sName,(va->m_iMolVirtAtom==0)?"Center of Geometry":"Center of Mass");
 
1628
                                if (va->m_iMolVirtAtom == 1)
 
1629
                                        mprintf("\n");
 
1630
                                continue;
 
1631
                        }
 
1632
                        mprintf(WHITE,"\n    #%d in %s - defined through %s\n",va->m_iMolVirtAtom+1,((CMolecule*)g_oaMolecules[va->m_iMolecule])->m_sName,(va->m_iMode==0)?"center:":"distance/angle/dihedral:");
 
1633
                        if (va->m_iMode == 0)
 
1634
                        {
 
1635
                                if (!((CMolecule*)g_oaMolecules[z0])->m_bPseudo || (z > 1))
 
1636
                                {
 
1637
                                        z4 = 0;
 
1638
                                        for (z2=0;z2<va->m_oCenterAtoms.m_baAtomType.GetSize();z2++)
 
1639
                                        {
 
1640
                                                for (z3=0;z3<((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z2])->GetSize();z3++)
 
1641
                                                {
 
1642
                                                        mprintf("      - %2s%-3d  Weight %.2f%c\n",((CAtom*)g_oaAtoms[va->m_oCenterAtoms.m_baRealAtomType[z2]])->m_sName,((CxIntArray*)va->m_oCenterAtoms.m_oaAtoms[z2])->GetAt(z3)+1,va->m_faWeight[z4]/va->m_fGesWeight*100.0f,'%');
 
1643
                                                        z4++;
 
1644
                                                }
 
1645
                                        }
 
1646
                                } else mprintf("        (pseudo-molecule, skipping atoms)\n");
 
1647
                        } else
 
1648
                        {
 
1649
                                mprintf("      - Distance #%d-%s%d = %.2f pm\n",z+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,va->m_fValues[0]);
 
1650
                                mprintf("      - Angle #%d-%s%d-%s%d = %.2f degree\n",z+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1,va->m_fValues[1]*180.0/Pi);
 
1651
                                mprintf("      - Dihedral #%d-%s%d-%s%d-%s%d = %.2f degree\n",z+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[0]])->m_sName,va->m_iAtom[0]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[1]])->m_sName,va->m_iAtom[1]+1,((CAtom*)g_oaAtoms[va->m_iRealAtomType[2]])->m_sName,va->m_iAtom[2]+1,va->m_fValues[2]*180.0/Pi);
 
1652
                        }
 
1653
                }
 
1654
        }
 
1655
        mprintf(GREEN,"\n<<< End of virtual atoms <<<\n\n");
 
1656
 
 
1657
        if (g_bPeriodic)
 
1658
                g_TimeStep.UniteMolecules(false);
 
1659
 
 
1660
        g_TimeStep.CalcCenters();
 
1661
        g_bFoldAtomwise = false;
 
1662
 
 
1663
        if (g_bPeriodic)
 
1664
                g_TimeStep.FoldMolecules();
 
1665
 
 
1666
        BuildAtomIndices();
 
1667
 
 
1668
//      g_TimeStep.WritePOV("step.pov");
 
1669
 
 
1670
        mprintf(WHITE,"\n>>> List of functions <<<\n\n");
 
1671
        DumpAnalyses();
 
1672
        
 
1673
        mprintf("   (You may specify multiple analyses at once, but\n");
 
1674
        mprintf("    the safe way is to perform only one kind of analysis at a time.)\n");
 
1675
_fncinput:
 
1676
        inpprintf("! Which functions to compute (comma separated)?\n");
 
1677
        mprintf("\n    Which functions to compute (comma separated)? ");
 
1678
        myget(buf);
 
1679
        mprintf("\n");
 
1680
        if (!ParseFunctions(buf))
 
1681
        {
 
1682
                eprintf("Wrong input.\n");
 
1683
                inpprintf("! Wrong input.\n");
 
1684
                goto _fncinput;
 
1685
        }
 
1686
        mprintf("\n");
 
1687
 
 
1688
        if (g_bRegionAnalysis)
 
1689
        {
 
1690
                if (!(g_bRDF || g_bSDF || g_bADF || g_bDDF || g_bCDF || g_bRevSDF || g_bDens))
 
1691
                {
 
1692
                        eprintf("    Region-specific analysis needs to be applied to some static analysis.\n\n");
 
1693
                        return false;
 
1694
                }
 
1695
                g_iaSMRegion.SetSize(g_oaSingleMolecules.GetSize());
 
1696
                for (z=0;z<g_oaSingleMolecules.GetSize();z++)
 
1697
                        g_iaSMRegion[z] = (rand()%2)+1;
 
1698
        }
 
1699
 
 
1700
        if (g_bVoro || g_bVoid || g_bSaveJustTraj || g_bSaveRefEnv || g_bCutCluster)
 
1701
                g_bNeedMoleculeWrap = true;
 
1702
 
 
1703
        if (g_bNPT && (g_bACF || g_bMSD))
 
1704
        {
 
1705
                mprintf(RED,"    Warning: ");
 
1706
                mprintf("When a variable cell vector is used, dynamical analyses (like spectra or MSDs)\n");
 
1707
                mprintf("             will give erroneous results.\n\n");
 
1708
        }
 
1709
 
 
1710
        mprintf(WHITE,"    The advanced mode includes some options which are quite powerful,\n    yet possibly weird or seldomly required.\n\n");
 
1711
 
 
1712
        g_bAdvanced2 = AskYesNo("    Use the advanced mode for the main part (y/n)? [no] ",false);
 
1713
        mprintf("\n");
 
1714
 
 
1715
        if (g_bThermo || g_bVDF || g_bRaman || g_bCombined || g_bBondACF || g_bVHDF || g_bACF || g_bUseVelocities || g_bUseForces || g_bMSD || g_bAggregation || g_bDLDisp || g_bDLDF || g_bDACF || g_bRDyn || g_bIRSpec || g_bIRSpec || g_bTimeDiff || g_bDeriv)
 
1716
        {
 
1717
                g_fTimestepLength = AskFloat("    Enter the length of one trajectory time step in fs: [0.5] ",0.5f);
 
1718
                mprintf("\n");
 
1719
        }
 
1720
 
 
1721
        /*********** Interface ***************/
 
1722
        if (!Interface_BeforeAnalysis())
 
1723
                return false;
 
1724
 
 
1725
        if (g_bCDF)
 
1726
        {
 
1727
                mprintf(YELLOW,"*** Combined Distribution Function\n\n");
 
1728
                g_iCDFChannels = AskUnsignedInteger("    How many channels should the Combined Distribution Function have? [2] ",2);
 
1729
 
 
1730
                try { g_iObsChannel = new int[g_iCDFChannels]; } catch(...) { g_iObsChannel = NULL; }
 
1731
                if (g_iObsChannel == NULL) NewException((double)g_iCDFChannels*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1732
                
 
1733
                mprintf("    Choose from these functions: rdf, adf, ddf, dip, vdf");
 
1734
                if (g_bBetaFeatures)
 
1735
                        mprintf(", pldf, lidf");
 
1736
                mprintf("\n");
 
1737
                for (z=0;z<g_iCDFChannels;z++)
 
1738
                {
 
1739
_entertype:
 
1740
                        AskString_ND("    Channel %d: Enter function type (e.g. rdf): ",buf,z+1);
 
1741
                        if (mystricmp(buf,"rdf")==0)
 
1742
                        {
 
1743
                                g_iObsChannel[z] = 0;
 
1744
                                g_bRDF = true;
 
1745
                        } else if (mystricmp(buf,"adf")==0)
 
1746
                        {
 
1747
                                g_iObsChannel[z] = 1;
 
1748
                                g_bADF = true;
 
1749
                        } else if (mystricmp(buf,"ddf")==0)
 
1750
                        {
 
1751
                                g_iObsChannel[z] = 2;
 
1752
                                g_bDDF = true;
 
1753
                        } else if (mystricmp(buf,"dip")==0)
 
1754
                        {
 
1755
                                g_iObsChannel[z] = 3;
 
1756
                                g_bDipDF = true;
 
1757
                        } else if (mystricmp(buf,"vdf")==0)
 
1758
                        {
 
1759
                                g_iObsChannel[z] = 4;
 
1760
                                g_bVDF = true;
 
1761
                        } else if ((mystricmp(buf,"pldf")==0) && g_bBetaFeatures)
 
1762
                        {
 
1763
                                g_iObsChannel[z] = 5;
 
1764
                                g_bPlDF = true;
 
1765
                        } else if ((mystricmp(buf,"lidf")==0) && g_bBetaFeatures)
 
1766
                        {
 
1767
                                g_iObsChannel[z] = 6;
 
1768
                                g_bLiDF = true;
 
1769
                        } else
 
1770
                        {
 
1771
                                eprintf("Wrong input.\n");
 
1772
                                inpprintf("! Wrong input.\n");
 
1773
                                goto _entertype;
 
1774
                        }
 
1775
                }
 
1776
        } else g_iCDFChannels = 1;
 
1777
 
 
1778
        if (g_bDipDF || g_bDipole)
 
1779
                ParseDipole();
 
1780
 
 
1781
        if (g_bVoro)
 
1782
        {
 
1783
                try { g_pVoroWrapper = new CVoroWrapper(); } catch(...) { g_pVoroWrapper = NULL; }
 
1784
                if (g_pVoroWrapper == NULL) NewException((double)sizeof(CVoroWrapper),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1785
                
 
1786
                g_pVoroWrapper->Parse();
 
1787
        }
 
1788
 
 
1789
/*      if (g_bSFac)
 
1790
        {
 
1791
                try { g_pSFac = new CStructureFactor(); } catch(...) { g_pSFac = NULL; }
 
1792
                if (g_pSFac == NULL) NewException((double)sizeof(CStructureFactor),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1793
                
 
1794
                g_pSFac->Parse();
 
1795
        }*/
 
1796
 
 
1797
        if (g_bResp)
 
1798
        {
 
1799
                try { g_pResp = new CResp(); } catch(...) { g_pResp = NULL; }
 
1800
                if (g_pResp == NULL) NewException((double)sizeof(CResp),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1801
                
 
1802
                g_pResp->m_pTimeStep = &g_TimeStep;
 
1803
                g_pResp->ParseResp();
 
1804
 
 
1805
                if (!g_bFFGen)
 
1806
                        return true;
 
1807
        }
 
1808
 
 
1809
        if (g_bFFGen)
 
1810
        {
 
1811
                try { g_pFFGen = new CFFGen(); } catch(...) { g_pFFGen = NULL; }
 
1812
                if (g_pFFGen == NULL) NewException((double)sizeof(CFFGen),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1813
                
 
1814
                g_pFFGen->Parse(&g_TimeStep);
 
1815
 
 
1816
                return true;
 
1817
        }
 
1818
 
 
1819
        if (g_bVoid)
 
1820
        {
 
1821
                try { g_pVoroWrapper = new CVoroWrapper(); } catch(...) { g_pVoroWrapper = NULL; }
 
1822
                if (g_pVoroWrapper == NULL) NewException((double)sizeof(CVoroWrapper),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1823
 
 
1824
                try { g_pVoroAnalysis = new CVoroAnalysis(); } catch(...) { g_pVoroAnalysis = NULL; }
 
1825
                if (g_pVoroAnalysis == NULL) NewException((double)sizeof(CVoroAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1826
                
 
1827
                g_pVoroAnalysis->Parse();
 
1828
        }
 
1829
 
 
1830
        if (g_bAggregation)
 
1831
        {
 
1832
                mprintf(WHITE,">>> Selection of Aggregation Functions >>>\n\n");
 
1833
 
 
1834
                g_bDACF = AskYesNo("    Compute Dimer Existence Autocorrelation Functions (DACFs) (y/n)? [yes] ",true);
 
1835
                g_bDLDF = AskYesNo("    Compute Dimer Lifetime Distribution Functions (DLDFs) (y/n)? [yes] ",true);
 
1836
                g_bDDisp = AskYesNo("    Compute Dimer Displacement Functions / Pair Diffusion (y/n)? [no] ",false);
 
1837
                if (g_bDDisp)
 
1838
                {
 
1839
                        g_bPairMSD = AskYesNo("    Compute Pair Mean Square Displacement (Pair Diffusion) (y/n)? [yes] ",true);
 
1840
                        g_bDLDisp = AskYesNo("    Compute combined Dimer Lifetime/Displacement Function (DLDisp) (y/n)? [yes] ",true);
 
1841
                } else
 
1842
                {
 
1843
                        g_bDLDisp = false;
 
1844
                        g_bPairMSD = false;
 
1845
                }
 
1846
 
 
1847
                mprintf(WHITE,"\n<<< Selection of Aggregation Functions <<<\n\n");
 
1848
        }
 
1849
 
 
1850
        if (g_bNbExchange)
 
1851
        {
 
1852
                mprintf(WHITE,">>> Selection of Neighborhood Exchange Functions >>>\n\n");
 
1853
                mprintf(WHITE,"\n<<< Selection of Neighborhood Exchange Functions <<<\n\n");
 
1854
        }
 
1855
        
 
1856
        if (g_bAdvanced2)
 
1857
        {
 
1858
                if (g_bRDyn || g_bIRSpec)
 
1859
                        g_bRDynCacheMode = AskYesNo("    Use RDyn cached mode (do this unless there are problems) (y/n)? [yes] ",true);
 
1860
 
 
1861
                if (g_bMSD)
 
1862
                        g_bMSDCacheMode = AskYesNo("    Use MSD cached mode (do this unless there are problems) (y/n)? [yes] ",true);
 
1863
        } else
 
1864
        {
 
1865
                g_bRDynCacheMode = true;
 
1866
                g_bMSDCacheMode = true;
 
1867
        }
 
1868
 
 
1869
        if (g_bClusterAnalysis)
 
1870
        {
 
1871
                try { g_pClusterAnalysis = new CClusterAnalysis(); } catch(...) { g_pClusterAnalysis = NULL; }
 
1872
                if (g_pClusterAnalysis == NULL) NewException((double)sizeof(CClusterAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1873
 
 
1874
                g_pClusterAnalysis->Parse();
 
1875
        }
 
1876
 
 
1877
        if (g_bMicroHet)
 
1878
        {
 
1879
                try { g_pMicroHet = new CMicroHet(); } catch(...) { g_pMicroHet = NULL; }
 
1880
                if (g_pMicroHet == NULL) NewException((double)sizeof(CMicroHet),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1881
 
 
1882
                g_pMicroHet->Parse();
 
1883
        }
 
1884
 
 
1885
        if (g_bThermo)
 
1886
        {
 
1887
                try { g_pThermoAnalysis = new CThermoAnalysis(); } catch(...) { g_pThermoAnalysis = NULL; }
 
1888
                if (g_pThermoAnalysis == NULL) NewException((double)sizeof(CThermoAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1889
 
 
1890
                g_pThermoAnalysis->Parse();
 
1891
        }
 
1892
 
 
1893
        if (g_bFESA)
 
1894
        {
 
1895
                try { g_pFESA = new CFESAnalysis(); } catch(...) { g_pFESA = NULL; }
 
1896
                if (g_pFESA == NULL) NewException((double)sizeof(CFESAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1897
 
 
1898
                g_pFESA->Parse();
 
1899
        }
 
1900
 
 
1901
        if (g_bACF)
 
1902
        {
 
1903
//              mprintf(YELLOW,">>> Select Autocorrelation Functions >>>\n\n");
 
1904
 
 
1905
                if (!g_bPowerSpec)
 
1906
                        g_bVACF = AskYesNo("    Calculate velocity autocorrelation function / power spectra (y/n)? [yes] ",true);
 
1907
                                else g_bVACF = true;
 
1908
 
 
1909
                if (g_bVACF)
 
1910
                        g_bUseVelocities = true;
 
1911
 
 
1912
/*              if (g_bBetaFeatures)
 
1913
                        g_bBondACF = AskYesNo("    Calculate bond vibration spectra (y/n)? [no] ",false);
 
1914
                                else*/ g_bBondACF = false;
 
1915
 
 
1916
/*              g_bDipACF = AskYesNo("    Calculate dipole autocorrelation function / IR spectra (y/n)? [no] ",false);
 
1917
                if (g_bDipACF)
 
1918
                        g_bDipole = true;*/
 
1919
 
 
1920
//              mprintf(YELLOW,"\n<<< End of Select Autocorrelation Functions <<<\n\n");
 
1921
        }
 
1922
        
 
1923
        if (g_bBondACF)
 
1924
        {
 
1925
                mprintf(WHITE,">>> Bond vibration spectra >>>\n\n");
 
1926
                if (g_iTrajSteps != -1)
 
1927
                        g_iBondACFDepth = AskUnsignedInteger("    Enter bond ACF depth in time steps: [%d] ",g_iTrajSteps/2,g_iTrajSteps/2);
 
1928
                                else g_iBondACFDepth = AskUnsignedInteger("    Enter bond ACF depth in time steps: [%d] ",4096,4096);
 
1929
                ti = CalcFFTSize(g_iBondACFDepth,false);
 
1930
                if (g_iBondACFDepth != ti)
 
1931
                {
 
1932
                        mprintf(WHITE,"\n    The next \"fast\" size for FFT is %d. Using this instead of %d as size.\n",ti,g_iBondACFDepth);
 
1933
                        g_iBondACFDepth = ti;
 
1934
                }
 
1935
                g_bBondACFNormalize = AskYesNo("    Normalize all bond ACFs (removes intensity info for the peaks) (y/n)? [no] ",false);
 
1936
                g_bBondACFSymmetrize = AskYesNo("    Symmetrize all bond ACFs (y/n)? [no] ",false);
 
1937
                g_bBondACFWindow = AskYesNo("    Apply window function to bond ACFs (y/n)? [yes] ",true);
 
1938
                g_bBondACFDebug = AskYesNo("    Write out bond ACF debug data (y/n)? [no] ",false);
 
1939
                mprintf(WHITE,"\n<<< End of Bond vibration spectra <<<\n\n");
 
1940
        }
 
1941
 
 
1942
        if (g_bRDyn || g_bIRSpec || g_bBondACF || g_bVACF)
 
1943
        {
 
1944
                if (g_bAdvanced2)
 
1945
                        g_bACFFFT = AskYesNo("    Use fourier transform for autocorrelation (much faster) (y/n)? [yes] ",true);
 
1946
                                else g_bACFFFT = true;
 
1947
        } else g_bACFFFT = true;
 
1948
 
 
1949
        if (g_bCDF || g_bPlProj || g_bDipDF || g_bRDF || g_bVHDF || g_bSDF || g_bPlDF || g_bLiDF || g_bVoidSDF || g_bRevSDF || g_bADF || g_bDDF || g_bSaveRefEnv || g_bCutCluster || g_bCond || g_bNbAnalysis)
 
1950
        {
 
1951
                if (g_oaMolecules.GetSize() > 1)
 
1952
                {
 
1953
                        sprintf(buf,"\n    Which of the molecules should be the reference molecule (");
 
1954
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1955
                        {
 
1956
                                sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
 
1957
                                strcat(buf,buf2);
 
1958
                                if (z < g_oaMolecules.GetSize()-1)
 
1959
                                        strcat(buf,", ");
 
1960
                        }
 
1961
                        strcat(buf,")? ");
 
1962
                        g_iFixMol = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize()) - 1;
 
1963
                } else g_iFixMol = 0;
 
1964
                mprintf(WHITE,"\n    %s is the reference molecule.\n\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
 
1965
        } else g_iFixMol = -1;
 
1966
 
 
1967
        if (g_bSaveRefEnv)
 
1968
        {
 
1969
                mprintf(YELLOW,">>> Save environment of the reference molecule >>>\n\n");
 
1970
                g_bSaveRefWithEnv = AskYesNo("    Save the reference molecule itself (y/n)? [yes] ",true);
 
1971
                g_bRefEnvCenter = AskYesNo("    Center the reference molecule in the box (y/n)? [yes] ",true);
 
1972
                if (g_bRefEnvCenter)
 
1973
                {
 
1974
                        mprintf("\n    The first reference atom will be put into the middle of the box.\n\n");
 
1975
                        g_bRefEnvFix = AskYesNo("    Fix rotational freedom of the reference molecule (y/n)? [no] ",false);
 
1976
                        if (g_bRefEnvFix)
 
1977
                        {
 
1978
                                mprintf("\n    The 2nd reference atom will be put onto the positive X axis,\n");
 
1979
                                mprintf("    and the 3rd reference atom into the X-Y plane with positive Y values.\n\n");
 
1980
                        }
 
1981
                        mprintf(WHITE,"    You will be asked for the reference atom(s) lateron.\n\n");
 
1982
                }
 
1983
                if (((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize() > 1)
 
1984
                        g_iSaveRefMol = AskRangeInteger("    Which representative of the reference molecules to use (1-%d)? [1] ",1,((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize(),1,((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize()) - 1;
 
1985
                                else g_iSaveRefMol = 0;
 
1986
                mprintf(WHITE,"\nPlease choose mode for neighborhood detection:\n\n");
 
1987
                inpprintf("! Please choose mode for neighborhood detection:\n");
 
1988
                mprintf("  1.) Search neighbors once in the beginning and always show those.\n");
 
1989
                mprintf("  2.) Search neighbors in every step and show the current neighbors.\n");
 
1990
                mprintf("      (Warning: Neighbor count differs from step to step - be aware.\n");
 
1991
                mprintf("  3.) Find the frequentiest neighbors over all steps and always show those.\n\n");
 
1992
                mprintf(WHITE,"    Please note: ");
 
1993
                mprintf("Programs such as VMD cannot handle variable atom count \n");
 
1994
                mprintf("    along a trajectory and will therefore not work properly with mode 2!\n\n");
 
1995
                g_iNbhMode = AskRangeInteger("    Choice (1-3): [3] ",1,3,3);
 
1996
                mprintf(YELLOW,"\n<<< End of Save environment of the reference molecule <<<\n\n");
 
1997
        }
 
1998
 
 
1999
        if (g_bCutCluster)
 
2000
        {
 
2001
                mprintf(WHITE,">>> Cut clusters >>>\n\n");
 
2002
                g_bSaveRefWithEnv = AskYesNo("    Show reference molecule itself (y/n)? [yes] ",true);
 
2003
                g_bRefEnvCenter = AskYesNo("    Center reference molecule in the box (y/n)? [yes] ",true);
 
2004
                if (g_bRefEnvCenter)
 
2005
                        g_bRefEnvFix = AskYesNo("    Fix rotational freedom of the reference molecule (y/n)? [no] ",false);
 
2006
_clustercount:
 
2007
                g_iClusterCount = AskUnsignedInteger("    How many clusters to create? [100] ",100);
 
2008
                g_iClusterSteps = AskUnsignedInteger("    How many time steps to use for cluster creation? [%d] ",g_iTrajSteps,g_iTrajSteps);
 
2009
                mprintf("\nCreating cluster distribution...");
 
2010
                for (z=0;z<g_iClusterCount;z++)
 
2011
                {
 
2012
                        if (fmod(z,g_iClusterCount/25.0) < 1.0)
 
2013
                                mprintf(".");
 
2014
                        z3=0;
 
2015
_clustagain:
 
2016
                        z3++;
 
2017
                        if (z3 > 500)
 
2018
                        {
 
2019
                                eprintf("Error: Too few molecules / time steps for requested cluster count.\n");
 
2020
                                goto _clustercount;
 
2021
                        }
 
2022
                        ti = ((((unsigned long)rand()%16384)+rand()*16384) % g_iClusterSteps) + 1;
 
2023
                        ti2 = rand()%((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize();
 
2024
                        for (z2=0;z2<g_iaClusterSteps.GetSize();z2++)
 
2025
                                if ((g_iaClusterSteps[z2] == ti) && (g_iaClusterMol[z2] == ti2))
 
2026
                                        goto _clustagain;
 
2027
                        g_iaClusterSteps.Add(ti);
 
2028
                        g_iaClusterMol.Add(ti2);
 
2029
                }
 
2030
                mprintf("Done.\n");
 
2031
                mprintf("Sorting cluster distribution...");
 
2032
                for (z=0;z<g_iClusterCount-1;z++)
 
2033
                {
 
2034
                        if (fmod(z,(g_iClusterCount-1)/25.0) < 1.0)
 
2035
                                mprintf(".");
 
2036
                        ti = 99999999;
 
2037
                        ti2 = 99999999;
 
2038
                        ti3 = -1;
 
2039
                        for (z2=z;z2<g_iClusterCount;z2++)
 
2040
                        {
 
2041
                                if (g_iaClusterSteps[z2] < ti)
 
2042
                                {
 
2043
                                        ti = g_iaClusterSteps[z2];
 
2044
                                        ti2 = g_iaClusterMol[z2];
 
2045
                                        ti3 = z2;
 
2046
                                } else if (g_iaClusterSteps[z2] == ti)
 
2047
                                {
 
2048
                                        if (g_iaClusterMol[z2] < ti2)
 
2049
                                        {
 
2050
                                                ti2 = g_iaClusterMol[z2];
 
2051
                                                ti3 = z2;
 
2052
                                        }
 
2053
                                }
 
2054
                        }
 
2055
                        if (ti3 == -1)
 
2056
                                abort();
 
2057
                        ti = g_iaClusterSteps[z];
 
2058
                        g_iaClusterSteps[z] = g_iaClusterSteps[ti3];
 
2059
                        g_iaClusterSteps[ti3] = ti;
 
2060
                        ti = g_iaClusterMol[z];
 
2061
                        g_iaClusterMol[z] = g_iaClusterMol[ti3];
 
2062
                        g_iaClusterMol[ti3] = ti;
 
2063
                }
 
2064
                mprintf("Done.\n\n");
 
2065
                mprintf("Writing cluster selection to \"cluster.csv\"...");
 
2066
                a = OpenFileWrite("cluster.csv",true);
 
2067
                mfprintf(a,"# Cluster;  Timestep;  Ref. Mol.\n");
 
2068
 
 
2069
                for (z=0;z<g_iClusterCount;z++)
 
2070
                        mfprintf(a,"%d;  %d;  %d\n",z+1,g_iaClusterSteps[z],g_iaClusterMol[z]+1);
 
2071
 
 
2072
                fclose(a);
 
2073
                mprintf("Done.\n\n");
 
2074
                mprintf(WHITE,"<<< End of Cut clusters <<<\n\n");
 
2075
        }
 
2076
 
 
2077
        if (g_bSDF || g_bPlProj || g_bVoidSDF || g_bAvg || ((g_bSaveRefEnv || g_bCutCluster) && g_bRefEnvFix)) // Nur fuer SDFs: Welche zwei weiteren Atome fixieren?
 
2078
        {
 
2079
                g_iRefSystemDim = 3;
 
2080
_ref3again:
 
2081
                mprintf(WHITE,"    You have to choose three reference atoms from the reference molecule %s:\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
 
2082
                mprintf("    The first reference atom will be put into the center.\n");
 
2083
                mprintf("    The 2nd reference atom will be put onto the positive X axis.\n");
 
2084
                mprintf("    The 3rd reference atom will be put into the X-Y plane with positive Y values.\n\n");
 
2085
                mprintf("    Please enter three comma-separated reference atoms (e.g. \"C1,H2,O1\"): ");
 
2086
                inpprintf("! Please enter three comma-separated reference atoms (e.g. \"C1,H2,O1\"):\n");
 
2087
                myget(buf);
 
2088
                if (!ParseRefSystem(g_iFixMol,buf,3))
 
2089
                        goto _ref3again;
 
2090
                for (z=1;z<3;z++)
 
2091
                {
 
2092
                        for (z2=0;z2<z;z2++)
 
2093
                        {
 
2094
                                if ((g_iFixAtomType[z] == g_iFixAtomType[z2]) && (g_iFixAtom[z] == g_iFixAtom[z2]))
 
2095
                                {
 
2096
                                        eprintf("Please enter three pairwise different atoms.\n\n");
 
2097
                                        inpprintf("! Please enter three pairwise different atoms.\n");
 
2098
                                        goto _ref3again;
 
2099
                                }
 
2100
                        }
 
2101
                }
 
2102
                mprintf("\n");
 
2103
                mprintf(WHITE,"    Reference plane: Fixing in %s the %d. %s-, the %d. %s- and the %d. %s atom.\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,g_iFixAtom[0]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[0]])->m_sName,g_iFixAtom[1]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[1]])->m_sName,g_iFixAtom[2]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[2]])->m_sName);
 
2104
                mprintf("\n");
 
2105
        } else if (g_bRevSDF)
 
2106
        {
 
2107
                g_iRefSystemDim = 2;
 
2108
_ref2again:
 
2109
                mprintf("    Please enter two reference atoms (e.g. C1,H3): ");
 
2110
                inpprintf("! Please enter two reference atoms (e.g. C1,H3):\n");
 
2111
                myget(buf);
 
2112
                if (!ParseRefSystem(g_iFixMol,buf,2))
 
2113
                        goto _ref2again;
 
2114
                if ((g_iFixAtomType[0] == g_iFixAtomType[1]) && (g_iFixAtom[0] == g_iFixAtom[1]))
 
2115
                {
 
2116
                        eprintf("Please enter two different atoms.\n\n");
 
2117
                        inpprintf("! Please enter two different atoms.\n");
 
2118
                        goto _ref2again;
 
2119
                }
 
2120
                mprintf("\n");
 
2121
                mprintf(WHITE,"Reference axis: Fixing in %s the %d. %s and the %d. %s atom.\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,g_iFixAtom[0]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[0]])->m_sName,g_iFixAtom[1]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[1]])->m_sName);
 
2122
                mprintf("\n");
 
2123
        } else if (g_bVHDF || g_bRDF || g_bADF || g_bPlDF || g_bLiDF || g_bDDF || g_bSaveRefEnv || g_bSaveRefEnv || g_bCutCluster) // Fuer Verteilungsfunktion: Welches Atom im Ursprung
 
2124
        {
 
2125
                g_iRefSystemDim = 1;
 
2126
                if (g_bAdvanced2)
 
2127
                {
 
2128
_ref1again:
 
2129
                        mprintf("    Please enter the atom to put into the box center (e.g. C3): [center of mass] ");
 
2130
                        inpprintf("! Please enter the atom to put into the box center (e.g. C3): [center of mass]\n");
 
2131
                        myget(buf);
 
2132
                        if (strlen(buf)==0)
 
2133
                        {
 
2134
                                if (!ParseRefSystem(g_iFixMol,"#2",1))
 
2135
                                {
 
2136
                                        eprintf("Weird error.\n");
 
2137
                                        inpprintf("! Weird error.\n");
 
2138
                                        abort();
 
2139
                                }
 
2140
                        } else if (!ParseRefSystem(g_iFixMol,buf,1))
 
2141
                                goto _ref1again;
 
2142
                        mprintf("\n");
 
2143
                        mprintf(WHITE,"Reference atom: Fixing in %s the %d. %s atom.\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,g_iFixAtom[0]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[0]])->m_sName);
 
2144
                        mprintf("\n");
 
2145
                } else
 
2146
                {
 
2147
                        if (!ParseRefSystem(g_iFixMol,"#2",1))
 
2148
                        {
 
2149
                                eprintf("Weird error.\n");
 
2150
                                inpprintf("! Weird error.\n");
 
2151
                                abort();
 
2152
                        }
 
2153
                }
 
2154
        } else if (g_iFixMol != -1)
 
2155
        {
 
2156
                g_iRefSystemDim = 1;
 
2157
                if (!ParseRefSystem(g_iFixMol,"#2",1))
 
2158
                {
 
2159
                        eprintf("Weird error.\n");
 
2160
                        abort();
 
2161
                }
 
2162
                mprintf("    Reference atom: Fixing in %s the %d. %s atom.\n\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,g_iFixAtom[0]+1,((CAtom*)g_oaAtoms[g_iFixRealAtomType[0]])->m_sName);
 
2163
        }
 
2164
 
 
2165
        if (g_bSaveRefEnv || g_bCutCluster)
 
2166
        {
 
2167
                mprintf(WHITE,">>> Neighborhood Definition >>>\n\n");
 
2168
 
 
2169
                try { g_pNbSet = new CNbSet(); } catch(...) { g_pNbSet = NULL; }
 
2170
                if (g_pNbSet == NULL) NewException((double)sizeof(CNbSet),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2171
                
 
2172
                g_pNbSet->Parse(g_iFixMol);
 
2173
                mprintf(WHITE,"\n<<< End of Neighborhood Definition <<<\n\n");
 
2174
 
 
2175
                if (g_bSaveRefEnv)
 
2176
                {
 
2177
                        if (AskYesNo("    Create a temporal development overlay (TDO) plot (y/n)? [no] ",false))
 
2178
                        {
 
2179
                                g_bTDO = true;
 
2180
                                g_laTDOSteps.RemoveAll();
 
2181
                                if (AskYesNo("    Use equidistant intervals (y) or specify each point (n) (y/n)? [yes] ",true))
 
2182
                                {
 
2183
                                        g_bTDOEqui = true;
 
2184
                                        g_iTDOCount = AskUnsignedInteger("    Enter the overlay count: [5] ",5);
 
2185
                                        g_iTDOStart = AskUnsignedInteger("    Enter the starting timestep: [0] ",0);
 
2186
                                        g_iTDOStride = AskUnsignedInteger("    Enter the overlay distance in steps: [1000] ",1000);
 
2187
                                        for (z=0;z<g_iTDOCount;z++)
 
2188
                                                g_laTDOSteps.Add(g_iTDOStart+z*g_iTDOStride);
 
2189
                                } else
 
2190
                                {
 
2191
                                        g_bTDOEqui = false;
 
2192
                                        while (true)
 
2193
                                        {
 
2194
                                                ti = AskUnsignedInteger("    Enter timestep for %dth overlay: [done] ",999999,g_laTDOSteps.GetSize()+1);
 
2195
                                                if (ti == 999999)
 
2196
                                                        break;
 
2197
                                                g_laTDOSteps.Add(ti);
 
2198
                                        }
 
2199
                                }
 
2200
                                g_fTDOBleaching = AskRangeFloat("    Enter the TDO bleaching grade (0-1): [0.8] ",0.0f,1.0f,0.8f);
 
2201
                        } else g_bTDO = false;
 
2202
                }
 
2203
        }
 
2204
 
 
2205
        if (g_bPlProj || g_bAggregation || g_bNbAnalysis || g_bPlDF || g_bLiDF || g_bRDyn || g_bIRSpec || g_bDipDF || g_bMSD || g_bADF || g_bDDF || g_bVACF || g_bDipACF || g_bRevSDF || g_bSDF || g_bVHDF || g_bRDF || g_bDens || g_bVDF || g_bFDF || g_bCond) // Fuer Verteilungsfunktion: Welches Atom beobachten?
 
2206
        {
 
2207
                if (g_bVACF)
 
2208
                {
 
2209
                        if (g_bAdvanced2)
 
2210
                                g_bVACFCacheMode = AskYesNo("    Use VACF cached mode (do this unless there are problems) (y/n)? [yes] ",true);
 
2211
                                        else g_bVACFCacheMode = true;
 
2212
 
 
2213
                        if (g_bPowerSpec)
 
2214
                        {
 
2215
                                g_bGlobalVACF = AskYesNo("    Compute power spectrum of whole system (y/n)? [yes] ",true);
 
2216
 
 
2217
                                if (g_bGlobalVACF)
 
2218
                                        if (!AskYesNo("    Compute also power spectra for certain atoms/molecules (y/n)? [no] ",false))
 
2219
                                                goto _endobs;
 
2220
                        } else
 
2221
                        {
 
2222
                                g_bGlobalVACF = AskYesNo("    Compute global velocity ACF of whole system (y/n)? [yes] ",true);
 
2223
 
 
2224
                                if (g_bGlobalVACF)
 
2225
                                        if (!AskYesNo("    Compute also velocity ACFs for certain atoms/molecules (y/n)? [no] ",false))
 
2226
                                                goto _endobs;
 
2227
                        }
 
2228
                }
 
2229
 
 
2230
                if (g_bIRSpec)
 
2231
                {
 
2232
                        g_bGlobalIR = AskYesNo("    Compute IR spectrum of whole system (y/n)? [yes] ",true);
 
2233
                        if (g_bGlobalIR)
 
2234
                                if (!AskYesNo("    Compute also IR spectra for certain molecule types (y/n)? [no] ",false))
 
2235
                                        goto _endobs;
 
2236
                }
 
2237
 
 
2238
/*              if (g_bDipACF)
 
2239
                {
 
2240
                        g_bGlobalDipACF = AskYesNo("    Create global dipole ACF of all atoms (y/n)? [yes] ",true);
 
2241
                }*/
 
2242
_nextsdf:
 
2243
                mprintf(YELLOW,"\n>>> Observation %d >>>\n\n",g_oaObserv.GetSize()+1);
 
2244
 
 
2245
                try { o = new CObservation(); } catch(...) { o = NULL; }
 
2246
                if (o == NULL) NewException((double)sizeof(CObservation),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2247
                
 
2248
                o->m_pConditions = NULL;
 
2249
                g_oaObserv.Add(o);
 
2250
                o->m_bTimeDev = false;
 
2251
                if (g_bAggregation || g_bNbExchange)
 
2252
                {
 
2253
                        o->m_bSelf = false;
 
2254
                        o->m_bOthers = false;
 
2255
                } else if (g_bNbAnalysis)
 
2256
                {
 
2257
                        o->m_bSelf = false;
 
2258
                        o->m_bOthers = true;
 
2259
                        mprintf("    Performing this observation intermolecular.\n\n");
 
2260
                } else if (g_iFixMol != -1)
 
2261
                {
 
2262
                        if (AskRangeInteger("    Perform this observation intramolecular (within the reference molecule) (0) or intermolecular (1)? [1] ",0,1,1) == 1)
 
2263
                        {
 
2264
                                o->m_bSelf = false;
 
2265
                                o->m_bOthers = true;
 
2266
                        } else
 
2267
                        {
 
2268
                                o->m_bSelf = true;
 
2269
                                o->m_bOthers = false;
 
2270
                        }
 
2271
                        mprintf("\n");
 
2272
                } else 
 
2273
                {
 
2274
                        o->m_bSelf = false;
 
2275
                        o->m_bOthers = true;
 
2276
                }
 
2277
                if (o->m_bOthers)
 
2278
                {
 
2279
                        if (g_bCDF)
 
2280
                        {
 
2281
                                mprintf(WHITE,"    Please note: ");
 
2282
                                mprintf("Although you specified this observation to be intermolecular, you may of course\n");
 
2283
                                mprintf("                 choose atoms from RM only (or OM only), which will yield an intramolecular quantity.\n\n");
 
2284
                        }
 
2285
                        if (g_bCDF)
 
2286
                                o->m_bSecondShowMol = AskYesNo("    CDF: Perform a three-body analysis (y) or observe one molecule at a time (n)? [no] ",false);
 
2287
                                        else o->m_bSecondShowMol = false;
 
2288
                        if (o->m_bSecondShowMol)
 
2289
                        {
 
2290
                                mprintf(WHITE,"\n    You have to select two observed molecules (OMs):\n");
 
2291
                                mprintf("    The first CDF channel observes the 1st OM, the second channel observes the 2nd OM.\n\n");
 
2292
                        }
 
2293
                        if (g_oaMolecules.GetSize() > 1)
 
2294
                        {
 
2295
_obsmolagain:
 
2296
                                if (o->m_bSecondShowMol)
 
2297
                                        sprintf(buf,"    Which 1st molecule should be observed (");
 
2298
                                                else sprintf(buf,"    Which molecule should be observed (");
 
2299
                                for (z=0;z<g_oaMolecules.GetSize();z++)
 
2300
                                {
 
2301
                                        sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
 
2302
                                        strcat(buf,buf2);
 
2303
                                        if (z < g_oaMolecules.GetSize()-1)
 
2304
                                                strcat(buf,", ");
 
2305
                                }
 
2306
                                strcat(buf,")? ");
 
2307
                                o->m_iShowMol = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize()) - 1;
 
2308
                                if ((((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize() == 1) && (o->m_iShowMol == g_iFixMol))
 
2309
                                {
 
2310
                                        eprintf("Error: There is only 1 molecule of %s.\n--> Intermolecular observation between %s and %s not possible.\n\n",((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
 
2311
                                        goto _obsmolagain;
 
2312
                                }
 
2313
                        } else 
 
2314
                        {
 
2315
                                mprintf("    Only one molecule type, choosing %s as observed molecule (OM).\n",((CMolecule*)g_oaMolecules[0])->m_sName);
 
2316
                                o->m_iShowMol = 0;
 
2317
                        }
 
2318
                        o->m_iShowMolCount = ((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize();
 
2319
                        if (o->m_bSecondShowMol)
 
2320
                        {
 
2321
                                if (g_oaMolecules.GetSize() > 1)
 
2322
                                {
 
2323
_obsmol2again:
 
2324
                                        sprintf(buf,"    Which 2nd molecule should be observed (");
 
2325
                                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
2326
                                        {
 
2327
                                                sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
 
2328
                                                strcat(buf,buf2);
 
2329
                                                if (z < g_oaMolecules.GetSize()-1)
 
2330
                                                        strcat(buf,", ");
 
2331
                                        }
 
2332
                                        strcat(buf,")? ");
 
2333
                                        o->m_iShowMol2 = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize()) - 1;
 
2334
                                        if ((((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_laSingleMolIndex.GetSize() == 1) && (o->m_iShowMol2 == g_iFixMol))
 
2335
                                        {
 
2336
                                                eprintf("Error: There is only 1 molecule of %s.\n  --> Intermolecular observation between %s and %s not possible.\n\n",((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName);
 
2337
                                                goto _obsmol2again;
 
2338
                                        }
 
2339
                                } else o->m_iShowMol2 = 0;
 
2340
                                o->m_iShowMol2Count = ((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_laSingleMolIndex.GetSize();
 
2341
                                if (o->m_iShowMol == o->m_iShowMol2)
 
2342
                                        o->m_bExclude1eq2 = AskYesNo("    Exclude the case \"1st OM = 2nd OM\" (y/n)? [yes] ",true);
 
2343
                                                else o->m_bExclude1eq2 = false;
 
2344
                        }
 
2345
                } else 
 
2346
                {
 
2347
                        o->m_iShowMol = -1;
 
2348
                        o->m_iShowMol2 = -1;
 
2349
                        o->m_bSecondShowMol = false;
 
2350
                        o->m_iShowMolCount = 1;
 
2351
                }
 
2352
 
 
2353
                buf[0] = 0;
 
2354
                if ((o->m_bSecondShowMol) && (o->m_iShowMol != o->m_iShowMol2))
 
2355
                        sprintf(buf," of %s / %s / %s",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName);
 
2356
                                else if ((o->m_iShowMol != -1) && (g_iFixMol != -1))
 
2357
                                        sprintf(buf," of %s / %s",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
 
2358
                                                else if (g_iFixMol != -1) sprintf(buf," of %s",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
 
2359
 
 
2360
                if (g_iFixMol != -1)
 
2361
                {
 
2362
                        if (g_bAdvanced2)
 
2363
                        {
 
2364
                                if (AskYesNo("    Observe only certain molecules%s (y/n)? [no] ",false,buf))
 
2365
                                {
 
2366
                                        o->m_bObsCertain = true;
 
2367
                                        if (!g_bCDF && (g_bRDF || g_bADF || g_bDDF || g_bDipDF))
 
2368
                                                o->m_bDecompDist = AskYesNo("    Decompose distribution functions into contributions from molecules (y/n)? [yes] ",true);
 
2369
                                        
 
2370
                                        if (((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize() > 1)
 
2371
                                        {
 
2372
                                                mprintf("    Which %s molecules (RM) to take into account (e.g. 1,3-7)? [all] ",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
 
2373
                                                inpprintf("! Which %s molecules (RM) to take into account (e.g. 1,3-7)? [all]\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName);
 
2374
                                                myget(buf);
 
2375
                                                if (strlen(buf)==0)
 
2376
                                                {
 
2377
                                                        for (z=0;z<((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize();z++)
 
2378
                                                                o->m_waObsRefList.Add(z);
 
2379
                                                } else
 
2380
                                                {
 
2381
                                                        ParseIntList(buf,&o->m_waObsRefList);
 
2382
                                                        for (z=0;z<o->m_waObsRefList.GetSize();z++)
 
2383
                                                                o->m_waObsRefList[z]--;
 
2384
                                                }
 
2385
                                        } else o->m_waObsRefList.Add(0);
 
2386
 
 
2387
                                //      mprintf("RefList[0] = %d\n",o->m_waObsRefList[0]);
 
2388
 
 
2389
                                        if (o->m_iShowMol != -1)
 
2390
                                        {
 
2391
                                                if (((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize() > 1)
 
2392
                                                {
 
2393
                                                        mprintf("    Which %s molecules (OM) to take into account (e.g. 1,3-7)? [all] ",((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
 
2394
                                                        inpprintf("! Which %s molecules (OM) to take into account (e.g. 1,3-7)? [all]\n",((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
 
2395
                                                        myget(buf);
 
2396
                                                        if (strlen(buf)==0)
 
2397
                                                        {
 
2398
                                                                for (z=0;z<((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize();z++)
 
2399
                                                                        o->m_waObsShowList.Add(z);
 
2400
                                                        } else
 
2401
                                                        {
 
2402
                                                                ParseIntList(buf,&o->m_waObsShowList);
 
2403
                                                                for (z=0;z<o->m_waObsShowList.GetSize();z++)
 
2404
                                                                        o->m_waObsShowList[z]--;
 
2405
                                                        }
 
2406
                                                } else o->m_waObsShowList.Add(0);
 
2407
                                        } else o->m_waObsShowList.Add(0); // Dummy
 
2408
 
 
2409
                                        if (o->m_bSecondShowMol)
 
2410
                                        {
 
2411
                                                if (o->m_iShowMol2 != -1)
 
2412
                                                {
 
2413
                                                        if (((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_laSingleMolIndex.GetSize() > 1)
 
2414
                                                        {
 
2415
                                                                mprintf("    Which %s molecules (2nd OM) to take into account (e.g. 1,3-7)? [all] ",((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName);
 
2416
                                                                inpprintf("! Which %s molecules (2nd OM) to take into account (e.g. 1,3-7)? [all]\n",((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_sName);
 
2417
                                                                myget(buf);
 
2418
                                                                if (strlen(buf)==0)
 
2419
                                                                {
 
2420
                                                                        for (z=0;z<((CMolecule*)g_oaMolecules[o->m_iShowMol2])->m_laSingleMolIndex.GetSize();z++)
 
2421
                                                                                o->m_waObsShow2List.Add(z);
 
2422
                                                                } else
 
2423
                                                                {
 
2424
                                                                        ParseIntList(buf,&o->m_waObsShow2List);
 
2425
                                                                        for (z=0;z<o->m_waObsShow2List.GetSize();z++)
 
2426
                                                                                o->m_waObsShow2List[z]--;
 
2427
                                                                }
 
2428
                                                        } else o->m_waObsShow2List.Add(0);
 
2429
                                                } else o->m_waObsShow2List.Add(0); // Dummy
 
2430
                                        }
 
2431
                                } else // if not onlysome
 
2432
                                {
 
2433
                                        o->m_bObsCertain = false;
 
2434
                                        o->m_bDecompDist = false;
 
2435
                                }
 
2436
                        } else // if not advanced
 
2437
                        {
 
2438
                                o->m_bObsCertain = false;
 
2439
                                o->m_bDecompDist = false;
 
2440
                        }
 
2441
                } else
 
2442
                {
 
2443
                        o->m_bObsCertain = false;
 
2444
                        o->m_bDecompDist = false;
 
2445
                }
 
2446
 
 
2447
                o->m_bDecompType = false;
 
2448
 
 
2449
                if ((!o->m_bObsCertain) && (!g_bCDF) && g_bAdvanced2 && (g_bRDF || g_bADF || g_bDDF || g_bDipDF))
 
2450
                {
 
2451
                        if (AskYesNo("    Decompose this observation into contributions from different elements (y/n)? [no] ",false))
 
2452
                        {
 
2453
                                o->m_bDecompType = true;
 
2454
                        }
 
2455
                }
 
2456
 
 
2457
                if (g_bRegionAnalysis)
 
2458
                {
 
2459
                        AskString("    Take reference molecules from which regions? [all] ",buf,"0");
 
2460
                        ParseIntList(buf,&o->m_iaRMRegions);
 
2461
        //              for (z6=0;z6<o->m_iaRMRegions.GetSize();z6++)
 
2462
        //                      if (o->m_iaRMRegions[z6] != 0)
 
2463
        //                              o->m_iaRMRegions[z6]--;
 
2464
 
 
2465
                        if (o->m_bOthers)
 
2466
                        {
 
2467
                                if (o->m_bSecondShowMol)
 
2468
                                {
 
2469
                                        AskString("    Take 1st observed molecules from which regions? [all] ",buf,"0");
 
2470
                                        ParseIntList(buf,&o->m_iaOM1Regions);
 
2471
                                //      for (z6=0;z6<o->m_iaOM1Regions.GetSize();z6++)
 
2472
                                //              if (o->m_iaOM1Regions[z6] != 0)
 
2473
                                //                      o->m_iaOM1Regions[z6]--;
 
2474
                                        AskString("    Take 2nd observed molecules from which regions? [all] ",buf,"0");
 
2475
                                        ParseIntList(buf,&o->m_iaOM2Regions);
 
2476
                                //      for (z6=0;z6<o->m_iaOM2Regions.GetSize();z6++)
 
2477
                                //              if (o->m_iaOM2Regions[z6] != 0)
 
2478
                                //                      o->m_iaOM2Regions[z6]--;
 
2479
                                } else
 
2480
                                {
 
2481
                                        AskString("    Take observed molecules from which regions? [all] ",buf,"0");
 
2482
                                        ParseIntList(buf,&o->m_iaOM1Regions);
 
2483
                                //      for (z6=0;z6<o->m_iaOM1Regions.GetSize();z6++)
 
2484
                                //              if (o->m_iaOM1Regions[z6] != 0)
 
2485
                                //                      o->m_iaOM1Regions[z6]--;
 
2486
                                }
 
2487
                        }
 
2488
                }
 
2489
 
 
2490
                if (g_bAggregation || g_bNbExchange)
 
2491
                {
 
2492
                        try { o->m_pDACF = new CDACF(); } catch(...) { o->m_pDACF = NULL; }
 
2493
                        if (o->m_pDACF == NULL) NewException((double)sizeof(CDACF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2494
                        
 
2495
                        o->m_pDACF->Parse();
 
2496
                }
 
2497
 
 
2498
                if (g_bRDyn)
 
2499
                {
 
2500
                        try { o->m_pRDyn = new CReorDyn(); } catch(...) { o->m_pRDyn = NULL; }
 
2501
                        if (o->m_pRDyn == NULL) NewException((double)sizeof(CReorDyn),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2502
                        
 
2503
                        o->m_pRDyn->m_iShowMol = o->m_iShowMol;
 
2504
                        o->m_pRDyn->Parse();
 
2505
                }
 
2506
 
 
2507
                if (g_bIRSpec)
 
2508
                {
 
2509
                        try { o->m_pIRSpec = new CReorDyn(); } catch(...) { o->m_pIRSpec = NULL; }
 
2510
                        if (o->m_pIRSpec == NULL) NewException((double)sizeof(CReorDyn),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2511
                        
 
2512
                        o->m_pIRSpec->m_iShowMol = o->m_iShowMol;
 
2513
                        o->m_pIRSpec->ParseSpec();
 
2514
                }
 
2515
 
 
2516
                if (g_bDens)
 
2517
                {
 
2518
                        try { o->m_pDensityDF = new CDensDF(); } catch(...) { o->m_pDensityDF = NULL; }
 
2519
                        if (o->m_pDensityDF == NULL) NewException((double)sizeof(CDensDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2520
                        
 
2521
                        o->m_pDensityDF->m_iShowMol = o->m_iShowMol;
 
2522
                        o->m_pDensityDF->Parse();
 
2523
                }
 
2524
                        
 
2525
                if (g_bSDF)
 
2526
                {
 
2527
                        try { o->m_pSDF = new CSDF(); } catch(...) { o->m_pSDF = NULL; }
 
2528
                        if (o->m_pSDF == NULL) NewException((double)sizeof(CSDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2529
                         
 
2530
                        o->m_pSDF->m_bIntra = o->m_bSelf;
 
2531
                        o->m_pSDF->m_iShowMol = o->m_iShowMol;
 
2532
                        o->m_pSDF->Parse(false);
 
2533
                }
 
2534
 
 
2535
                if (g_bPlProj)
 
2536
                {
 
2537
                        try { o->m_pPlProj = new CPlProj(); } catch(...) { o->m_pPlProj = NULL; }
 
2538
                        if (o->m_pPlProj == NULL) NewException((double)sizeof(CPlProj),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2524
2539
                         
2525
 
                        o->m_pSDF->m_bIntra = o->m_bSelf;
2526
 
                        o->m_pSDF->m_iShowMol = o->m_iShowMol;
2527
 
                        o->m_pSDF->Parse(false);
2528
 
                }
2529
 
 
2530
 
                if (g_bRevSDF)
2531
 
                {
2532
 
                        try { o->m_pRevSDF = new CRevSDF();  } catch(...) { o->m_pRevSDF = NULL; }
2533
 
                        if (o->m_pRevSDF == NULL) NewException((double)sizeof(CRevSDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2534
 
                        
2535
 
                        o->m_pRevSDF->m_bIntra = o->m_bSelf;
2536
 
                        o->m_pRevSDF->m_iShowMol = o->m_iShowMol;
2537
 
                        o->m_pRevSDF->Parse();
2538
 
                }
2539
 
 
2540
 
                if (g_bNbAnalysis)
2541
 
                {
2542
 
                        try { o->m_pNbAnalysis = new CNbAnalysis();  } catch(...) { o->m_pNbAnalysis = NULL; }
2543
 
                        if (o->m_pNbAnalysis == NULL) NewException((double)sizeof(CNbAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2544
 
                        
2545
 
                        o->m_pNbAnalysis->m_iShowMol = o->m_iShowMol;
2546
 
                        o->m_pNbAnalysis->Parse();
2547
 
                }
2548
 
 
2549
 
                try { o->m_pRDF = new CRDF*[g_iCDFChannels];  } catch(...) { o->m_pRDF = NULL; }
2550
 
                if (o->m_pRDF == NULL) NewException((double)g_iCDFChannels*sizeof(CRDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2551
 
                
2552
 
                try { o->m_pADF = new CADF*[g_iCDFChannels];  } catch(...) { o->m_pADF = NULL; }
2553
 
                if (o->m_pADF == NULL) NewException((double)g_iCDFChannels*sizeof(CADF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2554
 
                
2555
 
                try { o->m_pDDF = new CDDF*[g_iCDFChannels];  } catch(...) { o->m_pDDF = NULL; }
2556
 
                if (o->m_pDDF == NULL) NewException((double)g_iCDFChannels*sizeof(CDDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2557
 
                
2558
 
                try { o->m_pDipDF = new CDipDF*[g_iCDFChannels];  } catch(...) { o->m_pDipDF = NULL; }
2559
 
                if (o->m_pDipDF == NULL) NewException((double)g_iCDFChannels*sizeof(CDipDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2560
 
                
2561
 
                try { o->m_pVDF = new CVDF*[g_iCDFChannels];  } catch(...) { o->m_pVDF = NULL; }
2562
 
                if (o->m_pVDF == NULL) NewException((double)g_iCDFChannels*sizeof(CVDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2563
 
 
2564
 
                try { o->m_pPlDF = new CPlDF*[g_iCDFChannels];  } catch(...) { o->m_pPlDF = NULL; }
2565
 
                if (o->m_pPlDF == NULL) NewException((double)g_iCDFChannels*sizeof(CVDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2566
 
 
2567
 
                try { o->m_pLiDF = new CLiDF*[g_iCDFChannels];  } catch(...) { o->m_pLiDF = NULL; }
2568
 
                if (o->m_pLiDF == NULL) NewException((double)g_iCDFChannels*sizeof(CVDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2569
 
 
2570
 
                for (z=0;z<g_iCDFChannels;z++)
2571
 
                {
2572
 
                        o->m_pRDF[z] = NULL;
2573
 
                        o->m_pADF[z] = NULL;
2574
 
                        o->m_pDDF[z] = NULL;
2575
 
                        o->m_pDipDF[z] = NULL;
2576
 
                        o->m_pVDF[z] = NULL;
2577
 
                        o->m_pPlDF[z] = NULL;
2578
 
                        o->m_pLiDF[z] = NULL;
2579
 
                }
2580
 
 
2581
 
                if (g_bCDF)
2582
 
                {
2583
 
                        try { o->m_pCDF = new CCDF();  } catch(...) { o->m_pCDF = NULL; }
2584
 
                        if (o->m_pCDF == NULL) NewException((double)sizeof(CCDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2585
 
                        
2586
 
                        try { o->m_pCDF->m_iCombinations = new int[g_iCDFChannels];  } catch(...) { o->m_pCDF->m_iCombinations = NULL; }
2587
 
                        if (o->m_pCDF->m_iCombinations == NULL) NewException((double)g_iCDFChannels*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2588
 
                        
2589
 
                        mprintf(BLUE,"\n>>> Combined Distribution Function >>>\n");
2590
 
//                      o->m_pCDF->m_bChannelAll = new bool[g_iCDFChannels];
2591
 
                        o->m_pCDF->m_iCombinationProd = 1;
2592
 
                        for (z=0;z<g_iCDFChannels;z++)
 
2540
                        o->m_pPlProj->m_bIntra = o->m_bSelf;
 
2541
                        o->m_pPlProj->m_iShowMol = o->m_iShowMol;
 
2542
                        o->m_pPlProj->Parse();
 
2543
                }
 
2544
 
 
2545
                if (g_bRevSDF)
 
2546
                {
 
2547
                        try { o->m_pRevSDF = new CRevSDF();  } catch(...) { o->m_pRevSDF = NULL; }
 
2548
                        if (o->m_pRevSDF == NULL) NewException((double)sizeof(CRevSDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2549
                        
 
2550
                        o->m_pRevSDF->m_bIntra = o->m_bSelf;
 
2551
                        o->m_pRevSDF->m_iShowMol = o->m_iShowMol;
 
2552
                        o->m_pRevSDF->Parse();
 
2553
                }
 
2554
 
 
2555
                if (g_bNbAnalysis)
 
2556
                {
 
2557
                        try { o->m_pNbAnalysis = new CNbAnalysis();  } catch(...) { o->m_pNbAnalysis = NULL; }
 
2558
                        if (o->m_pNbAnalysis == NULL) NewException((double)sizeof(CNbAnalysis),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2559
                        
 
2560
                        o->m_pNbAnalysis->m_iShowMol = o->m_iShowMol;
 
2561
                        o->m_pNbAnalysis->Parse();
 
2562
                }
 
2563
 
 
2564
                try { o->m_pRDF = new CRDF*[g_iCDFChannels];  } catch(...) { o->m_pRDF = NULL; }
 
2565
                if (o->m_pRDF == NULL) NewException((double)g_iCDFChannels*sizeof(CRDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2566
                
 
2567
                try { o->m_pADF = new CADF*[g_iCDFChannels];  } catch(...) { o->m_pADF = NULL; }
 
2568
                if (o->m_pADF == NULL) NewException((double)g_iCDFChannels*sizeof(CADF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2569
                
 
2570
                try { o->m_pDDF = new CDDF*[g_iCDFChannels];  } catch(...) { o->m_pDDF = NULL; }
 
2571
                if (o->m_pDDF == NULL) NewException((double)g_iCDFChannels*sizeof(CDDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2572
                
 
2573
                try { o->m_pDipDF = new CDipDF*[g_iCDFChannels];  } catch(...) { o->m_pDipDF = NULL; }
 
2574
                if (o->m_pDipDF == NULL) NewException((double)g_iCDFChannels*sizeof(CDipDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2575
                
 
2576
                try { o->m_pVDF = new CVDF*[g_iCDFChannels];  } catch(...) { o->m_pVDF = NULL; }
 
2577
                if (o->m_pVDF == NULL) NewException((double)g_iCDFChannels*sizeof(CVDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2578
 
 
2579
                try { o->m_pPlDF = new CPlDF*[g_iCDFChannels];  } catch(...) { o->m_pPlDF = NULL; }
 
2580
                if (o->m_pPlDF == NULL) NewException((double)g_iCDFChannels*sizeof(CVDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2581
 
 
2582
                try { o->m_pLiDF = new CLiDF*[g_iCDFChannels];  } catch(...) { o->m_pLiDF = NULL; }
 
2583
                if (o->m_pLiDF == NULL) NewException((double)g_iCDFChannels*sizeof(CVDF*),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2584
 
 
2585
                for (z=0;z<g_iCDFChannels;z++)
 
2586
                {
 
2587
                        o->m_pRDF[z] = NULL;
 
2588
                        o->m_pADF[z] = NULL;
 
2589
                        o->m_pDDF[z] = NULL;
 
2590
                        o->m_pDipDF[z] = NULL;
 
2591
                        o->m_pVDF[z] = NULL;
 
2592
                        o->m_pPlDF[z] = NULL;
 
2593
                        o->m_pLiDF[z] = NULL;
 
2594
                }
 
2595
 
 
2596
                if (g_bCDF)
 
2597
                {
 
2598
                        try { o->m_pCDF = new CCDF();  } catch(...) { o->m_pCDF = NULL; }
 
2599
                        if (o->m_pCDF == NULL) NewException((double)sizeof(CCDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2600
                        
 
2601
                        try { o->m_pCDF->m_iCombinations = new int[g_iCDFChannels];  } catch(...) { o->m_pCDF->m_iCombinations = NULL; }
 
2602
                        if (o->m_pCDF->m_iCombinations == NULL) NewException((double)g_iCDFChannels*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2603
                        
 
2604
                        mprintf(BLUE,"\n>>> Combined Distribution Function >>>\n");
 
2605
//                      o->m_pCDF->m_bChannelAll = new bool[g_iCDFChannels];
 
2606
                        o->m_pCDF->m_iCombinationProd = 1;
 
2607
                        for (z=0;z<g_iCDFChannels;z++)
 
2608
                        {
 
2609
                                mprintf(BLUE,"\n### Channel %d ###\n",z+1);
 
2610
                                switch(g_iObsChannel[z])
 
2611
                                {
 
2612
                                        case 0:
 
2613
                                                try { o->m_pRDF[z] = new CRDF(); } catch(...) { o->m_pRDF[z] = NULL; }
 
2614
                                                if (o->m_pRDF[z] == NULL) NewException((double)sizeof(CRDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2615
                                                
 
2616
                                                if (o->m_bSecondShowMol && (z == 1))
 
2617
                                                        o->m_pRDF[z]->m_iShowMol = o->m_iShowMol2;
 
2618
                                                                else o->m_pRDF[z]->m_iShowMol = o->m_iShowMol;
 
2619
                                                o->m_pRDF[z]->Parse();
 
2620
                                                o->m_pCDF->m_iCombinations[z] = o->m_pRDF[z]->m_iCombinations;
 
2621
                                                o->m_pCDF->m_iCombinationProd *= o->m_pRDF[z]->m_iCombinations;
 
2622
/*                                              if (o->m_pRDF[z]->m_bSaveDist)
 
2623
                                                        o->m_bTimeDev = true;*/
 
2624
                                                break;
 
2625
 
 
2626
                                        case 1:
 
2627
                                                try { o->m_pADF[z] = new CADF(); } catch(...) { o->m_pADF[z] = NULL; }
 
2628
                                                if (o->m_pADF[z] == NULL) NewException((double)sizeof(CADF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2629
                                                
 
2630
                                                if (o->m_bSecondShowMol && (z == 1))
 
2631
                                                        o->m_pADF[z]->m_iShowMol = o->m_iShowMol2;
 
2632
                                                                else o->m_pADF[z]->m_iShowMol = o->m_iShowMol;
 
2633
                                                o->m_pADF[z]->Parse();
 
2634
                                                o->m_pCDF->m_iCombinations[z] = o->m_pADF[z]->m_iCombinations;
 
2635
                                                o->m_pCDF->m_iCombinationProd *= o->m_pADF[z]->m_iCombinations;
 
2636
/*                                              if (o->m_pADF[z]->m_bSaveAngle)
 
2637
                                                        o->m_bTimeDev = true;*/
 
2638
                                                break;
 
2639
 
 
2640
                                        case 2:
 
2641
                                                try { o->m_pDDF[z] = new CDDF(); } catch(...) { o->m_pDDF[z] = NULL; }
 
2642
                                                if (o->m_pDDF[z] == NULL) NewException((double)sizeof(CDDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2643
                                                
 
2644
                                                if (o->m_bSecondShowMol && (z == 1))
 
2645
                                                        o->m_pDDF[z]->m_iShowMol = o->m_iShowMol2;
 
2646
                                                                else o->m_pDDF[z]->m_iShowMol = o->m_iShowMol;
 
2647
                                                o->m_pDDF[z]->Parse();
 
2648
                                                o->m_pCDF->m_iCombinations[z] = o->m_pDDF[z]->m_iCombinations;
 
2649
                                                o->m_pCDF->m_iCombinationProd *= o->m_pDDF[z]->m_iCombinations;
 
2650
/*                                              if (o->m_pDDF[z]->m_bSaveAngle)
 
2651
                                                        o->m_bTimeDev = true;*/
 
2652
                                                break;
 
2653
 
 
2654
                                        case 3:
 
2655
                                                try { o->m_pDipDF[z] = new CDipDF(); } catch(...) { o->m_pDipDF[z] = NULL; }
 
2656
                                                if (o->m_pDipDF[z] == NULL) NewException((double)sizeof(CDipDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2657
                                                
 
2658
                                                if (o->m_bSecondShowMol && (z == 1))
 
2659
                                                        o->m_pDipDF[z]->m_iShowMol = o->m_iShowMol2;
 
2660
                                                                else o->m_pDipDF[z]->m_iShowMol = o->m_iShowMol;
 
2661
                                                o->m_pDipDF[z]->m_iCombinations = 1;
 
2662
                                                o->m_pDipDF[z]->Parse();
 
2663
                                                o->m_pCDF->m_iCombinations[z] = 1;
 
2664
/*                                              if (o->m_pDipDF[z]->m_bSaveDipole)
 
2665
                                                        o->m_bTimeDev = true;*/
 
2666
                                                break;
 
2667
 
 
2668
                                        case 4:
 
2669
                                                try { o->m_pVDF[z] = new CVDF(); } catch(...) { o->m_pVDF[z] = NULL; }
 
2670
                                                if (o->m_pVDF[z] == NULL) NewException((double)sizeof(CVDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2671
                                                 
 
2672
                                                if (o->m_bSecondShowMol && (z == 1))
 
2673
                                                        o->m_pVDF[z]->m_iShowMol = o->m_iShowMol2;
 
2674
                                                                else o->m_pVDF[z]->m_iShowMol = o->m_iShowMol;
 
2675
                                                o->m_pVDF[z]->Parse();
 
2676
                                                o->m_pCDF->m_iCombinations[z] = o->m_pVDF[z]->m_iCombinations;
 
2677
                                                o->m_pCDF->m_iCombinationProd *= o->m_pVDF[z]->m_iCombinations;
 
2678
                                                g_bUseVelocities = true;
 
2679
/*                                              if (o->m_pVDF[z]->m_bSaveSpeed)
 
2680
                                                        o->m_bTimeDev = true;*/
 
2681
                                                break;
 
2682
 
 
2683
                                        case 5:
 
2684
                                                try { o->m_pPlDF[z] = new CPlDF(); } catch(...) { o->m_pPlDF[z] = NULL; }
 
2685
                                                if (o->m_pPlDF[z] == NULL) NewException((double)sizeof(CPlDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2686
                                                
 
2687
                                                if (o->m_bSecondShowMol && (z == 1))
 
2688
                                                        o->m_pPlDF[z]->m_iShowMol = o->m_iShowMol2;
 
2689
                                                                else o->m_pPlDF[z]->m_iShowMol = o->m_iShowMol;
 
2690
                                                o->m_pPlDF[z]->Parse();
 
2691
                                                o->m_pCDF->m_iCombinations[z] = o->m_pPlDF[z]->m_iCombinations;
 
2692
                                                o->m_pCDF->m_iCombinationProd *= o->m_pPlDF[z]->m_iCombinations;
 
2693
                                                break;
 
2694
 
 
2695
                                        case 6:
 
2696
                                                try { o->m_pLiDF[z] = new CLiDF(); } catch(...) { o->m_pLiDF[z] = NULL; }
 
2697
                                                if (o->m_pLiDF[z] == NULL) NewException((double)sizeof(CLiDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2698
                                                
 
2699
                                                if (o->m_bSecondShowMol && (z == 1))
 
2700
                                                        o->m_pLiDF[z]->m_iShowMol = o->m_iShowMol2;
 
2701
                                                                else o->m_pLiDF[z]->m_iShowMol = o->m_iShowMol;
 
2702
                                                o->m_pLiDF[z]->Parse();
 
2703
                                                o->m_pCDF->m_iCombinations[z] = o->m_pLiDF[z]->m_iCombinations;
 
2704
                                                o->m_pCDF->m_iCombinationProd *= o->m_pLiDF[z]->m_iCombinations;
 
2705
                                                break;
 
2706
                                }
 
2707
/*                              if (z != 0)
 
2708
                                        o->m_pCDF->m_bChannelAll[z] = AskYesNo("    Should this CDF Channel observe all OMs (y) or only the current one (n)? [no] ",false);
 
2709
                                                else o->m_pCDF->m_bChannelAll[z] = false;*/
 
2710
                        }
 
2711
/*                      mprintf("    Write out temporal development for this CDF (1=yes,0=no)? [no] ");
 
2712
                        myget(buf);
 
2713
                        o->m_pCDF->m_bTimeDev = (atoi(buf)!=0);
 
2714
                        if (o->m_pCDF->m_bTimeDev)
 
2715
                                o->m_bTimeDev = true;*/
 
2716
 
 
2717
                        mprintf("\n");
 
2718
 
 
2719
                        try { o->m_pCDF->m_iResolution = new int[g_iCDFChannels]; } catch(...) { o->m_pCDF->m_iResolution = NULL; }
 
2720
                        if (o->m_pCDF->m_iResolution == NULL) NewException((double)g_iCDFChannels*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2721
                        
 
2722
                        for (z=0;z<g_iCDFChannels;z++)
 
2723
                        {
 
2724
                                switch(g_iObsChannel[z])
 
2725
                                {
 
2726
                                        case 0: sprintf(buf,"RDF"); break;
 
2727
                                        case 1: sprintf(buf,"ADF"); break;
 
2728
                                        case 2: sprintf(buf,"DDF"); break;
 
2729
                                        case 3: sprintf(buf,"DipDF"); break;
 
2730
                                        case 4: sprintf(buf,"VDF"); break;
 
2731
                                        case 5: sprintf(buf,"PlDF"); break;
 
2732
                                        case 6: sprintf(buf,"LiDF"); break;
 
2733
                                }
 
2734
                                o->m_pCDF->m_iResolution[z] = AskUnsignedInteger("    Please enter the resolution (bin count) for CDF channel %d (%s): [100] ",100,z+1,buf);
 
2735
                        }
 
2736
 
 
2737
                        if (g_bAdvanced2)
 
2738
                                o->m_pCDF->m_iHistogramRes = AskUnsignedInteger("    Please enter CDF histogram resolution (0=no histogram): [5000] ",5000);
 
2739
                                        else o->m_pCDF->m_iHistogramRes = 0;
 
2740
 
 
2741
                        if (g_iCDFChannels == 2)
 
2742
                        {
 
2743
                                try { o->m_pCDF->m_pCombineList = new char[o->m_pCDF->m_iCombinationProd]; } catch(...) { o->m_pCDF->m_pCombineList = NULL; }
 
2744
                                if (o->m_pCDF->m_pCombineList == NULL) NewException((double)o->m_pCDF->m_iCombinationProd*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2745
                                
 
2746
                                if ((o->m_pCDF->m_iCombinations[0] > 1) && (o->m_pCDF->m_iCombinations[1] > 1))
 
2747
                                {
 
2748
                                        mprintf("\n");
 
2749
                                        for (z=0;z<g_iCDFChannels;z++)
 
2750
                                        {
 
2751
                                                mprintf(WHITE,"CDF channel %d has the following %d observations:\n",z+1,o->m_pCDF->m_iCombinations[z]);
 
2752
                                                o->ListCDFObservations(z);
 
2753
                                                mprintf("\n");
 
2754
                                        }
 
2755
                                        if (o->m_pCDF->m_iCombinations[0] == o->m_pCDF->m_iCombinations[1])
 
2756
                                        {
 
2757
                                                if (AskYesNo("    Combine n-th with n-th observation? (y/n) [yes] ",true))
 
2758
                                                {
 
2759
                                                        for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
 
2760
                                                                for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
 
2761
                                                                        o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]+z2] = (z==z2)?1:0;
 
2762
                                                        goto _combdone;
 
2763
                                                } goto _askcomball;
 
2764
                                        } else
 
2765
                                        {
 
2766
_askcomball:
 
2767
                                                if (!AskYesNo("    Combine each with each observation (y), or use only some combinations (n)? [yes] ",true))
 
2768
                                                {
 
2769
                                                        for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
 
2770
                                                                for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
 
2771
                                                                        o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]+z2] = 0;
 
2772
 
 
2773
                                                        mprintf("\n    Please enter all the combinations you want to observe.\n");
 
2774
                                                        mprintf("    Enter each combination as a comma-separated %d-tuple (e.g. ",g_iCDFChannels);
 
2775
                                                        for (z=0;z<g_iCDFChannels;z++)
 
2776
                                                        {
 
2777
                                                                mprintf("%d",z+1);
 
2778
                                                                if (z+1 < g_iCDFChannels)
 
2779
                                                                        mprintf(",");
 
2780
                                                        }
 
2781
                                                        mprintf(").\n\n");
 
2782
_nextcomb:
 
2783
                                                        AskString("    Enter combination (return=finished): ",buf,"");
 
2784
                                                        if (strlen(buf)==0)
 
2785
                                                                goto _combdone;
 
2786
                                                        tempwa.RemoveAll_KeepSize();
 
2787
                                                        ParseIntList(buf,&tempwa);
 
2788
                                                        if (tempwa.GetSize() != g_iCDFChannels)
 
2789
                                                        {
 
2790
                                                                eprintf("    Wrong input, %d instead of %d values.\n",tempwa.GetSize(),g_iCDFChannels);
 
2791
                                                                goto _nextcomb;
 
2792
                                                        }
 
2793
                                                        for (z=0;z<g_iCDFChannels;z++)
 
2794
                                                        {
 
2795
                                                                if ((tempwa[z] < 1) || (tempwa[z] > o->m_pCDF->m_iCombinations[z]))
 
2796
                                                                {
 
2797
                                                                        eprintf("    Wrong input, channel %d has only %d observations (%d requested).\n",z+1,o->m_pCDF->m_iCombinations[z],tempwa[z]);
 
2798
                                                                        goto _nextcomb;
 
2799
                                                                }
 
2800
                                                                tempwa[z]--;
 
2801
                                                        }
 
2802
                                                        if (o->m_pCDF->m_pCombineList[tempwa[0]*o->m_pCDF->m_iCombinations[1]+tempwa[1]] == 1)
 
2803
                                                        {
 
2804
                                                                eprintf("    This combination has already been added.\n");
 
2805
                                                                goto _nextcomb;
 
2806
                                                        }
 
2807
                                                        o->m_pCDF->m_pCombineList[tempwa[0]*o->m_pCDF->m_iCombinations[1]+tempwa[1]] = 1;
 
2808
                                                        goto _nextcomb;
 
2809
                                                } else goto _combineall;
 
2810
_combdone:;
 
2811
                                        }
 
2812
                                } else
 
2813
                                {
 
2814
_combineall:
 
2815
                                        for (z=0;z<o->m_pCDF->m_iCombinationProd;z++)
 
2816
                                                o->m_pCDF->m_pCombineList[z] = 1;
 
2817
                                }
 
2818
 
 
2819
                                o->m_pCDF->m_iCombinationsEnabled = 0;
 
2820
                                for (z=0;z<o->m_pCDF->m_iCombinationProd;z++)
 
2821
                                        if (o->m_pCDF->m_pCombineList[z] != 0)
 
2822
                                                o->m_pCDF->m_iCombinationsEnabled++;
 
2823
 
 
2824
                                if (o->m_pCDF->m_iCombinationsEnabled == 1)
 
2825
                                {
 
2826
                                        mprintf(WHITE,"\n    Using 1 combination for each RM-OM pair.\n\n");
 
2827
                                } else
 
2828
                                {
 
2829
                                        mprintf(WHITE,"\n    Using %d combinations for each RM-OM pair:\n\n",o->m_pCDF->m_iCombinationsEnabled);
 
2830
                                        z3 = 0;
 
2831
                                        for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
 
2832
                                        {
 
2833
                                                for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
 
2834
                                                {
 
2835
                                                        if (o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]+z2] == 1)
 
2836
                                                        {
 
2837
                                                                mprintf("      %2d.) %2d - %2d\n",z3+1,z+1,z2+1);
 
2838
                                                                z3++;
 
2839
                                                        }
 
2840
                                                }
 
2841
                                        }
 
2842
                                        mprintf("\n");
 
2843
                                }
 
2844
 
 
2845
                                if (g_bAdvanced2)
 
2846
                                {
 
2847
                                        o->m_pCDF->m_bAxisDivide = AskYesNo("    Write out +/- correlation plot for this CDF (y/n)? [no] ",false);
 
2848
 
 
2849
                                        if (o->m_pCDF->m_bAxisDivide)
 
2850
                                                o->m_pCDF->m_bAxisDivideAll = AskYesNo("    Also write tensor product and axis projection quotients (y/n)? [no] ",false);
 
2851
                                } else
 
2852
                                {
 
2853
                                        o->m_pCDF->m_bAxisDivide = false;
 
2854
                                        o->m_pCDF->m_bAxisDivideAll = false;
 
2855
                                }
 
2856
 
 
2857
                                if (g_bAdvanced2)
 
2858
                                {
 
2859
                                        o->m_pCDF->m_bGraceBunch = AskYesNo("    Write out grace stack (multiple 2D plots) for this CDF (y/n)? [no] ",false);
 
2860
                                        if (o->m_pCDF->m_bGraceBunch)
 
2861
                                        {
 
2862
                                                o->m_pCDF->m_iGraceBunchC1 = AskUnsignedInteger("    How many graphs do you want do draw in the channel 1 grace stack (0=disable)? [10] ",10);
 
2863
                                                o->m_pCDF->m_iGraceBunchC2 = AskUnsignedInteger("    How many graphs do you want do draw in the channel 2 grace stack (0=disable)? [10] ",10);
 
2864
                                        }
 
2865
                                } else o->m_pCDF->m_bGraceBunch = false;
 
2866
                        }
 
2867
 
 
2868
                        if (g_iCDFChannels == 3)
 
2869
                        {
 
2870
                                mprintf("\n");
 
2871
 
 
2872
                                try { o->m_pCDF->m_pCombineList = new char[o->m_pCDF->m_iCombinationProd]; } catch(...) { o->m_pCDF->m_pCombineList = NULL; }
 
2873
                                if (o->m_pCDF->m_pCombineList == NULL) NewException((double)o->m_pCDF->m_iCombinationProd*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2874
                                
 
2875
                                if ((o->m_pCDF->m_iCombinations[0] > 1) || (o->m_pCDF->m_iCombinations[1] > 1) || (o->m_pCDF->m_iCombinations[2] > 1))
 
2876
                                {
 
2877
                                        for (z=0;z<g_iCDFChannels;z++)
 
2878
                                        {
 
2879
                                                mprintf(WHITE,"CDF channel %d has the following %d observations:\n",z+1,o->m_pCDF->m_iCombinations[z]);
 
2880
                                                o->ListCDFObservations(z);
 
2881
                                                mprintf("\n");
 
2882
                                        }
 
2883
                                        if (!AskYesNo("    Combine each with each observation (y), or use only some combinations (n)? [yes] ",true))
 
2884
                                        {
 
2885
                                                for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
 
2886
                                                        for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
 
2887
                                                                for (z3=0;z3<o->m_pCDF->m_iCombinations[2];z3++)
 
2888
                                                                        o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]*o->m_pCDF->m_iCombinations[2]+z2*o->m_pCDF->m_iCombinations[2]+z3] = 0;
 
2889
 
 
2890
                                                mprintf("\n    Please enter all the combinations you want to observe.\n");
 
2891
                                                mprintf("    Enter each combination as a comma-separated %d-tuple (e.g. ",g_iCDFChannels);
 
2892
                                                for (z=0;z<g_iCDFChannels;z++)
 
2893
                                                {
 
2894
                                                        mprintf("%d",z+1);
 
2895
                                                        if (z+1 < g_iCDFChannels)
 
2896
                                                                mprintf(",");
 
2897
                                                }
 
2898
                                                mprintf(").\n\n");
 
2899
_3nextcomb:
 
2900
                                                AskString("    Enter combination (return=finished): ",buf,"");
 
2901
                                                if (strlen(buf)==0)
 
2902
                                                        goto _3combdone;
 
2903
                                                tempwa.RemoveAll_KeepSize();
 
2904
                                                ParseIntList(buf,&tempwa);
 
2905
                                                if (tempwa.GetSize() != g_iCDFChannels)
 
2906
                                                {
 
2907
                                                        eprintf("    Wrong input, %d instead of %d values.\n",tempwa.GetSize(),g_iCDFChannels);
 
2908
                                                        goto _3nextcomb;
 
2909
                                                }
 
2910
                                                for (z=0;z<g_iCDFChannels;z++)
 
2911
                                                {
 
2912
                                                        if ((tempwa[z] < 1) || (tempwa[z] > o->m_pCDF->m_iCombinations[z]))
 
2913
                                                        {
 
2914
                                                                eprintf("    Wrong input, channel %d has only %d observations (%d requested).\n",z+1,o->m_pCDF->m_iCombinations[z],tempwa[z]);
 
2915
                                                                goto _3nextcomb;
 
2916
                                                        }
 
2917
                                                        tempwa[z]--;
 
2918
                                                }
 
2919
                                                if (o->m_pCDF->m_pCombineList[tempwa[0]*o->m_pCDF->m_iCombinations[1]*o->m_pCDF->m_iCombinations[2]+tempwa[1]*o->m_pCDF->m_iCombinations[2]+tempwa[2]] == 1)
 
2920
                                                {
 
2921
                                                        eprintf("    This combination has already been added.\n");
 
2922
                                                        goto _3nextcomb;
 
2923
                                                }
 
2924
                                                o->m_pCDF->m_pCombineList[tempwa[0]*o->m_pCDF->m_iCombinations[1]*o->m_pCDF->m_iCombinations[2]+tempwa[1]*o->m_pCDF->m_iCombinations[2]+tempwa[2]] = 1;
 
2925
                                                goto _3nextcomb;
 
2926
                                        } else goto _3combineall;
 
2927
                                } else
 
2928
                                {
 
2929
_3combineall:
 
2930
                                        for (z=0;z<o->m_pCDF->m_iCombinationProd;z++)
 
2931
                                                o->m_pCDF->m_pCombineList[z] = 1;
 
2932
                                }
 
2933
_3combdone:
 
2934
                                o->m_pCDF->m_iCombinationsEnabled = 0;
 
2935
                                for (z=0;z<o->m_pCDF->m_iCombinationProd;z++)
 
2936
                                        if (o->m_pCDF->m_pCombineList[z] != 0)
 
2937
                                                o->m_pCDF->m_iCombinationsEnabled++;
 
2938
 
 
2939
                                if (o->m_pCDF->m_iCombinationsEnabled == 1)
 
2940
                                {
 
2941
                                        mprintf(WHITE,"\n    Using 1 combination for each RM-OM pair.\n\n");
 
2942
                                } else
 
2943
                                {
 
2944
                                        mprintf(WHITE,"\n    Using %d combinations for each RM-OM pair:\n\n",o->m_pCDF->m_iCombinationsEnabled);
 
2945
                                        z4 = 0;
 
2946
                                        for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
 
2947
                                                for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
 
2948
                                                        for (z3=0;z3<o->m_pCDF->m_iCombinations[2];z3++)
 
2949
                                                                if (o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]*o->m_pCDF->m_iCombinations[2]+z2*o->m_pCDF->m_iCombinations[2]+z3] == 1)
 
2950
                                                                {
 
2951
                                                                        mprintf("      %2d.) %2d - %2d - %2d\n",z4+1,z+1,z2+1,z3+1);
 
2952
                                                                        z4++;
 
2953
                                                                }
 
2954
                                        mprintf("\n");
 
2955
                                }
 
2956
 
 
2957
                                if (g_bAdvanced2)
 
2958
                                {
 
2959
                                        o->m_pCDF->m_b3DSlices = AskYesNo("    Write out 2D slices for this CDF (y/n)? [no] ",false);
 
2960
 
 
2961
                                        if (o->m_pCDF->m_b3DSlices)
 
2962
                                                for (z=0;z<3;z++)
 
2963
                                                        o->m_pCDF->m_i3DSliceIntervals[z] = AskUnsignedInteger("    How many slice intervals to create along channel %d axis (0=skip)? [0] ",0,z+1);
 
2964
                                } else o->m_pCDF->m_b3DSlices = false;
 
2965
                        } // end if channels == 3
 
2966
 
 
2967
 
 
2968
                        if (g_bAdvanced2)
 
2969
                        {
 
2970
                                o->m_pCDF->m_bDumpDat = AskYesNo("    Write out input tuples (very large!) for this CDF (y/n)? [no] ",false);
 
2971
                                if ((g_iCDFChannels == 2) && (g_iObsChannel[0] == 0) && (g_iObsChannel[1] == 1))
 
2972
                                        o->m_pCDF->m_iNormalize = AskRangeInteger("    Normalize uniformly (3), data range (2), integral (1), or do not normalize (0)? [1] ",0,3,1);
 
2973
                                                else o->m_pCDF->m_iNormalize = AskRangeInteger("    Normalize data range (2), integral (1), or do not normalize (0)? [1] ",0,2,1);
 
2974
                                if (o->m_pCDF->m_iNormalize == 1)
 
2975
                                        o->m_pCDF->m_fNormValue = AskFloat("    Set CDF integral to which value? [1000000] ",1000000.0f);
 
2976
                                if (o->m_pCDF->m_iNormalize == 2)
 
2977
                                        o->m_pCDF->m_fNormValue = AskFloat("    Set maximum entry to which value? [100] ",100.0f);
 
2978
                        } else
 
2979
                        {
 
2980
                                o->m_pCDF->m_bDumpDat = false;
 
2981
                                o->m_pCDF->m_iNormalize = 1;
 
2982
                                o->m_pCDF->m_fNormValue = 1000000.0f;
 
2983
                        }
 
2984
 
 
2985
                        mprintf(BLUE,"\n<<< End of Combined Distribution Function <<<\n\n");
 
2986
                } else
 
2987
                {
 
2988
                        if (g_bRDF)
 
2989
                        {
 
2990
                                try { o->m_pRDF[0] = new CRDF(); } catch(...) { o->m_pRDF[0] = NULL; }
 
2991
                                if (o->m_pRDF[0] == NULL) NewException((double)sizeof(CRDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2992
                                 
 
2993
                                o->m_pRDF[0]->m_iShowMol = o->m_iShowMol;
 
2994
                                o->m_pRDF[0]->Parse();
 
2995
                                o->m_pRDF[0]->m_bSelf = o->m_bSelf;
 
2996
                        }
 
2997
                        if (g_bPlDF)
 
2998
                        {
 
2999
                                try { o->m_pPlDF[0] = new CPlDF(); } catch(...) { o->m_pPlDF[0] = NULL; }
 
3000
                                if (o->m_pPlDF[0] == NULL) NewException((double)sizeof(CPlDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3001
                                 
 
3002
                                o->m_pPlDF[0]->m_iShowMol = o->m_iShowMol;
 
3003
                                o->m_pPlDF[0]->Parse();
 
3004
                                o->m_pPlDF[0]->m_bSelf = o->m_bSelf;
 
3005
                        }
 
3006
                        if (g_bLiDF)
 
3007
                        {
 
3008
                                try { o->m_pLiDF[0] = new CLiDF(); } catch(...) { o->m_pLiDF[0] = NULL; }
 
3009
                                if (o->m_pLiDF[0] == NULL) NewException((double)sizeof(CLiDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3010
                                 
 
3011
                                o->m_pLiDF[0]->m_iShowMol = o->m_iShowMol;
 
3012
                                o->m_pLiDF[0]->Parse();
 
3013
                                o->m_pLiDF[0]->m_bSelf = o->m_bSelf;
 
3014
                        }
 
3015
                        if (g_bVHDF)
 
3016
                        {
 
3017
                                try { o->m_pVHDF = new CVHDF(); } catch(...) { o->m_pVHDF = NULL; }
 
3018
                                if (o->m_pVHDF == NULL) NewException((double)sizeof(CVHDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3019
                                 
 
3020
                                o->m_pVHDF->m_iShowMol = o->m_iShowMol;
 
3021
                                o->m_pVHDF->m_bSelf = o->m_bSelf;
 
3022
                                o->m_pVHDF->Parse();
 
3023
                        }
 
3024
                        if (g_bADF)
 
3025
                        {
 
3026
                                try { o->m_pADF[0] = new CADF(); } catch(...) { o->m_pADF[0] = NULL; }
 
3027
                                if (o->m_pADF[0] == NULL) NewException((double)sizeof(CADF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3028
                                 
 
3029
                                o->m_pADF[0]->m_iShowMol = o->m_iShowMol;
 
3030
                                o->m_pADF[0]->m_bSelf = o->m_bSelf;
 
3031
                                o->m_pADF[0]->Parse();
 
3032
                        }
 
3033
                        if (g_bDDF)
 
3034
                        {
 
3035
                                try { o->m_pDDF[0] = new CDDF(); } catch(...) { o->m_pDDF[0] = NULL; }
 
3036
                                if (o->m_pDDF[0] == NULL) NewException((double)sizeof(CDDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3037
                                 
 
3038
                                o->m_pDDF[0]->m_iShowMol = o->m_iShowMol;
 
3039
                                o->m_pDDF[0]->m_bSelf = o->m_bSelf;
 
3040
                                o->m_pDDF[0]->Parse();
 
3041
                        }
 
3042
                        if (g_bDipDF)
 
3043
                        {
 
3044
                                try { o->m_pDipDF[0] = new CDipDF(); } catch(...) { o->m_pDipDF[0] = NULL; }
 
3045
                                if (o->m_pDipDF[0] == NULL) NewException((double)sizeof(CDipDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3046
                                 
 
3047
                                o->m_pDipDF[0]->m_iShowMol = o->m_iShowMol;
 
3048
                                o->m_pDipDF[0]->m_bSelf = o->m_bSelf;
 
3049
                                o->m_pDipDF[0]->Parse();
 
3050
                        }
 
3051
                        if (g_bVDF)
 
3052
                        {
 
3053
                                try { o->m_pVDF[0] = new CVDF(); } catch(...) { o->m_pVDF[0] = NULL; }
 
3054
                                if (o->m_pVDF[0] == NULL) NewException((double)sizeof(CVDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3055
                                 
 
3056
                                o->m_pVDF[0]->m_iShowMol = o->m_iShowMol;
 
3057
                                o->m_pVDF[0]->m_bSelf = true;
 
3058
                                o->m_pVDF[0]->Parse();
 
3059
                                g_bUseVelocities = true;
 
3060
                        }
 
3061
                        if (g_bMSD)
 
3062
                        {
 
3063
                                try { o->m_pMSD = new CMSD(); } catch(...) { o->m_pMSD = NULL; }
 
3064
                                if (o->m_pMSD == NULL) NewException((double)sizeof(CMSD),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3065
                                 
 
3066
                                o->m_pMSD->m_iShowMol = o->m_iShowMol;
 
3067
                                o->m_pMSD->Parse();
 
3068
                        }
 
3069
                }
 
3070
 
 
3071
                if ((g_bCDF && (g_iCDFChannels == 2)) || g_bRDF || g_bADF || g_bVDF || g_bDDF || g_bDipDF)
 
3072
                {
 
3073
                        if (!o->m_bSecondShowMol)
 
3074
                        {
 
3075
                                if (AskYesNo("    Save temporal development for this observation (y/n)? [no] ",false))
 
3076
                                {
 
3077
                                        mprintf(WHITE,"\n>>> Save temporal development >>>\n\n");
 
3078
                                        o->m_bTimeDev = true;
 
3079
 
 
3080
                                        if (g_fTimestepLength == 0)
 
3081
                                        {
 
3082
                                                g_fTimestepLength = AskFloat("    Enter the length of one trajectory time step in fs: [0.5] ",0.5f);
 
3083
                                                mprintf("\n");
 
3084
                                        }
 
3085
 
 
3086
                                        if (g_bDDF && (!g_bCDF))
 
3087
                                        {
 
3088
                                                if ((o->m_pDDF[0]->m_iDeriv == 0) && (!o->m_pDDF[0]->m_bCosine) && (!o->m_pDDF[0]->m_bAbs) && (!o->m_pDDF[0]->m_bPositive))
 
3089
                                                {
 
3090
                                                        mprintf("\n    You can include full rotations into the DDF's temporal development.\n");
 
3091
                                                        mprintf("    This means, if a dihedral makes a full rotation, the value will be 360 deg insteat of 0 deg.\n");
 
3092
                                                        mprintf("    You may count the number of full rotations during simulation in this way.\n\n");
 
3093
                                                        o->m_pDDF[0]->m_bRotate = AskYesNo("    Include full rotations into the DDF's temporal development (y/n)? [no] ",false);
 
3094
                                                } else o->m_pDDF[0]->m_bRotate = false;
 
3095
                                                if (o->m_pDDF[0]->m_bRotate)
 
3096
                                                {
 
3097
                                                        mprintf(WHITE,"\n   Warning: ");
 
3098
                                                        mprintf("This only works if your trajectory time step is small enough to ensure\n");
 
3099
                                                        mprintf("             that the dihedral is never changing more than 180 deg within one step!\n\n");
 
3100
                                                }
 
3101
                                        }
 
3102
                                        if (g_bRDF || g_bADF || g_bVDF || g_bDDF || g_bDipDF)
 
3103
                                        {
 
3104
                                                if (AskYesNo("    Create combined development/histogram-plots for 2D analyses (y/n)? [yes] ",true))
 
3105
                                                {
 
3106
                                                        g_bCombined = true;
 
3107
                                                        o->m_bCombinedPlot = true;
 
3108
                                                        if (AskYesNo("    Use grey tones for combined plot (y) or standard colors (n)? [no] ",false))
 
3109
                                                        {
 
3110
                                                                o->m_bCombinedGreyMode = true;
 
3111
                                                                o->m_iCombinedGreyMin = AskRangeInteger("    Darkest shade of grey to use (0=black, 255=white)? [128] ",0,255,128);
 
3112
                                                                o->m_iCombinedGreyMax = AskRangeInteger("    Lightest shade of grey to use (0=black, 255=white)? [224] ",o->m_iCombinedGreyMin,255,224);
 
3113
                                                                o->m_iCombinedGreyShades = AskUnsignedInteger("    How many different shades of grey to use? [4] ",4);
 
3114
                                                        } else o->m_bCombinedGreyMode = false;
 
3115
                                                } else o->m_bCombinedPlot = false;
 
3116
                                        } else o->m_bCombinedPlot = false;
 
3117
 
 
3118
                                        if (((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize() > 1)
 
3119
                                        {
 
3120
                                                mprintf("    Save development for which rep. of the reference molecule (e.g. 1,3-7)? [1] ");
 
3121
                                                inpprintf("! Save development for which rep. of the reference molecule (e.g. 1,3-7)? [1]\n");
 
3122
                                                myget(buf);
 
3123
                                                if (strlen(buf)==0)
 
3124
                                                        o->m_waSaveRefList.Add(0);
 
3125
                                                else {
 
3126
                                                        ParseIntList(buf,&o->m_waSaveRefList);
 
3127
                                                        for (z=0;z<o->m_waSaveRefList.GetSize();z++)
 
3128
                                                                o->m_waSaveRefList[z]--;
 
3129
                                                }
 
3130
                                        } else o->m_waSaveRefList.Add(0);
 
3131
                                        if (o->m_iShowMol != -1)
 
3132
                                        {
 
3133
                                                if (((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize() > 1)
 
3134
                                                {
 
3135
                                                        mprintf("    Save development for which rep. of the observed molecule (e.g. 1,3-7)? [all] ");
 
3136
                                                        inpprintf("! Save development for which rep. of the observed molecule (e.g. 1,3-7)? [all]\n");
 
3137
                                                        myget(buf);
 
3138
                                                        if (strlen(buf)==0)
 
3139
                                                        {
 
3140
                                                                for (z=0;z<((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize();z++)
 
3141
                                                                        o->m_waSaveShowList.Add(z);
 
3142
                                                        } else
 
3143
                                                        {
 
3144
                                                                ParseIntList(buf,&o->m_waSaveShowList);
 
3145
                                                                for (z=0;z<o->m_waSaveShowList.GetSize();z++)
 
3146
                                                                        o->m_waSaveShowList[z]--;
 
3147
                                                        }
 
3148
                                                } else o->m_waSaveShowList.Add(0);
 
3149
                                        } else o->m_waSaveShowList.Add(0); // Dummy
 
3150
                                        if ((o->m_waSaveRefList.GetSize() > 1) && (o->m_bOthers))
 
3151
                                                o->m_bSaveSeparateFiles = AskYesNo("    Developments for different ref. molecules to same (n) or different (y) files? [yes] ",true);
 
3152
                                                        else o->m_bSaveSeparateFiles = false;
 
3153
                                        if ((g_bCDF) && (g_iCDFChannels == 2))
 
3154
                                        {
 
3155
                                                if (AskYesNo("    Generate time development animation (TDO) for CDF (y/n)? [no] ",false))
 
3156
                                                {
 
3157
                                                        o->m_pCDF->m_bTDAnimation = true;
 
3158
                                                        o->m_pCDF->m_iTDASteps = AskUnsignedInteger("    How many steps should the animation have? [1000] ",1000);
 
3159
                                                        o->m_pCDF->m_iTDAStride = AskUnsignedInteger("    Enter distance between the frames in timesteps: [100] ",50);
 
3160
                                                        o->m_pCDF->m_iTDATail = AskUnsignedInteger("    Enter length of the tail in timesteps: [100] ",100);
 
3161
                                                        o->m_pCDF->m_bTDATrace = AskYesNo("    Show trace (y/n)? [yes] ",true);
 
3162
                                                        o->m_pCDF->m_iTDAResX = AskUnsignedInteger("    Enter width (in pixel) of the TDA images: [640] ",640);
 
3163
                                                        o->m_pCDF->m_iTDAResY = AskUnsignedInteger("    Enter height (in pixel) of the TDA images: [480] ",480);
 
3164
                                                } else o->m_pCDF->m_bTDAnimation = false;
 
3165
                                        }
 
3166
                                        mprintf("\n    Saving temporal development for reference molecules ");
 
3167
                                        for (z=0;z<o->m_waSaveRefList.GetSize();z++)
 
3168
                                        {
 
3169
                                                if (z < (int)o->m_waSaveRefList.GetSize()-1)
 
3170
                                                {
 
3171
                                                        mprintf("%d, ",o->m_waSaveRefList[z]+1);
 
3172
                                                        if (((z+1) % 16) == 0)
 
3173
                                                                mprintf("\n      ");
 
3174
                                                } else mprintf("%d",o->m_waSaveRefList[z]+1);
 
3175
                                        }
 
3176
                                        if (o->m_bOthers)
 
3177
                                        {
 
3178
                                                mprintf("\n    and for observed molecules ");
 
3179
                                                for (z=0;z<o->m_waSaveShowList.GetSize();z++)
 
3180
                                                {
 
3181
                                                        if (z < (int)o->m_waSaveShowList.GetSize()-1)
 
3182
                                                        {
 
3183
                                                                mprintf("%d, ",o->m_waSaveShowList[z]+1);
 
3184
                                                                if (((z+1) % 16) == 0)
 
3185
                                                                        mprintf("\n      ");
 
3186
                                                        } else mprintf("%d",o->m_waSaveShowList[z]+1);
 
3187
                                                }
 
3188
                                        }
 
3189
                                        mprintf(".\n");
 
3190
                                        mprintf(WHITE,"\n<<< End of Save temporal development <<<\n\n");
 
3191
                                } else o->m_bTimeDev = false;
 
3192
 
 
3193
                                if (g_bAdvanced2)
 
3194
                                {
 
3195
                                        if (AskYesNo("    Create a temporal difference plot for this observation (y/n)? [no] ",false))
 
3196
                                        {
 
3197
                                                o->m_bTimeDiff = true;
 
3198
                                                g_bTimeDiff = true;
 
3199
                                                o->m_iTimeDiffDepth = AskUnsignedInteger("    Enter temporal depth of this plot in time steps: [1000] ",1000);
 
3200
                                                o->m_b3DTimeDiff = AskYesNo("    Create also 3D temporal difference plots (y/n)? [yes] ",true);
 
3201
                                                if (o->m_b3DTimeDiff)
 
3202
                                                {
 
3203
                                                        tf = 0;
 
3204
                                                        tf2 = 0;
 
3205
                                                        if (g_bRDF)
 
3206
                                                        {
 
3207
                                                                tf = o->m_pRDF[0]->m_fMinDist;
 
3208
                                                                tf2 = o->m_pRDF[0]->m_fMaxDist;
 
3209
                                                        }
 
3210
                                                        if (g_bADF)
 
3211
                                                        {
 
3212
                                                                tf = o->m_pADF[0]->m_fMinAngle;
 
3213
                                                                tf2 = o->m_pADF[0]->m_fMaxAngle;
 
3214
                                                        }
 
3215
                                                        if (g_bDDF)
 
3216
                                                        {
 
3217
                                                                tf = o->m_pDDF[0]->m_fMinAngle;
 
3218
                                                                tf2 = o->m_pDDF[0]->m_fMaxAngle;
 
3219
                                                        }
 
3220
                                                        if (g_bVDF)
 
3221
                                                        {
 
3222
                                                                tf = o->m_pVDF[0]->m_fMinSpeed;
 
3223
                                                                tf2 = o->m_pVDF[0]->m_fMaxSpeed;
 
3224
                                                        }
 
3225
                                                        if (g_bDipDF)
 
3226
                                                        {
 
3227
                                                                tf = o->m_pDipDF[0]->m_fDipoleMin;
 
3228
                                                                tf2 = o->m_pDipDF[0]->m_fDipoleMax;
 
3229
                                                        }
 
3230
                                                        o->m_iTimeDiffStride3D = AskUnsignedInteger("    Take every n-th time step for the tau axis: [%d] ",o->m_iTimeDiffDepth/100,o->m_iTimeDiffDepth/100);
 
3231
                                                        o->m_fTimeDiffMinVal3D = AskFloat("    Enter min. value for the starting point: [%.2f] ",tf,tf);
 
3232
                                                        o->m_fTimeDiffMaxVal3D = AskFloat("    Enter max. value for the starting point: [%.2f] ",tf2,tf2);
 
3233
                                                        o->m_iTimeDiffRes3D = AskUnsignedInteger("    Enter binning resolution for the starting value: [100] ",100);
 
3234
                                                        mprintf("\n    Temporal before/after 3D plot:\n");
 
3235
                                                        o->m_iTimeDiffDistSteps= AskUnsignedInteger("    Every how many time steps create a 2D slice (0 to disable): [0] ",0);
 
3236
                                                        o->m_fTimeDiffDistMinValX = AskFloat("    Enter min. value for the starting point: [%.2f] ",tf,tf);
 
3237
                                                        o->m_fTimeDiffDistMaxValX = AskFloat("    Enter max. value for the starting point: [%.2f] ",tf2,tf2);
 
3238
                                                        o->m_iTimeDiffDistResX = AskUnsignedInteger("    Enter binning resolution for the X axis: [100] ",100);
 
3239
                                                        o->m_fTimeDiffDistMinValY = AskFloat("    Enter min. value for the end point: [%.2f] ",tf,tf);
 
3240
                                                        o->m_fTimeDiffDistMaxValY = AskFloat("    Enter max. value for the end point: [%.2f] ",tf2,tf2);
 
3241
                                                        o->m_iTimeDiffDistResY = AskUnsignedInteger("    Enter binning resolution for the Y axis: [100] ",100);
 
3242
                                                }
 
3243
                                                mprintf("\n");
 
3244
                                        } else o->m_bTimeDiff = false;
 
3245
                                } else o->m_bTimeDiff = false;
 
3246
                        } else
 
3247
                        {
 
3248
                                o->m_bTimeDev = false;
 
3249
                                o->m_bTimeDiff = false;
 
3250
                        }
 
3251
                } else
 
3252
                {
 
3253
                        o->m_bTimeDev = false;
 
3254
                        o->m_bTimeDiff = false;
 
3255
                }
 
3256
 
 
3257
                if ((g_iFixMol != -1) && (o->m_iShowMol != -1) && (g_bRDyn || g_bDipDF || g_bMSD || g_bADF || g_bPlDF || g_bLiDF || g_bDDF || g_bVACF || g_bDipACF ||g_bRevSDF || g_bSDF || g_bPlProj || g_bVHDF || g_bRDF || g_bVDF || g_bFDF || g_bCond))
 
3258
                {
 
3259
                        if (g_bCond)
 
3260
                                goto _askcond;
 
3261
                        if (AskYesNo("    Add a condition to this observation (y/n)? [no] ",false))
 
3262
                        {
 
3263
_askcond:
 
3264
                                mprintf(GREEN,"\n>>> Condition input >>>\n\n");
 
3265
//                              mprintf("You may enter several sets of conditions. They are connected with \"or\",\nonly one of them needs to apply to take a configuration into account.\n\n");
 
3266
//                              mprintf("In each set of conditions, you may enter several conditions. They are connected\nwith \"and\", all of them have to apply to make this set of conditions apply.\n");
 
3267
 
 
3268
                                if (o->m_bSecondShowMol)
 
3269
                                {
 
3270
                                        if (!AskYesNo("    Add a condition between RM and 1st OM (y/n)? [yes] ",true))
 
3271
                                                goto _no1stcond;
 
3272
                                        mprintf(WHITE,"\n    *** Input of Condition between RM and 1st OM ***\n\n");
 
3273
                                }
 
3274
 
 
3275
                                try { o->m_pConditions = new CConditionGroup(); } catch(...) { o->m_pConditions = NULL; }
 
3276
                                if (o->m_pConditions == NULL) NewException((double)sizeof(CConditionGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3277
                                
 
3278
                                o->m_pConditions->m_iShowMol = o->m_iShowMol;
 
3279
                                o->m_pConditions->Parse(g_iFixMol,o->m_iShowMol);
 
3280
_no1stcond:
 
3281
 
 
3282
                                if (o->m_bSecondShowMol)
 
3283
                                {
 
3284
                                        mprintf("\n");
 
3285
                                        if (!AskYesNo("    Add a condition between RM and 2nd OM (y/n)? [yes] ",true))
 
3286
                                                goto _no2ndcond;
 
3287
                                        mprintf(WHITE,"\n    *** Input of Condition between RM and 2nd OM ***\n\n");
 
3288
 
 
3289
                                        try { o->m_pConditionsOM2 = new CConditionGroup(); } catch(...) { o->m_pConditionsOM2 = NULL; }
 
3290
                                        if (o->m_pConditionsOM2 == NULL) NewException((double)sizeof(CConditionGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3291
                                        
 
3292
                                        o->m_pConditionsOM2->m_iShowMol = o->m_iShowMol2;
 
3293
                                        o->m_pConditionsOM2->Parse(g_iFixMol,o->m_iShowMol2);
 
3294
_no2ndcond:;
 
3295
                                }
 
3296
 
 
3297
                                if (o->m_pConditions != NULL)
 
3298
                                {
 
3299
                                        if (o->m_pConditions->m_bInvertCondition)
 
3300
                                        {
 
3301
                                                o->m_bBinOnlyNotPassedAtoms = false;
 
3302
                                                o->m_bBinOnlyPassedAtoms = false;
 
3303
                                                goto _nobinonly;
 
3304
                                        }
 
3305
                                }
 
3306
 
 
3307
                                if (o->m_pConditionsOM2 != NULL)
 
3308
                                {
 
3309
                                        if (o->m_pConditionsOM2->m_bInvertCondition)
 
3310
                                        {
 
3311
                                                o->m_bBinOnlyNotPassedAtoms = false;
 
3312
                                                o->m_bBinOnlyPassedAtoms = false;
 
3313
                                                goto _nobinonly;
 
3314
                                        }
 
3315
                                }
 
3316
 
 
3317
                                mprintf("\n    Normally, TRAVIS evaluates the condition for each RM-OM pair. If the condition\n");
 
3318
                                mprintf("    is fulfilled, all atoms from this pair are evaluated. The following question\n");
 
3319
                                mprintf("    enables to take into account only exactly the atoms which fulfilled the condition.\n\n");
 
3320
 
 
3321
                                mprintf("    If you have a distance condition with \"nearest neighbor mode\", only the atom\n");
 
3322
                                mprintf("    from the OM that is closest to the RM will be taken into account.\n\n");
 
3323
 
 
3324
                                o->m_bBinOnlyPassedAtoms = AskYesNo("    Add only atoms to the bin that passed the condition(s) (y/n)? [no] ",false);
 
3325
/*                              if (!o->m_bBinOnlyPassedAtoms)
 
3326
                                        o->m_bBinOnlyNotPassedAtoms = AskYesNo("    Add only atoms to the bin that did NOT pass the condition(s) (y/n)? [no] ",false);
 
3327
                                                else*/ o->m_bBinOnlyNotPassedAtoms = false;
 
3328
_nobinonly:
 
3329
 
 
3330
                                g_bSaveCondSnapshot = AskYesNo("    Save a snapshot every time the conditions are fulfilled (y/n)? [no] ",false);
 
3331
                                
 
3332
                                if (g_bSaveCondSnapshot)
 
3333
                                        g_bNeedMoleculeWrap = true;
 
3334
 
 
3335
                                if (g_bSaveCondSnapshot)
 
3336
                                {
 
3337
                                        g_bSaveCondWholeBox = AskYesNo("    Save the whole box (y) or only the RM/OM pair (n)? [no] ",false);
 
3338
                                        if (g_bSaveCondWholeBox)
 
3339
                                                mprintf("\n    The RM that fulfills the condition will be centered (coordinates 0|0|0).\n");
 
3340
                                }
 
3341
 
 
3342
                                mprintf(GREEN,"\n<<< End of Condition input <<<\n\n");
 
3343
                        }
 
3344
                }
 
3345
 
 
3346
                if (g_bVACF)
 
3347
                {
 
3348
                        mprintf(WHITE,"\n>>> Velocity autocorrelation function >>>\n\n");
 
3349
 
 
3350
                        try { o->m_pVACF = new CACF(); } catch(...) { o->m_pVACF = NULL; }
 
3351
                        if (o->m_pVACF == NULL) NewException((double)sizeof(CACF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3352
                        
 
3353
                        o->m_pVACF->m_iShowMol = o->m_iShowMol;
 
3354
                        o->m_pVACF->Parse();
 
3355
                        mprintf(WHITE,"\n<< End of Velocity autocorrelation function <<<\n\n");
 
3356
                }
 
3357
 
 
3358
/*              if (g_bDipACF)
 
3359
                {
 
3360
                        mprintf(WHITE,"\n>>> Dipole moment autocorrelation function >>>\n\n");
 
3361
 
 
3362
                        try { o->m_pDipACF = new CACF(); } catch(...) { o->m_pDipACF = NULL; }
 
3363
                        if (o->m_pDipACF == NULL) NewException((double)sizeof(CACF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3364
                        
 
3365
                        o->m_pDipACF->Parse();
 
3366
                        mprintf(WHITE,"\n<<< End of Dipole moment autocorrelation function <<<\n\n");
 
3367
                }*/
 
3368
 
 
3369
                if (g_bUseVelocities)
 
3370
                {
 
3371
                        if (g_iFixMol != -1)
 
3372
                                o->m_bVelocityRelToRef = (AskRangeInteger("    Use absolute velocities (0) or relative to the reference molecule (1)? [0] ",0,1,0) != 0);
 
3373
                                        else o->m_bVelocityRelToRef = false;
 
3374
                }
 
3375
 
 
3376
                mprintf(YELLOW,"\n<<< End of Observation %d <<<\n",g_oaObserv.GetSize());
 
3377
 
 
3378
                if (AskYesNo("\n    Add another observation (y/n)? [no] ",false))
 
3379
                        goto _nextsdf;
 
3380
                mprintf("\n");
 
3381
 
 
3382
                mprintf(WHITE,">>> Observation List >>>\n\n");
 
3383
                for (z2=0;z2<g_oaObserv.GetSize();z2++)
 
3384
                {
 
3385
                        mprintf(YELLOW,"  *** Observation %d\n",z2+1);
 
3386
                        o = (CObservation*)g_oaObserv[z2];
 
3387
 
 
3388
                        if (g_bCond)
 
3389
                                mprintf("    - Condition between %s and %s\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
 
3390
 
 
3391
                        if (g_bAggregation)
 
3392
                        {
 
3393
                                mprintf("    - Aggregation functions - %d value sets:\n",o->m_pDACF->m_oaSubDACFs.GetSize());
 
3394
                                for (z3=0;z3<o->m_pDACF->m_oaSubDACFs.GetSize();z3++)
 
3395
                                        mprintf("      > %s\n",((CDACFSub*)o->m_pDACF->m_oaSubDACFs[z3])->m_sName);
 
3396
                        }
 
3397
 
 
3398
                        if (g_bNbExchange)
 
3399
                        {
 
3400
                                mprintf("    - Neighborhood exchange functions:\n");
 
3401
                                for (z3=0;z3<o->m_pDACF->m_oaSubDACFs.GetSize();z3++)
 
3402
                                        mprintf("      > %s\n",((CDACFSub*)o->m_pDACF->m_oaSubDACFs[z3])->m_sName);
 
3403
                        }
 
3404
 
 
3405
                        if (g_bRDyn)
 
3406
                                mprintf("    - Reorientation Dynamics: %s\n",o->m_pRDyn->m_sName);
 
3407
 
 
3408
                        if (g_bIRSpec)
 
3409
                                mprintf("    - IR Spectrum: %s\n",o->m_pIRSpec->m_sName);
 
3410
 
 
3411
                        if (g_bDens)
 
3412
                                mprintf("    - Density DF: %s\n",o->m_pDensityDF->m_sName);
 
3413
 
 
3414
                        if (g_bSDF)
 
3415
                                mprintf("    - SDF: %s\n",o->m_pSDF->m_sName);
 
3416
 
 
3417
                        if (g_bPlProj)
 
3418
                                mprintf("    - Plane Projection DF: %s\n",o->m_pPlProj->m_sName);
 
3419
 
 
3420
                        if (g_bRevSDF)
 
3421
                                mprintf("    - Pseudo SDF: %s\n",o->m_pRevSDF->m_sName);
 
3422
 
 
3423
                        if (g_bNbAnalysis)
 
3424
                                mprintf("    - Neighborhood Analysis: %s\n",o->m_pNbAnalysis->m_sName);
 
3425
 
 
3426
                        if (g_bVACF)
 
3427
                                mprintf("    - VACF: %s\n",o->m_pVACF->m_sName);
 
3428
 
 
3429
                        if (g_bMSD)
 
3430
                                mprintf("    - MSD: %s\n",o->m_pMSD->m_sName);
 
3431
 
 
3432
                        if (g_bVHDF)
 
3433
                                mprintf("    - VHDF: %s\n",o->m_pVHDF->m_sName);
 
3434
 
 
3435
                        if (g_bCDF)
 
3436
                        {
 
3437
                                mprintf("    - Combined Distribution Function:\n");
 
3438
                                for (z3=0;z3<g_iCDFChannels;z3++)
 
3439
                                {
 
3440
                                        if (o->m_pRDF[z3] != NULL)
 
3441
                                                mprintf("      - Channel %d: RDF: %s\n",z3+1,o->m_pRDF[z3]->m_sName);
 
3442
                                        if (o->m_pADF[z3] != NULL)
 
3443
                                                mprintf("      - Channel %d: ADF: %s\n",z3+1,o->m_pADF[z3]->m_sName);
 
3444
                                        if (o->m_pDDF[z3] != NULL)
 
3445
                                                mprintf("      - Channel %d: DDF: %s\n",z3+1,o->m_pDDF[z3]->m_sName);
 
3446
                                        if (o->m_pDipDF[z3] != NULL)
 
3447
                                                mprintf("      - Channel %d: DipDF: %s\n",z3+1,o->m_pDipDF[z3]->m_sName);
 
3448
                                        if (o->m_pVDF[z3] != NULL)
 
3449
                                                mprintf("      - Channel %d: VDF: %s\n",z3+1,o->m_pVDF[z3]->m_sName);
 
3450
                                        if (o->m_pPlDF[z3] != NULL)
 
3451
                                                mprintf("      - Channel %d: PlDF: %s\n",z3+1,o->m_pPlDF[z3]->m_sName);
 
3452
                                        if (o->m_pLiDF[z3] != NULL)
 
3453
                                                mprintf("      - Channel %d: LiDF: %s\n",z3+1,o->m_pLiDF[z3]->m_sName);
 
3454
                                }
 
3455
                        } else
 
3456
                        {
 
3457
                                if (g_bRDF)
 
3458
                                        mprintf("    - RDF: %s\n",o->m_pRDF[0]->m_sName);
 
3459
                                if (g_bDipDF)
 
3460
                                        mprintf("    - DipDF: %s\n",o->m_pDipDF[0]->m_sName);
 
3461
                                if (g_bADF)
 
3462
                                        mprintf("    - ADF: %s\n",o->m_pADF[0]->m_sName);
 
3463
                                if (g_bDDF)
 
3464
                                        mprintf("    - DDF: %s\n",o->m_pDDF[0]->m_sName);
 
3465
                                if (g_bVDF)
 
3466
                                        mprintf("    - VDF: %s\n",o->m_pVDF[0]->m_sName);
 
3467
                                if (g_bPlDF)
 
3468
                                        mprintf("    - PlDF: %s\n",o->m_pPlDF[0]->m_sName);
 
3469
                                if (g_bLiDF)
 
3470
                                        mprintf("    - LiDF: %s\n",o->m_pLiDF[0]->m_sName);
 
3471
                        }
 
3472
                }
 
3473
                mprintf(WHITE,"\n<<< End of Observation List <<<\n\n");
 
3474
        }
 
3475
_endobs:
 
3476
 
 
3477
        if (g_bVACF && g_bGlobalVACF)
 
3478
        {
 
3479
                try { g_pGlobalVACF = new CACF(); } catch(...) { g_pGlobalVACF = NULL; }
 
3480
                if (g_pGlobalVACF == NULL) NewException((double)sizeof(CACF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3481
                
 
3482
                mprintf(WHITE,"\n>>> Global velocity autocorrelation function >>>\n\n");
 
3483
                g_pGlobalVACF->Parse();
 
3484
                mprintf(WHITE,"\n<<< End of global velocity autocorrelation function <<<\n\n");
 
3485
        }
 
3486
 
 
3487
        if (g_bIRSpec && g_bGlobalIR)
 
3488
        {
 
3489
                try { g_pGlobalIR = new CReorDyn(); } catch(...) { g_pGlobalIR = NULL; }
 
3490
                if (g_pGlobalIR == NULL) NewException((double)sizeof(CReorDyn),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3491
                
 
3492
                mprintf(WHITE,"\n*** Definition of system-wide IR spectrum ***\n\n");
 
3493
                g_pGlobalIR->ParseSpec();
 
3494
        }
 
3495
 
 
3496
        if (g_bSDF || g_bVoidSDF || g_bCreateRevSDF)
 
3497
        {
 
3498
                g_iSDFSmoothGrade = AskInteger("    Up to which degree should the SDFs be smoothened (0=not at all)? [3] ",3);
 
3499
 
 
3500
                if (g_bSDF)
 
3501
                {
 
3502
_sdf_norm_again:
 
3503
                        g_bSDFUniform = AskYesNo("    Calculate SDF values in nm^-3 (n) or relative to uniform density (y)? [no] ",false);
 
3504
                        if (g_bSDFUniform && ((!g_bPeriodicX) || (!g_bPeriodicY) || (!g_bPeriodicZ)))
 
3505
                        {
 
3506
                                eprintf("\n    Error: Uniform particle density is only defined for XYZ-periodic systems.\n\n");
 
3507
                                goto _sdf_norm_again;
 
3508
                        }
 
3509
                }
 
3510
//                      g_iSDFScale = AskRangeInteger("    SDF values in ppm (1), pm^-3 (2), nm^-3 (3) or rel. to uniform density (4)? [4] ",1,4,4) - 1;
 
3511
//                      g_iSDFScale = 2; // nm^-3
 
3512
        } else if (g_bCDF && (g_iCDFChannels == 3))
 
3513
                g_iSDFSmoothGrade = AskInteger("    Up to which degree should the 3D CDFs be smoothened (0=not at all)? [3] ",3);
 
3514
 
 
3515
//      if (g_bVDF || g_bSVDF)
 
3516
//              g_bSaveVelForce = AskYesNo("    Save maximum/averaged velocity time development (y/n)? [yes] ",true);
 
3517
 
 
3518
//      if (g_bVDF || g_bFDF)
 
3519
//      {
 
3520
//              g_fVelPercentage = AskFloat("    Which percentage of all velocities/forces to take into account? [95] ",95.0f);
 
3521
//              g_fForcePercentage = g_fVelPercentage;
 
3522
//      }
 
3523
        g_bSaveVelForce = false;
 
3524
 
 
3525
        if ((g_bSDF && g_bAdvanced2) || g_bSaveRefEnv || g_bCutCluster || g_bSaveJustTraj)
 
3526
        {
 
3527
                mprintf(WHITE,"\n>>> Coordinate output options >>>\n\n");
 
3528
 
 
3529
                if ((g_bSDF && g_bAdvanced2) || g_bSaveRefEnv || g_bCutCluster)
 
3530
                {
 
3531
                        if (g_bAdvanced2)
 
3532
                                g_bWriteAtomwise = (AskRangeInteger("    Sort output coordinates by molecules (0) or by element types (1)? [molecules] ",0,1,0)!=0);
 
3533
                                        else g_bWriteAtomwise = false;
 
3534
                }
 
3535
 
 
3536
                g_bSaveVirtAtoms = AskYesNo("    Save also virtual atoms (y/n)? [no] ",false);
 
3537
 
 
3538
                if (g_bSaveVirtAtoms)
 
3539
                {
 
3540
                        if (AskYesNo("    Ref.Env.: Use alias names (instead of #) for virtual atoms (y/n)? [no] ",false))
 
3541
                        {
 
3542
                                for (z2=0;z2<g_oaMolecules.GetSize();z2++)
 
3543
                                {
 
3544
                                        CMolecule *m = (CMolecule*)g_oaMolecules[z2];
 
3545
                                        for (z=0;z<m->m_baAtomIndex.GetSize();z++)
 
3546
                                        {
 
3547
                                                if (m->m_baAtomIndex[z] != g_iVirtAtomType)
 
3548
                                                        continue;
 
3549
                                                for (z3=0;z3<m->m_waAtomCount[z];z3++)
 
3550
                                                {
 
3551
                                                        mprintf("    How to name atom #%d in %s? [#%d] ",z3+1,m->m_sName,z3+1);
 
3552
                                                        inpprintf("! How to name atom #%d in %s? [#%d]\n",z3+1,m->m_sName,z3+1);
 
3553
                                                        myget(buf);
 
3554
                                                        if (strlen(buf) != 0)
 
3555
                                                                strcpy(((CVirtualAtom*)g_oaVirtualAtoms[m->m_laVirtualAtoms[z3]])->m_sLabel,buf);
 
3556
                                                }
 
3557
                                        }
 
3558
                                }
 
3559
                        }
 
3560
                }
 
3561
 
 
3562
                if (g_bSaveRefEnv || g_bCutCluster)
 
3563
                        g_bEnvWriteDetailedInfo = AskYesNo("    Write detailed (long) comment lines into output xyz file (y/n)? [yes] ",true);
 
3564
                                else g_bEnvWriteDetailedInfo = false;
 
3565
 
 
3566
                if ((g_bSaveRefEnv || g_bCutCluster) && !g_bEnvDisableSortNb)
 
3567
                        g_bEnvSortNb = AskYesNo("    Sort molecules according to distance from reference molecule (y/n)? [yes] ",true);
 
3568
                                else g_bEnvSortNb = false;
 
3569
 
 
3570
                mprintf(WHITE,"\n<<< End of Coordinate output options <<<\n\n");
 
3571
        } else
 
3572
        {
 
3573
                g_bWriteAtomwise = false;
 
3574
                g_bSaveVirtAtoms = false;
 
3575
        }
 
3576
 
 
3577
        if (g_bSaveRefEnv || g_bCutCluster)
 
3578
                g_bCenterZero = AskYesNo("    Put the center of the system to (0|0|0) (y) or to (x/2|y/2|z/2) (n)? [yes] ",true);
 
3579
 
 
3580
        g_bMiddleAvg = false;
 
3581
        g_iSwapAtoms = 0;
 
3582
 
 
3583
        if (g_bSaveJustTraj)
 
3584
        {
 
3585
                mprintf(WHITE,"\n>>> Process Trajectory >>>\n\n");
 
3586
 
 
3587
                if (g_bAdvanced2)
 
3588
                        g_bSaveTrajNoRot = AskYesNo("    Remove angular momentum from trajectory (y/n)? [no] ",false);
 
3589
                                else g_bSaveTrajNoRot = false;
 
3590
 
 
3591
                if (g_bSaveTrajNoRot)
 
3592
                {
 
3593
                        mprintf("\n    This centers the mass center of the system. All atoms of the system are saved.\n\n");
 
3594
                        g_bSaveCoordsUnchanged = false;
 
3595
                        g_bSaveJustCenter = false;
 
3596
                        if(AskYesNo("    Put the center of the system to (0|0|0) (y) or to (x/2|y/2|z/2) (n)? [yes] ",true))
 
3597
                                g_bCenterZero = true;
 
3598
                                        else g_bCenterZero = false;
 
3599
                        goto _norot;
 
3600
                } else
 
3601
                {
 
3602
                        switch(AskRangeInteger("    Put the center of the system to (0|0|0) (0), to (x/2|y/2|z/2) (1), or leave coords unchanged (2)? [1] ",0,2,1))
 
3603
                        {
 
3604
                                case 0:
 
3605
                                        g_bCenterZero = true;
 
3606
                                        g_bSaveCoordsUnchanged = false;
 
3607
                                        break;
 
3608
                                case 1:
 
3609
                                        g_bCenterZero = false;
 
3610
                                        g_bSaveCoordsUnchanged = false;
 
3611
                                        break;
 
3612
                                case 2:
 
3613
                                        g_bSaveCoordsUnchanged = true;
 
3614
                                        break;
 
3615
                        }
 
3616
 
 
3617
                        if (!g_bSaveCoordsUnchanged)
 
3618
                                g_bSaveJustCenter = AskYesNo("\n    Put a specific atom into the box center (y/n)? [no] ",false);
 
3619
                                        else g_bSaveJustCenter = false;
 
3620
                }
 
3621
 
 
3622
                if (g_bSaveJustCenter)
 
3623
                {
 
3624
                        if (g_oaMolecules.GetSize() > 1)
 
3625
                        {
 
3626
                                sprintf(buf,"    Choose center atom from which of the molecules (");
 
3627
                                for (z=0;z<g_oaMolecules.GetSize();z++)
 
3628
                                {
 
3629
                                        sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
 
3630
                                        strcat(buf,buf2);
 
3631
                                        if (z < g_oaMolecules.GetSize()-1)
 
3632
                                                strcat(buf,", ");
 
3633
                                }
 
3634
                                strcat(buf,")? ");
 
3635
                                g_iSaveJustMol = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize()) - 1;
 
3636
                        } else
 
3637
                        {
 
3638
                                g_iSaveJustMol = 0;
 
3639
                                mprintf("    Choosing center atom from %s.\n",((CMolecule*)g_oaMolecules[0])->m_sName);
 
3640
                        }
 
3641
                        if (((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_laSingleMolIndex.GetSize() > 1)
 
3642
                                g_iSaveJustSM = AskRangeInteger("    Take which representant from %s (1-%d)? [1] ",1,((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_laSingleMolIndex.GetSize(),1,((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_sName,((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_laSingleMolIndex.GetSize()) - 1;
 
3643
                                        else g_iSaveJustSM = 0;
 
3644
_proccenter:
 
3645
                        AskString("    Which atom from %s %d to put into the box center? [#2] ",buf,"#2",((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_sName,g_iSaveJustSM+1);
 
3646
                        if (!ParseAtom(buf,g_iSaveJustMol,g_iSaveJustAtomType,g_iSaveJustRealAtomType,g_iSaveJustAtom))
 
3647
                                goto _proccenter;
 
3648
                }
 
3649
                g_iSaveGesAtoms = 0;
 
3650
                if (!AskYesNo("    Save all atoms in the system (y/n)? [yes] ",true))
 
3651
                {
 
3652
                        mprintf("\n");
 
3653
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
3654
                        {
 
3655
                                if (AskYesNo("    Save (some/all) atoms from molecule %s (y/n)? [yes] ",true,((CMolecule*)g_oaMolecules[z])->m_sName))
 
3656
                                {
 
3657
                                        try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
 
3658
                                        if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3659
                                        
 
3660
                                        g_oaSaveMolecules.Add(ag);
 
3661
_savejust1:                     mprintf("    Which atoms to save from %s (e.g. \"C1,C3-5,H\")? [all] ",((CMolecule*)g_oaMolecules[z])->m_sName);
 
3662
                                        inpprintf("! Which atoms to save from %s (e.g. \"C1,C3-5,H\")? [all]\n",((CMolecule*)g_oaMolecules[z])->m_sName);
 
3663
                                        myget(buf);
 
3664
                                        if (strlen(buf)==0)
 
3665
                                                ag->AddAllAtoms((CMolecule*)g_oaMolecules[z],g_bSaveVirtAtoms);
 
3666
                                                        else if (!ag->ParseAtoms((CMolecule*)g_oaMolecules[z],buf))
 
3667
                                                                goto _savejust1;
 
3668
                                        g_iSaveGesAtoms += ag->m_iAtomGes * ((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();
 
3669
                                }
 
3670
                        }
 
3671
                } else
 
3672
                {
 
3673
_norot:
 
3674
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
3675
                        {
 
3676
                                try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
 
3677
                                if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3678
 
 
3679
                                g_oaSaveMolecules.Add(ag);
 
3680
                                ag->AddAllAtoms((CMolecule*)g_oaMolecules[z],g_bSaveVirtAtoms);
 
3681
                                g_iSaveGesAtoms += ag->m_iAtomGes * ((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();
 
3682
                        }
 
3683
                }
 
3684
 
 
3685
                if (g_bUnknownElements)
 
3686
                {
 
3687
                        g_bUnwrapWannier = AskYesNo("    Write out Wannier centers together with trajectory (y/n)? [no] ",false);
 
3688
 
 
3689
                        if (g_bUnwrapWannier)
 
3690
                                ParseDipole();
 
3691
 
 
3692
                } else g_bUnwrapWannier = false;
 
3693
 
 
3694
                if ((!g_bSaveCoordsUnchanged) && (!g_bSaveTrajNoRot))
 
3695
                        g_bUnwrap = AskYesNo("    Try to unwrap the trajectory (y/n)? [no] ",false);
 
3696
                                else g_bUnwrap = false;
 
3697
 
 
3698
                if (g_bUnwrap)
 
3699
                        mprintf("\n    Attention! This feature only works if the time step\n    in the trajectory is quite small. One particle may never\n    move further than half of the box length in one time step!\n");
 
3700
 
 
3701
                mprintf("\nSaving %d atoms per step:\n",g_iSaveGesAtoms);
 
3702
                for (z2=0;z2<g_oaSaveMolecules.GetSize();z2++)
 
3703
                {
 
3704
                        ag = (CAtomGroup*)g_oaSaveMolecules[z2];
 
3705
                        mprintf("  - In %s: ",ag->m_pMolecule->m_sName);
 
3706
                        for (z=0;z<ag->m_baAtomType.GetSize();z++)
 
3707
                        {
 
3708
                                for (z3=0;z3<((CxIntArray*)ag->m_oaAtoms[z])->GetSize();z3++)
 
3709
                                {
 
3710
                                        mprintf("%s%d",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z])->GetAt(z3)+1);
 
3711
                                        if (z3 < ((CxIntArray*)ag->m_oaAtoms[z])->GetSize()-1)
 
3712
                                                mprintf(", ");
 
3713
                                }
 
3714
                                if (z+1 < ag->m_baAtomType.GetSize())
 
3715
                                        mprintf(", ");
 
3716
                        }
 
3717
                        mprintf("\n");
 
3718
                }
 
3719
//              g_bTrajAtomwise = (AskRangeInteger("\n    Save trajectory ordered molecule-wise (0) or atom-wise (1)? [0] ",0,1,0)!=0);
 
3720
 
 
3721
                mprintf("\n");
 
3722
 
 
3723
                if (g_bAdvanced2)
 
3724
                {
 
3725
                        if ((int)g_iSaveGesAtoms == g_iGesAtomCount)
2593
3726
                        {
2594
 
                                mprintf(BLUE,"\n### Channel %d ###\n",z+1);
2595
 
                                switch(g_iObsChannel[z])
 
3727
                                switch(AskRangeInteger("    Sort output coordinates by molecules (0), element types (1), or input file order (2)? [0] ",0,2,0))
2596
3728
                                {
2597
3729
                                        case 0:
2598
 
                                                try { o->m_pRDF[z] = new CRDF(); } catch(...) { o->m_pRDF[z] = NULL; }
2599
 
                                                if (o->m_pRDF[z] == NULL) NewException((double)sizeof(CRDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2600
 
                                                
2601
 
                                                if (o->m_bSecondShowMol && (z == 1))
2602
 
                                                        o->m_pRDF[z]->m_iShowMol = o->m_iShowMol2;
2603
 
                                                                else o->m_pRDF[z]->m_iShowMol = o->m_iShowMol;
2604
 
                                                o->m_pRDF[z]->Parse();
2605
 
                                                o->m_pCDF->m_iCombinations[z] = o->m_pRDF[z]->m_iCombinations;
2606
 
                                                o->m_pCDF->m_iCombinationProd *= o->m_pRDF[z]->m_iCombinations;
2607
 
/*                                              if (o->m_pRDF[z]->m_bSaveDist)
2608
 
                                                        o->m_bTimeDev = true;*/
 
3730
                                                g_bWriteAtomwise = false;
 
3731
                                                g_bWriteInputOrder = false;
2609
3732
                                                break;
2610
 
 
2611
3733
                                        case 1:
2612
 
                                                try { o->m_pADF[z] = new CADF(); } catch(...) { o->m_pADF[z] = NULL; }
2613
 
                                                if (o->m_pADF[z] == NULL) NewException((double)sizeof(CADF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2614
 
                                                
2615
 
                                                if (o->m_bSecondShowMol && (z == 1))
2616
 
                                                        o->m_pADF[z]->m_iShowMol = o->m_iShowMol2;
2617
 
                                                                else o->m_pADF[z]->m_iShowMol = o->m_iShowMol;
2618
 
                                                o->m_pADF[z]->Parse();
2619
 
                                                o->m_pCDF->m_iCombinations[z] = o->m_pADF[z]->m_iCombinations;
2620
 
                                                o->m_pCDF->m_iCombinationProd *= o->m_pADF[z]->m_iCombinations;
2621
 
/*                                              if (o->m_pADF[z]->m_bSaveAngle)
2622
 
                                                        o->m_bTimeDev = true;*/
 
3734
                                                g_bWriteAtomwise = true;
 
3735
                                                g_bWriteInputOrder = false;
2623
3736
                                                break;
2624
 
 
2625
3737
                                        case 2:
2626
 
                                                try { o->m_pDDF[z] = new CDDF(); } catch(...) { o->m_pDDF[z] = NULL; }
2627
 
                                                if (o->m_pDDF[z] == NULL) NewException((double)sizeof(CDDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2628
 
                                                
2629
 
                                                if (o->m_bSecondShowMol && (z == 1))
2630
 
                                                        o->m_pDDF[z]->m_iShowMol = o->m_iShowMol2;
2631
 
                                                                else o->m_pDDF[z]->m_iShowMol = o->m_iShowMol;
2632
 
                                                o->m_pDDF[z]->Parse();
2633
 
                                                o->m_pCDF->m_iCombinations[z] = o->m_pDDF[z]->m_iCombinations;
2634
 
                                                o->m_pCDF->m_iCombinationProd *= o->m_pDDF[z]->m_iCombinations;
2635
 
/*                                              if (o->m_pDDF[z]->m_bSaveAngle)
2636
 
                                                        o->m_bTimeDev = true;*/
2637
 
                                                break;
2638
 
 
2639
 
                                        case 3:
2640
 
                                                try { o->m_pDipDF[z] = new CDipDF(); } catch(...) { o->m_pDipDF[z] = NULL; }
2641
 
                                                if (o->m_pDipDF[z] == NULL) NewException((double)sizeof(CDipDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2642
 
                                                
2643
 
                                                if (o->m_bSecondShowMol && (z == 1))
2644
 
                                                        o->m_pDipDF[z]->m_iShowMol = o->m_iShowMol2;
2645
 
                                                                else o->m_pDipDF[z]->m_iShowMol = o->m_iShowMol;
2646
 
                                                o->m_pDipDF[z]->m_iCombinations = 1;
2647
 
                                                o->m_pDipDF[z]->Parse();
2648
 
                                                o->m_pCDF->m_iCombinations[z] = 1;
2649
 
/*                                              if (o->m_pDipDF[z]->m_bSaveDipole)
2650
 
                                                        o->m_bTimeDev = true;*/
2651
 
                                                break;
2652
 
 
2653
 
                                        case 4:
2654
 
                                                try { o->m_pVDF[z] = new CVDF(); } catch(...) { o->m_pVDF[z] = NULL; }
2655
 
                                                if (o->m_pVDF[z] == NULL) NewException((double)sizeof(CVDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2656
 
                                                 
2657
 
                                                if (o->m_bSecondShowMol && (z == 1))
2658
 
                                                        o->m_pVDF[z]->m_iShowMol = o->m_iShowMol2;
2659
 
                                                                else o->m_pVDF[z]->m_iShowMol = o->m_iShowMol;
2660
 
                                                o->m_pVDF[z]->Parse();
2661
 
                                                o->m_pCDF->m_iCombinations[z] = o->m_pVDF[z]->m_iCombinations;
2662
 
                                                o->m_pCDF->m_iCombinationProd *= o->m_pVDF[z]->m_iCombinations;
2663
 
                                                g_bUseVelocities = true;
2664
 
/*                                              if (o->m_pVDF[z]->m_bSaveSpeed)
2665
 
                                                        o->m_bTimeDev = true;*/
2666
 
                                                break;
2667
 
 
2668
 
                                        case 5:
2669
 
                                                try { o->m_pPlDF[z] = new CPlDF(); } catch(...) { o->m_pPlDF[z] = NULL; }
2670
 
                                                if (o->m_pPlDF[z] == NULL) NewException((double)sizeof(CPlDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2671
 
                                                
2672
 
                                                if (o->m_bSecondShowMol && (z == 1))
2673
 
                                                        o->m_pPlDF[z]->m_iShowMol = o->m_iShowMol2;
2674
 
                                                                else o->m_pPlDF[z]->m_iShowMol = o->m_iShowMol;
2675
 
                                                o->m_pPlDF[z]->Parse();
2676
 
                                                o->m_pCDF->m_iCombinations[z] = o->m_pPlDF[z]->m_iCombinations;
2677
 
                                                o->m_pCDF->m_iCombinationProd *= o->m_pPlDF[z]->m_iCombinations;
2678
 
                                                break;
2679
 
 
2680
 
                                        case 6:
2681
 
                                                try { o->m_pLiDF[z] = new CLiDF(); } catch(...) { o->m_pLiDF[z] = NULL; }
2682
 
                                                if (o->m_pLiDF[z] == NULL) NewException((double)sizeof(CLiDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2683
 
                                                
2684
 
                                                if (o->m_bSecondShowMol && (z == 1))
2685
 
                                                        o->m_pLiDF[z]->m_iShowMol = o->m_iShowMol2;
2686
 
                                                                else o->m_pLiDF[z]->m_iShowMol = o->m_iShowMol;
2687
 
                                                o->m_pLiDF[z]->Parse();
2688
 
                                                o->m_pCDF->m_iCombinations[z] = o->m_pLiDF[z]->m_iCombinations;
2689
 
                                                o->m_pCDF->m_iCombinationProd *= o->m_pLiDF[z]->m_iCombinations;
2690
 
                                                break;
2691
 
                                }
2692
 
/*                              if (z != 0)
2693
 
                                        o->m_pCDF->m_bChannelAll[z] = AskYesNo("    Should this CDF Channel observe all OMs (y) or only the current one (n)? [no] ",false);
2694
 
                                                else o->m_pCDF->m_bChannelAll[z] = false;*/
2695
 
                        }
2696
 
/*                      mprintf("    Write out temporal development for this CDF (1=yes,0=no)? [no] ");
2697
 
                        myget(buf);
2698
 
                        o->m_pCDF->m_bTimeDev = (atoi(buf)!=0);
2699
 
                        if (o->m_pCDF->m_bTimeDev)
2700
 
                                o->m_bTimeDev = true;*/
2701
 
 
2702
 
                        mprintf("\n");
2703
 
 
2704
 
                        try { o->m_pCDF->m_iResolution = new int[g_iCDFChannels]; } catch(...) { o->m_pCDF->m_iResolution = NULL; }
2705
 
                        if (o->m_pCDF->m_iResolution == NULL) NewException((double)g_iCDFChannels*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2706
 
                        
2707
 
                        for (z=0;z<g_iCDFChannels;z++)
2708
 
                        {
2709
 
                                switch(g_iObsChannel[z])
2710
 
                                {
2711
 
                                        case 0: sprintf(buf,"RDF"); break;
2712
 
                                        case 1: sprintf(buf,"ADF"); break;
2713
 
                                        case 2: sprintf(buf,"DDF"); break;
2714
 
                                        case 3: sprintf(buf,"DipDF"); break;
2715
 
                                        case 4: sprintf(buf,"VDF"); break;
2716
 
                                        case 5: sprintf(buf,"PlDF"); break;
2717
 
                                        case 6: sprintf(buf,"LiDF"); break;
2718
 
                                }
2719
 
                                o->m_pCDF->m_iResolution[z] = AskUnsignedInteger("    Please enter the resolution (bin count) for CDF channel %d (%s): [100] ",100,z+1,buf);
2720
 
                        }
2721
 
 
2722
 
                        if (g_bAdvanced2)
2723
 
                                o->m_pCDF->m_iHistogramRes = AskUnsignedInteger("    Please enter CDF histogram resolution (0=no histogram): [5000] ",5000);
2724
 
                                        else o->m_pCDF->m_iHistogramRes = 0;
2725
 
 
2726
 
                        if (g_iCDFChannels == 2)
2727
 
                        {
2728
 
                                try { o->m_pCDF->m_pCombineList = new char[o->m_pCDF->m_iCombinationProd]; } catch(...) { o->m_pCDF->m_pCombineList = NULL; }
2729
 
                                if (o->m_pCDF->m_pCombineList == NULL) NewException((double)o->m_pCDF->m_iCombinationProd*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2730
 
                                
2731
 
                                if ((o->m_pCDF->m_iCombinations[0] > 1) && (o->m_pCDF->m_iCombinations[1] > 1))
2732
 
                                {
2733
 
                                        mprintf("\n");
2734
 
                                        for (z=0;z<g_iCDFChannels;z++)
2735
 
                                        {
2736
 
                                                mprintf(WHITE,"CDF channel %d has the following %d observations:\n",z+1,o->m_pCDF->m_iCombinations[z]);
2737
 
                                                o->ListCDFObservations(z);
2738
 
                                                mprintf("\n");
2739
 
                                        }
2740
 
                                        if (o->m_pCDF->m_iCombinations[0] == o->m_pCDF->m_iCombinations[1])
2741
 
                                        {
2742
 
                                                if (AskYesNo("    Combine n-th with n-th observation? (y/n) [yes] ",true))
2743
 
                                                {
2744
 
                                                        for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
2745
 
                                                                for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
2746
 
                                                                        o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]+z2] = (z==z2)?1:0;
2747
 
                                                        goto _combdone;
2748
 
                                                } goto _askcomball;
2749
 
                                        } else
2750
 
                                        {
2751
 
_askcomball:
2752
 
                                                if (!AskYesNo("    Combine each with each observation (y), or use only some combinations (n)? [yes] ",true))
2753
 
                                                {
2754
 
                                                        for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
2755
 
                                                                for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
2756
 
                                                                        o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]+z2] = 0;
2757
 
 
2758
 
                                                        mprintf("\n    Please enter all the combinations you want to observe.\n");
2759
 
                                                        mprintf("    Enter each combination as a comma-separated %d-tuple (e.g. ",g_iCDFChannels);
2760
 
                                                        for (z=0;z<g_iCDFChannels;z++)
2761
 
                                                        {
2762
 
                                                                mprintf("%d",z+1);
2763
 
                                                                if (z+1 < g_iCDFChannels)
2764
 
                                                                        mprintf(",");
2765
 
                                                        }
2766
 
                                                        mprintf(").\n\n");
2767
 
_nextcomb:
2768
 
                                                        AskString("    Enter combination (return=finished): ",buf,"");
2769
 
                                                        if (strlen(buf)==0)
2770
 
                                                                goto _combdone;
2771
 
                                                        tempwa.RemoveAll_KeepSize();
2772
 
                                                        ParseIntList(buf,&tempwa);
2773
 
                                                        if (tempwa.GetSize() != g_iCDFChannels)
2774
 
                                                        {
2775
 
                                                                eprintf("    Wrong input, %d instead of %d values.\n",tempwa.GetSize(),g_iCDFChannels);
2776
 
                                                                goto _nextcomb;
2777
 
                                                        }
2778
 
                                                        for (z=0;z<g_iCDFChannels;z++)
2779
 
                                                        {
2780
 
                                                                if ((tempwa[z] < 1) || (tempwa[z] > o->m_pCDF->m_iCombinations[z]))
2781
 
                                                                {
2782
 
                                                                        eprintf("    Wrong input, channel %d has only %d observations (%d requested).\n",z+1,o->m_pCDF->m_iCombinations[z],tempwa[z]);
2783
 
                                                                        goto _nextcomb;
2784
 
                                                                }
2785
 
                                                                tempwa[z]--;
2786
 
                                                        }
2787
 
                                                        if (o->m_pCDF->m_pCombineList[tempwa[0]*o->m_pCDF->m_iCombinations[1]+tempwa[1]] == 1)
2788
 
                                                        {
2789
 
                                                                eprintf("    This combination has already been added.\n");
2790
 
                                                                goto _nextcomb;
2791
 
                                                        }
2792
 
                                                        o->m_pCDF->m_pCombineList[tempwa[0]*o->m_pCDF->m_iCombinations[1]+tempwa[1]] = 1;
2793
 
                                                        goto _nextcomb;
2794
 
                                                } else goto _combineall;
2795
 
_combdone:;
2796
 
                                        }
2797
 
                                } else
2798
 
                                {
2799
 
_combineall:
2800
 
                                        for (z=0;z<o->m_pCDF->m_iCombinationProd;z++)
2801
 
                                                o->m_pCDF->m_pCombineList[z] = 1;
2802
 
                                }
2803
 
 
2804
 
                                o->m_pCDF->m_iCombinationsEnabled = 0;
2805
 
                                for (z=0;z<o->m_pCDF->m_iCombinationProd;z++)
2806
 
                                        if (o->m_pCDF->m_pCombineList[z] != 0)
2807
 
                                                o->m_pCDF->m_iCombinationsEnabled++;
2808
 
 
2809
 
                                if (o->m_pCDF->m_iCombinationsEnabled == 1)
2810
 
                                {
2811
 
                                        mprintf(WHITE,"\n    Using 1 combination for each RM-OM pair.\n\n");
2812
 
                                } else
2813
 
                                {
2814
 
                                        mprintf(WHITE,"\n    Using %d combinations for each RM-OM pair:\n\n",o->m_pCDF->m_iCombinationsEnabled);
2815
 
                                        z3 = 0;
2816
 
                                        for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
2817
 
                                        {
2818
 
                                                for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
2819
 
                                                {
2820
 
                                                        if (o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]+z2] == 1)
2821
 
                                                        {
2822
 
                                                                mprintf("      %2d.) %2d - %2d\n",z3+1,z+1,z2+1);
2823
 
                                                                z3++;
2824
 
                                                        }
2825
 
                                                }
2826
 
                                        }
2827
 
                                        mprintf("\n");
2828
 
                                }
2829
 
 
2830
 
                                if (g_bAdvanced2)
2831
 
                                {
2832
 
                                        o->m_pCDF->m_bAxisDivide = AskYesNo("    Write out +/- correlation plot for this CDF (y/n)? [no] ",false);
2833
 
 
2834
 
                                        if (o->m_pCDF->m_bAxisDivide)
2835
 
                                                o->m_pCDF->m_bAxisDivideAll = AskYesNo("    Also write tensor product and axis projection quotients (y/n)? [no] ",false);
2836
 
                                } else
2837
 
                                {
2838
 
                                        o->m_pCDF->m_bAxisDivide = false;
2839
 
                                        o->m_pCDF->m_bAxisDivideAll = false;
2840
 
                                }
2841
 
 
2842
 
                                if (g_bAdvanced2)
2843
 
                                {
2844
 
                                        o->m_pCDF->m_bGraceBunch = AskYesNo("    Write out grace stack (multiple 2D plots) for this CDF (y/n)? [no] ",false);
2845
 
                                        if (o->m_pCDF->m_bGraceBunch)
2846
 
                                        {
2847
 
                                                o->m_pCDF->m_iGraceBunchC1 = AskUnsignedInteger("    How many graphs do you want do draw in the channel 1 grace stack (0=disable)? [10] ",10);
2848
 
                                                o->m_pCDF->m_iGraceBunchC2 = AskUnsignedInteger("    How many graphs do you want do draw in the channel 2 grace stack (0=disable)? [10] ",10);
2849
 
                                        }
2850
 
                                } else o->m_pCDF->m_bGraceBunch = false;
2851
 
                        }
2852
 
 
2853
 
                        if (g_iCDFChannels == 3)
2854
 
                        {
2855
 
                                mprintf("\n");
2856
 
 
2857
 
                                try { o->m_pCDF->m_pCombineList = new char[o->m_pCDF->m_iCombinationProd]; } catch(...) { o->m_pCDF->m_pCombineList = NULL; }
2858
 
                                if (o->m_pCDF->m_pCombineList == NULL) NewException((double)o->m_pCDF->m_iCombinationProd*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2859
 
                                
2860
 
                                if ((o->m_pCDF->m_iCombinations[0] > 1) || (o->m_pCDF->m_iCombinations[1] > 1) || (o->m_pCDF->m_iCombinations[2] > 1))
2861
 
                                {
2862
 
                                        for (z=0;z<g_iCDFChannels;z++)
2863
 
                                        {
2864
 
                                                mprintf(WHITE,"CDF channel %d has the following %d observations:\n",z+1,o->m_pCDF->m_iCombinations[z]);
2865
 
                                                o->ListCDFObservations(z);
2866
 
                                                mprintf("\n");
2867
 
                                        }
2868
 
                                        if (!AskYesNo("    Combine each with each observation (y), or use only some combinations (n)? [yes] ",true))
2869
 
                                        {
2870
 
                                                for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
2871
 
                                                        for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
2872
 
                                                                for (z3=0;z3<o->m_pCDF->m_iCombinations[2];z3++)
2873
 
                                                                        o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]*o->m_pCDF->m_iCombinations[2]+z2*o->m_pCDF->m_iCombinations[2]+z3] = 0;
2874
 
 
2875
 
                                                mprintf("\n    Please enter all the combinations you want to observe.\n");
2876
 
                                                mprintf("    Enter each combination as a comma-separated %d-tuple (e.g. ",g_iCDFChannels);
2877
 
                                                for (z=0;z<g_iCDFChannels;z++)
2878
 
                                                {
2879
 
                                                        mprintf("%d",z+1);
2880
 
                                                        if (z+1 < g_iCDFChannels)
2881
 
                                                                mprintf(",");
2882
 
                                                }
2883
 
                                                mprintf(").\n\n");
2884
 
_3nextcomb:
2885
 
                                                AskString("    Enter combination (return=finished): ",buf,"");
2886
 
                                                if (strlen(buf)==0)
2887
 
                                                        goto _3combdone;
2888
 
                                                tempwa.RemoveAll_KeepSize();
2889
 
                                                ParseIntList(buf,&tempwa);
2890
 
                                                if (tempwa.GetSize() != g_iCDFChannels)
2891
 
                                                {
2892
 
                                                        eprintf("    Wrong input, %d instead of %d values.\n",tempwa.GetSize(),g_iCDFChannels);
2893
 
                                                        goto _3nextcomb;
2894
 
                                                }
2895
 
                                                for (z=0;z<g_iCDFChannels;z++)
2896
 
                                                {
2897
 
                                                        if ((tempwa[z] < 1) || (tempwa[z] > o->m_pCDF->m_iCombinations[z]))
2898
 
                                                        {
2899
 
                                                                eprintf("    Wrong input, channel %d has only %d observations (%d requested).\n",z+1,o->m_pCDF->m_iCombinations[z],tempwa[z]);
2900
 
                                                                goto _3nextcomb;
2901
 
                                                        }
2902
 
                                                        tempwa[z]--;
2903
 
                                                }
2904
 
                                                if (o->m_pCDF->m_pCombineList[tempwa[0]*o->m_pCDF->m_iCombinations[1]*o->m_pCDF->m_iCombinations[2]+tempwa[1]*o->m_pCDF->m_iCombinations[2]+tempwa[2]] == 1)
2905
 
                                                {
2906
 
                                                        eprintf("    This combination has already been added.\n");
2907
 
                                                        goto _3nextcomb;
2908
 
                                                }
2909
 
                                                o->m_pCDF->m_pCombineList[tempwa[0]*o->m_pCDF->m_iCombinations[1]*o->m_pCDF->m_iCombinations[2]+tempwa[1]*o->m_pCDF->m_iCombinations[2]+tempwa[2]] = 1;
2910
 
                                                goto _3nextcomb;
2911
 
                                        } else goto _3combineall;
2912
 
                                } else
2913
 
                                {
2914
 
_3combineall:
2915
 
                                        for (z=0;z<o->m_pCDF->m_iCombinationProd;z++)
2916
 
                                                o->m_pCDF->m_pCombineList[z] = 1;
2917
 
                                }
2918
 
_3combdone:
2919
 
                                o->m_pCDF->m_iCombinationsEnabled = 0;
2920
 
                                for (z=0;z<o->m_pCDF->m_iCombinationProd;z++)
2921
 
                                        if (o->m_pCDF->m_pCombineList[z] != 0)
2922
 
                                                o->m_pCDF->m_iCombinationsEnabled++;
2923
 
 
2924
 
                                if (o->m_pCDF->m_iCombinationsEnabled == 1)
2925
 
                                {
2926
 
                                        mprintf(WHITE,"\n    Using 1 combination for each RM-OM pair.\n\n");
2927
 
                                } else
2928
 
                                {
2929
 
                                        mprintf(WHITE,"\n    Using %d combinations for each RM-OM pair:\n\n",o->m_pCDF->m_iCombinationsEnabled);
2930
 
                                        z4 = 0;
2931
 
                                        for (z=0;z<o->m_pCDF->m_iCombinations[0];z++)
2932
 
                                                for (z2=0;z2<o->m_pCDF->m_iCombinations[1];z2++)
2933
 
                                                        for (z3=0;z3<o->m_pCDF->m_iCombinations[2];z3++)
2934
 
                                                                if (o->m_pCDF->m_pCombineList[z*o->m_pCDF->m_iCombinations[1]*o->m_pCDF->m_iCombinations[2]+z2*o->m_pCDF->m_iCombinations[2]+z3] == 1)
2935
 
                                                                {
2936
 
                                                                        mprintf("      %2d.) %2d - %2d - %2d\n",z4+1,z+1,z2+1,z3+1);
2937
 
                                                                        z4++;
2938
 
                                                                }
2939
 
                                        mprintf("\n");
2940
 
                                }
2941
 
 
2942
 
                                if (g_bAdvanced2)
2943
 
                                {
2944
 
                                        o->m_pCDF->m_b3DSlices = AskYesNo("    Write out 2D slices for this CDF (y/n)? [no] ",false);
2945
 
 
2946
 
                                        if (o->m_pCDF->m_b3DSlices)
2947
 
                                                for (z=0;z<3;z++)
2948
 
                                                        o->m_pCDF->m_i3DSliceIntervals[z] = AskUnsignedInteger("    How many slice intervals to create along channel %d axis (0=skip)? [0] ",0,z+1);
2949
 
                                } else o->m_pCDF->m_b3DSlices = false;
2950
 
                        } // end if channels == 3
2951
 
 
2952
 
 
2953
 
                        if (g_bAdvanced2)
2954
 
                        {
2955
 
                                o->m_pCDF->m_bDumpDat = AskYesNo("    Write out input tuples (very large!) for this CDF (y/n)? [no] ",false);
2956
 
                                if ((g_iCDFChannels == 2) && (g_iObsChannel[0] == 0) && (g_iObsChannel[1] == 1))
2957
 
                                        o->m_pCDF->m_iNormalize = AskRangeInteger("    Normalize uniformly (3), data range (2), integral (1), or do not normalize (0)? [1] ",0,3,1);
2958
 
                                                else o->m_pCDF->m_iNormalize = AskRangeInteger("    Normalize data range (2), integral (1), or do not normalize (0)? [1] ",0,2,1);
2959
 
                                if (o->m_pCDF->m_iNormalize == 1)
2960
 
                                        o->m_pCDF->m_fNormValue = AskFloat("    Set CDF integral to which value? [1000000] ",1000000.0f);
2961
 
                                if (o->m_pCDF->m_iNormalize == 2)
2962
 
                                        o->m_pCDF->m_fNormValue = AskFloat("    Set maximum entry to which value? [100] ",100.0f);
2963
 
                        } else
2964
 
                        {
2965
 
                                o->m_pCDF->m_bDumpDat = false;
2966
 
                                o->m_pCDF->m_iNormalize = 1;
2967
 
                                o->m_pCDF->m_fNormValue = 1000000.0f;
2968
 
                        }
2969
 
 
2970
 
                        mprintf(BLUE,"\n<<< End of Combined Distribution Function <<<\n\n");
2971
 
                } else
2972
 
                {
2973
 
                        if (g_bRDF)
2974
 
                        {
2975
 
                                try { o->m_pRDF[0] = new CRDF(); } catch(...) { o->m_pRDF[0] = NULL; }
2976
 
                                if (o->m_pRDF[0] == NULL) NewException((double)sizeof(CRDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2977
 
                                 
2978
 
                                o->m_pRDF[0]->m_iShowMol = o->m_iShowMol;
2979
 
                                o->m_pRDF[0]->Parse();
2980
 
                                o->m_pRDF[0]->m_bSelf = o->m_bSelf;
2981
 
                        }
2982
 
                        if (g_bPlDF)
2983
 
                        {
2984
 
                                try { o->m_pPlDF[0] = new CPlDF(); } catch(...) { o->m_pPlDF[0] = NULL; }
2985
 
                                if (o->m_pPlDF[0] == NULL) NewException((double)sizeof(CPlDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2986
 
                                 
2987
 
                                o->m_pPlDF[0]->m_iShowMol = o->m_iShowMol;
2988
 
                                o->m_pPlDF[0]->Parse();
2989
 
                                o->m_pPlDF[0]->m_bSelf = o->m_bSelf;
2990
 
                        }
2991
 
                        if (g_bLiDF)
2992
 
                        {
2993
 
                                try { o->m_pLiDF[0] = new CLiDF(); } catch(...) { o->m_pLiDF[0] = NULL; }
2994
 
                                if (o->m_pLiDF[0] == NULL) NewException((double)sizeof(CLiDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2995
 
                                 
2996
 
                                o->m_pLiDF[0]->m_iShowMol = o->m_iShowMol;
2997
 
                                o->m_pLiDF[0]->Parse();
2998
 
                                o->m_pLiDF[0]->m_bSelf = o->m_bSelf;
2999
 
                        }
3000
 
                        if (g_bVHDF)
3001
 
                        {
3002
 
                                try { o->m_pVHDF = new CVHDF(); } catch(...) { o->m_pVHDF = NULL; }
3003
 
                                if (o->m_pVHDF == NULL) NewException((double)sizeof(CVHDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3004
 
                                 
3005
 
                                o->m_pVHDF->m_iShowMol = o->m_iShowMol;
3006
 
                                o->m_pVHDF->m_bSelf = o->m_bSelf;
3007
 
                                o->m_pVHDF->Parse();
3008
 
                        }
3009
 
                        if (g_bADF)
3010
 
                        {
3011
 
                                try { o->m_pADF[0] = new CADF(); } catch(...) { o->m_pADF[0] = NULL; }
3012
 
                                if (o->m_pADF[0] == NULL) NewException((double)sizeof(CADF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3013
 
                                 
3014
 
                                o->m_pADF[0]->m_iShowMol = o->m_iShowMol;
3015
 
                                o->m_pADF[0]->m_bSelf = o->m_bSelf;
3016
 
                                o->m_pADF[0]->Parse();
3017
 
                        }
3018
 
                        if (g_bDDF)
3019
 
                        {
3020
 
                                try { o->m_pDDF[0] = new CDDF(); } catch(...) { o->m_pDDF[0] = NULL; }
3021
 
                                if (o->m_pDDF[0] == NULL) NewException((double)sizeof(CDDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3022
 
                                 
3023
 
                                o->m_pDDF[0]->m_iShowMol = o->m_iShowMol;
3024
 
                                o->m_pDDF[0]->m_bSelf = o->m_bSelf;
3025
 
                                o->m_pDDF[0]->Parse();
3026
 
                        }
3027
 
                        if (g_bDipDF)
3028
 
                        {
3029
 
                                try { o->m_pDipDF[0] = new CDipDF(); } catch(...) { o->m_pDipDF[0] = NULL; }
3030
 
                                if (o->m_pDipDF[0] == NULL) NewException((double)sizeof(CDipDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3031
 
                                 
3032
 
                                o->m_pDipDF[0]->m_iShowMol = o->m_iShowMol;
3033
 
                                o->m_pDipDF[0]->m_bSelf = o->m_bSelf;
3034
 
                                o->m_pDipDF[0]->Parse();
3035
 
                        }
3036
 
                        if (g_bVDF)
3037
 
                        {
3038
 
                                try { o->m_pVDF[0] = new CVDF(); } catch(...) { o->m_pVDF[0] = NULL; }
3039
 
                                if (o->m_pVDF[0] == NULL) NewException((double)sizeof(CVDF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3040
 
                                 
3041
 
                                o->m_pVDF[0]->m_iShowMol = o->m_iShowMol;
3042
 
                                o->m_pVDF[0]->m_bSelf = true;
3043
 
                                o->m_pVDF[0]->Parse();
3044
 
                                g_bUseVelocities = true;
3045
 
                        }
3046
 
                        if (g_bMSD)
3047
 
                        {
3048
 
                                try { o->m_pMSD = new CMSD(); } catch(...) { o->m_pMSD = NULL; }
3049
 
                                if (o->m_pMSD == NULL) NewException((double)sizeof(CMSD),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3050
 
                                 
3051
 
                                o->m_pMSD->m_iShowMol = o->m_iShowMol;
3052
 
                                o->m_pMSD->Parse();
3053
 
                        }
3054
 
                }
3055
 
 
3056
 
                if ((g_bCDF && (g_iCDFChannels == 2)) || g_bRDF || g_bADF || g_bVDF || g_bDDF || g_bDipDF)
3057
 
                {
3058
 
                        if (!o->m_bSecondShowMol)
3059
 
                        {
3060
 
                                if (AskYesNo("    Save temporal development for this observation (y/n)? [no] ",false))
3061
 
                                {
3062
 
                                        mprintf(WHITE,"\n>>> Save temporal development >>>\n\n");
3063
 
                                        o->m_bTimeDev = true;
3064
 
 
3065
 
                                        if (g_fTimestepLength == 0)
3066
 
                                        {
3067
 
                                                g_fTimestepLength = AskFloat("    Enter the length of one trajectory time step in fs: [0.5] ",0.5f);
3068
 
                                                mprintf("\n");
3069
 
                                        }
3070
 
 
3071
 
                                        if (g_bDDF && (!g_bCDF))
3072
 
                                        {
3073
 
                                                if ((o->m_pDDF[0]->m_iDeriv == 0) && (!o->m_pDDF[0]->m_bCosine) && (!o->m_pDDF[0]->m_bAbs) && (!o->m_pDDF[0]->m_bPositive))
3074
 
                                                {
3075
 
                                                        mprintf("\n    You can include full rotations into the DDF's temporal development.\n");
3076
 
                                                        mprintf("    This means, if a dihedral makes a full rotation, the value will be 360 deg insteat of 0 deg.\n");
3077
 
                                                        mprintf("    You may count the number of full rotations during simulation in this way.\n\n");
3078
 
                                                        o->m_pDDF[0]->m_bRotate = AskYesNo("    Include full rotations into the DDF's temporal development (y/n)? [no] ",false);
3079
 
                                                } else o->m_pDDF[0]->m_bRotate = false;
3080
 
                                                if (o->m_pDDF[0]->m_bRotate)
3081
 
                                                {
3082
 
                                                        mprintf(WHITE,"\n   Warning: ");
3083
 
                                                        mprintf("This only works if your trajectory time step is small enough to ensure\n");
3084
 
                                                        mprintf("             that the dihedral is never changing more than 180 deg within one step!\n\n");
3085
 
                                                }
3086
 
                                        }
3087
 
                                        if (g_bRDF || g_bADF || g_bVDF || g_bDDF || g_bDipDF)
3088
 
                                        {
3089
 
                                                if (AskYesNo("    Create combined development/histogram-plots for 2D analyses (y/n)? [yes] ",true))
3090
 
                                                {
3091
 
                                                        g_bCombined = true;
3092
 
                                                        o->m_bCombinedPlot = true;
3093
 
                                                        if (AskYesNo("    Use grey tones for combined plot (y) or standard colors (n)? [no] ",false))
3094
 
                                                        {
3095
 
                                                                o->m_bCombinedGreyMode = true;
3096
 
                                                                o->m_iCombinedGreyMin = AskRangeInteger("    Darkest shade of grey to use (0=black, 255=white)? [128] ",0,255,128);
3097
 
                                                                o->m_iCombinedGreyMax = AskRangeInteger("    Lightest shade of grey to use (0=black, 255=white)? [224] ",o->m_iCombinedGreyMin,255,224);
3098
 
                                                                o->m_iCombinedGreyShades = AskUnsignedInteger("    How many different shades of grey to use? [4] ",4);
3099
 
                                                        } else o->m_bCombinedGreyMode = false;
3100
 
                                                } else o->m_bCombinedPlot = false;
3101
 
                                        } else o->m_bCombinedPlot = false;
3102
 
 
3103
 
                                        if (((CMolecule*)g_oaMolecules[g_iFixMol])->m_laSingleMolIndex.GetSize() > 1)
3104
 
                                        {
3105
 
                                                mprintf("    Save development for which rep. of the reference molecule (e.g. 1,3-7)? [1] ");
3106
 
                                                inpprintf("! Save development for which rep. of the reference molecule (e.g. 1,3-7)? [1]\n");
3107
 
                                                myget(buf);
3108
 
                                                if (strlen(buf)==0)
3109
 
                                                        o->m_waSaveRefList.Add(0);
3110
 
                                                else {
3111
 
                                                        ParseIntList(buf,&o->m_waSaveRefList);
3112
 
                                                        for (z=0;z<o->m_waSaveRefList.GetSize();z++)
3113
 
                                                                o->m_waSaveRefList[z]--;
3114
 
                                                }
3115
 
                                        } else o->m_waSaveRefList.Add(0);
3116
 
                                        if (o->m_iShowMol != -1)
3117
 
                                        {
3118
 
                                                if (((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize() > 1)
3119
 
                                                {
3120
 
                                                        mprintf("    Save development for which rep. of the observed molecule (e.g. 1,3-7)? [all] ");
3121
 
                                                        inpprintf("! Save development for which rep. of the observed molecule (e.g. 1,3-7)? [all]\n");
3122
 
                                                        myget(buf);
3123
 
                                                        if (strlen(buf)==0)
3124
 
                                                        {
3125
 
                                                                for (z=0;z<((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_laSingleMolIndex.GetSize();z++)
3126
 
                                                                        o->m_waSaveShowList.Add(z);
3127
 
                                                        } else
3128
 
                                                        {
3129
 
                                                                ParseIntList(buf,&o->m_waSaveShowList);
3130
 
                                                                for (z=0;z<o->m_waSaveShowList.GetSize();z++)
3131
 
                                                                        o->m_waSaveShowList[z]--;
3132
 
                                                        }
3133
 
                                                } else o->m_waSaveShowList.Add(0);
3134
 
                                        } else o->m_waSaveShowList.Add(0); // Dummy
3135
 
                                        if ((o->m_waSaveRefList.GetSize() > 1) && (o->m_bOthers))
3136
 
                                                o->m_bSaveSeparateFiles = AskYesNo("    Developments for different ref. molecules to same (n) or different (y) files? [yes] ",true);
3137
 
                                                        else o->m_bSaveSeparateFiles = false;
3138
 
                                        if ((g_bCDF) && (g_iCDFChannels == 2))
3139
 
                                        {
3140
 
                                                if (AskYesNo("    Generate time development animation (TDO) for CDF (y/n)? [no] ",false))
3141
 
                                                {
3142
 
                                                        o->m_pCDF->m_bTDAnimation = true;
3143
 
                                                        o->m_pCDF->m_iTDASteps = AskUnsignedInteger("    How many steps should the animation have? [1000] ",1000);
3144
 
                                                        o->m_pCDF->m_iTDAStride = AskUnsignedInteger("    Enter distance between the frames in timesteps: [100] ",50);
3145
 
                                                        o->m_pCDF->m_iTDATail = AskUnsignedInteger("    Enter length of the tail in timesteps: [100] ",100);
3146
 
                                                        o->m_pCDF->m_bTDATrace = AskYesNo("    Show trace (y/n)? [yes] ",true);
3147
 
                                                        o->m_pCDF->m_iTDAResX = AskUnsignedInteger("    Enter width (in pixel) of the TDA images: [640] ",640);
3148
 
                                                        o->m_pCDF->m_iTDAResY = AskUnsignedInteger("    Enter height (in pixel) of the TDA images: [480] ",480);
3149
 
                                                } else o->m_pCDF->m_bTDAnimation = false;
3150
 
                                        }
3151
 
                                        mprintf("\n    Saving temporal development for reference molecules ");
3152
 
                                        for (z=0;z<o->m_waSaveRefList.GetSize();z++)
3153
 
                                        {
3154
 
                                                if (z < (int)o->m_waSaveRefList.GetSize()-1)
3155
 
                                                {
3156
 
                                                        mprintf("%d, ",o->m_waSaveRefList[z]+1);
3157
 
                                                        if (((z+1) % 16) == 0)
3158
 
                                                                mprintf("\n      ");
3159
 
                                                } else mprintf("%d",o->m_waSaveRefList[z]+1);
3160
 
                                        }
3161
 
                                        if (o->m_bOthers)
3162
 
                                        {
3163
 
                                                mprintf("\n    and for observed molecules ");
3164
 
                                                for (z=0;z<o->m_waSaveShowList.GetSize();z++)
3165
 
                                                {
3166
 
                                                        if (z < (int)o->m_waSaveShowList.GetSize()-1)
3167
 
                                                        {
3168
 
                                                                mprintf("%d, ",o->m_waSaveShowList[z]+1);
3169
 
                                                                if (((z+1) % 16) == 0)
3170
 
                                                                        mprintf("\n      ");
3171
 
                                                        } else mprintf("%d",o->m_waSaveShowList[z]+1);
3172
 
                                                }
3173
 
                                        }
3174
 
                                        mprintf(".\n");
3175
 
                                        mprintf(WHITE,"\n<<< End of Save temporal development <<<\n\n");
3176
 
                                } else o->m_bTimeDev = false;
3177
 
 
3178
 
                                if (g_bAdvanced2)
3179
 
                                {
3180
 
                                        if (AskYesNo("    Create a temporal difference plot for this observation (y/n)? [no] ",false))
3181
 
                                        {
3182
 
                                                o->m_bTimeDiff = true;
3183
 
                                                g_bTimeDiff = true;
3184
 
                                                o->m_iTimeDiffDepth = AskUnsignedInteger("    Enter temporal depth of this plot in time steps: [1000] ",1000);
3185
 
                                                o->m_b3DTimeDiff = AskYesNo("    Create also 3D temporal difference plots (y/n)? [yes] ",true);
3186
 
                                                if (o->m_b3DTimeDiff)
3187
 
                                                {
3188
 
                                                        tf = 0;
3189
 
                                                        tf2 = 0;
3190
 
                                                        if (g_bRDF)
3191
 
                                                        {
3192
 
                                                                tf = o->m_pRDF[0]->m_fMinDist;
3193
 
                                                                tf2 = o->m_pRDF[0]->m_fMaxDist;
3194
 
                                                        }
3195
 
                                                        if (g_bADF)
3196
 
                                                        {
3197
 
                                                                tf = o->m_pADF[0]->m_fMinAngle;
3198
 
                                                                tf2 = o->m_pADF[0]->m_fMaxAngle;
3199
 
                                                        }
3200
 
                                                        if (g_bDDF)
3201
 
                                                        {
3202
 
                                                                tf = o->m_pDDF[0]->m_fMinAngle;
3203
 
                                                                tf2 = o->m_pDDF[0]->m_fMaxAngle;
3204
 
                                                        }
3205
 
                                                        if (g_bVDF)
3206
 
                                                        {
3207
 
                                                                tf = o->m_pVDF[0]->m_fMinSpeed;
3208
 
                                                                tf2 = o->m_pVDF[0]->m_fMaxSpeed;
3209
 
                                                        }
3210
 
                                                        if (g_bDipDF)
3211
 
                                                        {
3212
 
                                                                tf = o->m_pDipDF[0]->m_fDipoleMin;
3213
 
                                                                tf2 = o->m_pDipDF[0]->m_fDipoleMax;
3214
 
                                                        }
3215
 
                                                        o->m_iTimeDiffStride3D = AskUnsignedInteger("    Take every n-th time step for the tau axis: [%d] ",o->m_iTimeDiffDepth/100,o->m_iTimeDiffDepth/100);
3216
 
                                                        o->m_fTimeDiffMinVal3D = AskFloat("    Enter min. value for the starting point: [%.2f] ",tf,tf);
3217
 
                                                        o->m_fTimeDiffMaxVal3D = AskFloat("    Enter max. value for the starting point: [%.2f] ",tf2,tf2);
3218
 
                                                        o->m_iTimeDiffRes3D = AskUnsignedInteger("    Enter binning resolution for the starting value: [100] ",100);
3219
 
                                                        mprintf("\n    Temporal before/after 3D plot:\n");
3220
 
                                                        o->m_iTimeDiffDistSteps= AskUnsignedInteger("    Every how many time steps create a 2D slice (0 to disable): [0] ",0);
3221
 
                                                        o->m_fTimeDiffDistMinValX = AskFloat("    Enter min. value for the starting point: [%.2f] ",tf,tf);
3222
 
                                                        o->m_fTimeDiffDistMaxValX = AskFloat("    Enter max. value for the starting point: [%.2f] ",tf2,tf2);
3223
 
                                                        o->m_iTimeDiffDistResX = AskUnsignedInteger("    Enter binning resolution for the X axis: [100] ",100);
3224
 
                                                        o->m_fTimeDiffDistMinValY = AskFloat("    Enter min. value for the end point: [%.2f] ",tf,tf);
3225
 
                                                        o->m_fTimeDiffDistMaxValY = AskFloat("    Enter max. value for the end point: [%.2f] ",tf2,tf2);
3226
 
                                                        o->m_iTimeDiffDistResY = AskUnsignedInteger("    Enter binning resolution for the Y axis: [100] ",100);
3227
 
                                                }
3228
 
                                                mprintf("\n");
3229
 
                                        } else o->m_bTimeDiff = false;
3230
 
                                } else o->m_bTimeDiff = false;
3231
 
                        } else
3232
 
                        {
3233
 
                                o->m_bTimeDev = false;
3234
 
                                o->m_bTimeDiff = false;
3235
 
                        }
3236
 
                } else
3237
 
                {
3238
 
                        o->m_bTimeDev = false;
3239
 
                        o->m_bTimeDiff = false;
3240
 
                }
3241
 
 
3242
 
                if ((g_iFixMol != -1) && (o->m_iShowMol != -1) && (g_bRDyn || g_bDipDF || g_bMSD || g_bADF || g_bPlDF || g_bLiDF || g_bDDF || g_bVACF || g_bDipACF ||g_bRevSDF || g_bSDF || g_bVHDF || g_bRDF || g_bVDF || g_bFDF || g_bCond))
3243
 
                {
3244
 
                        if (g_bCond)
3245
 
                                goto _askcond;
3246
 
                        if (AskYesNo("    Add a condition to this observation (y/n)? [no] ",false))
3247
 
                        {
3248
 
_askcond:
3249
 
                                mprintf(GREEN,"\n>>> Condition input >>>\n\n");
3250
 
//                              mprintf("You may enter several sets of conditions. They are connected with \"or\",\nonly one of them needs to apply to take a configuration into account.\n\n");
3251
 
//                              mprintf("In each set of conditions, you may enter several conditions. They are connected\nwith \"and\", all of them have to apply to make this set of conditions apply.\n");
3252
 
 
3253
 
                                if (o->m_bSecondShowMol)
3254
 
                                {
3255
 
                                        if (!AskYesNo("    Add a condition between RM and 1st OM (y/n)? [yes] ",true))
3256
 
                                                goto _no1stcond;
3257
 
                                        mprintf(WHITE,"\n    *** Input of Condition between RM and 1st OM ***\n\n");
3258
 
                                }
3259
 
 
3260
 
                                try { o->m_pConditions = new CConditionGroup(); } catch(...) { o->m_pConditions = NULL; }
3261
 
                                if (o->m_pConditions == NULL) NewException((double)sizeof(CConditionGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3262
 
                                
3263
 
                                o->m_pConditions->m_iShowMol = o->m_iShowMol;
3264
 
                                o->m_pConditions->Parse(g_iFixMol,o->m_iShowMol);
3265
 
_no1stcond:
3266
 
 
3267
 
                                if (o->m_bSecondShowMol)
3268
 
                                {
3269
 
                                        mprintf("\n");
3270
 
                                        if (!AskYesNo("    Add a condition between RM and 2nd OM (y/n)? [yes] ",true))
3271
 
                                                goto _no2ndcond;
3272
 
                                        mprintf(WHITE,"\n    *** Input of Condition between RM and 2nd OM ***\n\n");
3273
 
 
3274
 
                                        try { o->m_pConditionsOM2 = new CConditionGroup(); } catch(...) { o->m_pConditionsOM2 = NULL; }
3275
 
                                        if (o->m_pConditionsOM2 == NULL) NewException((double)sizeof(CConditionGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3276
 
                                        
3277
 
                                        o->m_pConditionsOM2->m_iShowMol = o->m_iShowMol2;
3278
 
                                        o->m_pConditionsOM2->Parse(g_iFixMol,o->m_iShowMol2);
3279
 
_no2ndcond:;
3280
 
                                }
3281
 
 
3282
 
                                if (o->m_pConditions != NULL)
3283
 
                                {
3284
 
                                        if (o->m_pConditions->m_bInvertCondition)
3285
 
                                        {
3286
 
                                                o->m_bBinOnlyNotPassedAtoms = false;
3287
 
                                                o->m_bBinOnlyPassedAtoms = false;
3288
 
                                                goto _nobinonly;
3289
 
                                        }
3290
 
                                }
3291
 
 
3292
 
                                if (o->m_pConditionsOM2 != NULL)
3293
 
                                {
3294
 
                                        if (o->m_pConditionsOM2->m_bInvertCondition)
3295
 
                                        {
3296
 
                                                o->m_bBinOnlyNotPassedAtoms = false;
3297
 
                                                o->m_bBinOnlyPassedAtoms = false;
3298
 
                                                goto _nobinonly;
3299
 
                                        }
3300
 
                                }
3301
 
 
3302
 
                                mprintf("\n    Normally, TRAVIS evaluates the condition for each RM-OM pair. If the condition\n");
3303
 
                                mprintf("    is fulfilled, all atoms from this pair are evaluated. The following question\n");
3304
 
                                mprintf("    enables to take into account only exactly the atoms which fulfilled the condition.\n\n");
3305
 
 
3306
 
                                mprintf("    If you have a distance condition with \"nearest neighbor mode\", only the atom\n");
3307
 
                                mprintf("    from the OM that is closest to the RM will be taken into account.\n\n");
3308
 
 
3309
 
                                o->m_bBinOnlyPassedAtoms = AskYesNo("    Add only atoms to the bin that passed the condition(s) (y/n)? [no] ",false);
3310
 
/*                              if (!o->m_bBinOnlyPassedAtoms)
3311
 
                                        o->m_bBinOnlyNotPassedAtoms = AskYesNo("    Add only atoms to the bin that did NOT pass the condition(s) (y/n)? [no] ",false);
3312
 
                                                else*/ o->m_bBinOnlyNotPassedAtoms = false;
3313
 
_nobinonly:
3314
 
 
3315
 
                                g_bSaveCondSnapshot = AskYesNo("    Save a snapshot every time the conditions are fulfilled (y/n)? [no] ",false);
3316
 
                                
3317
 
                                if (g_bSaveCondSnapshot)
3318
 
                                        g_bNeedMoleculeWrap = true;
3319
 
 
3320
 
                                if (g_bSaveCondSnapshot)
3321
 
                                {
3322
 
                                        g_bSaveCondWholeBox = AskYesNo("    Save the whole box (y) or only the RM/OM pair (n)? [no] ",false);
3323
 
                                        if (g_bSaveCondWholeBox)
3324
 
                                                mprintf("\n    The RM that fulfills the condition will be centered (coordinates 0|0|0).\n");
3325
 
                                }
3326
 
 
3327
 
                                mprintf(GREEN,"\n<<< End of Condition input <<<\n\n");
3328
 
                        }
3329
 
                }
3330
 
 
3331
 
                if (g_bVACF)
3332
 
                {
3333
 
                        mprintf(WHITE,"\n>>> Velocity autocorrelation function >>>\n\n");
3334
 
 
3335
 
                        try { o->m_pVACF = new CACF(); } catch(...) { o->m_pVACF = NULL; }
3336
 
                        if (o->m_pVACF == NULL) NewException((double)sizeof(CACF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3337
 
                        
3338
 
                        o->m_pVACF->m_iShowMol = o->m_iShowMol;
3339
 
                        o->m_pVACF->Parse();
3340
 
                        mprintf(WHITE,"\n<< End of Velocity autocorrelation function <<<\n\n");
3341
 
                }
3342
 
 
3343
 
/*              if (g_bDipACF)
3344
 
                {
3345
 
                        mprintf(WHITE,"\n>>> Dipole moment autocorrelation function >>>\n\n");
3346
 
 
3347
 
                        try { o->m_pDipACF = new CACF(); } catch(...) { o->m_pDipACF = NULL; }
3348
 
                        if (o->m_pDipACF == NULL) NewException((double)sizeof(CACF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3349
 
                        
3350
 
                        o->m_pDipACF->Parse();
3351
 
                        mprintf(WHITE,"\n<<< End of Dipole moment autocorrelation function <<<\n\n");
3352
 
                }*/
3353
 
 
3354
 
                if (g_bUseVelocities)
3355
 
                {
3356
 
                        if (g_iFixMol != -1)
3357
 
                                o->m_bVelocityRelToRef = (AskRangeInteger("    Use absolute velocities (0) or relative to the reference molecule (1)? [0] ",0,1,0) != 0);
3358
 
                                        else o->m_bVelocityRelToRef = false;
3359
 
                }
3360
 
 
3361
 
                mprintf(YELLOW,"\n<<< End of Observation %d <<<\n",g_oaObserv.GetSize());
3362
 
 
3363
 
                if (AskYesNo("\n    Add another observation (y/n)? [no] ",false))
3364
 
                        goto _nextsdf;
3365
 
                mprintf("\n");
3366
 
 
3367
 
                mprintf(WHITE,">>> Observation List >>>\n\n");
3368
 
                for (z2=0;z2<g_oaObserv.GetSize();z2++)
3369
 
                {
3370
 
                        mprintf(YELLOW,"  *** Observation %d\n",z2+1);
3371
 
                        o = (CObservation*)g_oaObserv[z2];
3372
 
 
3373
 
                        if (g_bCond)
3374
 
                                mprintf("    - Condition between %s and %s\n",((CMolecule*)g_oaMolecules[g_iFixMol])->m_sName,((CMolecule*)g_oaMolecules[o->m_iShowMol])->m_sName);
3375
 
 
3376
 
                        if (g_bAggregation)
3377
 
                        {
3378
 
                                mprintf("    - Aggregation functions - %d value sets:\n",o->m_pDACF->m_oaSubDACFs.GetSize());
3379
 
                                for (z3=0;z3<o->m_pDACF->m_oaSubDACFs.GetSize();z3++)
3380
 
                                        mprintf("      > %s\n",((CDACFSub*)o->m_pDACF->m_oaSubDACFs[z3])->m_sName);
3381
 
                        }
3382
 
 
3383
 
                        if (g_bNbExchange)
3384
 
                        {
3385
 
                                mprintf("    - Neighborhood exchange functions:\n");
3386
 
                                for (z3=0;z3<o->m_pDACF->m_oaSubDACFs.GetSize();z3++)
3387
 
                                        mprintf("      > %s\n",((CDACFSub*)o->m_pDACF->m_oaSubDACFs[z3])->m_sName);
3388
 
                        }
3389
 
 
3390
 
                        if (g_bRDyn)
3391
 
                                mprintf("    - Reorientation Dynamics: %s\n",o->m_pRDyn->m_sName);
3392
 
 
3393
 
                        if (g_bIRSpec)
3394
 
                                mprintf("    - IR Spectrum: %s\n",o->m_pIRSpec->m_sName);
3395
 
 
3396
 
                        if (g_bDens)
3397
 
                                mprintf("    - Density DF: %s\n",o->m_pDensityDF->m_sName);
3398
 
 
3399
 
                        if (g_bSDF)
3400
 
                                mprintf("    - SDF: %s\n",o->m_pSDF->m_sName);
3401
 
 
3402
 
                        if (g_bRevSDF)
3403
 
                                mprintf("    - Pseudo SDF: %s\n",o->m_pRevSDF->m_sName);
3404
 
 
3405
 
                        if (g_bNbAnalysis)
3406
 
                                mprintf("    - Neighborhood Analysis: %s\n",o->m_pNbAnalysis->m_sName);
3407
 
 
3408
 
                        if (g_bVACF)
3409
 
                                mprintf("    - VACF: %s\n",o->m_pVACF->m_sName);
3410
 
 
3411
 
                        if (g_bMSD)
3412
 
                                mprintf("    - MSD: %s\n",o->m_pMSD->m_sName);
3413
 
 
3414
 
                        if (g_bVHDF)
3415
 
                                mprintf("    - VHDF: %s\n",o->m_pVHDF->m_sName);
3416
 
 
3417
 
                        if (g_bCDF)
3418
 
                        {
3419
 
                                mprintf("    - Combined Distribution Function:\n");
3420
 
                                for (z3=0;z3<g_iCDFChannels;z3++)
3421
 
                                {
3422
 
                                        if (o->m_pRDF[z3] != NULL)
3423
 
                                                mprintf("      - Channel %d: RDF: %s\n",z3+1,o->m_pRDF[z3]->m_sName);
3424
 
                                        if (o->m_pADF[z3] != NULL)
3425
 
                                                mprintf("      - Channel %d: ADF: %s\n",z3+1,o->m_pADF[z3]->m_sName);
3426
 
                                        if (o->m_pDDF[z3] != NULL)
3427
 
                                                mprintf("      - Channel %d: DDF: %s\n",z3+1,o->m_pDDF[z3]->m_sName);
3428
 
                                        if (o->m_pDipDF[z3] != NULL)
3429
 
                                                mprintf("      - Channel %d: DipDF: %s\n",z3+1,o->m_pDipDF[z3]->m_sName);
3430
 
                                        if (o->m_pVDF[z3] != NULL)
3431
 
                                                mprintf("      - Channel %d: VDF: %s\n",z3+1,o->m_pVDF[z3]->m_sName);
3432
 
                                        if (o->m_pPlDF[z3] != NULL)
3433
 
                                                mprintf("      - Channel %d: PlDF: %s\n",z3+1,o->m_pPlDF[z3]->m_sName);
3434
 
                                        if (o->m_pLiDF[z3] != NULL)
3435
 
                                                mprintf("      - Channel %d: LiDF: %s\n",z3+1,o->m_pLiDF[z3]->m_sName);
3436
 
                                }
3437
 
                        } else
3438
 
                        {
3439
 
                                if (g_bRDF)
3440
 
                                        mprintf("    - RDF: %s\n",o->m_pRDF[0]->m_sName);
3441
 
                                if (g_bDipDF)
3442
 
                                        mprintf("    - DipDF: %s\n",o->m_pDipDF[0]->m_sName);
3443
 
                                if (g_bADF)
3444
 
                                        mprintf("    - ADF: %s\n",o->m_pADF[0]->m_sName);
3445
 
                                if (g_bDDF)
3446
 
                                        mprintf("    - DDF: %s\n",o->m_pDDF[0]->m_sName);
3447
 
                                if (g_bVDF)
3448
 
                                        mprintf("    - VDF: %s\n",o->m_pVDF[0]->m_sName);
3449
 
                                if (g_bPlDF)
3450
 
                                        mprintf("    - PlDF: %s\n",o->m_pPlDF[0]->m_sName);
3451
 
                                if (g_bLiDF)
3452
 
                                        mprintf("    - LiDF: %s\n",o->m_pLiDF[0]->m_sName);
3453
 
                        }
3454
 
                }
3455
 
                mprintf(WHITE,"\n<<< End of Observation List <<<\n\n");
3456
 
        }
3457
 
_endobs:
3458
 
 
3459
 
        if (g_bVACF && g_bGlobalVACF)
3460
 
        {
3461
 
                try { g_pGlobalVACF = new CACF(); } catch(...) { g_pGlobalVACF = NULL; }
3462
 
                if (g_pGlobalVACF == NULL) NewException((double)sizeof(CACF),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3463
 
                
3464
 
                mprintf(WHITE,"\n>>> Global velocity autocorrelation function >>>\n\n");
3465
 
                g_pGlobalVACF->Parse();
3466
 
                mprintf(WHITE,"\n<<< End of global velocity autocorrelation function <<<\n\n");
3467
 
        }
3468
 
 
3469
 
        if (g_bIRSpec && g_bGlobalIR)
3470
 
        {
3471
 
                try { g_pGlobalIR = new CReorDyn(); } catch(...) { g_pGlobalIR = NULL; }
3472
 
                if (g_pGlobalIR == NULL) NewException((double)sizeof(CReorDyn),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3473
 
                
3474
 
                mprintf(WHITE,"\n*** Definition of system-wide IR spectrum ***\n\n");
3475
 
                g_pGlobalIR->ParseSpec();
3476
 
        }
3477
 
 
3478
 
        if (g_bSDF || g_bVoidSDF || g_bCreateRevSDF)
3479
 
        {
3480
 
                g_iSDFSmoothGrade = AskInteger("    Up to which degree should the SDFs be smoothened (0=not at all)? [3] ",3);
3481
 
 
3482
 
                if (g_bSDF)
3483
 
                {
3484
 
_sdf_norm_again:
3485
 
                        g_bSDFUniform = AskYesNo("    Calculate SDF values in nm^-3 (n) or relative to uniform density (y)? [no] ",false);
3486
 
                        if (g_bSDFUniform && ((!g_bPeriodicX) || (!g_bPeriodicY) || (!g_bPeriodicZ)))
3487
 
                        {
3488
 
                                eprintf("\n    Error: Uniform particle density is only defined for XYZ-periodic systems.\n\n");
3489
 
                                goto _sdf_norm_again;
3490
 
                        }
3491
 
                }
3492
 
//                      g_iSDFScale = AskRangeInteger("    SDF values in ppm (1), pm^-3 (2), nm^-3 (3) or rel. to uniform density (4)? [4] ",1,4,4) - 1;
3493
 
//                      g_iSDFScale = 2; // nm^-3
3494
 
        } else if (g_bCDF && (g_iCDFChannels == 3))
3495
 
                g_iSDFSmoothGrade = AskInteger("    Up to which degree should the 3D CDFs be smoothened (0=not at all)? [3] ",3);
3496
 
 
3497
 
//      if (g_bVDF || g_bSVDF)
3498
 
//              g_bSaveVelForce = AskYesNo("    Save maximum/averaged velocity time development (y/n)? [yes] ",true);
3499
 
 
3500
 
//      if (g_bVDF || g_bFDF)
3501
 
//      {
3502
 
//              g_fVelPercentage = AskFloat("    Which percentage of all velocities/forces to take into account? [95] ",95.0f);
3503
 
//              g_fForcePercentage = g_fVelPercentage;
3504
 
//      }
3505
 
        g_bSaveVelForce = false;
3506
 
 
3507
 
        if ((g_bSDF && g_bAdvanced2) || g_bSaveRefEnv || g_bCutCluster || g_bSaveJustTraj)
3508
 
        {
3509
 
                mprintf(WHITE,"\n>>> Coordinate output options >>>\n\n");
3510
 
 
3511
 
                if (g_bAdvanced2)
3512
 
                        g_bWriteAtomwise = (AskRangeInteger("    Sort output coordinates after molecules (0) or after elements (1)? [molecules] ",0,1,0)!=0);
3513
 
                                else g_bWriteAtomwise = false;
3514
 
 
3515
 
                g_bSaveVirtAtoms = AskYesNo("    Save also virtual atoms (y/n)? [no] ",false);
3516
 
 
3517
 
                if (g_bSaveVirtAtoms)
3518
 
                {
3519
 
                        if (AskYesNo("    Ref.Env.: Use alias names (instead of #) for virtual atoms (y/n)? [no] ",false))
3520
 
                        {
3521
 
                                for (z2=0;z2<g_oaMolecules.GetSize();z2++)
3522
 
                                {
3523
 
                                        CMolecule *m = (CMolecule*)g_oaMolecules[z2];
3524
 
                                        for (z=0;z<m->m_baAtomIndex.GetSize();z++)
3525
 
                                        {
3526
 
                                                if (m->m_baAtomIndex[z] != g_iVirtAtomType)
3527
 
                                                        continue;
3528
 
                                                for (z3=0;z3<m->m_waAtomCount[z];z3++)
3529
 
                                                {
3530
 
                                                        mprintf("    How to name atom #%d in %s? [#%d] ",z3+1,m->m_sName,z3+1);
3531
 
                                                        inpprintf("! How to name atom #%d in %s? [#%d]\n",z3+1,m->m_sName,z3+1);
3532
 
                                                        myget(buf);
3533
 
                                                        if (strlen(buf) != 0)
3534
 
                                                                strcpy(((CVirtualAtom*)g_oaVirtualAtoms[m->m_laVirtualAtoms[z3]])->m_sLabel,buf);
3535
 
                                                }
3536
 
                                        }
3537
 
                                }
3538
 
                        }
3539
 
                }
3540
 
 
3541
 
                if (g_bSaveRefEnv || g_bCutCluster)
3542
 
                        g_bEnvWriteDetailedInfo = AskYesNo("    Write detailed (long) comment lines into output xyz file (y/n)? [yes] ",true);
3543
 
                                else g_bEnvWriteDetailedInfo = false;
3544
 
 
3545
 
                if ((g_bSaveRefEnv || g_bCutCluster) && !g_bEnvDisableSortNb)
3546
 
                        g_bEnvSortNb = AskYesNo("    Sort molecules according to distance from reference molecule (y/n)? [yes] ",true);
3547
 
                                else g_bEnvSortNb = false;
3548
 
 
3549
 
                mprintf(WHITE,"\n<<< End of Coordinate output options <<<\n\n");
3550
 
        } else
3551
 
        {
3552
 
                g_bWriteAtomwise = false;
3553
 
                g_bSaveVirtAtoms = false;
3554
 
        }
3555
 
 
3556
 
        if (g_bSaveRefEnv || g_bCutCluster)
3557
 
                g_bCenterZero = AskYesNo("    Put the center of the system to (0|0|0) (y) or to (x/2|y/2|z/2) (n)? [yes] ",true);
3558
 
 
3559
 
        g_bMiddleAvg = false;
3560
 
        g_iSwapAtoms = 0;
3561
 
 
3562
 
        if (g_bSaveJustTraj)
3563
 
        {
3564
 
                mprintf(WHITE,"\n>>> Process Trajectory >>>\n\n");
3565
 
 
3566
 
                if (g_bAdvanced2)
3567
 
                        g_bSaveTrajNoRot = AskYesNo("    Remove angular momentum from trajectory (y/n)? [no] ",false);
3568
 
                                else g_bSaveTrajNoRot = false;
3569
 
 
3570
 
                if (g_bSaveTrajNoRot)
3571
 
                {
3572
 
                        mprintf("\n    This centers the mass center of the system. All atoms of the system are saved.\n\n");
3573
 
                        g_bSaveCoordsUnchanged = false;
3574
 
                        g_bSaveJustCenter = false;
3575
 
                        if(AskYesNo("    Put the center of the system to (0|0|0) (y) or to (x/2|y/2|z/2) (n)? [yes] ",true))
3576
 
                                g_bCenterZero = true;
3577
 
                                        else g_bCenterZero = false;
3578
 
                        goto _norot;
3579
 
                } else
3580
 
                {
3581
 
                        switch(AskRangeInteger("    Put the center of the system to (0|0|0) (0), to (x/2|y/2|z/2) (1), or leave coords unchanged (2)? [1] ",0,2,1))
3582
 
                        {
3583
 
                                case 0:
3584
 
                                        g_bCenterZero = true;
3585
 
                                        g_bSaveCoordsUnchanged = false;
3586
 
                                        break;
3587
 
                                case 1:
3588
 
                                        g_bCenterZero = false;
3589
 
                                        g_bSaveCoordsUnchanged = false;
3590
 
                                        break;
3591
 
                                case 2:
3592
 
                                        g_bSaveCoordsUnchanged = true;
3593
 
                                        break;
3594
 
                        }
3595
 
 
3596
 
                        if (!g_bSaveCoordsUnchanged)
3597
 
                                g_bSaveJustCenter = AskYesNo("\n    Put a specific atom into the box center (y/n)? [no] ",false);
3598
 
                                        else g_bSaveJustCenter = false;
3599
 
                }
3600
 
 
3601
 
                if (g_bSaveJustCenter)
3602
 
                {
3603
 
                        if (g_oaMolecules.GetSize() > 1)
3604
 
                        {
3605
 
                                sprintf(buf,"    Choose center atom from which of the molecules (");
3606
 
                                for (z=0;z<g_oaMolecules.GetSize();z++)
3607
 
                                {
3608
 
                                        sprintf(buf2,"%s=%d",((CMolecule*)g_oaMolecules[z])->m_sName,z+1);
3609
 
                                        strcat(buf,buf2);
3610
 
                                        if (z < g_oaMolecules.GetSize()-1)
3611
 
                                                strcat(buf,", ");
3612
 
                                }
3613
 
                                strcat(buf,")? ");
3614
 
                                g_iSaveJustMol = AskRangeInteger_ND(buf,1,g_oaMolecules.GetSize()) - 1;
3615
 
                        } else
3616
 
                        {
3617
 
                                g_iSaveJustMol = 0;
3618
 
                                mprintf("    Choosing center atom from %s.\n",((CMolecule*)g_oaMolecules[0])->m_sName);
3619
 
                        }
3620
 
                        if (((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_laSingleMolIndex.GetSize() > 1)
3621
 
                                g_iSaveJustSM = AskRangeInteger("    Take which representant from %s (1-%d)? [1] ",1,((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_laSingleMolIndex.GetSize(),1,((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_sName,((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_laSingleMolIndex.GetSize()) - 1;
3622
 
                                        else g_iSaveJustSM = 0;
3623
 
_proccenter:
3624
 
                        AskString("    Which atom from %s %d to put into the box center? [#2] ",buf,"#2",((CMolecule*)g_oaMolecules[g_iSaveJustMol])->m_sName,g_iSaveJustSM+1);
3625
 
                        if (!ParseAtom(buf,g_iSaveJustMol,g_iSaveJustAtomType,g_iSaveJustRealAtomType,g_iSaveJustAtom))
3626
 
                                goto _proccenter;
3627
 
                }
3628
 
                g_iSaveGesAtoms = 0;
3629
 
                if (!AskYesNo("    Save all atoms in the system (y/n)? [yes] ",true))
3630
 
                {
3631
 
                        mprintf("\n");
3632
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
3633
 
                        {
3634
 
                                if (AskYesNo("    Save (some/all) atoms from molecule %s (y/n)? [yes] ",true,((CMolecule*)g_oaMolecules[z])->m_sName))
3635
 
                                {
3636
 
                                        try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
3637
 
                                        if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3638
 
                                        
3639
 
                                        g_oaSaveMolecules.Add(ag);
3640
 
_savejust1:                     mprintf("    Which atoms to save from %s (e.g. \"C1,C3-5,H\")? [all] ",((CMolecule*)g_oaMolecules[z])->m_sName);
3641
 
                                        inpprintf("! Which atoms to save from %s (e.g. \"C1,C3-5,H\")? [all]\n",((CMolecule*)g_oaMolecules[z])->m_sName);
3642
 
                                        myget(buf);
3643
 
                                        if (strlen(buf)==0)
3644
 
                                                ag->AddAllAtoms((CMolecule*)g_oaMolecules[z],g_bSaveVirtAtoms);
3645
 
                                                        else if (!ag->ParseAtoms((CMolecule*)g_oaMolecules[z],buf))
3646
 
                                                                goto _savejust1;
3647
 
                                        g_iSaveGesAtoms += ag->m_iAtomGes * ((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();
3648
 
                                }
3649
 
                        }
3650
 
                } else
3651
 
                {
3652
 
_norot:
3653
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
3654
 
                        {
3655
 
                                try { ag = new CAtomGroup(); } catch(...) { ag = NULL; }
3656
 
                                if (ag == NULL) NewException((double)sizeof(CAtomGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3657
 
 
3658
 
                                g_oaSaveMolecules.Add(ag);
3659
 
                                ag->AddAllAtoms((CMolecule*)g_oaMolecules[z],g_bSaveVirtAtoms);
3660
 
                                g_iSaveGesAtoms += ag->m_iAtomGes * ((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();
3661
 
                        }
3662
 
                }
3663
 
 
3664
 
                if (g_bUnknownElements)
3665
 
                {
3666
 
                        g_bUnwrapWannier = AskYesNo("    Write out Wannier centers together with trajectory (y/n)? [no] ",false);
3667
 
 
3668
 
                        if (g_bUnwrapWannier)
3669
 
                                ParseDipole();
3670
 
 
3671
 
                } else g_bUnwrapWannier = false;
3672
 
 
3673
 
                if ((!g_bSaveCoordsUnchanged) && (!g_bSaveTrajNoRot))
3674
 
                        g_bUnwrap = AskYesNo("    Try to unwrap the trajectory (y/n)? [no] ",false);
3675
 
                                else g_bUnwrap = false;
3676
 
 
3677
 
                if (g_bUnwrap)
3678
 
                        mprintf("\n    Attention! This feature only works if the time step\n    in the trajectory is quite small. One particle may never\n    move further than half of the box length in one time step!\n");
3679
 
 
3680
 
                mprintf("\nSaving %d atoms per step:\n",g_iSaveGesAtoms);
3681
 
                for (z2=0;z2<g_oaSaveMolecules.GetSize();z2++)
3682
 
                {
3683
 
                        ag = (CAtomGroup*)g_oaSaveMolecules[z2];
3684
 
                        mprintf("  - In %s: ",ag->m_pMolecule->m_sName);
3685
 
                        for (z=0;z<ag->m_baAtomType.GetSize();z++)
3686
 
                        {
3687
 
                                for (z3=0;z3<((CxIntArray*)ag->m_oaAtoms[z])->GetSize();z3++)
3688
 
                                {
3689
 
                                        mprintf("%s%d",((CAtom*)g_oaAtoms[ag->m_baRealAtomType[z]])->m_sName,((CxIntArray*)ag->m_oaAtoms[z])->GetAt(z3)+1);
3690
 
                                        if (z3 < ((CxIntArray*)ag->m_oaAtoms[z])->GetSize()-1)
3691
 
                                                mprintf(", ");
3692
 
                                }
3693
 
                                if (z+1 < ag->m_baAtomType.GetSize())
3694
 
                                        mprintf(", ");
3695
 
                        }
3696
 
                        mprintf("\n");
3697
 
                }
3698
 
//              g_bTrajAtomwise = (AskRangeInteger("\n    Save trajectory ordered molecule-wise (0) or atom-wise (1)? [0] ",0,1,0)!=0);
3699
 
                mprintf(WHITE,"\n<<<< End of Process Trajectory <<<\n\n");
3700
 
        } else g_bUnwrap = false;
3701
 
 
3702
 
        if (g_bUnwrap)
3703
 
        {
3704
 
                g_vaUnwrapArray.SetSize(g_oaSingleMolecules.GetSize());
3705
 
                for (z=0;z<g_vaUnwrapArray.GetSize();z++)
3706
 
                        g_vaUnwrapArray[z] = 0;
3707
 
        }
3708
 
 
3709
 
        if (g_bReact)
3710
 
        {
3711
 
                try { g_pReact = new CReact(); } catch(...) { g_pReact = NULL; }
3712
 
                if (g_pReact == NULL) NewException((double)sizeof(CReact),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3713
 
                
3714
 
                g_pReact->Parse();
3715
 
                g_bFold = false;
3716
 
//              g_bSilentProgress = true;
3717
 
        }
3718
 
 
3719
 
        g_iBinning = 2;
3720
 
 
3721
 
        if (g_bPeriodic && (g_bSDF || g_bSaveRefEnv || g_bCutCluster || g_bRevSDF) && (!g_bUnwrap))
3722
 
        {
3723
 
                g_bFold = true;
3724
 
                mprintf("\n    Wrapping molecules into the box.\n");
3725
 
        } else if (g_bSaveJustTraj && !g_bSaveTrajNoRot && !g_bUnwrap)
3726
 
        {
3727
 
                if (g_bPeriodic && (!g_bUnwrap) && (!g_bSaveCoordsUnchanged))
3728
 
                {
3729
 
                        g_bFold = AskYesNo("\n    Wrap the molecules into the box (y/n)? [yes] ",true);
3730
 
                } else
3731
 
                {
3732
 
                        mprintf("\n    Not wrapping molecules into the box.\n");
3733
 
                        g_bFold = false;
3734
 
                }
3735
 
        } else
3736
 
        {
3737
 
                g_bFold = false;
3738
 
                mprintf("\n    Not wrapping molecules into the box.\n");
3739
 
        }
3740
 
 
 
3738
                                                g_bWriteAtomwise = false;
 
3739
                                                g_bWriteInputOrder = true;
 
3740
                                                break;
 
3741
                                        default:
 
3742
                                                eprintf("Should never happen ^^\n");
 
3743
                                                abort();
 
3744
                                }
 
3745
                        } else 
 
3746
                        {
 
3747
                                g_bWriteAtomwise = (AskRangeInteger("    Sort output coordinates by molecules (0) or by element types (1)? [0] ",0,1,0)!=0);
 
3748
                                g_bWriteInputOrder = false;
 
3749
                        }
 
3750
                } else
 
3751
                {
 
3752
                        g_bWriteAtomwise = false;
 
3753
                        g_bWriteInputOrder = false;
 
3754
                }
 
3755
 
 
3756
                mprintf(WHITE,"\n<<<< End of Process Trajectory <<<\n\n");
 
3757
        } else g_bUnwrap = false;
 
3758
 
 
3759
        if (g_bUnwrap)
 
3760
        {
 
3761
                g_vaUnwrapArray.SetSize(g_oaSingleMolecules.GetSize());
 
3762
                for (z=0;z<g_vaUnwrapArray.GetSize();z++)
 
3763
                        g_vaUnwrapArray[z] = 0;
 
3764
        }
 
3765
 
 
3766
        if (g_bReact)
 
3767
        {
 
3768
                try { g_pReact = new CReact(); } catch(...) { g_pReact = NULL; }
 
3769
                if (g_pReact == NULL) NewException((double)sizeof(CReact),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3770
                
 
3771
                g_pReact->Parse();
 
3772
                g_bFold = false;
 
3773
//              g_bSilentProgress = true;
 
3774
        }
 
3775
 
 
3776
        g_iBinning = 2;
 
3777
 
 
3778
        if (g_bPeriodic && (g_bSDF || g_bPlProj || g_bSaveRefEnv || g_bCutCluster || g_bRevSDF) && (!g_bUnwrap))
 
3779
        {
 
3780
                g_bFold = true;
 
3781
//              mprintf("\n    Wrapping molecules into the box.\n");
 
3782
        } else if (g_bSaveJustTraj && !g_bSaveTrajNoRot && !g_bUnwrap)
 
3783
        {
 
3784
                if (g_bPeriodic && (!g_bUnwrap) && (!g_bSaveCoordsUnchanged))
 
3785
                {
 
3786
                        g_bFold = AskYesNo("\n    Wrap the molecules into the box (y/n)? [yes] ",true);
 
3787
                } else
 
3788
                {
 
3789
//                      mprintf("\n    Not wrapping molecules into the box.\n");
 
3790
                        g_bFold = false;
 
3791
                }
 
3792
        } else
 
3793
        {
 
3794
                g_bFold = false;
 
3795
//              mprintf("\n    Not wrapping molecules into the box.\n");
 
3796
        }
 
3797
 
3741
3798
        if (g_bAdvanced2 && g_bFold)
3742
 
                g_bFoldAtomwise = (AskRangeInteger("    Wrap molecule-wise (0) or atom-wise (1)? [0] ",0,1,0)!=0);
3743
 
                        else g_bFoldAtomwise = false;
3744
 
 
3745
 
        if (g_bMSD || g_bPairMSD || g_bSaveJustTraj || g_bACF || (g_bIRSpec && g_bDipoleRefFixed) || g_bVHDF/* || g_bThermo*/)
3746
 
        {
3747
 
                if (g_bUnwrap)
3748
 
                        g_bRemoveCOM = AskYesNo("    Remove center of mass movement of the MD box (y/n)? [no] ",false);
3749
 
                                else g_bRemoveCOM = AskYesNo("    Remove center of mass movement of the MD box (y/n)? [yes] ",true);
3750
 
        } else g_bRemoveCOM = false;
3751
 
 
3752
 
        if (g_bUseVelocities && (g_fTimestepLength > 1.0))
3753
 
        {
3754
 
                mprintf(RED,"\n    Warning: ");
3755
 
                mprintf("Atom velocities are obtained from positions by numerical differentiation.\n");
3756
 
                mprintf("             This is only reliable for trajectory timestep distances <= approx. 1 fs.\n");
3757
 
                mprintf("             Your timestep distance is %.2f fs, which is larger than 1 fs.\n\n",g_fTimestepLength);
3758
 
 
3759
 
                if (!AskYesNo("    Proceed anyway (y/n)? [yes] ",true))
3760
 
                        return false;
3761
 
        }
3762
 
 
3763
 
        if (g_TimeStep.GetCommentNumberCount() > 0)
3764
 
        {
3765
 
                g_bSkipDoubleSteps = AskYesNo("    Skip repeated time steps (y/n)? [no] ",false);
3766
 
                if (g_bSkipDoubleSteps)
3767
 
                {
3768
 
                        mprintf("\n");
3769
 
                        mprintf("    The comment line is \"%s\".\n",g_TimeStep.m_pComment);
3770
 
                        if (g_TimeStep.GetCommentNumberCount() > 1)
3771
 
                        {
3772
 
                                if (!AskYesNo("    Does this line contain the time step number (y/n)? [yes] ",true))
3773
 
                                        g_bSkipDoubleSteps = false;
3774
 
                                if (g_bSkipDoubleSteps)
3775
 
                                {
3776
 
                                        sprintf(buf,"    Choose the time step number: ");
3777
 
                                        for (z=0;z<g_TimeStep.GetCommentNumberCount();z++)
3778
 
                                                if (z < g_TimeStep.GetCommentNumberCount()-1)
3779
 
                                                {
3780
 
                                                        sprintf(buf2,"%ld (%d), ",g_TimeStep.ExtractNumber(z),z+1);
3781
 
                                                        strcat(buf,buf2);
3782
 
                                                } else
3783
 
                                                {
3784
 
                                                        sprintf(buf2,"%ld (%d)",g_TimeStep.ExtractNumber(z),z+1);
3785
 
                                                        strcat(buf,buf2);
3786
 
                                                }
3787
 
                                        strcat(buf," [1] ");
3788
 
                                        g_iNumberPos = AskRangeInteger(buf,1,g_TimeStep.GetCommentNumberCount(),1) - 1;
3789
 
                                } else
3790
 
                                {
3791
 
                                        if (!AskYesNo("    Is %d the time step number of the first time step (y/n)? [yes] ",true,g_TimeStep.ExtractNumber(0)))
3792
 
                                                g_bSkipDoubleSteps = false;
3793
 
                                }
3794
 
                                if (!g_bSkipDoubleSteps)
3795
 
                                        mprintf("    NOT skipping repeated time steps.\n");
3796
 
                        }
3797
 
                        mprintf("\n");
3798
 
                }
3799
 
        }
3800
 
 
3801
 
        if (g_bAdvanced2)
3802
 
        {
3803
 
                if (AskYesNo("    Perform a multi-interval analysis (y/n)? [no] ",false))
3804
 
                {
3805
 
                        g_bMultiInterval = true;
3806
 
                        if (AskYesNo("    Use equidistant intervals (y) or enter data manually (n)? [yes] ",true))
3807
 
                        {
3808
 
                                g_iMultiIntervalBegin = AskUnsignedInteger("    In which time step to start processing the trajectory? [1] ",1) - 1;
3809
 
                                if (g_iMultiIntervalBegin == -1)
3810
 
                                        g_iMultiIntervalBegin = 0;
3811
 
                                ti = AskUnsignedInteger("    How many intervals to create? [5] ",5);
3812
 
                                if (g_iTrajSteps != -1)
3813
 
                                {
3814
 
                                        g_iMultiIntervalStride = AskUnsignedInteger("    Start a new interval each n-th step? [%d] ",g_iTrajSteps/ti,g_iTrajSteps/ti);
3815
 
                                        g_iMultiIntervalLength = AskUnsignedInteger("    Enter the length in steps of one interval: [%d] ",g_iTrajSteps/ti,g_iTrajSteps/ti);
3816
 
                                } else
3817
 
                                {
3818
 
                                        g_iMultiIntervalStride = AskUnsignedInteger("    Start a new interval each n-th step? [%d] ",10000/ti,10000/ti);
3819
 
                                        g_iMultiIntervalLength = AskUnsignedInteger("    Enter the length in steps of one interval: [%d] ",10000/ti,10000/ti);
3820
 
                                }
3821
 
                                for (z=0;z<ti;z++)
3822
 
                                {
3823
 
                                        g_laMultiIntervalStart.Add(g_iMultiIntervalBegin+z*g_iMultiIntervalStride);
3824
 
                                        g_laMultiIntervalEnd.Add(g_iMultiIntervalBegin+z*g_iMultiIntervalStride+g_iMultiIntervalLength);
3825
 
                                }
3826
 
                        } else
3827
 
                        {
3828
 
        _intervalagain:
3829
 
                                ti = AskInteger("    Enter starting time step of %d. interval: [quit] ",-1,g_laMultiIntervalStart.GetSize()+1);
3830
 
                                if (ti == 0)
3831
 
                                {
3832
 
                                        eprintf("Please enter a number >= 1.\n");
3833
 
                                        goto _intervalagain;
3834
 
                                }
3835
 
                                if (ti != -1)
3836
 
                                {
3837
 
                                        g_laMultiIntervalStart.Add(ti-1);
3838
 
                                        g_laMultiIntervalEnd.Add(AskUnsignedInteger_ND("    Enter ending time step of %d. interval: ",g_laMultiIntervalStart.GetSize())-1);
3839
 
                                        goto _intervalagain;
3840
 
                                }
3841
 
                        }
3842
 
                        mprintf(WHITE,"\n* %d Intervals have been defined:\n",g_laMultiIntervalStart.GetSize());
3843
 
                        for (z=0;z<g_laMultiIntervalStart.GetSize();z++)
3844
 
                                mprintf("  - Interval %2d: Steps %6d - %6d.\n",z+1,g_laMultiIntervalStart[z]+1,g_laMultiIntervalEnd[z]+1);
3845
 
                        mprintf("\n");
3846
 
                } else goto _nomulti;
3847
 
        } else
3848
 
        {
3849
 
_nomulti:
3850
 
                g_iBeginStep = AskUnsignedInteger("    In which time step to start processing the trajectory? [1] ",1) - 1;
3851
 
                if (g_iBeginStep == -1)
3852
 
                        g_iBeginStep = 0;
3853
 
                g_iMaxStep = AskUnsignedInteger("    How many time steps to use (from this position on)? [all] ",0);
3854
 
                if (g_iMaxStep == 0)
3855
 
                        g_iMaxStep = -1; // Alle verwenden
3856
 
        }
3857
 
        g_iStride = AskUnsignedInteger("    Use every n-th time step from the trajectory? [1] ",1);
3858
 
 
3859
 
        if (g_iTrajSteps != -1)
3860
 
        {
3861
 
                if (g_iMaxStep == -1)
3862
 
                        mprintf(YELLOW,"\n    Using %d time steps: Every %d%s within range %d - approx. %d.\n",(g_iTrajSteps-g_iBeginStep)/g_iStride,g_iStride,(g_iStride==1)?"st":"th",g_iBeginStep+1,g_iTrajSteps);
3863
 
                else mprintf(YELLOW,"\n    Using %d time steps: Every %d%s within range %d - %d.\n",g_iMaxStep/g_iStride,g_iStride,(g_iStride==1)?"st":"th",g_iBeginStep+1,g_iBeginStep+g_iMaxStep);
3864
 
        } else if (g_iMaxStep != -1)
3865
 
                mprintf(YELLOW,"\n    Using %d time steps: Every %d%s within range %d - %d.\n",g_iMaxStep/g_iStride,g_iStride,(g_iStride==1)?"st":"th",g_iBeginStep+1,g_iBeginStep+g_iMaxStep);
3866
 
                        else mprintf(YELLOW,"\n    Using every %d%s time step beginning from step %d.\n",g_iStride,(g_iStride==1)?"st":"th",g_iBeginStep+1);
3867
 
 
3868
 
        ti = -1;                                                                                                                                                                                                                                
3869
 
        if (g_iTrajSteps != -1)                                                                                                                                                                                                                 
3870
 
        {                                                                                                                                                                                                                                       
3871
 
                if (g_iMaxStep == -1)                                                                                                                                                                                                           
3872
 
                        ti = (g_iTrajSteps-g_iBeginStep)/g_iStride;                                                                                                                                                                             
3873
 
                                else ti = g_iMaxStep/g_iStride;                                                                                                                                                                                 
3874
 
        } else if (g_iMaxStep != -1)                                                                                                                                                                                                             
3875
 
                ti = g_iMaxStep/g_iStride;                                                                                                                                                                                                      
3876
 
                                                                                                                                                                                                                                        
3877
 
        if (ti >= 0)                                                                                                                                                                                                                            
3878
 
        {                                                                                                                                                                                                                                       
3879
 
                if (g_bMSD)                                                                                                                                                                                                                     
3880
 
                {                                                                                                                                                                                                                               
3881
 
                        for (z=0;z<g_oaObserv.GetSize();z++)                                                                                                                                                                                    
3882
 
                        {                                                                                                                                                                                                                       
3883
 
                                o = (CObservation*)g_oaObserv[z];                                                                                                                                                                               
3884
 
                                if (o->m_pMSD->m_iResolution > ti)                                                                                                                                                                              
3885
 
                                {                                                                                                                                                                                                               
3886
 
                                        eprintf("\n    MSD resolution of %d requires at least %d time steps, but using only %d steps.\n    This will lead to erroneous results!\n\n",o->m_pMSD->m_iResolution,o->m_pMSD->m_iResolution,ti);     
3887
 
                                        if (!AskYesNo("    Continue anyway (y/n)? [yes] ",true))                                                                                                                                                
3888
 
                                                return false;                                                                                                                                                                                   
3889
 
                                        goto _lessstepdone;                                                                                                                                                                                     
3890
 
                                }                                                                                                                                                                                                               
3891
 
                        }                                                                                                                                                                                                                       
3892
 
                }                                                                                                                                                                                                                               
3893
 
                if (g_bRDyn)                                                                                                                                                                                                                     
3894
 
                {                                                                                                                                                                                                                               
3895
 
                        for (z=0;z<g_oaObserv.GetSize();z++)                                                                                                                                                                                    
3896
 
                        {                                                                                                                                                                                                                       
3897
 
                                o = (CObservation*)g_oaObserv[z];                                                                                                                                                                               
3898
 
                                if (o->m_pRDyn->m_iDepth*o->m_pRDyn->m_iStride > ti)                                                                                                                                                                              
3899
 
                                {                                                                                                                                                                                                               
3900
 
                                        eprintf("\n    Reorientation dynamics resolution of %d requires at least %d time steps, but using only %d steps.\n    This will lead to erroneous results!\n\n",o->m_pRDyn->m_iDepth*o->m_pRDyn->m_iStride,o->m_pRDyn->m_iDepth*o->m_pRDyn->m_iStride,ti);     
3901
 
                                        if (!AskYesNo("    Continue anyway (y/n)? [yes] ",true))                                                                                                                                                
3902
 
                                                return false;                                                                                                                                                                                   
3903
 
                                        goto _lessstepdone;                                                                                                                                                                                     
3904
 
                                }                                                                                                                                                                                                               
3905
 
                        }                                                                                                                                                                                                                       
3906
 
                }                                                                                                                                                                                                                               
3907
 
                if (g_bIRSpec)                                                                                                                                                                                                                     
3908
 
                {                                                                                                                                                                                                                               
3909
 
                        for (z=0;z<g_oaObserv.GetSize();z++)                                                                                                                                                                                    
3910
 
                        {                                                                                                                                                                                                                       
3911
 
                                o = (CObservation*)g_oaObserv[z];                                                                                                                                                                               
3912
 
                                if (o->m_pIRSpec->m_iDepth*o->m_pIRSpec->m_iStride > ti)                                                                                                                                                                              
3913
 
                                {                                                                                                                                                                                                               
3914
 
                                        eprintf("\n    IR spectrum resolution of %d requires at least %d time steps, but using only %d steps.\n    This will lead to erroneous results!\n\n",o->m_pIRSpec->m_iDepth*o->m_pIRSpec->m_iStride,o->m_pIRSpec->m_iDepth*o->m_pIRSpec->m_iStride,ti);     
3915
 
                                        if (!AskYesNo("    Continue anyway (y/n)? [yes] ",true))                                                                                                                                                
3916
 
                                                return false;                                                                                                                                                                                   
3917
 
                                        goto _lessstepdone;                                                                                                                                                                                     
3918
 
                                }                                                                                                                                                                                                               
3919
 
                        }                                                                                                                                                                                                                       
3920
 
                }                                                                                                                                                                                                                               
3921
 
        }      
3922
 
_lessstepdone:
3923
 
 
3924
 
        if (g_bScanVelocities)
3925
 
        {
3926
 
                mprintf(WHITE,"\n>>> Velocity Pre-Analysis >>>\n\n");
3927
 
                g_iScanVelStart = AskUnsignedInteger("    Start in which time step for velocity pre-analysis? [0] ",0);
3928
 
                g_iScanVelSteps = AskUnsignedInteger("    Use how many time steps from this point on for vel. pre-analysis? [all] ",0);
3929
 
                g_iScanVelStride = AskUnsignedInteger("    Use every n-th step for velocity pre-analysis? [10] ",10);
3930
 
                mprintf(WHITE,"\n<<< End of Velocity Pre-Analysis <<<\n");
3931
 
        }
3932
 
 
3933
 
        if (g_bSaveRefEnv && (g_iNbhMode == 3))
3934
 
        {
3935
 
                mprintf(WHITE,"\n>>> Neighborhood Pre-Analysis >>>\n\n");
3936
 
                g_iScanNbhStart = AskUnsignedInteger("    Start in which time step for neighborhood analysis? [0] ",0);
3937
 
                g_iScanNbhSteps = AskUnsignedInteger("    Use how many time steps from this point on for nbh analysis? [all] ",0);
3938
 
                g_iScanNbhStride = AskUnsignedInteger("    Use every n-th step for the neighborhood analysis? [10] ",10);
3939
 
                mprintf(WHITE,"\n<<< End of Neighborhood Pre-Analysis <<<\n");
3940
 
        }
3941
 
 
3942
 
        mprintf(WHITE,"\n########## All information collected ##########\n\n");
3943
 
        BTOUT;
3944
 
        return true;
3945
 
}
3946
 
 
3947
 
 
 
3799
        {
 
3800
                if (g_bSDF || g_bPlProj)
 
3801
                        g_bFoldAtomwise = (AskRangeInteger("    Wrap molecule-wise (0) or atom-wise (1)? [1] ",0,1,1)!=0);
 
3802
                else
 
3803
                        g_bFoldAtomwise = (AskRangeInteger("    Wrap molecule-wise (0) or atom-wise (1)? [0] ",0,1,0)!=0);
 
3804
        } else
 
3805
        {
 
3806
                if (g_bSDF || g_bPlProj)
 
3807
                        g_bFoldAtomwise = true;
 
3808
                else
 
3809
                        g_bFoldAtomwise = false;
 
3810
        }
 
3811
 
 
3812
        if (g_bFold)
 
3813
        {
 
3814
                if (g_bFoldAtomwise)
 
3815
                        mprintf("\n    Wrapping molecules into the box (atom-wise).\n\n");
 
3816
                                else mprintf("\n    Wrapping molecules into the box (molecule-wise).\n\n");
 
3817
        } else mprintf("\n    Not wrapping molecules into the box.\n\n");
 
3818
 
 
3819
        if (g_bMSD || g_bPairMSD || g_bSaveJustTraj || g_bACF || (g_bIRSpec && g_bDipoleRefFixed) || g_bVHDF/* || g_bThermo*/)
 
3820
        {
 
3821
                if (g_bUnwrap)
 
3822
                        g_bRemoveCOM = AskYesNo("    Remove center of mass movement of the box (y/n)? [no] ",false);
 
3823
                                else g_bRemoveCOM = AskYesNo("    Remove center of mass movement of the box (y/n)? [yes] ",true);
 
3824
                mprintf("\n");
 
3825
        } else
 
3826
        {
 
3827
                mprintf("    Not removing center of mass movement of the box.\n\n");
 
3828
                g_bRemoveCOM = false;
 
3829
        }
 
3830
 
 
3831
        if (g_bUseVelocities && (g_fTimestepLength > 1.0))
 
3832
        {
 
3833
                mprintf(RED,"    Warning: ");
 
3834
                mprintf("Atom velocities are obtained from positions by numerical differentiation.\n");
 
3835
                mprintf("             This is only reliable for trajectory timestep distances <= approx. 1 fs.\n");
 
3836
                mprintf("             Your timestep distance is %.2f fs, which is larger than 1 fs.\n\n",g_fTimestepLength);
 
3837
 
 
3838
                if (!AskYesNo("    Proceed anyway (y/n)? [yes] ",true))
 
3839
                        return false;
 
3840
        }
 
3841
 
 
3842
        if (g_TimeStep.GetCommentNumberCount() > 0)
 
3843
        {
 
3844
                g_bSkipDoubleSteps = AskYesNo("    Skip repeated time steps (y/n)? [no] ",false);
 
3845
                if (g_bSkipDoubleSteps)
 
3846
                {
 
3847
                        mprintf("\n");
 
3848
                        mprintf("    The comment line is \"%s\".\n",g_TimeStep.m_pComment);
 
3849
                        if (g_TimeStep.GetCommentNumberCount() > 1)
 
3850
                        {
 
3851
                                if (!AskYesNo("    Does this line contain the time step number (y/n)? [yes] ",true))
 
3852
                                        g_bSkipDoubleSteps = false;
 
3853
                                if (g_bSkipDoubleSteps)
 
3854
                                {
 
3855
                                        sprintf(buf,"    Choose the time step number: ");
 
3856
                                        for (z=0;z<g_TimeStep.GetCommentNumberCount();z++)
 
3857
                                                if (z < g_TimeStep.GetCommentNumberCount()-1)
 
3858
                                                {
 
3859
                                                        sprintf(buf2,"%ld (%d), ",g_TimeStep.ExtractNumber(z),z+1);
 
3860
                                                        strcat(buf,buf2);
 
3861
                                                } else
 
3862
                                                {
 
3863
                                                        sprintf(buf2,"%ld (%d)",g_TimeStep.ExtractNumber(z),z+1);
 
3864
                                                        strcat(buf,buf2);
 
3865
                                                }
 
3866
                                        strcat(buf," [1] ");
 
3867
                                        g_iNumberPos = AskRangeInteger(buf,1,g_TimeStep.GetCommentNumberCount(),1) - 1;
 
3868
                                } else
 
3869
                                {
 
3870
                                        if (!AskYesNo("    Is %d the time step number of the first time step (y/n)? [yes] ",true,g_TimeStep.ExtractNumber(0)))
 
3871
                                                g_bSkipDoubleSteps = false;
 
3872
                                }
 
3873
                                if (!g_bSkipDoubleSteps)
 
3874
                                        mprintf("    NOT skipping repeated time steps.\n");
 
3875
                        }
 
3876
                        mprintf("\n");
 
3877
                }
 
3878
        }
 
3879
 
 
3880
        if (g_bAdvanced2)
 
3881
        {
 
3882
                if (AskYesNo("    Perform a multi-interval analysis (y/n)? [no] ",false))
 
3883
                {
 
3884
                        g_bMultiInterval = true;
 
3885
                        if (AskYesNo("    Use equidistant intervals (y) or enter data manually (n)? [yes] ",true))
 
3886
                        {
 
3887
                                g_iMultiIntervalBegin = AskUnsignedInteger("    In which time step to start processing the trajectory? [1] ",1) - 1;
 
3888
                                if (g_iMultiIntervalBegin == -1)
 
3889
                                        g_iMultiIntervalBegin = 0;
 
3890
                                ti = AskUnsignedInteger("    How many intervals to create? [5] ",5);
 
3891
                                if (g_iTrajSteps != -1)
 
3892
                                {
 
3893
                                        g_iMultiIntervalStride = AskUnsignedInteger("    Start a new interval each n-th step? [%d] ",g_iTrajSteps/ti,g_iTrajSteps/ti);
 
3894
                                        g_iMultiIntervalLength = AskUnsignedInteger("    Enter the length in steps of one interval: [%d] ",g_iTrajSteps/ti,g_iTrajSteps/ti);
 
3895
                                } else
 
3896
                                {
 
3897
                                        g_iMultiIntervalStride = AskUnsignedInteger("    Start a new interval each n-th step? [%d] ",10000/ti,10000/ti);
 
3898
                                        g_iMultiIntervalLength = AskUnsignedInteger("    Enter the length in steps of one interval: [%d] ",10000/ti,10000/ti);
 
3899
                                }
 
3900
                                for (z=0;z<ti;z++)
 
3901
                                {
 
3902
                                        g_laMultiIntervalStart.Add(g_iMultiIntervalBegin+z*g_iMultiIntervalStride);
 
3903
                                        g_laMultiIntervalEnd.Add(g_iMultiIntervalBegin+z*g_iMultiIntervalStride+g_iMultiIntervalLength);
 
3904
                                }
 
3905
                        } else
 
3906
                        {
 
3907
        _intervalagain:
 
3908
                                ti = AskInteger("    Enter starting time step of %d. interval: [quit] ",-1,g_laMultiIntervalStart.GetSize()+1);
 
3909
                                if (ti == 0)
 
3910
                                {
 
3911
                                        eprintf("Please enter a number >= 1.\n");
 
3912
                                        goto _intervalagain;
 
3913
                                }
 
3914
                                if (ti != -1)
 
3915
                                {
 
3916
                                        g_laMultiIntervalStart.Add(ti-1);
 
3917
                                        g_laMultiIntervalEnd.Add(AskUnsignedInteger_ND("    Enter ending time step of %d. interval: ",g_laMultiIntervalStart.GetSize())-1);
 
3918
                                        goto _intervalagain;
 
3919
                                }
 
3920
                        }
 
3921
                        mprintf(WHITE,"\n* %d Intervals have been defined:\n",g_laMultiIntervalStart.GetSize());
 
3922
                        for (z=0;z<g_laMultiIntervalStart.GetSize();z++)
 
3923
                                mprintf("  - Interval %2d: Steps %6d - %6d.\n",z+1,g_laMultiIntervalStart[z]+1,g_laMultiIntervalEnd[z]+1);
 
3924
                        mprintf("\n");
 
3925
                } else goto _nomulti;
 
3926
        } else
 
3927
        {
 
3928
_nomulti:
 
3929
                g_iBeginStep = AskUnsignedInteger("    In which time step to start processing the trajectory? [1] ",1) - 1;
 
3930
                if (g_iBeginStep == -1)
 
3931
                        g_iBeginStep = 0;
 
3932
                g_iMaxStep = AskUnsignedInteger("    How many time steps to use (from this position on)? [all] ",0);
 
3933
                if (g_iMaxStep == 0)
 
3934
                        g_iMaxStep = -1; // Alle verwenden
 
3935
        }
 
3936
        g_iStride = AskUnsignedInteger("    Use every n-th time step from the trajectory? [1] ",1);
 
3937
 
 
3938
        if (g_iTrajSteps != -1)
 
3939
        {
 
3940
                if (g_iMaxStep == -1)
 
3941
                        mprintf(YELLOW,"\n    Using %d time steps: Every %d%s within range %d - approx. %d.\n",(g_iTrajSteps-g_iBeginStep)/g_iStride,g_iStride,(g_iStride==1)?"st":"th",g_iBeginStep+1,g_iTrajSteps);
 
3942
                else mprintf(YELLOW,"\n    Using %d time steps: Every %d%s within range %d - %d.\n",g_iMaxStep/g_iStride,g_iStride,(g_iStride==1)?"st":"th",g_iBeginStep+1,g_iBeginStep+g_iMaxStep);
 
3943
        } else if (g_iMaxStep != -1)
 
3944
                mprintf(YELLOW,"\n    Using %d time steps: Every %d%s within range %d - %d.\n",g_iMaxStep/g_iStride,g_iStride,(g_iStride==1)?"st":"th",g_iBeginStep+1,g_iBeginStep+g_iMaxStep);
 
3945
                        else mprintf(YELLOW,"\n    Using every %d%s time step beginning from step %d.\n",g_iStride,(g_iStride==1)?"st":"th",g_iBeginStep+1);
 
3946
 
 
3947
        ti = -1;                                                                                                                                                                                                                                
 
3948
        if (g_iTrajSteps != -1)                                                                                                                                                                                                                 
 
3949
        {                                                                                                                                                                                                                                       
 
3950
                if (g_iMaxStep == -1)                                                                                                                                                                                                           
 
3951
                        ti = (g_iTrajSteps-g_iBeginStep)/g_iStride;                                                                                                                                                                             
 
3952
                                else ti = g_iMaxStep/g_iStride;                                                                                                                                                                                 
 
3953
        } else if (g_iMaxStep != -1)                                                                                                                                                                                                             
 
3954
                ti = g_iMaxStep/g_iStride;                                                                                                                                                                                                      
 
3955
                                                                                                                                                                                                                                        
 
3956
        if (ti >= 0)                                                                                                                                                                                                                            
 
3957
        {                                                                                                                                                                                                                                       
 
3958
                if (g_bMSD)                                                                                                                                                                                                                     
 
3959
                {                                                                                                                                                                                                                               
 
3960
                        for (z=0;z<g_oaObserv.GetSize();z++)                                                                                                                                                                                    
 
3961
                        {                                                                                                                                                                                                                       
 
3962
                                o = (CObservation*)g_oaObserv[z];                                                                                                                                                                               
 
3963
                                if (o->m_pMSD->m_iResolution > ti)                                                                                                                                                                              
 
3964
                                {                                                                                                                                                                                                               
 
3965
                                        eprintf("\n    MSD resolution of %d requires at least %d time steps, but using only %d steps.\n    This will lead to erroneous results!\n\n",o->m_pMSD->m_iResolution,o->m_pMSD->m_iResolution,ti);     
 
3966
                                        if (!AskYesNo("    Continue anyway (y/n)? [yes] ",true))                                                                                                                                                
 
3967
                                                return false;                                                                                                                                                                                   
 
3968
                                        goto _lessstepdone;                                                                                                                                                                                     
 
3969
                                }                                                                                                                                                                                                               
 
3970
                        }                                                                                                                                                                                                                       
 
3971
                }                                                                                                                                                                                                                               
 
3972
                if (g_bRDyn)                                                                                                                                                                                                                     
 
3973
                {                                                                                                                                                                                                                               
 
3974
                        for (z=0;z<g_oaObserv.GetSize();z++)                                                                                                                                                                                    
 
3975
                        {                                                                                                                                                                                                                       
 
3976
                                o = (CObservation*)g_oaObserv[z];                                                                                                                                                                               
 
3977
                                if (o->m_pRDyn->m_iDepth*o->m_pRDyn->m_iStride > ti)                                                                                                                                                                              
 
3978
                                {                                                                                                                                                                                                               
 
3979
                                        eprintf("\n    Reorientation dynamics resolution of %d requires at least %d time steps, but using only %d steps.\n    This will lead to erroneous results!\n\n",o->m_pRDyn->m_iDepth*o->m_pRDyn->m_iStride,o->m_pRDyn->m_iDepth*o->m_pRDyn->m_iStride,ti);     
 
3980
                                        if (!AskYesNo("    Continue anyway (y/n)? [yes] ",true))                                                                                                                                                
 
3981
                                                return false;                                                                                                                                                                                   
 
3982
                                        goto _lessstepdone;                                                                                                                                                                                     
 
3983
                                }                                                                                                                                                                                                               
 
3984
                        }                                                                                                                                                                                                                       
 
3985
                }                                                                                                                                                                                                                               
 
3986
                if (g_bIRSpec)                                                                                                                                                                                                                     
 
3987
                {                                                                                                                                                                                                                               
 
3988
                        for (z=0;z<g_oaObserv.GetSize();z++)                                                                                                                                                                                    
 
3989
                        {                                                                                                                                                                                                                       
 
3990
                                o = (CObservation*)g_oaObserv[z];                                                                                                                                                                               
 
3991
                                if (o->m_pIRSpec->m_iDepth*o->m_pIRSpec->m_iStride > ti)                                                                                                                                                                              
 
3992
                                {                                                                                                                                                                                                               
 
3993
                                        eprintf("\n    IR spectrum resolution of %d requires at least %d time steps, but using only %d steps.\n    This will lead to erroneous results!\n\n",o->m_pIRSpec->m_iDepth*o->m_pIRSpec->m_iStride,o->m_pIRSpec->m_iDepth*o->m_pIRSpec->m_iStride,ti);     
 
3994
                                        if (!AskYesNo("    Continue anyway (y/n)? [yes] ",true))                                                                                                                                                
 
3995
                                                return false;                                                                                                                                                                                   
 
3996
                                        goto _lessstepdone;                                                                                                                                                                                     
 
3997
                                }                                                                                                                                                                                                               
 
3998
                        }                                                                                                                                                                                                                       
 
3999
                }                                                                                                                                                                                                                               
 
4000
        }      
 
4001
_lessstepdone:
 
4002
 
 
4003
        if (g_bScanVelocities)
 
4004
        {
 
4005
                mprintf(WHITE,"\n>>> Velocity Pre-Analysis >>>\n\n");
 
4006
                g_iScanVelStart = AskUnsignedInteger("    Start in which time step for velocity pre-analysis? [0] ",0);
 
4007
                g_iScanVelSteps = AskUnsignedInteger("    Use how many time steps from this point on for vel. pre-analysis? [all] ",0);
 
4008
                g_iScanVelStride = AskUnsignedInteger("    Use every n-th step for velocity pre-analysis? [10] ",10);
 
4009
                mprintf(WHITE,"\n<<< End of Velocity Pre-Analysis <<<\n");
 
4010
        }
 
4011
 
 
4012
        if (g_bSaveRefEnv && (g_iNbhMode == 3))
 
4013
        {
 
4014
                mprintf(WHITE,"\n>>> Neighborhood Pre-Analysis >>>\n\n");
 
4015
                g_iScanNbhStart = AskUnsignedInteger("    Start in which time step for neighborhood analysis? [0] ",0);
 
4016
                g_iScanNbhSteps = AskUnsignedInteger("    Use how many time steps from this point on for nbh analysis? [all] ",0);
 
4017
                g_iScanNbhStride = AskUnsignedInteger("    Use every n-th step for the neighborhood analysis? [10] ",10);
 
4018
                mprintf(WHITE,"\n<<< End of Neighborhood Pre-Analysis <<<\n");
 
4019
        }
 
4020
 
 
4021
        mprintf(WHITE,"\n########## All information collected ##########\n\n");
 
4022
        BTOUT;
 
4023
        return true;
 
4024
}
 
4025
 
 
4026
 
 
4027
 
 
4028
/*      a = fopen("struct.xyz","wt");
 
4029
        mfprintf(a,"%d\n\n",g_iGesAtomCount*20);
 
4030
 
 
4031
        FILE *b;
 
4032
        for (z=0;z<20;z++)
 
4033
        {
 
4034
                g_pTempTimestep = new CTimeStep();
 
4035
                g_pTempTimestep->CopyFrom(&g_TimeStep);
 
4036
                g_pTempTimestep->CenterCOM();
 
4037
                CxMatrix3 ma;
 
4038
                CxVector3 vec1;
 
4039
                vec1[0] = ((rand()%20001)-10000)/10000.0;
 
4040
                vec1[1] = ((rand()%20001)-10000)/10000.0;
 
4041
                vec1[2] = ((rand()%20001)-10000)/10000.0;
 
4042
                vec1.Normalize();
 
4043
                tf = (rand()%10000)/10000.0*2.0*Pi;
 
4044
                ma.RotMat(vec1,tf);
 
4045
                g_pTempTimestep->Transform(ma);
 
4046
 
 
4047
                vec1[0] = (rand()%20000)/10.0;
 
4048
                vec1[1] = (rand()%20000)/10.0;
 
4049
                vec1[2] = (rand()%20000)/10.0;
 
4050
 
 
4051
                for (z2=0;z2<g_iGesAtomCount;z2++)
 
4052
                        g_pTempTimestep->m_vaCoords[z2] += vec1;
 
4053
 
 
4054
                sprintf(buf,"coord_%02d.xyz",z+1);
 
4055
                b = fopen(buf,"wt");
 
4056
//              mfprintf(b,"%d\n\n",g_iGesAtomCount);
 
4057
                for (z2=0;z2<g_iGesAtomCount;z2++)
 
4058
                {
 
4059
                        mfprintf(a,"%s  %f  %f  %f\n",((CAtom*)g_oaAtoms[g_waAtomRealElement[z2]])->m_sName,g_pTempTimestep->m_vaCoords[z2][0]/100.0,g_pTempTimestep->m_vaCoords[z2][1]/100.0,g_pTempTimestep->m_vaCoords[z2][2]/100.0);
 
4060
                        mfprintf(b,"%s  %f  %f  %f\n",((CAtom*)g_oaAtoms[g_waAtomRealElement[z2]])->m_sName,g_pTempTimestep->m_vaCoords[z2][0]/100.0,g_pTempTimestep->m_vaCoords[z2][1]/100.0,g_pTempTimestep->m_vaCoords[z2][2]/100.0);
 
4061
                }
 
4062
                fclose(b);
 
4063
        }
 
4064
        fclose(a);*/