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

« back to all changes in this revision

Viewing changes to src/timestep.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
 
#include "timestep.h"
25
 
#include "travis.h"
26
 
 
27
 
 
28
 
void CTimeStep::CalcCenters()
29
 
{
30
 
        BTIN;
31
 
        int z, z2, z3, z4, c;
32
 
        CxVector3 tv;
33
 
        CMolecule *m;
34
 
        CVirtualAtom *v;
35
 
        CSingleMolecule *sm;
36
 
 
37
 
        tv = 0;
38
 
 
39
 
//      mprintf("** CalcCenters **");
40
 
 
41
 
        if (m_vaCoords.GetSize() < g_iGesVirtAtomCount)
42
 
                m_vaCoords.SetSize(g_iGesVirtAtomCount);
43
 
 
44
 
//      mprintf("CalcCenters(): Size is now %d.\n",m_vaCoords.GetSize());
45
 
 
46
 
        if (g_bUseVelocities)
47
 
                if (m_vaVelocities.GetSize() < g_iGesVirtAtomCount)
48
 
                        m_vaVelocities.SetSize(g_iGesVirtAtomCount);
49
 
 
50
 
        if (g_bUseForces)
51
 
                if (m_vaForces.GetSize() < g_iGesVirtAtomCount)
52
 
                        m_vaForces.SetSize(g_iGesVirtAtomCount);
53
 
 
54
 
        for (z=0;z<g_oaVirtualAtoms.GetSize();z++)
55
 
        {
56
 
                v = (CVirtualAtom*)g_oaVirtualAtoms[z];
57
 
                m = (CMolecule*)g_oaMolecules[v->m_iMolecule];
58
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
59
 
                {
60
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
61
 
                        if (v->m_iMode == 0) // Mittel aus Atompositionen
62
 
                        {
63
 
                                tv = 0;
64
 
                                c = 0;
65
 
                                for (z3=0;z3<v->m_oCenterAtoms.m_baAtomType.GetSize();z3++)
66
 
                                {
67
 
                                        for (z4=0;z4<((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetSize();z4++)
68
 
                                        {
69
 
//                                              mprintf("{%d:(%G|%G|%G) }\n",((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4)),m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4))][0],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4))][1],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4))][2]);
70
 
                                                tv += m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4))] * v->m_faWeight[c];
71
 
                                                c++;
72
 
                                        }
73
 
                                }
74
 
                                tv /= v->m_fGesWeight;
75
 
                        } else if (v->m_iMode == 1) // Abstand, Winkel, Dihedralwinkel
76
 
                        {
77
 
                                tv = PointFromRAD(m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_iAtomType[0]])->GetAt(v->m_iAtom[0])],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_iAtomType[1]])->GetAt(v->m_iAtom[1])],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_iAtomType[2]])->GetAt(v->m_iAtom[2])],v->m_fValues[0],v->m_fValues[1],v->m_fValues[2]);
78
 
                        } else if (v->m_iMode == 2) // Dipolvektor
79
 
                        {
80
 
                                if (!g_bDipole)
81
 
                                {
82
 
                                        eprintf("Cannot use dipole vectors.\n");
83
 
                                        BTOUT;
84
 
                                        return;
85
 
                                }
86
 
                                tv = sm->m_vDipole + m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[sm->m_baAtomIndex.GetSize()-1])->GetAt(0)];
87
 
                        } else if (v->m_iMode == 3) // Geschwindigkeitsvektor
88
 
                        {
89
 
                        } else if (v->m_iMode == 4) // Kraftvektor
90
 
                        {
91
 
                        }
92
 
//                      mprintf("%d:(%G|%G|%G), ",((CxIntArray*)sm->m_oaAtomOffset[sm->m_baAtomIndex.GetSize()-1])->GetAt(v->m_iMolVirtAtom),tv[0],tv[1],tv[2]);
93
 
                        m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[sm->m_baAtomIndex.GetSize()-1])->GetAt(v->m_iMolVirtAtom)] = tv;
94
 
                }
95
 
        }
96
 
        BTOUT;
97
 
}
98
 
 
99
 
 
100
 
bool CTimeStep::BondRange(int i1, int i2, double *f)
101
 
{
102
 
        BTIN;
103
 
        int a, b;
104
 
        double d;
105
 
        double x, y, z;
106
 
 
107
 
        if (g_iScanMolStep == -1)
108
 
                return false;
109
 
 
110
 
        x = m_vaCoords[i1][0] - m_vaCoords[i2][0];
111
 
        y = m_vaCoords[i1][1] - m_vaCoords[i2][1];
112
 
        z = m_vaCoords[i1][2] - m_vaCoords[i2][2];
113
 
 
114
 
        if (g_bPeriodic)
115
 
        {
116
 
                if (g_bPeriodicX)
117
 
                {
118
 
                        while (x < -g_fBoxX/2)
119
 
                                x += g_fBoxX;
120
 
                        while (x > g_fBoxX/2)
121
 
                                x -= g_fBoxX;
122
 
                }
123
 
 
124
 
                if (g_bPeriodicY)
125
 
                {
126
 
                        while (y < -g_fBoxY/2)
127
 
                                y += g_fBoxY;
128
 
                        while (y > g_fBoxY/2)
129
 
                                y -= g_fBoxY;
130
 
                }
131
 
 
132
 
                if (g_bPeriodicZ)
133
 
                {
134
 
                        while (z < -g_fBoxZ/2)
135
 
                                z += g_fBoxZ;
136
 
                        while (z > g_fBoxZ/2)
137
 
                                z -= g_fBoxZ;
138
 
                }
139
 
        }
140
 
 
141
 
        d = (float)sqrt(x*x+y*y+z*z);
142
 
 
143
 
        if (f != NULL)
144
 
                *f = d;
145
 
 
146
 
        a = g_baAtomIndex[i1];
147
 
        b = g_baAtomIndex[i2];
148
 
 
149
 
        if ((a >= g_oaAtoms.GetSize()) || (b >= g_oaAtoms.GetSize()))
150
 
        {
151
 
                BTOUT; 
152
 
                return false;
153
 
        }
154
 
 
155
 
        if (((CAtom*)g_oaAtoms[a])->m_pElement->m_fRadius == 0)
156
 
        {
157
 
                BTOUT;
158
 
                return false;
159
 
        }
160
 
        
161
 
        if (((CAtom*)g_oaAtoms[b])->m_pElement->m_fRadius == 0)
162
 
        {
163
 
                BTOUT;
164
 
                return false;
165
 
        }
166
 
 
167
 
        if (d < (((CAtom*)g_oaAtoms[a])->m_pElement->m_fRadius+((CAtom*)g_oaAtoms[b])->m_pElement->m_fRadius)*g_fBondFactor)
168
 
        {
169
 
//              printf("    \"%s\" br=%f, \"%s\" br=%f Hat Nachbarn %s%d im Abstand von %.3f.\n",m_pLabels[i1],c1,m_pLabels[i2],c2,m_pLabels[i2],i2+1,d);
170
 
                BTOUT; 
171
 
                return true;
172
 
        } else 
173
 
        {
174
 
                BTOUT;
175
 
                return false;
176
 
        }
177
 
}
178
 
 
179
 
 
180
 
bool CTimeStep::MirrorBond(int i1, int i2)
181
 
{
182
 
        BTIN;
183
 
        bool changed;
184
 
 
185
 
        changed = false;
186
 
 
187
 
        if (g_bPeriodicX)
188
 
        {
189
 
                while (m_vaCoords[i1][0]-m_vaCoords[i2][0] > g_fBoxX/2)
190
 
                {
191
 
                        m_vaCoords[i2][0] += g_fBoxX;
192
 
                        changed = true;
193
 
                }
194
 
                while (m_vaCoords[i2][0]-m_vaCoords[i1][0] > g_fBoxX/2)
195
 
                {
196
 
                        m_vaCoords[i2][0] -= g_fBoxX;
197
 
                        changed = true;
198
 
                }
199
 
        }
200
 
 
201
 
        if (g_bPeriodicY)
202
 
        {
203
 
                while (m_vaCoords[i1][1]-m_vaCoords[i2][1] > g_fBoxY/2)
204
 
                {
205
 
                        m_vaCoords[i2][1] += g_fBoxY;
206
 
                        changed = true;
207
 
                }
208
 
                while (m_vaCoords[i2][1]-m_vaCoords[i1][1] > g_fBoxY/2)
209
 
                {
210
 
                        m_vaCoords[i2][1] -= g_fBoxY;
211
 
                        changed = true;
212
 
                }
213
 
        }
214
 
 
215
 
        if (g_bPeriodicZ)
216
 
        {
217
 
                while (m_vaCoords[i1][2]-m_vaCoords[i2][2] > g_fBoxZ/2)
218
 
                {
219
 
                        m_vaCoords[i2][2] += g_fBoxZ;
220
 
                        changed = true;
221
 
                }
222
 
                while (m_vaCoords[i2][2]-m_vaCoords[i1][2] > g_fBoxZ/2)
223
 
                {
224
 
                        m_vaCoords[i2][2] -= g_fBoxZ;
225
 
                        changed = true; 
226
 
                }
227
 
        }
228
 
 
229
 
        if (changed)
230
 
        {
231
 
                BTOUT; 
232
 
                return true;
233
 
        } 
234
 
        BTOUT; 
235
 
        return false;
236
 
}
237
 
 
238
 
 
239
 
void CTimeStep::RECURSION_ScanMolecules(int i, CxByteArray *ta, CSingleMolecule *sm, int depth, int *stack, unsigned long bmask, bool w)
240
 
{
241
 
        BTIN;
242
 
        int z, z2;
243
 
        int nblist[64], nbs;
244
 
        double f;
245
 
        CxIntArray *wa; 
246
 
        CMolAtom *ma;
247
 
//      mprintf("  Rekursion fuer Atom %d.\n",i+1);
248
 
 
249
 
//      mprintf("Depth=%d, i=%d.\n",depth,i);
250
 
        if (g_bVerbose)
251
 
        {
252
 
                mprintf("  ");
253
 
                for (z=1;z<depth;z++)
254
 
                {
255
 
                        if ((bmask & (int)pow(2.0,z)) != 0)
256
 
                                mprintf(WHITE,"|  ");
257
 
                                        else mprintf("   ");
258
 
                }
259
 
                if (depth != 0)
260
 
                {
261
 
                        if (w)
262
 
                                mprintf(WHITE,"|--");
263
 
                                        else mprintf(WHITE,"`--");
264
 
                }
265
 
                mprintf(CYAN,"%s",((CAtom*)g_oaAtoms[g_baAtomIndex[i]])->m_sName);
266
 
                mprintf("(%d)",i+1);
267
 
        }
268
 
 
269
 
        stack[depth] = i;
270
 
        g_laAtomSMIndex[i] = (unsigned long)g_oaSingleMolecules.GetSize()-1;
271
 
        (*ta)[i] = 1;
272
 
//      mprintf("  sm->m_baAtomIndex.GetSize()=%d\n",sm->m_baAtomIndex.GetSize());
273
 
        for (z=0;z<sm->m_baAtomIndex.GetSize();z++)
274
 
        {
275
 
                if (sm->m_baAtomIndex[z] == g_baAtomIndex[i])
276
 
                {
277
 
                        try { ma = new CMolAtom(); } catch(...) { ma = NULL; }
278
 
                        if (ma == NULL) NewException((double)sizeof(CMolAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
279
 
                        
280
 
                        ma->m_iOffset = i;
281
 
                        ma->m_iType = z;
282
 
                        sm->m_oaMolAtoms.Add(ma);
283
 
                        goto _ok;
284
 
                }
285
 
        }
286
 
 
287
 
        try { ma = new CMolAtom(); } catch(...) { ma = NULL; }
288
 
        if (ma == NULL) NewException((double)sizeof(CMolAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
289
 
        
290
 
        ma->m_iOffset = i;
291
 
        ma->m_iType = sm->m_baAtomIndex.GetSize();
292
 
        ma->m_iNumber = 0;
293
 
        sm->m_oaMolAtoms.Add(ma);
294
 
 
295
 
        sm->m_baAtomIndex.Add(g_baAtomIndex[i]);
296
 
_ok:
297
 
        m_iConnectedAtoms++;
298
 
 
299
 
        if (!g_bVerbose)
300
 
                if ((m_iConnectedAtoms % m_iGesAtomModulo)==0)
301
 
                        mprintf(WHITE,"#");
302
 
 
303
 
        nbs = 0;
304
 
        for (z=0;z<(long)m_iGesAtomCount;z++) // Schon mal alle Nachbarn raussuchen
305
 
        {
306
 
                if (z == i)
307
 
                        continue;
308
 
                if (((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_bExclude)
309
 
                        continue;
310
 
                if (BondRange(i,z,&f))
311
 
                {
312
 
                        if ((*ta)[z] != 0)
313
 
                        {
314
 
                                if ((depth > 0) && (z != stack[depth-1]))
315
 
                                {
316
 
                                        if (sm->m_oaRings.GetSize() < 100)
317
 
                                        {
318
 
                                                if (g_bVerbose)
319
 
                                                {
320
 
                                                        mprintf(GREEN,"  <-- Ring closure: ");
321
 
                                                        mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[stack[depth]]])->m_sName,stack[depth]+1);
322
 
                                                }
323
 
 
324
 
                                                try { wa = new CxIntArray("CTimeStep::RECURSION_ScanMolecules():wa"); } catch(...) { wa = NULL; }
325
 
                                                if (wa == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
326
 
                                                
327
 
                                                sm->m_oaRings.Add(wa);
328
 
                                                wa->Add(stack[depth]);
329
 
                                                z2 = depth-1;
330
 
                                                while ((stack[z2] != z) && (z2 >= 0))
331
 
                                                {
332
 
                                                        wa->Add(stack[z2]);
333
 
                                                        if (g_bVerbose)
334
 
                                                                mprintf(" - %s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[stack[z2]]])->m_sName,stack[z2]+1);
335
 
                                                        z2--;
336
 
                                                }
337
 
                                                wa->Add(z);
338
 
                                                if (g_bVerbose)
339
 
                                                        mprintf(" - %s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1);
340
 
                                        } else if (!m_bAbortRing)
341
 
                                        {
342
 
                                                m_bAbortRing = true;
343
 
                                                eprintf("\n### More than 100 rings, aborting ring system scan for molecule %d.",sm->m_iIndex+1);
344
 
                                        }
345
 
                                }
346
 
                                continue;
347
 
                        }
348
 
/*                      for (z2=0;z2<g_waBondBlackList.GetSize();z2+=2)
349
 
                                if (((g_waBondBlackList[z2] == i) && (g_waBondBlackList[z2+1] == z)) || 
350
 
                                        ((g_waBondBlackList[z2] == z) && (g_waBondBlackList[z2+1] == i)))
351
 
                                {
352
 
                                        if (g_bVerbose)
353
 
                                        {
354
 
                                                mprintf("\n  ");
355
 
                                                for (z2=1;z2<depth+1;z2++)
356
 
                                                {
357
 
                                                        if ((bmask & (int)pow(2,z2)) != 0)
358
 
                                                                mprintf(WHITE,"|  ");
359
 
                                                        else mprintf("   ");
360
 
                                                }
361
 
                                                if (z+1 < nbs)
362
 
                                                        mprintf(WHITE,"|--");
363
 
                                                                else mprintf("`--");
364
 
                                                mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1);
365
 
                                                mprintf(GREEN,"  <-- This bond has been broken, skipping.\n");
366
 
                                        }
367
 
                                        g_iBondBlackListUsed++;
368
 
                                        goto _nextnb;
369
 
                                }*/
370
 
                        if (f < 50.0f)
371
 
                        {
372
 
                                if (g_iCloseAtomCounter < 25)
373
 
                                        eprintf("\n### The atoms %s(%d) and %s(%d) are VERY close to each other. (Distance=%.4f pm)",((CAtom*)g_oaAtoms[g_baAtomIndex[i]])->m_sName,i+1,((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1,f);
374
 
                                else if (g_iCloseAtomCounter == 25)
375
 
                                        eprintf("\n### Suppressing further \"atoms close to each other\" warnings.");
376
 
 
377
 
                                g_iCloseAtomCounter++;
378
 
                        }
379
 
                        nblist[nbs] = z;
380
 
                        nbs++;
381
 
                        if (nbs >= MAX_BONDS)
382
 
                        {
383
 
                                eprintf("\n### Atom %s(%d) has more than %d bonds. Ignoring further bonds (defined via MAX_BONDS in config.h).",((CAtom*)g_oaAtoms[g_baAtomIndex[i]])->m_sName,i+1,MAX_BONDS);
384
 
                                goto _nbdone;
385
 
                        }
386
 
                }
387
 
        }
388
 
_nbdone:
389
 
        if (g_bVerbose)
390
 
                mprintf("\n");
391
 
        for (z=0;z<nbs;z++) // Fuer das aktuelle Atom z2 alle Nachbarn durchgehen
392
 
        {
393
 
                for (z2=0;z2<g_laBondBlackList.GetSize();z2+=2)
394
 
                {
395
 
                        if (((g_laBondBlackList[z2] == i) && (g_laBondBlackList[z2+1] == nblist[z])) || 
396
 
                                ((g_laBondBlackList[z2] == nblist[z]) && (g_laBondBlackList[z2+1] == i)))
397
 
                        {
398
 
                                if (g_bVerbose)
399
 
                                {
400
 
                                        mprintf("  ");
401
 
                                        for (z2=1;z2<depth+1;z2++)
402
 
                                        {
403
 
                                                if ((bmask & (int)pow(2.0,z2)) != 0)
404
 
                                                        mprintf(WHITE,"|  ");
405
 
                                                else mprintf("   ");
406
 
                                        }
407
 
                                        if (z+1 < nbs)
408
 
                                                mprintf(WHITE,"|--");
409
 
                                                        else mprintf(WHITE,"`--");
410
 
                                        mprintf(CYAN,"%s",((CAtom*)g_oaAtoms[g_baAtomIndex[nblist[z]]])->m_sName);
411
 
                                        mprintf("(%d)",nblist[z]+1);
412
 
                                        mprintf(GREEN,"  <-- This bond shall be broken, skipping.\n");
413
 
                                }
414
 
                                g_iBondBlackListUsed++;
415
 
                                goto _nextnb;
416
 
                        }
417
 
                }
418
 
 
419
 
                sm->m_laBonds.Add(i);
420
 
                sm->m_laBonds.Add(nblist[z]);
421
 
 
422
 
                if ((*ta)[nblist[z]] == 0) // Der Nachbar ist noch immer frei
423
 
                {
424
 
                        if (z+1 == nbs)
425
 
                                bmask -= (int)pow(2.0,depth+1);
426
 
                        RECURSION_ScanMolecules(nblist[z],ta,sm,depth+1,stack,bmask,(z+1==nbs)?false:true);
427
 
                } else // Ringschluss
428
 
                {
429
 
                        if (g_bVerbose)
430
 
                        {
431
 
                                mprintf("  ");
432
 
                                for (z2=1;z2<depth+1;z2++)
433
 
                                {
434
 
                                        if ((bmask & (int)pow(2.0,z2)) != 0)
435
 
                                                mprintf(WHITE,"|  ");
436
 
                                        else mprintf("   ");
437
 
                                }
438
 
                                if (z+1 < nbs)
439
 
                                        mprintf(WHITE,"|--");
440
 
                                                else mprintf(WHITE,"`--");
441
 
                                mprintf(CYAN,"%s",((CAtom*)g_oaAtoms[g_baAtomIndex[nblist[z]]])->m_sName);
442
 
                                mprintf("(%d)",nblist[z]+1);
443
 
                                mprintf(GREEN,"  <-- Ring closure\n");
444
 
                        }
445
 
                }
446
 
_nextnb:;
447
 
        }
448
 
        BTOUT; 
449
 
}
450
 
 
451
 
 
452
 
void CTimeStep::BuildAtomIndex()
453
 
{
454
 
        BTIN;
455
 
        int z, z2;
456
 
        CAtom *at;
457
 
        char buf[64];
458
 
 
459
 
        g_baAtomIndex.SetSize(m_iGesAtomCount);
460
 
        for (z=0;z<(long)m_iGesAtomCount;z++)
461
 
        {
462
 
                strcpy(buf,(char*)m_paLabels[z]);
463
 
                ReplaceDigits(buf);
464
 
                for (z2=0;z2<g_oaAtoms.GetSize();z2++)
465
 
                {
466
 
                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z2])->m_sName)==0)
467
 
                        {
468
 
                                at = (CAtom*)g_oaAtoms[z2];
469
 
        //                      mprintf("Atom %d: Type %d (%s).\n",z,z2,at->m_sName);
470
 
                                while (at->m_pMergedTo != NULL)
471
 
                                {
472
 
                                        at = at->m_pMergedTo;
473
 
        //                              mprintf("  ...was merged to %s.\n",at->m_sName);
474
 
                                }
475
 
        //                      mprintf("  Index is %d.\n",at->m_iIndex);
476
 
                                g_baAtomIndex[z] = (unsigned char)at->m_iIndex;
477
 
                                goto _e;
478
 
                        }
479
 
                }
480
 
                g_baAtomIndex[z] = 255;
481
 
                eprintf("Error: CTimeStep::BuildAtomIndex(): Atom type \"%s\" not known.\n",buf);
482
 
                _e:;
483
 
        }
484
 
        BTOUT; 
485
 
}
486
 
 
487
 
 
488
 
bool CTimeStep::ScanMolecules()
489
 
{
490
 
        BTIN;
491
 
        int z, z2, z3, z4, z5, i, i2, ti, ti2, i1;
492
 
        CxByteArray ta;
493
 
        CSingleMolecule *sm, *sm2;
494
 
        CxIntArray *wa, *waz2, *waz3, *waneu;
495
 
        CMolecule *m;
496
 
        CMolAtom *ma, *ma2, *ma3;
497
 
        CMolBond *bond, *bond2;
498
 
        CMolBondGroup *bg;
499
 
        CMolAngle *angle, *angle2;
500
 
        CMolAngleGroup *ag;
501
 
        CAtom *at;
502
 
        float f;
503
 
        bool b;
504
 
        double tfs;
505
 
        int *stack;
506
 
 
507
 
        BuildAtomIndex();
508
 
//      CalcRadii();
509
 
 
510
 
        try { stack = new int[g_iGesAtomCount]; } catch(...) { stack = NULL; }
511
 
        if (stack == NULL) NewException((double)g_iGesAtomCount*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
512
 
 
513
 
        b = false;
514
 
        for (z=0;z<g_oaAtoms.GetSize();z++)
515
 
        {
516
 
                if (z == g_iVirtAtomType)
517
 
                        continue;
518
 
                at = (CAtom*)g_oaAtoms[z];
519
 
                if (at->m_pMergedTo != NULL)
520
 
                        continue;
521
 
                if (at->m_pElement->m_fRadius == 0)
522
 
                {
523
 
                        if (!b)
524
 
                        {
525
 
                                b = true;
526
 
                                mprintf("\n");
527
 
                        }
528
 
                        at->m_bExclude = AskYesNo("    Atom type \"%s\" has bond radius 0. Exclude it from the system (y/n)? [yes] ",true,at->m_sName);
529
 
        //              if (!at->m_bExclude)
530
 
        //                      at->m_pElement->m_fRadius = AskFloat_ND("    Please enter covalent bond radius for %s (in pm): ",at->m_sName);
531
 
                }
532
 
        }
533
 
 
534
 
        ta.SetSize(g_iGesAtomCount);
535
 
        g_laAtomSMIndex.SetSize(g_iGesAtomCount);
536
 
        for (z=0;z<g_iGesAtomCount;z++)
537
 
        {
538
 
                ta[z] = 0;
539
 
                g_laAtomSMIndex[z] = -1;
540
 
        }
541
 
        g_iBondBlackListUsed = 0;
542
 
        g_oaSingleMolecules.RemoveAll();
543
 
        g_oaMolecules.RemoveAll();
544
 
        m_iConnectedAtoms = 0;
545
 
        m_iGesAtomModulo = (m_iGesAtomCount / 60)+1;
546
 
        if (g_iScanMolStep == -1)
547
 
        {
548
 
                mprintf(WHITE,"\n    Skipping molecule recognition, using atoms as molecules...\n\n");
549
 
                for (z=0;z<(long)m_iGesAtomCount;z++)
550
 
                {
551
 
                        if (((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_bExclude)
552
 
                                continue;
553
 
                        
554
 
                        try { sm = new CSingleMolecule(); } catch(...) { sm = NULL; }
555
 
                        if (sm == NULL) NewException((double)sizeof(CSingleMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
556
 
                        
557
 
                        sm->m_iIndex = g_oaSingleMolecules.GetSize();
558
 
 
559
 
                        g_oaSingleMolecules.Add(sm);
560
 
 
561
 
                        g_laAtomSMIndex[z] = (unsigned long)g_oaSingleMolecules.GetSize()-1;
562
 
 
563
 
                        try { ma = new CMolAtom(); } catch(...) { ma = NULL; }
564
 
                        if (ma == NULL) NewException((double)sizeof(CMolAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
565
 
                        
566
 
                        ma->m_iOffset = z;
567
 
                        ma->m_iType = sm->m_baAtomIndex.GetSize();
568
 
                        ma->m_iNumber = 0;
569
 
                        sm->m_oaMolAtoms.Add(ma);
570
 
                        sm->m_baAtomIndex.Add(g_baAtomIndex[z]);
571
 
                }
572
 
                mprintf("    %d molecules found.\n\n",g_oaSingleMolecules.GetSize());
573
 
        } else
574
 
        {
575
 
                if (g_bVerbose)
576
 
                {
577
 
                        mprintf(WHITE,"\n    Molecule recognition...\n\n");
578
 
                        mprintf(WHITE,">>> Output of the molecule tree >>>\n");
579
 
                } else mprintf("\n    Molecule recognition [");
580
 
        //      fflush(stdout);
581
 
                for (z=0;z<(long)m_iGesAtomCount;z++)
582
 
                {
583
 
                        if (ta[z] != 0) // Dieses Atom wurde bereits in irgendein Molekuel eingebaut
584
 
                        {
585
 
        //                      mprintf("> Atom %d: Schon vergeben.\n",z+1);
586
 
                                continue;
587
 
                        }
588
 
        //              mprintf("# Atom %d: Starte Rekursion.\n",z+1);
589
 
 
590
 
                        if (((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_bExclude)
591
 
                                continue;
592
 
                        
593
 
                        try { sm = new CSingleMolecule(); } catch(...) { sm = NULL; }
594
 
                        if (sm == NULL) NewException((double)sizeof(CSingleMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
595
 
                        
596
 
                        sm->m_iIndex = g_oaSingleMolecules.GetSize();
597
 
 
598
 
                        g_oaSingleMolecules.Add(sm);
599
 
 
600
 
        //              sm->m_iAtomGes = 0;
601
 
        /*              for (z2=0;z2<16;z2++)
602
 
                                sm->m_iAtomCount[z2] = 0;
603
 
                        sm->m_iElements = 0;*/
604
 
                        if (g_bVerbose)
605
 
                                mprintf(YELLOW,"\nThe next molecule starts with %s(%d):\n",m_paLabels[z],z+1);
606
 
                        
607
 
                        m_bAbortRing = false;
608
 
 
609
 
                        RECURSION_ScanMolecules(z,&ta,sm,0,stack,0xFFFFFFFF,true);
610
 
 
611
 
        //              printf("%d Atome in diesem Molekuel.\n",g_pSingleMolecules[g_oaSingleMolecules.GetSize()].AtomGes);
612
 
 
613
 
        //              g_oaSingleMolecules.GetSize()++;
614
 
                }
615
 
                if (g_bVerbose)
616
 
                {
617
 
                        mprintf(WHITE,"\n<<< Output of the molecule tree <<<\n\n");
618
 
                        mprintf("%d molecules found.\n\n",g_oaSingleMolecules.GetSize());
619
 
                } else mprintf("]\n\n    %d molecules found.\n\n",g_oaSingleMolecules.GetSize());
620
 
        }
621
 
 
622
 
        if (g_iCloseAtomCounter != 0)
623
 
        {
624
 
                mprintf(RED,"\n*** Warning: ");
625
 
                mprintf("Some of the atoms were found to be very close to each other (distance < 50 pm).\n");
626
 
                mprintf("             This usually indicates a problem, e.g. an incorrect cell vector.\n\n");
627
 
                if (!AskYesNo("    Continue with molecule recognition anyways (y/n)? [yes] ",true))
628
 
                        return false;
629
 
                mprintf("\n");
630
 
        }
631
 
 
632
 
        mprintf("    Sorting atom types...\n");
633
 
        SortSingleMolAtomTypes();
634
 
 
635
 
        delete[] stack;
636
 
 
637
 
/*      mprintf("\n");
638
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++)
639
 
        {
640
 
                mprintf("%d ",z+1);
641
 
                ((CSingleMolecule*)g_oaSingleMolecules[z])->Dump();
642
 
        }
643
 
 
644
 
        mprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");*/
645
 
 
646
 
/*      mprintf("\n");
647
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++)
648
 
        {
649
 
                mprintf("%d ",z+1);
650
 
                ((CSingleMolecule*)g_oaSingleMolecules[z])->Dump();
651
 
        }
652
 
        mprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");*/
653
 
        if (g_iBondBlackListUsed != 0)
654
 
                mprintf("    %d bonds have been broken.\n",g_iBondBlackListUsed);
655
 
        
656
 
/*      if (g_oaSingleMolecules.GetSize() >= 4096)
657
 
        {
658
 
                mprintf("\n>>> Mehr als 4096 Molekuele! Dies wird nicht unterstuetzt. <<<\n\n");
659
 
//              g_oaSingleMolecules.GetSize() = 4096;
660
 
        }*/
661
 
 
662
 
        mprintf("    Setting up bond lists...\n");
663
 
        // Die Bindungen in m_oaMolAtoms aufbauen
664
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
665
 
        {
666
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
667
 
                for (z2=0;z2<sm->m_laBonds.GetSize()/2;z2++)
668
 
                {
669
 
                        i = sm->m_laBonds[z2*2];
670
 
                        i2 = sm->m_laBonds[z2*2+1];
671
 
                        ti = -1;
672
 
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
673
 
                        {
674
 
                                if (((CMolAtom*)sm->m_oaMolAtoms[z3])->m_iOffset == i)
675
 
                                {
676
 
                                        ti = z3;
677
 
                                        break;
678
 
                                }
679
 
                        }
680
 
                        if (ti == -1)
681
 
                        {
682
 
                                eprintf("CTimeStep::ScanMolecules(): Atom 1 of bond (%d) not found.\n",i);
683
 
                                return false;
684
 
                        }
685
 
                        ti2 = -1;
686
 
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
687
 
                        {
688
 
                                if (((CMolAtom*)sm->m_oaMolAtoms[z3])->m_iOffset == i2)
689
 
                                {
690
 
                                        ti2 = z3;
691
 
                                        break;
692
 
                                }
693
 
                        }
694
 
                        if (ti2 == -1)
695
 
                        {
696
 
                                eprintf("CTimeStep::ScanMolecules(): Atom 2 of bond (%d) not found.\n",i2);
697
 
                                return false;
698
 
                        }
699
 
                        ((CMolAtom*)sm->m_oaMolAtoms[ti])->m_oaBonds.Add((CMolAtom*)sm->m_oaMolAtoms[ti2]);
700
 
                        ((CMolAtom*)sm->m_oaMolAtoms[ti2])->m_oaBonds.Add((CMolAtom*)sm->m_oaMolAtoms[ti]);
701
 
                }
702
 
        }
703
 
 
704
 
        // Die AtomCodes berechnen
705
 
        mprintf("    Building atom codes...\n");
706
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
707
 
        {
708
 
//              mprintf("Molecule %d: ",z+1);
709
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
710
 
                if (g_bVerbose)
711
 
                        mprintf(YELLOW,"\n*** Singlemolecule %d ***\n\n",z+1);
712
 
                sm->BuildAtomCodes();
713
 
        }
714
 
 
715
 
        mprintf("    Creating topological atom order...\n");
716
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
717
 
        {
718
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
719
 
                for (z2=0;z2<sm->m_baAtomIndex.GetSize();z2++)
720
 
                {
721
 
                        try { wa = new CxIntArray("CTimeStep::ScanMolecules():wa"); } catch(...) { wa = NULL; }
722
 
                        if (wa == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
723
 
                        
724
 
                        sm->m_oaAtomOffset.Add(wa);
725
 
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
726
 
                        {
727
 
                                ma = (CMolAtom*)sm->m_oaMolAtoms[z3];
728
 
                                if (ma->m_iType != z2)
729
 
                                        continue;
730
 
                                ma->m_iNumber = wa->GetSize();
731
 
                                wa->Add(ma->m_iOffset);
732
 
                        }
733
 
                }
734
 
        }
735
 
 
736
 
        mprintf("    Creating bond list...\n");
737
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
738
 
        {
739
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
740
 
//              mprintf("%d:\n",z+1);
741
 
                for (z2=0;z2<sm->m_oaMolAtoms.GetSize();z2++)
742
 
                {
743
 
                        ma = (CMolAtom*)sm->m_oaMolAtoms[z2];
744
 
                        for (z3=0;z3<ma->m_oaBonds.GetSize();z3++)
745
 
                        {
746
 
                                ma2 = (CMolAtom*)ma->m_oaBonds[z3];
747
 
                                if (ma2->m_iMolAtomNumber < z2 /* == ma->m_iMolAtomNumber*/)
748
 
                                        continue;
749
 
 
750
 
                //              mprintf("  %s%2d <--> %s%2d\n",((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma->m_iType]])->m_sName,ma->m_iNumber+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma2->m_iType]])->m_sName,ma2->m_iNumber+1);
751
 
 
752
 
                                try { bond = new CMolBond(); } catch(...) { bond = NULL; }
753
 
                                if (bond == NULL) NewException((double)sizeof(CMolBond),__FILE__,__LINE__,__PRETTY_FUNCTION__);
754
 
                                
755
 
                                bond->m_iAtom[0] = ma->m_iNumber;
756
 
                                bond->m_iAtom[1] = ma2->m_iNumber;
757
 
                                bond->m_iAtomType[0] = ma->m_iType;
758
 
                                bond->m_iAtomType[1] = ma2->m_iType;
759
 
                                bond->m_iMolAtom[0] = z2;
760
 
                                bond->m_iMolAtom[1] = ma2->m_iMolAtomNumber;
761
 
                                bond->m_iAtomOffset[0] = ma->m_iOffset;
762
 
                                bond->m_iAtomOffset[1] = ma2->m_iOffset;
763
 
                                sm->m_oaBonds.Add(bond);
764
 
                        }
765
 
                }
766
 
/*              if (z == 0)
767
 
                        mprintf("  %d Bonds added.\n",oatemp.GetSize());*/
768
 
                for (z2=0;z2<sm->m_oaBonds.GetSize();z2++)
769
 
                {
770
 
                        bond = (CMolBond*)sm->m_oaBonds[z2];
771
 
                        for (z3=0;z3<sm->m_oaBondGroups.GetSize();z3++)
772
 
                        {
773
 
                                bg = (CMolBondGroup*)sm->m_oaBondGroups[z3];
774
 
                                for (z4=0;z4<bg->m_oaBonds.GetSize();z4++)
775
 
                                {
776
 
                                        bond2 = (CMolBond*)bg->m_oaBonds[z4];
777
 
                                        if (((((CMolAtom*)sm->m_oaMolAtoms[bond->m_iMolAtom[0]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[bond2->m_iMolAtom[0]])->m_fAtomCode) &&
778
 
                                                 (((CMolAtom*)sm->m_oaMolAtoms[bond->m_iMolAtom[1]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[bond2->m_iMolAtom[1]])->m_fAtomCode)) ||
779
 
                                                ((((CMolAtom*)sm->m_oaMolAtoms[bond->m_iMolAtom[0]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[bond2->m_iMolAtom[1]])->m_fAtomCode) &&
780
 
                                                 (((CMolAtom*)sm->m_oaMolAtoms[bond->m_iMolAtom[1]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[bond2->m_iMolAtom[0]])->m_fAtomCode)))        
781
 
                                        {
782
 
                                                bg->m_oaBonds.Add(bond);
783
 
                                                goto _bonddone;
784
 
                                        }
785
 
                                }
786
 
                        }
787
 
 
788
 
                        try { bg = new CMolBondGroup(); } catch(...) { bg = NULL; }
789
 
                        if (bg == NULL) NewException((double)sizeof(CMolBondGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
790
 
                        
791
 
                        bg->m_oaBonds.Add(bond);
792
 
                        sm->m_oaBondGroups.Add(bg);
793
 
_bonddone:;
794
 
                }
795
 
/*              if (z == 0)
796
 
                {
797
 
                        mprintf("  %d Bond groups found:\n",sm->m_oaBondGroups.GetSize());
798
 
                        for (z2=0;z2<sm->m_oaBondGroups.GetSize();z2++)
799
 
                        {
800
 
                                mprintf("  - ");
801
 
                                bg = (CMolBondGroup*)sm->m_oaBondGroups[z2];
802
 
                                for (z3=0;z3<bg->m_oaBonds.GetSize();z3++)
803
 
                                {
804
 
                                        bond = (CMolBond*)bg->m_oaBonds[z3];
805
 
                                        mprintf("%s%2d <--> %s%2d",((CAtom*)g_oaAtoms[sm->m_baAtomIndex[bond->m_iAtomType[0]]])->m_sName,bond->m_iAtom[0]+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[bond->m_iAtomType[1]]])->m_sName,bond->m_iAtom[1]+1);
806
 
                                        if (z3 < bg->m_oaBonds.GetSize()-1)
807
 
                                                mprintf(", ");
808
 
                                }
809
 
                                mprintf("\n");
810
 
                        }
811
 
                }*/
812
 
        }
813
 
 
814
 
        mprintf("    Creating angle list...\n");
815
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
816
 
        {
817
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
818
 
//              mprintf("%d:\n",z+1);
819
 
                for (z2=0;z2<sm->m_oaMolAtoms.GetSize();z2++)
820
 
                {
821
 
                        ma = (CMolAtom*)sm->m_oaMolAtoms[z2];
822
 
                        for (z3=0;z3<ma->m_oaBonds.GetSize();z3++)
823
 
                        {
824
 
                                ma2 = (CMolAtom*)ma->m_oaBonds[z3];
825
 
                                for (z4=z3+1;z4<ma->m_oaBonds.GetSize();z4++)
826
 
                                {
827
 
                                        ma3 = (CMolAtom*)ma->m_oaBonds[z4];
828
 
                        //              mprintf("  (%s%2d, %s%2d, %s%2d)\n",((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma2->m_iType]])->m_sName,ma2->m_iNumber+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma->m_iType]])->m_sName,ma->m_iNumber+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma3->m_iType]])->m_sName,ma3->m_iNumber+1);
829
 
 
830
 
                                        try { angle = new CMolAngle(); } catch(...) { angle = NULL; }
831
 
                                        if (angle == NULL) NewException((double)sizeof(CMolAngle),__FILE__,__LINE__,__PRETTY_FUNCTION__);
832
 
                                        
833
 
                                        angle->m_iAtom[0] = ma2->m_iNumber;
834
 
                                        angle->m_iAtom[1] = ma->m_iNumber;
835
 
                                        angle->m_iAtom[2] = ma3->m_iNumber;
836
 
                                        angle->m_iAtomType[0] = ma2->m_iType;
837
 
                                        angle->m_iAtomType[1] = ma->m_iType;
838
 
                                        angle->m_iAtomType[2] = ma3->m_iType;
839
 
                                        angle->m_iMolAtom[0] = ma2->m_iMolAtomNumber;
840
 
                                        angle->m_iMolAtom[1] = z2;
841
 
                                        angle->m_iMolAtom[2] = ma3->m_iMolAtomNumber;
842
 
                                        angle->m_iAtomOffset[0] = ma2->m_iOffset;
843
 
                                        angle->m_iAtomOffset[1] = ma->m_iOffset;
844
 
                                        angle->m_iAtomOffset[2] = ma3->m_iOffset;
845
 
                                        sm->m_oaAngles.Add(angle);
846
 
                                }
847
 
                        }
848
 
                }
849
 
/*              if (z ==  0)
850
 
                        mprintf("  %d Angles added.\n",oatemp.GetSize());*/
851
 
                if (sm->m_oaAngles.GetSize() > 1000)
852
 
                        mprintf(WHITE,"      [");
853
 
                tfs = sm->m_oaAngles.GetSize() / 50.0;
854
 
                for (z2=0;z2<sm->m_oaAngles.GetSize();z2++)
855
 
                {
856
 
                        if (sm->m_oaAngles.GetSize() > 1000)
857
 
                                if (fmod(z2,tfs) < 1)
858
 
                                        mprintf(WHITE,"#");
859
 
                        angle = (CMolAngle*)sm->m_oaAngles[z2];
860
 
                        for (z3=0;z3<sm->m_oaAngleGroups.GetSize();z3++)
861
 
                        {
862
 
                                ag = (CMolAngleGroup*)sm->m_oaAngleGroups[z3];
863
 
                                for (z4=0;z4<ag->m_oaAngles.GetSize();z4++)
864
 
                                {
865
 
                                        angle2 = (CMolAngle*)ag->m_oaAngles[z4];
866
 
                                        if (( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[1]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[1]])->m_fAtomCode) &&
867
 
                                                (((( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[0]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[0]])->m_fAtomCode) &&
868
 
                                                ( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[2]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[2]])->m_fAtomCode))) ||
869
 
                                                (( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[0]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[2]])->m_fAtomCode) &&
870
 
                                                ( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[2]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[0]])->m_fAtomCode))))     
871
 
                                        {
872
 
                                                ag->m_oaAngles.Add(angle);
873
 
                                                goto _angledone;
874
 
                                        }
875
 
                                }
876
 
                        }
877
 
 
878
 
                        try { ag = new CMolAngleGroup(); } catch(...) { ag = NULL; }
879
 
                        if (ag == NULL) NewException((double)sizeof(CMolAngleGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
880
 
                        
881
 
                        ag->m_oaAngles.Add(angle);
882
 
                        sm->m_oaAngleGroups.Add(ag);
883
 
_angledone:;
884
 
                }
885
 
                if (sm->m_oaAngles.GetSize() > 1000)
886
 
                        mprintf(WHITE,"]\n");
887
 
/*              if (z == 0)
888
 
                {
889
 
                        mprintf("  %d Angle groups found:\n",sm->m_oaAngleGroups.GetSize());
890
 
                        for (z2=0;z2<sm->m_oaAngleGroups.GetSize();z2++)
891
 
                        {
892
 
                                mprintf("  - ");
893
 
                                ag = (CMolAngleGroup*)sm->m_oaAngleGroups[z2];
894
 
                                for (z3=0;z3<ag->m_oaAngles.GetSize();z3++)
895
 
                                {
896
 
                                        angle = (CMolAngle*)ag->m_oaAngles[z3];
897
 
                                        mprintf("  (%s%2d, %s%2d, %s%2d)",((CAtom*)g_oaAtoms[sm->m_baAtomIndex[angle->m_iAtomType[0]]])->m_sName,angle->m_iAtom[0]+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[angle->m_iAtomType[1]]])->m_sName,angle->m_iAtom[1]+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[angle->m_iAtomType[2]]])->m_sName,angle->m_iAtom[2]+1);
898
 
                                        if (z3 < ag->m_oaAngles.GetSize()-1)
899
 
                                                mprintf(", ");
900
 
                                }
901
 
                                mprintf("\n");
902
 
                        }
903
 
                }*/
904
 
        }
905
 
 
906
 
        mprintf("    Grouping together equivalent molecules...\n");
907
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) // Alle Molekuelvertreter durchgehen
908
 
        {
909
 
//              mprintf("Pruefe SM %d...\n",z+1);
910
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
911
 
                for (z2=0;z2<g_oaMolecules.GetSize();z2++) // Alle schon vorhandenen Molekueltemplates durchgehen
912
 
                {
913
 
                        m = (CMolecule*)g_oaMolecules[z2];
914
 
                        sm2 = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[0]];
915
 
/*                      if (m->m_baAtomIndex.GetSize() != sm->m_baAtomIndex.GetSize())
916
 
                                goto _cont; // Nich die Gleiche Anzahl verschiedener Elemente -> Keine Uebereinstimmung
917
 
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
918
 
                        {
919
 
                                if (m->m_baAtomIndex[z3] != sm->m_baAtomIndex[z3])
920
 
                                        goto _cont; // Elemente an Position z3 unterscheiden sich -> keine Uebereinstimmung
921
 
                                if (m->m_waAtomCount[z3] != ((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize())
922
 
                                        goto _cont; // Anzahl an Atomen dieser Elementsorte unterscheidet sich -> Keine Uebereinstimmung*/
923
 
//                              mprintf("  Stimmt mit M%d ueberein.\n",z2);
924
 
//                              ((CMolecule*)g_oaMolecules[z2])->Count++;
925
 
//                              g_pSingleMolecules[z].m_iMoleculeOffset = z2;
926
 
//                      }
927
 
                        if (sm->m_oaMolAtoms.GetSize() != sm2->m_oaMolAtoms.GetSize())
928
 
                                goto _cont;
929
 
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
930
 
                                if (((CMolAtom*)sm->m_oaMolAtoms[z3])->m_fAtomCode != ((CMolAtom*)sm2->m_oaMolAtoms[z3])->m_fAtomCode)
931
 
                                        goto _cont;
932
 
                        sm->m_iMolSMIndex = m->m_laSingleMolIndex.GetSize();
933
 
                        m->m_laSingleMolIndex.Add(z);
934
 
//                      sm->m_iMolType = z2;
935
 
                        goto _fert;
936
 
                        _cont:;
937
 
                }
938
 
 
939
 
                try { m = new CMolecule(); } catch(...) { m = NULL; }
940
 
                if (m == NULL) NewException((double)sizeof(CMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
941
 
                
942
 
                g_oaMolecules.Add(m);
943
 
//              m->Count = 1; // Neues Molekueltemplate hinzufuegen
944
 
//              m->Elements = ((CSingleMolecule*)g_oaSingleMolecules[z])->m_iElements;
945
 
                m->m_iAtomGes = 0;
946
 
                f = 0;
947
 
                for (z2=0;z2<sm->m_oaAtomOffset.GetSize();z2++)
948
 
                {
949
 
                        m->m_iAtomGes += ((CxIntArray*)sm->m_oaAtomOffset[z2])->GetSize();
950
 
                        f += ((CAtom*)g_oaAtoms[sm->m_baAtomIndex[z2]])->m_pElement->m_fMass * ((CxIntArray*)sm->m_oaAtomOffset[z2])->GetSize();
951
 
                }
952
 
                m->m_iAtomGesNoVirt = m->m_iAtomGes;
953
 
                m->m_fMass = f;
954
 
                ((CSingleMolecule*)g_oaSingleMolecules[z])->m_iMolType = g_oaMolecules.GetSize()-1;
955
 
                for (z2=0;z2<((CSingleMolecule*)g_oaSingleMolecules[z])->m_baAtomIndex.GetSize();z2++)
956
 
                {
957
 
                        m->m_baAtomIndex.Add(((CSingleMolecule*)g_oaSingleMolecules[z])->m_baAtomIndex[z2]);
958
 
                        m->m_waAtomCount.Add(((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[z])->m_oaAtomOffset[z2])->GetSize());
959
 
//                      m->AtomCount[z2] = ((CSingleMolecule*)g_oaSingleMolecules[z])->m_iAtomCount[z2];
960
 
                }
961
 
                sm->m_iMolSMIndex = m->m_laSingleMolIndex.GetSize();
962
 
                m->m_laSingleMolIndex.Add(z);
963
 
//              g_pSingleMolecules[z].m_iMoleculeOffset = g_oaMolecules.GetSize();
964
 
                m->BuildName();
965
 
 
966
 
                // Standardmaessig geom. Zentrum als Dipolzentrum
967
 
                m->m_iDipoleCenterType = m->m_baAtomIndex.GetSize();
968
 
                m->m_iDipoleCenterIndex = 0;
969
 
 
970
 
//              mprintf("### Erzeuge neues Molekuel %d \"%s\".\n",g_oaMolecules.GetSize(),m->Name);
971
 
//              g_oaMolecules.GetSize()++;
972
 
                _fert:;
973
 
        }
974
 
        mprintf("    Found %d unique molecule types.\n",g_oaMolecules.GetSize());
975
 
 
976
 
        // Sort by molecular mass
977
 
        mprintf("    Sorting molecule types by molecular mass...\n");
978
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
979
 
        {
980
 
//              mprintf("@ z=%d\n",z);
981
 
                f = -1.0f;
982
 
                z3 = -1;
983
 
                for (z2=z;z2<g_oaMolecules.GetSize();z2++)
984
 
                {
985
 
//                      mprintf("@   z2=%d\n",z2);
986
 
                        if (((CMolecule*)g_oaMolecules[z2])->m_fMass > f)
987
 
                        {
988
 
//                              mprintf("@     %f > %f --> z3 = %d\n",((CMolecule*)g_oaMolecules[z2])->m_fMass,f,z2);
989
 
                                f = ((CMolecule*)g_oaMolecules[z2])->m_fMass;
990
 
                                z3 = z2;
991
 
                        }
992
 
                }
993
 
                if (z3 == -1)
994
 
                        abort();
995
 
                if (f > 0)
996
 
                {
997
 
//                      mprintf("@ Swapping %d with %d.\n",z,z3);
998
 
                        m = (CMolecule*)g_oaMolecules[z3];
999
 
                        g_oaMolecules[z3] = g_oaMolecules[z];
1000
 
                        g_oaMolecules[z] = m;
1001
 
                }
1002
 
        }
1003
 
 
1004
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
1005
 
        {
1006
 
                ((CMolecule*)g_oaMolecules[z])->m_iIndex = z;
1007
 
                for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
1008
 
                        ((CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[z2]])->m_iMolType = z;
1009
 
        }
1010
 
 
1011
 
 
1012
 
/*      for (z=0;z<g_oaMolecules.GetSize();z++)
1013
 
        {
1014
 
                m = (CMolecule*)g_oaMolecules[z];
1015
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
1016
 
                mprintf("Molecule %d Ring systems:\n",z+1);
1017
 
                for (z2=0;z2<sm->m_oaRings.GetSize();z2++)
1018
 
                {
1019
 
                        wa = (CxIntArray*)sm->m_oaRings[z2];
1020
 
                        mprintf("  - Ring %d: ",z2+1);
1021
 
                        for (z3=0;z3<wa->GetSize();z3++)
1022
 
                        {
1023
 
                                mprintf("%d",(*wa)[z3]);
1024
 
                                if (z3+1 < wa->GetSize())
1025
 
                                        mprintf(", ");
1026
 
                        }
1027
 
                        mprintf("\n");
1028
 
                }
1029
 
                mprintf("\n");
1030
 
        }*/
1031
 
 
1032
 
        ti = 0;
1033
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
1034
 
        {
1035
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
1036
 
                ti += sm->m_oaRings.GetSize();
1037
 
        }
1038
 
 
1039
 
        mprintf("    Found %d rings.\n",ti);
1040
 
        if (ti != 0)
1041
 
        {
1042
 
                mprintf("    Refining ring systems...\n");
1043
 
 
1044
 
                try { wa = new CxIntArray("CTimeStep::ScanMolecules():wa"); } catch(...) { wa = NULL; }
1045
 
                if (wa == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1046
 
                
1047
 
                // Process ring systems
1048
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
1049
 
                {
1050
 
                        m = (CMolecule*)g_oaMolecules[z];
1051
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
1052
 
                        if (sm->m_oaRings.GetSize() > 100)
1053
 
                        {
1054
 
                                eprintf("      More than 100 rings in molecule %d, skipping refinement. Ring system may be improper.\n",z+1);
1055
 
                                continue;
1056
 
                        }
1057
 
                        ti2 = 0;
1058
 
_again:
1059
 
                        ti2++;
1060
 
                        if (ti2 > 1000)
1061
 
                        {
1062
 
                                eprintf("      Too many iterations in molecule %d, aborting refinement. Ring system may be improper.\n",z+1);
1063
 
                                continue;
1064
 
                        }
1065
 
//                      mprintf("### again\n");
1066
 
                        for (z2=0;z2<sm->m_oaRings.GetSize();z2++)
1067
 
                        {
1068
 
                                waz2 = (CxIntArray*)sm->m_oaRings[z2];
1069
 
                                for (z3=z2+1;z3<sm->m_oaRings.GetSize();z3++)
1070
 
                                {
1071
 
                                        waz3 = (CxIntArray*)sm->m_oaRings[z3];
1072
 
 
1073
 
//                                      mprintf("*A* Checking if %d(%d) contains %d(%d)...\n",z2+1,waz2->GetSize(),z3+1,waz3->GetSize());
1074
 
                                        // Check if waz2 contains waz3
1075
 
                                        wa->SetSize(waz2->GetSize());
1076
 
                                        for (z4=0;z4<waz2->GetSize();z4++)
1077
 
                                                (*wa)[z4] = 0;
1078
 
                                        for (z4=0;z4<waz3->GetSize();z4++)
1079
 
                                        {
1080
 
                                                for (z5=0;z5<waz2->GetSize();z5++)
1081
 
                                                {
1082
 
                                                        if ((*waz3)[z4] == (*waz2)[z5])
1083
 
                                                        {
1084
 
                                                                (*wa)[z5] = 1;
1085
 
                                                                goto _found2;
1086
 
                                                        }
1087
 
                                                }
1088
 
                                                goto _notfound2;
1089
 
_found2:;
1090
 
                                        }
1091
 
//                                      mprintf("  Yes!\n");
1092
 
 
1093
 
                                        try { waneu = new CxIntArray("CTimeStep::ScanMolecules():waneu"); } catch(...) { waneu = NULL; }
1094
 
                                        if (waneu == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1095
 
                                        
1096
 
                                        for (z4=0;z4<waz2->GetSize();z4++)
1097
 
                                        {
1098
 
                                                if (z4 == 0)
1099
 
                                                {
1100
 
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4+1] == 0) || ((*wa)[waz2->GetSize()-1] == 0))
1101
 
                                                                waneu->Add((*waz2)[z4]);
1102
 
                                                } else if (z4 == waz2->GetSize()-1)
1103
 
                                                {
1104
 
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4-1] == 0) || ((*wa)[0] == 0))
1105
 
                                                                waneu->Add((*waz2)[z4]);
1106
 
                                                } else
1107
 
                                                {
1108
 
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4+1] == 0) || ((*wa)[z4-1] == 0))
1109
 
                                                                waneu->Add((*waz2)[z4]);
1110
 
                                                }
1111
 
                                        }
1112
 
//                                      mprintf("   Took %d from %d atoms from waz2.\n",waneu->GetSize(),waz2->GetSize());
1113
 
                                        i1 = waz2->GetSize();
1114
 
                                        delete waz2;
1115
 
                                        sm->m_oaRings[z2] = waneu;
1116
 
                                        if (waneu->GetSize() != i1)
1117
 
                                                goto _again;
1118
 
_notfound2:
1119
 
 
1120
 
//                                      mprintf("*B* Checking if %d contains %d...\n",z3+1,z2+1);
1121
 
                                        // Check if waz3 contains waz2
1122
 
                                        wa->SetSize(waz3->GetSize());
1123
 
                                        for (z4=0;z4<waz3->GetSize();z4++)
1124
 
                                                (*wa)[z4] = 0;
1125
 
                                        for (z4=0;z4<waz2->GetSize();z4++)
1126
 
                                        {
1127
 
                                                for (z5=0;z5<waz3->GetSize();z5++)
1128
 
                                                {
1129
 
                                                        if ((*waz2)[z4] == (*waz3)[z5])
1130
 
                                                        {
1131
 
                                                                (*wa)[z5] = 1;
1132
 
                                                                goto _found3;
1133
 
                                                        }
1134
 
                                                }
1135
 
                                                goto _notfound3;
1136
 
_found3:;
1137
 
                                        }
1138
 
//                                      mprintf("  Yes!\n");
1139
 
 
1140
 
                                        try { waneu = new CxIntArray("CTimeStep::ScanMolecules():waneu"); } catch(...) { waneu = NULL; }
1141
 
                                        if (waneu == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1142
 
                                        
1143
 
                                        for (z4=0;z4<waz3->GetSize();z4++)
1144
 
                                        {
1145
 
                                                if (z4 == 0)
1146
 
                                                {
1147
 
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4+1] == 0) || ((*wa)[waz3->GetSize()-1] == 0))
1148
 
                                                                waneu->Add((*waz3)[z4]);
1149
 
                                                } else if (z4 == waz3->GetSize()-1)
1150
 
                                                {
1151
 
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4-1] == 0) || ((*wa)[0] == 0))
1152
 
                                                                waneu->Add((*waz3)[z4]);
1153
 
                                                } else
1154
 
                                                {
1155
 
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4+1] == 0) || ((*wa)[z4-1] == 0))
1156
 
                                                                waneu->Add((*waz3)[z4]);
1157
 
                                                }
1158
 
                                        }
1159
 
//                                      mprintf("   Took %d from %d atoms from waz3.\n",waneu->GetSize(),waz3->GetSize());
1160
 
                                        i1 = waz3->GetSize();
1161
 
                                        delete waz3;
1162
 
                                        sm->m_oaRings[z3] = waneu;
1163
 
                                        if (waneu->GetSize() != i1)
1164
 
                                                goto _again;
1165
 
_notfound3:;
1166
 
                                }
1167
 
                        }
1168
 
                }
1169
 
                delete wa;
1170
 
 
1171
 
                mprintf("    Assigning ring systems to molecule types...\n");
1172
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
1173
 
                {
1174
 
                        m = (CMolecule*)g_oaMolecules[z];
1175
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
1176
 
                        for (z2=0;z2<sm->m_oaRings.GetSize();z2++)
1177
 
                        {
1178
 
                                wa = (CxIntArray*)sm->m_oaRings[z2];
1179
 
 
1180
 
                                try { waz2 = new CxIntArray("CTimeStep::ScanMolecules():waz2"); } catch(...) { waz2 = NULL; }
1181
 
                                if (waz2 == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1182
 
                                
1183
 
                                try { waz3 = new CxIntArray("CTimeStep::ScanMolecules():waz3"); } catch(...) { waz3 = NULL; }
1184
 
                                if (waz3 == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
1185
 
                                
1186
 
                                m->m_oaRingAtomTypes.Add(waz2);
1187
 
                                m->m_oaRingAtoms.Add(waz3);
1188
 
                                for (z3=0;z3<wa->GetSize();z3++)
1189
 
                                {
1190
 
                                        for (z4=0;z4<sm->m_baAtomIndex.GetSize();z4++)
1191
 
                                        {
1192
 
                                                for (z5=0;z5<((CxIntArray*)sm->m_oaAtomOffset[z4])->GetSize();z5++)
1193
 
                                                {
1194
 
                                                        if (((CxIntArray*)sm->m_oaAtomOffset[z4])->GetAt(z5) == wa->GetAt(z3))
1195
 
                                                        {
1196
 
                                                                waz2->Add(z4);
1197
 
                                                                waz3->Add(z5);
1198
 
                                                                goto _done;
1199
 
                                                        }
1200
 
                                                }
1201
 
                                        }
1202
 
_done:;
1203
 
                                }
1204
 
                        }
1205
 
                }
1206
 
 
1207
 
                mprintf("    Sorting rings by size...\n");
1208
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
1209
 
                {
1210
 
                        m = (CMolecule*)g_oaMolecules[z];
1211
 
 
1212
 
                        for (z2=0;z2<m->m_oaRingAtoms.GetSize();z2++)
1213
 
                        {
1214
 
                                i1 = 0;
1215
 
                                ti = -1;
1216
 
                                for (z3=z2;z3<m->m_oaRingAtoms.GetSize();z3++)
1217
 
                                {
1218
 
                                        if (((CxIntArray*)m->m_oaRingAtoms[z3])->GetSize() > i1)
1219
 
                                        {
1220
 
                                                i1 = ((CxIntArray*)m->m_oaRingAtoms[z3])->GetSize();
1221
 
                                                ti = z3;
1222
 
                                        }
1223
 
                                }
1224
 
                                if ((ti != -1) && (ti != z2))
1225
 
                                {
1226
 
                                        wa = (CxIntArray*)m->m_oaRingAtoms[z2];
1227
 
                                        m->m_oaRingAtoms[z2] = m->m_oaRingAtoms[ti];
1228
 
                                        m->m_oaRingAtoms[ti] = wa;
1229
 
                                        wa = (CxIntArray*)m->m_oaRingAtomTypes[z2];
1230
 
                                        m->m_oaRingAtomTypes[z2] = m->m_oaRingAtomTypes[ti];
1231
 
                                        m->m_oaRingAtomTypes[ti] = wa;
1232
 
                                }
1233
 
                        }
1234
 
                }
1235
 
        }
1236
 
 
1237
 
/*      for (z=0;z<g_oaMolecules.GetSize();z++)
1238
 
        {
1239
 
                m = (CMolecule*)g_oaMolecules[z];
1240
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
1241
 
                mprintf("Molecule %d Ring systems:\n",z+1);
1242
 
                for (z2=0;z2<sm->m_oaRings.GetSize();z2++)
1243
 
                {
1244
 
                        wa = (CxIntArray*)sm->m_oaRings[z2];
1245
 
                        mprintf("  - Ring %d: ",z2+1);
1246
 
                        for (z3=0;z3<wa->GetSize();z3++)
1247
 
                        {
1248
 
                                mprintf("%d",(*wa)[z3]);
1249
 
                                if (z3+1 < wa->GetSize())
1250
 
                                        mprintf(", ");
1251
 
                        }
1252
 
                        mprintf("\n");
1253
 
                }
1254
 
                mprintf("\n");
1255
 
        }*/
1256
 
 
1257
 
/*      mprintf("\n%d Molekuelsorten gefunden.\n",g_oaMolecules.GetSize());
1258
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
1259
 
        mprintf("Molekuel \"%s\": %d Atome gesamt, %d mal in der Simulation.\n",g_pMolecules[z].Name,g_pMolecules[z].AtomGes,g_pMolecules[z].Count);
1260
 
        */
1261
 
/*      mprintf("\n");
1262
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
1263
 
        {
1264
 
                mprintf("%d ",z+1);
1265
 
                ((CMolecule*)g_oaMolecules[z])->Dump();
1266
 
        }*/
1267
 
        mprintf("    Molecule recognition finished.\n");
1268
 
        BTOUT; 
1269
 
        return true;
1270
 
}
1271
 
 
1272
 
 
1273
 
void CTimeStep::RECURSION_MegaTree(int i, char *ta, int depth, unsigned long bmask, bool w, int *stack)
1274
 
{
1275
 
        BTIN;
1276
 
        int z, z2;
1277
 
        int nblist[20], nbs;
1278
 
 
1279
 
        stack[depth] = i;
1280
 
        ta[i] = 1;
1281
 
        for (z=1;z<depth;z++)
1282
 
        {
1283
 
                if ((bmask & (int)pow(2.0,z)) != 0)
1284
 
                        mprintf(WHITE,"|  ");
1285
 
                                else mprintf("   ");
1286
 
        }
1287
 
        if (depth != 0)
1288
 
        {
1289
 
                if (w)
1290
 
                        mprintf(WHITE,"|--");
1291
 
                                else mprintf(WHITE,"`--");
1292
 
        }
1293
 
        mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[i]])->m_sName,i+1);
1294
 
        nbs = 0;
1295
 
        for (z=0;z<(long)m_iGesAtomCount;z++) // Schon mal alle Nachbarn raussuchen
1296
 
        {
1297
 
                if (z == i)
1298
 
                        continue;
1299
 
                if (BondRange(i,z,NULL))
1300
 
                {
1301
 
                        if (ta[z] != 0)
1302
 
                        {
1303
 
                                if ((depth > 0) && (z != stack[depth-1]))
1304
 
                                {
1305
 
                                        mprintf(GREEN,"  <-- Ring closure: ");
1306
 
                                        mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[stack[depth]]])->m_sName,stack[depth]+1);
1307
 
                                        z2 = depth-1;
1308
 
                                        while ((stack[z2] != z) && (z2 >= 0))
1309
 
                                        {
1310
 
                                                mprintf(" - %s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[stack[z2]]])->m_sName,stack[z2]+1);
1311
 
                                                z2--;
1312
 
                                        }
1313
 
                                        mprintf(" - %s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1);
1314
 
//                                      mprintf("Ringschluss! [d-1=%d,d=%d,i=%d] %s(%d)\n",stack[depth-1]+1,stack[depth]+1,i+1,((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1);
1315
 
                                }
1316
 
                                continue;
1317
 
                        }
1318
 
                        nblist[nbs] = z;
1319
 
                        nbs++;
1320
 
                }
1321
 
        }
1322
 
        mprintf("\n");
1323
 
        for (z=0;z<nbs;z++) // Fuer das aktuelle Atom z2 alle Nachbarn finden
1324
 
        {
1325
 
                if (ta[nblist[z]] != 0) // Der Nachbar wurde uns weggeschnappt -> Ringschluss
1326
 
                {
1327
 
                        for (z2=1;z2<depth+1;z2++)
1328
 
                        {
1329
 
                                if ((bmask & (int)pow(2.0,z2)) != 0)
1330
 
                                        mprintf(WHITE,"|  ");
1331
 
                                                else mprintf("   ");
1332
 
                        }
1333
 
                        if (z+1 < nbs)
1334
 
                                mprintf(WHITE,"|--");
1335
 
                                        else mprintf("`--");
1336
 
                        mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[nblist[z]]])->m_sName,nblist[z]+1);
1337
 
                        mprintf(GREEN,"  <-- Ring closure\n");
1338
 
                } else
1339
 
                {
1340
 
                        if (z+1 == nbs)
1341
 
                                bmask -= (int)pow(2.0,depth+1);
1342
 
                        RECURSION_MegaTree(nblist[z],ta,/*sm,*/depth+1,bmask,(z+1==nbs)?false:true,stack);
1343
 
                }
1344
 
        }
1345
 
        BTOUT; 
1346
 
}
1347
 
 
1348
 
 
1349
 
void CTimeStep::PrintMegaTree()
1350
 
{
1351
 
        BTIN;
1352
 
        int z;
1353
 
        char ta[16384];
1354
 
        int stack[16384];
1355
 
 
1356
 
        for (z=0;z<16384;z++)
1357
 
                ta[z] = 0;
1358
 
        for (z=0;z<(long)m_iGesAtomCount;z++)
1359
 
        {
1360
 
                if (ta[z] != 0) // Dieses Atom wurde bereits in irgendein Molekuel eingebaut
1361
 
                        continue;
1362
 
                mprintf(YELLOW,"\nThe next molecule starts with %s(%d):\n",m_paLabels[z],z+1);
1363
 
                RECURSION_MegaTree(z,ta,0,0xFFFFFFFF,true,stack);
1364
 
        }
1365
 
        mprintf("\n");
1366
 
        BTOUT; 
1367
 
}
1368
 
 
1369
 
 
1370
 
void CTimeStep::PrintMatrix(bool onlyfirst, bool onlybind)
1371
 
{
1372
 
        BTIN;
1373
 
        int z, z2, z3, z4, z5, z6, z7, z8, ti, ti2;
1374
 
        float tf;
1375
 
        bool b, c, noh;
1376
 
        CxVector3 vec1, vec2;
1377
 
        CSingleMolecule *sm;
1378
 
        CMolecule *m;
1379
 
        CMolAtom *ma, *ma0;
1380
 
        CxIntArray *wa, *wat;
1381
 
 
1382
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
1383
 
        {
1384
 
                m = (CMolecule*)g_oaMolecules[z];
1385
 
                for (z6=0;z6<(onlyfirst?1:m->m_laSingleMolIndex.GetSize());z6++)
1386
 
                {
1387
 
                        mprintf(YELLOW,"\n*** Molecule %d: %s; Representant %d; Distances in pm ***\n",z+1,m->m_sName,z6+1);
1388
 
                        if ((m->m_baAtomIndex.GetSize() == 1) && (m->m_waAtomCount[0] == 1))
1389
 
                        {
1390
 
                                mprintf("[only 1 Atom]\n");
1391
 
                                continue;
1392
 
                        }
1393
 
                        if (m->m_iAtomGes > 200)
1394
 
                        {
1395
 
                                mprintf(WHITE,"\n    This molecule has > 200 atoms. Output would flood the screen. Skipping.\n");
1396
 
                                continue;
1397
 
                        }
1398
 
                        noh = false;
1399
 
_matagain:
1400
 
                        if (m->m_oaRingAtoms.GetSize() != 0)
1401
 
                                mprintf(GREEN,"    (ring bonds are shown in green)\n");
1402
 
                        mprintf("\n");
1403
 
                        mprintf("   ");
1404
 
                        for (z2=0;z2<m->m_baAtomIndex.GetSize();z2++)
1405
 
                        {
1406
 
                                if (noh) // Skip H atoms
1407
 
                                        if (mystricmp(((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,"H") == 0)
1408
 
                                                continue;
1409
 
                                for (z3=0;z3<m->m_waAtomCount[z2];z3++)
1410
 
                                {
1411
 
                                        if (((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName[1] == 0)
1412
 
                                                mprintf(" ");
1413
 
                                        mprintf(WHITE,"%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,z3+1);  
1414
 
                                        if (z3+1 < 10)
1415
 
                                                mprintf(" ");
1416
 
                                }
1417
 
                        }
1418
 
                        mprintf("\n");
1419
 
                        for (z2=0;z2<m->m_baAtomIndex.GetSize();z2++)
1420
 
                        {
1421
 
                                if (noh) // Skip H atoms
1422
 
                                        if (mystricmp(((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,"H") == 0)
1423
 
                                                continue;
1424
 
                                for (z3=0;z3<m->m_waAtomCount[z2];z3++)
1425
 
                                {
1426
 
                                        mprintf(WHITE,"%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,z3+1);
1427
 
                                        if (((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName[1] == 0)
1428
 
                                                mprintf(" ");
1429
 
                                        if (z3+1 < 10)
1430
 
                                                mprintf(" ");
1431
 
                                        for (z4=0;z4<m->m_baAtomIndex.GetSize();z4++)
1432
 
                                        {
1433
 
                                                if (noh) // Skip H atoms
1434
 
                                                        if (mystricmp(((CAtom*)g_oaAtoms[m->m_baAtomIndex[z4]])->m_sName,"H") == 0)
1435
 
                                                                continue;
1436
 
                                                for (z5=0;z5<m->m_waAtomCount[z4];z5++)
1437
 
                                                {
1438
 
                                                        if ((z2 == z4) && (z3 == z5))
1439
 
                                                        {
1440
 
                                                                mprintf(BLUE,"*** ");
1441
 
                                                                continue;
1442
 
                                                        }
1443
 
                                                        ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z6]])->m_oaAtomOffset[z2])->GetAt(z3);
1444
 
                                                        vec1 = g_TimeStep.m_vaCoords[ti];
1445
 
                                                        ti2 = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z6]])->m_oaAtomOffset[z4])->GetAt(z5);
1446
 
                                                        vec2 = g_TimeStep.m_vaCoords[ti2];
1447
 
                                                        vec1 -= vec2;
1448
 
                                                        tf = vec1.GetLength();
1449
 
                                                        if ((g_TimeStep.BondRange(ti,ti2,NULL)) || (!onlybind))
1450
 
                                                        {
1451
 
                                                                for (z8=0;z8<m->m_oaRingAtomTypes.GetSize();z8++)
1452
 
                                                                {
1453
 
                                                                        wat = (CxIntArray*)m->m_oaRingAtomTypes[z8];
1454
 
                                                                        wa = (CxIntArray*)m->m_oaRingAtoms[z8];
1455
 
                                                                        for (z7=0;z7<wa->GetSize();z7++)
1456
 
                                                                        {
1457
 
                                                                                if (((*wat)[z7] == z2) && ((*wa)[z7] == z3))
1458
 
                                                                                {
1459
 
                                                                                        if (z7 == 0)
1460
 
                                                                                        {
1461
 
                                                                                                if (((*wat)[z7+1] == z4) && ((*wa)[z7+1] == z5))
1462
 
                                                                                                        goto _green;
1463
 
                                                                                                if (((*wat)[wa->GetSize()-1] == z4) && ((*wa)[wa->GetSize()-1] == z5))
1464
 
                                                                                                        goto _green;
1465
 
                                                                                        } else if (z7 == wa->GetSize()-1)
1466
 
                                                                                        {
1467
 
                                                                                                if (((*wat)[0] == z4) && ((*wa)[0] == z5))
1468
 
                                                                                                        goto _green;
1469
 
                                                                                                if (((*wat)[z7-1] == z4) && ((*wa)[z7-1] == z5))
1470
 
                                                                                                        goto _green;
1471
 
                                                                                        } else
1472
 
                                                                                        {
1473
 
                                                                                                if (((*wat)[z7+1] == z4) && ((*wa)[z7+1] == z5))
1474
 
                                                                                                        goto _green;
1475
 
                                                                                                if (((*wat)[z7-1] == z4) && ((*wa)[z7-1] == z5))
1476
 
                                                                                                        goto _green;
1477
 
                                                                                        }
1478
 
                                                                                }
1479
 
                                                                        }
1480
 
                                                                }
1481
 
                                                                mprintf("%3.0f ",tf);
1482
 
                                                                continue;
1483
 
_green:
1484
 
                                                                mprintf(GREEN,"%3.0f ",tf);
1485
 
                                                        } else mprintf(" -  ");
1486
 
                                                }
1487
 
                                        }       
1488
 
                                        mprintf("\n");
1489
 
                                }
1490
 
                        }
1491
 
                        if ((!noh) && (m->m_iAtomGes > 30))
1492
 
                        {
1493
 
                                mprintf(WHITE,"\n    This was a very large molecule.\n    Printing the matrix again without H atoms.\n");
1494
 
                                noh = true;
1495
 
                                goto _matagain;
1496
 
                        }
1497
 
//                      if (((!onlyfirst) && ((z2 < ((CMolecule*)g_oaMolecules[z])->Elements-1) || (g_oaMolecules.GetSize()-1))) || (z < g_oaMolecules.GetSize()-1))
1498
 
//                              mprintf(">>>");
1499
 
                }
1500
 
 
1501
 
                if (m->m_oaRingAtoms.GetSize() != 0)
1502
 
                {
1503
 
                        mprintf("\n");
1504
 
                        for (z2=0;z2<m->m_oaRingAtoms.GetSize();z2++)
1505
 
                        {
1506
 
                                mprintf("    %d-ring: ",((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize());
1507
 
                                if (((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize() > 20)
1508
 
                                {
1509
 
                                        for (z3=0;z3<5;z3++)
1510
 
                                        {
1511
 
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[((CxIntArray*)m->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)m->m_oaRingAtoms[z2])->GetAt(z3)+1);
1512
 
                                                if (z3+1 < ((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize())
1513
 
                                                        mprintf(" - ");
1514
 
                                        }
1515
 
                                        mprintf(RED,"...");
1516
 
                                        mprintf(" - ");
1517
 
                                        for (z3=((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize()-5;z3<((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize();z3++)
1518
 
                                        {
1519
 
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[((CxIntArray*)m->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)m->m_oaRingAtoms[z2])->GetAt(z3)+1);
1520
 
                                                if (z3+1 < ((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize())
1521
 
                                                        mprintf(" - ");
1522
 
                                        }
1523
 
                                } else
1524
 
                                {
1525
 
                                        for (z3=0;z3<((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize();z3++)
1526
 
                                        {
1527
 
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[((CxIntArray*)m->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)m->m_oaRingAtoms[z2])->GetAt(z3)+1);
1528
 
                                                if (z3+1 < ((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize())
1529
 
                                                        mprintf(" - ");
1530
 
                                        }
1531
 
                                }
1532
 
                                mprintf("\n");
1533
 
                                if (z2 >= 99)
1534
 
                                {
1535
 
                                        mprintf(RED,"\n    Only showing the first 100 rings.\n");
1536
 
                                        break;
1537
 
                                }
1538
 
                        }
1539
 
                }
1540
 
 
1541
 
                c = false;
1542
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[0]];
1543
 
                for (z2=0;z2<m->m_baAtomIndex.GetSize();z2++)
1544
 
                {
1545
 
                        b = false;
1546
 
                        ma = NULL;
1547
 
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
1548
 
                        {
1549
 
                                if (((CMolAtom*)sm->m_oaMolAtoms[z3])->m_iType != z2)
1550
 
                                        continue;
1551
 
                                ma0 = ma;
1552
 
                                ma = (CMolAtom*)sm->m_oaMolAtoms[z3];
1553
 
                                if (ma0 == NULL)
1554
 
                                        continue;
1555
 
                                z4 = ma0->m_iNumber;
1556
 
                                if (ma->m_fAtomCode == ma0->m_fAtomCode)
1557
 
                                {
1558
 
                                        if (b)
1559
 
                                        {
1560
 
                                                mprintf(", %s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,ma->m_iNumber+1);
1561
 
                                        } else
1562
 
                                        {
1563
 
                                                if (!c)
1564
 
                                                {
1565
 
                                                        c = true;
1566
 
                                                        mprintf("\n");
1567
 
                                                }
1568
 
                                                mprintf("    Atoms %s%d, %s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,z4+1,((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,ma->m_iNumber+1);
1569
 
                                                b = true;
1570
 
                                        }
1571
 
                                } else if (b)
1572
 
                                {
1573
 
                                        mprintf(" are equivalent.\n");
1574
 
                                        b = false;
1575
 
                                }
1576
 
                        }
1577
 
                        if (b)
1578
 
                                mprintf(" are equivalent.\n");
1579
 
                }
1580
 
        } // Tabelle Ende
1581
 
        BTOUT; 
1582
 
}
1583
 
 
1584
 
 
1585
 
void CTimeStep::Transform(const CxMatrix3 &mat)
1586
 
{
1587
 
        BTIN;
1588
 
        int z;
1589
 
//      CxVector3 v;
1590
 
 
1591
 
        for (z=0;z<g_iGesVirtAtomCount;z++)
1592
 
        {
1593
 
//              if (z < g_iGesAtomCount)
1594
 
//                      mprintf("@ %2d: ( %g | %g | %g ) --> ",z,m_vaCoords[z][0],m_vaCoords[z][1],m_vaCoords[z][2]);
1595
 
                m_vaCoords[z] = mat * m_vaCoords[z];
1596
 
//              if (z < g_iGesAtomCount)
1597
 
//                      mprintf("( %g | %g | %g )\n",m_vaCoords[z][0],m_vaCoords[z][1],m_vaCoords[z][2]);
1598
 
        }
1599
 
 
1600
 
        if (g_bUseVelocities)
1601
 
                for (z=0;z<g_iGesVirtAtomCount;z++)
1602
 
                        m_vaVelocities[z] = mat * m_vaVelocities[z];
1603
 
 
1604
 
        if (g_bUseForces)
1605
 
                for (z=0;z<g_iGesVirtAtomCount;z++)
1606
 
                        m_vaForces[z] = mat * m_vaForces[z];
1607
 
        BTOUT; 
1608
 
}
1609
 
 
1610
 
 
1611
 
void CTimeStep::Transform(const CxDMatrix3 &mat)
1612
 
{
1613
 
        BTIN;
1614
 
        int z;
1615
 
 
1616
 
        for (z=0;z<g_iGesVirtAtomCount;z++)
1617
 
                m_vaCoords[z] = mat * m_vaCoords[z];
1618
 
 
1619
 
        if (g_bUseVelocities)
1620
 
                for (z=0;z<g_iGesVirtAtomCount;z++)
1621
 
                        m_vaVelocities[z] = mat * m_vaVelocities[z];
1622
 
 
1623
 
        if (g_bUseForces)
1624
 
                for (z=0;z<g_iGesVirtAtomCount;z++)
1625
 
                        m_vaForces[z] = mat * m_vaForces[z];
1626
 
        BTOUT; 
1627
 
}
1628
 
 
1629
 
 
1630
 
void CTimeStep::Transform(const CxQuaternion &q)
1631
 
{
1632
 
        BTIN;
1633
 
        int z;
1634
 
 
1635
 
        for (z=0;z<g_iGesVirtAtomCount;z++)
1636
 
                m_vaCoords[z] = q.Transform(m_vaCoords[z]);
1637
 
 
1638
 
        if (g_bUseVelocities)
1639
 
                for (z=0;z<g_iGesVirtAtomCount;z++)
1640
 
                        m_vaVelocities[z] = q.Transform(m_vaVelocities[z]);
1641
 
 
1642
 
        if (g_bUseForces)
1643
 
                for (z=0;z<g_iGesVirtAtomCount;z++)
1644
 
                        m_vaForces[z] = q.Transform(m_vaForces[z]);
1645
 
        BTOUT; 
1646
 
}
1647
 
 
1648
 
 
1649
 
void CTimeStep::SubVelocities(const CxVector3 &vec)
1650
 
{
1651
 
        BTIN;
1652
 
        int z;
1653
 
 
1654
 
        for (z=0;z<g_iGesVirtAtomCount;z++)
1655
 
                m_vaVelocities[z] -= vec;
1656
 
        BTOUT; 
1657
 
}
1658
 
 
1659
 
 
1660
 
void CTimeStep::FoldMolecules()
1661
 
{
1662
 
        BTIN;
1663
 
        int z, z2, z3, z4;
1664
 
        CxVector3 v, vc;
1665
 
        CMolecule *m;
1666
 
        CSingleMolecule *sm;
1667
 
 
1668
 
        if (!g_bPeriodic)
1669
 
                return;
1670
 
 
1671
 
//      mprintf("*** Fold ***\n");
1672
 
        
1673
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
1674
 
        {
1675
 
                m = (CMolecule*)g_oaMolecules[z];
1676
 
                if (m->m_bPseudo)
1677
 
                        continue;
1678
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
1679
 
                {
1680
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
1681
 
 
1682
 
//                      mprintf("\n%d, %d",m->m_baAtomIndex.GetSize(),((CxIntArray*)sm->m_oaAtomOffset[m->m_baAtomIndex.GetSize()-1])->GetAt(1));
1683
 
 
1684
 
                        // Massenzentrum
1685
 
                        v = m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[m->m_baAtomIndex.GetSize()-1])->GetAt(1)];
1686
 
 
1687
 
/*                      mprintf("  .Mol ");
1688
 
                        v.Dump();
1689
 
                        mprintf("\n");                  
1690
 
 
1691
 
*/                      vc = CxVector3(0,0,0);
1692
 
                        
1693
 
                        if (g_bPeriodicX)
1694
 
                        {
1695
 
                                while (v[0] < -g_fBoxX/2) { v[0] += g_fBoxX; vc[0] += g_fBoxX; }
1696
 
                                while (v[0] >= g_fBoxX/2) { v[0] -= g_fBoxX; vc[0] -= g_fBoxX; }
1697
 
                        }
1698
 
                        if (g_bPeriodicY)
1699
 
                        {
1700
 
                                while (v[1] < -g_fBoxY/2) { v[1] += g_fBoxY; vc[1] += g_fBoxY; }
1701
 
                                while (v[1] >= g_fBoxY/2) { v[1] -= g_fBoxY; vc[1] -= g_fBoxY; }
1702
 
                        }
1703
 
                        if (g_bPeriodicZ)
1704
 
                        {
1705
 
                                while (v[2] < -g_fBoxZ/2) { v[2] += g_fBoxZ; vc[2] += g_fBoxZ; }
1706
 
                                while (v[2] >= g_fBoxZ/2) { v[2] -= g_fBoxZ; vc[2] -= g_fBoxZ; }
1707
 
                        }
1708
 
                        
1709
 
                        if ((vc[0] == 0) && (vc[1] == 0) && (vc[2] == 0))
1710
 
                                 continue;
1711
 
                        
1712
 
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
1713
 
                                for (z4=0;z4<m->m_waAtomCount[z3];z4++)
1714
 
                                         m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] += vc;
1715
 
 
1716
 
                        if (g_bWannier)
1717
 
                                for (z3=0;z3<sm->m_laWannier.GetSize();z3++)
1718
 
                                         m_vaCoords[sm->m_laWannier[z3]] += vc;
1719
 
                }
1720
 
        }
1721
 
//      mprintf("   Fold Done\n");
1722
 
        BTOUT;
1723
 
}
1724
 
 
1725
 
 
1726
 
void CTimeStep::FoldAtoms()
1727
 
{
1728
 
        BTIN;
1729
 
        int z;
1730
 
 
1731
 
        if (!g_bPeriodic)
1732
 
                return;
1733
 
 
1734
 
        for (z=0;z<g_iGesVirtAtomCount;z++)
1735
 
        {
1736
 
                if (g_bPeriodicX)
1737
 
                {
1738
 
                        while (m_vaCoords[z][0] < -g_fBoxX/2) m_vaCoords[z][0] += g_fBoxX;
1739
 
                        while (m_vaCoords[z][0] >= g_fBoxX/2) m_vaCoords[z][0] -= g_fBoxX;
1740
 
                }
1741
 
 
1742
 
                if (g_bPeriodicY)
1743
 
                {
1744
 
                        while (m_vaCoords[z][1] < -g_fBoxY/2) m_vaCoords[z][1] += g_fBoxY;
1745
 
                        while (m_vaCoords[z][1] >= g_fBoxY/2) m_vaCoords[z][1] -= g_fBoxY;
1746
 
                }
1747
 
 
1748
 
                if (g_bPeriodicZ)
1749
 
                {
1750
 
                        while (m_vaCoords[z][2] < -g_fBoxZ/2) m_vaCoords[z][2] += g_fBoxZ;
1751
 
                        while (m_vaCoords[z][2] >= g_fBoxZ/2) m_vaCoords[z][2] -= g_fBoxZ;
1752
 
                }
1753
 
        }
1754
 
        BTOUT; 
1755
 
}
1756
 
 
1757
 
 
1758
 
void CTimeStep::CenterPos(const CxVector3 &vec)
1759
 
{
1760
 
        BTIN;
1761
 
        int z/*, z2, z3, z4*/;
1762
 
 
1763
 
/*       for (z=0;z<g_oaMolecules.GetSize();z++)
1764
 
                 for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->Count;z2++)
1765
 
                         for (z3=0;z3<((CMolecule*)g_oaMolecules[z])->Elements;z3++)
1766
 
                                 for (z4=0;z4<((CMolecule*)g_oaMolecules[z])->AtomCount[z3];z4++)
1767
 
                                         m_vaCoords[((CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->SingleMolIndex[z2]])->m_iAtomOffset[z3][z4]] -= vec;*/
1768
 
 
1769
 
        for (z=0;z<g_iGesVirtAtomCount;z++)
1770
 
                m_vaCoords[z] -= vec;
1771
 
        BTOUT; 
1772
 
}
1773
 
 
1774
 
 
1775
 
void CTimeStep::AddAtoms()
1776
 
{
1777
 
        BTIN;
1778
 
        char *q;
1779
 
        int z;
1780
 
//      bool labeledatoms;
1781
 
 
1782
 
//      labeledatoms = false;
1783
 
        for (z=0;z<(long)m_iGesAtomCount;z++)
1784
 
        {
1785
 
                q = (char*)m_paLabels[z];
1786
 
                q+=strlen(q)-1;
1787
 
/*              while ((*q >= '0') && (*q <= '9'))
1788
 
                {
1789
 
                        if (!labeledatoms)
1790
 
                        {
1791
 
                                mprintf(">>>\n>>> The atoms in the input file are numbered.\n>>> Ignoring this, using own numbers ;-)\n>>>\n");
1792
 
                                labeledatoms = true;
1793
 
                        }
1794
 
                        *q = 0;
1795
 
                        q--;
1796
 
                }*/
1797
 
//              printf("AddAtoms: \"%s\"\n",q);
1798
 
                xAddAtom((char*)m_paLabels[z]);
1799
 
        }
1800
 
        BTOUT; 
1801
 
}
1802
 
 
1803
 
 
1804
 
void CTimeStep::WriteTimestep(FILE *a)
1805
 
{
1806
 
        BTIN;
1807
 
        int z, z2, z3, z4, z0;
1808
 
        CMolecule *m;
1809
 
        CSingleMolecule *sm;
1810
 
 
1811
 
        if (g_bSaveVirtAtoms)
1812
 
                mfprintf(a,"  %d\n",g_iGesVirtAtomCount);
1813
 
                        else mfprintf(a,"  %d\n",g_iGesAtomCount);
1814
 
        if (m_pComment != NULL)
1815
 
                mfprintf(a,"%s\n",m_pComment);
1816
 
                        else mfprintf(a,"\n");
1817
 
 
1818
 
        if (g_bWriteAtomwise)
1819
 
        {
1820
 
                for (z0=0;z0<g_oaAtoms.GetSize();z0++)
1821
 
                {
1822
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
1823
 
                        {
1824
 
                                m = (CMolecule*)g_oaMolecules[z];
1825
 
                                if (m->m_bPseudo)
1826
 
                                        continue;
1827
 
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
1828
 
                                {
1829
 
                                        if (m->m_baAtomIndex[z3] != z0)
1830
 
                                                continue;
1831
 
                                        if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
1832
 
                                                continue;
1833
 
                                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
1834
 
                                        {
1835
 
                                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
1836
 
                                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
1837
 
                                                        mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
1838
 
                                        }
1839
 
                                }
1840
 
                        }
1841
 
                }
1842
 
        } else
1843
 
        {
1844
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
1845
 
                {
1846
 
                        m = (CMolecule*)g_oaMolecules[z];
1847
 
                        if (m->m_bPseudo)
1848
 
                                continue;
1849
 
                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
1850
 
                        {
1851
 
                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
1852
 
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
1853
 
                                {
1854
 
                                        if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
1855
 
                                                continue;
1856
 
                                        for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
1857
 
                                                mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
1858
 
                                }
1859
 
                        }
1860
 
                }
1861
 
        }
1862
 
                        
1863
 
        BTOUT; 
1864
 
}
1865
 
 
1866
 
        
1867
 
void CTimeStep::WriteTimestepNb(FILE *a, CNbSet *nbs, int singlemol)
1868
 
{
1869
 
        BTIN;
1870
 
        int z, z2, z3, z4, z0, n, ti;
1871
 
        CMolecule *m;
1872
 
        CSingleMolecule *sm;
1873
 
        CConditionGroup *cg;
1874
 
        CConditionSubGroup *cs;
1875
 
        CNbSearch *nb;
1876
 
 
1877
 
        n = 0;
1878
 
 
1879
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
1880
 
        {
1881
 
                if (nbs->m_oaConditionGroups[z] == NULL)
1882
 
                        continue;
1883
 
                m = (CMolecule*)g_oaMolecules[z];
1884
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
1885
 
                {
1886
 
                        if (((CConditionGroup*)nbs->m_oaConditionGroups[z])->Contains(z2))
1887
 
                        {
1888
 
                                n += m->m_iAtomGes;
1889
 
                                if (!g_bSaveVirtAtoms)
1890
 
                                        n -= m->m_laVirtualAtoms.GetSize();
1891
 
                        }
1892
 
                }
1893
 
        }
1894
 
 
1895
 
        mfprintf(a,"  %d\n",n);
1896
 
 
1897
 
        mfprintf(a,"# Step %d",((int)g_iSteps));
1898
 
 
1899
 
        if (singlemol >= 0)
1900
 
        {
1901
 
                sm = (CSingleMolecule*)g_oaSingleMolecules[singlemol];
1902
 
                m = (CMolecule*)g_oaMolecules[sm->m_iMolType];
1903
 
                if (!g_bSaveVirtAtoms)
1904
 
                {
1905
 
                        if (g_bWriteAtomwise)
1906
 
                                mfprintf(a,", RM=%s[%d]",m->m_sName,sm->m_iMolSMIndex+1);
1907
 
                                        else mfprintf(a,", RM=%s[%d] (%d atoms)",m->m_sName,sm->m_iMolSMIndex+1,m->m_iAtomGes-m->m_laVirtualAtoms.GetSize());
1908
 
                } else
1909
 
                {
1910
 
                        if (g_bWriteAtomwise)
1911
 
                                mfprintf(a,", RM=%s[%d]",m->m_sName,sm->m_iMolSMIndex+1);
1912
 
                                        else mfprintf(a,", RM=%s[%d] (%d atoms)",m->m_sName,sm->m_iMolSMIndex+1,m->m_iAtomGes);
1913
 
                }
1914
 
        }
1915
 
 
1916
 
        if (g_bEnvWriteDetailedInfo)
1917
 
        {
1918
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
1919
 
                {
1920
 
                        if (nbs->m_oaConditionGroups[z] == NULL)
1921
 
                                continue;
1922
 
                        m = (CMolecule*)g_oaMolecules[z];
1923
 
 
1924
 
                        cg = (CConditionGroup*)nbs->m_oaConditionGroups[z];
1925
 
 
1926
 
                        if (g_bEnvSortNb)
1927
 
                        {
1928
 
                                nb = NULL;
1929
 
                                if (cg->m_oaConditionSubGroups.GetSize() == 1)
1930
 
                                {
1931
 
                                        cs = (CConditionSubGroup*)cg->m_oaConditionSubGroups[0];
1932
 
                                        if (cs->m_oaConditions.GetSize() == 1)
1933
 
                                                nb = (CNbSearch*)cs->m_oaConditions[0];
1934
 
                                }
1935
 
                                if (nb == NULL)
1936
 
                                        goto _nosortinfo;
1937
 
 
1938
 
                                if (nb->m_iNbCountMin <= -1)
1939
 
                                        goto _nosortinfo;
1940
 
 
1941
 
                                for (z2=nb->m_iNbCountMin;z2<=nb->m_iNbCountMax;z2++)
1942
 
                                {
1943
 
                                        ti = nb->m_pNbSort[z2].m_iOM;
1944
 
                                        if (!g_bSaveVirtAtoms)
1945
 
                                        {
1946
 
                                                if (m->m_laSingleMolIndex[ti] != singlemol)
1947
 
                                                {
1948
 
                                                        if (g_bWriteAtomwise)
1949
 
                                                                mfprintf(a,", %s[%d] d=%.3fpm",m->m_sName,z2+1,nb->m_pNbSort[z2].m_fMinDist);
1950
 
                                                                        else mfprintf(a,", %s[%d] d=%.3fpm (%d atoms)",m->m_sName,ti+1,nb->m_pNbSort[z2].m_fMinDist,m->m_iAtomGes-m->m_laVirtualAtoms.GetSize());
1951
 
                                                }
1952
 
                                        } else
1953
 
                                        {
1954
 
                                                if (m->m_laSingleMolIndex[ti] != singlemol)
1955
 
                                                {
1956
 
                                                        if (g_bWriteAtomwise)
1957
 
                                                                mfprintf(a,", %s[%d] d=%.3fpm",m->m_sName,z2+1,nb->m_pNbSort[z2].m_fMinDist);
1958
 
                                                                        else mfprintf(a,", %s[%d] d=%.3fpm (%d atoms)",m->m_sName,ti+1,nb->m_pNbSort[z2].m_fMinDist,m->m_iAtomGes);
1959
 
                                                }
1960
 
                                        }
1961
 
                                }
1962
 
                        } else
1963
 
                        {
1964
 
_nosortinfo:
1965
 
                                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
1966
 
                                {
1967
 
                                        if (cg->Contains(z2))
1968
 
                                        {
1969
 
                                                if (!g_bSaveVirtAtoms)
1970
 
                                                {
1971
 
                                                        if (m->m_laSingleMolIndex[z2] != singlemol)
1972
 
                                                        {
1973
 
                                                                if (g_bWriteAtomwise)
1974
 
                                                                        mfprintf(a,", %s[%d]",m->m_sName,z2+1);
1975
 
                                                                                else mfprintf(a,", %s[%d] (%d atoms)",m->m_sName,z2+1,m->m_iAtomGes-m->m_laVirtualAtoms.GetSize());
1976
 
                                                        }
1977
 
                                                } else
1978
 
                                                {
1979
 
                                                        if (m->m_laSingleMolIndex[z2] != singlemol)
1980
 
                                                        {
1981
 
                                                                if (g_bWriteAtomwise)
1982
 
                                                                        mfprintf(a,", %s[%d]",m->m_sName,z2+1);
1983
 
                                                                                else mfprintf(a,", %s[%d] (%d atoms)",m->m_sName,z2+1,m->m_iAtomGes);
1984
 
                                                        }
1985
 
                                                }
1986
 
                                        }
1987
 
                                }
1988
 
                        }
1989
 
                }
1990
 
        }
1991
 
 
1992
 
        mfprintf(a,"\n");
1993
 
 
1994
 
        if (g_bWriteAtomwise)
1995
 
        {
1996
 
                for (z0=0;z0<g_oaAtoms.GetSize();z0++)
1997
 
                {
1998
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
1999
 
                        {
2000
 
                                if (nbs->m_oaConditionGroups[z] == NULL)
2001
 
                                        continue;
2002
 
                                m = (CMolecule*)g_oaMolecules[z];
2003
 
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
2004
 
                                {
2005
 
                                        if (m->m_baAtomIndex[z3] != z0)
2006
 
                                                continue;
2007
 
                                        if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
2008
 
                                                continue;
2009
 
                                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
2010
 
                                        {
2011
 
                                                if (((CConditionGroup*)nbs->m_oaConditionGroups[z])->Contains(z2))
2012
 
                                                {
2013
 
                                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
2014
 
                                                        for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
2015
 
                                                                mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
2016
 
                                                }
2017
 
                                        }
2018
 
                                }
2019
 
                        }
2020
 
                }
2021
 
        } else
2022
 
        {
2023
 
                if (singlemol >= 0)
2024
 
                {
2025
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[singlemol];
2026
 
                        m = (CMolecule*)g_oaMolecules[sm->m_iMolType];
2027
 
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
2028
 
                        {
2029
 
                                if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
2030
 
                                        continue;
2031
 
                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
2032
 
                                        mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
2033
 
                        }
2034
 
                }
2035
 
 
2036
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
2037
 
                {
2038
 
                        if (nbs->m_oaConditionGroups[z] == NULL)
2039
 
                                continue;
2040
 
                        m = (CMolecule*)g_oaMolecules[z];
2041
 
                        cg = (CConditionGroup*)nbs->m_oaConditionGroups[z];
2042
 
 
2043
 
                        if (g_bEnvSortNb)
2044
 
                        {
2045
 
                                nb = NULL;
2046
 
                                if (cg->m_oaConditionSubGroups.GetSize() == 1)
2047
 
                                {
2048
 
                                        cs = (CConditionSubGroup*)cg->m_oaConditionSubGroups[0];
2049
 
                                        if (cs->m_oaConditions.GetSize() == 1)
2050
 
                                                nb = (CNbSearch*)cs->m_oaConditions[0];
2051
 
                                }
2052
 
                                if (nb == NULL)
2053
 
                                        goto _nosort;
2054
 
 
2055
 
                                if (nb->m_iNbCountMin <= -1)
2056
 
                                        goto _nosort;
2057
 
 
2058
 
                                for (z2=nb->m_iNbCountMin;z2<=nb->m_iNbCountMax;z2++)
2059
 
                                {
2060
 
                                        ti = nb->m_pNbSort[z2].m_iOM;
2061
 
 
2062
 
                                        if (m->m_laSingleMolIndex[ti] == singlemol)
2063
 
                                                continue;
2064
 
 
2065
 
                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ti]];
2066
 
                                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
2067
 
                                        {
2068
 
                                                if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
2069
 
                                                        continue;
2070
 
                                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
2071
 
                                                        mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
2072
 
                                        }
2073
 
                                }
2074
 
                        } else
2075
 
                        {
2076
 
_nosort:
2077
 
                                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
2078
 
                                {
2079
 
                                        if (((CConditionGroup*)nbs->m_oaConditionGroups[z])->Contains(z2))
2080
 
                                        {
2081
 
                                                if (m->m_laSingleMolIndex[z2] == singlemol)
2082
 
                                                        continue;
2083
 
                                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
2084
 
                                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
2085
 
                                                {
2086
 
                                                        if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
2087
 
                                                                continue;
2088
 
                                                        for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
2089
 
                                                                mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
2090
 
                                                }
2091
 
                                        }
2092
 
                                }
2093
 
                        }
2094
 
                }
2095
 
        }
2096
 
                        
2097
 
        BTOUT; 
2098
 
}
2099
 
 
2100
 
 
2101
 
/*void CTimeStep::WriteTimestepNb(int refmol, FILE *a)
2102
 
{
2103
 
        BTIN;
2104
 
        int z, c, z2, z3, z4, z0;
2105
 
        int ti;
2106
 
        CMolecule *m, *m2;
2107
 
 
2108
 
        m = (CMolecule*)g_oaMolecules[g_iFixMol];
2109
 
 
2110
 
        c = 0;
2111
 
        if (g_bRefEnvVirt)
2112
 
        {
2113
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
2114
 
                        c += g_pNbAll->m_waScanNeighborCount[z]*((CMolecule*)g_oaMolecules[z])->m_iAtomGes;
2115
 
                if (g_bSaveRefWithEnv)
2116
 
                        c += m->m_iAtomGes;
2117
 
        } else
2118
 
        {
2119
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
2120
 
                        c += g_pNbAll->m_waScanNeighborCount[z]*(((CMolecule*)g_oaMolecules[z])->m_iAtomGes-((CMolecule*)g_oaMolecules[z])->m_waVirtualAtoms.GetSize());
2121
 
                if (g_bSaveRefWithEnv)
2122
 
                        c += m->m_iAtomGes - m->m_waVirtualAtoms.GetSize();
2123
 
        }
2124
 
 
2125
 
        mfprintf(a,"  %d\n\n",c);
2126
 
 
2127
 
        if (g_bRefEnvAtomwise)
2128
 
        {
2129
 
                for (z0=0;z0<g_oaAtoms.GetSize();z0++)
2130
 
                {
2131
 
                        if (g_bSaveRefWithEnv)
2132
 
                        {
2133
 
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
2134
 
                                {
2135
 
                                        if (m->m_baAtomIndex[z3] != z0)
2136
 
                                                continue;
2137
 
                                        if (!g_bRefEnvVirt)
2138
 
                                                if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
2139
 
                                                        continue;
2140
 
                                        for (z4=0;z4<m->m_waAtomCount[z3];z4++)
2141
 
                                        {
2142
 
                                                ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]])->m_oaAtomOffset[z3])->GetAt(z4);
2143
 
                                                mfprintf(a,"  %s  %f  %f  %f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0f,m_vaCoords[ti][1]/100.0f,m_vaCoords[ti][2]/100.0f);
2144
 
                                        }
2145
 
                                }
2146
 
                        }
2147
 
                        for (z=0;z<g_oaMolecules.GetSize();z++)
2148
 
                        {
2149
 
                                m2 = (CMolecule*)g_oaMolecules[z];
2150
 
                                for (z2=0;z2<g_pNbAll->m_waScanNeighborCount[z];z2++)
2151
 
                                {
2152
 
                                        for (z3=0;z3<m2->m_baAtomIndex.GetSize();z3++)
2153
 
                                        {
2154
 
                                                if (m2->m_baAtomIndex[z3] != z0)
2155
 
                                                        continue;
2156
 
                                                if (!g_bRefEnvVirt)
2157
 
                                                        if (m2->m_baAtomIndex[z3] == g_iVirtAtomType)
2158
 
                                                                continue;
2159
 
                                                for (z4=0;z4<m2->m_waAtomCount[z3];z4++)
2160
 
                                                {
2161
 
                                                        ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[((CxIntArray*)g_pNbAll->m_oaScanNeighbors[z])->GetAt(z2)]])->m_oaAtomOffset[z3])->GetAt(z4);
2162
 
                                                        mfprintf(a,"  %s  %f  %f  %f\n",((CAtom*)g_oaAtoms[m2->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0f,m_vaCoords[ti][1]/100.0f,m_vaCoords[ti][2]/100.0f);
2163
 
                                                }
2164
 
                                        }
2165
 
                                }
2166
 
                        }
2167
 
                }
2168
 
        } else
2169
 
        {
2170
 
                if (g_bSaveRefWithEnv)
2171
 
                {
2172
 
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
2173
 
                        {
2174
 
                                if (!g_bRefEnvVirt)
2175
 
                                        if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
2176
 
                                                continue;
2177
 
                                for (z4=0;z4<m->m_waAtomCount[z3];z4++)
2178
 
                                {
2179
 
                                        ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]])->m_oaAtomOffset[z3])->GetAt(z4);
2180
 
                                        mfprintf(a,"  %s  %f  %f  %f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0,m_vaCoords[ti][1]/100.0,m_vaCoords[ti][2]/100.0);
2181
 
                                }
2182
 
                        }
2183
 
                }
2184
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
2185
 
                {
2186
 
                        m2 = (CMolecule*)g_oaMolecules[z];
2187
 
                        for (z2=0;z2<g_pNbAll->m_waScanNeighborCount[z];z2++)
2188
 
                        {
2189
 
                                for (z3=0;z3<m2->m_baAtomIndex.GetSize();z3++)
2190
 
                                {
2191
 
                                        if (!g_bRefEnvVirt)
2192
 
                                                if (m2->m_baAtomIndex[z3] == g_iVirtAtomType)
2193
 
                                                        continue;
2194
 
                                        for (z4=0;z4<m2->m_waAtomCount[z3];z4++)
2195
 
                                        {
2196
 
                                                ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[((CxIntArray*)g_pNbAll->m_oaScanNeighbors[z])->GetAt(z2)]])->m_oaAtomOffset[z3])->GetAt(z4);
2197
 
                                                mfprintf(a,"  %s  %f  %f  %f\n",((CAtom*)g_oaAtoms[m2->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0,m_vaCoords[ti][1]/100.0,m_vaCoords[ti][2]/100.0);
2198
 
                                        }
2199
 
                                }
2200
 
                        }
2201
 
                }
2202
 
        }
2203
 
        BTOUT; 
2204
 
}*/
2205
 
 
2206
 
 
2207
 
/*float CTimeStep::MolDist(CSingleMolecule *ref, CSingleMolecule *sm2, CNbSearch *nb)
2208
 
{
2209
 
        BXIN;
2210
 
        int z3, z4;
2211
 
        float d;
2212
 
        CxVector3 vec;
2213
 
 
2214
 
        d = 99999.0f;
2215
 
        for (z3=0;z3<nb->m_waRefElements.GetSize();z3++)
2216
 
                for (z4=0;z4<((CxIntArray*)nb->m_oaNbElements[sm2->m_iMolType])->GetSize();z4++)
2217
 
                {
2218
 
                        vec = m_vaCoords[((CxIntArray*)ref->m_oaAtomOffset[nb->m_waRefElements[z3]])->GetAt(nb->m_waRefAtoms[z3])] - m_vaCoords[((CxIntArray*)sm2->m_oaAtomOffset[((CxIntArray*)nb->m_oaNbElements[sm2->m_iMolType])->GetAt(z4)])->GetAt(((CxIntArray*)nb->m_oaNbAtoms[sm2->m_iMolType])->GetAt(z4))];
2219
 
                        if (g_bFold)
2220
 
                        {
2221
 
                                while (vec[0] >= g_fBoxX/2) vec[0] -= g_fBoxX;
2222
 
                                while (vec[0] < -g_fBoxX/2) vec[0] += g_fBoxX;
2223
 
                                while (vec[1] >= g_fBoxY/2) vec[1] -= g_fBoxY;
2224
 
                                while (vec[1] < -g_fBoxY/2) vec[1] += g_fBoxY;
2225
 
                                while (vec[2] >= g_fBoxZ/2) vec[2] -= g_fBoxZ;
2226
 
                                while (vec[2] < -g_fBoxZ/2) vec[2] += g_fBoxZ;
2227
 
                        }
2228
 
                        if (vec.GetLength() < d)
2229
 
                                d = vec.GetLength();
2230
 
                }
2231
 
        BXOUT;
2232
 
        if (d < 90000.0f)
2233
 
                return d;
2234
 
                        else return -1.0f;
2235
 
}*/
2236
 
 
2237
 
 
2238
 
/*void CTimeStep::ScanNeighborhood(int fixmol, int refmol, CNbSearch *nb, CNbSearch *prev)
2239
 
{
2240
 
        BTIN;
2241
 
        float *del, d;
2242
 
        int *best, b;
2243
 
        int z, z2, z3, c;
2244
 
        CMolecule *m, *m2;
2245
 
        CSingleMolecule *sm, *sm2;
2246
 
        CxVector3 vec;
2247
 
 
2248
 
        m = (CMolecule*)g_oaMolecules[fixmol];
2249
 
        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]];
2250
 
        del = new float[g_oaSingleMolecules.GetSize()];
2251
 
        best = new int[g_oaSingleMolecules.GetSize()];
2252
 
 
2253
 
//      printf("Suche Nachbarschaft von Molekuel %d...\n",refmol+1);
2254
 
 
2255
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
2256
 
        {
2257
 
                if (((!nb->m_bDistMode) && (nb->m_waMolCount[z] == 0)) || (nb->m_bDistMode && (nb->m_faMolDist[z] == 0)))
2258
 
                {
2259
 
                        nb->m_waScanNeighborCount[z] = 0;
2260
 
                        continue;
2261
 
                }
2262
 
                m2 = (CMolecule*)g_oaMolecules[z];
2263
 
//              printf("*** Molekuel %d: %s\n",z+1,m2->Name);
2264
 
                for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
2265
 
                {
2266
 
                        del[z2] = 99999.0f;
2267
 
                        if ((z == fixmol) && (z2 == refmol))
2268
 
                                continue;
2269
 
                        if (prev != NULL)
2270
 
                                if (!prev->Contains(z,z2))
2271
 
                                        continue;
2272
 
//                      printf("  - Vertreter %d\n",z2+1);
2273
 
                        sm2 = (CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[z2]];
2274
 
                        del[z2] = MolDist(sm,sm2,nb);
2275
 
//                      printf("  - Finaler Abstand: %f\n",del[z2]);
2276
 
                }
2277
 
                if (nb->m_bDistMode)
2278
 
                {
2279
 
//                      printf("**DistMode**\n");
2280
 
//                      mprintf("Die Nachbarn: ");
2281
 
                        c = 0;
2282
 
                        for (z3=0;z3<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z3++)
2283
 
                                if ((del[z3] <= nb->m_faMolDist[z]) && (del[z3] >= nb->m_faMolMinDist[z]))
2284
 
                                {
2285
 
//                                      mprintf("%d (%f), ",z3+1,del[z3]);
2286
 
                                        best[c] = z3;
2287
 
                                        c++;
2288
 
                                }
2289
 
//                      mprintf("\n");
2290
 
//                      printf("  # Die naechsten Nachbarn: ");
2291
 
                        for (z2=0;z2<c;z2++)
2292
 
                        {
2293
 
//                              printf("%d, ",best[z2]+1);
2294
 
                                nb->m_iNeighbourCount++;
2295
 
                                for (z3=0;z3<nb->m_waScanNeighborCount[z];z3++)
2296
 
                                        if (((CxIntArray*)nb->m_oaScanNeighbors[z])->GetAt(z3) == best[z2])
2297
 
                                        {
2298
 
                                                ((CxIntArray*)nb->m_oaScanNeighborHits[z])->GetAt(z3)++;
2299
 
                                                goto _enddist;
2300
 
                                        }
2301
 
                                ((CxIntArray*)nb->m_oaScanNeighbors[z])->Add(best[z2]);
2302
 
                                ((CxIntArray*)nb->m_oaScanNeighborHits[z])->Add(1);
2303
 
                                nb->m_waScanNeighborCount[z]++;
2304
 
_enddist:;
2305
 
                        }
2306
 
//                      printf("\n");
2307
 
                } else
2308
 
                {
2309
 
//                      printf("**CountMode**\n");
2310
 
                        for (z2=0;z2<nb->m_waMolCount[z];z2++)
2311
 
                        {
2312
 
                                d = 999999.0f;
2313
 
                                b = -1;
2314
 
                                for (z3=0;z3<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z3++)
2315
 
                                {
2316
 
                                        if (del[z3] < d)
2317
 
                                        {
2318
 
                                                d = del[z3];
2319
 
                                                b = z3;
2320
 
                                        }
2321
 
                                }
2322
 
                                best[z2] = b;
2323
 
                                del[b] = 1000000.0f;
2324
 
                        }
2325
 
//                      printf("  # Die naechsten Nachbarn: ");
2326
 
                        for (z2=nb->m_waMolCountMin[z]-1;z2<nb->m_waMolCount[z];z2++)
2327
 
                        {
2328
 
//                              printf("%d, ",best[z2]);
2329
 
                                nb->m_iNeighbourCount++;
2330
 
                                for (z3=0;z3<nb->m_waScanNeighborCount[z];z3++)
2331
 
                                        if (((CxIntArray*)nb->m_oaScanNeighbors[z])->GetAt(z3) == best[z2])
2332
 
                                        {
2333
 
                                                ((CxIntArray*)nb->m_oaScanNeighborHits[z])->GetAt(z3)++;
2334
 
                                                goto _end;
2335
 
                                        }
2336
 
                                ((CxIntArray*)nb->m_oaScanNeighbors[z])->Add(best[z2]);
2337
 
                                ((CxIntArray*)nb->m_oaScanNeighborHits[z])->Add(1);
2338
 
                                nb->m_waScanNeighborCount[z]++;
2339
 
_end:;
2340
 
                        }
2341
 
//                      printf("\n");
2342
 
                }
2343
 
        }
2344
 
        delete del;
2345
 
        delete best;
2346
 
        BTOUT; 
2347
 
}*/
2348
 
 
2349
 
 
2350
 
/*void CTimeStep::ScanAngle(int fixmol, int refmol, CCondition *co, CNbSearch *prev)
2351
 
{
2352
 
        BTIN;
2353
 
        int z2, z3, z4;
2354
 
        float tf;
2355
 
        CMolecule *m, *m2;
2356
 
        CSingleMolecule *sm, *sm2;
2357
 
        CxVector3 vec0, vec1, vec2, vec3, vec4, vec5;
2358
 
        CxIntArray tempwa;
2359
 
        CNbSearch *nb;
2360
 
 
2361
 
//      mprintf("*** ScanAngle ***\n");
2362
 
//      mprintf("  FixMol = %d, RefMol = %d\n",fixmol,refmol);
2363
 
        m = (CMolecule*)g_oaMolecules[fixmol];
2364
 
//      mprintf("  m->m_laSingleMolIndex[refmol] = %d\n",m->m_laSingleMolIndex[refmol]);
2365
 
 
2366
 
        nb = co->m_pTempNbS;
2367
 
        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]];
2368
 
 
2369
 
//      printf("Suche Nachbarschaft von Molekuel %d...\n",refmol+1);
2370
 
 
2371
 
//      mprintf("  SecondMol = %d\n",co->m_iSecondMol);
2372
 
        m2 = (CMolecule*)g_oaMolecules[co->m_iSecondMol];
2373
 
 
2374
 
//      printf("*** Molekuel %d: %s\n",z+1,m2->Name);
2375
 
        for (z2=0;z2<m2->m_laSingleMolIndex.GetSize();z2++)
2376
 
        {
2377
 
                if ((co->m_iSecondMol == fixmol) && (z2 == refmol))
2378
 
                        continue;
2379
 
                if (prev != NULL)
2380
 
                        if (!prev->Contains(co->m_iSecondMol,z2))
2381
 
                                continue;
2382
 
//              printf("  - Vertreter %d\n",z2+1);
2383
 
                sm2 = (CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[z2]];
2384
 
 
2385
 
                co->m_pADF->BuildAtomList(sm,sm2,NULL,&tempwa);
2386
 
 
2387
 
                for (z4=0;z4<tempwa.GetSize();z4+=6)
2388
 
                {
2389
 
                        if (co->m_pADF->m_bOrtho[0])
2390
 
                        {
2391
 
                                vec0 = m_vaCoords[tempwa[z4]];
2392
 
                                vec2 = m_vaCoords[tempwa[z4+1]];
2393
 
                                vec3 = m_vaCoords[tempwa[z4+2]];
2394
 
                                vec1 = CrossP(vec2-vec0,vec3-vec0);
2395
 
                        } else
2396
 
                        {
2397
 
                                vec0 = m_vaCoords[tempwa[z4]];
2398
 
                                vec2 = m_vaCoords[tempwa[z4+1]];
2399
 
                                vec1 = vec2-vec0;
2400
 
                        }
2401
 
                        if (co->m_pADF->m_bOrtho[1])
2402
 
                        {
2403
 
                                vec4 = m_vaCoords[tempwa[z4+3]];
2404
 
                                vec3 = m_vaCoords[tempwa[z4+4]];
2405
 
                                vec5 = m_vaCoords[tempwa[z4+5]];
2406
 
                                vec2 = CrossP(vec3-vec4,vec5-vec4);
2407
 
                        } else
2408
 
                        {
2409
 
                                vec4 = m_vaCoords[tempwa[z4+3]];
2410
 
                                vec3 = m_vaCoords[tempwa[z4+4]];
2411
 
                                vec2 = vec3-vec4;
2412
 
                        }
2413
 
 
2414
 
                        tf = Angle_Deg(vec1,vec2);
2415
 
 
2416
 
  if ((tf >= co->m_pADF->m_fMinAngle) && (tf <= co->m_pADF->m_fMaxAngle))
2417
 
                        {
2418
 
                                nb->m_iNeighbourCount++;
2419
 
                                for (z3=0;z3<nb->m_waScanNeighborCount[co->m_iSecondMol];z3++)
2420
 
                                        if (((CxIntArray*)nb->m_oaScanNeighbors[co->m_iSecondMol])->GetAt(z3) == z2)
2421
 
                                        {
2422
 
                                                ((CxIntArray*)nb->m_oaScanNeighborHits[co->m_iSecondMol])->GetAt(z3)++;
2423
 
                                                goto _endang;
2424
 
                                        }
2425
 
                                ((CxIntArray*)nb->m_oaScanNeighbors[co->m_iSecondMol])->Add(z2);
2426
 
                                ((CxIntArray*)nb->m_oaScanNeighborHits[co->m_iSecondMol])->Add(1);
2427
 
                                nb->m_waScanNeighborCount[co->m_iSecondMol]++;
2428
 
_endang:;               break;
2429
 
                        }
2430
 
                }
2431
 
        }
2432
 
        BTOUT; 
2433
 
}*/
2434
 
 
2435
 
/*void CTimeStep::GatherNbDiagram(int refmol, CNbSearch *nb)
2436
 
{
2437
 
        BTIN;
2438
 
        float *del, d;
2439
 
        int *best, b;
2440
 
        bool *done;
2441
 
        int z, z2, z3, z4, c, z0;
2442
 
        CMolecule *m, *m2;
2443
 
        CSingleMolecule *sm, *sm2;
2444
 
        CxVector3 vec;
2445
 
//      FILE *a;
2446
 
 
2447
 
        m = (CMolecule*)g_oaMolecules[g_iFixMol];
2448
 
        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]];
2449
 
        del = new float[g_oaSingleMolecules.GetSize()];
2450
 
        best = new int[g_oaSingleMolecules.GetSize()];
2451
 
        done = new bool[g_oaSingleMolecules.GetSize()];
2452
 
 
2453
 
//      printf("Suche Nachbarschaft von Molekuel %d...\n",refmol+1);
2454
 
 
2455
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
2456
 
        {
2457
 
                if (nb->m_bDistMode && (nb->m_faMolDist[z] == 0))
2458
 
                {
2459
 
                        nb->m_waScanNeighborCount[z] = 0;
2460
 
                        continue;
2461
 
                }
2462
 
                m2 = (CMolecule*)g_oaMolecules[z];
2463
 
//              printf("*** Molekuel %d: %s\n",z+1,m2->Name);
2464
 
//              for (z2=0;z2<=((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
2465
 
//                      del[z2] = 99999.0f;
2466
 
                for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
2467
 
                {
2468
 
                        del[z2] = 99999.0f;
2469
 
                        if ((z == g_iFixMol) && (z2 == refmol))
2470
 
                                continue;
2471
 
//                      printf("  - Vertreter %d\n",z2+1);
2472
 
                        sm2 = (CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[z2]];
2473
 
                        for (z3=0;z3<nb->m_waRefElements.GetSize();z3++)
2474
 
                                for (z4=0;z4<((CxIntArray*)nb->m_oaNbElements[z])->GetSize();z4++)
2475
 
                                {
2476
 
                                        vec = m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[nb->m_waRefElements[z3]])->GetAt(nb->m_waRefAtoms[z3])] - m_vaCoords[((CxIntArray*)sm2->m_oaAtomOffset[((CxIntArray*)nb->m_oaNbElements[z])->GetAt(z4)])->GetAt(((CxIntArray*)nb->m_oaNbAtoms[z])->GetAt(z4))];
2477
 
                                        if (g_bFold)
2478
 
                                        {
2479
 
                                                while (vec[0] >= g_fBoxX/2) vec[0] -= g_fBoxX;
2480
 
                                                while (vec[0] < -g_fBoxX/2) vec[0] += g_fBoxX;
2481
 
                                                while (vec[1] >= g_fBoxY/2) vec[1] -= g_fBoxY;
2482
 
                                                while (vec[1] < -g_fBoxY/2) vec[1] += g_fBoxY;
2483
 
                                                while (vec[2] >= g_fBoxZ/2) vec[2] -= g_fBoxZ;
2484
 
                                                while (vec[2] < -g_fBoxZ/2) vec[2] += g_fBoxZ;
2485
 
                                        }
2486
 
                                        d = vec.GetLength();
2487
 
//                                      printf("    = m1 %d (%d|%d); m2 %d (%d|%d); Dist = %f\n",z3+1,m->m_waNbElements[z3]+1,m->m_waNbAtoms[z3]+1,z4+1,m2->m_waNbElements[z4]+1,m2->m_waNbAtoms[z4]+1,d);
2488
 
                                        if (d < del[z2])
2489
 
                                                del[z2] = d;
2490
 
                                }
2491
 
//                      printf("  - Finaler Abstand: %f\n",del[z2]);
2492
 
                }
2493
 
 
2494
 
                for (z0=0;z0<nb->m_pAF->m_iResolution;z0++)
2495
 
                {
2496
 
                        c = 0;
2497
 
                        for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
2498
 
                                done[z2] = false;
2499
 
                        while (true)
2500
 
                        {
2501
 
                                d = 999999.0f;
2502
 
                                b = -1;
2503
 
                                for (z3=0;z3<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z3++)
2504
 
                                {
2505
 
                                        if (done[z3])
2506
 
                                                continue;
2507
 
                                        if (del[z3] < d)
2508
 
                                        {
2509
 
                                                d = del[z3];
2510
 
                                                b = z3;
2511
 
                                        }
2512
 
                                }
2513
 
                                if (d > nb->m_pAF->m_fMaxVal*z0/nb->m_pAF->m_iResolution)
2514
 
                                        break;
2515
 
                                best[c] = b;
2516
 
                                done[b] = true;
2517
 
                                c++;
2518
 
//                              if (c >= ((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize())
2519
 
//                                      break;
2520
 
                        }
2521
 
                        nb->m_pAF->AddToBin(nb->m_pAF->m_fMaxVal*z0/nb->m_pAF->m_iResolution,(float)c);
2522
 
//                      if (g_iSteps == 1)
2523
 
//                              mfprintf(a,"%f;%f\n",nb->m_pAF->m_fMaxVal*z0/nb->m_pAF->m_iResolution,(float)c);
2524
 
                }
2525
 
//              if (g_iSteps == 1)
2526
 
//                      fclose(a);
2527
 
        }
2528
 
        delete del;
2529
 
        delete best;
2530
 
        BTOUT; 
2531
 
}*/
2532
 
 
2533
 
 
2534
 
int CTimeStep::REC_UniteMolecules(CSingleMolecule *sm, int i0, int depth)
2535
 
{
2536
 
        int z, z2, n;
2537
 
        CMolAtom *m;
2538
 
 
2539
 
        n = 0;
2540
 
        m = (CMolAtom*)sm->m_oaMolAtoms[i0];
2541
 
 
2542
 
/*      if (g_bVerbose)
2543
 
        {
2544
 
                mprintf("# ");
2545
 
                for (z2=0;z2<depth;z2++)
2546
 
                        mprintf(". ");
2547
 
                mprintf(">>> REC_UniteMolecules MolAtom=%d, Offset=%d.\n",i0,m->m_iOffset);
2548
 
        }*/
2549
 
 
2550
 
        g_pUniteTemp[m->m_iOffset] = true;
2551
 
 
2552
 
        for (z=0;z<m->m_oaBonds.GetSize();z++)
2553
 
        {
2554
 
                if (!g_pUniteTemp[((CMolAtom*)m->m_oaBonds[z])->m_iOffset])
2555
 
                {
2556
 
                        if (MirrorBond(m->m_iOffset,((CMolAtom*)m->m_oaBonds[z])->m_iOffset))
2557
 
                        {
2558
 
                                if (g_bVerbose)
2559
 
                                {
2560
 
                                        mprintf("# ");
2561
 
                                        for (z2=0;z2<depth;z2++)
2562
 
                                                mprintf(". ");
2563
 
                                        mprintf("    Bond %s(%d) <--> %s(%d) unwrapped.\n",((CAtom*)g_oaAtoms[g_baAtomIndex[m->m_iOffset]])->m_sName,m->m_iOffset+1,((CAtom*)g_oaAtoms[g_baAtomIndex[((CMolAtom*)m->m_oaBonds[z])->m_iOffset]])->m_sName,((CMolAtom*)m->m_oaBonds[z])->m_iOffset+1);
2564
 
                                }
2565
 
                                n++;
2566
 
                        }
2567
 
                        n += REC_UniteMolecules(sm,((CMolAtom*)m->m_oaBonds[z])->m_iMolAtomNumber,depth+1);
2568
 
                }
2569
 
        }
2570
 
/*      if (g_bVerbose)
2571
 
        {
2572
 
                mprintf("# ");
2573
 
                for (z2=0;z2<depth;z2++)
2574
 
                        mprintf(". ");
2575
 
                mprintf("<<< REC_UniteMolecules MolAtom=%d, Offset=%d.\n",i0,m->m_iOffset);
2576
 
        }*/
2577
 
        return n;
2578
 
}
2579
 
 
2580
 
 
2581
 
void CTimeStep::UniteMolecules(bool verbose)
2582
 
{
2583
 
        BTIN;
2584
 
        int z, z2, n;
2585
 
        CMolecule *m;
2586
 
        CSingleMolecule *sm;
2587
 
 
2588
 
        for (z=0;z<g_iGesAtomCount;z++)
2589
 
                g_pUniteTemp[z] = false;
2590
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
2591
 
        {
2592
 
                m = (CMolecule*)g_oaMolecules[z];
2593
 
                if (m->m_bPseudo)
2594
 
                        continue;
2595
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
2596
 
                {
2597
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
2598
 
 
2599
 
//                      if (g_bVerbose)
2600
 
//                              mprintf("  # UniteMolecules molecule %s (%d)\n",m->m_sName,z2+1);
2601
 
 
2602
 
                        n = REC_UniteMolecules(sm,0,0);
2603
 
 
2604
 
                        if ((n != 0) && verbose)
2605
 
                                mprintf("      - Molecule %s[%d] united, %d bonds unwrapped.\n",m->m_sName,z2+1,n);
2606
 
 
2607
 
                        if ((n != 0) && (!verbose) && g_bVerbose)
2608
 
                                mprintf("\n  # UniteMolecules: Molecule %s[%d] united, %d bonds unwrapped.",m->m_sName,z2+1,n);
2609
 
        
2610
 
                }
2611
 
        }
2612
 
        BTOUT; 
2613
 
}
2614
 
 
2615
 
 
2616
 
bool CTimeStep::ReadTimestep(FILE *a, bool needinfo)
2617
 
{
2618
 
        BTIN;
2619
 
        switch(g_iTrajFormat)
2620
 
        {
2621
 
                case 0:
2622
 
                        if (!ReadXYZ(a,needinfo,&m_vaCoords))
2623
 
                                return false;
2624
 
                        break;
2625
 
 
2626
 
                case 1:
2627
 
                        if (!ReadPDB(a,needinfo,&m_vaCoords))
2628
 
                                return false;
2629
 
                        break;
2630
 
 
2631
 
                case 2:
2632
 
                        if (!ReadMol2(a,needinfo))
2633
 
                                return false;
2634
 
                        break;
2635
 
 
2636
 
                case 3:
2637
 
                        if (!ReadLAMMPS(a,needinfo))
2638
 
                                return false;
2639
 
                        break;
2640
 
 
2641
 
                case 4:
2642
 
                        if (!ReadDLPOLY(a,needinfo))
2643
 
                                return false;
2644
 
                        break;
2645
 
        }
2646
 
        if (g_bDoubleBox)
2647
 
                DoubleBox();
2648
 
        BTOUT; 
2649
 
        return true;
2650
 
}
2651
 
 
2652
 
 
2653
 
bool CTimeStep::SkipTimestep(FILE *a)
2654
 
{
2655
 
        BTIN;
2656
 
        switch(g_iTrajFormat)
2657
 
        {
2658
 
                case 0:
2659
 
                        if (!SkipXYZ(a))
2660
 
                                return false;
2661
 
                        break;
2662
 
 
2663
 
                case 1:
2664
 
                        if (!SkipPDB(a))
2665
 
                                return false;
2666
 
                        break;
2667
 
 
2668
 
                case 2:
2669
 
                        if (!SkipMol2(a))
2670
 
                                return false;
2671
 
                        break;
2672
 
 
2673
 
                case 3:
2674
 
                        if (!SkipLAMMPS(a))
2675
 
                                return false;
2676
 
                        break;
2677
 
 
2678
 
                case 4:
2679
 
                        if (!SkipDLPOLY(a))
2680
 
                                return false;
2681
 
                        break;
2682
 
        }
2683
 
        BTOUT; 
2684
 
        return true;
2685
 
}
2686
 
 
2687
 
 
2688
 
bool CTimeStep::ReadTimestepVel(FILE *a)
2689
 
{
2690
 
        BTIN;
2691
 
        char buf[256], *p, *q;
2692
 
        int z, tc;
2693
 
 
2694
 
        buf[0] = 0;
2695
 
        fgets(buf,256,a);
2696
 
        if (feof(a))
2697
 
        {
2698
 
                BTOUT; 
2699
 
                return false;
2700
 
        }
2701
 
        if (strlen(buf) > 0)
2702
 
                buf[strlen(buf)-1] = 0;
2703
 
        tc = atoi(buf);
2704
 
        if (tc == 0)
2705
 
        {
2706
 
                BTOUT; 
2707
 
                return false;
2708
 
        }
2709
 
        m_vaVelocities.SetSize(tc);
2710
 
        buf[0] = 0;
2711
 
        fgets(buf,256,a); // Zeitschritt - egal hier
2712
 
        if (strlen(buf) > 0)
2713
 
                buf[strlen(buf)-1] = 0;
2714
 
        for (z=0;z<tc;z++) // den ersten Zeitschritt einlesen
2715
 
        {
2716
 
                buf[0] = 0;
2717
 
                fgets(buf,256,a);
2718
 
                if (feof(a))
2719
 
                {
2720
 
                        BTOUT; 
2721
 
                        return false;
2722
 
                }
2723
 
                if (strlen(buf) > 0)
2724
 
                        buf[strlen(buf)-1] = 0;
2725
 
                q = buf;
2726
 
                while (*q == ' ')
2727
 
                        q++;
2728
 
                p = strchr(q,' ');
2729
 
                if (p == NULL)
2730
 
                {
2731
 
                        eprintf("CTimeStep::ReadTimestepVel(): Error 1. %d, \"%s\"\n",z+1,buf);
2732
 
                        continue;
2733
 
                }
2734
 
                while (isdigit(*(p-1)) && (p > buf))
2735
 
                        p--;
2736
 
                if (p == buf)
2737
 
                {
2738
 
                        eprintf("CTimeStep::ReadTimestepVel(): No Atom laben found. %d, \"%s\"\n",z+1,buf);
2739
 
                        continue;
2740
 
                }
2741
 
                *p = 0;
2742
 
                p++;
2743
 
                q = strchr(p,' ');
2744
 
                if (q == NULL)
2745
 
                {
2746
 
                        eprintf("CTimeStep::ReadTimestepVel(): Error 2. %d, \"%s\"\n",z+1,p);
2747
 
                        continue;
2748
 
                }
2749
 
                while (*q == ' ')
2750
 
                        q++;
2751
 
                p = strchr(q,' ');
2752
 
                if (p == NULL)
2753
 
                {
2754
 
                        eprintf("CTimeStep::ReadTimestepVel(): Error 3. %d, \"%s\"\n",z+1,q);
2755
 
                        continue;
2756
 
                }
2757
 
                *p = 0;
2758
 
                m_vaVelocities[z][0] = (float)atof(q);
2759
 
                q = p+1;
2760
 
                while (*q == ' ')
2761
 
                        q++;
2762
 
                p = strchr(q,' ');
2763
 
                if (p == NULL)
2764
 
                {
2765
 
                        eprintf("CTimeStep::ReadTimestepVel(): Error 4. %d, \"%s\"\n",z+1,q);
2766
 
                        continue;
2767
 
                }
2768
 
                *p = 0;
2769
 
                m_vaVelocities[z][1] = (float)atof(q);
2770
 
                q = p+1;
2771
 
                while (*q == ' ')
2772
 
                        q++;
2773
 
                p = strchr(q,' ');
2774
 
                if (p != NULL)
2775
 
                        *p = 0;
2776
 
                m_vaVelocities[z][2] = (float)atof(q);
2777
 
        }
2778
 
        if (g_bDoubleBox)
2779
 
                DoubleBoxVelocity();
2780
 
        BTOUT; 
2781
 
        return true;
2782
 
}
2783
 
 
2784
 
 
2785
 
bool CTimeStep::ReadTimestepForce(FILE *a)
2786
 
{
2787
 
        BTIN;
2788
 
        char buf[256], *p, *q;
2789
 
        int z, tc;
2790
 
 
2791
 
        buf[0] = 0;
2792
 
        fgets(buf,256,a);
2793
 
        if (feof(a))
2794
 
        {
2795
 
                BTOUT; 
2796
 
                return false;
2797
 
        }
2798
 
        if (strlen(buf) > 0)
2799
 
                buf[strlen(buf)-1] = 0;
2800
 
        tc = atoi(buf);
2801
 
        if (tc == 0)
2802
 
        {
2803
 
                BTOUT; 
2804
 
                return false;
2805
 
        }
2806
 
        m_vaForces.SetSize(tc);
2807
 
        buf[0] = 0;
2808
 
        fgets(buf,256,a); // Zeitschritt - egal hier
2809
 
        if (strlen(buf) > 0)
2810
 
                buf[strlen(buf)-1] = 0;
2811
 
        for (z=0;z<tc;z++) // den ersten Zeitschritt einlesen
2812
 
        {
2813
 
                buf[0] = 0;
2814
 
                fgets(buf,256,a);
2815
 
                if (feof(a))
2816
 
                {
2817
 
                        BTOUT; 
2818
 
                        return false;
2819
 
                }
2820
 
                if (strlen(buf) > 0)
2821
 
                        buf[strlen(buf)-1] = 0;
2822
 
                q = buf;
2823
 
                while (*q == ' ')
2824
 
                        q++;
2825
 
                p = strchr(q,' ');
2826
 
                if (p == NULL)
2827
 
                {
2828
 
                        eprintf("CTimeStep::ReadTimestepForce(): Error 1. %d, \"%s\"\n",z+1,buf);
2829
 
                        continue;
2830
 
                }
2831
 
                while (isdigit(*(p-1)) && (p > buf))
2832
 
                        p--;
2833
 
                if (p == buf)
2834
 
                {
2835
 
                        eprintf("CTimeStep::ReadTimestepForce(): No Atom laben found. %d, \"%s\"\n",z+1,buf);
2836
 
                        continue;
2837
 
                }
2838
 
                *p = 0;
2839
 
                p++;
2840
 
                q = strchr(p,' ');
2841
 
                if (q == NULL)
2842
 
                {
2843
 
                        eprintf("CTimeStep::ReadTimestepForce(): Error 2. %d, \"%s\"\n",z+1,p);
2844
 
                        continue;
2845
 
                }
2846
 
                while (*q == ' ')
2847
 
                        q++;
2848
 
                p = strchr(q,' ');
2849
 
                if (p == NULL)
2850
 
                {
2851
 
                        eprintf("CTimeStep::ReadTimestepForce(): Error 3. %d, \"%s\"\n",z+1,q);
2852
 
                        continue;
2853
 
                }
2854
 
                *p = 0;
2855
 
                m_vaForces[z][0] = (float)atof(q);
2856
 
                q = p+1;
2857
 
                while (*q == ' ')
2858
 
                        q++;
2859
 
                p = strchr(q,' ');
2860
 
                if (p == NULL)
2861
 
                {
2862
 
                        eprintf("CTimeStep::ReadTimestepForce(): Error 4. %d, \"%s\"\n",z+1,q);
2863
 
                        continue;
2864
 
                }
2865
 
                *p = 0;
2866
 
                m_vaForces[z][1] = (float)atof(q);
2867
 
                q = p+1;
2868
 
                while (*q == ' ')
2869
 
                        q++;
2870
 
                p = strchr(q,' ');
2871
 
                if (p != NULL)
2872
 
                        *p = 0;
2873
 
                m_vaForces[z][2] = (float)atof(q);
2874
 
        }
2875
 
        if (g_bDoubleBox)
2876
 
                DoubleBoxForce();
2877
 
        BTOUT; 
2878
 
        return true;
2879
 
}
2880
 
 
2881
 
 
2882
 
bool CTimeStep::SkipXYZ(FILE *a)
2883
 
{
2884
 
        BTIN;
2885
 
        char buf[256];
2886
 
        int z, tc;
2887
 
 
2888
 
//      mprintf("*** Skip Anfang ***\n");
2889
 
        buf[0] = 0;
2890
 
        fgets_bin(buf,256,a);
2891
 
        if (feof(a))
2892
 
        {
2893
 
                BTOUT; 
2894
 
                return false;
2895
 
        }
2896
 
        if (strlen(buf)==0)
2897
 
        {
2898
 
                BTOUT; 
2899
 
                return false;
2900
 
        }
2901
 
        buf[strlen(buf)-1] = 0;
2902
 
        tc = atoi(buf);
2903
 
//      mprintf("SkipA: \"%s\".\n",buf);
2904
 
        if (tc == 0)
2905
 
        {
2906
 
                BTOUT; 
2907
 
                return false;
2908
 
        }
2909
 
//      buf[0] = 0;
2910
 
        fgets_bin(buf,256,a); // Zeitschritt - egal hier
2911
 
//      mprintf("SkipB: \"%s\".\n",buf);
2912
 
        for (z=0;z<tc;z++) // den ersten Zeitschritt einlesen
2913
 
        {
2914
 
//              buf[0] = 0;
2915
 
                fgets_bin(buf,256,a);
2916
 
//              mprintf("SkipC%d: \"%s\".\n",z,buf);
2917
 
                if (feof(a))
2918
 
                {
2919
 
                        BTOUT; 
2920
 
                        return false;
2921
 
                }
2922
 
        }
2923
 
//      mprintf("*** Skip Ende ***\n");
2924
 
        BTOUT; 
2925
 
        return true;
2926
 
}
2927
 
 
2928
 
 
2929
 
void CTimeStep::CopyFrom(CTimeStep *t)
2930
 
{
2931
 
        BTIN;
2932
 
        int z;
2933
 
        char *p;
2934
 
        CxVector3 v;
2935
 
 
2936
 
        m_iGesAtomCount = t->m_iGesAtomCount;
2937
 
        m_vaCoords.CopyFrom(&t->m_vaCoords);
2938
 
        if (g_bKeepUnfoldedCoords)
2939
 
                m_vaCoords_Unfolded.CopyFrom(&t->m_vaCoords_Unfolded);
2940
 
        m_vaForces.CopyFrom(&t->m_vaForces);
2941
 
        m_vaVelocities.CopyFrom(&t->m_vaVelocities);
2942
 
        if (t->m_paLabels.GetSize() != 0)
2943
 
        {
2944
 
                for (z=0;z<m_paLabels.GetSize();z++)
2945
 
                        delete[] (char*)m_paLabels[z];
2946
 
                m_paLabels.RemoveAll();
2947
 
                for (z=0;z<t->m_paLabels.GetSize();z++)
2948
 
                {
2949
 
                        try { p = new char[strlen((char*)t->m_paLabels[z])+1]; } catch(...) { p = NULL; }
2950
 
                        if (p == NULL) NewException((double)(strlen((char*)t->m_paLabels[z])+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2951
 
                        
2952
 
                        strcpy(p,(char*)t->m_paLabels[z]);
2953
 
                        m_paLabels.Add(p);
2954
 
                }
2955
 
        }
2956
 
        if (t->m_pComment != NULL)
2957
 
        {
2958
 
                if (m_pComment == NULL)
2959
 
                {
2960
 
                        try { m_pComment = new char[256]; } catch(...) { m_pComment = NULL; }
2961
 
                        if (m_pComment == NULL) NewException((double)256*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
2962
 
                }
2963
 
                strcpy(m_pComment,t->m_pComment);
2964
 
        }
2965
 
        BTOUT; 
2966
 
}
2967
 
 
2968
 
          
2969
 
long CTimeStep::ExtractNumber(int i)
2970
 
{
2971
 
        BXIN;
2972
 
        char *p, *q, buf[20];
2973
 
        int z;
2974
 
        long l;
2975
 
 
2976
 
        if (m_pComment == NULL)
2977
 
                return -1;
2978
 
        p = m_pComment;
2979
 
        for (z=0;z<i;z++)
2980
 
        {
2981
 
                while ((!isdigit(*p)) && (*p != 0))
2982
 
                        p++;
2983
 
                if (*p == 0)
2984
 
                {
2985
 
                        BXOUT;
2986
 
                        return -1;
2987
 
                }
2988
 
                q = p+1;
2989
 
                while ((isdigit(*q)) && (*q != 0))
2990
 
                        q++;
2991
 
                if (*q == 0)
2992
 
                {
2993
 
                        BXOUT;
2994
 
                        return -1;
2995
 
                }
2996
 
                p = q+1;
2997
 
        }
2998
 
        while ((!isdigit(*p)) && (*p != 0))
2999
 
                p++;
3000
 
        if (*p == 0)
3001
 
        {
3002
 
                BXOUT;
3003
 
                return -1;
3004
 
        }
3005
 
        q = p;
3006
 
        while ((isdigit(*q)) && (*q != 0))
3007
 
                q++;
3008
 
        if (q == p)
3009
 
        {
3010
 
                BXOUT;
3011
 
                return -1;
3012
 
        }
3013
 
        memcpy(buf,p,q-p);
3014
 
        buf[q-p] = 0;
3015
 
        l = atoi(buf);
3016
 
        BXOUT;
3017
 
        return l;
3018
 
}
3019
 
 
3020
 
 
3021
 
int CTimeStep::GetCommentNumberCount()
3022
 
{
3023
 
        BXIN;
3024
 
        char *p, *q;
3025
 
        int z;
3026
 
 
3027
 
        if (m_pComment == NULL)
3028
 
                return 0;
3029
 
        p = m_pComment;
3030
 
        z = 0;
3031
 
        while (true)
3032
 
        {
3033
 
                while ((!isdigit(*p)) && (*p != 0))
3034
 
                        p++;
3035
 
                if (*p == 0)
3036
 
                {
3037
 
//                      mprintf("GetCommentNumberCount 1: %d (p=\"%s\", q=\"%s\")\n",z,p,q);
3038
 
                        BXOUT;
3039
 
                        return z;
3040
 
                }
3041
 
                q = p;
3042
 
                while ((isdigit(*q)) && (*q != 0))
3043
 
                        q++;
3044
 
                if (q == p)
3045
 
                {
3046
 
//                      mprintf("GetCommentNumberCount 2: %d (p=\"%s\", q=\"%s\")\n",z,p,q);
3047
 
                        BXOUT;
3048
 
                        return z;
3049
 
                }
3050
 
                z++;
3051
 
                if (*q == 0)
3052
 
                {
3053
 
//                      mprintf("GetCommentNumberCount 3: %d (p=\"%s\", q=\"%s\")\n",z,p,q);
3054
 
                        BXOUT;
3055
 
                        return z;
3056
 
                }
3057
 
                p = q+1;
3058
 
        }
3059
 
        return 0; // Never happens
3060
 
}
3061
 
 
3062
 
 
3063
 
bool CTimeStep::ScanWannier(bool verbose)
3064
 
{
3065
 
        BTIN;
3066
 
        int z, z2, z3;
3067
 
        float td, d, dx, dy, dz;
3068
 
        CMolecule *m;
3069
 
 
3070
 
        if (g_bVerbose)
3071
 
        {
3072
 
                mprintf(WHITE,"\n*** ScanWannier ***\n\n");
3073
 
                verbose = true;
3074
 
        }
3075
 
 
3076
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++)
3077
 
                ((CSingleMolecule*)g_oaSingleMolecules[z])->m_laWannier.RemoveAll_KeepSize();
3078
 
 
3079
 
        for (z=0;z<g_iGesAtomCount;z++)
3080
 
        {
3081
 
                if (g_baAtomIndex[z] != g_iWannierAtomType)
3082
 
                        continue;
3083
 
                d = 9999.0f;
3084
 
                z3 = -1;
3085
 
                for (z2=0;z2<g_iGesAtomCount;z2++)
3086
 
                {
3087
 
                        if (g_baAtomIndex[z2] == g_iWannierAtomType)
3088
 
                                continue;
3089
 
                        dx = m_vaCoords[z][0]-m_vaCoords[z2][0];
3090
 
                        dy = m_vaCoords[z][1]-m_vaCoords[z2][1];
3091
 
                        dz = m_vaCoords[z][2]-m_vaCoords[z2][2];
3092
 
                        if (g_bPeriodicX)
3093
 
                        {
3094
 
                                while (dx > g_fBoxX/2.0f) dx -= g_fBoxX;
3095
 
                                while (dx < -g_fBoxX/2.0f) dx += g_fBoxX;
3096
 
                        }
3097
 
                        if (g_bPeriodicY)
3098
 
                        {
3099
 
                                while (dy > g_fBoxY/2.0f) dy -= g_fBoxY;
3100
 
                                while (dy < -g_fBoxY/2.0f) dy += g_fBoxY;
3101
 
                        }
3102
 
                        if (g_bPeriodicZ)
3103
 
                        {
3104
 
                                while (dz > g_fBoxZ/2.0f) dz -= g_fBoxZ;
3105
 
                                while (dz < -g_fBoxZ/2.0f) dz += g_fBoxZ;
3106
 
                        }
3107
 
                        td = (float)sqrt(dx*dx+dy*dy+dz*dz);
3108
 
                        if (td < d)
3109
 
                        {
3110
 
                                d = td;
3111
 
                                z3 = z2;
3112
 
                        }
3113
 
                }
3114
 
                if (z3 == -1)
3115
 
                        abort();
3116
 
                if (g_bPeriodicX)
3117
 
                {
3118
 
                        while (m_vaCoords[z][0]-m_vaCoords[z3][0] > g_fBoxX/2.0f) m_vaCoords[z][0] -= g_fBoxX;
3119
 
                        while (m_vaCoords[z][0]-m_vaCoords[z3][0] < -g_fBoxX/2.0f) m_vaCoords[z][0] += g_fBoxX;
3120
 
                }
3121
 
                if (g_bPeriodicY)
3122
 
                {
3123
 
                        while (m_vaCoords[z][1]-m_vaCoords[z3][1] > g_fBoxY/2.0f) m_vaCoords[z][1] -= g_fBoxY;
3124
 
                        while (m_vaCoords[z][1]-m_vaCoords[z3][1] < -g_fBoxY/2.0f) m_vaCoords[z][1] += g_fBoxY;
3125
 
                }
3126
 
                if (g_bPeriodicZ)
3127
 
                {
3128
 
                        while (m_vaCoords[z][2]-m_vaCoords[z3][2] > g_fBoxZ/2.0f) m_vaCoords[z][2] -= g_fBoxZ;
3129
 
                        while (m_vaCoords[z][2]-m_vaCoords[z3][2] < -g_fBoxZ/2.0f) m_vaCoords[z][2] += g_fBoxZ;
3130
 
                }
3131
 
                z2 = g_laAtomSMIndex[z3];
3132
 
                if (d > 100.0)
3133
 
                {
3134
 
                        eprintf("Step %d: Wannier center at offset %d too far away from any atom (closest atom is %s[%d] %s%d, %.0f pm).\n",g_iSteps,z+1,((CMolecule*)g_oaMolecules[((CSingleMolecule*)g_oaSingleMolecules[z2])->m_iMolType])->m_sName,((CSingleMolecule*)g_oaSingleMolecules[z2])->m_iMolSMIndex+1,((CAtom*)g_oaAtoms[g_waAtomRealElement[z3]])->m_sName,g_waAtomMolNumber[z3]+1,d);
3135
 
                } else if (verbose)
3136
 
                        mprintf("  - Wannier center %d belongs to %s[%d] %s%d (%.0f pm).\n",z+1,((CMolecule*)g_oaMolecules[((CSingleMolecule*)g_oaSingleMolecules[z2])->m_iMolType])->m_sName,((CSingleMolecule*)g_oaSingleMolecules[z2])->m_iMolSMIndex+1,((CAtom*)g_oaAtoms[g_waAtomRealElement[z3]])->m_sName,g_waAtomMolNumber[z3]+1,d);
3137
 
/*              if (z2 == -1)
3138
 
                {
3139
 
                        eprintf("Wannier center %d: Atom %d does not belong to any molecule.\n",z+1,z3+1);
3140
 
                        continue;
3141
 
                }*/
3142
 
//              mprintf("Wannier Center %d hat Abstand %.2f zu Atom %d in SM %d.\n",z+1,d,z3+1,z2+1);
3143
 
                ((CSingleMolecule*)g_oaSingleMolecules[z2])->m_laWannier.Add(z);
3144
 
        }
3145
 
        if (verbose)
3146
 
                mprintf("\n\n");
3147
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
3148
 
        {
3149
 
                m = (CMolecule*)g_oaMolecules[z];
3150
 
                if (m->m_iWannierCount == 0)
3151
 
                {
3152
 
                        m->m_iWannierCount = ((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[0]])->m_laWannier.GetSize();
3153
 
                        td = 0;
3154
 
                        for (z2=0;z2<m->m_baAtomIndex.GetSize();z2++)
3155
 
                        {
3156
 
                                if (m->m_baAtomIndex[z2] == g_iWannierAtomType)
3157
 
                                        continue;
3158
 
                                if (m->m_baAtomIndex[z2] == g_iVirtAtomType)
3159
 
                                        continue;
3160
 
                                td += ((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_fCharge * m->m_waAtomCount[z2];
3161
 
                        }
3162
 
                        m->m_fCharge = td-m->m_iWannierCount*g_fWannierCharge;
3163
 
                        mprintf("  - Molecule %s contains %d wannier centers. Total charge is %.2f - %.2f = %.2f\n",m->m_sName,m->m_iWannierCount,td,m->m_iWannierCount*g_fWannierCharge,m->m_fCharge);
3164
 
                        if (m->m_fCharge > 5.0)
3165
 
                        {
3166
 
                                eprintf("\n    This molecular charge seems to be too high.\n\n");
3167
 
                                if (!AskYesNo("    Do you want to continue (y/n)? [yes] ",true))
3168
 
                                        return false;
3169
 
                        }
3170
 
                }
3171
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
3172
 
                {
3173
 
                        if (m->m_iWannierCount != ((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]])->m_laWannier.GetSize())
3174
 
                                eprintf("Step %d: Molecule %s[%d] contains %d instead of %d wannier centers.\n",g_iSteps,m->m_sName,z2+1,((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]])->m_laWannier.GetSize(),m->m_iWannierCount);
3175
 
                }
3176
 
        }
3177
 
        BTOUT;
3178
 
        return true;
3179
 
}
3180
 
 
3181
 
 
3182
 
void CTimeStep::CalcDipoles()
3183
 
{
3184
 
        BTIN;
3185
 
        int z, z2, z3, z4;
3186
 
        CMolecule *m;
3187
 
        CSingleMolecule *sm;
3188
 
        CAtom *a;
3189
 
        CxVector3 dc;
3190
 
 
3191
 
//      mprintf("\n*** CalcDipoles ***");
3192
 
 
3193
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
3194
 
        {
3195
 
                m = (CMolecule*)g_oaMolecules[z];
3196
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
3197
 
                {
3198
 
                        if (g_bVerbose)
3199
 
                                mprintf("\nCalcDipoles %s (%d):\n",m->m_sName,z2+1);
3200
 
 
3201
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
3202
 
 
3203
 
                        sm->m_vDipole = CxVector3(0,0,0);
3204
 
 
3205
 
                        if ((!g_bWannier) && (!m->m_bChargesAssigned))
3206
 
                                continue;
3207
 
 
3208
 
                        if (g_bDipoleRefFixed)
3209
 
                                dc = CxVector3(0,0,0);
3210
 
                                        else dc = m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[m->m_iDipoleCenterType])->GetAt(m->m_iDipoleCenterIndex)];
3211
 
 
3212
 
                        if (g_bVerbose)
3213
 
                                mprintf("  Ref. point is ( %f | %f | %f )\n",dc[0],dc[1],dc[2]);
3214
 
 
3215
 
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
3216
 
                        {
3217
 
                                if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
3218
 
                                        continue;
3219
 
 
3220
 
                                if (g_bWannier)
3221
 
                                        if (m->m_baAtomIndex[z3] == g_iWannierAtomType)
3222
 
                                                continue;
3223
 
 
3224
 
                                a = (CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]];
3225
 
                                for (z4=0;z4<m->m_waAtomCount[z3];z4++)
3226
 
                                {
3227
 
//                                      mprintf("  %s%d %.2f x ",a->m_sName,z4+1,a->m_fCharge);
3228
 
//                                      (m_vaCoords[sm->m_iAtomOffset[z3][z4]]-m_vaCoords[sm->m_iAtomOffset[m->Elements-1][0]]).Dump();
3229
 
//                                      mprintf("\n");
3230
 
//                                      mprintf("  %s%d %.2f (%d)\n",a->m_sName,z4+1,a->m_fCharge,((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4));
3231
 
 
3232
 
                                        if (g_bWannier)
3233
 
                                        {
3234
 
                                                sm->m_vDipole += a->m_fCharge * (m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] - dc);
3235
 
 
3236
 
                                                if (g_bVerbose)
3237
 
                                                        mprintf("  %.2f: ( %f | %f | %f )\n",a->m_fCharge,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]);
3238
 
                                        } else
3239
 
                                        {
3240
 
                                                if (g_bReadChargesFrom4thXYZ)
3241
 
                                                {
3242
 
                                //                      mprintf("Moep. z3=%d, z4=%d, c=%f.\n",z3,z4,m_faCharge[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)]);
3243
 
                                                        sm->m_vDipole += m_faCharge[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] * (m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] - dc);
3244
 
                                                        if (g_bVerbose)
3245
 
                                                                mprintf("  %.2f: ( %f | %f | %f )\n",m_faCharge[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]);
3246
 
                                                } else
3247
 
                                                {
3248
 
                                                        sm->m_vDipole += ((CxFloatArray*)m->m_oaCharges[z3])->GetAt(z4) * (m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] - dc);
3249
 
                                                        if (g_bVerbose)
3250
 
                                                                mprintf("  %.2f: ( %f | %f | %f )\n",((CxFloatArray*)m->m_oaCharges[z3])->GetAt(z4),m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]);
3251
 
                                                }
3252
 
                                        }
3253
 
                                }
3254
 
                        }
3255
 
                        for (z3=0;z3<sm->m_laWannier.GetSize();z3++)
3256
 
                        {
3257
 
//                              mprintf("  - %.2f x ",g_fWannierCharge);
3258
 
//                              (m_vaCoords[sm->m_waWannier[z3]] - m_vaCoords[sm->m_iAtomOffset[m->Elements-1][0]]).Dump();
3259
 
//                              mprintf("\n");
3260
 
                                sm->m_vDipole -= g_fWannierCharge * (m_vaCoords[sm->m_laWannier[z3]] - dc);
3261
 
 
3262
 
                                if (g_bVerbose)
3263
 
                                        mprintf("  %.2f: ( %f | %f | %f )\n",-g_fWannierCharge,m_vaCoords[sm->m_laWannier[z3]][0],m_vaCoords[sm->m_laWannier[z3]][1],m_vaCoords[sm->m_laWannier[z3]][2]);
3264
 
                        }
3265
 
//                      mprintf("  = ");
3266
 
//                      sm->m_vDipole.Dump();
3267
 
//                      mprintf("\n");
3268
 
                        sm->m_vDipole *= 0.048008f; // Conversion e*pm --> Debye
3269
 
 
3270
 
                        if (g_bVerbose)
3271
 
                                mprintf("  Result: %f.\n",sm->m_vDipole.GetLength());
3272
 
 
3273
 
//                      mprintf("Molecule %s - Dipole %.3f\n",m->Name,sm->m_vDipole.GetLength());
3274
 
                }
3275
 
        }
3276
 
        BTOUT;
3277
 
}
3278
 
 
3279
 
 
3280
 
void CTimeStep::DoubleBox()
3281
 
{
3282
 
        int px, py, pz, z;
3283
 
        char *p;
3284
 
 
3285
 
        if (m_vaCoords.GetSize() < g_iGesAtomCount)
3286
 
                m_vaCoords.SetSize(g_iGesAtomCount);
3287
 
 
3288
 
        if (m_paLabels.GetSize() != 0)
3289
 
                m_paLabels.SetSize(g_iGesAtomCount);
3290
 
 
3291
 
        for (pz=0;pz<g_iDoubleBoxZ;pz++)
3292
 
        {
3293
 
                for (py=0;py<g_iDoubleBoxY;py++)
3294
 
                {
3295
 
                        for (px=0;px<g_iDoubleBoxX;px++)
3296
 
                        {
3297
 
                                if ((px == 0) && (py == 0) && (pz == 0))
3298
 
                                        continue;
3299
 
                                for (z=0;z<g_iGesAtomCount/g_iDoubleBoxFactor;z++)
3300
 
                                {
3301
 
                                        m_vaCoords[(pz*g_iDoubleBoxX*g_iDoubleBoxY+py*g_iDoubleBoxX+px)*g_iGesAtomCount/g_iDoubleBoxFactor+z] = m_vaCoords[z] + CxVector3(px*g_fBoxX/g_iDoubleBoxX,py*g_fBoxY/g_iDoubleBoxY,pz*g_fBoxZ/g_iDoubleBoxZ);
3302
 
                                        if (m_paLabels.GetSize() != 0)
3303
 
                                        {
3304
 
                                                try { p = new char[strlen((char*)m_paLabels[z])+1]; } catch(...) { p = NULL; }
3305
 
                                                if (p == NULL) NewException((double)(strlen((char*)m_paLabels[z])+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3306
 
                                                
3307
 
                                                strcpy(p,(char*)m_paLabels[z]);
3308
 
                                                m_paLabels[(pz*g_iDoubleBoxX*g_iDoubleBoxY+py*g_iDoubleBoxX+px)*g_iGesAtomCount/g_iDoubleBoxFactor+z] = p;
3309
 
                                        }
3310
 
                                }
3311
 
                        }
3312
 
                }
3313
 
        }
3314
 
        m_iGesAtomCount = g_iGesAtomCount;
3315
 
}
3316
 
 
3317
 
 
3318
 
void CTimeStep::DoubleBoxVelocity()
3319
 
{
3320
 
        int px, py, pz, z;
3321
 
 
3322
 
        if (m_vaVelocities.GetSize() < g_iGesAtomCount)
3323
 
                m_vaVelocities.SetSize(g_iGesAtomCount);
3324
 
 
3325
 
        for (pz=0;pz<g_iDoubleBoxZ;pz++)
3326
 
        {
3327
 
                for (py=0;py<g_iDoubleBoxY;py++)
3328
 
                {
3329
 
                        for (px=0;px<g_iDoubleBoxX;px++)
3330
 
                        {
3331
 
                                if ((px == 0) && (py == 0) && (pz == 0))
3332
 
                                        continue;
3333
 
                                for (z=0;z<g_iGesAtomCount/g_iDoubleBoxFactor;z++)
3334
 
                                        m_vaVelocities[(pz*g_iDoubleBoxX*g_iDoubleBoxY+py*g_iDoubleBoxX+px)*g_iGesAtomCount/g_iDoubleBoxFactor+z] = m_vaVelocities[z];
3335
 
                        }
3336
 
                }
3337
 
        }
3338
 
}
3339
 
 
3340
 
 
3341
 
void CTimeStep::DoubleBoxForce()
3342
 
{
3343
 
        int px, py, pz, z;
3344
 
 
3345
 
        if (m_vaForces.GetSize() < g_iGesAtomCount)
3346
 
                m_vaForces.SetSize(g_iGesAtomCount);
3347
 
 
3348
 
        for (pz=0;pz<g_iDoubleBoxZ;pz++)
3349
 
        {
3350
 
                for (py=0;py<g_iDoubleBoxY;py++)
3351
 
                {
3352
 
                        for (px=0;px<g_iDoubleBoxX;px++)
3353
 
                        {
3354
 
                                if ((px == 0) && (py == 0) && (pz == 0))
3355
 
                                        continue;
3356
 
                                for (z=0;z<g_iGesAtomCount/g_iDoubleBoxFactor;z++)
3357
 
                                        m_vaForces[(pz*g_iDoubleBoxX*g_iDoubleBoxY+py*g_iDoubleBoxX+px)*g_iGesAtomCount/g_iDoubleBoxFactor+z] = m_vaForces[z];
3358
 
                        }
3359
 
                }
3360
 
        }
3361
 
}
3362
 
 
3363
 
 
3364
 
bool CTimeStep::ReadXYZ(FILE *a, bool needinfo, CxVec3Array *v)
3365
 
{
3366
 
        BTIN;
3367
 
        char buf[256], obuf[256],  *p, *q, *r;
3368
 
        int z, /*i,*/ j;
3369
 
        const char *separators = " ,;\"'\t";
3370
 
 
3371
 
//      mprintf("*** Read Anfang.\n");
3372
 
        j = 0;
3373
 
//      m_iSizeBytes = 0;
3374
 
_readagain:
3375
 
        buf[0] = 0;
3376
 
        fgets_bin(buf,256,a);
3377
 
//      m_iSizeBytes += strlen(buf);
3378
 
        if (strlen(buf) > 0)
3379
 
                buf[strlen(buf)-1] = 0;
3380
 
//      mprintf("Read1: \"%s\".\n",buf);
3381
 
        goto _firsttry;
3382
 
_again:
3383
 
        eprintf("\nTrajectory file seems to be damaged. Searching for next time step...");
3384
 
_firsttry:
3385
 
        if (feof(a))
3386
 
        {
3387
 
//              mprintf("CTimeStep::ReadTimestep(): Unexpected End of File (1).\n"); 
3388
 
                BTOUT; 
3389
 
                return false;
3390
 
        }
3391
 
        if (strchr(buf,'.') != NULL)
3392
 
        {
3393
 
                if (j < 10)
3394
 
                        eprintf("x",j,buf);
3395
 
//                      mprintf("x: %d - \"%s\"\n",j,buf);
3396
 
                j++;
3397
 
                goto _readagain;
3398
 
        }
3399
 
        m_iGesAtomCount = atoi(buf);
3400
 
        if (m_iGesAtomCount == 0)
3401
 
        {
3402
 
                eprintf("\nCTimeStep::ReadXYZ(): Error - atom count = 0. \"%s\"",buf);
3403
 
                goto _readagain;
3404
 
        }
3405
 
        if (m_pComment == NULL)
3406
 
        {
3407
 
                try { m_pComment = new char[128]; } catch(...) { m_pComment = NULL; }
3408
 
                if (m_pComment == NULL) NewException((double)128*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3409
 
        }
3410
 
        if (needinfo)
3411
 
        {
3412
 
                for (z=0;z<m_paLabels.GetSize();z++)
3413
 
                        delete[] (char*)m_paLabels[z];
3414
 
                m_paLabels.RemoveAll();
3415
 
                if (g_bDoubleBox)
3416
 
                        m_paLabels.SetSize(m_iGesAtomCount*g_iDoubleBoxFactor);
3417
 
                                else m_paLabels.SetSize(m_iGesAtomCount);
3418
 
        }
3419
 
        if (v->GetSize() < (long)m_iGesAtomCount)
3420
 
                v->SetSize(m_iGesAtomCount);
3421
 
 
3422
 
        if (g_bKeepOriginalCoords)
3423
 
        {
3424
 
                if (m_vaCoords_Original.GetSize() < (long)m_iGesAtomCount)
3425
 
                        m_vaCoords_Original.SetSize(m_iGesAtomCount);
3426
 
        }
3427
 
 
3428
 
        m_pComment[0] = 0;
3429
 
        fgets_bin(m_pComment,128,a); // Zeitschritt - egal hier
3430
 
//      if (strlen(m_pComment) > 0)
3431
 
//              m_pComment[strlen(m_pComment)-1] = 0;
3432
 
 
3433
 
        p = m_pComment;
3434
 
        while (*p != 0)
3435
 
        {
3436
 
                if ((*p == 10) || (*p == 13))
3437
 
                        *p = 0;
3438
 
                p++;
3439
 
        }
3440
 
//      mprintf("Comment: \"%s\".\n",m_pComment);
3441
 
//      m_iSizeBytes += strlen(m_pComment);
3442
 
 
3443
 
        if (g_bReadChargesFrom4thXYZ)
3444
 
                m_faCharge.SetSize(m_iGesAtomCount);
3445
 
 
3446
 
        for (z=0;z<(long)m_iGesAtomCount;z++) // den ersten Zeitschritt einlesen
3447
 
        {
3448
 
                buf[0] = 0;
3449
 
                fgets_bin(buf,256,a);
3450
 
                if (feof(a))
3451
 
                {
3452
 
                        eprintf("\nCTimeStep::ReadXYZ(): Unexpected end of file (2). \"%s\"\n",buf);
3453
 
                        BTOUT; 
3454
 
                        return false;
3455
 
                }
3456
 
//              m_iSizeBytes += strlen(buf);
3457
 
                buf[strlen(buf)-1] = 0;
3458
 
//              mprintf("  %d: \"%s\".\n",z,buf);
3459
 
                strcpy(obuf,buf);
3460
 
//              i = 0;
3461
 
 
3462
 
                p = &buf[0];
3463
 
                while (strchr(separators,*p) != NULL)
3464
 
                        p++;
3465
 
                q = p+1;
3466
 
                while ((strchr(separators,*q) == NULL) && (*q != 0))
3467
 
                        q++;
3468
 
                if (*q == 0)
3469
 
                {
3470
 
                        eprintf("\nCTimeStep::ReadXYZ(): %d: Incomplete line (1): \"%s\"\n",z+1,obuf);
3471
 
                        BTOUT; 
3472
 
                        return false;
3473
 
                }
3474
 
                *q = 0;
3475
 
 
3476
 
                if (needinfo)
3477
 
                {
3478
 
                        if (strlen(p) > 7)
3479
 
                        {
3480
 
                                eprintf("\nCTimeStep::ReadXYZ(): \"%s\" - Maximum length of atom labels is 7 chars; truncating.\n",p);
3481
 
                                p[7] = 0;
3482
 
                        }
3483
 
 
3484
 
                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
3485
 
                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3486
 
                        
3487
 
                        strcpy(r,p);
3488
 
                        m_paLabels[z] = r;
3489
 
                }
3490
 
 
3491
 
                q++;
3492
 
                while (strchr(separators,*q) != NULL)
3493
 
                        q++;
3494
 
                p = q;
3495
 
                while ((strchr(separators,*p) == NULL) && (*p != 0))
3496
 
                        p++;
3497
 
                if (*p == 0)
3498
 
                {
3499
 
                        eprintf("\nCTimeStep::ReadXYZ(): %d: Incomplete line (2): \"%s\"",z+1,obuf);
3500
 
                        goto _again;
3501
 
                }
3502
 
                *p = 0;
3503
 
                (*v)[z][0] = (float)atof(q) * 100.0f;
3504
 
 
3505
 
                if (g_bKeepOriginalCoords)
3506
 
                        m_vaCoords_Original[z][0] = (double)atof(q) * 100.0;
3507
 
 
3508
 
                q = p+1;
3509
 
                while (strchr(separators,*q) != NULL)
3510
 
                        q++;
3511
 
                p = q;
3512
 
                while ((strchr(separators,*p) == NULL) && (*p != 0))
3513
 
                        p++;
3514
 
                if (*p == 0)
3515
 
                {
3516
 
                        eprintf("\nCTimeStep::ReadXYZ(): %d: Incomplete line (3) \"%s\"",z+1,obuf);
3517
 
                        goto _again;
3518
 
                }
3519
 
                *p = 0;
3520
 
                (*v)[z][1] = (float)atof(q) * 100.0f;
3521
 
 
3522
 
                if (g_bKeepOriginalCoords)
3523
 
                        m_vaCoords_Original[z][1] = (double)atof(q) * 100.0;
3524
 
 
3525
 
                q = p+1;
3526
 
                while (strchr(separators,*q) != NULL)
3527
 
                        q++;
3528
 
                p = q;
3529
 
                while ((strchr(separators,*p) == NULL) && (*p != 0))
3530
 
                        p++;
3531
 
                if (g_bReadChargesFrom4thXYZ)
3532
 
                {
3533
 
                        if (*p == 0)
3534
 
                        {
3535
 
                                eprintf("\nCTimeStep::ReadXYZ(): %d: Incomplete line (4) \"%s\"",z+1,obuf);
3536
 
                                goto _again;
3537
 
                        }
3538
 
                        *p = 0;
3539
 
                } else
3540
 
                {
3541
 
                        if (*p != 0)
3542
 
                                *p = 0;
3543
 
                }
3544
 
                (*v)[z][2] = (float)atof(q) * 100.0f;
3545
 
 
3546
 
                if (g_bKeepOriginalCoords)
3547
 
                        m_vaCoords_Original[z][2] = (double)atof(q) * 100.0;
3548
 
 
3549
 
                if (g_bReadChargesFrom4thXYZ)
3550
 
                {
3551
 
                        q = p+1;
3552
 
                        while (strchr(separators,*q) != NULL)
3553
 
                                q++;
3554
 
                        p = q;
3555
 
                        while ((strchr(separators,*p) == NULL) && (*p != 0))
3556
 
                                p++;
3557
 
                        if (*p != 0)
3558
 
                                *p = 0;
3559
 
                        m_faCharge[z] = (float)atof(q);
3560
 
                } else if (needinfo && (z==0))
3561
 
                {
3562
 
                        if (*p == 0)
3563
 
                                goto _no4;
3564
 
                        q = p+1;
3565
 
                        if (*q == 0)
3566
 
                                goto _no4;
3567
 
                        while (strchr(separators,*q) != NULL)
3568
 
                                q++;
3569
 
                        p = q;
3570
 
                        while ((strchr(separators,*p) == NULL) && (*p != 0))
3571
 
                                p++;
3572
 
                        if ((p-q) > 3)
3573
 
                        {
3574
 
                                for (;q<p;q++)
3575
 
                                        if (!(((*q >= '0') && (*q <= '9')) || (*q == '-') || (*q == '.')))
3576
 
                                                goto _no4;
3577
 
                                g_bXYZ4thCol = true;
3578
 
_no4:;
3579
 
                        }
3580
 
                }
3581
 
 
3582
 
/*              q = strchr(buf,'.');
3583
 
                if (q != NULL)
3584
 
                {
3585
 
                        i++;
3586
 
                        q = strchr(q+1,'.');
3587
 
                }
3588
 
                if (q != NULL)
3589
 
                {
3590
 
                        i++;
3591
 
                        q = strchr(q+1,'.');
3592
 
                }
3593
 
                if (q==NULL)
3594
 
                {
3595
 
                        eprintf("\nCTimeStep::ReadXYZ(): Error - only %d/3 dots. %d, \"%s\"",i,z+1,buf);
3596
 
                        goto _again;
3597
 
                }
3598
 
                q = buf;
3599
 
                while (*q == ' ')
3600
 
                        q++;
3601
 
                p = strchr(q,' ');
3602
 
                if (p == NULL)
3603
 
                {
3604
 
                        eprintf("\nCTimeStep::ReadXYZ(): Error 1. %d, \"%s\"",z+1,buf);
3605
 
                        goto _again;
3606
 
                }
3607
 
                while (isdigit(*(p-1)) && (p > buf))
3608
 
                        p--;
3609
 
                if (p == buf)
3610
 
                {
3611
 
                        eprintf("\nCTimeStep::ReadXYZ(): No Atom label found. %d, \"%s\"",z+1,buf);
3612
 
                        goto _again;
3613
 
                }
3614
 
                *p = 0;
3615
 
                if (needinfo)
3616
 
                {
3617
 
                        r = new char[strlen(q)+1];
3618
 
                        strcpy(r,q);
3619
 
                        m_paLabels[z] = r;
3620
 
                }
3621
 
                q = p+1;
3622
 
                while (*q == ' ')
3623
 
                        q++;
3624
 
                p = strchr(q,' ');
3625
 
                if (p == NULL)
3626
 
                {
3627
 
                        eprintf("\nCTimeStep::ReadXYZ(): Error 3. %d, \"%s\"",z+1,q);
3628
 
                        goto _again;
3629
 
                }
3630
 
                *p = 0;
3631
 
                (*v)[z][0] = (float)atof(q) * 100.0f;
3632
 
                q = p+1;
3633
 
                while (*q == ' ')
3634
 
                        q++;
3635
 
                p = strchr(q,' ');
3636
 
                if (p == NULL)
3637
 
                {
3638
 
                        eprintf("\nCTimeStep::ReadXYZ(): Error 4. %d, \"%s\"",z+1,q);
3639
 
                        goto _again;
3640
 
                }
3641
 
                *p = 0;
3642
 
                (*v)[z][1] = (float)atof(q) * 100.0f;
3643
 
                q = p+1;
3644
 
                while (*q == ' ')
3645
 
                        q++;
3646
 
                p = strchr(q,' ');
3647
 
                if (p != NULL)
3648
 
                        *p = 0;
3649
 
                (*v)[z][2] = (float)atof(q) * 100.0f;*/
3650
 
 
3651
 
 
3652
 
        }
3653
 
//      mprintf("*** Read Ende.\n");
3654
 
        BTOUT; 
3655
 
        return true;
3656
 
}
3657
 
 
3658
 
 
3659
 
bool CTimeStep::ReadPDB(FILE *a, bool needinfo, CxVec3Array *v)
3660
 
{
3661
 
        int i;
3662
 
        static char buf[256], obuf[256], buf2[64];
3663
 
        char *p, *q, *r;
3664
 
        float x, y, z;
3665
 
        bool b;
3666
 
 
3667
 
        v->RemoveAll_KeepSize();
3668
 
        for (i=0;i<m_paLabels.GetSize();i++)
3669
 
                delete[] (char*)m_paLabels[i];
3670
 
        m_paLabels.RemoveAll();
3671
 
        while (true)
3672
 
        {
3673
 
                fgets_bin(buf,256,a);
3674
 
                if (feof(a))
3675
 
                        return false;
3676
 
                if (strlen(buf) == 0)
3677
 
                        continue;
3678
 
                buf[strlen(buf)-1] = 0;
3679
 
                strcpy(obuf,buf);
3680
 
                if (g_bNPT)
3681
 
                {
3682
 
                        if (strstr(buf,"CRYST1") != 0) // Boxlaenge
3683
 
                        {
3684
 
        //                      mprintf(GREY,"\"%s\".\n",buf);
3685
 
                                p = &buf[6];
3686
 
                                while (*p == ' ')
3687
 
                                        p++;
3688
 
                                q = p;
3689
 
                                while ((*q != ' ') && (*q != 0))
3690
 
                                        q++;
3691
 
                                if (*q == 0)
3692
 
                                {
3693
 
                                        eprintf("Error 5 reading PDB line: \"%s\".\n",obuf);
3694
 
                                        return false;
3695
 
                                }
3696
 
                                *q = 0;
3697
 
                                g_fBoxX = (float)(atof(p)*100.0);
3698
 
                                p = q+1;
3699
 
 
3700
 
                                while (*p == ' ')
3701
 
                                        p++;
3702
 
                                q = p;
3703
 
                                while ((*q != ' ') && (*q != 0))
3704
 
                                        q++;
3705
 
                                if (*q == 0)
3706
 
                                {
3707
 
                                        eprintf("Error 6 reading PDB line: \"%s\".\n",obuf);
3708
 
                                        return false;
3709
 
                                }
3710
 
                                *q = 0;
3711
 
                                g_fBoxY = (float)(atof(p)*100.0);
3712
 
                                p = q+1;
3713
 
 
3714
 
                                while (*p == ' ')
3715
 
                                        p++;
3716
 
                                q = p;
3717
 
                                while ((*q != ' ') && (*q != 0))
3718
 
                                        q++;
3719
 
                                if (*q != 0)
3720
 
                                        *q = 0;
3721
 
                                g_fBoxZ = (float)(atof(p)*100.0);
3722
 
//                              mprintf(GREY,"--> %f %f %f\n",g_fBoxX,g_fBoxY,g_fBoxZ);
3723
 
                        }
3724
 
                }
3725
 
 
3726
 
                if (strstr(buf,"END") == buf)
3727
 
                        break;
3728
 
 
3729
 
                if ((strstr(buf,"ATOM")==0) && (strstr(buf,"HETATM")==0))
3730
 
                        continue;
3731
 
 
3732
 
                p = &buf[7];
3733
 
                while (!(isalpha(*p) || (*p == '_')) && (*p != 0))
3734
 
                        p++;
3735
 
                if (*p == 0)
3736
 
                {
3737
 
                        eprintf("Error 4 reading PDB line: \"%s\".\n",obuf);
3738
 
                        return false;
3739
 
                }
3740
 
                q = p;
3741
 
                while (isalpha(*q) || (*q == '_'))
3742
 
                        q++;
3743
 
                if (needinfo)
3744
 
                {
3745
 
                        *q = 0;
3746
 
                        if (strlen(p) > 7)
3747
 
                        {
3748
 
                                eprintf("\nCTimeStep::ReadPDB(): \"%s\" - maximum length for atom labels is 7 chars; truncating.\n",p);
3749
 
                                p[7] = 0;
3750
 
                        }
3751
 
 
3752
 
                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
3753
 
                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3754
 
                        
3755
 
                        strcpy(r,p);
3756
 
                        m_paLabels.Add(r);
3757
 
                }
3758
 
                p = q+1;
3759
 
 
3760
 
                while ((*p != '.') && (*p != 0))
3761
 
                        p++;
3762
 
 
3763
 
                while (*p != ' ')
3764
 
                        p--;
3765
 
 
3766
 
                p++;
3767
 
 
3768
 
                q = p;
3769
 
                b = false;
3770
 
                while (*q != 0)
3771
 
                {
3772
 
                        if (b)
3773
 
                        {
3774
 
                                if ((*q == ' ') || (*q == '-'))
3775
 
                                        break;
3776
 
                        }
3777
 
                        if (*q == 0)
3778
 
                                break;
3779
 
                        if ((*q == '-') || (*q == '.') || ((*q >= '0') && (*q <= '9')))
3780
 
                                b = true;
3781
 
                        q++;
3782
 
                }
3783
 
//              q = strchr(p,' ');
3784
 
                if (*q == 0)
3785
 
                {
3786
 
                        eprintf("\nCTimeStep::ReadPDB(): Error 1. \"%s\".",obuf);
3787
 
                        return false;
3788
 
                }
3789
 
                memcpy(buf2,p,q-p);
3790
 
                buf2[q-p] = 0;
3791
 
                x = (float)atof(buf2) * 100.0f;
3792
 
//              mprintf("\n  \"%s\".",buf2);
3793
 
 
3794
 
                p = q;
3795
 
                b = false;
3796
 
                while (*q != 0)
3797
 
                {
3798
 
                        if (b)
3799
 
                        {
3800
 
                                if ((*q == ' ') || (*q == '-'))
3801
 
                                        break;
3802
 
                        }
3803
 
                        if (*q == 0)
3804
 
                                break;
3805
 
                        if ((*q == '-') || (*q == '.') || ((*q >= '0') && (*q <= '9')))
3806
 
                                b = true;
3807
 
                        q++;
3808
 
                }
3809
 
//              q = strchr(p,' ');
3810
 
                if (*q == 0)
3811
 
                {
3812
 
                        eprintf("\nCTimeStep::ReadPDB(): Error 2. \"%s\".",obuf);
3813
 
                        return false;
3814
 
                }
3815
 
                memcpy(buf2,p,q-p);
3816
 
                buf2[q-p] = 0;
3817
 
                y = (float)atof(buf2) * 100.0f;
3818
 
//              mprintf("\n  \"%s\".",buf2);
3819
 
 
3820
 
                z = (float)atof(q) * 100.0f;
3821
 
//              mprintf("\n  \"%s\".",q);
3822
 
 
3823
 
//              mprintf("\n%f, %f, %f",x,y,z);
3824
 
 
3825
 
                m_vaCoords.Add(CxVector3(x,y,z));
3826
 
        }
3827
 
        m_iGesAtomCount = m_vaCoords.GetSize();
3828
 
 
3829
 
        return true;
3830
 
}
3831
 
 
3832
 
 
3833
 
bool CTimeStep::SkipPDB(FILE *a)
3834
 
{
3835
 
        char buf[256];
3836
 
//      bool b;
3837
 
 
3838
 
        while (true)
3839
 
        {
3840
 
                fgets_bin(buf,256,a);
3841
 
                if (feof(a))
3842
 
                        return false;
3843
 
                if (strlen(buf) == 0)
3844
 
                        continue;
3845
 
                buf[strlen(buf)-1] = 0;
3846
 
                if (strstr(buf,"END") == buf)
3847
 
                        break;
3848
 
        }
3849
 
        return true;
3850
 
}
3851
 
 
3852
 
 
3853
 
bool CTimeStep::ReadLAMMPS(FILE *a, bool needinfo)
3854
 
{
3855
 
        int i;
3856
 
        char buf[256], obuf[256], *p, *q, *r;
3857
 
        float x, y, z;
3858
 
 
3859
 
        m_vaCoords.RemoveAll_KeepSize();
3860
 
        for (i=0;i<m_paLabels.GetSize();i++)
3861
 
                delete[] (char*)m_paLabels[i];
3862
 
        m_paLabels.RemoveAll();
3863
 
        m_iGesAtomCount = 0;
3864
 
        while (true)
3865
 
        {
3866
 
                fgets_bin(buf,256,a);
3867
 
                if (feof(a))
3868
 
                        return false;
3869
 
                if (strlen(buf) == 0)
3870
 
                        continue;
3871
 
                buf[strlen(buf)-1] = 0;
3872
 
                strcpy(obuf,buf);
3873
 
                if (g_bNPT)
3874
 
                {
3875
 
                        if (strstr(buf,"ITEM: BOX BOUNDS") != 0) // Boxlaenge
3876
 
                        {
3877
 
                                for (i=0;i<3;i++)
3878
 
                                {
3879
 
                                        fgets_bin(buf,256,a);
3880
 
                                        if (feof(a))
3881
 
                                                return false;
3882
 
 
3883
 
                                        p = &buf[0];
3884
 
                                        while (strchr(" ",*p) != NULL)
3885
 
                                                p++;
3886
 
                                        q = p+1;
3887
 
                                        while ((strchr(" ",*q) == NULL) && (*q != 0))
3888
 
                                                q++;
3889
 
                                        if (*q == 0)
3890
 
                                        {
3891
 
                                                eprintf("\nCTimeStep::ReadLAMMPS(): Incomplete line: \"%s\"\n",obuf);
3892
 
                                                return false;
3893
 
                                        }
3894
 
                                        *q = 0;
3895
 
                                        x = atof(p);
3896
 
 
3897
 
                                        p = q+1;
3898
 
                                        while (strchr(" ",*p) != NULL)
3899
 
                                                p++;
3900
 
 
3901
 
                                        y = atof(p);
3902
 
 
3903
 
                                        switch(i)
3904
 
                                        {
3905
 
                                                case 0: g_fBoxX = (y-x)*100.0f; break;
3906
 
                                                case 1: g_fBoxY = (y-x)*100.0f; break;
3907
 
                                                case 2: g_fBoxZ = (y-x)*100.0f; break;
3908
 
                                        }
3909
 
                                }
3910
 
                        }
3911
 
                }
3912
 
                if (strstr(buf,"ITEM: NUMBER OF ATOMS") != 0)
3913
 
                {
3914
 
                        fgets_bin(buf,256,a);
3915
 
                        if (feof(a))
3916
 
                                return false;
3917
 
                        buf[strlen(buf)-1] = 0;
3918
 
                        m_iGesAtomCount = atoi(buf);
3919
 
                        continue;
3920
 
                }
3921
 
                if (strstr(buf,"ITEM: ATOMS") != 0)
3922
 
                {
3923
 
                        if (strstr(buf,"ITEM: ATOMS element xu yu zu") == 0)
3924
 
                        {
3925
 
                                eprintf("CTimeStep::ReadLAMMPS(): Wrong LAMMPS dump style: \"%s\".\n",buf);
3926
 
                                eprintf("You need to use \"dump custom element xu yu zu\".\n");
3927
 
                                return false;
3928
 
                        }
3929
 
 
3930
 
                        if (m_iGesAtomCount == 0)
3931
 
                        {
3932
 
                                eprintf("CTimeStep::ReadLAMMPS(): \"ITEM: ATOMS\" before \"ITEM: NUMBER OF ATOMS\".\n");
3933
 
                                return false;
3934
 
                        }
3935
 
 
3936
 
                        if (needinfo)
3937
 
                        {
3938
 
                                if (g_bDoubleBox)
3939
 
                                        m_paLabels.SetSize(m_iGesAtomCount*g_iDoubleBoxFactor);
3940
 
                                                else m_paLabels.SetSize(m_iGesAtomCount);
3941
 
                        }
3942
 
 
3943
 
                        for (i=0;i<(int)m_iGesAtomCount;i++)
3944
 
                        {
3945
 
                                fgets_bin(buf,256,a);
3946
 
                                if (feof(a))
3947
 
                                        return false;
3948
 
 
3949
 
                                p = &buf[0];
3950
 
                                while (strchr(" ",*p) != NULL)
3951
 
                                        p++;
3952
 
                                q = p+1;
3953
 
                                while ((strchr(" ",*q) == NULL) && (*q != 0))
3954
 
                                        q++;
3955
 
                                if (*q == 0)
3956
 
                                {
3957
 
                                        eprintf("\nCTimeStep::ReadLAMMPS(): %d: Incomplete line (1): \"%s\"\n",i+1,obuf);
3958
 
                                        BTOUT; 
3959
 
                                        return false;
3960
 
                                }
3961
 
                                *q = 0;
3962
 
 
3963
 
                                if (needinfo)
3964
 
                                {
3965
 
                                        if (strlen(p) > 7)
3966
 
                                        {
3967
 
                                                eprintf("\nCTimeStep::ReadLAMMPS(): \"%s\" - maximum length for atom labels is 7 chars; truncating.\n",p);
3968
 
                                                p[7] = 0;
3969
 
                                        }
3970
 
 
3971
 
                                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
3972
 
                                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
3973
 
                                        
3974
 
                                        strcpy(r,p);
3975
 
                                        m_paLabels[i] = r;
3976
 
                                }
3977
 
 
3978
 
                                q++;
3979
 
                                while (strchr(" ",*q) != NULL)
3980
 
                                        q++;
3981
 
                                p = q;
3982
 
                                while ((strchr(" ",*p) == NULL) && (*p != 0))
3983
 
                                        p++;
3984
 
                                if (*p == 0)
3985
 
                                {
3986
 
                                        eprintf("\nCTimeStep::ReadLAMMPS(): %d: Incomplete line (2): \"%s\"",i+1,obuf);
3987
 
                                        return false;
3988
 
                                }
3989
 
                                *p = 0;
3990
 
                                x = (float)atof(q) * 100.0f;
3991
 
                                q = p+1;
3992
 
                                while (strchr(" ",*q) != NULL)
3993
 
                                        q++;
3994
 
                                p = q;
3995
 
                                while ((strchr(" ",*p) == NULL) && (*p != 0))
3996
 
                                        p++;
3997
 
                                if (*p == 0)
3998
 
                                {
3999
 
                                        eprintf("\nCTimeStep::ReadLAMMPS(): %d: Incomplete line (3) \"%s\"",i+1,obuf);
4000
 
                                        return false;
4001
 
                                }
4002
 
                                *p = 0;
4003
 
                                y = (float)atof(q) * 100.0f;
4004
 
                                q = p+1;
4005
 
                                while (strchr(" ",*q) != NULL)
4006
 
                                        q++;
4007
 
                                p = q;
4008
 
                                while ((strchr(" ",*p) == NULL) && (*p != 0))
4009
 
                                        p++;
4010
 
                                if (*p != 0)
4011
 
                                        *p = 0;
4012
 
                                z = (float)atof(q) * 100.0f;
4013
 
 
4014
 
                                m_vaCoords.Add(CxVector3(x,y,z));
4015
 
                        }
4016
 
                        break;
4017
 
                }
4018
 
        }
4019
 
        return true;
4020
 
}
4021
 
 
4022
 
 
4023
 
bool CTimeStep::SkipLAMMPS(FILE *a)
4024
 
{
4025
 
        int i, j;
4026
 
        char buf[256];
4027
 
 
4028
 
        j = 0;
4029
 
        while (true)
4030
 
        {
4031
 
                fgets_bin(buf,256,a);
4032
 
                if (feof(a))
4033
 
                        return false;
4034
 
                if (strlen(buf) == 0)
4035
 
                        continue;
4036
 
                buf[strlen(buf)-1] = 0;
4037
 
                if (strstr(buf,"ITEM: NUMBER OF ATOMS") != 0)
4038
 
                {
4039
 
                        fgets_bin(buf,256,a);
4040
 
                        if (feof(a))
4041
 
                                return false;
4042
 
                        buf[strlen(buf)-1] = 0;
4043
 
                        j = atoi(buf);
4044
 
                        continue;
4045
 
                }
4046
 
                if (strstr(buf,"ITEM: ATOMS") != 0)
4047
 
                {
4048
 
                        if (j == 0)
4049
 
                        {
4050
 
                                eprintf("CTimeStep::SkipLAMMPS():  \"ITEM: ATOMS\" before \"ITEM: NUMBER OF ATOMS\".\n");
4051
 
                                return false;
4052
 
                        }
4053
 
                        for (i=0;i<j;i++)
4054
 
                        {
4055
 
                                fgets_bin(buf,256,a);
4056
 
                                if (feof(a))
4057
 
                                        return false;
4058
 
                        }
4059
 
                        break;
4060
 
                }
4061
 
        }
4062
 
        return true;
4063
 
}
4064
 
 
4065
 
 
4066
 
bool CTimeStep::ReadDLPOLY(FILE *a, bool needinfo)
4067
 
{
4068
 
        int i;
4069
 
        char buf[256], obuf[256], *p, *q, *r;
4070
 
        float x, y, z;
4071
 
 
4072
 
        m_vaCoords.RemoveAll_KeepSize();
4073
 
        for (i=0;i<m_paLabels.GetSize();i++)
4074
 
                delete[] (char*)m_paLabels[i];
4075
 
        m_paLabels.RemoveAll();
4076
 
        m_iGesAtomCount = 0;
4077
 
        while (true)
4078
 
        {
4079
 
                fgets_bin(buf,256,a);
4080
 
                if (feof(a))
4081
 
                        return false;
4082
 
                if (strlen(buf) == 0)
4083
 
                        continue;
4084
 
                buf[strlen(buf)-1] = 0;
4085
 
                strcpy(obuf,buf);
4086
 
 
4087
 
                if (strstr(buf,"timestep") != 0)
4088
 
                {
4089
 
                        p = &buf[0];
4090
 
                        while (*p == ' ')
4091
 
                                p++;
4092
 
                        q = p;
4093
 
                        while ((*q != ' ') && (*q != 0))
4094
 
                                q++;
4095
 
                        if (*q == 0)
4096
 
                        {
4097
 
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line A: \"%s\"\n",obuf);
4098
 
                                return false;
4099
 
                        }
4100
 
                        *q = 0;
4101
 
                        p=q+1;
4102
 
 
4103
 
                        while (*p == ' ')
4104
 
                                p++;
4105
 
                        q = p;
4106
 
                        while ((*q != ' ') && (*q != 0))
4107
 
                                q++;
4108
 
                        if (*q == 0)
4109
 
                        {
4110
 
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line B: \"%s\"\n",obuf);
4111
 
                                return false;
4112
 
                        }
4113
 
                        *q = 0;
4114
 
                        p=q+1;
4115
 
 
4116
 
                        while (*p == ' ')
4117
 
                                p++;
4118
 
                        q = p;
4119
 
                        while ((*q != ' ') && (*q != 0))
4120
 
                                q++;
4121
 
                        if (*q == 0)
4122
 
                        {
4123
 
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line C: \"%s\"\n",obuf);
4124
 
                                return false;
4125
 
                        }
4126
 
                        *q = 0;
4127
 
                        m_iGesAtomCount = atoi(p);
4128
 
 
4129
 
                        if (g_bNPT)
4130
 
                        {
4131
 
                                for (i=0;i<3;i++)
4132
 
                                {
4133
 
                                        fgets_bin(buf,256,a);
4134
 
                                        if (feof(a))
4135
 
                                                return false;
4136
 
 
4137
 
                                        p = &buf[0];
4138
 
 
4139
 
                                        while (*p == ' ')
4140
 
                                                p++;
4141
 
                                        q = p;
4142
 
                                        while ((*q != ' ') && (*q != 0))
4143
 
                                                q++;
4144
 
                                        if (*q == 0)
4145
 
                                        {
4146
 
                                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line D: \"%s\"\n",obuf);
4147
 
                                                return false;
4148
 
                                        }
4149
 
                                        *q = 0;
4150
 
                                        x = atof(p);
4151
 
                                        p = q+1;
4152
 
 
4153
 
                                        while (*p == ' ')
4154
 
                                                p++;
4155
 
                                        q = p;
4156
 
                                        while ((*q != ' ') && (*q != 0))
4157
 
                                                q++;
4158
 
                                        if (*q == 0)
4159
 
                                        {
4160
 
                                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line E: \"%s\"\n",obuf);
4161
 
                                                return false;
4162
 
                                        }
4163
 
                                        *q = 0;
4164
 
                                        y = atof(p);
4165
 
                                        p = q+1;
4166
 
 
4167
 
                                        while (*p == ' ')
4168
 
                                                p++;
4169
 
                                        q = p;
4170
 
                                        while ((*q != ' ') && (*q != 0))
4171
 
                                                q++;
4172
 
                                        *q = 0;
4173
 
                                        z = atof(p);
4174
 
 
4175
 
                                        switch(i)
4176
 
                                        {
4177
 
                                                case 0:
4178
 
                                                        if ((y != 0) || (z != 0))
4179
 
                                                        {
4180
 
                                                                eprintf("\nCTimeStep::ReadDLPOLY(): X: Only orthorhombic cells are supported.\n");
4181
 
                                                                return false;
4182
 
                                                        }
4183
 
                                                        g_fBoxX = x*100.0f;
4184
 
                                                        break;
4185
 
 
4186
 
                                                case 1:
4187
 
                                                        if ((x != 0) || (z != 0))
4188
 
                                                        {
4189
 
                                                                eprintf("\nCTimeStep::ReadDLPOLY(): Y: Only orthorhombic cells are supported.\n");
4190
 
                                                                return false;
4191
 
                                                        }
4192
 
                                                        g_fBoxY = y*100.0f;
4193
 
                                                        break;
4194
 
 
4195
 
                                                case 2:
4196
 
                                                        if ((x != 0) || (y != 0))
4197
 
                                                        {
4198
 
                                                                eprintf("\nCTimeStep::ReadDLPOLY(): Z: Only orthorhombic cells are supported.\n");
4199
 
                                                                return false;
4200
 
                                                        }
4201
 
                                                        g_fBoxZ = z*100.0f;
4202
 
                                                        break;
4203
 
 
4204
 
                                        }
4205
 
                                }
4206
 
                        } else
4207
 
                        {
4208
 
                                fgets_bin(buf,256,a);
4209
 
                                fgets_bin(buf,256,a);
4210
 
                                fgets_bin(buf,256,a);
4211
 
                        }
4212
 
 
4213
 
                        if (m_iGesAtomCount == 0)
4214
 
                        {
4215
 
                                eprintf("CTimeStep::ReadDLPOLY(): Error: Atom count is 0.\n");
4216
 
                                return false;
4217
 
                        }
4218
 
 
4219
 
                        if (needinfo)
4220
 
                        {
4221
 
                                if (g_bDoubleBox)
4222
 
                                        m_paLabels.SetSize(m_iGesAtomCount*g_iDoubleBoxFactor);
4223
 
                                                else m_paLabels.SetSize(m_iGesAtomCount);
4224
 
                        }
4225
 
 
4226
 
                        for (i=0;i<(int)m_iGesAtomCount;i++)
4227
 
                        {
4228
 
_readagain:
4229
 
                                fgets_bin(buf,256,a);
4230
 
                                if (feof(a))
4231
 
                                        return false;
4232
 
 
4233
 
                                p = &buf[0];
4234
 
                                while (*p == ' ')
4235
 
                                        p++;
4236
 
                                q = p;
4237
 
 
4238
 
                                // Numer at beginning of line: Likely velocities. Skip that line
4239
 
                                if ((*p == '-') || (*p == '.') || ((*p >= '0') && (*p <= '9')))
4240
 
                                        goto _readagain;
4241
 
 
4242
 
                                while ((*q != ' ') && (*q != 0))
4243
 
                                        q++;
4244
 
                                if (*q == 0)
4245
 
                                {
4246
 
                                        eprintf("\nCTimeStep::ReadDLPOLY(): %d: Incomplete line F: \"%s\"\n",i+1,obuf);
4247
 
                                        return false;
4248
 
                                }
4249
 
                                *q = 0;
4250
 
 
4251
 
                                if (needinfo)
4252
 
                                {
4253
 
                                        if (strlen(p) > 7)
4254
 
                                        {
4255
 
                                                eprintf("\nCTimeStep::ReadDLPOLY(): \"%s\" - maximum length for atom labels is 7 chars; truncating.\n",p);
4256
 
                                                p[7] = 0;
4257
 
                                        }
4258
 
 
4259
 
                                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
4260
 
                                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
4261
 
                                        
4262
 
                                        strcpy(r,p);
4263
 
                                        m_paLabels[i] = r;
4264
 
                                }
4265
 
 
4266
 
                                fgets_bin(buf,256,a);
4267
 
                                if (feof(a))
4268
 
                                        return false;
4269
 
 
4270
 
                                p = &buf[0];
4271
 
 
4272
 
                                while (*p == ' ')
4273
 
                                        p++;
4274
 
                                q = p;
4275
 
                                while ((*q != ' ') && (*q != 0))
4276
 
                                        q++;
4277
 
                                if (*q == 0)
4278
 
                                {
4279
 
                                        eprintf("\nCTimeStep::ReadDLPOLY(): %d: Incomplete line G: \"%s\"\n",i+1,obuf);
4280
 
                                        return false;
4281
 
                                }
4282
 
                                *q = 0;
4283
 
                                x = atof(p)*100.0f;
4284
 
                                p = q+1;
4285
 
 
4286
 
                                while (*p == ' ')
4287
 
                                        p++;
4288
 
                                q = p;
4289
 
                                while ((*q != ' ') && (*q != 0))
4290
 
                                        q++;
4291
 
                                if (*q == 0)
4292
 
                                {
4293
 
                                        eprintf("\nCTimeStep::ReadDLPOLY(): %d: Incomplete line H: \"%s\"\n",i+1,obuf);
4294
 
                                        return false;
4295
 
                                }
4296
 
                                *q = 0;
4297
 
                                y = atof(p)*100.0f;
4298
 
                                p = q+1;
4299
 
 
4300
 
                                while (*p == ' ')
4301
 
                                        p++;
4302
 
                                q = p;
4303
 
                                while ((*q != ' ') && (*q != 0))
4304
 
                                        q++;
4305
 
                                *q = 0;
4306
 
                                z = atof(p)*100.0f;
4307
 
 
4308
 
                                m_vaCoords.Add(CxVector3(x,y,z));
4309
 
                        }
4310
 
                        break;
4311
 
                }
4312
 
        }
4313
 
        return true;
4314
 
}
4315
 
 
4316
 
 
4317
 
bool CTimeStep::SkipDLPOLY(FILE *a)
4318
 
{
4319
 
        int i, j;
4320
 
        char buf[256], obuf[256], *p, *q;
4321
 
 
4322
 
        while (true)
4323
 
        {
4324
 
                fgets_bin(buf,256,a);
4325
 
                if (feof(a))
4326
 
                        return false;
4327
 
                if (strlen(buf) == 0)
4328
 
                        continue;
4329
 
                buf[strlen(buf)-1] = 0;
4330
 
                strcpy(obuf,buf);
4331
 
 
4332
 
                if (strstr(buf,"timestep") != 0)
4333
 
                {
4334
 
                        p = &buf[0];
4335
 
                        while (*p == ' ')
4336
 
                                p++;
4337
 
                        q = p;
4338
 
                        while ((*q != ' ') && (*q != 0))
4339
 
                                q++;
4340
 
                        if (*q == 0)
4341
 
                        {
4342
 
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line A: \"%s\"\n",obuf);
4343
 
                                return false;
4344
 
                        }
4345
 
                        *q = 0;
4346
 
                        p=q+1;
4347
 
 
4348
 
                        while (*p == ' ')
4349
 
                                p++;
4350
 
                        q = p;
4351
 
                        while ((*q != ' ') && (*q != 0))
4352
 
                                q++;
4353
 
                        if (*q == 0)
4354
 
                        {
4355
 
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line B: \"%s\"\n",obuf);
4356
 
                                return false;
4357
 
                        }
4358
 
                        *q = 0;
4359
 
                        p=q+1;
4360
 
 
4361
 
                        while (*p == ' ')
4362
 
                                p++;
4363
 
                        q = p;
4364
 
                        while ((*q != ' ') && (*q != 0))
4365
 
                                q++;
4366
 
                        if (*q == 0)
4367
 
                        {
4368
 
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line C: \"%s\"\n",obuf);
4369
 
                                return false;
4370
 
                        }
4371
 
                        *q = 0;
4372
 
                        j = atoi(p);
4373
 
 
4374
 
                        fgets_bin(buf,256,a);
4375
 
                        fgets_bin(buf,256,a);
4376
 
                        fgets_bin(buf,256,a);
4377
 
 
4378
 
                        if (j == 0)
4379
 
                        {
4380
 
                                eprintf("CTimeStep::ReadDLPOLY(): Error: Atom count is 0.\n");
4381
 
                                return false;
4382
 
                        }
4383
 
 
4384
 
                        for (i=0;i<j;i++)
4385
 
                        {
4386
 
                                fgets_bin(buf,256,a);
4387
 
                                fgets_bin(buf,256,a);
4388
 
                                if (feof(a))
4389
 
                                        return false;
4390
 
                        }
4391
 
                        break;
4392
 
                }
4393
 
        }
4394
 
        return true;
4395
 
}
4396
 
 
4397
 
 
4398
 
bool CTimeStep::ReadMol2(FILE *a, bool needinfo)
4399
 
{
4400
 
        int i;
4401
 
        char buf[256], obuf[256], *p, *q, *r;
4402
 
        float x, y, z;
4403
 
 
4404
 
        fgets_bin(buf,256,a);
4405
 
        fgets_bin(buf,256,a);
4406
 
        fgets_bin(buf,256,a);
4407
 
        p = buf;
4408
 
        while (*p == ' ')
4409
 
                p++;
4410
 
        q = p;
4411
 
        while ((*q != ' ') && (*q != 0))
4412
 
                q++;
4413
 
        *q = 0;
4414
 
        m_iGesAtomCount = atoi(p);
4415
 
        
4416
 
        if (needinfo)
4417
 
        {
4418
 
                m_vaCoords.RemoveAll_KeepSize();
4419
 
                for (i=0;i<m_paLabels.GetSize();i++)
4420
 
                        delete[] (char*)m_paLabels[i];
4421
 
                m_paLabels.RemoveAll();
4422
 
                m_paLabels.SetSize(m_iGesAtomCount);
4423
 
                for (i=0;i<m_paMol2Types.GetSize();i++)
4424
 
                        delete[] (char*)m_paMol2Types[i];
4425
 
                m_paMol2Types.RemoveAll();
4426
 
                m_paMol2Types.SetSize(m_iGesAtomCount);
4427
 
        }
4428
 
        fgets_bin(buf,256,a);
4429
 
        fgets_bin(buf,256,a);
4430
 
        fgets_bin(buf,256,a);
4431
 
        fgets_bin(buf,256,a);
4432
 
        fgets_bin(buf,256,a);
4433
 
 
4434
 
        for (i=0;i<(long)m_iGesAtomCount;i++)
4435
 
        {
4436
 
                fgets_bin(buf,256,a);
4437
 
                if (feof(a))
4438
 
                        return false;
4439
 
                buf[strlen(buf)-1] = 0;
4440
 
                strcpy(obuf,buf);
4441
 
//              mprintf("  \"%s\"\n",buf);
4442
 
                p = buf;
4443
 
                while (*p == ' ')
4444
 
                        p++;
4445
 
                while ((*p != ' ') && (*p != 0))
4446
 
                        p++;
4447
 
                while (*p == ' ')
4448
 
                        p++;
4449
 
                q = p;
4450
 
                while (isalpha(*q) || (*q == '_'))
4451
 
                        q++;
4452
 
                if (needinfo)
4453
 
                {
4454
 
                        *q = 0;
4455
 
                        if (strlen(p) > 7)
4456
 
                        {
4457
 
                                eprintf("\nCTimeStep::ReadMol2(): \"%s\" - maximum length for atom labels is 7 chars; truncating.\n",p);
4458
 
                                p[7] = 0;
4459
 
                        }
4460
 
 
4461
 
                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
4462
 
                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
4463
 
                        
4464
 
                        strcpy(r,p);
4465
 
                        m_paLabels[i] = r;
4466
 
                }
4467
 
                p = q+1;
4468
 
                while ((*p != ' ') && (*p != 0))
4469
 
                        p++;
4470
 
                while (*p == ' ')
4471
 
                        p++;
4472
 
 
4473
 
                q = strchr(p,' ');
4474
 
                if (q == NULL)
4475
 
                {
4476
 
                        eprintf("\nCTimeStep::ReadMol2(): Error 1. %d. \"%s\".",i+1,obuf);
4477
 
                        return false;
4478
 
                }
4479
 
                *q = 0;
4480
 
                x = (float)atof(p) * 100.0f;
4481
 
                p = q+1;
4482
 
                while (*p == ' ')
4483
 
                        p++;
4484
 
 
4485
 
                q = strchr(p,' ');
4486
 
                if (q == NULL)
4487
 
                {
4488
 
                        eprintf("\nCTimeStep::ReadMol2(): Error 2. %d. \"%s\".",i+1,obuf);
4489
 
                        return false;
4490
 
                }
4491
 
                *q = 0;
4492
 
                y = (float)atof(p) * 100.0f;
4493
 
                p = q+1;
4494
 
                while (*p == ' ')
4495
 
                        p++;
4496
 
 
4497
 
                q = strchr(p,' ');
4498
 
                if (q == NULL)
4499
 
                {
4500
 
                        eprintf("\nCTimeStep::ReadMol2(): Error 3. %d. \"%s\".",i+1,obuf);
4501
 
                        return false;
4502
 
                }
4503
 
                *q = 0;
4504
 
                z = (float)atof(p) * 100.0f;
4505
 
                m_vaCoords.Add(CxVector3(x,y,z));
4506
 
 
4507
 
                p = q+1;
4508
 
                while (*p == ' ')
4509
 
                        p++;
4510
 
                q = p;
4511
 
                while ((*q != ' ') && (*q != 0))
4512
 
                        q++;
4513
 
                if (needinfo)
4514
 
                {
4515
 
                        *q = 0;
4516
 
 
4517
 
                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
4518
 
                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
4519
 
                        
4520
 
                        strcpy(r,p);
4521
 
                        m_paMol2Types[i] = r;
4522
 
                }
4523
 
/*              mprintf("  X=%f, Y=%f, Z=%f",x,y,z);
4524
 
                if (needinfo)
4525
 
                        mprintf(", A=%s, B=%s",(char*)m_paLabels[i],(char*)m_paMol2Types[i]);
4526
 
                mprintf("\n");*/
4527
 
        }
4528
 
        m_iGesAtomCount = m_vaCoords.GetSize();
4529
 
 
4530
 
        return true;
4531
 
}
4532
 
 
4533
 
 
4534
 
bool CTimeStep::SkipMol2(FILE *a)
4535
 
{
4536
 
        int i;
4537
 
        char buf[256];
4538
 
 
4539
 
        fgets_bin(buf,256,a);
4540
 
        fgets_bin(buf,256,a);
4541
 
        fgets_bin(buf,256,a);
4542
 
        fgets_bin(buf,256,a);
4543
 
        fgets_bin(buf,256,a);
4544
 
        fgets_bin(buf,256,a);
4545
 
        fgets_bin(buf,256,a);
4546
 
        fgets_bin(buf,256,a);
4547
 
 
4548
 
        for (i=0;i<(long)m_iGesAtomCount;i++)
4549
 
        {
4550
 
                fgets_bin(buf,256,a);
4551
 
                if (feof(a))
4552
 
                        return false;
4553
 
        }
4554
 
 
4555
 
        return true;
4556
 
}
4557
 
 
4558
 
 
4559
 
void CTimeStep::CalcMinMax()
4560
 
{
4561
 
        int z;
4562
 
 
4563
 
        m_vMin[0] = 1E20f;
4564
 
        m_vMin[1] = 1E20f;
4565
 
        m_vMin[2] = 1E20f;
4566
 
        m_vMax[0] = -1E20f;
4567
 
        m_vMax[1] = -1E20f;
4568
 
        m_vMax[2] = -1E20f;
4569
 
 
4570
 
        for (z=0;z<(long)m_iGesAtomCount;z++)
4571
 
        {
4572
 
                if (m_vMin[0] > m_vaCoords[z][0])
4573
 
                        m_vMin[0] = m_vaCoords[z][0];
4574
 
                if (m_vMin[1] > m_vaCoords[z][1])
4575
 
                        m_vMin[1] = m_vaCoords[z][1];
4576
 
                if (m_vMin[2] > m_vaCoords[z][2])
4577
 
                        m_vMin[2] = m_vaCoords[z][2];
4578
 
                if (m_vMax[0] < m_vaCoords[z][0])
4579
 
                        m_vMax[0] = m_vaCoords[z][0];
4580
 
                if (m_vMax[1] < m_vaCoords[z][1])
4581
 
                        m_vMax[1] = m_vaCoords[z][1];
4582
 
                if (m_vMax[2] < m_vaCoords[z][2])
4583
 
                        m_vMax[2] = m_vaCoords[z][2];
4584
 
        }
4585
 
}
4586
 
 
4587
 
 
4588
 
void CTimeStep::WriteMol2(FILE *a)
4589
 
{
4590
 
        int z, z2, z3, z4, ti, c, mc;
4591
 
        CMolecule *m;
4592
 
        CSingleMolecule *sm;
4593
 
        int bonds;
4594
 
        int *tpi;
4595
 
        char *cc;
4596
 
 
4597
 
        bonds = 0;
4598
 
        for (z=0;z<g_oaSingleMolecules.GetSize();z++)
4599
 
                bonds += ((CSingleMolecule*)g_oaSingleMolecules[z])->m_oaBonds.GetSize();
4600
 
 
4601
 
        try { tpi = new int[g_iGesAtomCount]; } catch(...) { tpi = NULL; }
4602
 
        if (tpi == NULL) NewException((double)g_iGesAtomCount*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
4603
 
        
4604
 
        mfprintf(a," @<TRIPOS>MOLECULE\n");
4605
 
        mfprintf(a,"MOL\n");
4606
 
        mfprintf(a,"    %d    %d     %d  0  0\n",g_iGesAtomCount,bonds,g_oaSingleMolecules.GetSize());
4607
 
        mfprintf(a," SMALL\n");
4608
 
        mfprintf(a,"resp\n\n\n");
4609
 
        mfprintf(a," @<TRIPOS>ATOM\n");
4610
 
        c = 0;
4611
 
        mc = 0;
4612
 
        if (m_faCharge.GetSize() != g_iGesAtomCount)
4613
 
        {
4614
 
                m_faCharge.SetSize(g_iGesAtomCount);
4615
 
                for (z=0;z<g_iGesAtomCount;z++)
4616
 
                        m_faCharge[z] = 0;
4617
 
        }
4618
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
4619
 
        {
4620
 
                m = (CMolecule*)g_oaMolecules[z];
4621
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
4622
 
                {
4623
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
4624
 
                        mc++;
4625
 
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
4626
 
                        {
4627
 
                                if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
4628
 
                                        continue;
4629
 
                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
4630
 
                                {
4631
 
                                        ti = ((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4);
4632
 
                                        if (m_paMol2Types.GetSize() != 0)
4633
 
                                                cc = (char*)m_paMol2Types[ti];
4634
 
                                                        else cc = ((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName;
4635
 
                                        tpi[ti] = c++;
4636
 
                                        mfprintf(a,"  %6d  %2s  % 11.4f  % 11.4f  % 11.4f  %2s  %4d  MOL  % 8.4f\n",c,((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0,m_vaCoords[ti][1]/100.0,m_vaCoords[ti][2]/100.0,cc,mc,m_faCharge[ti]);
4637
 
                                }
4638
 
                        }
4639
 
                }
4640
 
        }
4641
 
        mfprintf(a," @<TRIPOS>BOND\n");
4642
 
        c = 0;
4643
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
4644
 
        {
4645
 
                m = (CMolecule*)g_oaMolecules[z];
4646
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
4647
 
                {
4648
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
4649
 
                        for (z3=0;z3<sm->m_oaBonds.GetSize();z3++)
4650
 
                                mfprintf(a,"  %6d  %6d  %6d  1\n",++c,tpi[((CMolBond*)sm->m_oaBonds[z3])->m_iAtomOffset[0]]+1,tpi[((CMolBond*)sm->m_oaBonds[z3])->m_iAtomOffset[1]]+1);
4651
 
                }
4652
 
        }
4653
 
        mfprintf(a," @<TRIPOS>SUBSTRUCTURE\n");
4654
 
        c = 0;
4655
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
4656
 
        {
4657
 
                m = (CMolecule*)g_oaMolecules[z];
4658
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
4659
 
                {
4660
 
                        mfprintf(a,"  %4d  MOL  %4d  TEMP              0 ****  ****    0 ROOT\n",c+1,c+1);
4661
 
                        c++;
4662
 
                }
4663
 
        }
4664
 
        delete[] tpi;
4665
 
}
4666
 
 
4667
 
 
4668
 
void CTimeStep::ReadCellVector(FILE *a)
4669
 
{
4670
 
        char buf[256], obuf[256];
4671
 
        char *p, *q;
4672
 
        float tf;
4673
 
 
4674
 
        fgets(buf,256,a);
4675
 
        if (feof(a))
4676
 
        {
4677
 
                eprintf("\nReadCellVector: End of file.\n");
4678
 
                eprintf("Your cell vector text file is too short.\n");
4679
 
                return;
4680
 
        }
4681
 
        if (strlen(buf) == 0)
4682
 
        {
4683
 
                eprintf("\nReadCellVector: Empty line.\n");
4684
 
                return;
4685
 
        }
4686
 
        buf[strlen(buf)-1] = 0;
4687
 
        strcpy(obuf,buf);
4688
 
//      mprintf(GREY,"\nReadCellVector: \"%s\".\n",buf);
4689
 
        p = buf;
4690
 
        while ((!isnumeric(*p)) && (*p != 0))
4691
 
                p++;
4692
 
        if (*p == 0)
4693
 
        {
4694
 
                eprintf("\nReadCellVector: Incomplete line (1) \"%s\".\n",obuf);
4695
 
                return;
4696
 
        }
4697
 
        q = p;
4698
 
        while (isnumeric(*q))
4699
 
                q++;
4700
 
        if (*q == 0)
4701
 
        {
4702
 
                eprintf("\nReadCellVector: Incomplete line (2) \"%s\".\n",obuf);
4703
 
                return;
4704
 
        }
4705
 
        *q = 0;
4706
 
        tf = (float)(atof(p)*100.0);
4707
 
        if (tf <= 0)
4708
 
        {
4709
 
                eprintf("\nReadCellVector: Cell vectors need to be > 0 (X) \"%s\".\n",obuf);
4710
 
                return;
4711
 
        }
4712
 
        g_fBoxX = tf;
4713
 
 
4714
 
        p = q+1;
4715
 
        while ((!isnumeric(*p)) && (*p != 0))
4716
 
                p++;
4717
 
        if (*p == 0)
4718
 
        {
4719
 
                eprintf("\nReadCellVector: Incomplete line (3) \"%s\".\n",obuf);
4720
 
                return;
4721
 
        }
4722
 
        q = p;
4723
 
        while (isnumeric(*q))
4724
 
                q++;
4725
 
        if (*q == 0)
4726
 
        {
4727
 
                eprintf("\nReadCellVector: Incomplete line (4) \"%s\".\n",obuf);
4728
 
                return;
4729
 
        }
4730
 
        *q = 0;
4731
 
        tf = (float)(atof(p)*100.0);
4732
 
        if (tf <= 0)
4733
 
        {
4734
 
                eprintf("\nReadCellVector: Cell vectors need to be > 0 (Y) \"%s\".\n",obuf);
4735
 
                return;
4736
 
        }
4737
 
        g_fBoxY = tf;
4738
 
        p = q+1;
4739
 
 
4740
 
        while ((!isnumeric(*p)) && (*p != 0))
4741
 
                p++;
4742
 
        if (*p == 0)
4743
 
        {
4744
 
                eprintf("\nReadCellVector: Incomplete line (5) \"%s\".\n",obuf);
4745
 
                return;
4746
 
        }
4747
 
        q = p;
4748
 
        while (isnumeric(*q))
4749
 
                q++;
4750
 
        if (*q != 0)
4751
 
                *q = 0;
4752
 
        tf = (float)(atof(p)*100.0);
4753
 
        if (tf <= 0)
4754
 
        {
4755
 
                eprintf("\nReadCellVector: Cell vectors need to be > 0 (Z) \"%s\".\n",obuf);
4756
 
                return;
4757
 
        }
4758
 
        g_fBoxZ = tf;
4759
 
 
4760
 
//      mprintf(GREY," --> %f %f %f\n",g_fBoxX,g_fBoxY,g_fBoxZ);
4761
 
}
4762
 
 
4763
 
 
4764
 
void CTimeStep::CenterCOM()
4765
 
{
4766
 
        CxVector3 vc;
4767
 
        double m;
4768
 
        int z;
4769
 
 
4770
 
        vc = CxVector3(0,0,0);
4771
 
        m = 0;
4772
 
        for (z=0;z<g_iGesAtomCount;z++)
4773
 
        {
4774
 
                if (g_bWannier)
4775
 
                        if (g_baAtomIndex[z] == g_iWannierAtomType)
4776
 
                                continue;
4777
 
                vc += m_vaCoords[z] * ((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_pElement->m_fMass;
4778
 
                m += ((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_pElement->m_fMass;
4779
 
        }
4780
 
        vc /= m;
4781
 
        for (z=0;z<g_iGesAtomCount;z++)
4782
 
                m_vaCoords[z] -= vc;
4783
 
}
4784
 
 
4785
 
 
4786
 
float CTimeStep::FoldedDistance(int i1, int i2)
4787
 
{
4788
 
        CxVector3 t;
4789
 
 
4790
 
        t = m_vaCoords[i2]-m_vaCoords[i1];
4791
 
 
4792
 
        if (g_bPeriodicX)
4793
 
        {
4794
 
                while (t[0] < -g_fBoxX/2) t[0] += g_fBoxX;
4795
 
                while (t[0] >= g_fBoxX/2) t[0] -= g_fBoxX;
4796
 
        }
4797
 
 
4798
 
        if (g_bPeriodicY)
4799
 
        {
4800
 
                while (t[1] < -g_fBoxY/2) t[1] += g_fBoxY;
4801
 
                while (t[1] >= g_fBoxY/2) t[1] -= g_fBoxY;
4802
 
        }
4803
 
 
4804
 
        if (g_bPeriodicZ)
4805
 
        {
4806
 
                while (t[2] < -g_fBoxZ/2) t[2] += g_fBoxZ;
4807
 
                while (t[2] >= g_fBoxZ/2) t[2] -= g_fBoxZ;
4808
 
        }
4809
 
 
4810
 
        return t.GetLength();
4811
 
}
4812
 
 
4813
 
 
4814
 
void CTimeStep::FoldAtomsPositive()
4815
 
{
4816
 
        BTIN;
4817
 
        int z;
4818
 
 
4819
 
        if (!g_bPeriodic)
4820
 
                return;
4821
 
 
4822
 
        for (z=0;z<g_iGesVirtAtomCount;z++)
4823
 
        {
4824
 
                if (g_bPeriodicX)
4825
 
                {
4826
 
                        while (m_vaCoords[z][0] < 0) m_vaCoords[z][0] += g_fBoxX;
4827
 
                        while (m_vaCoords[z][0] >= g_fBoxX) m_vaCoords[z][0] -= g_fBoxX;
4828
 
                }
4829
 
 
4830
 
                if (g_bPeriodicX)
4831
 
                {
4832
 
                        while (m_vaCoords[z][1] < 0) m_vaCoords[z][1] += g_fBoxY;
4833
 
                        while (m_vaCoords[z][1] >= g_fBoxY) m_vaCoords[z][1] -= g_fBoxY;
4834
 
                }
4835
 
 
4836
 
                if (g_bPeriodicX)
4837
 
                {
4838
 
                        while (m_vaCoords[z][2] < 0) m_vaCoords[z][2] += g_fBoxZ;
4839
 
                        while (m_vaCoords[z][2] >= g_fBoxZ) m_vaCoords[z][2] -= g_fBoxZ;
4840
 
                }
4841
 
        }
4842
 
        BTOUT; 
4843
 
}
4844
 
 
4845
 
 
4846
 
void CTimeStep::WritePOV(const char *s)
4847
 
{
4848
 
        FILE *b;
4849
 
        CMolecule *m;
4850
 
        CSingleMolecule *sm;
4851
 
        CElement *el, *el2;
4852
 
        int z, z2, z3, z4, o, o2;
4853
 
        CxVector3 vec1, vec2, vec3, vec1b, vec2b, vec3b, vecA, vecB, vecC, vecD;
4854
 
        CMolBond *mb;
4855
 
        CxVector3 cam;
4856
 
//      float cr, cg, cb;
4857
 
 
4858
 
        b = OpenFileWrite(s,true);
4859
 
 
4860
 
        mfprintf(b,"// Written by TRAVIS\n");
4861
 
        mfprintf(b,"// See http://www.travis-analyzer.de\n\n");
4862
 
        mfprintf(b,"#version 3.6;\n");
4863
 
        mfprintf(b,"\n");
4864
 
 
4865
 
        mfprintf(b,"/**** Atoms ****/\n");
4866
 
 
4867
 
        mfprintf(b,"#declare atom_draw          = true;\n");
4868
 
        mfprintf(b,"#declare atom_r             = 0.65;\n");
4869
 
        mfprintf(b,"#declare atom_specular      = 0.7;\n");
4870
 
        mfprintf(b,"#declare atom_reflect       = 0;\n");
4871
 
        mfprintf(b,"#declare atom_ambient       = 0.2;\n");
4872
 
        mfprintf(b,"#declare atom_diffuse       = 0.7;\n");
4873
 
        mfprintf(b,"//#declare atom_color         = < 1.0, 1.0, 1.0, 0, 0 >;\n");
4874
 
        mfprintf(b,"//#declare atom_trans         = 0.7;\n");
4875
 
 
4876
 
        mfprintf(b,"\n");
4877
 
 
4878
 
        mfprintf(b,"#declare atom_draw_halo1      = true;\n");
4879
 
        mfprintf(b,"#declare atom_r_halo1         = 0.008;\n");
4880
 
        mfprintf(b,"#declare atom_d_halo1         = 0.0125;\n");
4881
 
        mfprintf(b,"#declare atom_color_halo1     = < 0, 0, 0, 0, 0 >;\n");
4882
 
        mfprintf(b,"#declare atom_specular_halo1  = 0;\n");
4883
 
        mfprintf(b,"#declare atom_reflect_halo1   = 0;\n");
4884
 
        mfprintf(b,"#declare atom_ambient_halo1   = 1.0;\n");
4885
 
        mfprintf(b,"#declare atom_diffuse_halo1   = 0;\n");
4886
 
 
4887
 
        mfprintf(b,"\n");
4888
 
 
4889
 
        mfprintf(b,"#declare atom_draw_halo2      = true;\n");
4890
 
        mfprintf(b,"#declare atom_r_halo2         = 0.003;\n");
4891
 
        mfprintf(b,"#declare atom_d_halo2         = 0.01875;\n");
4892
 
        mfprintf(b,"#declare atom_color_halo2     = < 1, 1, 1, 0, 0 >;\n");
4893
 
        mfprintf(b,"#declare atom_specular_halo2  = 0;\n");
4894
 
        mfprintf(b,"#declare atom_reflect_halo2   = 0;\n");
4895
 
        mfprintf(b,"#declare atom_ambient_halo2   = 1.0;\n");
4896
 
        mfprintf(b,"#declare atom_diffuse_halo2   = 0;\n");
4897
 
 
4898
 
        mfprintf(b,"\n");
4899
 
 
4900
 
        mfprintf(b,"#declare atom_draw_halo3      = true;\n");
4901
 
        mfprintf(b,"#declare atom_r_halo3         = 0.003;\n");
4902
 
        mfprintf(b,"#declare atom_d_halo3         = 0.025;\n");
4903
 
        mfprintf(b,"#declare atom_color_halo3     = < 1, 1, 1, 0, 0.5 >;\n");
4904
 
        mfprintf(b,"#declare atom_specular_halo3  = 0;\n");
4905
 
        mfprintf(b,"#declare atom_reflect_halo3   = 0;\n");
4906
 
        mfprintf(b,"#declare atom_ambient_halo3   = 1.0;\n");
4907
 
        mfprintf(b,"#declare atom_diffuse_halo3   = 0;\n");
4908
 
 
4909
 
        mfprintf(b,"\n");
4910
 
 
4911
 
        mfprintf(b,"/**** Bonds ****/\n");
4912
 
 
4913
 
        mfprintf(b,"#declare bond_draw        = true;\n");
4914
 
        mfprintf(b,"#declare bond_r           = 0.015;\n");
4915
 
        mfprintf(b,"#declare bond_specular    = 0.7;\n");
4916
 
        mfprintf(b,"#declare bond_reflect     = 0;\n");
4917
 
        mfprintf(b,"#declare bond_ambient     = 0.2;\n");
4918
 
        mfprintf(b,"#declare bond_diffuse     = 0.7;\n");
4919
 
 
4920
 
        mfprintf(b,"\n");
4921
 
 
4922
 
        mfprintf(b,"#declare bond_draw_halo1      = true;\n");
4923
 
        mfprintf(b,"#declare bond_r_halo1         = 0.008;\n");
4924
 
        mfprintf(b,"#declare bond_d_halo1         = 0;\n");
4925
 
        mfprintf(b,"#declare bond_color_halo1     = < 0, 0, 0, 0, 0 >;\n");
4926
 
        mfprintf(b,"#declare bond_specular_halo1  = 0;\n");
4927
 
        mfprintf(b,"#declare bond_reflect_halo1   = 0;\n");
4928
 
        mfprintf(b,"#declare bond_ambient_halo1   = 1.0;\n");
4929
 
        mfprintf(b,"#declare bond_diffuse_halo1   = 0;\n");
4930
 
 
4931
 
        mfprintf(b,"\n");
4932
 
 
4933
 
        mfprintf(b,"#declare bond_draw_halo2      = true;\n");
4934
 
        mfprintf(b,"#declare bond_r_halo2         = 0.003;\n");
4935
 
        mfprintf(b,"#declare bond_d_halo2         = 0.0286;\n");
4936
 
        mfprintf(b,"#declare bond_color_halo2     = < 1, 1, 1, 0, 0 >;\n");
4937
 
        mfprintf(b,"#declare bond_specular_halo2  = 0;\n");
4938
 
        mfprintf(b,"#declare bond_reflect_halo2   = 0;\n");
4939
 
        mfprintf(b,"#declare bond_ambient_halo2   = 1.0;\n");
4940
 
        mfprintf(b,"#declare bond_diffuse_halo2   = 0;\n");
4941
 
 
4942
 
        mfprintf(b,"\n");
4943
 
 
4944
 
        mfprintf(b,"#declare bond_draw_halo3      = true;\n");
4945
 
        mfprintf(b,"#declare bond_r_halo3         = 0.003;\n");
4946
 
        mfprintf(b,"#declare bond_d_halo3         = 0.0333;\n");
4947
 
        mfprintf(b,"#declare bond_color_halo3     = < 1, 1, 1, 0, 0.5 >;\n");
4948
 
        mfprintf(b,"#declare bond_specular_halo3  = 0;\n");
4949
 
        mfprintf(b,"#declare bond_reflect_halo3   = 0;\n");
4950
 
        mfprintf(b,"#declare bond_ambient_halo3   = 1.0;\n");
4951
 
        mfprintf(b,"#declare bond_diffuse_halo3   = 0;\n");
4952
 
 
4953
 
        mfprintf(b,"\n");
4954
 
 
4955
 
        mfprintf(b,"#declare bond_draw_stub       = true;\n");
4956
 
        mfprintf(b,"#declare bond_r_stub          = 0.004;\n");
4957
 
        mfprintf(b,"#declare bond_l_stub          = 0.004;\n");
4958
 
        mfprintf(b,"#declare bond_color_stub      = < 0, 0, 0, 0, 0 >;\n");
4959
 
        mfprintf(b,"#declare bond_specular_stub   = 0;\n");
4960
 
        mfprintf(b,"#declare bond_reflect_stub    = 0;\n");
4961
 
        mfprintf(b,"#declare bond_ambient_stub    = 1.0;\n");
4962
 
        mfprintf(b,"#declare bond_diffuse_stub    = 0;\n");
4963
 
 
4964
 
        mfprintf(b,"\n");
4965
 
 
4966
 
        mfprintf(b,"/**** Element Colors ****/\n");
4967
 
        for (z=0;z<g_oaAtoms.GetSize();z++)
4968
 
        {
4969
 
                if (z == g_iVirtAtomType)
4970
 
                        continue;
4971
 
                el = ((CAtom*)g_oaAtoms[z])->m_pElement;
4972
 
                mfprintf(b,"#declare elem_%s_col   = < %f, %f, %f, 0, 0 >;\n",el->m_sLabel,el->m_iColorR/255.0,el->m_iColorG/255.0,el->m_iColorB/255.0);
4973
 
        }
4974
 
 
4975
 
        mfprintf(b,"\n/**** Element Radii ****/\n");
4976
 
        for (z=0;z<g_oaAtoms.GetSize();z++)
4977
 
        {
4978
 
                if (z == g_iVirtAtomType)
4979
 
                        continue;
4980
 
                el = ((CAtom*)g_oaAtoms[z])->m_pElement;
4981
 
                mfprintf(b,"#declare elem_%s_r  = %f;\n",el->m_sLabel,el->m_fRadius/1000.0);
4982
 
        }
4983
 
        mfprintf(b,"\n");
4984
 
 
4985
 
        cam[0] = 0;
4986
 
        cam[1] = 0;
4987
 
        cam[2] = 40.0;
4988
 
 
4989
 
        mfprintf(b,"global_settings {\n");
4990
 
        mfprintf(b,"  assumed_gamma 1\n");
4991
 
        mfprintf(b,"/*  radiosity {\n");
4992
 
        mfprintf(b,"    pretrace_start 0.08\n");
4993
 
        mfprintf(b,"    pretrace_end   0.04\n");
4994
 
        mfprintf(b,"    count 100\n\n");
4995
 
        mfprintf(b,"    nearest_count 5\n");
4996
 
        mfprintf(b,"    error_bound 0.4\n");
4997
 
        mfprintf(b,"    recursion_limit 1\n\n");
4998
 
        mfprintf(b,"    low_error_factor .5\n");
4999
 
        mfprintf(b,"    gray_threshold 0.0\n");
5000
 
        mfprintf(b,"    minimum_reuse 0.015\n");
5001
 
        mfprintf(b,"    brightness 1\n\n");
5002
 
        mfprintf(b,"    adc_bailout 0.01/2\n");
5003
 
        mfprintf(b,"  }*/\n");
5004
 
        mfprintf(b,"}\n");
5005
 
 
5006
 
        mfprintf(b,"\ncamera {\n");
5007
 
        mfprintf(b,"    location <%f, %f, %f>\n",cam[0],cam[1],cam[2]);
5008
 
        mfprintf(b,"    sky y\n");
5009
 
        mfprintf(b,"    right -0.06*x*image_width/image_height\n");
5010
 
        mfprintf(b,"    up 0.06*y\n");
5011
 
        mfprintf(b,"    look_at <0, 0, 0>\n");
5012
 
        mfprintf(b,"}\n");
5013
 
        mfprintf(b,"\n");
5014
 
 
5015
 
        mfprintf(b,"// Solid background\n");
5016
 
        mfprintf(b,"background { rgb < 0.15, 0.1, 0.3 > }\n");
5017
 
        mfprintf(b,"\n");
5018
 
 
5019
 
        mfprintf(b,"// Gradient background\n");
5020
 
        mfprintf(b,"sky_sphere {\n");
5021
 
        mfprintf(b,"  pigment {\n");
5022
 
        mfprintf(b,"    gradient y\n");
5023
 
        mfprintf(b,"    color_map {\n");
5024
 
        mfprintf(b,"      [ 0 color rgb < 0.05, 0.05, 0.05 > ]\n");
5025
 
        mfprintf(b,"      [ 1 color rgb < 0.20, 0.16, 0.50 > ]\n");
5026
 
        mfprintf(b,"    }\n");
5027
 
        mfprintf(b,"    scale 0.1\n");
5028
 
        mfprintf(b,"    translate -0.05\n");
5029
 
        mfprintf(b,"  }\n");
5030
 
        mfprintf(b,"}\n\n");
5031
 
 
5032
 
        mfprintf(b,"/**** Invisible, only for Radiosity ****/\n");
5033
 
        mfprintf(b,"sphere {\n");
5034
 
        mfprintf(b,"  <0, 0, 0>, 1\n");
5035
 
        mfprintf(b,"  texture {\n");
5036
 
        mfprintf(b,"    pigment {color rgb < 1.0, 1.0, 1.0 > }\n");
5037
 
        mfprintf(b,"    finish { diffuse 0 ambient 1 }\n");
5038
 
        mfprintf(b,"  }\n");
5039
 
        mfprintf(b,"  hollow on\n");
5040
 
        mfprintf(b,"  no_shadow\n");
5041
 
        mfprintf(b,"  no_image\n");
5042
 
        mfprintf(b,"  scale 30000\n");
5043
 
        mfprintf(b,"}\n\n");
5044
 
 
5045
 
        mfprintf(b,"light_source { < -8, 20, 20 > color rgb 0.8 }\n");
5046
 
        mfprintf(b,"//light_source { < 25, 12, 20 > color rgb 0.5 }\n\n");
5047
 
 
5048
 
        mfprintf(b,"#macro m_atom_color(col)\n");
5049
 
        mfprintf(b,"  #ifdef(atom_color)\n");
5050
 
        mfprintf(b,"    atom_color\n");
5051
 
        mfprintf(b,"  #else #if (defined(atom_trans))\n");
5052
 
        mfprintf(b,"    col + < 0, 0, 0, 0, atom_trans >\n");
5053
 
        mfprintf(b,"  #else\n");
5054
 
        mfprintf(b,"    col\n");
5055
 
        mfprintf(b,"  #end #end\n");
5056
 
        mfprintf(b,"#end\n");
5057
 
 
5058
 
        mfprintf(b,"\nunion {\n");
5059
 
 
5060
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
5061
 
        {
5062
 
                m = (CMolecule*)g_oaMolecules[z];
5063
 
 
5064
 
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
5065
 
                {
5066
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
5067
 
 
5068
 
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
5069
 
                        {
5070
 
                                if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
5071
 
                                        continue;
5072
 
 
5073
 
                                el = ((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_pElement;
5074
 
 
5075
 
                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
5076
 
                                {
5077
 
                                        o = ((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4);
5078
 
                                        vec1 = m_vaCoords[o];
5079
 
                                        vec1 /= 1000.0;
5080
 
 
5081
 
                                        mfprintf(b,"#if (atom_draw)\n");
5082
 
                                        mfprintf(b,"  sphere { <%g, %g, %g>, elem_%s_r*atom_r\n",vec1[0],vec1[1],vec1[2],el->m_sLabel);
5083
 
                                        mfprintf(b,"    pigment { rgbft m_atom_color(elem_%s_col) } finish { reflection atom_reflect specular atom_specular ambient atom_ambient diffuse atom_diffuse } }\n",el->m_sLabel);
5084
 
                                        mfprintf(b,"#end\n");
5085
 
 
5086
 
                                        vec2 = cam - vec1;
5087
 
                                        vec2.Normalize();
5088
 
 
5089
 
        //                              if (shadow)
5090
 
                                        {
5091
 
                                                mfprintf(b,"#if (atom_draw_halo1)\n");
5092
 
                                                mfprintf(b,"  disc { < %g - (%g) * atom_d_halo1, %g - (%g) * atom_d_halo1, %g - (%g) * atom_d_halo1 >,\n",vec1[0],vec2[0],vec1[1],vec2[1],vec1[2],vec2[2]);
5093
 
                                                mfprintf(b,"    < %g, %g, %g >, (elem_%s_r * atom_r) + atom_r_halo1, elem_%s_r * atom_r\n",vec2[0],vec2[1],vec2[2],el->m_sLabel,el->m_sLabel);
5094
 
                                                mfprintf(b,"    pigment { rgbft atom_color_halo1 } finish { reflection atom_reflect_halo1 specular atom_specular_halo1 ambient atom_ambient_halo1 diffuse atom_diffuse_halo1 } no_reflection no_radiosity }\n");
5095
 
                                                mfprintf(b,"#end\n");
5096
 
                                        }
5097
 
 
5098
 
        //                              if (halo)
5099
 
                                        {
5100
 
                                                mfprintf(b,"#if (atom_draw_halo2)\n");
5101
 
                                                mfprintf(b,"  disc { < %g - (%g) * atom_d_halo2, %g - (%g) * atom_d_halo2, %g - (%g) * atom_d_halo2 >,\n",vec1[0],vec2[0],vec1[1],vec2[1],vec1[2],vec2[2]);
5102
 
                                                mfprintf(b,"    < %g, %g, %g >, (elem_%s_r * atom_r) + atom_r_halo1 + atom_r_halo2, elem_%s_r * atom_r\n",vec2[0],vec2[1],vec2[2],el->m_sLabel,el->m_sLabel);
5103
 
                                                mfprintf(b,"    pigment { rgbft atom_color_halo2 } finish { reflection atom_reflect_halo2 specular atom_specular_halo2 ambient atom_ambient_halo2 diffuse atom_diffuse_halo2 } no_reflection no_radiosity }\n");
5104
 
                                                mfprintf(b,"#end\n");
5105
 
 
5106
 
                                                mfprintf(b,"#if (atom_draw_halo3)\n");
5107
 
                                                mfprintf(b,"  disc { < %g - (%g) * atom_d_halo3, %g - (%g) * atom_d_halo3, %g - (%g) * atom_d_halo3 >,\n",vec1[0],vec2[0],vec1[1],vec2[1],vec1[2],vec2[2]);
5108
 
                                                mfprintf(b,"    < %g, %g, %g >, (elem_%s_r * atom_r) + atom_r_halo1 + atom_r_halo2 + atom_r_halo3, elem_%s_r * atom_r\n",vec2[0],vec2[1],vec2[2],el->m_sLabel,el->m_sLabel);
5109
 
                                                mfprintf(b,"    pigment { rgbft atom_color_halo3 } finish { reflection atom_reflect_halo3 specular atom_specular_halo3 ambient atom_ambient_halo3 diffuse atom_diffuse_halo3 } no_reflection no_radiosity }\n");
5110
 
                                                mfprintf(b,"#end\n");
5111
 
                                        }
5112
 
                                }
5113
 
                        }
5114
 
 
5115
 
                        for (z3=0;z3<sm->m_oaBonds.GetSize();z3++)
5116
 
                        {
5117
 
                                mb = (CMolBond*)sm->m_oaBonds[z3];
5118
 
                                o = mb->m_iAtomOffset[0];
5119
 
                                o2 = mb->m_iAtomOffset[1];
5120
 
 
5121
 
                                el = ((CAtom*)g_oaAtoms[g_waAtomRealElement[o]])->m_pElement;
5122
 
                                el2 = ((CAtom*)g_oaAtoms[g_waAtomRealElement[o2]])->m_pElement;
5123
 
 
5124
 
                                vec1 = m_vaCoords[o];
5125
 
                                vec1 /= 1000.0;
5126
 
 
5127
 
                                vec2 = m_vaCoords[o2];
5128
 
                                vec2 /= 1000.0;
5129
 
 
5130
 
                                if ((vec1-vec2).GetLength() > 0.3)
5131
 
                                        continue;
5132
 
 
5133
 
                                vec3 = (vec1/el->m_fRadius + vec2/el2->m_fRadius) / (1.0/el->m_fRadius+1.0/el2->m_fRadius);
5134
 
 
5135
 
                                vec3b = vec2 - vec1;
5136
 
                                vec3b.Normalize();
5137
 
 
5138
 
                                mfprintf(b,"#local vec1c = < %g + (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ),\n",vec1[0],vec3b[0],el->m_sLabel,el->m_sLabel,el->m_sLabel,el->m_sLabel);
5139
 
                                mfprintf(b,"  %g + (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ),\n",vec1[1],vec3b[1],el->m_sLabel,el->m_sLabel,el->m_sLabel,el->m_sLabel);
5140
 
                                mfprintf(b,"  %g + (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ) >;\n",vec1[2],vec3b[2],el->m_sLabel,el->m_sLabel,el->m_sLabel,el->m_sLabel);
5141
 
                                mfprintf(b,"#local vec2c = < %g - (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ),\n",vec2[0],vec3b[0],el2->m_sLabel,el2->m_sLabel,el2->m_sLabel,el2->m_sLabel);
5142
 
                                mfprintf(b,"  %g - (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ),\n",vec2[1],vec3b[1],el2->m_sLabel,el2->m_sLabel,el2->m_sLabel,el2->m_sLabel);
5143
 
                                mfprintf(b,"  %g - (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ) >;\n",vec2[2],vec3b[2],el2->m_sLabel,el2->m_sLabel,el2->m_sLabel,el2->m_sLabel);
5144
 
 
5145
 
                                mfprintf(b,"#if (bond_draw)\n");
5146
 
                                mfprintf(b,"  cylinder { < %g, %g, %g >, vec1c, bond_r open\n",vec3[0],vec3[1],vec3[2]);
5147
 
                                mfprintf(b,"    pigment { rgbft m_atom_color(elem_%s_col) } finish { reflection bond_reflect specular bond_specular ambient bond_ambient diffuse bond_diffuse } }\n",el->m_sLabel);
5148
 
                                mfprintf(b,"  cylinder { < %g, %g, %g >, vec2c, bond_r open\n",vec3[0],vec3[1],vec3[2]);
5149
 
                                mfprintf(b,"    pigment { rgbft m_atom_color(elem_%s_col) } finish { reflection bond_reflect specular bond_specular ambient bond_ambient diffuse bond_diffuse } }\n",el2->m_sLabel);
5150
 
                                mfprintf(b,"#end\n");
5151
 
 
5152
 
                                vec3 = cam - (vec1 + vec2) / 2.0;
5153
 
                                vec3.Normalize();
5154
 
 
5155
 
                                vec2b = vec2-vec1;
5156
 
                                vec1b = CrossP(vec3,vec2b);
5157
 
                                vec1b.Normalize();
5158
 
 
5159
 
                                mfprintf(b,"#local vec3  = < %g, %g, %g >;\n",vec3[0],vec3[1],vec3[2]);
5160
 
                                mfprintf(b,"#local vec1b = < %g, %g, %g >;\n",vec1b[0],vec1b[1],vec1b[2]);
5161
 
 
5162
 
//                              if (shadow)
5163
 
                                {
5164
 
                                        mfprintf(b,"#if (bond_draw_halo1)\n");
5165
 
                                        mfprintf(b,"  #local vecA = vec1c + vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo1;\n");
5166
 
                                        mfprintf(b,"  #local vecB = vec2c + vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo1;\n");
5167
 
                                        mfprintf(b,"  #local vecC = vec2c + vec1b * (bond_r) - vec3 * bond_d_halo1;\n");
5168
 
                                        mfprintf(b,"  #local vecD = vec1c + vec1b * (bond_r) - vec3 * bond_d_halo1;\n");
5169
 
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
5170
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo1 } finish { reflection bond_reflect_halo1 specular bond_specular_halo1 ambient bond_ambient_halo1 diffuse bond_diffuse_halo1 } no_reflection no_radiosity }\n");
5171
 
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
5172
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo1 } finish { reflection bond_reflect_halo1 specular bond_specular_halo1 ambient bond_ambient_halo1 diffuse bond_diffuse_halo1 } no_reflection no_radiosity }\n");
5173
 
                                        mfprintf(b,"  #local vecA = vec1c - vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo1;\n");
5174
 
                                        mfprintf(b,"  #local vecB = vec2c - vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo1;\n");
5175
 
                                        mfprintf(b,"  #local vecC = vec2c - vec1b * (bond_r) - vec3 * bond_d_halo1;\n");
5176
 
                                        mfprintf(b,"  #local vecD = vec1c - vec1b * (bond_r) - vec3 * bond_d_halo1;\n");
5177
 
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
5178
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo1 } finish { reflection bond_reflect_halo1 specular bond_specular_halo1 ambient bond_ambient_halo1 diffuse bond_diffuse_halo1 } no_reflection no_radiosity }\n");
5179
 
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
5180
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo1 } finish { reflection bond_reflect_halo1 specular bond_specular_halo1 ambient bond_ambient_halo1 diffuse bond_diffuse_halo1 } no_reflection no_radiosity }\n");
5181
 
                                        mfprintf(b,"#end\n");
5182
 
                                }
5183
 
 
5184
 
//                              if (halo)
5185
 
                                {
5186
 
                                        mfprintf(b,"#if (bond_draw_halo2)\n");
5187
 
                                        mfprintf(b,"  #local vecA = vec1c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
5188
 
                                        mfprintf(b,"  #local vecB = vec2c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
5189
 
                                        mfprintf(b,"  #local vecC = vec2c + vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo2;\n");
5190
 
                                        mfprintf(b,"  #local vecD = vec1c + vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo2;\n");
5191
 
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
5192
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo2 } finish { reflection bond_reflect_halo2 specular bond_specular_halo2 ambient bond_ambient_halo2 diffuse bond_diffuse_halo2 } no_reflection no_radiosity }\n");
5193
 
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
5194
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo2 } finish { reflection bond_reflect_halo2 specular bond_specular_halo2 ambient bond_ambient_halo2 diffuse bond_diffuse_halo2 } no_reflection no_radiosity }\n");
5195
 
                                        mfprintf(b,"  #local vecA = vec1c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
5196
 
                                        mfprintf(b,"  #local vecB = vec2c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
5197
 
                                        mfprintf(b,"  #local vecC = vec2c - vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo2;\n");
5198
 
                                        mfprintf(b,"  #local vecD = vec1c - vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo2;\n");
5199
 
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
5200
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo2 } finish { reflection bond_reflect_halo2 specular bond_specular_halo2 ambient bond_ambient_halo2 diffuse bond_diffuse_halo2 } no_reflection no_radiosity }\n");
5201
 
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
5202
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo2 } finish { reflection bond_reflect_halo2 specular bond_specular_halo2 ambient bond_ambient_halo2 diffuse bond_diffuse_halo2 } no_reflection no_radiosity }\n");
5203
 
                                        mfprintf(b,"#end\n");
5204
 
 
5205
 
                                        mfprintf(b,"#if (bond_draw_halo3)\n");
5206
 
                                        mfprintf(b,"  #local vecA = vec1c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2 + bond_r_halo3) - vec3 * bond_d_halo2;\n");
5207
 
                                        mfprintf(b,"  #local vecB = vec2c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2 + bond_r_halo3) - vec3 * bond_d_halo2;\n");
5208
 
                                        mfprintf(b,"  #local vecC = vec2c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
5209
 
                                        mfprintf(b,"  #local vecD = vec1c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
5210
 
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
5211
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo3 } finish { reflection bond_reflect_halo3 specular bond_specular_halo3 ambient bond_ambient_halo3 diffuse bond_diffuse_halo3 } no_reflection no_radiosity }\n");
5212
 
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
5213
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo3 } finish { reflection bond_reflect_halo3 specular bond_specular_halo3 ambient bond_ambient_halo3 diffuse bond_diffuse_halo3 } no_reflection no_radiosity }\n");
5214
 
                                        mfprintf(b,"  #local vecA = vec1c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2 + bond_r_halo3) - vec3 * bond_d_halo2;\n");
5215
 
                                        mfprintf(b,"  #local vecB = vec2c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2 + bond_r_halo3) - vec3 * bond_d_halo2;\n");
5216
 
                                        mfprintf(b,"  #local vecC = vec2c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
5217
 
                                        mfprintf(b,"  #local vecD = vec1c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
5218
 
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
5219
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo3 } finish { reflection bond_reflect_halo3 specular bond_specular_halo3 ambient bond_ambient_halo3 diffuse bond_diffuse_halo3 } no_reflection no_radiosity }\n");
5220
 
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
5221
 
                                        mfprintf(b,"    pigment { rgbft bond_color_halo3 } finish { reflection bond_reflect_halo3 specular bond_specular_halo3 ambient bond_ambient_halo3 diffuse bond_diffuse_halo3 } no_reflection no_radiosity }\n");
5222
 
                                        mfprintf(b,"#end\n");
5223
 
                                }
5224
 
 
5225
 
//                              if (shadow)
5226
 
                                {
5227
 
                                        vec3 = vec2 - vec1;
5228
 
                                        vec3.Normalize();
5229
 
 
5230
 
                                        mfprintf(b,"#if (bond_draw_stub)\n");
5231
 
                                        mfprintf(b,"  #local vec3  = < %g, %g, %g >;\n",vec3[0],vec3[1],vec3[2]);
5232
 
                                        mfprintf(b,"  difference {\n");
5233
 
                                        mfprintf(b,"    cylinder { vec1c, vec1c + vec3 * bond_l_stub, bond_r + bond_r_stub }\n");
5234
 
                                        mfprintf(b,"    cylinder { vec1c - vec3 * (bond_l_stub+0.001), vec1c + vec3 * (bond_l_stub+0.001), bond_r }\n");
5235
 
                                        mfprintf(b,"    pigment { rgbft bond_color_stub } finish { reflection bond_reflect_stub specular bond_specular_stub ambient bond_ambient_stub diffuse bond_diffuse_stub } }\n");
5236
 
                                        mfprintf(b,"  difference {\n");
5237
 
                                        mfprintf(b,"    cylinder { vec2c, vec2c - vec3 * bond_l_stub, bond_r + bond_r_stub }\n");
5238
 
                                        mfprintf(b,"    cylinder { vec2c + vec3 * (bond_l_stub+0.001), vec2c - vec3 * (bond_l_stub+0.001), bond_r }\n");
5239
 
                                        mfprintf(b,"    pigment { rgbft bond_color_stub } finish { reflection bond_reflect_stub specular bond_specular_stub ambient bond_ambient_stub diffuse bond_diffuse_stub } }\n");
5240
 
                                        mfprintf(b,"#end\n");
5241
 
                                }
5242
 
                        }
5243
 
                }
5244
 
        }
5245
 
 
5246
 
        mfprintf(b,"\n  no_shadow\n}\n\n");
5247
 
 
5248
 
        fclose(b);
5249
 
}
5250
 
 
5251
 
 
5252
 
void CTimeStep::DumpDipoles()
5253
 
{
5254
 
        int z, z2, z3, z4, ti;
5255
 
        CMolecule *m;
5256
 
        CSingleMolecule *sm;
5257
 
        CxVector3 dc;
5258
 
 
5259
 
        if (!(g_bDipole && g_bDumpDipoleVector))
5260
 
                return;
5261
 
 
5262
 
        fprintf(g_fDumpDipole,"%lu",g_iSteps);
5263
 
        for (z=0;z<g_oaMolecules.GetSize();z++)
5264
 
        {
5265
 
                if (g_oaDumpDipoleVector[z] == NULL)
5266
 
                        continue;
5267
 
                m = (CMolecule*)g_oaMolecules[z];
5268
 
                for (z2=0;z2<((CxIntArray*)g_oaDumpDipoleVector[z])->GetSize();z2++)
5269
 
                {
5270
 
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[((CxIntArray*)g_oaDumpDipoleVector[z])->GetAt(z2)]];
5271
 
                        fprintf(g_fDumpDipole,";  %10G;  %10G;  %10G",sm->m_vDipole[0],sm->m_vDipole[1],sm->m_vDipole[2]);
5272
 
                        if (g_bDumpDipoleAbs)
5273
 
                                fprintf(g_fDumpDipole,";  %10G",sm->m_vDipole.GetLength());
5274
 
                }
5275
 
        }
5276
 
        fprintf(g_fDumpDipole,"\n");
5277
 
 
5278
 
        if (g_bDumpDipoleXYZ)
5279
 
        {
5280
 
                fprintf(g_fDumpDipoleXYZ,"%d\n\n",g_iDumpDipoleXYZAtoms);
5281
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
5282
 
                {
5283
 
                        if (g_oaDumpDipoleVector[z] == NULL)
5284
 
                                continue;
5285
 
                        m = (CMolecule*)g_oaMolecules[z];
5286
 
                        for (z2=0;z2<((CxIntArray*)g_oaDumpDipoleVector[z])->GetSize();z2++)
5287
 
                        {
5288
 
                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[((CxIntArray*)g_oaDumpDipoleVector[z])->GetAt(z2)]];
5289
 
 
5290
 
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
5291
 
                                {
5292
 
                                        if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
5293
 
                                                continue;
5294
 
                                        for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
5295
 
                                        {
5296
 
                                                ti = ((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4);
5297
 
                                                fprintf(g_fDumpDipoleXYZ,"%s  %12f  %12f  %12f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0,m_vaCoords[ti][1]/100.0,m_vaCoords[ti][2]/100.0);
5298
 
                                        }
5299
 
                                }
5300
 
                        }
5301
 
                }
5302
 
 
5303
 
                for (z=0;z<g_oaMolecules.GetSize();z++)
5304
 
                {
5305
 
                        if (g_oaDumpDipoleVector[z] == NULL)
5306
 
                                continue;
5307
 
                        m = (CMolecule*)g_oaMolecules[z];
5308
 
                        for (z2=0;z2<((CxIntArray*)g_oaDumpDipoleVector[z])->GetSize();z2++)
5309
 
                        {
5310
 
                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[((CxIntArray*)g_oaDumpDipoleVector[z])->GetAt(z2)]];
5311
 
                                dc = m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[m->m_iDipoleCenterType])->GetAt(m->m_iDipoleCenterIndex)];
5312
 
                                fprintf(g_fDumpDipoleXYZ,"B  %12f  %12f  %12f\n",dc[0]/100.0,dc[1]/100.0,dc[2]/100.0);
5313
 
                                fprintf(g_fDumpDipoleXYZ,"B  %12f  %12f  %12f\n",dc[0]/100.0+sm->m_vDipole[0]*g_fDumpDipoleScale,dc[1]/100.0+sm->m_vDipole[1]*g_fDumpDipoleScale,dc[2]/100.0+sm->m_vDipole[2]*g_fDumpDipoleScale);
5314
 
                        }
5315
 
                }
5316
 
        }
5317
 
}
5318
 
 
5319
 
 
5320
 
CTimeStep::CTimeStep()
5321
 
{
5322
 
        m_pComment = NULL;
5323
 
 
5324
 
        m_vaCoords.SetName("CTimeStep::m_vaCoords");
5325
 
        m_vaCoords_Unfolded.SetName("CTimeStep::m_vaCoords_Unfolded");
5326
 
        m_vaCoords_Original.SetName("CTimeStep::m_vaCoords_Original");
5327
 
        m_vaVelocities.SetName("CTimeStep::m_vaVelocities");
5328
 
        m_vaForces.SetName("CTimeStep::m_vaForces");
5329
 
        m_paLabels.SetName("CTimeStep::m_paLabels");
5330
 
        m_paMol2Types.SetName("CTimeStep::m_paMol2Types");
5331
 
        m_faCharge.SetName("CTimeStep::m_faCharge");
5332
 
}
5333
 
 
5334
 
 
5335
 
CTimeStep::~CTimeStep()
5336
 
{
5337
 
/*      if (m_pLabels != NULL)
5338
 
                delete[] m_pLabels;*/
5339
 
        if (m_pComment != NULL)
5340
 
                delete[] m_pComment;
5341
 
}
5342
 
 
 
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
#include "timestep.h"
 
25
#include "travis.h"
 
26
 
 
27
 
 
28
void CTimeStep::CalcCenters()
 
29
{
 
30
        BTIN;
 
31
        int z, z2, z3, z4, c;
 
32
        CxVector3 tv;
 
33
        CMolecule *m;
 
34
        CVirtualAtom *v;
 
35
        CSingleMolecule *sm;
 
36
 
 
37
        tv = 0;
 
38
 
 
39
//      mprintf("** CalcCenters **");
 
40
 
 
41
        if (m_vaCoords.GetSize() < g_iGesVirtAtomCount)
 
42
                m_vaCoords.SetSize(g_iGesVirtAtomCount);
 
43
 
 
44
//      mprintf("CalcCenters(): Size is now %d.\n",m_vaCoords.GetSize());
 
45
 
 
46
        if (g_bUseVelocities)
 
47
                if (m_vaVelocities.GetSize() < g_iGesVirtAtomCount)
 
48
                        m_vaVelocities.SetSize(g_iGesVirtAtomCount);
 
49
 
 
50
        if (g_bUseForces)
 
51
                if (m_vaForces.GetSize() < g_iGesVirtAtomCount)
 
52
                        m_vaForces.SetSize(g_iGesVirtAtomCount);
 
53
 
 
54
        for (z=0;z<g_oaVirtualAtoms.GetSize();z++)
 
55
        {
 
56
                v = (CVirtualAtom*)g_oaVirtualAtoms[z];
 
57
                m = (CMolecule*)g_oaMolecules[v->m_iMolecule];
 
58
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
59
                {
 
60
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
61
                        if (v->m_iMode == 0) // Mittel aus Atompositionen
 
62
                        {
 
63
                                tv = 0;
 
64
                                c = 0;
 
65
                                for (z3=0;z3<v->m_oCenterAtoms.m_baAtomType.GetSize();z3++)
 
66
                                {
 
67
                                        for (z4=0;z4<((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetSize();z4++)
 
68
                                        {
 
69
//                                              mprintf("{%d:(%G|%G|%G) }\n",((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4)),m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4))][0],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4))][1],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4))][2]);
 
70
                                                tv += m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_oCenterAtoms.m_baAtomType[z3]])->GetAt(((CxIntArray*)v->m_oCenterAtoms.m_oaAtoms[z3])->GetAt(z4))] * v->m_faWeight[c];
 
71
                                                c++;
 
72
                                        }
 
73
                                }
 
74
                                tv /= v->m_fGesWeight;
 
75
                        } else if (v->m_iMode == 1) // Abstand, Winkel, Dihedralwinkel
 
76
                        {
 
77
                                tv = PointFromRAD(m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_iAtomType[0]])->GetAt(v->m_iAtom[0])],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_iAtomType[1]])->GetAt(v->m_iAtom[1])],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[v->m_iAtomType[2]])->GetAt(v->m_iAtom[2])],v->m_fValues[0],v->m_fValues[1],v->m_fValues[2]);
 
78
                        } else if (v->m_iMode == 2) // Dipolvektor
 
79
                        {
 
80
                                if (!g_bDipole)
 
81
                                {
 
82
                                        eprintf("Cannot use dipole vectors.\n");
 
83
                                        BTOUT;
 
84
                                        return;
 
85
                                }
 
86
                                tv = sm->m_vDipole + m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[sm->m_baAtomIndex.GetSize()-1])->GetAt(0)];
 
87
                        } else if (v->m_iMode == 3) // Geschwindigkeitsvektor
 
88
                        {
 
89
                        } else if (v->m_iMode == 4) // Kraftvektor
 
90
                        {
 
91
                        }
 
92
//                      mprintf("%d:(%G|%G|%G), ",((CxIntArray*)sm->m_oaAtomOffset[sm->m_baAtomIndex.GetSize()-1])->GetAt(v->m_iMolVirtAtom),tv[0],tv[1],tv[2]);
 
93
                        m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[sm->m_baAtomIndex.GetSize()-1])->GetAt(v->m_iMolVirtAtom)] = tv;
 
94
                }
 
95
        }
 
96
        BTOUT;
 
97
}
 
98
 
 
99
 
 
100
bool CTimeStep::BondRange(int i1, int i2, double *f)
 
101
{
 
102
        BTIN;
 
103
        int a, b;
 
104
        double d;
 
105
        double x, y, z;
 
106
 
 
107
        if (g_iScanMolStep == -1)
 
108
                return false;
 
109
 
 
110
        x = m_vaCoords[i1][0] - m_vaCoords[i2][0];
 
111
        y = m_vaCoords[i1][1] - m_vaCoords[i2][1];
 
112
        z = m_vaCoords[i1][2] - m_vaCoords[i2][2];
 
113
 
 
114
        if (g_bPeriodic)
 
115
        {
 
116
                if (g_bPeriodicX)
 
117
                {
 
118
                        while (x < -g_fBoxX/2)
 
119
                                x += g_fBoxX;
 
120
                        while (x > g_fBoxX/2)
 
121
                                x -= g_fBoxX;
 
122
                }
 
123
 
 
124
                if (g_bPeriodicY)
 
125
                {
 
126
                        while (y < -g_fBoxY/2)
 
127
                                y += g_fBoxY;
 
128
                        while (y > g_fBoxY/2)
 
129
                                y -= g_fBoxY;
 
130
                }
 
131
 
 
132
                if (g_bPeriodicZ)
 
133
                {
 
134
                        while (z < -g_fBoxZ/2)
 
135
                                z += g_fBoxZ;
 
136
                        while (z > g_fBoxZ/2)
 
137
                                z -= g_fBoxZ;
 
138
                }
 
139
        }
 
140
 
 
141
        d = (float)sqrt(x*x+y*y+z*z);
 
142
 
 
143
        if (f != NULL)
 
144
                *f = d;
 
145
 
 
146
        a = g_baAtomIndex[i1];
 
147
        b = g_baAtomIndex[i2];
 
148
 
 
149
        if ((a >= g_oaAtoms.GetSize()) || (b >= g_oaAtoms.GetSize()))
 
150
        {
 
151
                BTOUT; 
 
152
                return false;
 
153
        }
 
154
 
 
155
        if (((CAtom*)g_oaAtoms[a])->m_pElement->m_fRadius == 0)
 
156
        {
 
157
                BTOUT;
 
158
                return false;
 
159
        }
 
160
        
 
161
        if (((CAtom*)g_oaAtoms[b])->m_pElement->m_fRadius == 0)
 
162
        {
 
163
                BTOUT;
 
164
                return false;
 
165
        }
 
166
 
 
167
        if (d < (((CAtom*)g_oaAtoms[a])->m_pElement->m_fRadius+((CAtom*)g_oaAtoms[b])->m_pElement->m_fRadius)*g_fBondFactor)
 
168
        {
 
169
//              printf("    \"%s\" br=%f, \"%s\" br=%f Hat Nachbarn %s%d im Abstand von %.3f.\n",m_pLabels[i1],c1,m_pLabels[i2],c2,m_pLabels[i2],i2+1,d);
 
170
                BTOUT; 
 
171
                return true;
 
172
        } else 
 
173
        {
 
174
                BTOUT;
 
175
                return false;
 
176
        }
 
177
}
 
178
 
 
179
 
 
180
bool CTimeStep::MirrorBond(int i1, int i2)
 
181
{
 
182
        BTIN;
 
183
        bool changed;
 
184
 
 
185
        changed = false;
 
186
 
 
187
        if (g_bPeriodicX)
 
188
        {
 
189
                while (m_vaCoords[i1][0]-m_vaCoords[i2][0] > g_fBoxX/2)
 
190
                {
 
191
                        m_vaCoords[i2][0] += g_fBoxX;
 
192
                        changed = true;
 
193
                }
 
194
                while (m_vaCoords[i2][0]-m_vaCoords[i1][0] > g_fBoxX/2)
 
195
                {
 
196
                        m_vaCoords[i2][0] -= g_fBoxX;
 
197
                        changed = true;
 
198
                }
 
199
        }
 
200
 
 
201
        if (g_bPeriodicY)
 
202
        {
 
203
                while (m_vaCoords[i1][1]-m_vaCoords[i2][1] > g_fBoxY/2)
 
204
                {
 
205
                        m_vaCoords[i2][1] += g_fBoxY;
 
206
                        changed = true;
 
207
                }
 
208
                while (m_vaCoords[i2][1]-m_vaCoords[i1][1] > g_fBoxY/2)
 
209
                {
 
210
                        m_vaCoords[i2][1] -= g_fBoxY;
 
211
                        changed = true;
 
212
                }
 
213
        }
 
214
 
 
215
        if (g_bPeriodicZ)
 
216
        {
 
217
                while (m_vaCoords[i1][2]-m_vaCoords[i2][2] > g_fBoxZ/2)
 
218
                {
 
219
                        m_vaCoords[i2][2] += g_fBoxZ;
 
220
                        changed = true;
 
221
                }
 
222
                while (m_vaCoords[i2][2]-m_vaCoords[i1][2] > g_fBoxZ/2)
 
223
                {
 
224
                        m_vaCoords[i2][2] -= g_fBoxZ;
 
225
                        changed = true; 
 
226
                }
 
227
        }
 
228
 
 
229
        if (changed)
 
230
        {
 
231
                BTOUT; 
 
232
                return true;
 
233
        } 
 
234
        BTOUT; 
 
235
        return false;
 
236
}
 
237
 
 
238
 
 
239
void CTimeStep::RECURSION_ScanMolecules(int i, CxByteArray *ta, CSingleMolecule *sm, int depth, int *stack, unsigned long bmask, bool w)
 
240
{
 
241
        BTIN;
 
242
        int z, z2;
 
243
        int nblist[64], nbs;
 
244
        double f;
 
245
        CxIntArray *wa; 
 
246
        CMolAtom *ma;
 
247
//      mprintf("  Rekursion fuer Atom %d.\n",i+1);
 
248
 
 
249
//      mprintf("Depth=%d, i=%d.\n",depth,i);
 
250
        if (g_bVerbose)
 
251
        {
 
252
                mprintf("  ");
 
253
                for (z=1;z<depth;z++)
 
254
                {
 
255
                        if ((bmask & (int)pow(2.0,z)) != 0)
 
256
                                mprintf(WHITE,"|  ");
 
257
                                        else mprintf("   ");
 
258
                }
 
259
                if (depth != 0)
 
260
                {
 
261
                        if (w)
 
262
                                mprintf(WHITE,"|--");
 
263
                                        else mprintf(WHITE,"`--");
 
264
                }
 
265
                mprintf(CYAN,"%s",((CAtom*)g_oaAtoms[g_baAtomIndex[i]])->m_sName);
 
266
                mprintf("(%d)",i+1);
 
267
        }
 
268
 
 
269
        stack[depth] = i;
 
270
        g_laAtomSMIndex[i] = (unsigned long)g_oaSingleMolecules.GetSize()-1;
 
271
        (*ta)[i] = 1;
 
272
//      mprintf("  sm->m_baAtomIndex.GetSize()=%d\n",sm->m_baAtomIndex.GetSize());
 
273
        for (z=0;z<sm->m_baAtomIndex.GetSize();z++)
 
274
        {
 
275
                if (sm->m_baAtomIndex[z] == g_baAtomIndex[i])
 
276
                {
 
277
                        try { ma = new CMolAtom(); } catch(...) { ma = NULL; }
 
278
                        if (ma == NULL) NewException((double)sizeof(CMolAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
279
                        
 
280
                        ma->m_iOffset = i;
 
281
                        ma->m_iType = z;
 
282
                        sm->m_oaMolAtoms.Add(ma);
 
283
                        goto _ok;
 
284
                }
 
285
        }
 
286
 
 
287
        try { ma = new CMolAtom(); } catch(...) { ma = NULL; }
 
288
        if (ma == NULL) NewException((double)sizeof(CMolAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
289
        
 
290
        ma->m_iOffset = i;
 
291
        ma->m_iType = sm->m_baAtomIndex.GetSize();
 
292
        ma->m_iNumber = 0;
 
293
        sm->m_oaMolAtoms.Add(ma);
 
294
 
 
295
        sm->m_baAtomIndex.Add(g_baAtomIndex[i]);
 
296
_ok:
 
297
        m_iConnectedAtoms++;
 
298
 
 
299
        if (!g_bVerbose)
 
300
                if ((m_iConnectedAtoms % m_iGesAtomModulo)==0)
 
301
                        mprintf(WHITE,"#");
 
302
 
 
303
        nbs = 0;
 
304
        for (z=0;z<(long)m_iGesAtomCount;z++) // Schon mal alle Nachbarn raussuchen
 
305
        {
 
306
                if (z == i)
 
307
                        continue;
 
308
                if (((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_bExclude)
 
309
                        continue;
 
310
                if (BondRange(i,z,&f))
 
311
                {
 
312
                        if ((*ta)[z] != 0)
 
313
                        {
 
314
                                if ((depth > 0) && (z != stack[depth-1]))
 
315
                                {
 
316
                                        if (sm->m_oaRings.GetSize() < 100)
 
317
                                        {
 
318
                                                if (g_bVerbose)
 
319
                                                {
 
320
                                                        mprintf(GREEN,"  <-- Ring closure: ");
 
321
                                                        mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[stack[depth]]])->m_sName,stack[depth]+1);
 
322
                                                }
 
323
 
 
324
                                                try { wa = new CxIntArray("CTimeStep::RECURSION_ScanMolecules():wa"); } catch(...) { wa = NULL; }
 
325
                                                if (wa == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
326
                                                
 
327
                                                sm->m_oaRings.Add(wa);
 
328
                                                wa->Add(stack[depth]);
 
329
                                                z2 = depth-1;
 
330
                                                while ((stack[z2] != z) && (z2 >= 0))
 
331
                                                {
 
332
                                                        wa->Add(stack[z2]);
 
333
                                                        if (g_bVerbose)
 
334
                                                                mprintf(" - %s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[stack[z2]]])->m_sName,stack[z2]+1);
 
335
                                                        z2--;
 
336
                                                }
 
337
                                                wa->Add(z);
 
338
                                                if (g_bVerbose)
 
339
                                                        mprintf(" - %s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1);
 
340
                                        } else if (!m_bAbortRing)
 
341
                                        {
 
342
                                                m_bAbortRing = true;
 
343
                                                eprintf("\n### More than 100 rings, aborting ring system scan for molecule %d.",sm->m_iIndex+1);
 
344
                                        }
 
345
                                }
 
346
                                continue;
 
347
                        }
 
348
/*                      for (z2=0;z2<g_waBondBlackList.GetSize();z2+=2)
 
349
                                if (((g_waBondBlackList[z2] == i) && (g_waBondBlackList[z2+1] == z)) || 
 
350
                                        ((g_waBondBlackList[z2] == z) && (g_waBondBlackList[z2+1] == i)))
 
351
                                {
 
352
                                        if (g_bVerbose)
 
353
                                        {
 
354
                                                mprintf("\n  ");
 
355
                                                for (z2=1;z2<depth+1;z2++)
 
356
                                                {
 
357
                                                        if ((bmask & (int)pow(2,z2)) != 0)
 
358
                                                                mprintf(WHITE,"|  ");
 
359
                                                        else mprintf("   ");
 
360
                                                }
 
361
                                                if (z+1 < nbs)
 
362
                                                        mprintf(WHITE,"|--");
 
363
                                                                else mprintf("`--");
 
364
                                                mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1);
 
365
                                                mprintf(GREEN,"  <-- This bond has been broken, skipping.\n");
 
366
                                        }
 
367
                                        g_iBondBlackListUsed++;
 
368
                                        goto _nextnb;
 
369
                                }*/
 
370
                        if (f < 50.0f)
 
371
                        {
 
372
                                if (g_iCloseAtomCounter < 25)
 
373
                                        eprintf("\n### The atoms %s(%d) and %s(%d) are VERY close to each other. (Distance=%.4f pm)",((CAtom*)g_oaAtoms[g_baAtomIndex[i]])->m_sName,i+1,((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1,f);
 
374
                                else if (g_iCloseAtomCounter == 25)
 
375
                                        eprintf("\n### Suppressing further \"atoms close to each other\" warnings.");
 
376
 
 
377
                                g_iCloseAtomCounter++;
 
378
                        }
 
379
                        nblist[nbs] = z;
 
380
                        nbs++;
 
381
                        if (nbs >= MAX_BONDS)
 
382
                        {
 
383
                                eprintf("\n### Atom %s(%d) has more than %d bonds. Ignoring further bonds (defined via MAX_BONDS in config.h).",((CAtom*)g_oaAtoms[g_baAtomIndex[i]])->m_sName,i+1,MAX_BONDS);
 
384
                                goto _nbdone;
 
385
                        }
 
386
                }
 
387
        }
 
388
_nbdone:
 
389
        if (g_bVerbose)
 
390
                mprintf("\n");
 
391
        for (z=0;z<nbs;z++) // Fuer das aktuelle Atom z2 alle Nachbarn durchgehen
 
392
        {
 
393
                for (z2=0;z2<g_laBondBlackList.GetSize();z2+=2)
 
394
                {
 
395
                        if (((g_laBondBlackList[z2] == i) && (g_laBondBlackList[z2+1] == nblist[z])) || 
 
396
                                ((g_laBondBlackList[z2] == nblist[z]) && (g_laBondBlackList[z2+1] == i)))
 
397
                        {
 
398
                                if (g_bVerbose)
 
399
                                {
 
400
                                        mprintf("  ");
 
401
                                        for (z2=1;z2<depth+1;z2++)
 
402
                                        {
 
403
                                                if ((bmask & (int)pow(2.0,z2)) != 0)
 
404
                                                        mprintf(WHITE,"|  ");
 
405
                                                else mprintf("   ");
 
406
                                        }
 
407
                                        if (z+1 < nbs)
 
408
                                                mprintf(WHITE,"|--");
 
409
                                                        else mprintf(WHITE,"`--");
 
410
                                        mprintf(CYAN,"%s",((CAtom*)g_oaAtoms[g_baAtomIndex[nblist[z]]])->m_sName);
 
411
                                        mprintf("(%d)",nblist[z]+1);
 
412
                                        mprintf(GREEN,"  <-- This bond shall be broken, skipping.\n");
 
413
                                }
 
414
                                g_iBondBlackListUsed++;
 
415
                                goto _nextnb;
 
416
                        }
 
417
                }
 
418
 
 
419
                sm->m_laBonds.Add(i);
 
420
                sm->m_laBonds.Add(nblist[z]);
 
421
 
 
422
                if ((*ta)[nblist[z]] == 0) // Der Nachbar ist noch immer frei
 
423
                {
 
424
                        if (z+1 == nbs)
 
425
                                bmask -= (int)pow(2.0,depth+1);
 
426
                        RECURSION_ScanMolecules(nblist[z],ta,sm,depth+1,stack,bmask,(z+1==nbs)?false:true);
 
427
                } else // Ringschluss
 
428
                {
 
429
                        if (g_bVerbose)
 
430
                        {
 
431
                                mprintf("  ");
 
432
                                for (z2=1;z2<depth+1;z2++)
 
433
                                {
 
434
                                        if ((bmask & (int)pow(2.0,z2)) != 0)
 
435
                                                mprintf(WHITE,"|  ");
 
436
                                        else mprintf("   ");
 
437
                                }
 
438
                                if (z+1 < nbs)
 
439
                                        mprintf(WHITE,"|--");
 
440
                                                else mprintf(WHITE,"`--");
 
441
                                mprintf(CYAN,"%s",((CAtom*)g_oaAtoms[g_baAtomIndex[nblist[z]]])->m_sName);
 
442
                                mprintf("(%d)",nblist[z]+1);
 
443
                                mprintf(GREEN,"  <-- Ring closure\n");
 
444
                        }
 
445
                }
 
446
_nextnb:;
 
447
        }
 
448
        BTOUT; 
 
449
}
 
450
 
 
451
 
 
452
void CTimeStep::BuildAtomIndex()
 
453
{
 
454
        BTIN;
 
455
        int z, z2;
 
456
        CAtom *at;
 
457
        char buf[64];
 
458
 
 
459
        g_baAtomIndex.SetSize(m_iGesAtomCount);
 
460
        for (z=0;z<(long)m_iGesAtomCount;z++)
 
461
        {
 
462
                strcpy(buf,(char*)m_paLabels[z]);
 
463
                ReplaceDigits(buf);
 
464
                for (z2=0;z2<g_oaAtoms.GetSize();z2++)
 
465
                {
 
466
                        if (mystricmp(buf,((CAtom*)g_oaAtoms[z2])->m_sName)==0)
 
467
                        {
 
468
                                at = (CAtom*)g_oaAtoms[z2];
 
469
        //                      mprintf("Atom %d: Type %d (%s).\n",z,z2,at->m_sName);
 
470
                                while (at->m_pMergedTo != NULL)
 
471
                                {
 
472
                                        at = at->m_pMergedTo;
 
473
        //                              mprintf("  ...was merged to %s.\n",at->m_sName);
 
474
                                }
 
475
        //                      mprintf("  Index is %d.\n",at->m_iIndex);
 
476
                                g_baAtomIndex[z] = (unsigned char)at->m_iIndex;
 
477
                                goto _e;
 
478
                        }
 
479
                }
 
480
                g_baAtomIndex[z] = 255;
 
481
                eprintf("Error: CTimeStep::BuildAtomIndex(): Atom type \"%s\" not known.\n",buf);
 
482
                _e:;
 
483
        }
 
484
        BTOUT; 
 
485
}
 
486
 
 
487
 
 
488
bool CTimeStep::ScanMolecules()
 
489
{
 
490
        BTIN;
 
491
        int z, z2, z3, z4, z5, i, i2, ti, ti2, i1;
 
492
        CxByteArray ta;
 
493
        CSingleMolecule *sm, *sm2;
 
494
        CxIntArray *wa, *waz2, *waz3, *waneu;
 
495
        CMolecule *m;
 
496
        CMolAtom *ma, *ma2, *ma3;
 
497
        CMolBond *bond, *bond2;
 
498
        CMolBondGroup *bg;
 
499
        CMolAngle *angle, *angle2;
 
500
        CMolAngleGroup *ag;
 
501
        CAtom *at;
 
502
        float f;
 
503
        bool b;
 
504
        double tfs;
 
505
        int *stack;
 
506
 
 
507
        BuildAtomIndex();
 
508
//      CalcRadii();
 
509
 
 
510
        try { stack = new int[g_iGesAtomCount]; } catch(...) { stack = NULL; }
 
511
        if (stack == NULL) NewException((double)g_iGesAtomCount*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
512
 
 
513
        b = false;
 
514
        for (z=0;z<g_oaAtoms.GetSize();z++)
 
515
        {
 
516
                if (z == g_iVirtAtomType)
 
517
                        continue;
 
518
                at = (CAtom*)g_oaAtoms[z];
 
519
                if (at->m_pMergedTo != NULL)
 
520
                        continue;
 
521
                if (at->m_pElement->m_fRadius == 0)
 
522
                {
 
523
                        if (!b)
 
524
                        {
 
525
                                b = true;
 
526
                                mprintf("\n");
 
527
                        }
 
528
                        at->m_bExclude = AskYesNo("    Atom type \"%s\" has bond radius 0. Exclude it from the system (y/n)? [yes] ",true,at->m_sName);
 
529
        //              if (!at->m_bExclude)
 
530
        //                      at->m_pElement->m_fRadius = AskFloat_ND("    Please enter covalent bond radius for %s (in pm): ",at->m_sName);
 
531
                }
 
532
        }
 
533
 
 
534
        ta.SetSize(g_iGesAtomCount);
 
535
        g_laAtomSMIndex.SetSize(g_iGesAtomCount);
 
536
        for (z=0;z<g_iGesAtomCount;z++)
 
537
        {
 
538
                ta[z] = 0;
 
539
                g_laAtomSMIndex[z] = -1;
 
540
        }
 
541
        g_iBondBlackListUsed = 0;
 
542
        g_oaSingleMolecules.RemoveAll();
 
543
        g_oaMolecules.RemoveAll();
 
544
        m_iConnectedAtoms = 0;
 
545
        m_iGesAtomModulo = (m_iGesAtomCount / 60)+1;
 
546
        if (g_iScanMolStep == -1)
 
547
        {
 
548
                mprintf(WHITE,"\n    Skipping molecule recognition, using atoms as molecules...\n\n");
 
549
                for (z=0;z<(long)m_iGesAtomCount;z++)
 
550
                {
 
551
                        if (((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_bExclude)
 
552
                                continue;
 
553
                        
 
554
                        try { sm = new CSingleMolecule(); } catch(...) { sm = NULL; }
 
555
                        if (sm == NULL) NewException((double)sizeof(CSingleMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
556
                        
 
557
                        sm->m_iIndex = g_oaSingleMolecules.GetSize();
 
558
 
 
559
                        g_oaSingleMolecules.Add(sm);
 
560
 
 
561
                        g_laAtomSMIndex[z] = (unsigned long)g_oaSingleMolecules.GetSize()-1;
 
562
 
 
563
                        try { ma = new CMolAtom(); } catch(...) { ma = NULL; }
 
564
                        if (ma == NULL) NewException((double)sizeof(CMolAtom),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
565
                        
 
566
                        ma->m_iOffset = z;
 
567
                        ma->m_iType = sm->m_baAtomIndex.GetSize();
 
568
                        ma->m_iNumber = 0;
 
569
                        sm->m_oaMolAtoms.Add(ma);
 
570
                        sm->m_baAtomIndex.Add(g_baAtomIndex[z]);
 
571
                }
 
572
                mprintf("    %d molecules found.\n\n",g_oaSingleMolecules.GetSize());
 
573
        } else
 
574
        {
 
575
                if (g_bVerbose)
 
576
                {
 
577
                        mprintf(WHITE,"\n    Molecule recognition...\n\n");
 
578
                        mprintf(WHITE,">>> Output of the molecule tree >>>\n");
 
579
                } else mprintf("\n    Molecule recognition [");
 
580
        //      fflush(stdout);
 
581
                for (z=0;z<(long)m_iGesAtomCount;z++)
 
582
                {
 
583
                        if (ta[z] != 0) // Dieses Atom wurde bereits in irgendein Molekuel eingebaut
 
584
                        {
 
585
        //                      mprintf("> Atom %d: Schon vergeben.\n",z+1);
 
586
                                continue;
 
587
                        }
 
588
        //              mprintf("# Atom %d: Starte Rekursion.\n",z+1);
 
589
 
 
590
                        if (((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_bExclude)
 
591
                                continue;
 
592
                        
 
593
                        try { sm = new CSingleMolecule(); } catch(...) { sm = NULL; }
 
594
                        if (sm == NULL) NewException((double)sizeof(CSingleMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
595
                        
 
596
                        sm->m_iIndex = g_oaSingleMolecules.GetSize();
 
597
 
 
598
                        g_oaSingleMolecules.Add(sm);
 
599
 
 
600
        //              sm->m_iAtomGes = 0;
 
601
        /*              for (z2=0;z2<16;z2++)
 
602
                                sm->m_iAtomCount[z2] = 0;
 
603
                        sm->m_iElements = 0;*/
 
604
                        if (g_bVerbose)
 
605
                                mprintf(YELLOW,"\nThe next molecule starts with %s(%d):\n",m_paLabels[z],z+1);
 
606
                        
 
607
                        m_bAbortRing = false;
 
608
 
 
609
                        RECURSION_ScanMolecules(z,&ta,sm,0,stack,0xFFFFFFFF,true);
 
610
 
 
611
        //              printf("%d Atome in diesem Molekuel.\n",g_pSingleMolecules[g_oaSingleMolecules.GetSize()].AtomGes);
 
612
 
 
613
        //              g_oaSingleMolecules.GetSize()++;
 
614
                }
 
615
                if (g_bVerbose)
 
616
                {
 
617
                        mprintf(WHITE,"\n<<< Output of the molecule tree <<<\n\n");
 
618
                        mprintf("%d molecules found.\n\n",g_oaSingleMolecules.GetSize());
 
619
                } else mprintf("]\n\n    %d molecules found.\n\n",g_oaSingleMolecules.GetSize());
 
620
        }
 
621
 
 
622
        if (g_iCloseAtomCounter != 0)
 
623
        {
 
624
                mprintf(RED,"\n*** Warning: ");
 
625
                mprintf("Some of the atoms were found to be very close to each other (distance < 50 pm).\n");
 
626
                mprintf("             This usually indicates a problem, e.g. an incorrect cell vector.\n\n");
 
627
                if (!AskYesNo("    Continue with molecule recognition anyways (y/n)? [yes] ",true))
 
628
                        return false;
 
629
                mprintf("\n");
 
630
        }
 
631
 
 
632
        mprintf("    Sorting atom types...\n");
 
633
        SortSingleMolAtomTypes();
 
634
 
 
635
        delete[] stack;
 
636
 
 
637
/*      mprintf("\n");
 
638
        for (z=0;z<g_oaSingleMolecules.GetSize();z++)
 
639
        {
 
640
                mprintf("%d ",z+1);
 
641
                ((CSingleMolecule*)g_oaSingleMolecules[z])->Dump();
 
642
        }
 
643
 
 
644
        mprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");*/
 
645
 
 
646
/*      mprintf("\n");
 
647
        for (z=0;z<g_oaSingleMolecules.GetSize();z++)
 
648
        {
 
649
                mprintf("%d ",z+1);
 
650
                ((CSingleMolecule*)g_oaSingleMolecules[z])->Dump();
 
651
        }
 
652
        mprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");*/
 
653
        if (g_iBondBlackListUsed != 0)
 
654
                mprintf("    %d bonds have been broken.\n",g_iBondBlackListUsed);
 
655
        
 
656
/*      if (g_oaSingleMolecules.GetSize() >= 4096)
 
657
        {
 
658
                mprintf("\n>>> Mehr als 4096 Molekuele! Dies wird nicht unterstuetzt. <<<\n\n");
 
659
//              g_oaSingleMolecules.GetSize() = 4096;
 
660
        }*/
 
661
 
 
662
        mprintf("    Setting up bond lists...\n");
 
663
        // Die Bindungen in m_oaMolAtoms aufbauen
 
664
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
 
665
        {
 
666
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
 
667
                for (z2=0;z2<sm->m_laBonds.GetSize()/2;z2++)
 
668
                {
 
669
                        i = sm->m_laBonds[z2*2];
 
670
                        i2 = sm->m_laBonds[z2*2+1];
 
671
                        ti = -1;
 
672
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
 
673
                        {
 
674
                                if (((CMolAtom*)sm->m_oaMolAtoms[z3])->m_iOffset == i)
 
675
                                {
 
676
                                        ti = z3;
 
677
                                        break;
 
678
                                }
 
679
                        }
 
680
                        if (ti == -1)
 
681
                        {
 
682
                                eprintf("CTimeStep::ScanMolecules(): Atom 1 of bond (%d) not found.\n",i);
 
683
                                return false;
 
684
                        }
 
685
                        ti2 = -1;
 
686
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
 
687
                        {
 
688
                                if (((CMolAtom*)sm->m_oaMolAtoms[z3])->m_iOffset == i2)
 
689
                                {
 
690
                                        ti2 = z3;
 
691
                                        break;
 
692
                                }
 
693
                        }
 
694
                        if (ti2 == -1)
 
695
                        {
 
696
                                eprintf("CTimeStep::ScanMolecules(): Atom 2 of bond (%d) not found.\n",i2);
 
697
                                return false;
 
698
                        }
 
699
                        ((CMolAtom*)sm->m_oaMolAtoms[ti])->m_oaBonds.Add((CMolAtom*)sm->m_oaMolAtoms[ti2]);
 
700
                        ((CMolAtom*)sm->m_oaMolAtoms[ti2])->m_oaBonds.Add((CMolAtom*)sm->m_oaMolAtoms[ti]);
 
701
                }
 
702
        }
 
703
 
 
704
        // Die AtomCodes berechnen
 
705
        mprintf("    Building atom codes...\n");
 
706
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
 
707
        {
 
708
//              mprintf("Molecule %d: ",z+1);
 
709
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
 
710
                if (g_bVerbose)
 
711
                        mprintf(YELLOW,"\n*** Singlemolecule %d ***\n\n",z+1);
 
712
                sm->BuildAtomCodes();
 
713
        }
 
714
 
 
715
        mprintf("    Creating topological atom order...\n");
 
716
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
 
717
        {
 
718
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
 
719
                for (z2=0;z2<sm->m_baAtomIndex.GetSize();z2++)
 
720
                {
 
721
                        try { wa = new CxIntArray("CTimeStep::ScanMolecules():wa"); } catch(...) { wa = NULL; }
 
722
                        if (wa == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
723
                        
 
724
                        sm->m_oaAtomOffset.Add(wa);
 
725
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
 
726
                        {
 
727
                                ma = (CMolAtom*)sm->m_oaMolAtoms[z3];
 
728
                                if (ma->m_iType != z2)
 
729
                                        continue;
 
730
                                ma->m_iNumber = wa->GetSize();
 
731
                                wa->Add(ma->m_iOffset);
 
732
                        }
 
733
                }
 
734
        }
 
735
 
 
736
        mprintf("    Creating bond list...\n");
 
737
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
 
738
        {
 
739
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
 
740
//              mprintf("%d:\n",z+1);
 
741
                for (z2=0;z2<sm->m_oaMolAtoms.GetSize();z2++)
 
742
                {
 
743
                        ma = (CMolAtom*)sm->m_oaMolAtoms[z2];
 
744
                        for (z3=0;z3<ma->m_oaBonds.GetSize();z3++)
 
745
                        {
 
746
                                ma2 = (CMolAtom*)ma->m_oaBonds[z3];
 
747
                                if (ma2->m_iMolAtomNumber < z2 /* == ma->m_iMolAtomNumber*/)
 
748
                                        continue;
 
749
 
 
750
                //              mprintf("  %s%2d <--> %s%2d\n",((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma->m_iType]])->m_sName,ma->m_iNumber+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma2->m_iType]])->m_sName,ma2->m_iNumber+1);
 
751
 
 
752
                                try { bond = new CMolBond(); } catch(...) { bond = NULL; }
 
753
                                if (bond == NULL) NewException((double)sizeof(CMolBond),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
754
                                
 
755
                                bond->m_iAtom[0] = ma->m_iNumber;
 
756
                                bond->m_iAtom[1] = ma2->m_iNumber;
 
757
                                bond->m_iAtomType[0] = ma->m_iType;
 
758
                                bond->m_iAtomType[1] = ma2->m_iType;
 
759
                                bond->m_iMolAtom[0] = z2;
 
760
                                bond->m_iMolAtom[1] = ma2->m_iMolAtomNumber;
 
761
                                bond->m_iAtomOffset[0] = ma->m_iOffset;
 
762
                                bond->m_iAtomOffset[1] = ma2->m_iOffset;
 
763
                                sm->m_oaBonds.Add(bond);
 
764
                        }
 
765
                }
 
766
/*              if (z == 0)
 
767
                        mprintf("  %d Bonds added.\n",oatemp.GetSize());*/
 
768
                for (z2=0;z2<sm->m_oaBonds.GetSize();z2++)
 
769
                {
 
770
                        bond = (CMolBond*)sm->m_oaBonds[z2];
 
771
                        for (z3=0;z3<sm->m_oaBondGroups.GetSize();z3++)
 
772
                        {
 
773
                                bg = (CMolBondGroup*)sm->m_oaBondGroups[z3];
 
774
                                for (z4=0;z4<bg->m_oaBonds.GetSize();z4++)
 
775
                                {
 
776
                                        bond2 = (CMolBond*)bg->m_oaBonds[z4];
 
777
                                        if (((((CMolAtom*)sm->m_oaMolAtoms[bond->m_iMolAtom[0]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[bond2->m_iMolAtom[0]])->m_fAtomCode) &&
 
778
                                                 (((CMolAtom*)sm->m_oaMolAtoms[bond->m_iMolAtom[1]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[bond2->m_iMolAtom[1]])->m_fAtomCode)) ||
 
779
                                                ((((CMolAtom*)sm->m_oaMolAtoms[bond->m_iMolAtom[0]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[bond2->m_iMolAtom[1]])->m_fAtomCode) &&
 
780
                                                 (((CMolAtom*)sm->m_oaMolAtoms[bond->m_iMolAtom[1]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[bond2->m_iMolAtom[0]])->m_fAtomCode)))        
 
781
                                        {
 
782
                                                bg->m_oaBonds.Add(bond);
 
783
                                                goto _bonddone;
 
784
                                        }
 
785
                                }
 
786
                        }
 
787
 
 
788
                        try { bg = new CMolBondGroup(); } catch(...) { bg = NULL; }
 
789
                        if (bg == NULL) NewException((double)sizeof(CMolBondGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
790
                        
 
791
                        bg->m_oaBonds.Add(bond);
 
792
                        sm->m_oaBondGroups.Add(bg);
 
793
_bonddone:;
 
794
                }
 
795
/*              if (z == 0)
 
796
                {
 
797
                        mprintf("  %d Bond groups found:\n",sm->m_oaBondGroups.GetSize());
 
798
                        for (z2=0;z2<sm->m_oaBondGroups.GetSize();z2++)
 
799
                        {
 
800
                                mprintf("  - ");
 
801
                                bg = (CMolBondGroup*)sm->m_oaBondGroups[z2];
 
802
                                for (z3=0;z3<bg->m_oaBonds.GetSize();z3++)
 
803
                                {
 
804
                                        bond = (CMolBond*)bg->m_oaBonds[z3];
 
805
                                        mprintf("%s%2d <--> %s%2d",((CAtom*)g_oaAtoms[sm->m_baAtomIndex[bond->m_iAtomType[0]]])->m_sName,bond->m_iAtom[0]+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[bond->m_iAtomType[1]]])->m_sName,bond->m_iAtom[1]+1);
 
806
                                        if (z3 < bg->m_oaBonds.GetSize()-1)
 
807
                                                mprintf(", ");
 
808
                                }
 
809
                                mprintf("\n");
 
810
                        }
 
811
                }*/
 
812
        }
 
813
 
 
814
        mprintf("    Creating angle list...\n");
 
815
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) 
 
816
        {
 
817
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
 
818
//              mprintf("%d:\n",z+1);
 
819
                for (z2=0;z2<sm->m_oaMolAtoms.GetSize();z2++)
 
820
                {
 
821
                        ma = (CMolAtom*)sm->m_oaMolAtoms[z2];
 
822
                        for (z3=0;z3<ma->m_oaBonds.GetSize();z3++)
 
823
                        {
 
824
                                ma2 = (CMolAtom*)ma->m_oaBonds[z3];
 
825
                                for (z4=z3+1;z4<ma->m_oaBonds.GetSize();z4++)
 
826
                                {
 
827
                                        ma3 = (CMolAtom*)ma->m_oaBonds[z4];
 
828
                        //              mprintf("  (%s%2d, %s%2d, %s%2d)\n",((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma2->m_iType]])->m_sName,ma2->m_iNumber+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma->m_iType]])->m_sName,ma->m_iNumber+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[ma3->m_iType]])->m_sName,ma3->m_iNumber+1);
 
829
 
 
830
                                        try { angle = new CMolAngle(); } catch(...) { angle = NULL; }
 
831
                                        if (angle == NULL) NewException((double)sizeof(CMolAngle),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
832
                                        
 
833
                                        angle->m_iAtom[0] = ma2->m_iNumber;
 
834
                                        angle->m_iAtom[1] = ma->m_iNumber;
 
835
                                        angle->m_iAtom[2] = ma3->m_iNumber;
 
836
                                        angle->m_iAtomType[0] = ma2->m_iType;
 
837
                                        angle->m_iAtomType[1] = ma->m_iType;
 
838
                                        angle->m_iAtomType[2] = ma3->m_iType;
 
839
                                        angle->m_iMolAtom[0] = ma2->m_iMolAtomNumber;
 
840
                                        angle->m_iMolAtom[1] = z2;
 
841
                                        angle->m_iMolAtom[2] = ma3->m_iMolAtomNumber;
 
842
                                        angle->m_iAtomOffset[0] = ma2->m_iOffset;
 
843
                                        angle->m_iAtomOffset[1] = ma->m_iOffset;
 
844
                                        angle->m_iAtomOffset[2] = ma3->m_iOffset;
 
845
                                        sm->m_oaAngles.Add(angle);
 
846
                                }
 
847
                        }
 
848
                }
 
849
/*              if (z ==  0)
 
850
                        mprintf("  %d Angles added.\n",oatemp.GetSize());*/
 
851
                if (sm->m_oaAngles.GetSize() > 1000)
 
852
                        mprintf(WHITE,"      [");
 
853
                tfs = sm->m_oaAngles.GetSize() / 50.0;
 
854
                for (z2=0;z2<sm->m_oaAngles.GetSize();z2++)
 
855
                {
 
856
                        if (sm->m_oaAngles.GetSize() > 1000)
 
857
                                if (fmod(z2,tfs) < 1)
 
858
                                        mprintf(WHITE,"#");
 
859
                        angle = (CMolAngle*)sm->m_oaAngles[z2];
 
860
                        for (z3=0;z3<sm->m_oaAngleGroups.GetSize();z3++)
 
861
                        {
 
862
                                ag = (CMolAngleGroup*)sm->m_oaAngleGroups[z3];
 
863
                                for (z4=0;z4<ag->m_oaAngles.GetSize();z4++)
 
864
                                {
 
865
                                        angle2 = (CMolAngle*)ag->m_oaAngles[z4];
 
866
                                        if (( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[1]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[1]])->m_fAtomCode) &&
 
867
                                                (((( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[0]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[0]])->m_fAtomCode) &&
 
868
                                                ( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[2]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[2]])->m_fAtomCode))) ||
 
869
                                                (( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[0]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[2]])->m_fAtomCode) &&
 
870
                                                ( ((CMolAtom*)sm->m_oaMolAtoms[angle->m_iMolAtom[2]])->m_fAtomCode == ((CMolAtom*)sm->m_oaMolAtoms[angle2->m_iMolAtom[0]])->m_fAtomCode))))     
 
871
                                        {
 
872
                                                ag->m_oaAngles.Add(angle);
 
873
                                                goto _angledone;
 
874
                                        }
 
875
                                }
 
876
                        }
 
877
 
 
878
                        try { ag = new CMolAngleGroup(); } catch(...) { ag = NULL; }
 
879
                        if (ag == NULL) NewException((double)sizeof(CMolAngleGroup),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
880
                        
 
881
                        ag->m_oaAngles.Add(angle);
 
882
                        sm->m_oaAngleGroups.Add(ag);
 
883
_angledone:;
 
884
                }
 
885
                if (sm->m_oaAngles.GetSize() > 1000)
 
886
                        mprintf(WHITE,"]\n");
 
887
/*              if (z == 0)
 
888
                {
 
889
                        mprintf("  %d Angle groups found:\n",sm->m_oaAngleGroups.GetSize());
 
890
                        for (z2=0;z2<sm->m_oaAngleGroups.GetSize();z2++)
 
891
                        {
 
892
                                mprintf("  - ");
 
893
                                ag = (CMolAngleGroup*)sm->m_oaAngleGroups[z2];
 
894
                                for (z3=0;z3<ag->m_oaAngles.GetSize();z3++)
 
895
                                {
 
896
                                        angle = (CMolAngle*)ag->m_oaAngles[z3];
 
897
                                        mprintf("  (%s%2d, %s%2d, %s%2d)",((CAtom*)g_oaAtoms[sm->m_baAtomIndex[angle->m_iAtomType[0]]])->m_sName,angle->m_iAtom[0]+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[angle->m_iAtomType[1]]])->m_sName,angle->m_iAtom[1]+1,((CAtom*)g_oaAtoms[sm->m_baAtomIndex[angle->m_iAtomType[2]]])->m_sName,angle->m_iAtom[2]+1);
 
898
                                        if (z3 < ag->m_oaAngles.GetSize()-1)
 
899
                                                mprintf(", ");
 
900
                                }
 
901
                                mprintf("\n");
 
902
                        }
 
903
                }*/
 
904
        }
 
905
 
 
906
        mprintf("    Grouping together equivalent molecules...\n");
 
907
        for (z=0;z<g_oaSingleMolecules.GetSize();z++) // Alle Molekuelvertreter durchgehen
 
908
        {
 
909
//              mprintf("Pruefe SM %d...\n",z+1);
 
910
                sm = (CSingleMolecule*)g_oaSingleMolecules[z];
 
911
                for (z2=0;z2<g_oaMolecules.GetSize();z2++) // Alle schon vorhandenen Molekueltemplates durchgehen
 
912
                {
 
913
                        m = (CMolecule*)g_oaMolecules[z2];
 
914
                        sm2 = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[0]];
 
915
/*                      if (m->m_baAtomIndex.GetSize() != sm->m_baAtomIndex.GetSize())
 
916
                                goto _cont; // Nich die Gleiche Anzahl verschiedener Elemente -> Keine Uebereinstimmung
 
917
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
918
                        {
 
919
                                if (m->m_baAtomIndex[z3] != sm->m_baAtomIndex[z3])
 
920
                                        goto _cont; // Elemente an Position z3 unterscheiden sich -> keine Uebereinstimmung
 
921
                                if (m->m_waAtomCount[z3] != ((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize())
 
922
                                        goto _cont; // Anzahl an Atomen dieser Elementsorte unterscheidet sich -> Keine Uebereinstimmung*/
 
923
//                              mprintf("  Stimmt mit M%d ueberein.\n",z2);
 
924
//                              ((CMolecule*)g_oaMolecules[z2])->Count++;
 
925
//                              g_pSingleMolecules[z].m_iMoleculeOffset = z2;
 
926
//                      }
 
927
                        if (sm->m_oaMolAtoms.GetSize() != sm2->m_oaMolAtoms.GetSize())
 
928
                                goto _cont;
 
929
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
 
930
                                if (((CMolAtom*)sm->m_oaMolAtoms[z3])->m_fAtomCode != ((CMolAtom*)sm2->m_oaMolAtoms[z3])->m_fAtomCode)
 
931
                                        goto _cont;
 
932
                        sm->m_iMolSMIndex = m->m_laSingleMolIndex.GetSize();
 
933
                        m->m_laSingleMolIndex.Add(z);
 
934
//                      sm->m_iMolType = z2;
 
935
                        goto _fert;
 
936
                        _cont:;
 
937
                }
 
938
 
 
939
                try { m = new CMolecule(); } catch(...) { m = NULL; }
 
940
                if (m == NULL) NewException((double)sizeof(CMolecule),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
941
                
 
942
                g_oaMolecules.Add(m);
 
943
//              m->Count = 1; // Neues Molekueltemplate hinzufuegen
 
944
//              m->Elements = ((CSingleMolecule*)g_oaSingleMolecules[z])->m_iElements;
 
945
                m->m_iAtomGes = 0;
 
946
                f = 0;
 
947
                for (z2=0;z2<sm->m_oaAtomOffset.GetSize();z2++)
 
948
                {
 
949
                        m->m_iAtomGes += ((CxIntArray*)sm->m_oaAtomOffset[z2])->GetSize();
 
950
                        f += ((CAtom*)g_oaAtoms[sm->m_baAtomIndex[z2]])->m_pElement->m_fMass * ((CxIntArray*)sm->m_oaAtomOffset[z2])->GetSize();
 
951
                }
 
952
                m->m_iAtomGesNoVirt = m->m_iAtomGes;
 
953
                m->m_fMass = f;
 
954
                ((CSingleMolecule*)g_oaSingleMolecules[z])->m_iMolType = g_oaMolecules.GetSize()-1;
 
955
                for (z2=0;z2<((CSingleMolecule*)g_oaSingleMolecules[z])->m_baAtomIndex.GetSize();z2++)
 
956
                {
 
957
                        m->m_baAtomIndex.Add(((CSingleMolecule*)g_oaSingleMolecules[z])->m_baAtomIndex[z2]);
 
958
                        m->m_waAtomCount.Add(((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[z])->m_oaAtomOffset[z2])->GetSize());
 
959
//                      m->AtomCount[z2] = ((CSingleMolecule*)g_oaSingleMolecules[z])->m_iAtomCount[z2];
 
960
                }
 
961
                sm->m_iMolSMIndex = m->m_laSingleMolIndex.GetSize();
 
962
                m->m_laSingleMolIndex.Add(z);
 
963
//              g_pSingleMolecules[z].m_iMoleculeOffset = g_oaMolecules.GetSize();
 
964
                m->BuildName();
 
965
 
 
966
                // Standardmaessig geom. Zentrum als Dipolzentrum
 
967
                m->m_iDipoleCenterType = m->m_baAtomIndex.GetSize();
 
968
                m->m_iDipoleCenterIndex = 0;
 
969
 
 
970
//              mprintf("### Erzeuge neues Molekuel %d \"%s\".\n",g_oaMolecules.GetSize(),m->Name);
 
971
//              g_oaMolecules.GetSize()++;
 
972
                _fert:;
 
973
        }
 
974
        mprintf("    Found %d unique molecule types.\n",g_oaMolecules.GetSize());
 
975
 
 
976
        // Sort by molecular mass
 
977
        mprintf("    Sorting molecule types by molecular mass...\n");
 
978
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
979
        {
 
980
//              mprintf("@ z=%d\n",z);
 
981
                f = -1.0f;
 
982
                z3 = -1;
 
983
                for (z2=z;z2<g_oaMolecules.GetSize();z2++)
 
984
                {
 
985
//                      mprintf("@   z2=%d\n",z2);
 
986
                        if (((CMolecule*)g_oaMolecules[z2])->m_fMass > f)
 
987
                        {
 
988
//                              mprintf("@     %f > %f --> z3 = %d\n",((CMolecule*)g_oaMolecules[z2])->m_fMass,f,z2);
 
989
                                f = ((CMolecule*)g_oaMolecules[z2])->m_fMass;
 
990
                                z3 = z2;
 
991
                        }
 
992
                }
 
993
                if (z3 == -1)
 
994
                        abort();
 
995
                if (f > 0)
 
996
                {
 
997
//                      mprintf("@ Swapping %d with %d.\n",z,z3);
 
998
                        m = (CMolecule*)g_oaMolecules[z3];
 
999
                        g_oaMolecules[z3] = g_oaMolecules[z];
 
1000
                        g_oaMolecules[z] = m;
 
1001
                }
 
1002
        }
 
1003
 
 
1004
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1005
        {
 
1006
                ((CMolecule*)g_oaMolecules[z])->m_iIndex = z;
 
1007
                for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
 
1008
                        ((CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[z2]])->m_iMolType = z;
 
1009
        }
 
1010
 
 
1011
 
 
1012
/*      for (z=0;z<g_oaMolecules.GetSize();z++)
 
1013
        {
 
1014
                m = (CMolecule*)g_oaMolecules[z];
 
1015
                sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
 
1016
                mprintf("Molecule %d Ring systems:\n",z+1);
 
1017
                for (z2=0;z2<sm->m_oaRings.GetSize();z2++)
 
1018
                {
 
1019
                        wa = (CxIntArray*)sm->m_oaRings[z2];
 
1020
                        mprintf("  - Ring %d: ",z2+1);
 
1021
                        for (z3=0;z3<wa->GetSize();z3++)
 
1022
                        {
 
1023
                                mprintf("%d",(*wa)[z3]);
 
1024
                                if (z3+1 < wa->GetSize())
 
1025
                                        mprintf(", ");
 
1026
                        }
 
1027
                        mprintf("\n");
 
1028
                }
 
1029
                mprintf("\n");
 
1030
        }*/
 
1031
 
 
1032
        ti = 0;
 
1033
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1034
        {
 
1035
                sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
 
1036
                ti += sm->m_oaRings.GetSize();
 
1037
        }
 
1038
 
 
1039
        mprintf("    Found %d rings.\n",ti);
 
1040
        if (ti != 0)
 
1041
        {
 
1042
                mprintf("    Refining ring systems...\n");
 
1043
 
 
1044
                try { wa = new CxIntArray("CTimeStep::ScanMolecules():wa"); } catch(...) { wa = NULL; }
 
1045
                if (wa == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1046
                
 
1047
                // Process ring systems
 
1048
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
1049
                {
 
1050
                        m = (CMolecule*)g_oaMolecules[z];
 
1051
                        sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
 
1052
                        if (sm->m_oaRings.GetSize() > 100)
 
1053
                        {
 
1054
                                eprintf("      More than 100 rings in molecule %d, skipping refinement. Ring system may be improper.\n",z+1);
 
1055
                                continue;
 
1056
                        }
 
1057
                        ti2 = 0;
 
1058
_again:
 
1059
                        ti2++;
 
1060
                        if (ti2 > 1000)
 
1061
                        {
 
1062
                                eprintf("      Too many iterations in molecule %d, aborting refinement. Ring system may be improper.\n",z+1);
 
1063
                                continue;
 
1064
                        }
 
1065
//                      mprintf("### again\n");
 
1066
                        for (z2=0;z2<sm->m_oaRings.GetSize();z2++)
 
1067
                        {
 
1068
                                waz2 = (CxIntArray*)sm->m_oaRings[z2];
 
1069
                                for (z3=z2+1;z3<sm->m_oaRings.GetSize();z3++)
 
1070
                                {
 
1071
                                        waz3 = (CxIntArray*)sm->m_oaRings[z3];
 
1072
 
 
1073
//                                      mprintf("*A* Checking if %d(%d) contains %d(%d)...\n",z2+1,waz2->GetSize(),z3+1,waz3->GetSize());
 
1074
                                        // Check if waz2 contains waz3
 
1075
                                        wa->SetSize(waz2->GetSize());
 
1076
                                        for (z4=0;z4<waz2->GetSize();z4++)
 
1077
                                                (*wa)[z4] = 0;
 
1078
                                        for (z4=0;z4<waz3->GetSize();z4++)
 
1079
                                        {
 
1080
                                                for (z5=0;z5<waz2->GetSize();z5++)
 
1081
                                                {
 
1082
                                                        if ((*waz3)[z4] == (*waz2)[z5])
 
1083
                                                        {
 
1084
                                                                (*wa)[z5] = 1;
 
1085
                                                                goto _found2;
 
1086
                                                        }
 
1087
                                                }
 
1088
                                                goto _notfound2;
 
1089
_found2:;
 
1090
                                        }
 
1091
//                                      mprintf("  Yes!\n");
 
1092
 
 
1093
                                        try { waneu = new CxIntArray("CTimeStep::ScanMolecules():waneu"); } catch(...) { waneu = NULL; }
 
1094
                                        if (waneu == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1095
                                        
 
1096
                                        for (z4=0;z4<waz2->GetSize();z4++)
 
1097
                                        {
 
1098
                                                if (z4 == 0)
 
1099
                                                {
 
1100
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4+1] == 0) || ((*wa)[waz2->GetSize()-1] == 0))
 
1101
                                                                waneu->Add((*waz2)[z4]);
 
1102
                                                } else if (z4 == waz2->GetSize()-1)
 
1103
                                                {
 
1104
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4-1] == 0) || ((*wa)[0] == 0))
 
1105
                                                                waneu->Add((*waz2)[z4]);
 
1106
                                                } else
 
1107
                                                {
 
1108
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4+1] == 0) || ((*wa)[z4-1] == 0))
 
1109
                                                                waneu->Add((*waz2)[z4]);
 
1110
                                                }
 
1111
                                        }
 
1112
//                                      mprintf("   Took %d from %d atoms from waz2.\n",waneu->GetSize(),waz2->GetSize());
 
1113
                                        i1 = waz2->GetSize();
 
1114
                                        delete waz2;
 
1115
                                        sm->m_oaRings[z2] = waneu;
 
1116
                                        if (waneu->GetSize() != i1)
 
1117
                                                goto _again;
 
1118
_notfound2:
 
1119
 
 
1120
//                                      mprintf("*B* Checking if %d contains %d...\n",z3+1,z2+1);
 
1121
                                        // Check if waz3 contains waz2
 
1122
                                        wa->SetSize(waz3->GetSize());
 
1123
                                        for (z4=0;z4<waz3->GetSize();z4++)
 
1124
                                                (*wa)[z4] = 0;
 
1125
                                        for (z4=0;z4<waz2->GetSize();z4++)
 
1126
                                        {
 
1127
                                                for (z5=0;z5<waz3->GetSize();z5++)
 
1128
                                                {
 
1129
                                                        if ((*waz2)[z4] == (*waz3)[z5])
 
1130
                                                        {
 
1131
                                                                (*wa)[z5] = 1;
 
1132
                                                                goto _found3;
 
1133
                                                        }
 
1134
                                                }
 
1135
                                                goto _notfound3;
 
1136
_found3:;
 
1137
                                        }
 
1138
//                                      mprintf("  Yes!\n");
 
1139
 
 
1140
                                        try { waneu = new CxIntArray("CTimeStep::ScanMolecules():waneu"); } catch(...) { waneu = NULL; }
 
1141
                                        if (waneu == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1142
                                        
 
1143
                                        for (z4=0;z4<waz3->GetSize();z4++)
 
1144
                                        {
 
1145
                                                if (z4 == 0)
 
1146
                                                {
 
1147
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4+1] == 0) || ((*wa)[waz3->GetSize()-1] == 0))
 
1148
                                                                waneu->Add((*waz3)[z4]);
 
1149
                                                } else if (z4 == waz3->GetSize()-1)
 
1150
                                                {
 
1151
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4-1] == 0) || ((*wa)[0] == 0))
 
1152
                                                                waneu->Add((*waz3)[z4]);
 
1153
                                                } else
 
1154
                                                {
 
1155
                                                        if (((*wa)[z4] == 0) || ((*wa)[z4+1] == 0) || ((*wa)[z4-1] == 0))
 
1156
                                                                waneu->Add((*waz3)[z4]);
 
1157
                                                }
 
1158
                                        }
 
1159
//                                      mprintf("   Took %d from %d atoms from waz3.\n",waneu->GetSize(),waz3->GetSize());
 
1160
                                        i1 = waz3->GetSize();
 
1161
                                        delete waz3;
 
1162
                                        sm->m_oaRings[z3] = waneu;
 
1163
                                        if (waneu->GetSize() != i1)
 
1164
                                                goto _again;
 
1165
_notfound3:;
 
1166
                                }
 
1167
                        }
 
1168
                }
 
1169
                delete wa;
 
1170
 
 
1171
                mprintf("    Assigning ring systems to molecule types...\n");
 
1172
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
1173
                {
 
1174
                        m = (CMolecule*)g_oaMolecules[z];
 
1175
                        sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
 
1176
                        for (z2=0;z2<sm->m_oaRings.GetSize();z2++)
 
1177
                        {
 
1178
                                wa = (CxIntArray*)sm->m_oaRings[z2];
 
1179
 
 
1180
                                try { waz2 = new CxIntArray("CTimeStep::ScanMolecules():waz2"); } catch(...) { waz2 = NULL; }
 
1181
                                if (waz2 == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1182
                                
 
1183
                                try { waz3 = new CxIntArray("CTimeStep::ScanMolecules():waz3"); } catch(...) { waz3 = NULL; }
 
1184
                                if (waz3 == NULL) NewException((double)sizeof(CxIntArray),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
1185
                                
 
1186
                                m->m_oaRingAtomTypes.Add(waz2);
 
1187
                                m->m_oaRingAtoms.Add(waz3);
 
1188
                                for (z3=0;z3<wa->GetSize();z3++)
 
1189
                                {
 
1190
                                        for (z4=0;z4<sm->m_baAtomIndex.GetSize();z4++)
 
1191
                                        {
 
1192
                                                for (z5=0;z5<((CxIntArray*)sm->m_oaAtomOffset[z4])->GetSize();z5++)
 
1193
                                                {
 
1194
                                                        if (((CxIntArray*)sm->m_oaAtomOffset[z4])->GetAt(z5) == wa->GetAt(z3))
 
1195
                                                        {
 
1196
                                                                waz2->Add(z4);
 
1197
                                                                waz3->Add(z5);
 
1198
                                                                goto _done;
 
1199
                                                        }
 
1200
                                                }
 
1201
                                        }
 
1202
_done:;
 
1203
                                }
 
1204
                        }
 
1205
                }
 
1206
 
 
1207
                mprintf("    Sorting rings by size...\n");
 
1208
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
1209
                {
 
1210
                        m = (CMolecule*)g_oaMolecules[z];
 
1211
 
 
1212
                        for (z2=0;z2<m->m_oaRingAtoms.GetSize();z2++)
 
1213
                        {
 
1214
                                i1 = 0;
 
1215
                                ti = -1;
 
1216
                                for (z3=z2;z3<m->m_oaRingAtoms.GetSize();z3++)
 
1217
                                {
 
1218
                                        if (((CxIntArray*)m->m_oaRingAtoms[z3])->GetSize() > i1)
 
1219
                                        {
 
1220
                                                i1 = ((CxIntArray*)m->m_oaRingAtoms[z3])->GetSize();
 
1221
                                                ti = z3;
 
1222
                                        }
 
1223
                                }
 
1224
                                if ((ti != -1) && (ti != z2))
 
1225
                                {
 
1226
                                        wa = (CxIntArray*)m->m_oaRingAtoms[z2];
 
1227
                                        m->m_oaRingAtoms[z2] = m->m_oaRingAtoms[ti];
 
1228
                                        m->m_oaRingAtoms[ti] = wa;
 
1229
                                        wa = (CxIntArray*)m->m_oaRingAtomTypes[z2];
 
1230
                                        m->m_oaRingAtomTypes[z2] = m->m_oaRingAtomTypes[ti];
 
1231
                                        m->m_oaRingAtomTypes[ti] = wa;
 
1232
                                }
 
1233
                        }
 
1234
                }
 
1235
        }
 
1236
 
 
1237
/*      for (z=0;z<g_oaMolecules.GetSize();z++)
 
1238
        {
 
1239
                m = (CMolecule*)g_oaMolecules[z];
 
1240
                sm = (CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex[0]];
 
1241
                mprintf("Molecule %d Ring systems:\n",z+1);
 
1242
                for (z2=0;z2<sm->m_oaRings.GetSize();z2++)
 
1243
                {
 
1244
                        wa = (CxIntArray*)sm->m_oaRings[z2];
 
1245
                        mprintf("  - Ring %d: ",z2+1);
 
1246
                        for (z3=0;z3<wa->GetSize();z3++)
 
1247
                        {
 
1248
                                mprintf("%d",(*wa)[z3]);
 
1249
                                if (z3+1 < wa->GetSize())
 
1250
                                        mprintf(", ");
 
1251
                        }
 
1252
                        mprintf("\n");
 
1253
                }
 
1254
                mprintf("\n");
 
1255
        }*/
 
1256
 
 
1257
/*      mprintf("\n%d Molekuelsorten gefunden.\n",g_oaMolecules.GetSize());
 
1258
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1259
        mprintf("Molekuel \"%s\": %d Atome gesamt, %d mal in der Simulation.\n",g_pMolecules[z].Name,g_pMolecules[z].AtomGes,g_pMolecules[z].Count);
 
1260
        */
 
1261
/*      mprintf("\n");
 
1262
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1263
        {
 
1264
                mprintf("%d ",z+1);
 
1265
                ((CMolecule*)g_oaMolecules[z])->Dump();
 
1266
        }*/
 
1267
        mprintf("    Molecule recognition finished.\n");
 
1268
        BTOUT; 
 
1269
        return true;
 
1270
}
 
1271
 
 
1272
 
 
1273
void CTimeStep::RECURSION_MegaTree(int i, char *ta, int depth, unsigned long bmask, bool w, int *stack)
 
1274
{
 
1275
        BTIN;
 
1276
        int z, z2;
 
1277
        int nblist[20], nbs;
 
1278
 
 
1279
        stack[depth] = i;
 
1280
        ta[i] = 1;
 
1281
        for (z=1;z<depth;z++)
 
1282
        {
 
1283
                if ((bmask & (int)pow(2.0,z)) != 0)
 
1284
                        mprintf(WHITE,"|  ");
 
1285
                                else mprintf("   ");
 
1286
        }
 
1287
        if (depth != 0)
 
1288
        {
 
1289
                if (w)
 
1290
                        mprintf(WHITE,"|--");
 
1291
                                else mprintf(WHITE,"`--");
 
1292
        }
 
1293
        mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[i]])->m_sName,i+1);
 
1294
        nbs = 0;
 
1295
        for (z=0;z<(long)m_iGesAtomCount;z++) // Schon mal alle Nachbarn raussuchen
 
1296
        {
 
1297
                if (z == i)
 
1298
                        continue;
 
1299
                if (BondRange(i,z,NULL))
 
1300
                {
 
1301
                        if (ta[z] != 0)
 
1302
                        {
 
1303
                                if ((depth > 0) && (z != stack[depth-1]))
 
1304
                                {
 
1305
                                        mprintf(GREEN,"  <-- Ring closure: ");
 
1306
                                        mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[stack[depth]]])->m_sName,stack[depth]+1);
 
1307
                                        z2 = depth-1;
 
1308
                                        while ((stack[z2] != z) && (z2 >= 0))
 
1309
                                        {
 
1310
                                                mprintf(" - %s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[stack[z2]]])->m_sName,stack[z2]+1);
 
1311
                                                z2--;
 
1312
                                        }
 
1313
                                        mprintf(" - %s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1);
 
1314
//                                      mprintf("Ringschluss! [d-1=%d,d=%d,i=%d] %s(%d)\n",stack[depth-1]+1,stack[depth]+1,i+1,((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_sName,z+1);
 
1315
                                }
 
1316
                                continue;
 
1317
                        }
 
1318
                        nblist[nbs] = z;
 
1319
                        nbs++;
 
1320
                }
 
1321
        }
 
1322
        mprintf("\n");
 
1323
        for (z=0;z<nbs;z++) // Fuer das aktuelle Atom z2 alle Nachbarn finden
 
1324
        {
 
1325
                if (ta[nblist[z]] != 0) // Der Nachbar wurde uns weggeschnappt -> Ringschluss
 
1326
                {
 
1327
                        for (z2=1;z2<depth+1;z2++)
 
1328
                        {
 
1329
                                if ((bmask & (int)pow(2.0,z2)) != 0)
 
1330
                                        mprintf(WHITE,"|  ");
 
1331
                                                else mprintf("   ");
 
1332
                        }
 
1333
                        if (z+1 < nbs)
 
1334
                                mprintf(WHITE,"|--");
 
1335
                                        else mprintf("`--");
 
1336
                        mprintf("%s(%d)",((CAtom*)g_oaAtoms[g_baAtomIndex[nblist[z]]])->m_sName,nblist[z]+1);
 
1337
                        mprintf(GREEN,"  <-- Ring closure\n");
 
1338
                } else
 
1339
                {
 
1340
                        if (z+1 == nbs)
 
1341
                                bmask -= (int)pow(2.0,depth+1);
 
1342
                        RECURSION_MegaTree(nblist[z],ta,/*sm,*/depth+1,bmask,(z+1==nbs)?false:true,stack);
 
1343
                }
 
1344
        }
 
1345
        BTOUT; 
 
1346
}
 
1347
 
 
1348
 
 
1349
void CTimeStep::PrintMegaTree()
 
1350
{
 
1351
        BTIN;
 
1352
        int z;
 
1353
        char ta[16384];
 
1354
        int stack[16384];
 
1355
 
 
1356
        for (z=0;z<16384;z++)
 
1357
                ta[z] = 0;
 
1358
        for (z=0;z<(long)m_iGesAtomCount;z++)
 
1359
        {
 
1360
                if (ta[z] != 0) // Dieses Atom wurde bereits in irgendein Molekuel eingebaut
 
1361
                        continue;
 
1362
                mprintf(YELLOW,"\nThe next molecule starts with %s(%d):\n",m_paLabels[z],z+1);
 
1363
                RECURSION_MegaTree(z,ta,0,0xFFFFFFFF,true,stack);
 
1364
        }
 
1365
        mprintf("\n");
 
1366
        BTOUT; 
 
1367
}
 
1368
 
 
1369
 
 
1370
void CTimeStep::PrintMatrix(bool onlyfirst, bool onlybind)
 
1371
{
 
1372
        BTIN;
 
1373
        int z, z2, z3, z4, z5, z6, z7, z8, ti, ti2;
 
1374
        float tf;
 
1375
        bool b, c, noh;
 
1376
        CxVector3 vec1, vec2;
 
1377
        CSingleMolecule *sm;
 
1378
        CMolecule *m;
 
1379
        CMolAtom *ma, *ma0;
 
1380
        CxIntArray *wa, *wat;
 
1381
 
 
1382
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1383
        {
 
1384
                m = (CMolecule*)g_oaMolecules[z];
 
1385
                for (z6=0;z6<(onlyfirst?1:m->m_laSingleMolIndex.GetSize());z6++)
 
1386
                {
 
1387
                        mprintf(YELLOW,"\n*** Molecule %d: %s; Representant %d; Distances in pm ***\n",z+1,m->m_sName,z6+1);
 
1388
                        if ((m->m_baAtomIndex.GetSize() == 1) && (m->m_waAtomCount[0] == 1))
 
1389
                        {
 
1390
                                mprintf("[only 1 Atom]\n");
 
1391
                                continue;
 
1392
                        }
 
1393
                        if (m->m_iAtomGes > 200)
 
1394
                        {
 
1395
                                mprintf(WHITE,"\n    This molecule has > 200 atoms. Output would flood the screen. Skipping.\n");
 
1396
                                continue;
 
1397
                        }
 
1398
                        noh = false;
 
1399
_matagain:
 
1400
                        if (m->m_oaRingAtoms.GetSize() != 0)
 
1401
                                mprintf(GREEN,"    (ring bonds are shown in green)\n");
 
1402
                        mprintf("\n");
 
1403
                        mprintf("   ");
 
1404
                        for (z2=0;z2<m->m_baAtomIndex.GetSize();z2++)
 
1405
                        {
 
1406
                                if (noh) // Skip H atoms
 
1407
                                        if (mystricmp(((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,"H") == 0)
 
1408
                                                continue;
 
1409
                                for (z3=0;z3<m->m_waAtomCount[z2];z3++)
 
1410
                                {
 
1411
                                        if (((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName[1] == 0)
 
1412
                                                mprintf(" ");
 
1413
                                        mprintf(WHITE,"%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,z3+1);  
 
1414
                                        if (z3+1 < 10)
 
1415
                                                mprintf(" ");
 
1416
                                }
 
1417
                        }
 
1418
                        mprintf("\n");
 
1419
                        for (z2=0;z2<m->m_baAtomIndex.GetSize();z2++)
 
1420
                        {
 
1421
                                if (noh) // Skip H atoms
 
1422
                                        if (mystricmp(((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,"H") == 0)
 
1423
                                                continue;
 
1424
                                for (z3=0;z3<m->m_waAtomCount[z2];z3++)
 
1425
                                {
 
1426
                                        mprintf(WHITE,"%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,z3+1);
 
1427
                                        if (((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName[1] == 0)
 
1428
                                                mprintf(" ");
 
1429
                                        if (z3+1 < 10)
 
1430
                                                mprintf(" ");
 
1431
                                        for (z4=0;z4<m->m_baAtomIndex.GetSize();z4++)
 
1432
                                        {
 
1433
                                                if (noh) // Skip H atoms
 
1434
                                                        if (mystricmp(((CAtom*)g_oaAtoms[m->m_baAtomIndex[z4]])->m_sName,"H") == 0)
 
1435
                                                                continue;
 
1436
                                                for (z5=0;z5<m->m_waAtomCount[z4];z5++)
 
1437
                                                {
 
1438
                                                        if ((z2 == z4) && (z3 == z5))
 
1439
                                                        {
 
1440
                                                                mprintf(BLUE,"*** ");
 
1441
                                                                continue;
 
1442
                                                        }
 
1443
                                                        ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z6]])->m_oaAtomOffset[z2])->GetAt(z3);
 
1444
                                                        vec1 = g_TimeStep.m_vaCoords[ti];
 
1445
                                                        ti2 = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z6]])->m_oaAtomOffset[z4])->GetAt(z5);
 
1446
                                                        vec2 = g_TimeStep.m_vaCoords[ti2];
 
1447
                                                        vec1 -= vec2;
 
1448
                                                        tf = vec1.GetLength();
 
1449
                                                        if ((g_TimeStep.BondRange(ti,ti2,NULL)) || (!onlybind))
 
1450
                                                        {
 
1451
                                                                for (z8=0;z8<m->m_oaRingAtomTypes.GetSize();z8++)
 
1452
                                                                {
 
1453
                                                                        wat = (CxIntArray*)m->m_oaRingAtomTypes[z8];
 
1454
                                                                        wa = (CxIntArray*)m->m_oaRingAtoms[z8];
 
1455
                                                                        for (z7=0;z7<wa->GetSize();z7++)
 
1456
                                                                        {
 
1457
                                                                                if (((*wat)[z7] == z2) && ((*wa)[z7] == z3))
 
1458
                                                                                {
 
1459
                                                                                        if (z7 == 0)
 
1460
                                                                                        {
 
1461
                                                                                                if (((*wat)[z7+1] == z4) && ((*wa)[z7+1] == z5))
 
1462
                                                                                                        goto _green;
 
1463
                                                                                                if (((*wat)[wa->GetSize()-1] == z4) && ((*wa)[wa->GetSize()-1] == z5))
 
1464
                                                                                                        goto _green;
 
1465
                                                                                        } else if (z7 == wa->GetSize()-1)
 
1466
                                                                                        {
 
1467
                                                                                                if (((*wat)[0] == z4) && ((*wa)[0] == z5))
 
1468
                                                                                                        goto _green;
 
1469
                                                                                                if (((*wat)[z7-1] == z4) && ((*wa)[z7-1] == z5))
 
1470
                                                                                                        goto _green;
 
1471
                                                                                        } else
 
1472
                                                                                        {
 
1473
                                                                                                if (((*wat)[z7+1] == z4) && ((*wa)[z7+1] == z5))
 
1474
                                                                                                        goto _green;
 
1475
                                                                                                if (((*wat)[z7-1] == z4) && ((*wa)[z7-1] == z5))
 
1476
                                                                                                        goto _green;
 
1477
                                                                                        }
 
1478
                                                                                }
 
1479
                                                                        }
 
1480
                                                                }
 
1481
                                                                mprintf("%3.0f ",tf);
 
1482
                                                                continue;
 
1483
_green:
 
1484
                                                                mprintf(GREEN,"%3.0f ",tf);
 
1485
                                                        } else mprintf(" -  ");
 
1486
                                                }
 
1487
                                        }       
 
1488
                                        mprintf("\n");
 
1489
                                }
 
1490
                        }
 
1491
                        if ((!noh) && (m->m_iAtomGes > 30))
 
1492
                        {
 
1493
                                mprintf(WHITE,"\n    This was a very large molecule.\n    Printing the matrix again without H atoms.\n");
 
1494
                                noh = true;
 
1495
                                goto _matagain;
 
1496
                        }
 
1497
//                      if (((!onlyfirst) && ((z2 < ((CMolecule*)g_oaMolecules[z])->Elements-1) || (g_oaMolecules.GetSize()-1))) || (z < g_oaMolecules.GetSize()-1))
 
1498
//                              mprintf(">>>");
 
1499
                }
 
1500
 
 
1501
                if (m->m_oaRingAtoms.GetSize() != 0)
 
1502
                {
 
1503
                        mprintf("\n");
 
1504
                        for (z2=0;z2<m->m_oaRingAtoms.GetSize();z2++)
 
1505
                        {
 
1506
                                mprintf("    %d-ring: ",((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize());
 
1507
                                if (((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize() > 20)
 
1508
                                {
 
1509
                                        for (z3=0;z3<5;z3++)
 
1510
                                        {
 
1511
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[((CxIntArray*)m->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)m->m_oaRingAtoms[z2])->GetAt(z3)+1);
 
1512
                                                if (z3+1 < ((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize())
 
1513
                                                        mprintf(" - ");
 
1514
                                        }
 
1515
                                        mprintf(RED,"...");
 
1516
                                        mprintf(" - ");
 
1517
                                        for (z3=((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize()-5;z3<((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize();z3++)
 
1518
                                        {
 
1519
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[((CxIntArray*)m->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)m->m_oaRingAtoms[z2])->GetAt(z3)+1);
 
1520
                                                if (z3+1 < ((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize())
 
1521
                                                        mprintf(" - ");
 
1522
                                        }
 
1523
                                } else
 
1524
                                {
 
1525
                                        for (z3=0;z3<((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize();z3++)
 
1526
                                        {
 
1527
                                                mprintf("%s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[((CxIntArray*)m->m_oaRingAtomTypes[z2])->GetAt(z3)]])->m_sName,((CxIntArray*)m->m_oaRingAtoms[z2])->GetAt(z3)+1);
 
1528
                                                if (z3+1 < ((CxIntArray*)m->m_oaRingAtoms[z2])->GetSize())
 
1529
                                                        mprintf(" - ");
 
1530
                                        }
 
1531
                                }
 
1532
                                mprintf("\n");
 
1533
                                if (z2 >= 99)
 
1534
                                {
 
1535
                                        mprintf(RED,"\n    Only showing the first 100 rings.\n");
 
1536
                                        break;
 
1537
                                }
 
1538
                        }
 
1539
                }
 
1540
 
 
1541
                c = false;
 
1542
                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[0]];
 
1543
                for (z2=0;z2<m->m_baAtomIndex.GetSize();z2++)
 
1544
                {
 
1545
                        b = false;
 
1546
                        ma = NULL;
 
1547
                        for (z3=0;z3<sm->m_oaMolAtoms.GetSize();z3++)
 
1548
                        {
 
1549
                                if (((CMolAtom*)sm->m_oaMolAtoms[z3])->m_iType != z2)
 
1550
                                        continue;
 
1551
                                ma0 = ma;
 
1552
                                ma = (CMolAtom*)sm->m_oaMolAtoms[z3];
 
1553
                                if (ma0 == NULL)
 
1554
                                        continue;
 
1555
                                z4 = ma0->m_iNumber;
 
1556
                                if (ma->m_fAtomCode == ma0->m_fAtomCode)
 
1557
                                {
 
1558
                                        if (b)
 
1559
                                        {
 
1560
                                                mprintf(", %s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,ma->m_iNumber+1);
 
1561
                                        } else
 
1562
                                        {
 
1563
                                                if (!c)
 
1564
                                                {
 
1565
                                                        c = true;
 
1566
                                                        mprintf("\n");
 
1567
                                                }
 
1568
                                                mprintf("    Atoms %s%d, %s%d",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,z4+1,((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_sName,ma->m_iNumber+1);
 
1569
                                                b = true;
 
1570
                                        }
 
1571
                                } else if (b)
 
1572
                                {
 
1573
                                        mprintf(" are equivalent.\n");
 
1574
                                        b = false;
 
1575
                                }
 
1576
                        }
 
1577
                        if (b)
 
1578
                                mprintf(" are equivalent.\n");
 
1579
                }
 
1580
        } // Tabelle Ende
 
1581
        BTOUT; 
 
1582
}
 
1583
 
 
1584
 
 
1585
void CTimeStep::Transform(const CxMatrix3 &mat)
 
1586
{
 
1587
        BTIN;
 
1588
        int z;
 
1589
//      CxVector3 v;
 
1590
 
 
1591
        for (z=0;z<g_iGesVirtAtomCount;z++)
 
1592
        {
 
1593
//              if (z < g_iGesAtomCount)
 
1594
//                      mprintf("@ %2d: ( %g | %g | %g ) --> ",z,m_vaCoords[z][0],m_vaCoords[z][1],m_vaCoords[z][2]);
 
1595
                m_vaCoords[z] = mat * m_vaCoords[z];
 
1596
//              if (z < g_iGesAtomCount)
 
1597
//                      mprintf("( %g | %g | %g )\n",m_vaCoords[z][0],m_vaCoords[z][1],m_vaCoords[z][2]);
 
1598
        }
 
1599
 
 
1600
        if (g_bUseVelocities)
 
1601
                for (z=0;z<g_iGesVirtAtomCount;z++)
 
1602
                        m_vaVelocities[z] = mat * m_vaVelocities[z];
 
1603
 
 
1604
        if (g_bUseForces)
 
1605
                for (z=0;z<g_iGesVirtAtomCount;z++)
 
1606
                        m_vaForces[z] = mat * m_vaForces[z];
 
1607
        BTOUT; 
 
1608
}
 
1609
 
 
1610
 
 
1611
void CTimeStep::Transform(const CxDMatrix3 &mat)
 
1612
{
 
1613
        BTIN;
 
1614
        int z;
 
1615
 
 
1616
        for (z=0;z<g_iGesVirtAtomCount;z++)
 
1617
                m_vaCoords[z] = mat * m_vaCoords[z];
 
1618
 
 
1619
        if (g_bUseVelocities)
 
1620
                for (z=0;z<g_iGesVirtAtomCount;z++)
 
1621
                        m_vaVelocities[z] = mat * m_vaVelocities[z];
 
1622
 
 
1623
        if (g_bUseForces)
 
1624
                for (z=0;z<g_iGesVirtAtomCount;z++)
 
1625
                        m_vaForces[z] = mat * m_vaForces[z];
 
1626
        BTOUT; 
 
1627
}
 
1628
 
 
1629
 
 
1630
void CTimeStep::Transform(const CxQuaternion &q)
 
1631
{
 
1632
        BTIN;
 
1633
        int z;
 
1634
 
 
1635
        for (z=0;z<g_iGesVirtAtomCount;z++)
 
1636
                m_vaCoords[z] = q.Transform(m_vaCoords[z]);
 
1637
 
 
1638
        if (g_bUseVelocities)
 
1639
                for (z=0;z<g_iGesVirtAtomCount;z++)
 
1640
                        m_vaVelocities[z] = q.Transform(m_vaVelocities[z]);
 
1641
 
 
1642
        if (g_bUseForces)
 
1643
                for (z=0;z<g_iGesVirtAtomCount;z++)
 
1644
                        m_vaForces[z] = q.Transform(m_vaForces[z]);
 
1645
        BTOUT; 
 
1646
}
 
1647
 
 
1648
 
 
1649
void CTimeStep::SubVelocities(const CxVector3 &vec)
 
1650
{
 
1651
        BTIN;
 
1652
        int z;
 
1653
 
 
1654
        for (z=0;z<g_iGesVirtAtomCount;z++)
 
1655
                m_vaVelocities[z] -= vec;
 
1656
        BTOUT; 
 
1657
}
 
1658
 
 
1659
 
 
1660
void CTimeStep::FoldMolecules()
 
1661
{
 
1662
        BTIN;
 
1663
        int z, z2, z3, z4;
 
1664
        CxVector3 v, vc;
 
1665
        CMolecule *m;
 
1666
        CSingleMolecule *sm;
 
1667
 
 
1668
        if (!g_bPeriodic)
 
1669
                return;
 
1670
 
 
1671
//      mprintf("*** Fold ***\n");
 
1672
        
 
1673
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1674
        {
 
1675
                m = (CMolecule*)g_oaMolecules[z];
 
1676
                if (m->m_bPseudo)
 
1677
                        continue;
 
1678
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
1679
                {
 
1680
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
1681
 
 
1682
//                      mprintf("\n%d, %d",m->m_baAtomIndex.GetSize(),((CxIntArray*)sm->m_oaAtomOffset[m->m_baAtomIndex.GetSize()-1])->GetAt(1));
 
1683
 
 
1684
                        // Massenzentrum
 
1685
                        v = m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[m->m_baAtomIndex.GetSize()-1])->GetAt(1)];
 
1686
 
 
1687
/*                      mprintf("  .Mol ");
 
1688
                        v.Dump();
 
1689
                        mprintf("\n");                  
 
1690
 
 
1691
*/                      vc = CxVector3(0,0,0);
 
1692
                        
 
1693
                        if (g_bPeriodicX)
 
1694
                        {
 
1695
                                while (v[0] < -g_fBoxX/2) { v[0] += g_fBoxX; vc[0] += g_fBoxX; }
 
1696
                                while (v[0] >= g_fBoxX/2) { v[0] -= g_fBoxX; vc[0] -= g_fBoxX; }
 
1697
                        }
 
1698
                        if (g_bPeriodicY)
 
1699
                        {
 
1700
                                while (v[1] < -g_fBoxY/2) { v[1] += g_fBoxY; vc[1] += g_fBoxY; }
 
1701
                                while (v[1] >= g_fBoxY/2) { v[1] -= g_fBoxY; vc[1] -= g_fBoxY; }
 
1702
                        }
 
1703
                        if (g_bPeriodicZ)
 
1704
                        {
 
1705
                                while (v[2] < -g_fBoxZ/2) { v[2] += g_fBoxZ; vc[2] += g_fBoxZ; }
 
1706
                                while (v[2] >= g_fBoxZ/2) { v[2] -= g_fBoxZ; vc[2] -= g_fBoxZ; }
 
1707
                        }
 
1708
                        
 
1709
                        if ((vc[0] == 0) && (vc[1] == 0) && (vc[2] == 0))
 
1710
                                 continue;
 
1711
                        
 
1712
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
1713
                                for (z4=0;z4<m->m_waAtomCount[z3];z4++)
 
1714
                                         m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] += vc;
 
1715
 
 
1716
                        if (g_bWannier)
 
1717
                                for (z3=0;z3<sm->m_laWannier.GetSize();z3++)
 
1718
                                         m_vaCoords[sm->m_laWannier[z3]] += vc;
 
1719
                }
 
1720
        }
 
1721
//      mprintf("   Fold Done\n");
 
1722
        BTOUT;
 
1723
}
 
1724
 
 
1725
 
 
1726
void CTimeStep::FoldAtoms()
 
1727
{
 
1728
        BTIN;
 
1729
        int z;
 
1730
 
 
1731
        if (!g_bPeriodic)
 
1732
                return;
 
1733
 
 
1734
        for (z=0;z<g_iGesVirtAtomCount;z++)
 
1735
        {
 
1736
                if (g_bPeriodicX)
 
1737
                {
 
1738
                        while (m_vaCoords[z][0] < -g_fBoxX/2) m_vaCoords[z][0] += g_fBoxX;
 
1739
                        while (m_vaCoords[z][0] >= g_fBoxX/2) m_vaCoords[z][0] -= g_fBoxX;
 
1740
                }
 
1741
 
 
1742
                if (g_bPeriodicY)
 
1743
                {
 
1744
                        while (m_vaCoords[z][1] < -g_fBoxY/2) m_vaCoords[z][1] += g_fBoxY;
 
1745
                        while (m_vaCoords[z][1] >= g_fBoxY/2) m_vaCoords[z][1] -= g_fBoxY;
 
1746
                }
 
1747
 
 
1748
                if (g_bPeriodicZ)
 
1749
                {
 
1750
                        while (m_vaCoords[z][2] < -g_fBoxZ/2) m_vaCoords[z][2] += g_fBoxZ;
 
1751
                        while (m_vaCoords[z][2] >= g_fBoxZ/2) m_vaCoords[z][2] -= g_fBoxZ;
 
1752
                }
 
1753
        }
 
1754
        BTOUT; 
 
1755
}
 
1756
 
 
1757
 
 
1758
void CTimeStep::CenterPos(const CxVector3 &vec)
 
1759
{
 
1760
        BTIN;
 
1761
        int z/*, z2, z3, z4*/;
 
1762
 
 
1763
/*       for (z=0;z<g_oaMolecules.GetSize();z++)
 
1764
                 for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->Count;z2++)
 
1765
                         for (z3=0;z3<((CMolecule*)g_oaMolecules[z])->Elements;z3++)
 
1766
                                 for (z4=0;z4<((CMolecule*)g_oaMolecules[z])->AtomCount[z3];z4++)
 
1767
                                         m_vaCoords[((CSingleMolecule*)g_oaSingleMolecules[((CMolecule*)g_oaMolecules[z])->SingleMolIndex[z2]])->m_iAtomOffset[z3][z4]] -= vec;*/
 
1768
 
 
1769
        for (z=0;z<g_iGesVirtAtomCount;z++)
 
1770
                m_vaCoords[z] -= vec;
 
1771
        BTOUT; 
 
1772
}
 
1773
 
 
1774
 
 
1775
void CTimeStep::AddAtoms()
 
1776
{
 
1777
        BTIN;
 
1778
        char *q;
 
1779
        int z;
 
1780
//      bool labeledatoms;
 
1781
 
 
1782
//      labeledatoms = false;
 
1783
        for (z=0;z<(long)m_iGesAtomCount;z++)
 
1784
        {
 
1785
                q = (char*)m_paLabels[z];
 
1786
                q+=strlen(q)-1;
 
1787
/*              while ((*q >= '0') && (*q <= '9'))
 
1788
                {
 
1789
                        if (!labeledatoms)
 
1790
                        {
 
1791
                                mprintf(">>>\n>>> The atoms in the input file are numbered.\n>>> Ignoring this, using own numbers ;-)\n>>>\n");
 
1792
                                labeledatoms = true;
 
1793
                        }
 
1794
                        *q = 0;
 
1795
                        q--;
 
1796
                }*/
 
1797
//              printf("AddAtoms: \"%s\"\n",q);
 
1798
                xAddAtom((char*)m_paLabels[z]);
 
1799
        }
 
1800
        BTOUT; 
 
1801
}
 
1802
 
 
1803
 
 
1804
void CTimeStep::WriteTimestep(FILE *a)
 
1805
{
 
1806
        BTIN;
 
1807
        int z, z2, z3, z4, z0;
 
1808
        CMolecule *m;
 
1809
        CSingleMolecule *sm;
 
1810
 
 
1811
        if (g_bSaveVirtAtoms)
 
1812
                mfprintf(a,"  %d\n",g_iGesVirtAtomCount);
 
1813
                        else mfprintf(a,"  %d\n",g_iGesAtomCount);
 
1814
        if (m_pComment != NULL)
 
1815
                mfprintf(a,"%s\n",m_pComment);
 
1816
                        else mfprintf(a,"\n");
 
1817
 
 
1818
        if (g_bWriteAtomwise)
 
1819
        {
 
1820
                for (z0=0;z0<g_oaAtoms.GetSize();z0++)
 
1821
                {
 
1822
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1823
                        {
 
1824
                                m = (CMolecule*)g_oaMolecules[z];
 
1825
                                if (m->m_bPseudo)
 
1826
                                        continue;
 
1827
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
1828
                                {
 
1829
                                        if (m->m_baAtomIndex[z3] != z0)
 
1830
                                                continue;
 
1831
                                        if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
 
1832
                                                continue;
 
1833
                                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
1834
                                        {
 
1835
                                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
1836
                                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
1837
                                                        mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
 
1838
                                        }
 
1839
                                }
 
1840
                        }
 
1841
                }
 
1842
        } else
 
1843
        {
 
1844
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
1845
                {
 
1846
                        m = (CMolecule*)g_oaMolecules[z];
 
1847
                        if (m->m_bPseudo)
 
1848
                                continue;
 
1849
                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
1850
                        {
 
1851
                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
1852
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
1853
                                {
 
1854
                                        if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
 
1855
                                                continue;
 
1856
                                        for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
1857
                                                mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
 
1858
                                }
 
1859
                        }
 
1860
                }
 
1861
        }
 
1862
                        
 
1863
        BTOUT; 
 
1864
}
 
1865
 
 
1866
        
 
1867
void CTimeStep::WriteTimestepNb(FILE *a, CNbSet *nbs, int singlemol)
 
1868
{
 
1869
        BTIN;
 
1870
        int z, z2, z3, z4, z0, n, ti;
 
1871
        CMolecule *m;
 
1872
        CSingleMolecule *sm;
 
1873
        CConditionGroup *cg;
 
1874
        CConditionSubGroup *cs;
 
1875
        CNbSearch *nb;
 
1876
 
 
1877
        n = 0;
 
1878
 
 
1879
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1880
        {
 
1881
                if (nbs->m_oaConditionGroups[z] == NULL)
 
1882
                        continue;
 
1883
                m = (CMolecule*)g_oaMolecules[z];
 
1884
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
1885
                {
 
1886
                        if (((CConditionGroup*)nbs->m_oaConditionGroups[z])->Contains(z2))
 
1887
                        {
 
1888
                                n += m->m_iAtomGes;
 
1889
                                if (!g_bSaveVirtAtoms)
 
1890
                                        n -= m->m_laVirtualAtoms.GetSize();
 
1891
                        }
 
1892
                }
 
1893
        }
 
1894
 
 
1895
        mfprintf(a,"  %d\n",n);
 
1896
 
 
1897
        mfprintf(a,"# Step %d",((int)g_iSteps));
 
1898
 
 
1899
        if (singlemol >= 0)
 
1900
        {
 
1901
                sm = (CSingleMolecule*)g_oaSingleMolecules[singlemol];
 
1902
                m = (CMolecule*)g_oaMolecules[sm->m_iMolType];
 
1903
                if (!g_bSaveVirtAtoms)
 
1904
                {
 
1905
                        if (g_bWriteAtomwise)
 
1906
                                mfprintf(a,", RM=%s[%d]",m->m_sName,sm->m_iMolSMIndex+1);
 
1907
                                        else mfprintf(a,", RM=%s[%d] (%d atoms)",m->m_sName,sm->m_iMolSMIndex+1,m->m_iAtomGes-m->m_laVirtualAtoms.GetSize());
 
1908
                } else
 
1909
                {
 
1910
                        if (g_bWriteAtomwise)
 
1911
                                mfprintf(a,", RM=%s[%d]",m->m_sName,sm->m_iMolSMIndex+1);
 
1912
                                        else mfprintf(a,", RM=%s[%d] (%d atoms)",m->m_sName,sm->m_iMolSMIndex+1,m->m_iAtomGes);
 
1913
                }
 
1914
        }
 
1915
 
 
1916
        if (g_bEnvWriteDetailedInfo)
 
1917
        {
 
1918
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
1919
                {
 
1920
                        if (nbs->m_oaConditionGroups[z] == NULL)
 
1921
                                continue;
 
1922
                        m = (CMolecule*)g_oaMolecules[z];
 
1923
 
 
1924
                        cg = (CConditionGroup*)nbs->m_oaConditionGroups[z];
 
1925
 
 
1926
                        if (g_bEnvSortNb)
 
1927
                        {
 
1928
                                nb = NULL;
 
1929
                                if (cg->m_oaConditionSubGroups.GetSize() == 1)
 
1930
                                {
 
1931
                                        cs = (CConditionSubGroup*)cg->m_oaConditionSubGroups[0];
 
1932
                                        if (cs->m_oaConditions.GetSize() == 1)
 
1933
                                                nb = (CNbSearch*)cs->m_oaConditions[0];
 
1934
                                }
 
1935
                                if (nb == NULL)
 
1936
                                        goto _nosortinfo;
 
1937
 
 
1938
                                if (nb->m_iNbCountMin <= -1)
 
1939
                                        goto _nosortinfo;
 
1940
 
 
1941
                                for (z2=nb->m_iNbCountMin;z2<=nb->m_iNbCountMax;z2++)
 
1942
                                {
 
1943
                                        ti = nb->m_pNbSort[z2].m_iOM;
 
1944
                                        if (!g_bSaveVirtAtoms)
 
1945
                                        {
 
1946
                                                if (m->m_laSingleMolIndex[ti] != singlemol)
 
1947
                                                {
 
1948
                                                        if (g_bWriteAtomwise)
 
1949
                                                                mfprintf(a,", %s[%d] d=%.3fpm",m->m_sName,z2+1,nb->m_pNbSort[z2].m_fMinDist);
 
1950
                                                                        else mfprintf(a,", %s[%d] d=%.3fpm (%d atoms)",m->m_sName,ti+1,nb->m_pNbSort[z2].m_fMinDist,m->m_iAtomGes-m->m_laVirtualAtoms.GetSize());
 
1951
                                                }
 
1952
                                        } else
 
1953
                                        {
 
1954
                                                if (m->m_laSingleMolIndex[ti] != singlemol)
 
1955
                                                {
 
1956
                                                        if (g_bWriteAtomwise)
 
1957
                                                                mfprintf(a,", %s[%d] d=%.3fpm",m->m_sName,z2+1,nb->m_pNbSort[z2].m_fMinDist);
 
1958
                                                                        else mfprintf(a,", %s[%d] d=%.3fpm (%d atoms)",m->m_sName,ti+1,nb->m_pNbSort[z2].m_fMinDist,m->m_iAtomGes);
 
1959
                                                }
 
1960
                                        }
 
1961
                                }
 
1962
                        } else
 
1963
                        {
 
1964
_nosortinfo:
 
1965
                                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
1966
                                {
 
1967
                                        if (cg->Contains(z2))
 
1968
                                        {
 
1969
                                                if (!g_bSaveVirtAtoms)
 
1970
                                                {
 
1971
                                                        if (m->m_laSingleMolIndex[z2] != singlemol)
 
1972
                                                        {
 
1973
                                                                if (g_bWriteAtomwise)
 
1974
                                                                        mfprintf(a,", %s[%d]",m->m_sName,z2+1);
 
1975
                                                                                else mfprintf(a,", %s[%d] (%d atoms)",m->m_sName,z2+1,m->m_iAtomGes-m->m_laVirtualAtoms.GetSize());
 
1976
                                                        }
 
1977
                                                } else
 
1978
                                                {
 
1979
                                                        if (m->m_laSingleMolIndex[z2] != singlemol)
 
1980
                                                        {
 
1981
                                                                if (g_bWriteAtomwise)
 
1982
                                                                        mfprintf(a,", %s[%d]",m->m_sName,z2+1);
 
1983
                                                                                else mfprintf(a,", %s[%d] (%d atoms)",m->m_sName,z2+1,m->m_iAtomGes);
 
1984
                                                        }
 
1985
                                                }
 
1986
                                        }
 
1987
                                }
 
1988
                        }
 
1989
                }
 
1990
        }
 
1991
 
 
1992
        mfprintf(a,"\n");
 
1993
 
 
1994
        if (g_bWriteAtomwise)
 
1995
        {
 
1996
                for (z0=0;z0<g_oaAtoms.GetSize();z0++)
 
1997
                {
 
1998
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
1999
                        {
 
2000
                                if (nbs->m_oaConditionGroups[z] == NULL)
 
2001
                                        continue;
 
2002
                                m = (CMolecule*)g_oaMolecules[z];
 
2003
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
2004
                                {
 
2005
                                        if (m->m_baAtomIndex[z3] != z0)
 
2006
                                                continue;
 
2007
                                        if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
 
2008
                                                continue;
 
2009
                                        for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
2010
                                        {
 
2011
                                                if (((CConditionGroup*)nbs->m_oaConditionGroups[z])->Contains(z2))
 
2012
                                                {
 
2013
                                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
2014
                                                        for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
2015
                                                                mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
 
2016
                                                }
 
2017
                                        }
 
2018
                                }
 
2019
                        }
 
2020
                }
 
2021
        } else
 
2022
        {
 
2023
                if (singlemol >= 0)
 
2024
                {
 
2025
                        sm = (CSingleMolecule*)g_oaSingleMolecules[singlemol];
 
2026
                        m = (CMolecule*)g_oaMolecules[sm->m_iMolType];
 
2027
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
2028
                        {
 
2029
                                if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
 
2030
                                        continue;
 
2031
                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
2032
                                        mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
 
2033
                        }
 
2034
                }
 
2035
 
 
2036
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
2037
                {
 
2038
                        if (nbs->m_oaConditionGroups[z] == NULL)
 
2039
                                continue;
 
2040
                        m = (CMolecule*)g_oaMolecules[z];
 
2041
                        cg = (CConditionGroup*)nbs->m_oaConditionGroups[z];
 
2042
 
 
2043
                        if (g_bEnvSortNb)
 
2044
                        {
 
2045
                                nb = NULL;
 
2046
                                if (cg->m_oaConditionSubGroups.GetSize() == 1)
 
2047
                                {
 
2048
                                        cs = (CConditionSubGroup*)cg->m_oaConditionSubGroups[0];
 
2049
                                        if (cs->m_oaConditions.GetSize() == 1)
 
2050
                                                nb = (CNbSearch*)cs->m_oaConditions[0];
 
2051
                                }
 
2052
                                if (nb == NULL)
 
2053
                                        goto _nosort;
 
2054
 
 
2055
                                if (nb->m_iNbCountMin <= -1)
 
2056
                                        goto _nosort;
 
2057
 
 
2058
                                for (z2=nb->m_iNbCountMin;z2<=nb->m_iNbCountMax;z2++)
 
2059
                                {
 
2060
                                        ti = nb->m_pNbSort[z2].m_iOM;
 
2061
 
 
2062
                                        if (m->m_laSingleMolIndex[ti] == singlemol)
 
2063
                                                continue;
 
2064
 
 
2065
                                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[ti]];
 
2066
                                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
2067
                                        {
 
2068
                                                if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
 
2069
                                                        continue;
 
2070
                                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
2071
                                                        mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
 
2072
                                        }
 
2073
                                }
 
2074
                        } else
 
2075
                        {
 
2076
_nosort:
 
2077
                                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
2078
                                {
 
2079
                                        if (((CConditionGroup*)nbs->m_oaConditionGroups[z])->Contains(z2))
 
2080
                                        {
 
2081
                                                if (m->m_laSingleMolIndex[z2] == singlemol)
 
2082
                                                        continue;
 
2083
                                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
2084
                                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
2085
                                                {
 
2086
                                                        if ((!g_bSaveVirtAtoms) && (m->m_baAtomIndex[z3] == g_iVirtAtomType))
 
2087
                                                                continue;
 
2088
                                                        for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
2089
                                                                mfprintf(a,"  %s  %8.5f  %8.5f  %8.5f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1]/100.0f,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]/100.0f);
 
2090
                                                }
 
2091
                                        }
 
2092
                                }
 
2093
                        }
 
2094
                }
 
2095
        }
 
2096
                        
 
2097
        BTOUT; 
 
2098
}
 
2099
 
 
2100
 
 
2101
/*void CTimeStep::WriteTimestepNb(int refmol, FILE *a)
 
2102
{
 
2103
        BTIN;
 
2104
        int z, c, z2, z3, z4, z0;
 
2105
        int ti;
 
2106
        CMolecule *m, *m2;
 
2107
 
 
2108
        m = (CMolecule*)g_oaMolecules[g_iFixMol];
 
2109
 
 
2110
        c = 0;
 
2111
        if (g_bRefEnvVirt)
 
2112
        {
 
2113
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
2114
                        c += g_pNbAll->m_waScanNeighborCount[z]*((CMolecule*)g_oaMolecules[z])->m_iAtomGes;
 
2115
                if (g_bSaveRefWithEnv)
 
2116
                        c += m->m_iAtomGes;
 
2117
        } else
 
2118
        {
 
2119
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
2120
                        c += g_pNbAll->m_waScanNeighborCount[z]*(((CMolecule*)g_oaMolecules[z])->m_iAtomGes-((CMolecule*)g_oaMolecules[z])->m_waVirtualAtoms.GetSize());
 
2121
                if (g_bSaveRefWithEnv)
 
2122
                        c += m->m_iAtomGes - m->m_waVirtualAtoms.GetSize();
 
2123
        }
 
2124
 
 
2125
        mfprintf(a,"  %d\n\n",c);
 
2126
 
 
2127
        if (g_bRefEnvAtomwise)
 
2128
        {
 
2129
                for (z0=0;z0<g_oaAtoms.GetSize();z0++)
 
2130
                {
 
2131
                        if (g_bSaveRefWithEnv)
 
2132
                        {
 
2133
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
2134
                                {
 
2135
                                        if (m->m_baAtomIndex[z3] != z0)
 
2136
                                                continue;
 
2137
                                        if (!g_bRefEnvVirt)
 
2138
                                                if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
 
2139
                                                        continue;
 
2140
                                        for (z4=0;z4<m->m_waAtomCount[z3];z4++)
 
2141
                                        {
 
2142
                                                ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]])->m_oaAtomOffset[z3])->GetAt(z4);
 
2143
                                                mfprintf(a,"  %s  %f  %f  %f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0f,m_vaCoords[ti][1]/100.0f,m_vaCoords[ti][2]/100.0f);
 
2144
                                        }
 
2145
                                }
 
2146
                        }
 
2147
                        for (z=0;z<g_oaMolecules.GetSize();z++)
 
2148
                        {
 
2149
                                m2 = (CMolecule*)g_oaMolecules[z];
 
2150
                                for (z2=0;z2<g_pNbAll->m_waScanNeighborCount[z];z2++)
 
2151
                                {
 
2152
                                        for (z3=0;z3<m2->m_baAtomIndex.GetSize();z3++)
 
2153
                                        {
 
2154
                                                if (m2->m_baAtomIndex[z3] != z0)
 
2155
                                                        continue;
 
2156
                                                if (!g_bRefEnvVirt)
 
2157
                                                        if (m2->m_baAtomIndex[z3] == g_iVirtAtomType)
 
2158
                                                                continue;
 
2159
                                                for (z4=0;z4<m2->m_waAtomCount[z3];z4++)
 
2160
                                                {
 
2161
                                                        ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[((CxIntArray*)g_pNbAll->m_oaScanNeighbors[z])->GetAt(z2)]])->m_oaAtomOffset[z3])->GetAt(z4);
 
2162
                                                        mfprintf(a,"  %s  %f  %f  %f\n",((CAtom*)g_oaAtoms[m2->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0f,m_vaCoords[ti][1]/100.0f,m_vaCoords[ti][2]/100.0f);
 
2163
                                                }
 
2164
                                        }
 
2165
                                }
 
2166
                        }
 
2167
                }
 
2168
        } else
 
2169
        {
 
2170
                if (g_bSaveRefWithEnv)
 
2171
                {
 
2172
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
2173
                        {
 
2174
                                if (!g_bRefEnvVirt)
 
2175
                                        if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
 
2176
                                                continue;
 
2177
                                for (z4=0;z4<m->m_waAtomCount[z3];z4++)
 
2178
                                {
 
2179
                                        ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]])->m_oaAtomOffset[z3])->GetAt(z4);
 
2180
                                        mfprintf(a,"  %s  %f  %f  %f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0,m_vaCoords[ti][1]/100.0,m_vaCoords[ti][2]/100.0);
 
2181
                                }
 
2182
                        }
 
2183
                }
 
2184
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
2185
                {
 
2186
                        m2 = (CMolecule*)g_oaMolecules[z];
 
2187
                        for (z2=0;z2<g_pNbAll->m_waScanNeighborCount[z];z2++)
 
2188
                        {
 
2189
                                for (z3=0;z3<m2->m_baAtomIndex.GetSize();z3++)
 
2190
                                {
 
2191
                                        if (!g_bRefEnvVirt)
 
2192
                                                if (m2->m_baAtomIndex[z3] == g_iVirtAtomType)
 
2193
                                                        continue;
 
2194
                                        for (z4=0;z4<m2->m_waAtomCount[z3];z4++)
 
2195
                                        {
 
2196
                                                ti = ((CxIntArray*)((CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[((CxIntArray*)g_pNbAll->m_oaScanNeighbors[z])->GetAt(z2)]])->m_oaAtomOffset[z3])->GetAt(z4);
 
2197
                                                mfprintf(a,"  %s  %f  %f  %f\n",((CAtom*)g_oaAtoms[m2->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0,m_vaCoords[ti][1]/100.0,m_vaCoords[ti][2]/100.0);
 
2198
                                        }
 
2199
                                }
 
2200
                        }
 
2201
                }
 
2202
        }
 
2203
        BTOUT; 
 
2204
}*/
 
2205
 
 
2206
 
 
2207
/*float CTimeStep::MolDist(CSingleMolecule *ref, CSingleMolecule *sm2, CNbSearch *nb)
 
2208
{
 
2209
        BXIN;
 
2210
        int z3, z4;
 
2211
        float d;
 
2212
        CxVector3 vec;
 
2213
 
 
2214
        d = 99999.0f;
 
2215
        for (z3=0;z3<nb->m_waRefElements.GetSize();z3++)
 
2216
                for (z4=0;z4<((CxIntArray*)nb->m_oaNbElements[sm2->m_iMolType])->GetSize();z4++)
 
2217
                {
 
2218
                        vec = m_vaCoords[((CxIntArray*)ref->m_oaAtomOffset[nb->m_waRefElements[z3]])->GetAt(nb->m_waRefAtoms[z3])] - m_vaCoords[((CxIntArray*)sm2->m_oaAtomOffset[((CxIntArray*)nb->m_oaNbElements[sm2->m_iMolType])->GetAt(z4)])->GetAt(((CxIntArray*)nb->m_oaNbAtoms[sm2->m_iMolType])->GetAt(z4))];
 
2219
                        if (g_bFold)
 
2220
                        {
 
2221
                                while (vec[0] >= g_fBoxX/2) vec[0] -= g_fBoxX;
 
2222
                                while (vec[0] < -g_fBoxX/2) vec[0] += g_fBoxX;
 
2223
                                while (vec[1] >= g_fBoxY/2) vec[1] -= g_fBoxY;
 
2224
                                while (vec[1] < -g_fBoxY/2) vec[1] += g_fBoxY;
 
2225
                                while (vec[2] >= g_fBoxZ/2) vec[2] -= g_fBoxZ;
 
2226
                                while (vec[2] < -g_fBoxZ/2) vec[2] += g_fBoxZ;
 
2227
                        }
 
2228
                        if (vec.GetLength() < d)
 
2229
                                d = vec.GetLength();
 
2230
                }
 
2231
        BXOUT;
 
2232
        if (d < 90000.0f)
 
2233
                return d;
 
2234
                        else return -1.0f;
 
2235
}*/
 
2236
 
 
2237
 
 
2238
/*void CTimeStep::ScanNeighborhood(int fixmol, int refmol, CNbSearch *nb, CNbSearch *prev)
 
2239
{
 
2240
        BTIN;
 
2241
        float *del, d;
 
2242
        int *best, b;
 
2243
        int z, z2, z3, c;
 
2244
        CMolecule *m, *m2;
 
2245
        CSingleMolecule *sm, *sm2;
 
2246
        CxVector3 vec;
 
2247
 
 
2248
        m = (CMolecule*)g_oaMolecules[fixmol];
 
2249
        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]];
 
2250
        del = new float[g_oaSingleMolecules.GetSize()];
 
2251
        best = new int[g_oaSingleMolecules.GetSize()];
 
2252
 
 
2253
//      printf("Suche Nachbarschaft von Molekuel %d...\n",refmol+1);
 
2254
 
 
2255
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
2256
        {
 
2257
                if (((!nb->m_bDistMode) && (nb->m_waMolCount[z] == 0)) || (nb->m_bDistMode && (nb->m_faMolDist[z] == 0)))
 
2258
                {
 
2259
                        nb->m_waScanNeighborCount[z] = 0;
 
2260
                        continue;
 
2261
                }
 
2262
                m2 = (CMolecule*)g_oaMolecules[z];
 
2263
//              printf("*** Molekuel %d: %s\n",z+1,m2->Name);
 
2264
                for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
 
2265
                {
 
2266
                        del[z2] = 99999.0f;
 
2267
                        if ((z == fixmol) && (z2 == refmol))
 
2268
                                continue;
 
2269
                        if (prev != NULL)
 
2270
                                if (!prev->Contains(z,z2))
 
2271
                                        continue;
 
2272
//                      printf("  - Vertreter %d\n",z2+1);
 
2273
                        sm2 = (CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[z2]];
 
2274
                        del[z2] = MolDist(sm,sm2,nb);
 
2275
//                      printf("  - Finaler Abstand: %f\n",del[z2]);
 
2276
                }
 
2277
                if (nb->m_bDistMode)
 
2278
                {
 
2279
//                      printf("**DistMode**\n");
 
2280
//                      mprintf("Die Nachbarn: ");
 
2281
                        c = 0;
 
2282
                        for (z3=0;z3<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z3++)
 
2283
                                if ((del[z3] <= nb->m_faMolDist[z]) && (del[z3] >= nb->m_faMolMinDist[z]))
 
2284
                                {
 
2285
//                                      mprintf("%d (%f), ",z3+1,del[z3]);
 
2286
                                        best[c] = z3;
 
2287
                                        c++;
 
2288
                                }
 
2289
//                      mprintf("\n");
 
2290
//                      printf("  # Die naechsten Nachbarn: ");
 
2291
                        for (z2=0;z2<c;z2++)
 
2292
                        {
 
2293
//                              printf("%d, ",best[z2]+1);
 
2294
                                nb->m_iNeighbourCount++;
 
2295
                                for (z3=0;z3<nb->m_waScanNeighborCount[z];z3++)
 
2296
                                        if (((CxIntArray*)nb->m_oaScanNeighbors[z])->GetAt(z3) == best[z2])
 
2297
                                        {
 
2298
                                                ((CxIntArray*)nb->m_oaScanNeighborHits[z])->GetAt(z3)++;
 
2299
                                                goto _enddist;
 
2300
                                        }
 
2301
                                ((CxIntArray*)nb->m_oaScanNeighbors[z])->Add(best[z2]);
 
2302
                                ((CxIntArray*)nb->m_oaScanNeighborHits[z])->Add(1);
 
2303
                                nb->m_waScanNeighborCount[z]++;
 
2304
_enddist:;
 
2305
                        }
 
2306
//                      printf("\n");
 
2307
                } else
 
2308
                {
 
2309
//                      printf("**CountMode**\n");
 
2310
                        for (z2=0;z2<nb->m_waMolCount[z];z2++)
 
2311
                        {
 
2312
                                d = 999999.0f;
 
2313
                                b = -1;
 
2314
                                for (z3=0;z3<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z3++)
 
2315
                                {
 
2316
                                        if (del[z3] < d)
 
2317
                                        {
 
2318
                                                d = del[z3];
 
2319
                                                b = z3;
 
2320
                                        }
 
2321
                                }
 
2322
                                best[z2] = b;
 
2323
                                del[b] = 1000000.0f;
 
2324
                        }
 
2325
//                      printf("  # Die naechsten Nachbarn: ");
 
2326
                        for (z2=nb->m_waMolCountMin[z]-1;z2<nb->m_waMolCount[z];z2++)
 
2327
                        {
 
2328
//                              printf("%d, ",best[z2]);
 
2329
                                nb->m_iNeighbourCount++;
 
2330
                                for (z3=0;z3<nb->m_waScanNeighborCount[z];z3++)
 
2331
                                        if (((CxIntArray*)nb->m_oaScanNeighbors[z])->GetAt(z3) == best[z2])
 
2332
                                        {
 
2333
                                                ((CxIntArray*)nb->m_oaScanNeighborHits[z])->GetAt(z3)++;
 
2334
                                                goto _end;
 
2335
                                        }
 
2336
                                ((CxIntArray*)nb->m_oaScanNeighbors[z])->Add(best[z2]);
 
2337
                                ((CxIntArray*)nb->m_oaScanNeighborHits[z])->Add(1);
 
2338
                                nb->m_waScanNeighborCount[z]++;
 
2339
_end:;
 
2340
                        }
 
2341
//                      printf("\n");
 
2342
                }
 
2343
        }
 
2344
        delete del;
 
2345
        delete best;
 
2346
        BTOUT; 
 
2347
}*/
 
2348
 
 
2349
 
 
2350
/*void CTimeStep::ScanAngle(int fixmol, int refmol, CCondition *co, CNbSearch *prev)
 
2351
{
 
2352
        BTIN;
 
2353
        int z2, z3, z4;
 
2354
        float tf;
 
2355
        CMolecule *m, *m2;
 
2356
        CSingleMolecule *sm, *sm2;
 
2357
        CxVector3 vec0, vec1, vec2, vec3, vec4, vec5;
 
2358
        CxIntArray tempwa;
 
2359
        CNbSearch *nb;
 
2360
 
 
2361
//      mprintf("*** ScanAngle ***\n");
 
2362
//      mprintf("  FixMol = %d, RefMol = %d\n",fixmol,refmol);
 
2363
        m = (CMolecule*)g_oaMolecules[fixmol];
 
2364
//      mprintf("  m->m_laSingleMolIndex[refmol] = %d\n",m->m_laSingleMolIndex[refmol]);
 
2365
 
 
2366
        nb = co->m_pTempNbS;
 
2367
        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]];
 
2368
 
 
2369
//      printf("Suche Nachbarschaft von Molekuel %d...\n",refmol+1);
 
2370
 
 
2371
//      mprintf("  SecondMol = %d\n",co->m_iSecondMol);
 
2372
        m2 = (CMolecule*)g_oaMolecules[co->m_iSecondMol];
 
2373
 
 
2374
//      printf("*** Molekuel %d: %s\n",z+1,m2->Name);
 
2375
        for (z2=0;z2<m2->m_laSingleMolIndex.GetSize();z2++)
 
2376
        {
 
2377
                if ((co->m_iSecondMol == fixmol) && (z2 == refmol))
 
2378
                        continue;
 
2379
                if (prev != NULL)
 
2380
                        if (!prev->Contains(co->m_iSecondMol,z2))
 
2381
                                continue;
 
2382
//              printf("  - Vertreter %d\n",z2+1);
 
2383
                sm2 = (CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[z2]];
 
2384
 
 
2385
                co->m_pADF->BuildAtomList(sm,sm2,NULL,&tempwa);
 
2386
 
 
2387
                for (z4=0;z4<tempwa.GetSize();z4+=6)
 
2388
                {
 
2389
                        if (co->m_pADF->m_bOrtho[0])
 
2390
                        {
 
2391
                                vec0 = m_vaCoords[tempwa[z4]];
 
2392
                                vec2 = m_vaCoords[tempwa[z4+1]];
 
2393
                                vec3 = m_vaCoords[tempwa[z4+2]];
 
2394
                                vec1 = CrossP(vec2-vec0,vec3-vec0);
 
2395
                        } else
 
2396
                        {
 
2397
                                vec0 = m_vaCoords[tempwa[z4]];
 
2398
                                vec2 = m_vaCoords[tempwa[z4+1]];
 
2399
                                vec1 = vec2-vec0;
 
2400
                        }
 
2401
                        if (co->m_pADF->m_bOrtho[1])
 
2402
                        {
 
2403
                                vec4 = m_vaCoords[tempwa[z4+3]];
 
2404
                                vec3 = m_vaCoords[tempwa[z4+4]];
 
2405
                                vec5 = m_vaCoords[tempwa[z4+5]];
 
2406
                                vec2 = CrossP(vec3-vec4,vec5-vec4);
 
2407
                        } else
 
2408
                        {
 
2409
                                vec4 = m_vaCoords[tempwa[z4+3]];
 
2410
                                vec3 = m_vaCoords[tempwa[z4+4]];
 
2411
                                vec2 = vec3-vec4;
 
2412
                        }
 
2413
 
 
2414
                        tf = Angle_Deg(vec1,vec2);
 
2415
 
 
2416
  if ((tf >= co->m_pADF->m_fMinAngle) && (tf <= co->m_pADF->m_fMaxAngle))
 
2417
                        {
 
2418
                                nb->m_iNeighbourCount++;
 
2419
                                for (z3=0;z3<nb->m_waScanNeighborCount[co->m_iSecondMol];z3++)
 
2420
                                        if (((CxIntArray*)nb->m_oaScanNeighbors[co->m_iSecondMol])->GetAt(z3) == z2)
 
2421
                                        {
 
2422
                                                ((CxIntArray*)nb->m_oaScanNeighborHits[co->m_iSecondMol])->GetAt(z3)++;
 
2423
                                                goto _endang;
 
2424
                                        }
 
2425
                                ((CxIntArray*)nb->m_oaScanNeighbors[co->m_iSecondMol])->Add(z2);
 
2426
                                ((CxIntArray*)nb->m_oaScanNeighborHits[co->m_iSecondMol])->Add(1);
 
2427
                                nb->m_waScanNeighborCount[co->m_iSecondMol]++;
 
2428
_endang:;               break;
 
2429
                        }
 
2430
                }
 
2431
        }
 
2432
        BTOUT; 
 
2433
}*/
 
2434
 
 
2435
/*void CTimeStep::GatherNbDiagram(int refmol, CNbSearch *nb)
 
2436
{
 
2437
        BTIN;
 
2438
        float *del, d;
 
2439
        int *best, b;
 
2440
        bool *done;
 
2441
        int z, z2, z3, z4, c, z0;
 
2442
        CMolecule *m, *m2;
 
2443
        CSingleMolecule *sm, *sm2;
 
2444
        CxVector3 vec;
 
2445
//      FILE *a;
 
2446
 
 
2447
        m = (CMolecule*)g_oaMolecules[g_iFixMol];
 
2448
        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[refmol]];
 
2449
        del = new float[g_oaSingleMolecules.GetSize()];
 
2450
        best = new int[g_oaSingleMolecules.GetSize()];
 
2451
        done = new bool[g_oaSingleMolecules.GetSize()];
 
2452
 
 
2453
//      printf("Suche Nachbarschaft von Molekuel %d...\n",refmol+1);
 
2454
 
 
2455
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
2456
        {
 
2457
                if (nb->m_bDistMode && (nb->m_faMolDist[z] == 0))
 
2458
                {
 
2459
                        nb->m_waScanNeighborCount[z] = 0;
 
2460
                        continue;
 
2461
                }
 
2462
                m2 = (CMolecule*)g_oaMolecules[z];
 
2463
//              printf("*** Molekuel %d: %s\n",z+1,m2->Name);
 
2464
//              for (z2=0;z2<=((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
 
2465
//                      del[z2] = 99999.0f;
 
2466
                for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
 
2467
                {
 
2468
                        del[z2] = 99999.0f;
 
2469
                        if ((z == g_iFixMol) && (z2 == refmol))
 
2470
                                continue;
 
2471
//                      printf("  - Vertreter %d\n",z2+1);
 
2472
                        sm2 = (CSingleMolecule*)g_oaSingleMolecules[m2->m_laSingleMolIndex[z2]];
 
2473
                        for (z3=0;z3<nb->m_waRefElements.GetSize();z3++)
 
2474
                                for (z4=0;z4<((CxIntArray*)nb->m_oaNbElements[z])->GetSize();z4++)
 
2475
                                {
 
2476
                                        vec = m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[nb->m_waRefElements[z3]])->GetAt(nb->m_waRefAtoms[z3])] - m_vaCoords[((CxIntArray*)sm2->m_oaAtomOffset[((CxIntArray*)nb->m_oaNbElements[z])->GetAt(z4)])->GetAt(((CxIntArray*)nb->m_oaNbAtoms[z])->GetAt(z4))];
 
2477
                                        if (g_bFold)
 
2478
                                        {
 
2479
                                                while (vec[0] >= g_fBoxX/2) vec[0] -= g_fBoxX;
 
2480
                                                while (vec[0] < -g_fBoxX/2) vec[0] += g_fBoxX;
 
2481
                                                while (vec[1] >= g_fBoxY/2) vec[1] -= g_fBoxY;
 
2482
                                                while (vec[1] < -g_fBoxY/2) vec[1] += g_fBoxY;
 
2483
                                                while (vec[2] >= g_fBoxZ/2) vec[2] -= g_fBoxZ;
 
2484
                                                while (vec[2] < -g_fBoxZ/2) vec[2] += g_fBoxZ;
 
2485
                                        }
 
2486
                                        d = vec.GetLength();
 
2487
//                                      printf("    = m1 %d (%d|%d); m2 %d (%d|%d); Dist = %f\n",z3+1,m->m_waNbElements[z3]+1,m->m_waNbAtoms[z3]+1,z4+1,m2->m_waNbElements[z4]+1,m2->m_waNbAtoms[z4]+1,d);
 
2488
                                        if (d < del[z2])
 
2489
                                                del[z2] = d;
 
2490
                                }
 
2491
//                      printf("  - Finaler Abstand: %f\n",del[z2]);
 
2492
                }
 
2493
 
 
2494
                for (z0=0;z0<nb->m_pAF->m_iResolution;z0++)
 
2495
                {
 
2496
                        c = 0;
 
2497
                        for (z2=0;z2<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z2++)
 
2498
                                done[z2] = false;
 
2499
                        while (true)
 
2500
                        {
 
2501
                                d = 999999.0f;
 
2502
                                b = -1;
 
2503
                                for (z3=0;z3<((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize();z3++)
 
2504
                                {
 
2505
                                        if (done[z3])
 
2506
                                                continue;
 
2507
                                        if (del[z3] < d)
 
2508
                                        {
 
2509
                                                d = del[z3];
 
2510
                                                b = z3;
 
2511
                                        }
 
2512
                                }
 
2513
                                if (d > nb->m_pAF->m_fMaxVal*z0/nb->m_pAF->m_iResolution)
 
2514
                                        break;
 
2515
                                best[c] = b;
 
2516
                                done[b] = true;
 
2517
                                c++;
 
2518
//                              if (c >= ((CMolecule*)g_oaMolecules[z])->m_laSingleMolIndex.GetSize())
 
2519
//                                      break;
 
2520
                        }
 
2521
                        nb->m_pAF->AddToBin(nb->m_pAF->m_fMaxVal*z0/nb->m_pAF->m_iResolution,(float)c);
 
2522
//                      if (g_iSteps == 1)
 
2523
//                              mfprintf(a,"%f;%f\n",nb->m_pAF->m_fMaxVal*z0/nb->m_pAF->m_iResolution,(float)c);
 
2524
                }
 
2525
//              if (g_iSteps == 1)
 
2526
//                      fclose(a);
 
2527
        }
 
2528
        delete del;
 
2529
        delete best;
 
2530
        BTOUT; 
 
2531
}*/
 
2532
 
 
2533
 
 
2534
int CTimeStep::REC_UniteMolecules(CSingleMolecule *sm, int i0, int depth)
 
2535
{
 
2536
        int z, z2, n;
 
2537
        CMolAtom *m;
 
2538
 
 
2539
        n = 0;
 
2540
        m = (CMolAtom*)sm->m_oaMolAtoms[i0];
 
2541
 
 
2542
/*      if (g_bVerbose)
 
2543
        {
 
2544
                mprintf("# ");
 
2545
                for (z2=0;z2<depth;z2++)
 
2546
                        mprintf(". ");
 
2547
                mprintf(">>> REC_UniteMolecules MolAtom=%d, Offset=%d.\n",i0,m->m_iOffset);
 
2548
        }*/
 
2549
 
 
2550
        g_pUniteTemp[m->m_iOffset] = true;
 
2551
 
 
2552
        for (z=0;z<m->m_oaBonds.GetSize();z++)
 
2553
        {
 
2554
                if (!g_pUniteTemp[((CMolAtom*)m->m_oaBonds[z])->m_iOffset])
 
2555
                {
 
2556
                        if (MirrorBond(m->m_iOffset,((CMolAtom*)m->m_oaBonds[z])->m_iOffset))
 
2557
                        {
 
2558
                                if (g_bVerbose)
 
2559
                                {
 
2560
                                        mprintf("# ");
 
2561
                                        for (z2=0;z2<depth;z2++)
 
2562
                                                mprintf(". ");
 
2563
                                        mprintf("    Bond %s(%d) <--> %s(%d) unwrapped.\n",((CAtom*)g_oaAtoms[g_baAtomIndex[m->m_iOffset]])->m_sName,m->m_iOffset+1,((CAtom*)g_oaAtoms[g_baAtomIndex[((CMolAtom*)m->m_oaBonds[z])->m_iOffset]])->m_sName,((CMolAtom*)m->m_oaBonds[z])->m_iOffset+1);
 
2564
                                }
 
2565
                                n++;
 
2566
                        }
 
2567
                        n += REC_UniteMolecules(sm,((CMolAtom*)m->m_oaBonds[z])->m_iMolAtomNumber,depth+1);
 
2568
                }
 
2569
        }
 
2570
/*      if (g_bVerbose)
 
2571
        {
 
2572
                mprintf("# ");
 
2573
                for (z2=0;z2<depth;z2++)
 
2574
                        mprintf(". ");
 
2575
                mprintf("<<< REC_UniteMolecules MolAtom=%d, Offset=%d.\n",i0,m->m_iOffset);
 
2576
        }*/
 
2577
        return n;
 
2578
}
 
2579
 
 
2580
 
 
2581
void CTimeStep::UniteMolecules(bool verbose)
 
2582
{
 
2583
        BTIN;
 
2584
        int z, z2, n;
 
2585
        CMolecule *m;
 
2586
        CSingleMolecule *sm;
 
2587
 
 
2588
        for (z=0;z<g_iGesAtomCount;z++)
 
2589
                g_pUniteTemp[z] = false;
 
2590
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
2591
        {
 
2592
                m = (CMolecule*)g_oaMolecules[z];
 
2593
                if (m->m_bPseudo)
 
2594
                        continue;
 
2595
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
2596
                {
 
2597
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
2598
 
 
2599
//                      if (g_bVerbose)
 
2600
//                              mprintf("  # UniteMolecules molecule %s (%d)\n",m->m_sName,z2+1);
 
2601
 
 
2602
                        n = REC_UniteMolecules(sm,0,0);
 
2603
 
 
2604
                        if ((n != 0) && verbose)
 
2605
                                mprintf("      - Molecule %s[%d] united, %d bonds unwrapped.\n",m->m_sName,z2+1,n);
 
2606
 
 
2607
                        if ((n != 0) && (!verbose) && g_bVerbose)
 
2608
                                mprintf("\n  # UniteMolecules: Molecule %s[%d] united, %d bonds unwrapped.",m->m_sName,z2+1,n);
 
2609
        
 
2610
                }
 
2611
        }
 
2612
        BTOUT; 
 
2613
}
 
2614
 
 
2615
 
 
2616
bool CTimeStep::ReadTimestep(FILE *a, bool needinfo)
 
2617
{
 
2618
        BTIN;
 
2619
        switch(g_iTrajFormat)
 
2620
        {
 
2621
                case 0:
 
2622
                        if (!ReadXYZ(a,needinfo,&m_vaCoords))
 
2623
                                return false;
 
2624
                        break;
 
2625
 
 
2626
                case 1:
 
2627
                        if (!ReadPDB(a,needinfo,&m_vaCoords))
 
2628
                                return false;
 
2629
                        break;
 
2630
 
 
2631
                case 2:
 
2632
                        if (!ReadMol2(a,needinfo))
 
2633
                                return false;
 
2634
                        break;
 
2635
 
 
2636
                case 3:
 
2637
                        if (!ReadLAMMPS(a,needinfo))
 
2638
                                return false;
 
2639
                        break;
 
2640
 
 
2641
                case 4:
 
2642
                        if (!ReadDLPOLY(a,needinfo))
 
2643
                                return false;
 
2644
                        break;
 
2645
        }
 
2646
        if (g_bDoubleBox)
 
2647
                DoubleBox();
 
2648
        BTOUT; 
 
2649
        return true;
 
2650
}
 
2651
 
 
2652
 
 
2653
bool CTimeStep::SkipTimestep(FILE *a)
 
2654
{
 
2655
        BTIN;
 
2656
        switch(g_iTrajFormat)
 
2657
        {
 
2658
                case 0:
 
2659
                        if (!SkipXYZ(a))
 
2660
                                return false;
 
2661
                        break;
 
2662
 
 
2663
                case 1:
 
2664
                        if (!SkipPDB(a))
 
2665
                                return false;
 
2666
                        break;
 
2667
 
 
2668
                case 2:
 
2669
                        if (!SkipMol2(a))
 
2670
                                return false;
 
2671
                        break;
 
2672
 
 
2673
                case 3:
 
2674
                        if (!SkipLAMMPS(a))
 
2675
                                return false;
 
2676
                        break;
 
2677
 
 
2678
                case 4:
 
2679
                        if (!SkipDLPOLY(a))
 
2680
                                return false;
 
2681
                        break;
 
2682
        }
 
2683
        BTOUT; 
 
2684
        return true;
 
2685
}
 
2686
 
 
2687
 
 
2688
bool CTimeStep::ReadTimestepVel(FILE *a)
 
2689
{
 
2690
        BTIN;
 
2691
        char buf[256], *p, *q;
 
2692
        int z, tc;
 
2693
 
 
2694
        buf[0] = 0;
 
2695
        fgets(buf,256,a);
 
2696
        if (feof(a))
 
2697
        {
 
2698
                BTOUT; 
 
2699
                return false;
 
2700
        }
 
2701
        if (strlen(buf) > 0)
 
2702
                buf[strlen(buf)-1] = 0;
 
2703
        tc = atoi(buf);
 
2704
        if (tc == 0)
 
2705
        {
 
2706
                BTOUT; 
 
2707
                return false;
 
2708
        }
 
2709
        m_vaVelocities.SetSize(tc);
 
2710
        buf[0] = 0;
 
2711
        fgets(buf,256,a); // Zeitschritt - egal hier
 
2712
        if (strlen(buf) > 0)
 
2713
                buf[strlen(buf)-1] = 0;
 
2714
        for (z=0;z<tc;z++) // den ersten Zeitschritt einlesen
 
2715
        {
 
2716
                buf[0] = 0;
 
2717
                fgets(buf,256,a);
 
2718
                if (feof(a))
 
2719
                {
 
2720
                        BTOUT; 
 
2721
                        return false;
 
2722
                }
 
2723
                if (strlen(buf) > 0)
 
2724
                        buf[strlen(buf)-1] = 0;
 
2725
                q = buf;
 
2726
                while (*q == ' ')
 
2727
                        q++;
 
2728
                p = strchr(q,' ');
 
2729
                if (p == NULL)
 
2730
                {
 
2731
                        eprintf("CTimeStep::ReadTimestepVel(): Error 1. %d, \"%s\"\n",z+1,buf);
 
2732
                        continue;
 
2733
                }
 
2734
                while (isdigit(*(p-1)) && (p > buf))
 
2735
                        p--;
 
2736
                if (p == buf)
 
2737
                {
 
2738
                        eprintf("CTimeStep::ReadTimestepVel(): No Atom laben found. %d, \"%s\"\n",z+1,buf);
 
2739
                        continue;
 
2740
                }
 
2741
                *p = 0;
 
2742
                p++;
 
2743
                q = strchr(p,' ');
 
2744
                if (q == NULL)
 
2745
                {
 
2746
                        eprintf("CTimeStep::ReadTimestepVel(): Error 2. %d, \"%s\"\n",z+1,p);
 
2747
                        continue;
 
2748
                }
 
2749
                while (*q == ' ')
 
2750
                        q++;
 
2751
                p = strchr(q,' ');
 
2752
                if (p == NULL)
 
2753
                {
 
2754
                        eprintf("CTimeStep::ReadTimestepVel(): Error 3. %d, \"%s\"\n",z+1,q);
 
2755
                        continue;
 
2756
                }
 
2757
                *p = 0;
 
2758
                m_vaVelocities[z][0] = (float)atof(q);
 
2759
                q = p+1;
 
2760
                while (*q == ' ')
 
2761
                        q++;
 
2762
                p = strchr(q,' ');
 
2763
                if (p == NULL)
 
2764
                {
 
2765
                        eprintf("CTimeStep::ReadTimestepVel(): Error 4. %d, \"%s\"\n",z+1,q);
 
2766
                        continue;
 
2767
                }
 
2768
                *p = 0;
 
2769
                m_vaVelocities[z][1] = (float)atof(q);
 
2770
                q = p+1;
 
2771
                while (*q == ' ')
 
2772
                        q++;
 
2773
                p = strchr(q,' ');
 
2774
                if (p != NULL)
 
2775
                        *p = 0;
 
2776
                m_vaVelocities[z][2] = (float)atof(q);
 
2777
        }
 
2778
        if (g_bDoubleBox)
 
2779
                DoubleBoxVelocity();
 
2780
        BTOUT; 
 
2781
        return true;
 
2782
}
 
2783
 
 
2784
 
 
2785
bool CTimeStep::ReadTimestepForce(FILE *a)
 
2786
{
 
2787
        BTIN;
 
2788
        char buf[256], *p, *q;
 
2789
        int z, tc;
 
2790
 
 
2791
        buf[0] = 0;
 
2792
        fgets(buf,256,a);
 
2793
        if (feof(a))
 
2794
        {
 
2795
                BTOUT; 
 
2796
                return false;
 
2797
        }
 
2798
        if (strlen(buf) > 0)
 
2799
                buf[strlen(buf)-1] = 0;
 
2800
        tc = atoi(buf);
 
2801
        if (tc == 0)
 
2802
        {
 
2803
                BTOUT; 
 
2804
                return false;
 
2805
        }
 
2806
        m_vaForces.SetSize(tc);
 
2807
        buf[0] = 0;
 
2808
        fgets(buf,256,a); // Zeitschritt - egal hier
 
2809
        if (strlen(buf) > 0)
 
2810
                buf[strlen(buf)-1] = 0;
 
2811
        for (z=0;z<tc;z++) // den ersten Zeitschritt einlesen
 
2812
        {
 
2813
                buf[0] = 0;
 
2814
                fgets(buf,256,a);
 
2815
                if (feof(a))
 
2816
                {
 
2817
                        BTOUT; 
 
2818
                        return false;
 
2819
                }
 
2820
                if (strlen(buf) > 0)
 
2821
                        buf[strlen(buf)-1] = 0;
 
2822
                q = buf;
 
2823
                while (*q == ' ')
 
2824
                        q++;
 
2825
                p = strchr(q,' ');
 
2826
                if (p == NULL)
 
2827
                {
 
2828
                        eprintf("CTimeStep::ReadTimestepForce(): Error 1. %d, \"%s\"\n",z+1,buf);
 
2829
                        continue;
 
2830
                }
 
2831
                while (isdigit(*(p-1)) && (p > buf))
 
2832
                        p--;
 
2833
                if (p == buf)
 
2834
                {
 
2835
                        eprintf("CTimeStep::ReadTimestepForce(): No Atom laben found. %d, \"%s\"\n",z+1,buf);
 
2836
                        continue;
 
2837
                }
 
2838
                *p = 0;
 
2839
                p++;
 
2840
                q = strchr(p,' ');
 
2841
                if (q == NULL)
 
2842
                {
 
2843
                        eprintf("CTimeStep::ReadTimestepForce(): Error 2. %d, \"%s\"\n",z+1,p);
 
2844
                        continue;
 
2845
                }
 
2846
                while (*q == ' ')
 
2847
                        q++;
 
2848
                p = strchr(q,' ');
 
2849
                if (p == NULL)
 
2850
                {
 
2851
                        eprintf("CTimeStep::ReadTimestepForce(): Error 3. %d, \"%s\"\n",z+1,q);
 
2852
                        continue;
 
2853
                }
 
2854
                *p = 0;
 
2855
                m_vaForces[z][0] = (float)atof(q);
 
2856
                q = p+1;
 
2857
                while (*q == ' ')
 
2858
                        q++;
 
2859
                p = strchr(q,' ');
 
2860
                if (p == NULL)
 
2861
                {
 
2862
                        eprintf("CTimeStep::ReadTimestepForce(): Error 4. %d, \"%s\"\n",z+1,q);
 
2863
                        continue;
 
2864
                }
 
2865
                *p = 0;
 
2866
                m_vaForces[z][1] = (float)atof(q);
 
2867
                q = p+1;
 
2868
                while (*q == ' ')
 
2869
                        q++;
 
2870
                p = strchr(q,' ');
 
2871
                if (p != NULL)
 
2872
                        *p = 0;
 
2873
                m_vaForces[z][2] = (float)atof(q);
 
2874
        }
 
2875
        if (g_bDoubleBox)
 
2876
                DoubleBoxForce();
 
2877
        BTOUT; 
 
2878
        return true;
 
2879
}
 
2880
 
 
2881
 
 
2882
bool CTimeStep::SkipXYZ(FILE *a)
 
2883
{
 
2884
        BTIN;
 
2885
        char buf[256];
 
2886
        int z, tc;
 
2887
 
 
2888
//      mprintf("*** Skip Anfang ***\n");
 
2889
        buf[0] = 0;
 
2890
        fgets_bin(buf,256,a);
 
2891
        if (feof(a))
 
2892
        {
 
2893
                BTOUT; 
 
2894
                return false;
 
2895
        }
 
2896
        if (strlen(buf)==0)
 
2897
        {
 
2898
                BTOUT; 
 
2899
                return false;
 
2900
        }
 
2901
        buf[strlen(buf)-1] = 0;
 
2902
        tc = atoi(buf);
 
2903
//      mprintf("SkipA: \"%s\".\n",buf);
 
2904
        if (tc == 0)
 
2905
        {
 
2906
                BTOUT; 
 
2907
                return false;
 
2908
        }
 
2909
//      buf[0] = 0;
 
2910
        fgets_bin(buf,256,a); // Zeitschritt - egal hier
 
2911
//      mprintf("SkipB: \"%s\".\n",buf);
 
2912
        for (z=0;z<tc;z++) // den ersten Zeitschritt einlesen
 
2913
        {
 
2914
//              buf[0] = 0;
 
2915
                fgets_bin(buf,256,a);
 
2916
//              mprintf("SkipC%d: \"%s\".\n",z,buf);
 
2917
                if (feof(a))
 
2918
                {
 
2919
                        BTOUT; 
 
2920
                        return false;
 
2921
                }
 
2922
        }
 
2923
//      mprintf("*** Skip Ende ***\n");
 
2924
        BTOUT; 
 
2925
        return true;
 
2926
}
 
2927
 
 
2928
 
 
2929
void CTimeStep::CopyFrom(CTimeStep *t)
 
2930
{
 
2931
        BTIN;
 
2932
        int z;
 
2933
        char *p;
 
2934
        CxVector3 v;
 
2935
 
 
2936
        m_iGesAtomCount = t->m_iGesAtomCount;
 
2937
        m_vaCoords.CopyFrom(&t->m_vaCoords);
 
2938
        if (g_bKeepUnfoldedCoords)
 
2939
                m_vaCoords_Unfolded.CopyFrom(&t->m_vaCoords_Unfolded);
 
2940
        m_vaForces.CopyFrom(&t->m_vaForces);
 
2941
        m_vaVelocities.CopyFrom(&t->m_vaVelocities);
 
2942
        if (t->m_paLabels.GetSize() != 0)
 
2943
        {
 
2944
                for (z=0;z<m_paLabels.GetSize();z++)
 
2945
                        delete[] (char*)m_paLabels[z];
 
2946
                m_paLabels.RemoveAll();
 
2947
                for (z=0;z<t->m_paLabels.GetSize();z++)
 
2948
                {
 
2949
                        try { p = new char[strlen((char*)t->m_paLabels[z])+1]; } catch(...) { p = NULL; }
 
2950
                        if (p == NULL) NewException((double)(strlen((char*)t->m_paLabels[z])+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2951
                        
 
2952
                        strcpy(p,(char*)t->m_paLabels[z]);
 
2953
                        m_paLabels.Add(p);
 
2954
                }
 
2955
        }
 
2956
        if (t->m_pComment != NULL)
 
2957
        {
 
2958
                if (m_pComment == NULL)
 
2959
                {
 
2960
                        try { m_pComment = new char[256]; } catch(...) { m_pComment = NULL; }
 
2961
                        if (m_pComment == NULL) NewException((double)256*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
2962
                }
 
2963
                strcpy(m_pComment,t->m_pComment);
 
2964
        }
 
2965
        BTOUT; 
 
2966
}
 
2967
 
 
2968
          
 
2969
long CTimeStep::ExtractNumber(int i)
 
2970
{
 
2971
        BXIN;
 
2972
        char *p, *q, buf[20];
 
2973
        int z;
 
2974
        long l;
 
2975
 
 
2976
        if (m_pComment == NULL)
 
2977
                return -1;
 
2978
        p = m_pComment;
 
2979
        for (z=0;z<i;z++)
 
2980
        {
 
2981
                while ((!isdigit(*p)) && (*p != 0))
 
2982
                        p++;
 
2983
                if (*p == 0)
 
2984
                {
 
2985
                        BXOUT;
 
2986
                        return -1;
 
2987
                }
 
2988
                q = p+1;
 
2989
                while ((isdigit(*q)) && (*q != 0))
 
2990
                        q++;
 
2991
                if (*q == 0)
 
2992
                {
 
2993
                        BXOUT;
 
2994
                        return -1;
 
2995
                }
 
2996
                p = q+1;
 
2997
        }
 
2998
        while ((!isdigit(*p)) && (*p != 0))
 
2999
                p++;
 
3000
        if (*p == 0)
 
3001
        {
 
3002
                BXOUT;
 
3003
                return -1;
 
3004
        }
 
3005
        q = p;
 
3006
        while ((isdigit(*q)) && (*q != 0))
 
3007
                q++;
 
3008
        if (q == p)
 
3009
        {
 
3010
                BXOUT;
 
3011
                return -1;
 
3012
        }
 
3013
        memcpy(buf,p,q-p);
 
3014
        buf[q-p] = 0;
 
3015
        l = atoi(buf);
 
3016
        BXOUT;
 
3017
        return l;
 
3018
}
 
3019
 
 
3020
 
 
3021
int CTimeStep::GetCommentNumberCount()
 
3022
{
 
3023
        BXIN;
 
3024
        char *p, *q;
 
3025
        int z;
 
3026
 
 
3027
        if (m_pComment == NULL)
 
3028
                return 0;
 
3029
        p = m_pComment;
 
3030
        z = 0;
 
3031
        while (true)
 
3032
        {
 
3033
                while ((!isdigit(*p)) && (*p != 0))
 
3034
                        p++;
 
3035
                if (*p == 0)
 
3036
                {
 
3037
//                      mprintf("GetCommentNumberCount 1: %d (p=\"%s\", q=\"%s\")\n",z,p,q);
 
3038
                        BXOUT;
 
3039
                        return z;
 
3040
                }
 
3041
                q = p;
 
3042
                while ((isdigit(*q)) && (*q != 0))
 
3043
                        q++;
 
3044
                if (q == p)
 
3045
                {
 
3046
//                      mprintf("GetCommentNumberCount 2: %d (p=\"%s\", q=\"%s\")\n",z,p,q);
 
3047
                        BXOUT;
 
3048
                        return z;
 
3049
                }
 
3050
                z++;
 
3051
                if (*q == 0)
 
3052
                {
 
3053
//                      mprintf("GetCommentNumberCount 3: %d (p=\"%s\", q=\"%s\")\n",z,p,q);
 
3054
                        BXOUT;
 
3055
                        return z;
 
3056
                }
 
3057
                p = q+1;
 
3058
        }
 
3059
        return 0; // Never happens
 
3060
}
 
3061
 
 
3062
 
 
3063
bool CTimeStep::ScanWannier(bool verbose)
 
3064
{
 
3065
        BTIN;
 
3066
        int z, z2, z3;
 
3067
        float td, d, dx, dy, dz;
 
3068
        CMolecule *m;
 
3069
 
 
3070
        if (g_bVerbose)
 
3071
        {
 
3072
                mprintf(WHITE,"\n*** ScanWannier ***\n\n");
 
3073
                verbose = true;
 
3074
        }
 
3075
 
 
3076
        for (z=0;z<g_oaSingleMolecules.GetSize();z++)
 
3077
                ((CSingleMolecule*)g_oaSingleMolecules[z])->m_laWannier.RemoveAll_KeepSize();
 
3078
 
 
3079
        for (z=0;z<g_iGesAtomCount;z++)
 
3080
        {
 
3081
                if (g_baAtomIndex[z] != g_iWannierAtomType)
 
3082
                        continue;
 
3083
                d = 9999.0f;
 
3084
                z3 = -1;
 
3085
                for (z2=0;z2<g_iGesAtomCount;z2++)
 
3086
                {
 
3087
                        if (g_baAtomIndex[z2] == g_iWannierAtomType)
 
3088
                                continue;
 
3089
                        dx = m_vaCoords[z][0]-m_vaCoords[z2][0];
 
3090
                        dy = m_vaCoords[z][1]-m_vaCoords[z2][1];
 
3091
                        dz = m_vaCoords[z][2]-m_vaCoords[z2][2];
 
3092
                        if (g_bPeriodicX)
 
3093
                        {
 
3094
                                while (dx > g_fBoxX/2.0f) dx -= g_fBoxX;
 
3095
                                while (dx < -g_fBoxX/2.0f) dx += g_fBoxX;
 
3096
                        }
 
3097
                        if (g_bPeriodicY)
 
3098
                        {
 
3099
                                while (dy > g_fBoxY/2.0f) dy -= g_fBoxY;
 
3100
                                while (dy < -g_fBoxY/2.0f) dy += g_fBoxY;
 
3101
                        }
 
3102
                        if (g_bPeriodicZ)
 
3103
                        {
 
3104
                                while (dz > g_fBoxZ/2.0f) dz -= g_fBoxZ;
 
3105
                                while (dz < -g_fBoxZ/2.0f) dz += g_fBoxZ;
 
3106
                        }
 
3107
                        td = (float)sqrt(dx*dx+dy*dy+dz*dz);
 
3108
                        if (td < d)
 
3109
                        {
 
3110
                                d = td;
 
3111
                                z3 = z2;
 
3112
                        }
 
3113
                }
 
3114
                if (z3 == -1)
 
3115
                        abort();
 
3116
                if (g_bPeriodicX)
 
3117
                {
 
3118
                        while (m_vaCoords[z][0]-m_vaCoords[z3][0] > g_fBoxX/2.0f) m_vaCoords[z][0] -= g_fBoxX;
 
3119
                        while (m_vaCoords[z][0]-m_vaCoords[z3][0] < -g_fBoxX/2.0f) m_vaCoords[z][0] += g_fBoxX;
 
3120
                }
 
3121
                if (g_bPeriodicY)
 
3122
                {
 
3123
                        while (m_vaCoords[z][1]-m_vaCoords[z3][1] > g_fBoxY/2.0f) m_vaCoords[z][1] -= g_fBoxY;
 
3124
                        while (m_vaCoords[z][1]-m_vaCoords[z3][1] < -g_fBoxY/2.0f) m_vaCoords[z][1] += g_fBoxY;
 
3125
                }
 
3126
                if (g_bPeriodicZ)
 
3127
                {
 
3128
                        while (m_vaCoords[z][2]-m_vaCoords[z3][2] > g_fBoxZ/2.0f) m_vaCoords[z][2] -= g_fBoxZ;
 
3129
                        while (m_vaCoords[z][2]-m_vaCoords[z3][2] < -g_fBoxZ/2.0f) m_vaCoords[z][2] += g_fBoxZ;
 
3130
                }
 
3131
                z2 = g_laAtomSMIndex[z3];
 
3132
                if (d > 100.0)
 
3133
                {
 
3134
                        eprintf("Step %d: Wannier center at offset %d too far away from any atom (closest atom is %s[%d] %s%d, %.0f pm).\n",g_iSteps,z+1,((CMolecule*)g_oaMolecules[((CSingleMolecule*)g_oaSingleMolecules[z2])->m_iMolType])->m_sName,((CSingleMolecule*)g_oaSingleMolecules[z2])->m_iMolSMIndex+1,((CAtom*)g_oaAtoms[g_waAtomRealElement[z3]])->m_sName,g_waAtomMolNumber[z3]+1,d);
 
3135
                } else if (verbose)
 
3136
                        mprintf("  - Wannier center %d belongs to %s[%d] %s%d (%.0f pm).\n",z+1,((CMolecule*)g_oaMolecules[((CSingleMolecule*)g_oaSingleMolecules[z2])->m_iMolType])->m_sName,((CSingleMolecule*)g_oaSingleMolecules[z2])->m_iMolSMIndex+1,((CAtom*)g_oaAtoms[g_waAtomRealElement[z3]])->m_sName,g_waAtomMolNumber[z3]+1,d);
 
3137
/*              if (z2 == -1)
 
3138
                {
 
3139
                        eprintf("Wannier center %d: Atom %d does not belong to any molecule.\n",z+1,z3+1);
 
3140
                        continue;
 
3141
                }*/
 
3142
//              mprintf("Wannier Center %d hat Abstand %.2f zu Atom %d in SM %d.\n",z+1,d,z3+1,z2+1);
 
3143
                ((CSingleMolecule*)g_oaSingleMolecules[z2])->m_laWannier.Add(z);
 
3144
        }
 
3145
        if (verbose)
 
3146
                mprintf("\n\n");
 
3147
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
3148
        {
 
3149
                m = (CMolecule*)g_oaMolecules[z];
 
3150
                if (m->m_iWannierCount == 0)
 
3151
                {
 
3152
                        m->m_iWannierCount = ((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[0]])->m_laWannier.GetSize();
 
3153
                        td = 0;
 
3154
                        for (z2=0;z2<m->m_baAtomIndex.GetSize();z2++)
 
3155
                        {
 
3156
                                if (m->m_baAtomIndex[z2] == g_iWannierAtomType)
 
3157
                                        continue;
 
3158
                                if (m->m_baAtomIndex[z2] == g_iVirtAtomType)
 
3159
                                        continue;
 
3160
                                td += ((CAtom*)g_oaAtoms[m->m_baAtomIndex[z2]])->m_fCharge * m->m_waAtomCount[z2];
 
3161
                        }
 
3162
                        m->m_fCharge = td-m->m_iWannierCount*g_fWannierCharge;
 
3163
                        mprintf("  - Molecule %s contains %d wannier centers. Total charge is %.2f - %.2f = %.2f\n",m->m_sName,m->m_iWannierCount,td,m->m_iWannierCount*g_fWannierCharge,m->m_fCharge);
 
3164
                        if (m->m_fCharge > 5.0)
 
3165
                        {
 
3166
                                eprintf("\n    This molecular charge seems to be too high.\n\n");
 
3167
                                if (!AskYesNo("    Do you want to continue (y/n)? [yes] ",true))
 
3168
                                        return false;
 
3169
                        }
 
3170
                }
 
3171
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
3172
                {
 
3173
                        if (m->m_iWannierCount != ((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]])->m_laWannier.GetSize())
 
3174
                                eprintf("Step %d: Molecule %s[%d] contains %d instead of %d wannier centers.\n",g_iSteps,m->m_sName,z2+1,((CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]])->m_laWannier.GetSize(),m->m_iWannierCount);
 
3175
                }
 
3176
        }
 
3177
        BTOUT;
 
3178
        return true;
 
3179
}
 
3180
 
 
3181
 
 
3182
void CTimeStep::CalcDipoles()
 
3183
{
 
3184
        BTIN;
 
3185
        int z, z2, z3, z4;
 
3186
        CMolecule *m;
 
3187
        CSingleMolecule *sm;
 
3188
        CAtom *a;
 
3189
        CxVector3 dc;
 
3190
 
 
3191
//      mprintf("\n*** CalcDipoles ***");
 
3192
 
 
3193
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
3194
        {
 
3195
                m = (CMolecule*)g_oaMolecules[z];
 
3196
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
3197
                {
 
3198
                        if (g_bVerbose)
 
3199
                                mprintf("\nCalcDipoles %s (%d):\n",m->m_sName,z2+1);
 
3200
 
 
3201
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
3202
 
 
3203
                        sm->m_vDipole = CxVector3(0,0,0);
 
3204
 
 
3205
                        if ((!g_bWannier) && (!m->m_bChargesAssigned))
 
3206
                                continue;
 
3207
 
 
3208
                        if (g_bDipoleRefFixed)
 
3209
                                dc = CxVector3(0,0,0);
 
3210
                                        else dc = m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[m->m_iDipoleCenterType])->GetAt(m->m_iDipoleCenterIndex)];
 
3211
 
 
3212
                        if (g_bVerbose)
 
3213
                                mprintf("  Ref. point is ( %f | %f | %f )\n",dc[0],dc[1],dc[2]);
 
3214
 
 
3215
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
3216
                        {
 
3217
                                if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
 
3218
                                        continue;
 
3219
 
 
3220
                                if (g_bWannier)
 
3221
                                        if (m->m_baAtomIndex[z3] == g_iWannierAtomType)
 
3222
                                                continue;
 
3223
 
 
3224
                                a = (CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]];
 
3225
                                for (z4=0;z4<m->m_waAtomCount[z3];z4++)
 
3226
                                {
 
3227
//                                      mprintf("  %s%d %.2f x ",a->m_sName,z4+1,a->m_fCharge);
 
3228
//                                      (m_vaCoords[sm->m_iAtomOffset[z3][z4]]-m_vaCoords[sm->m_iAtomOffset[m->Elements-1][0]]).Dump();
 
3229
//                                      mprintf("\n");
 
3230
//                                      mprintf("  %s%d %.2f (%d)\n",a->m_sName,z4+1,a->m_fCharge,((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4));
 
3231
 
 
3232
                                        if (g_bWannier)
 
3233
                                        {
 
3234
                                                sm->m_vDipole += a->m_fCharge * (m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] - dc);
 
3235
 
 
3236
                                                if (g_bVerbose)
 
3237
                                                        mprintf("  %.2f: ( %f | %f | %f )\n",a->m_fCharge,m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]);
 
3238
                                        } else
 
3239
                                        {
 
3240
                                                if (g_bReadChargesFrom4thXYZ)
 
3241
                                                {
 
3242
                                //                      mprintf("Moep. z3=%d, z4=%d, c=%f.\n",z3,z4,m_faCharge[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)]);
 
3243
                                                        sm->m_vDipole += m_faCharge[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] * (m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] - dc);
 
3244
                                                        if (g_bVerbose)
 
3245
                                                                mprintf("  %.2f: ( %f | %f | %f )\n",m_faCharge[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]);
 
3246
                                                } else
 
3247
                                                {
 
3248
                                                        sm->m_vDipole += ((CxFloatArray*)m->m_oaCharges[z3])->GetAt(z4) * (m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)] - dc);
 
3249
                                                        if (g_bVerbose)
 
3250
                                                                mprintf("  %.2f: ( %f | %f | %f )\n",((CxFloatArray*)m->m_oaCharges[z3])->GetAt(z4),m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][0],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][1],m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4)][2]);
 
3251
                                                }
 
3252
                                        }
 
3253
                                }
 
3254
                        }
 
3255
                        for (z3=0;z3<sm->m_laWannier.GetSize();z3++)
 
3256
                        {
 
3257
//                              mprintf("  - %.2f x ",g_fWannierCharge);
 
3258
//                              (m_vaCoords[sm->m_waWannier[z3]] - m_vaCoords[sm->m_iAtomOffset[m->Elements-1][0]]).Dump();
 
3259
//                              mprintf("\n");
 
3260
                                sm->m_vDipole -= g_fWannierCharge * (m_vaCoords[sm->m_laWannier[z3]] - dc);
 
3261
 
 
3262
                                if (g_bVerbose)
 
3263
                                        mprintf("  %.2f: ( %f | %f | %f )\n",-g_fWannierCharge,m_vaCoords[sm->m_laWannier[z3]][0],m_vaCoords[sm->m_laWannier[z3]][1],m_vaCoords[sm->m_laWannier[z3]][2]);
 
3264
                        }
 
3265
//                      mprintf("  = ");
 
3266
//                      sm->m_vDipole.Dump();
 
3267
//                      mprintf("\n");
 
3268
                        sm->m_vDipole *= 0.048008f; // Conversion e*pm --> Debye
 
3269
 
 
3270
                        if (g_bVerbose)
 
3271
                                mprintf("  Result: %f.\n",sm->m_vDipole.GetLength());
 
3272
 
 
3273
//                      mprintf("Molecule %s - Dipole %.3f\n",m->Name,sm->m_vDipole.GetLength());
 
3274
                }
 
3275
        }
 
3276
        BTOUT;
 
3277
}
 
3278
 
 
3279
 
 
3280
void CTimeStep::DoubleBox()
 
3281
{
 
3282
        int px, py, pz, z;
 
3283
        char *p;
 
3284
 
 
3285
        if (m_vaCoords.GetSize() < g_iGesAtomCount)
 
3286
                m_vaCoords.SetSize(g_iGesAtomCount);
 
3287
 
 
3288
        if (m_paLabels.GetSize() != 0)
 
3289
                m_paLabels.SetSize(g_iGesAtomCount);
 
3290
 
 
3291
        for (pz=0;pz<g_iDoubleBoxZ;pz++)
 
3292
        {
 
3293
                for (py=0;py<g_iDoubleBoxY;py++)
 
3294
                {
 
3295
                        for (px=0;px<g_iDoubleBoxX;px++)
 
3296
                        {
 
3297
                                if ((px == 0) && (py == 0) && (pz == 0))
 
3298
                                        continue;
 
3299
                                for (z=0;z<g_iGesAtomCount/g_iDoubleBoxFactor;z++)
 
3300
                                {
 
3301
                                        m_vaCoords[(pz*g_iDoubleBoxX*g_iDoubleBoxY+py*g_iDoubleBoxX+px)*g_iGesAtomCount/g_iDoubleBoxFactor+z] = m_vaCoords[z] + CxVector3(px*g_fBoxX/g_iDoubleBoxX,py*g_fBoxY/g_iDoubleBoxY,pz*g_fBoxZ/g_iDoubleBoxZ);
 
3302
                                        if (m_paLabels.GetSize() != 0)
 
3303
                                        {
 
3304
                                                try { p = new char[strlen((char*)m_paLabels[z])+1]; } catch(...) { p = NULL; }
 
3305
                                                if (p == NULL) NewException((double)(strlen((char*)m_paLabels[z])+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3306
                                                
 
3307
                                                strcpy(p,(char*)m_paLabels[z]);
 
3308
                                                m_paLabels[(pz*g_iDoubleBoxX*g_iDoubleBoxY+py*g_iDoubleBoxX+px)*g_iGesAtomCount/g_iDoubleBoxFactor+z] = p;
 
3309
                                        }
 
3310
                                }
 
3311
                        }
 
3312
                }
 
3313
        }
 
3314
        m_iGesAtomCount = g_iGesAtomCount;
 
3315
}
 
3316
 
 
3317
 
 
3318
void CTimeStep::DoubleBoxVelocity()
 
3319
{
 
3320
        int px, py, pz, z;
 
3321
 
 
3322
        if (m_vaVelocities.GetSize() < g_iGesAtomCount)
 
3323
                m_vaVelocities.SetSize(g_iGesAtomCount);
 
3324
 
 
3325
        for (pz=0;pz<g_iDoubleBoxZ;pz++)
 
3326
        {
 
3327
                for (py=0;py<g_iDoubleBoxY;py++)
 
3328
                {
 
3329
                        for (px=0;px<g_iDoubleBoxX;px++)
 
3330
                        {
 
3331
                                if ((px == 0) && (py == 0) && (pz == 0))
 
3332
                                        continue;
 
3333
                                for (z=0;z<g_iGesAtomCount/g_iDoubleBoxFactor;z++)
 
3334
                                        m_vaVelocities[(pz*g_iDoubleBoxX*g_iDoubleBoxY+py*g_iDoubleBoxX+px)*g_iGesAtomCount/g_iDoubleBoxFactor+z] = m_vaVelocities[z];
 
3335
                        }
 
3336
                }
 
3337
        }
 
3338
}
 
3339
 
 
3340
 
 
3341
void CTimeStep::DoubleBoxForce()
 
3342
{
 
3343
        int px, py, pz, z;
 
3344
 
 
3345
        if (m_vaForces.GetSize() < g_iGesAtomCount)
 
3346
                m_vaForces.SetSize(g_iGesAtomCount);
 
3347
 
 
3348
        for (pz=0;pz<g_iDoubleBoxZ;pz++)
 
3349
        {
 
3350
                for (py=0;py<g_iDoubleBoxY;py++)
 
3351
                {
 
3352
                        for (px=0;px<g_iDoubleBoxX;px++)
 
3353
                        {
 
3354
                                if ((px == 0) && (py == 0) && (pz == 0))
 
3355
                                        continue;
 
3356
                                for (z=0;z<g_iGesAtomCount/g_iDoubleBoxFactor;z++)
 
3357
                                        m_vaForces[(pz*g_iDoubleBoxX*g_iDoubleBoxY+py*g_iDoubleBoxX+px)*g_iGesAtomCount/g_iDoubleBoxFactor+z] = m_vaForces[z];
 
3358
                        }
 
3359
                }
 
3360
        }
 
3361
}
 
3362
 
 
3363
 
 
3364
bool CTimeStep::ReadXYZ(FILE *a, bool needinfo, CxVec3Array *v)
 
3365
{
 
3366
        BTIN;
 
3367
        char buf[256], obuf[256],  *p, *q, *r;
 
3368
        int z, /*i,*/ j;
 
3369
        const char *separators = " ,;\"'\t";
 
3370
 
 
3371
//      mprintf("*** Read Anfang.\n");
 
3372
        j = 0;
 
3373
//      m_iSizeBytes = 0;
 
3374
_readagain:
 
3375
        buf[0] = 0;
 
3376
        fgets_bin(buf,256,a);
 
3377
//      m_iSizeBytes += strlen(buf);
 
3378
        if (strlen(buf) > 0)
 
3379
                buf[strlen(buf)-1] = 0;
 
3380
//      mprintf("Read1: \"%s\".\n",buf);
 
3381
        goto _firsttry;
 
3382
_again:
 
3383
        eprintf("\nTrajectory file seems to be damaged. Searching for next time step...");
 
3384
_firsttry:
 
3385
        if (feof(a))
 
3386
        {
 
3387
//              mprintf("CTimeStep::ReadTimestep(): Unexpected End of File (1).\n"); 
 
3388
                BTOUT; 
 
3389
                return false;
 
3390
        }
 
3391
        if (strchr(buf,'.') != NULL)
 
3392
        {
 
3393
                if (j < 10)
 
3394
                        eprintf("x",j,buf);
 
3395
//                      mprintf("x: %d - \"%s\"\n",j,buf);
 
3396
                j++;
 
3397
                goto _readagain;
 
3398
        }
 
3399
        m_iGesAtomCount = atoi(buf);
 
3400
        if (m_iGesAtomCount == 0)
 
3401
        {
 
3402
                eprintf("\nCTimeStep::ReadXYZ(): Error - atom count = 0. \"%s\"",buf);
 
3403
                goto _readagain;
 
3404
        }
 
3405
        if (m_pComment == NULL)
 
3406
        {
 
3407
                try { m_pComment = new char[128]; } catch(...) { m_pComment = NULL; }
 
3408
                if (m_pComment == NULL) NewException((double)128*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3409
        }
 
3410
        if (needinfo)
 
3411
        {
 
3412
                for (z=0;z<m_paLabels.GetSize();z++)
 
3413
                        delete[] (char*)m_paLabels[z];
 
3414
                m_paLabels.RemoveAll();
 
3415
                if (g_bDoubleBox)
 
3416
                        m_paLabels.SetSize(m_iGesAtomCount*g_iDoubleBoxFactor);
 
3417
                                else m_paLabels.SetSize(m_iGesAtomCount);
 
3418
        }
 
3419
        if (v->GetSize() < (long)m_iGesAtomCount)
 
3420
                v->SetSize(m_iGesAtomCount);
 
3421
 
 
3422
        if (g_bKeepOriginalCoords)
 
3423
        {
 
3424
                if (m_vaCoords_Original.GetSize() < (long)m_iGesAtomCount)
 
3425
                        m_vaCoords_Original.SetSize(m_iGesAtomCount);
 
3426
        }
 
3427
 
 
3428
        m_pComment[0] = 0;
 
3429
        fgets_bin(m_pComment,128,a); // Zeitschritt - egal hier
 
3430
//      if (strlen(m_pComment) > 0)
 
3431
//              m_pComment[strlen(m_pComment)-1] = 0;
 
3432
 
 
3433
        p = m_pComment;
 
3434
        while (*p != 0)
 
3435
        {
 
3436
                if ((*p == 10) || (*p == 13))
 
3437
                        *p = 0;
 
3438
                p++;
 
3439
        }
 
3440
//      mprintf("Comment: \"%s\".\n",m_pComment);
 
3441
//      m_iSizeBytes += strlen(m_pComment);
 
3442
 
 
3443
        if (g_bReadChargesFrom4thXYZ)
 
3444
                m_faCharge.SetSize(m_iGesAtomCount);
 
3445
 
 
3446
        for (z=0;z<(long)m_iGesAtomCount;z++) // den ersten Zeitschritt einlesen
 
3447
        {
 
3448
                buf[0] = 0;
 
3449
                fgets_bin(buf,256,a);
 
3450
                if (feof(a))
 
3451
                {
 
3452
                        eprintf("\nCTimeStep::ReadXYZ(): Unexpected end of file (2). \"%s\"\n",buf);
 
3453
                        BTOUT; 
 
3454
                        return false;
 
3455
                }
 
3456
//              m_iSizeBytes += strlen(buf);
 
3457
                buf[strlen(buf)-1] = 0;
 
3458
//              mprintf("  %d: \"%s\".\n",z,buf);
 
3459
                strcpy(obuf,buf);
 
3460
//              i = 0;
 
3461
 
 
3462
                p = &buf[0];
 
3463
                while (strchr(separators,*p) != NULL)
 
3464
                        p++;
 
3465
                q = p+1;
 
3466
                while ((strchr(separators,*q) == NULL) && (*q != 0))
 
3467
                        q++;
 
3468
                if (*q == 0)
 
3469
                {
 
3470
                        eprintf("\nCTimeStep::ReadXYZ(): %d: Incomplete line (1): \"%s\"\n",z+1,obuf);
 
3471
                        BTOUT; 
 
3472
                        return false;
 
3473
                }
 
3474
                *q = 0;
 
3475
 
 
3476
                if (needinfo)
 
3477
                {
 
3478
                        if (strlen(p) > 7)
 
3479
                        {
 
3480
                                eprintf("\nCTimeStep::ReadXYZ(): \"%s\" - Maximum length of atom labels is 7 chars; truncating.\n",p);
 
3481
                                p[7] = 0;
 
3482
                        }
 
3483
 
 
3484
                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
 
3485
                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3486
                        
 
3487
                        strcpy(r,p);
 
3488
                        m_paLabels[z] = r;
 
3489
                }
 
3490
 
 
3491
                q++;
 
3492
                while (strchr(separators,*q) != NULL)
 
3493
                        q++;
 
3494
                p = q;
 
3495
                while ((strchr(separators,*p) == NULL) && (*p != 0))
 
3496
                        p++;
 
3497
                if (*p == 0)
 
3498
                {
 
3499
                        eprintf("\nCTimeStep::ReadXYZ(): %d: Incomplete line (2): \"%s\"",z+1,obuf);
 
3500
                        goto _again;
 
3501
                }
 
3502
                *p = 0;
 
3503
                (*v)[z][0] = (float)atof(q) * 100.0f;
 
3504
 
 
3505
                if (g_bKeepOriginalCoords)
 
3506
                        m_vaCoords_Original[z][0] = (double)atof(q) * 100.0;
 
3507
 
 
3508
                q = p+1;
 
3509
                while (strchr(separators,*q) != NULL)
 
3510
                        q++;
 
3511
                p = q;
 
3512
                while ((strchr(separators,*p) == NULL) && (*p != 0))
 
3513
                        p++;
 
3514
                if (*p == 0)
 
3515
                {
 
3516
                        eprintf("\nCTimeStep::ReadXYZ(): %d: Incomplete line (3) \"%s\"",z+1,obuf);
 
3517
                        goto _again;
 
3518
                }
 
3519
                *p = 0;
 
3520
                (*v)[z][1] = (float)atof(q) * 100.0f;
 
3521
 
 
3522
                if (g_bKeepOriginalCoords)
 
3523
                        m_vaCoords_Original[z][1] = (double)atof(q) * 100.0;
 
3524
 
 
3525
                q = p+1;
 
3526
                while (strchr(separators,*q) != NULL)
 
3527
                        q++;
 
3528
                p = q;
 
3529
                while ((strchr(separators,*p) == NULL) && (*p != 0))
 
3530
                        p++;
 
3531
                if (g_bReadChargesFrom4thXYZ)
 
3532
                {
 
3533
                        if (*p == 0)
 
3534
                        {
 
3535
                                eprintf("\nCTimeStep::ReadXYZ(): %d: Incomplete line (4) \"%s\"",z+1,obuf);
 
3536
                                goto _again;
 
3537
                        }
 
3538
                        *p = 0;
 
3539
                } else
 
3540
                {
 
3541
                        if (*p != 0)
 
3542
                                *p = 0;
 
3543
                }
 
3544
                (*v)[z][2] = (float)atof(q) * 100.0f;
 
3545
 
 
3546
                if (g_bKeepOriginalCoords)
 
3547
                        m_vaCoords_Original[z][2] = (double)atof(q) * 100.0;
 
3548
 
 
3549
                if (g_bReadChargesFrom4thXYZ)
 
3550
                {
 
3551
                        q = p+1;
 
3552
                        while (strchr(separators,*q) != NULL)
 
3553
                                q++;
 
3554
                        p = q;
 
3555
                        while ((strchr(separators,*p) == NULL) && (*p != 0))
 
3556
                                p++;
 
3557
                        if (*p != 0)
 
3558
                                *p = 0;
 
3559
                        m_faCharge[z] = (float)atof(q);
 
3560
                } else if (needinfo && (z==0))
 
3561
                {
 
3562
                        if (*p == 0)
 
3563
                                goto _no4;
 
3564
                        q = p+1;
 
3565
                        if (*q == 0)
 
3566
                                goto _no4;
 
3567
                        while (strchr(separators,*q) != NULL)
 
3568
                                q++;
 
3569
                        p = q;
 
3570
                        while ((strchr(separators,*p) == NULL) && (*p != 0))
 
3571
                                p++;
 
3572
                        if ((p-q) > 3)
 
3573
                        {
 
3574
                                for (;q<p;q++)
 
3575
                                        if (!(((*q >= '0') && (*q <= '9')) || (*q == '-') || (*q == '.')))
 
3576
                                                goto _no4;
 
3577
                                g_bXYZ4thCol = true;
 
3578
_no4:;
 
3579
                        }
 
3580
                }
 
3581
 
 
3582
/*              q = strchr(buf,'.');
 
3583
                if (q != NULL)
 
3584
                {
 
3585
                        i++;
 
3586
                        q = strchr(q+1,'.');
 
3587
                }
 
3588
                if (q != NULL)
 
3589
                {
 
3590
                        i++;
 
3591
                        q = strchr(q+1,'.');
 
3592
                }
 
3593
                if (q==NULL)
 
3594
                {
 
3595
                        eprintf("\nCTimeStep::ReadXYZ(): Error - only %d/3 dots. %d, \"%s\"",i,z+1,buf);
 
3596
                        goto _again;
 
3597
                }
 
3598
                q = buf;
 
3599
                while (*q == ' ')
 
3600
                        q++;
 
3601
                p = strchr(q,' ');
 
3602
                if (p == NULL)
 
3603
                {
 
3604
                        eprintf("\nCTimeStep::ReadXYZ(): Error 1. %d, \"%s\"",z+1,buf);
 
3605
                        goto _again;
 
3606
                }
 
3607
                while (isdigit(*(p-1)) && (p > buf))
 
3608
                        p--;
 
3609
                if (p == buf)
 
3610
                {
 
3611
                        eprintf("\nCTimeStep::ReadXYZ(): No Atom label found. %d, \"%s\"",z+1,buf);
 
3612
                        goto _again;
 
3613
                }
 
3614
                *p = 0;
 
3615
                if (needinfo)
 
3616
                {
 
3617
                        r = new char[strlen(q)+1];
 
3618
                        strcpy(r,q);
 
3619
                        m_paLabels[z] = r;
 
3620
                }
 
3621
                q = p+1;
 
3622
                while (*q == ' ')
 
3623
                        q++;
 
3624
                p = strchr(q,' ');
 
3625
                if (p == NULL)
 
3626
                {
 
3627
                        eprintf("\nCTimeStep::ReadXYZ(): Error 3. %d, \"%s\"",z+1,q);
 
3628
                        goto _again;
 
3629
                }
 
3630
                *p = 0;
 
3631
                (*v)[z][0] = (float)atof(q) * 100.0f;
 
3632
                q = p+1;
 
3633
                while (*q == ' ')
 
3634
                        q++;
 
3635
                p = strchr(q,' ');
 
3636
                if (p == NULL)
 
3637
                {
 
3638
                        eprintf("\nCTimeStep::ReadXYZ(): Error 4. %d, \"%s\"",z+1,q);
 
3639
                        goto _again;
 
3640
                }
 
3641
                *p = 0;
 
3642
                (*v)[z][1] = (float)atof(q) * 100.0f;
 
3643
                q = p+1;
 
3644
                while (*q == ' ')
 
3645
                        q++;
 
3646
                p = strchr(q,' ');
 
3647
                if (p != NULL)
 
3648
                        *p = 0;
 
3649
                (*v)[z][2] = (float)atof(q) * 100.0f;*/
 
3650
 
 
3651
 
 
3652
        }
 
3653
//      mprintf("*** Read Ende.\n");
 
3654
        BTOUT; 
 
3655
        return true;
 
3656
}
 
3657
 
 
3658
 
 
3659
bool CTimeStep::ReadPDB(FILE *a, bool needinfo, CxVec3Array *v)
 
3660
{
 
3661
        int i;
 
3662
        static char buf[256], obuf[256], buf2[64];
 
3663
        char *p, *q, *r;
 
3664
        float x, y, z;
 
3665
        bool b;
 
3666
 
 
3667
        v->RemoveAll_KeepSize();
 
3668
        for (i=0;i<m_paLabels.GetSize();i++)
 
3669
                delete[] (char*)m_paLabels[i];
 
3670
        m_paLabels.RemoveAll();
 
3671
        while (true)
 
3672
        {
 
3673
                fgets_bin(buf,256,a);
 
3674
                if (feof(a))
 
3675
                        return false;
 
3676
                if (strlen(buf) == 0)
 
3677
                        continue;
 
3678
                buf[strlen(buf)-1] = 0;
 
3679
                strcpy(obuf,buf);
 
3680
                if (g_bNPT)
 
3681
                {
 
3682
                        if (strstr(buf,"CRYST1") != 0) // Boxlaenge
 
3683
                        {
 
3684
        //                      mprintf(GREY,"\"%s\".\n",buf);
 
3685
                                p = &buf[6];
 
3686
                                while (*p == ' ')
 
3687
                                        p++;
 
3688
                                q = p;
 
3689
                                while ((*q != ' ') && (*q != 0))
 
3690
                                        q++;
 
3691
                                if (*q == 0)
 
3692
                                {
 
3693
                                        eprintf("Error 5 reading PDB line: \"%s\".\n",obuf);
 
3694
                                        return false;
 
3695
                                }
 
3696
                                *q = 0;
 
3697
                                g_fBoxX = (float)(atof(p)*100.0);
 
3698
                                p = q+1;
 
3699
 
 
3700
                                while (*p == ' ')
 
3701
                                        p++;
 
3702
                                q = p;
 
3703
                                while ((*q != ' ') && (*q != 0))
 
3704
                                        q++;
 
3705
                                if (*q == 0)
 
3706
                                {
 
3707
                                        eprintf("Error 6 reading PDB line: \"%s\".\n",obuf);
 
3708
                                        return false;
 
3709
                                }
 
3710
                                *q = 0;
 
3711
                                g_fBoxY = (float)(atof(p)*100.0);
 
3712
                                p = q+1;
 
3713
 
 
3714
                                while (*p == ' ')
 
3715
                                        p++;
 
3716
                                q = p;
 
3717
                                while ((*q != ' ') && (*q != 0))
 
3718
                                        q++;
 
3719
                                if (*q != 0)
 
3720
                                        *q = 0;
 
3721
                                g_fBoxZ = (float)(atof(p)*100.0);
 
3722
//                              mprintf(GREY,"--> %f %f %f\n",g_fBoxX,g_fBoxY,g_fBoxZ);
 
3723
                        }
 
3724
                }
 
3725
 
 
3726
                if (strstr(buf,"END") == buf)
 
3727
                        break;
 
3728
 
 
3729
                if ((strstr(buf,"ATOM")==0) && (strstr(buf,"HETATM")==0))
 
3730
                        continue;
 
3731
 
 
3732
                p = &buf[7];
 
3733
                while (!(isalpha(*p) || (*p == '_')) && (*p != 0))
 
3734
                        p++;
 
3735
                if (*p == 0)
 
3736
                {
 
3737
                        eprintf("Error 4 reading PDB line: \"%s\".\n",obuf);
 
3738
                        return false;
 
3739
                }
 
3740
                q = p;
 
3741
                while (isalpha(*q) || (*q == '_'))
 
3742
                        q++;
 
3743
                if (needinfo)
 
3744
                {
 
3745
                        *q = 0;
 
3746
                        if (strlen(p) > 7)
 
3747
                        {
 
3748
                                eprintf("\nCTimeStep::ReadPDB(): \"%s\" - maximum length for atom labels is 7 chars; truncating.\n",p);
 
3749
                                p[7] = 0;
 
3750
                        }
 
3751
 
 
3752
                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
 
3753
                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3754
                        
 
3755
                        strcpy(r,p);
 
3756
                        m_paLabels.Add(r);
 
3757
                }
 
3758
                p = q+1;
 
3759
 
 
3760
                while ((*p != '.') && (*p != 0))
 
3761
                        p++;
 
3762
 
 
3763
                while (*p != ' ')
 
3764
                        p--;
 
3765
 
 
3766
                p++;
 
3767
 
 
3768
                q = p;
 
3769
                b = false;
 
3770
                while (*q != 0)
 
3771
                {
 
3772
                        if (b)
 
3773
                        {
 
3774
                                if ((*q == ' ') || (*q == '-'))
 
3775
                                        break;
 
3776
                        }
 
3777
                        if (*q == 0)
 
3778
                                break;
 
3779
                        if ((*q == '-') || (*q == '.') || ((*q >= '0') && (*q <= '9')))
 
3780
                                b = true;
 
3781
                        q++;
 
3782
                }
 
3783
//              q = strchr(p,' ');
 
3784
                if (*q == 0)
 
3785
                {
 
3786
                        eprintf("\nCTimeStep::ReadPDB(): Error 1. \"%s\".",obuf);
 
3787
                        return false;
 
3788
                }
 
3789
                memcpy(buf2,p,q-p);
 
3790
                buf2[q-p] = 0;
 
3791
                x = (float)atof(buf2) * 100.0f;
 
3792
//              mprintf("\n  \"%s\".",buf2);
 
3793
 
 
3794
                p = q;
 
3795
                b = false;
 
3796
                while (*q != 0)
 
3797
                {
 
3798
                        if (b)
 
3799
                        {
 
3800
                                if ((*q == ' ') || (*q == '-'))
 
3801
                                        break;
 
3802
                        }
 
3803
                        if (*q == 0)
 
3804
                                break;
 
3805
                        if ((*q == '-') || (*q == '.') || ((*q >= '0') && (*q <= '9')))
 
3806
                                b = true;
 
3807
                        q++;
 
3808
                }
 
3809
//              q = strchr(p,' ');
 
3810
                if (*q == 0)
 
3811
                {
 
3812
                        eprintf("\nCTimeStep::ReadPDB(): Error 2. \"%s\".",obuf);
 
3813
                        return false;
 
3814
                }
 
3815
                memcpy(buf2,p,q-p);
 
3816
                buf2[q-p] = 0;
 
3817
                y = (float)atof(buf2) * 100.0f;
 
3818
//              mprintf("\n  \"%s\".",buf2);
 
3819
 
 
3820
                z = (float)atof(q) * 100.0f;
 
3821
//              mprintf("\n  \"%s\".",q);
 
3822
 
 
3823
//              mprintf("\n%f, %f, %f",x,y,z);
 
3824
 
 
3825
                m_vaCoords.Add(CxVector3(x,y,z));
 
3826
        }
 
3827
        m_iGesAtomCount = m_vaCoords.GetSize();
 
3828
 
 
3829
        return true;
 
3830
}
 
3831
 
 
3832
 
 
3833
bool CTimeStep::SkipPDB(FILE *a)
 
3834
{
 
3835
        char buf[256];
 
3836
//      bool b;
 
3837
 
 
3838
        while (true)
 
3839
        {
 
3840
                fgets_bin(buf,256,a);
 
3841
                if (feof(a))
 
3842
                        return false;
 
3843
                if (strlen(buf) == 0)
 
3844
                        continue;
 
3845
                buf[strlen(buf)-1] = 0;
 
3846
                if (strstr(buf,"END") == buf)
 
3847
                        break;
 
3848
        }
 
3849
        return true;
 
3850
}
 
3851
 
 
3852
 
 
3853
bool CTimeStep::ReadLAMMPS(FILE *a, bool needinfo)
 
3854
{
 
3855
        int i;
 
3856
        char buf[256], obuf[256], *p, *q, *r;
 
3857
        float x, y, z;
 
3858
 
 
3859
        m_vaCoords.RemoveAll_KeepSize();
 
3860
        for (i=0;i<m_paLabels.GetSize();i++)
 
3861
                delete[] (char*)m_paLabels[i];
 
3862
        m_paLabels.RemoveAll();
 
3863
        m_iGesAtomCount = 0;
 
3864
        while (true)
 
3865
        {
 
3866
                fgets_bin(buf,256,a);
 
3867
                if (feof(a))
 
3868
                        return false;
 
3869
                if (strlen(buf) == 0)
 
3870
                        continue;
 
3871
                buf[strlen(buf)-1] = 0;
 
3872
                strcpy(obuf,buf);
 
3873
                if (g_bNPT)
 
3874
                {
 
3875
                        if (strstr(buf,"ITEM: BOX BOUNDS") != 0) // Boxlaenge
 
3876
                        {
 
3877
                                for (i=0;i<3;i++)
 
3878
                                {
 
3879
                                        fgets_bin(buf,256,a);
 
3880
                                        if (feof(a))
 
3881
                                                return false;
 
3882
 
 
3883
                                        p = &buf[0];
 
3884
                                        while (strchr(" ",*p) != NULL)
 
3885
                                                p++;
 
3886
                                        q = p+1;
 
3887
                                        while ((strchr(" ",*q) == NULL) && (*q != 0))
 
3888
                                                q++;
 
3889
                                        if (*q == 0)
 
3890
                                        {
 
3891
                                                eprintf("\nCTimeStep::ReadLAMMPS(): Incomplete line: \"%s\"\n",obuf);
 
3892
                                                return false;
 
3893
                                        }
 
3894
                                        *q = 0;
 
3895
                                        x = atof(p);
 
3896
 
 
3897
                                        p = q+1;
 
3898
                                        while (strchr(" ",*p) != NULL)
 
3899
                                                p++;
 
3900
 
 
3901
                                        y = atof(p);
 
3902
 
 
3903
                                        switch(i)
 
3904
                                        {
 
3905
                                                case 0: g_fBoxX = (y-x)*100.0f; break;
 
3906
                                                case 1: g_fBoxY = (y-x)*100.0f; break;
 
3907
                                                case 2: g_fBoxZ = (y-x)*100.0f; break;
 
3908
                                        }
 
3909
                                }
 
3910
                        }
 
3911
                }
 
3912
                if (strstr(buf,"ITEM: NUMBER OF ATOMS") != 0)
 
3913
                {
 
3914
                        fgets_bin(buf,256,a);
 
3915
                        if (feof(a))
 
3916
                                return false;
 
3917
                        buf[strlen(buf)-1] = 0;
 
3918
                        m_iGesAtomCount = atoi(buf);
 
3919
                        continue;
 
3920
                }
 
3921
                if (strstr(buf,"ITEM: ATOMS") != 0)
 
3922
                {
 
3923
                        if (strstr(buf,"ITEM: ATOMS element xu yu zu") == 0)
 
3924
                        {
 
3925
                                eprintf("CTimeStep::ReadLAMMPS(): Wrong LAMMPS dump style: \"%s\".\n",buf);
 
3926
                                eprintf("You need to use \"dump custom element xu yu zu\".\n");
 
3927
                                return false;
 
3928
                        }
 
3929
 
 
3930
                        if (m_iGesAtomCount == 0)
 
3931
                        {
 
3932
                                eprintf("CTimeStep::ReadLAMMPS(): \"ITEM: ATOMS\" before \"ITEM: NUMBER OF ATOMS\".\n");
 
3933
                                return false;
 
3934
                        }
 
3935
 
 
3936
                        if (needinfo)
 
3937
                        {
 
3938
                                if (g_bDoubleBox)
 
3939
                                        m_paLabels.SetSize(m_iGesAtomCount*g_iDoubleBoxFactor);
 
3940
                                                else m_paLabels.SetSize(m_iGesAtomCount);
 
3941
                        }
 
3942
 
 
3943
                        for (i=0;i<(int)m_iGesAtomCount;i++)
 
3944
                        {
 
3945
                                fgets_bin(buf,256,a);
 
3946
                                if (feof(a))
 
3947
                                        return false;
 
3948
 
 
3949
                                p = &buf[0];
 
3950
                                while (strchr(" ",*p) != NULL)
 
3951
                                        p++;
 
3952
                                q = p+1;
 
3953
                                while ((strchr(" ",*q) == NULL) && (*q != 0))
 
3954
                                        q++;
 
3955
                                if (*q == 0)
 
3956
                                {
 
3957
                                        eprintf("\nCTimeStep::ReadLAMMPS(): %d: Incomplete line (1): \"%s\"\n",i+1,obuf);
 
3958
                                        BTOUT; 
 
3959
                                        return false;
 
3960
                                }
 
3961
                                *q = 0;
 
3962
 
 
3963
                                if (needinfo)
 
3964
                                {
 
3965
                                        if (strlen(p) > 7)
 
3966
                                        {
 
3967
                                                eprintf("\nCTimeStep::ReadLAMMPS(): \"%s\" - maximum length for atom labels is 7 chars; truncating.\n",p);
 
3968
                                                p[7] = 0;
 
3969
                                        }
 
3970
 
 
3971
                                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
 
3972
                                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
3973
                                        
 
3974
                                        strcpy(r,p);
 
3975
                                        m_paLabels[i] = r;
 
3976
                                }
 
3977
 
 
3978
                                q++;
 
3979
                                while (strchr(" ",*q) != NULL)
 
3980
                                        q++;
 
3981
                                p = q;
 
3982
                                while ((strchr(" ",*p) == NULL) && (*p != 0))
 
3983
                                        p++;
 
3984
                                if (*p == 0)
 
3985
                                {
 
3986
                                        eprintf("\nCTimeStep::ReadLAMMPS(): %d: Incomplete line (2): \"%s\"",i+1,obuf);
 
3987
                                        return false;
 
3988
                                }
 
3989
                                *p = 0;
 
3990
                                x = (float)atof(q) * 100.0f;
 
3991
                                q = p+1;
 
3992
                                while (strchr(" ",*q) != NULL)
 
3993
                                        q++;
 
3994
                                p = q;
 
3995
                                while ((strchr(" ",*p) == NULL) && (*p != 0))
 
3996
                                        p++;
 
3997
                                if (*p == 0)
 
3998
                                {
 
3999
                                        eprintf("\nCTimeStep::ReadLAMMPS(): %d: Incomplete line (3) \"%s\"",i+1,obuf);
 
4000
                                        return false;
 
4001
                                }
 
4002
                                *p = 0;
 
4003
                                y = (float)atof(q) * 100.0f;
 
4004
                                q = p+1;
 
4005
                                while (strchr(" ",*q) != NULL)
 
4006
                                        q++;
 
4007
                                p = q;
 
4008
                                while ((strchr(" ",*p) == NULL) && (*p != 0))
 
4009
                                        p++;
 
4010
                                if (*p != 0)
 
4011
                                        *p = 0;
 
4012
                                z = (float)atof(q) * 100.0f;
 
4013
 
 
4014
                                m_vaCoords.Add(CxVector3(x,y,z));
 
4015
                        }
 
4016
                        break;
 
4017
                }
 
4018
        }
 
4019
        return true;
 
4020
}
 
4021
 
 
4022
 
 
4023
bool CTimeStep::SkipLAMMPS(FILE *a)
 
4024
{
 
4025
        int i, j;
 
4026
        char buf[256];
 
4027
 
 
4028
        j = 0;
 
4029
        while (true)
 
4030
        {
 
4031
                fgets_bin(buf,256,a);
 
4032
                if (feof(a))
 
4033
                        return false;
 
4034
                if (strlen(buf) == 0)
 
4035
                        continue;
 
4036
                buf[strlen(buf)-1] = 0;
 
4037
                if (strstr(buf,"ITEM: NUMBER OF ATOMS") != 0)
 
4038
                {
 
4039
                        fgets_bin(buf,256,a);
 
4040
                        if (feof(a))
 
4041
                                return false;
 
4042
                        buf[strlen(buf)-1] = 0;
 
4043
                        j = atoi(buf);
 
4044
                        continue;
 
4045
                }
 
4046
                if (strstr(buf,"ITEM: ATOMS") != 0)
 
4047
                {
 
4048
                        if (j == 0)
 
4049
                        {
 
4050
                                eprintf("CTimeStep::SkipLAMMPS():  \"ITEM: ATOMS\" before \"ITEM: NUMBER OF ATOMS\".\n");
 
4051
                                return false;
 
4052
                        }
 
4053
                        for (i=0;i<j;i++)
 
4054
                        {
 
4055
                                fgets_bin(buf,256,a);
 
4056
                                if (feof(a))
 
4057
                                        return false;
 
4058
                        }
 
4059
                        break;
 
4060
                }
 
4061
        }
 
4062
        return true;
 
4063
}
 
4064
 
 
4065
 
 
4066
bool CTimeStep::ReadDLPOLY(FILE *a, bool needinfo)
 
4067
{
 
4068
        int i;
 
4069
        char buf[256], obuf[256], *p, *q, *r;
 
4070
        float x, y, z;
 
4071
 
 
4072
        m_vaCoords.RemoveAll_KeepSize();
 
4073
        for (i=0;i<m_paLabels.GetSize();i++)
 
4074
                delete[] (char*)m_paLabels[i];
 
4075
        m_paLabels.RemoveAll();
 
4076
        m_iGesAtomCount = 0;
 
4077
        while (true)
 
4078
        {
 
4079
                fgets_bin(buf,256,a);
 
4080
                if (feof(a))
 
4081
                        return false;
 
4082
                if (strlen(buf) == 0)
 
4083
                        continue;
 
4084
                buf[strlen(buf)-1] = 0;
 
4085
                strcpy(obuf,buf);
 
4086
 
 
4087
                if (strstr(buf,"timestep") != 0)
 
4088
                {
 
4089
                        p = &buf[0];
 
4090
                        while (*p == ' ')
 
4091
                                p++;
 
4092
                        q = p;
 
4093
                        while ((*q != ' ') && (*q != 0))
 
4094
                                q++;
 
4095
                        if (*q == 0)
 
4096
                        {
 
4097
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line A: \"%s\"\n",obuf);
 
4098
                                return false;
 
4099
                        }
 
4100
                        *q = 0;
 
4101
                        p=q+1;
 
4102
 
 
4103
                        while (*p == ' ')
 
4104
                                p++;
 
4105
                        q = p;
 
4106
                        while ((*q != ' ') && (*q != 0))
 
4107
                                q++;
 
4108
                        if (*q == 0)
 
4109
                        {
 
4110
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line B: \"%s\"\n",obuf);
 
4111
                                return false;
 
4112
                        }
 
4113
                        *q = 0;
 
4114
                        p=q+1;
 
4115
 
 
4116
                        while (*p == ' ')
 
4117
                                p++;
 
4118
                        q = p;
 
4119
                        while ((*q != ' ') && (*q != 0))
 
4120
                                q++;
 
4121
                        if (*q == 0)
 
4122
                        {
 
4123
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line C: \"%s\"\n",obuf);
 
4124
                                return false;
 
4125
                        }
 
4126
                        *q = 0;
 
4127
                        m_iGesAtomCount = atoi(p);
 
4128
 
 
4129
                        if (g_bNPT)
 
4130
                        {
 
4131
                                for (i=0;i<3;i++)
 
4132
                                {
 
4133
                                        fgets_bin(buf,256,a);
 
4134
                                        if (feof(a))
 
4135
                                                return false;
 
4136
 
 
4137
                                        p = &buf[0];
 
4138
 
 
4139
                                        while (*p == ' ')
 
4140
                                                p++;
 
4141
                                        q = p;
 
4142
                                        while ((*q != ' ') && (*q != 0))
 
4143
                                                q++;
 
4144
                                        if (*q == 0)
 
4145
                                        {
 
4146
                                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line D: \"%s\"\n",obuf);
 
4147
                                                return false;
 
4148
                                        }
 
4149
                                        *q = 0;
 
4150
                                        x = atof(p);
 
4151
                                        p = q+1;
 
4152
 
 
4153
                                        while (*p == ' ')
 
4154
                                                p++;
 
4155
                                        q = p;
 
4156
                                        while ((*q != ' ') && (*q != 0))
 
4157
                                                q++;
 
4158
                                        if (*q == 0)
 
4159
                                        {
 
4160
                                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line E: \"%s\"\n",obuf);
 
4161
                                                return false;
 
4162
                                        }
 
4163
                                        *q = 0;
 
4164
                                        y = atof(p);
 
4165
                                        p = q+1;
 
4166
 
 
4167
                                        while (*p == ' ')
 
4168
                                                p++;
 
4169
                                        q = p;
 
4170
                                        while ((*q != ' ') && (*q != 0))
 
4171
                                                q++;
 
4172
                                        *q = 0;
 
4173
                                        z = atof(p);
 
4174
 
 
4175
                                        switch(i)
 
4176
                                        {
 
4177
                                                case 0:
 
4178
                                                        if ((y != 0) || (z != 0))
 
4179
                                                        {
 
4180
                                                                eprintf("\nCTimeStep::ReadDLPOLY(): X: Only orthorhombic cells are supported.\n");
 
4181
                                                                return false;
 
4182
                                                        }
 
4183
                                                        g_fBoxX = x*100.0f;
 
4184
                                                        break;
 
4185
 
 
4186
                                                case 1:
 
4187
                                                        if ((x != 0) || (z != 0))
 
4188
                                                        {
 
4189
                                                                eprintf("\nCTimeStep::ReadDLPOLY(): Y: Only orthorhombic cells are supported.\n");
 
4190
                                                                return false;
 
4191
                                                        }
 
4192
                                                        g_fBoxY = y*100.0f;
 
4193
                                                        break;
 
4194
 
 
4195
                                                case 2:
 
4196
                                                        if ((x != 0) || (y != 0))
 
4197
                                                        {
 
4198
                                                                eprintf("\nCTimeStep::ReadDLPOLY(): Z: Only orthorhombic cells are supported.\n");
 
4199
                                                                return false;
 
4200
                                                        }
 
4201
                                                        g_fBoxZ = z*100.0f;
 
4202
                                                        break;
 
4203
 
 
4204
                                        }
 
4205
                                }
 
4206
                        } else
 
4207
                        {
 
4208
                                fgets_bin(buf,256,a);
 
4209
                                fgets_bin(buf,256,a);
 
4210
                                fgets_bin(buf,256,a);
 
4211
                        }
 
4212
 
 
4213
                        if (m_iGesAtomCount == 0)
 
4214
                        {
 
4215
                                eprintf("CTimeStep::ReadDLPOLY(): Error: Atom count is 0.\n");
 
4216
                                return false;
 
4217
                        }
 
4218
 
 
4219
                        if (needinfo)
 
4220
                        {
 
4221
                                if (g_bDoubleBox)
 
4222
                                        m_paLabels.SetSize(m_iGesAtomCount*g_iDoubleBoxFactor);
 
4223
                                                else m_paLabels.SetSize(m_iGesAtomCount);
 
4224
                        }
 
4225
 
 
4226
                        for (i=0;i<(int)m_iGesAtomCount;i++)
 
4227
                        {
 
4228
_readagain:
 
4229
                                fgets_bin(buf,256,a);
 
4230
                                if (feof(a))
 
4231
                                        return false;
 
4232
 
 
4233
                                p = &buf[0];
 
4234
                                while (*p == ' ')
 
4235
                                        p++;
 
4236
                                q = p;
 
4237
 
 
4238
                                // Numer at beginning of line: Likely velocities. Skip that line
 
4239
                                if ((*p == '-') || (*p == '.') || ((*p >= '0') && (*p <= '9')))
 
4240
                                        goto _readagain;
 
4241
 
 
4242
                                while ((*q != ' ') && (*q != 0))
 
4243
                                        q++;
 
4244
                                if (*q == 0)
 
4245
                                {
 
4246
                                        eprintf("\nCTimeStep::ReadDLPOLY(): %d: Incomplete line F: \"%s\"\n",i+1,obuf);
 
4247
                                        return false;
 
4248
                                }
 
4249
                                *q = 0;
 
4250
 
 
4251
                                if (needinfo)
 
4252
                                {
 
4253
                                        if (strlen(p) > 7)
 
4254
                                        {
 
4255
                                                eprintf("\nCTimeStep::ReadDLPOLY(): \"%s\" - maximum length for atom labels is 7 chars; truncating.\n",p);
 
4256
                                                p[7] = 0;
 
4257
                                        }
 
4258
 
 
4259
                                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
 
4260
                                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
4261
                                        
 
4262
                                        strcpy(r,p);
 
4263
                                        m_paLabels[i] = r;
 
4264
                                }
 
4265
 
 
4266
                                fgets_bin(buf,256,a);
 
4267
                                if (feof(a))
 
4268
                                        return false;
 
4269
 
 
4270
                                p = &buf[0];
 
4271
 
 
4272
                                while (*p == ' ')
 
4273
                                        p++;
 
4274
                                q = p;
 
4275
                                while ((*q != ' ') && (*q != 0))
 
4276
                                        q++;
 
4277
                                if (*q == 0)
 
4278
                                {
 
4279
                                        eprintf("\nCTimeStep::ReadDLPOLY(): %d: Incomplete line G: \"%s\"\n",i+1,obuf);
 
4280
                                        return false;
 
4281
                                }
 
4282
                                *q = 0;
 
4283
                                x = atof(p)*100.0f;
 
4284
                                p = q+1;
 
4285
 
 
4286
                                while (*p == ' ')
 
4287
                                        p++;
 
4288
                                q = p;
 
4289
                                while ((*q != ' ') && (*q != 0))
 
4290
                                        q++;
 
4291
                                if (*q == 0)
 
4292
                                {
 
4293
                                        eprintf("\nCTimeStep::ReadDLPOLY(): %d: Incomplete line H: \"%s\"\n",i+1,obuf);
 
4294
                                        return false;
 
4295
                                }
 
4296
                                *q = 0;
 
4297
                                y = atof(p)*100.0f;
 
4298
                                p = q+1;
 
4299
 
 
4300
                                while (*p == ' ')
 
4301
                                        p++;
 
4302
                                q = p;
 
4303
                                while ((*q != ' ') && (*q != 0))
 
4304
                                        q++;
 
4305
                                *q = 0;
 
4306
                                z = atof(p)*100.0f;
 
4307
 
 
4308
                                m_vaCoords.Add(CxVector3(x,y,z));
 
4309
                        }
 
4310
                        break;
 
4311
                }
 
4312
        }
 
4313
        return true;
 
4314
}
 
4315
 
 
4316
 
 
4317
bool CTimeStep::SkipDLPOLY(FILE *a)
 
4318
{
 
4319
        int i, j;
 
4320
        char buf[256], obuf[256], *p, *q;
 
4321
 
 
4322
        while (true)
 
4323
        {
 
4324
                fgets_bin(buf,256,a);
 
4325
                if (feof(a))
 
4326
                        return false;
 
4327
                if (strlen(buf) == 0)
 
4328
                        continue;
 
4329
                buf[strlen(buf)-1] = 0;
 
4330
                strcpy(obuf,buf);
 
4331
 
 
4332
                if (strstr(buf,"timestep") != 0)
 
4333
                {
 
4334
                        p = &buf[0];
 
4335
                        while (*p == ' ')
 
4336
                                p++;
 
4337
                        q = p;
 
4338
                        while ((*q != ' ') && (*q != 0))
 
4339
                                q++;
 
4340
                        if (*q == 0)
 
4341
                        {
 
4342
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line A: \"%s\"\n",obuf);
 
4343
                                return false;
 
4344
                        }
 
4345
                        *q = 0;
 
4346
                        p=q+1;
 
4347
 
 
4348
                        while (*p == ' ')
 
4349
                                p++;
 
4350
                        q = p;
 
4351
                        while ((*q != ' ') && (*q != 0))
 
4352
                                q++;
 
4353
                        if (*q == 0)
 
4354
                        {
 
4355
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line B: \"%s\"\n",obuf);
 
4356
                                return false;
 
4357
                        }
 
4358
                        *q = 0;
 
4359
                        p=q+1;
 
4360
 
 
4361
                        while (*p == ' ')
 
4362
                                p++;
 
4363
                        q = p;
 
4364
                        while ((*q != ' ') && (*q != 0))
 
4365
                                q++;
 
4366
                        if (*q == 0)
 
4367
                        {
 
4368
                                eprintf("\nCTimeStep::ReadDLPOLY(): Incomplete line C: \"%s\"\n",obuf);
 
4369
                                return false;
 
4370
                        }
 
4371
                        *q = 0;
 
4372
                        j = atoi(p);
 
4373
 
 
4374
                        fgets_bin(buf,256,a);
 
4375
                        fgets_bin(buf,256,a);
 
4376
                        fgets_bin(buf,256,a);
 
4377
 
 
4378
                        if (j == 0)
 
4379
                        {
 
4380
                                eprintf("CTimeStep::ReadDLPOLY(): Error: Atom count is 0.\n");
 
4381
                                return false;
 
4382
                        }
 
4383
 
 
4384
                        for (i=0;i<j;i++)
 
4385
                        {
 
4386
                                fgets_bin(buf,256,a);
 
4387
                                fgets_bin(buf,256,a);
 
4388
                                if (feof(a))
 
4389
                                        return false;
 
4390
                        }
 
4391
                        break;
 
4392
                }
 
4393
        }
 
4394
        return true;
 
4395
}
 
4396
 
 
4397
 
 
4398
bool CTimeStep::ReadMol2(FILE *a, bool needinfo)
 
4399
{
 
4400
        int i;
 
4401
        char buf[256], obuf[256], *p, *q, *r;
 
4402
        float x, y, z;
 
4403
 
 
4404
        fgets_bin(buf,256,a);
 
4405
        fgets_bin(buf,256,a);
 
4406
        fgets_bin(buf,256,a);
 
4407
        p = buf;
 
4408
        while (*p == ' ')
 
4409
                p++;
 
4410
        q = p;
 
4411
        while ((*q != ' ') && (*q != 0))
 
4412
                q++;
 
4413
        *q = 0;
 
4414
        m_iGesAtomCount = atoi(p);
 
4415
        
 
4416
        if (needinfo)
 
4417
        {
 
4418
                m_vaCoords.RemoveAll_KeepSize();
 
4419
                for (i=0;i<m_paLabels.GetSize();i++)
 
4420
                        delete[] (char*)m_paLabels[i];
 
4421
                m_paLabels.RemoveAll();
 
4422
                m_paLabels.SetSize(m_iGesAtomCount);
 
4423
                for (i=0;i<m_paMol2Types.GetSize();i++)
 
4424
                        delete[] (char*)m_paMol2Types[i];
 
4425
                m_paMol2Types.RemoveAll();
 
4426
                m_paMol2Types.SetSize(m_iGesAtomCount);
 
4427
        }
 
4428
        fgets_bin(buf,256,a);
 
4429
        fgets_bin(buf,256,a);
 
4430
        fgets_bin(buf,256,a);
 
4431
        fgets_bin(buf,256,a);
 
4432
        fgets_bin(buf,256,a);
 
4433
 
 
4434
        for (i=0;i<(long)m_iGesAtomCount;i++)
 
4435
        {
 
4436
                fgets_bin(buf,256,a);
 
4437
                if (feof(a))
 
4438
                        return false;
 
4439
                buf[strlen(buf)-1] = 0;
 
4440
                strcpy(obuf,buf);
 
4441
//              mprintf("  \"%s\"\n",buf);
 
4442
                p = buf;
 
4443
                while (*p == ' ')
 
4444
                        p++;
 
4445
                while ((*p != ' ') && (*p != 0))
 
4446
                        p++;
 
4447
                while (*p == ' ')
 
4448
                        p++;
 
4449
                q = p;
 
4450
                while (isalpha(*q) || (*q == '_'))
 
4451
                        q++;
 
4452
                if (needinfo)
 
4453
                {
 
4454
                        *q = 0;
 
4455
                        if (strlen(p) > 7)
 
4456
                        {
 
4457
                                eprintf("\nCTimeStep::ReadMol2(): \"%s\" - maximum length for atom labels is 7 chars; truncating.\n",p);
 
4458
                                p[7] = 0;
 
4459
                        }
 
4460
 
 
4461
                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
 
4462
                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
4463
                        
 
4464
                        strcpy(r,p);
 
4465
                        m_paLabels[i] = r;
 
4466
                }
 
4467
                p = q+1;
 
4468
                while ((*p != ' ') && (*p != 0))
 
4469
                        p++;
 
4470
                while (*p == ' ')
 
4471
                        p++;
 
4472
 
 
4473
                q = strchr(p,' ');
 
4474
                if (q == NULL)
 
4475
                {
 
4476
                        eprintf("\nCTimeStep::ReadMol2(): Error 1. %d. \"%s\".",i+1,obuf);
 
4477
                        return false;
 
4478
                }
 
4479
                *q = 0;
 
4480
                x = (float)atof(p) * 100.0f;
 
4481
                p = q+1;
 
4482
                while (*p == ' ')
 
4483
                        p++;
 
4484
 
 
4485
                q = strchr(p,' ');
 
4486
                if (q == NULL)
 
4487
                {
 
4488
                        eprintf("\nCTimeStep::ReadMol2(): Error 2. %d. \"%s\".",i+1,obuf);
 
4489
                        return false;
 
4490
                }
 
4491
                *q = 0;
 
4492
                y = (float)atof(p) * 100.0f;
 
4493
                p = q+1;
 
4494
                while (*p == ' ')
 
4495
                        p++;
 
4496
 
 
4497
                q = strchr(p,' ');
 
4498
                if (q == NULL)
 
4499
                {
 
4500
                        eprintf("\nCTimeStep::ReadMol2(): Error 3. %d. \"%s\".",i+1,obuf);
 
4501
                        return false;
 
4502
                }
 
4503
                *q = 0;
 
4504
                z = (float)atof(p) * 100.0f;
 
4505
                m_vaCoords.Add(CxVector3(x,y,z));
 
4506
 
 
4507
                p = q+1;
 
4508
                while (*p == ' ')
 
4509
                        p++;
 
4510
                q = p;
 
4511
                while ((*q != ' ') && (*q != 0))
 
4512
                        q++;
 
4513
                if (needinfo)
 
4514
                {
 
4515
                        *q = 0;
 
4516
 
 
4517
                        try { r = new char[strlen(p)+1]; } catch(...) { r = NULL; }
 
4518
                        if (r == NULL) NewException((double)(strlen(p)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
4519
                        
 
4520
                        strcpy(r,p);
 
4521
                        m_paMol2Types[i] = r;
 
4522
                }
 
4523
/*              mprintf("  X=%f, Y=%f, Z=%f",x,y,z);
 
4524
                if (needinfo)
 
4525
                        mprintf(", A=%s, B=%s",(char*)m_paLabels[i],(char*)m_paMol2Types[i]);
 
4526
                mprintf("\n");*/
 
4527
        }
 
4528
        m_iGesAtomCount = m_vaCoords.GetSize();
 
4529
 
 
4530
        return true;
 
4531
}
 
4532
 
 
4533
 
 
4534
bool CTimeStep::SkipMol2(FILE *a)
 
4535
{
 
4536
        int i;
 
4537
        char buf[256];
 
4538
 
 
4539
        fgets_bin(buf,256,a);
 
4540
        fgets_bin(buf,256,a);
 
4541
        fgets_bin(buf,256,a);
 
4542
        fgets_bin(buf,256,a);
 
4543
        fgets_bin(buf,256,a);
 
4544
        fgets_bin(buf,256,a);
 
4545
        fgets_bin(buf,256,a);
 
4546
        fgets_bin(buf,256,a);
 
4547
 
 
4548
        for (i=0;i<(long)m_iGesAtomCount;i++)
 
4549
        {
 
4550
                fgets_bin(buf,256,a);
 
4551
                if (feof(a))
 
4552
                        return false;
 
4553
        }
 
4554
 
 
4555
        return true;
 
4556
}
 
4557
 
 
4558
 
 
4559
void CTimeStep::CalcMinMax()
 
4560
{
 
4561
        int z;
 
4562
 
 
4563
        m_vMin[0] = 1E20f;
 
4564
        m_vMin[1] = 1E20f;
 
4565
        m_vMin[2] = 1E20f;
 
4566
        m_vMax[0] = -1E20f;
 
4567
        m_vMax[1] = -1E20f;
 
4568
        m_vMax[2] = -1E20f;
 
4569
 
 
4570
        for (z=0;z<(long)m_iGesAtomCount;z++)
 
4571
        {
 
4572
                if (m_vMin[0] > m_vaCoords[z][0])
 
4573
                        m_vMin[0] = m_vaCoords[z][0];
 
4574
                if (m_vMin[1] > m_vaCoords[z][1])
 
4575
                        m_vMin[1] = m_vaCoords[z][1];
 
4576
                if (m_vMin[2] > m_vaCoords[z][2])
 
4577
                        m_vMin[2] = m_vaCoords[z][2];
 
4578
                if (m_vMax[0] < m_vaCoords[z][0])
 
4579
                        m_vMax[0] = m_vaCoords[z][0];
 
4580
                if (m_vMax[1] < m_vaCoords[z][1])
 
4581
                        m_vMax[1] = m_vaCoords[z][1];
 
4582
                if (m_vMax[2] < m_vaCoords[z][2])
 
4583
                        m_vMax[2] = m_vaCoords[z][2];
 
4584
        }
 
4585
}
 
4586
 
 
4587
 
 
4588
void CTimeStep::WriteMol2(FILE *a)
 
4589
{
 
4590
        int z, z2, z3, z4, ti, c, mc;
 
4591
        CMolecule *m;
 
4592
        CSingleMolecule *sm;
 
4593
        int bonds;
 
4594
        int *tpi;
 
4595
        char *cc;
 
4596
 
 
4597
        bonds = 0;
 
4598
        for (z=0;z<g_oaSingleMolecules.GetSize();z++)
 
4599
                bonds += ((CSingleMolecule*)g_oaSingleMolecules[z])->m_oaBonds.GetSize();
 
4600
 
 
4601
        try { tpi = new int[g_iGesAtomCount]; } catch(...) { tpi = NULL; }
 
4602
        if (tpi == NULL) NewException((double)g_iGesAtomCount*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
4603
        
 
4604
        mfprintf(a," @<TRIPOS>MOLECULE\n");
 
4605
        mfprintf(a,"MOL\n");
 
4606
        mfprintf(a,"    %d    %d     %d  0  0\n",g_iGesAtomCount,bonds,g_oaSingleMolecules.GetSize());
 
4607
        mfprintf(a," SMALL\n");
 
4608
        mfprintf(a,"resp\n\n\n");
 
4609
        mfprintf(a," @<TRIPOS>ATOM\n");
 
4610
        c = 0;
 
4611
        mc = 0;
 
4612
        if (m_faCharge.GetSize() != g_iGesAtomCount)
 
4613
        {
 
4614
                m_faCharge.SetSize(g_iGesAtomCount);
 
4615
                for (z=0;z<g_iGesAtomCount;z++)
 
4616
                        m_faCharge[z] = 0;
 
4617
        }
 
4618
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
4619
        {
 
4620
                m = (CMolecule*)g_oaMolecules[z];
 
4621
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
4622
                {
 
4623
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
4624
                        mc++;
 
4625
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
4626
                        {
 
4627
                                if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
 
4628
                                        continue;
 
4629
                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
4630
                                {
 
4631
                                        ti = ((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4);
 
4632
                                        if (m_paMol2Types.GetSize() != 0)
 
4633
                                                cc = (char*)m_paMol2Types[ti];
 
4634
                                                        else cc = ((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName;
 
4635
                                        tpi[ti] = c++;
 
4636
                                        mfprintf(a,"  %6d  %2s  % 11.4f  % 11.4f  % 11.4f  %2s  %4d  MOL  % 8.4f\n",c,((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0,m_vaCoords[ti][1]/100.0,m_vaCoords[ti][2]/100.0,cc,mc,m_faCharge[ti]);
 
4637
                                }
 
4638
                        }
 
4639
                }
 
4640
        }
 
4641
        mfprintf(a," @<TRIPOS>BOND\n");
 
4642
        c = 0;
 
4643
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
4644
        {
 
4645
                m = (CMolecule*)g_oaMolecules[z];
 
4646
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
4647
                {
 
4648
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
4649
                        for (z3=0;z3<sm->m_oaBonds.GetSize();z3++)
 
4650
                                mfprintf(a,"  %6d  %6d  %6d  1\n",++c,tpi[((CMolBond*)sm->m_oaBonds[z3])->m_iAtomOffset[0]]+1,tpi[((CMolBond*)sm->m_oaBonds[z3])->m_iAtomOffset[1]]+1);
 
4651
                }
 
4652
        }
 
4653
        mfprintf(a," @<TRIPOS>SUBSTRUCTURE\n");
 
4654
        c = 0;
 
4655
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
4656
        {
 
4657
                m = (CMolecule*)g_oaMolecules[z];
 
4658
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
4659
                {
 
4660
                        mfprintf(a,"  %4d  MOL  %4d  TEMP              0 ****  ****    0 ROOT\n",c+1,c+1);
 
4661
                        c++;
 
4662
                }
 
4663
        }
 
4664
        delete[] tpi;
 
4665
}
 
4666
 
 
4667
 
 
4668
void CTimeStep::ReadCellVector(FILE *a)
 
4669
{
 
4670
        char buf[256], obuf[256];
 
4671
        char *p, *q;
 
4672
        float tf;
 
4673
 
 
4674
        fgets(buf,256,a);
 
4675
        if (feof(a))
 
4676
        {
 
4677
                eprintf("\nReadCellVector: End of file.\n");
 
4678
                eprintf("Your cell vector text file is too short.\n");
 
4679
                return;
 
4680
        }
 
4681
        if (strlen(buf) == 0)
 
4682
        {
 
4683
                eprintf("\nReadCellVector: Empty line.\n");
 
4684
                return;
 
4685
        }
 
4686
        buf[strlen(buf)-1] = 0;
 
4687
        strcpy(obuf,buf);
 
4688
//      mprintf(GREY,"\nReadCellVector: \"%s\".\n",buf);
 
4689
        p = buf;
 
4690
        while ((!isnumeric(*p)) && (*p != 0))
 
4691
                p++;
 
4692
        if (*p == 0)
 
4693
        {
 
4694
                eprintf("\nReadCellVector: Incomplete line (1) \"%s\".\n",obuf);
 
4695
                return;
 
4696
        }
 
4697
        q = p;
 
4698
        while (isnumeric(*q))
 
4699
                q++;
 
4700
        if (*q == 0)
 
4701
        {
 
4702
                eprintf("\nReadCellVector: Incomplete line (2) \"%s\".\n",obuf);
 
4703
                return;
 
4704
        }
 
4705
        *q = 0;
 
4706
        tf = (float)(atof(p)*100.0);
 
4707
        if (tf <= 0)
 
4708
        {
 
4709
                eprintf("\nReadCellVector: Cell vectors need to be > 0 (X) \"%s\".\n",obuf);
 
4710
                return;
 
4711
        }
 
4712
        g_fBoxX = tf;
 
4713
 
 
4714
        p = q+1;
 
4715
        while ((!isnumeric(*p)) && (*p != 0))
 
4716
                p++;
 
4717
        if (*p == 0)
 
4718
        {
 
4719
                eprintf("\nReadCellVector: Incomplete line (3) \"%s\".\n",obuf);
 
4720
                return;
 
4721
        }
 
4722
        q = p;
 
4723
        while (isnumeric(*q))
 
4724
                q++;
 
4725
        if (*q == 0)
 
4726
        {
 
4727
                eprintf("\nReadCellVector: Incomplete line (4) \"%s\".\n",obuf);
 
4728
                return;
 
4729
        }
 
4730
        *q = 0;
 
4731
        tf = (float)(atof(p)*100.0);
 
4732
        if (tf <= 0)
 
4733
        {
 
4734
                eprintf("\nReadCellVector: Cell vectors need to be > 0 (Y) \"%s\".\n",obuf);
 
4735
                return;
 
4736
        }
 
4737
        g_fBoxY = tf;
 
4738
        p = q+1;
 
4739
 
 
4740
        while ((!isnumeric(*p)) && (*p != 0))
 
4741
                p++;
 
4742
        if (*p == 0)
 
4743
        {
 
4744
                eprintf("\nReadCellVector: Incomplete line (5) \"%s\".\n",obuf);
 
4745
                return;
 
4746
        }
 
4747
        q = p;
 
4748
        while (isnumeric(*q))
 
4749
                q++;
 
4750
        if (*q != 0)
 
4751
                *q = 0;
 
4752
        tf = (float)(atof(p)*100.0);
 
4753
        if (tf <= 0)
 
4754
        {
 
4755
                eprintf("\nReadCellVector: Cell vectors need to be > 0 (Z) \"%s\".\n",obuf);
 
4756
                return;
 
4757
        }
 
4758
        g_fBoxZ = tf;
 
4759
 
 
4760
//      mprintf(GREY," --> %f %f %f\n",g_fBoxX,g_fBoxY,g_fBoxZ);
 
4761
}
 
4762
 
 
4763
 
 
4764
void CTimeStep::CenterCOM()
 
4765
{
 
4766
        CxVector3 vc;
 
4767
        double m;
 
4768
        int z;
 
4769
 
 
4770
        vc = CxVector3(0,0,0);
 
4771
        m = 0;
 
4772
        for (z=0;z<g_iGesAtomCount;z++)
 
4773
        {
 
4774
                if (g_bWannier)
 
4775
                        if (g_baAtomIndex[z] == g_iWannierAtomType)
 
4776
                                continue;
 
4777
                vc += m_vaCoords[z] * ((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_pElement->m_fMass;
 
4778
                m += ((CAtom*)g_oaAtoms[g_baAtomIndex[z]])->m_pElement->m_fMass;
 
4779
        }
 
4780
        vc /= m;
 
4781
        for (z=0;z<g_iGesAtomCount;z++)
 
4782
                m_vaCoords[z] -= vc;
 
4783
}
 
4784
 
 
4785
 
 
4786
float CTimeStep::FoldedDistance(int i1, int i2)
 
4787
{
 
4788
        CxVector3 t;
 
4789
 
 
4790
        t = m_vaCoords[i2]-m_vaCoords[i1];
 
4791
 
 
4792
        if (g_bPeriodicX)
 
4793
        {
 
4794
                while (t[0] < -g_fBoxX/2) t[0] += g_fBoxX;
 
4795
                while (t[0] >= g_fBoxX/2) t[0] -= g_fBoxX;
 
4796
        }
 
4797
 
 
4798
        if (g_bPeriodicY)
 
4799
        {
 
4800
                while (t[1] < -g_fBoxY/2) t[1] += g_fBoxY;
 
4801
                while (t[1] >= g_fBoxY/2) t[1] -= g_fBoxY;
 
4802
        }
 
4803
 
 
4804
        if (g_bPeriodicZ)
 
4805
        {
 
4806
                while (t[2] < -g_fBoxZ/2) t[2] += g_fBoxZ;
 
4807
                while (t[2] >= g_fBoxZ/2) t[2] -= g_fBoxZ;
 
4808
        }
 
4809
 
 
4810
        return t.GetLength();
 
4811
}
 
4812
 
 
4813
 
 
4814
void CTimeStep::FoldAtomsPositive()
 
4815
{
 
4816
        BTIN;
 
4817
        int z;
 
4818
 
 
4819
        if (!g_bPeriodic)
 
4820
                return;
 
4821
 
 
4822
        for (z=0;z<g_iGesVirtAtomCount;z++)
 
4823
        {
 
4824
                if (g_bPeriodicX)
 
4825
                {
 
4826
                        while (m_vaCoords[z][0] < 0) m_vaCoords[z][0] += g_fBoxX;
 
4827
                        while (m_vaCoords[z][0] >= g_fBoxX) m_vaCoords[z][0] -= g_fBoxX;
 
4828
                }
 
4829
 
 
4830
                if (g_bPeriodicX)
 
4831
                {
 
4832
                        while (m_vaCoords[z][1] < 0) m_vaCoords[z][1] += g_fBoxY;
 
4833
                        while (m_vaCoords[z][1] >= g_fBoxY) m_vaCoords[z][1] -= g_fBoxY;
 
4834
                }
 
4835
 
 
4836
                if (g_bPeriodicX)
 
4837
                {
 
4838
                        while (m_vaCoords[z][2] < 0) m_vaCoords[z][2] += g_fBoxZ;
 
4839
                        while (m_vaCoords[z][2] >= g_fBoxZ) m_vaCoords[z][2] -= g_fBoxZ;
 
4840
                }
 
4841
        }
 
4842
        BTOUT; 
 
4843
}
 
4844
 
 
4845
 
 
4846
void CTimeStep::WritePOV(const char *s)
 
4847
{
 
4848
        FILE *b;
 
4849
        CMolecule *m;
 
4850
        CSingleMolecule *sm;
 
4851
        CElement *el, *el2;
 
4852
        int z, z2, z3, z4, o, o2;
 
4853
        CxVector3 vec1, vec2, vec3, vec1b, vec2b, vec3b, vecA, vecB, vecC, vecD;
 
4854
        CMolBond *mb;
 
4855
        CxVector3 cam;
 
4856
//      float cr, cg, cb;
 
4857
 
 
4858
        b = OpenFileWrite(s,true);
 
4859
 
 
4860
        mfprintf(b,"// Written by TRAVIS\n");
 
4861
        mfprintf(b,"// See http://www.travis-analyzer.de\n\n");
 
4862
        mfprintf(b,"#version 3.6;\n");
 
4863
        mfprintf(b,"\n");
 
4864
 
 
4865
        mfprintf(b,"/**** Atoms ****/\n");
 
4866
 
 
4867
        mfprintf(b,"#declare atom_draw          = true;\n");
 
4868
        mfprintf(b,"#declare atom_r             = 0.65;\n");
 
4869
        mfprintf(b,"#declare atom_specular      = 0.7;\n");
 
4870
        mfprintf(b,"#declare atom_reflect       = 0;\n");
 
4871
        mfprintf(b,"#declare atom_ambient       = 0.2;\n");
 
4872
        mfprintf(b,"#declare atom_diffuse       = 0.7;\n");
 
4873
        mfprintf(b,"//#declare atom_color         = < 1.0, 1.0, 1.0, 0, 0 >;\n");
 
4874
        mfprintf(b,"//#declare atom_trans         = 0.7;\n");
 
4875
 
 
4876
        mfprintf(b,"\n");
 
4877
 
 
4878
        mfprintf(b,"#declare atom_draw_halo1      = true;\n");
 
4879
        mfprintf(b,"#declare atom_r_halo1         = 0.008;\n");
 
4880
        mfprintf(b,"#declare atom_d_halo1         = 0.0125;\n");
 
4881
        mfprintf(b,"#declare atom_color_halo1     = < 0, 0, 0, 0, 0 >;\n");
 
4882
        mfprintf(b,"#declare atom_specular_halo1  = 0;\n");
 
4883
        mfprintf(b,"#declare atom_reflect_halo1   = 0;\n");
 
4884
        mfprintf(b,"#declare atom_ambient_halo1   = 1.0;\n");
 
4885
        mfprintf(b,"#declare atom_diffuse_halo1   = 0;\n");
 
4886
 
 
4887
        mfprintf(b,"\n");
 
4888
 
 
4889
        mfprintf(b,"#declare atom_draw_halo2      = true;\n");
 
4890
        mfprintf(b,"#declare atom_r_halo2         = 0.003;\n");
 
4891
        mfprintf(b,"#declare atom_d_halo2         = 0.01875;\n");
 
4892
        mfprintf(b,"#declare atom_color_halo2     = < 1, 1, 1, 0, 0 >;\n");
 
4893
        mfprintf(b,"#declare atom_specular_halo2  = 0;\n");
 
4894
        mfprintf(b,"#declare atom_reflect_halo2   = 0;\n");
 
4895
        mfprintf(b,"#declare atom_ambient_halo2   = 1.0;\n");
 
4896
        mfprintf(b,"#declare atom_diffuse_halo2   = 0;\n");
 
4897
 
 
4898
        mfprintf(b,"\n");
 
4899
 
 
4900
        mfprintf(b,"#declare atom_draw_halo3      = true;\n");
 
4901
        mfprintf(b,"#declare atom_r_halo3         = 0.003;\n");
 
4902
        mfprintf(b,"#declare atom_d_halo3         = 0.025;\n");
 
4903
        mfprintf(b,"#declare atom_color_halo3     = < 1, 1, 1, 0, 0.5 >;\n");
 
4904
        mfprintf(b,"#declare atom_specular_halo3  = 0;\n");
 
4905
        mfprintf(b,"#declare atom_reflect_halo3   = 0;\n");
 
4906
        mfprintf(b,"#declare atom_ambient_halo3   = 1.0;\n");
 
4907
        mfprintf(b,"#declare atom_diffuse_halo3   = 0;\n");
 
4908
 
 
4909
        mfprintf(b,"\n");
 
4910
 
 
4911
        mfprintf(b,"/**** Bonds ****/\n");
 
4912
 
 
4913
        mfprintf(b,"#declare bond_draw        = true;\n");
 
4914
        mfprintf(b,"#declare bond_r           = 0.015;\n");
 
4915
        mfprintf(b,"#declare bond_specular    = 0.7;\n");
 
4916
        mfprintf(b,"#declare bond_reflect     = 0;\n");
 
4917
        mfprintf(b,"#declare bond_ambient     = 0.2;\n");
 
4918
        mfprintf(b,"#declare bond_diffuse     = 0.7;\n");
 
4919
 
 
4920
        mfprintf(b,"\n");
 
4921
 
 
4922
        mfprintf(b,"#declare bond_draw_halo1      = true;\n");
 
4923
        mfprintf(b,"#declare bond_r_halo1         = 0.008;\n");
 
4924
        mfprintf(b,"#declare bond_d_halo1         = 0;\n");
 
4925
        mfprintf(b,"#declare bond_color_halo1     = < 0, 0, 0, 0, 0 >;\n");
 
4926
        mfprintf(b,"#declare bond_specular_halo1  = 0;\n");
 
4927
        mfprintf(b,"#declare bond_reflect_halo1   = 0;\n");
 
4928
        mfprintf(b,"#declare bond_ambient_halo1   = 1.0;\n");
 
4929
        mfprintf(b,"#declare bond_diffuse_halo1   = 0;\n");
 
4930
 
 
4931
        mfprintf(b,"\n");
 
4932
 
 
4933
        mfprintf(b,"#declare bond_draw_halo2      = true;\n");
 
4934
        mfprintf(b,"#declare bond_r_halo2         = 0.003;\n");
 
4935
        mfprintf(b,"#declare bond_d_halo2         = 0.0286;\n");
 
4936
        mfprintf(b,"#declare bond_color_halo2     = < 1, 1, 1, 0, 0 >;\n");
 
4937
        mfprintf(b,"#declare bond_specular_halo2  = 0;\n");
 
4938
        mfprintf(b,"#declare bond_reflect_halo2   = 0;\n");
 
4939
        mfprintf(b,"#declare bond_ambient_halo2   = 1.0;\n");
 
4940
        mfprintf(b,"#declare bond_diffuse_halo2   = 0;\n");
 
4941
 
 
4942
        mfprintf(b,"\n");
 
4943
 
 
4944
        mfprintf(b,"#declare bond_draw_halo3      = true;\n");
 
4945
        mfprintf(b,"#declare bond_r_halo3         = 0.003;\n");
 
4946
        mfprintf(b,"#declare bond_d_halo3         = 0.0333;\n");
 
4947
        mfprintf(b,"#declare bond_color_halo3     = < 1, 1, 1, 0, 0.5 >;\n");
 
4948
        mfprintf(b,"#declare bond_specular_halo3  = 0;\n");
 
4949
        mfprintf(b,"#declare bond_reflect_halo3   = 0;\n");
 
4950
        mfprintf(b,"#declare bond_ambient_halo3   = 1.0;\n");
 
4951
        mfprintf(b,"#declare bond_diffuse_halo3   = 0;\n");
 
4952
 
 
4953
        mfprintf(b,"\n");
 
4954
 
 
4955
        mfprintf(b,"#declare bond_draw_stub       = true;\n");
 
4956
        mfprintf(b,"#declare bond_r_stub          = 0.004;\n");
 
4957
        mfprintf(b,"#declare bond_l_stub          = 0.004;\n");
 
4958
        mfprintf(b,"#declare bond_color_stub      = < 0, 0, 0, 0, 0 >;\n");
 
4959
        mfprintf(b,"#declare bond_specular_stub   = 0;\n");
 
4960
        mfprintf(b,"#declare bond_reflect_stub    = 0;\n");
 
4961
        mfprintf(b,"#declare bond_ambient_stub    = 1.0;\n");
 
4962
        mfprintf(b,"#declare bond_diffuse_stub    = 0;\n");
 
4963
 
 
4964
        mfprintf(b,"\n");
 
4965
 
 
4966
        mfprintf(b,"/**** Element Colors ****/\n");
 
4967
        for (z=0;z<g_oaAtoms.GetSize();z++)
 
4968
        {
 
4969
                if (z == g_iVirtAtomType)
 
4970
                        continue;
 
4971
                el = ((CAtom*)g_oaAtoms[z])->m_pElement;
 
4972
                mfprintf(b,"#declare elem_%s_col   = < %f, %f, %f, 0, 0 >;\n",el->m_sLabel,el->m_iColorR/255.0,el->m_iColorG/255.0,el->m_iColorB/255.0);
 
4973
        }
 
4974
 
 
4975
        mfprintf(b,"\n/**** Element Radii ****/\n");
 
4976
        for (z=0;z<g_oaAtoms.GetSize();z++)
 
4977
        {
 
4978
                if (z == g_iVirtAtomType)
 
4979
                        continue;
 
4980
                el = ((CAtom*)g_oaAtoms[z])->m_pElement;
 
4981
                mfprintf(b,"#declare elem_%s_r  = %f;\n",el->m_sLabel,el->m_fRadius/1000.0);
 
4982
        }
 
4983
        mfprintf(b,"\n");
 
4984
 
 
4985
        cam[0] = 0;
 
4986
        cam[1] = 0;
 
4987
        cam[2] = 40.0;
 
4988
 
 
4989
        mfprintf(b,"global_settings {\n");
 
4990
        mfprintf(b,"  assumed_gamma 1\n");
 
4991
        mfprintf(b,"/*  radiosity {\n");
 
4992
        mfprintf(b,"    pretrace_start 0.08\n");
 
4993
        mfprintf(b,"    pretrace_end   0.04\n");
 
4994
        mfprintf(b,"    count 100\n\n");
 
4995
        mfprintf(b,"    nearest_count 5\n");
 
4996
        mfprintf(b,"    error_bound 0.4\n");
 
4997
        mfprintf(b,"    recursion_limit 1\n\n");
 
4998
        mfprintf(b,"    low_error_factor .5\n");
 
4999
        mfprintf(b,"    gray_threshold 0.0\n");
 
5000
        mfprintf(b,"    minimum_reuse 0.015\n");
 
5001
        mfprintf(b,"    brightness 1\n\n");
 
5002
        mfprintf(b,"    adc_bailout 0.01/2\n");
 
5003
        mfprintf(b,"  }*/\n");
 
5004
        mfprintf(b,"}\n");
 
5005
 
 
5006
        mfprintf(b,"\ncamera {\n");
 
5007
        mfprintf(b,"    location <%f, %f, %f>\n",cam[0],cam[1],cam[2]);
 
5008
        mfprintf(b,"    sky y\n");
 
5009
        mfprintf(b,"    right -0.06*x*image_width/image_height\n");
 
5010
        mfprintf(b,"    up 0.06*y\n");
 
5011
        mfprintf(b,"    look_at <0, 0, 0>\n");
 
5012
        mfprintf(b,"}\n");
 
5013
        mfprintf(b,"\n");
 
5014
 
 
5015
        mfprintf(b,"// Solid background\n");
 
5016
        mfprintf(b,"background { rgb < 0.15, 0.1, 0.3 > }\n");
 
5017
        mfprintf(b,"\n");
 
5018
 
 
5019
        mfprintf(b,"// Gradient background\n");
 
5020
        mfprintf(b,"sky_sphere {\n");
 
5021
        mfprintf(b,"  pigment {\n");
 
5022
        mfprintf(b,"    gradient y\n");
 
5023
        mfprintf(b,"    color_map {\n");
 
5024
        mfprintf(b,"      [ 0 color rgb < 0.05, 0.05, 0.05 > ]\n");
 
5025
        mfprintf(b,"      [ 1 color rgb < 0.20, 0.16, 0.50 > ]\n");
 
5026
        mfprintf(b,"    }\n");
 
5027
        mfprintf(b,"    scale 0.1\n");
 
5028
        mfprintf(b,"    translate -0.05\n");
 
5029
        mfprintf(b,"  }\n");
 
5030
        mfprintf(b,"}\n\n");
 
5031
 
 
5032
        mfprintf(b,"/**** Invisible, only for Radiosity ****/\n");
 
5033
        mfprintf(b,"sphere {\n");
 
5034
        mfprintf(b,"  <0, 0, 0>, 1\n");
 
5035
        mfprintf(b,"  texture {\n");
 
5036
        mfprintf(b,"    pigment {color rgb < 1.0, 1.0, 1.0 > }\n");
 
5037
        mfprintf(b,"    finish { diffuse 0 ambient 1 }\n");
 
5038
        mfprintf(b,"  }\n");
 
5039
        mfprintf(b,"  hollow on\n");
 
5040
        mfprintf(b,"  no_shadow\n");
 
5041
        mfprintf(b,"  no_image\n");
 
5042
        mfprintf(b,"  scale 30000\n");
 
5043
        mfprintf(b,"}\n\n");
 
5044
 
 
5045
        mfprintf(b,"light_source { < -8, 20, 20 > color rgb 0.8 }\n");
 
5046
        mfprintf(b,"//light_source { < 25, 12, 20 > color rgb 0.5 }\n\n");
 
5047
 
 
5048
        mfprintf(b,"#macro m_atom_color(col)\n");
 
5049
        mfprintf(b,"  #ifdef(atom_color)\n");
 
5050
        mfprintf(b,"    atom_color\n");
 
5051
        mfprintf(b,"  #else #if (defined(atom_trans))\n");
 
5052
        mfprintf(b,"    col + < 0, 0, 0, 0, atom_trans >\n");
 
5053
        mfprintf(b,"  #else\n");
 
5054
        mfprintf(b,"    col\n");
 
5055
        mfprintf(b,"  #end #end\n");
 
5056
        mfprintf(b,"#end\n");
 
5057
 
 
5058
        mfprintf(b,"\nunion {\n");
 
5059
 
 
5060
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
5061
        {
 
5062
                m = (CMolecule*)g_oaMolecules[z];
 
5063
 
 
5064
                for (z2=0;z2<m->m_laSingleMolIndex.GetSize();z2++)
 
5065
                {
 
5066
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[z2]];
 
5067
 
 
5068
                        for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
5069
                        {
 
5070
                                if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
 
5071
                                        continue;
 
5072
 
 
5073
                                el = ((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_pElement;
 
5074
 
 
5075
                                for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
5076
                                {
 
5077
                                        o = ((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4);
 
5078
                                        vec1 = m_vaCoords[o];
 
5079
                                        vec1 /= 1000.0;
 
5080
 
 
5081
                                        mfprintf(b,"#if (atom_draw)\n");
 
5082
                                        mfprintf(b,"  sphere { <%g, %g, %g>, elem_%s_r*atom_r\n",vec1[0],vec1[1],vec1[2],el->m_sLabel);
 
5083
                                        mfprintf(b,"    pigment { rgbft m_atom_color(elem_%s_col) } finish { reflection atom_reflect specular atom_specular ambient atom_ambient diffuse atom_diffuse } }\n",el->m_sLabel);
 
5084
                                        mfprintf(b,"#end\n");
 
5085
 
 
5086
                                        vec2 = cam - vec1;
 
5087
                                        vec2.Normalize();
 
5088
 
 
5089
        //                              if (shadow)
 
5090
                                        {
 
5091
                                                mfprintf(b,"#if (atom_draw_halo1)\n");
 
5092
                                                mfprintf(b,"  disc { < %g - (%g) * atom_d_halo1, %g - (%g) * atom_d_halo1, %g - (%g) * atom_d_halo1 >,\n",vec1[0],vec2[0],vec1[1],vec2[1],vec1[2],vec2[2]);
 
5093
                                                mfprintf(b,"    < %g, %g, %g >, (elem_%s_r * atom_r) + atom_r_halo1, elem_%s_r * atom_r\n",vec2[0],vec2[1],vec2[2],el->m_sLabel,el->m_sLabel);
 
5094
                                                mfprintf(b,"    pigment { rgbft atom_color_halo1 } finish { reflection atom_reflect_halo1 specular atom_specular_halo1 ambient atom_ambient_halo1 diffuse atom_diffuse_halo1 } no_reflection no_radiosity }\n");
 
5095
                                                mfprintf(b,"#end\n");
 
5096
                                        }
 
5097
 
 
5098
        //                              if (halo)
 
5099
                                        {
 
5100
                                                mfprintf(b,"#if (atom_draw_halo2)\n");
 
5101
                                                mfprintf(b,"  disc { < %g - (%g) * atom_d_halo2, %g - (%g) * atom_d_halo2, %g - (%g) * atom_d_halo2 >,\n",vec1[0],vec2[0],vec1[1],vec2[1],vec1[2],vec2[2]);
 
5102
                                                mfprintf(b,"    < %g, %g, %g >, (elem_%s_r * atom_r) + atom_r_halo1 + atom_r_halo2, elem_%s_r * atom_r\n",vec2[0],vec2[1],vec2[2],el->m_sLabel,el->m_sLabel);
 
5103
                                                mfprintf(b,"    pigment { rgbft atom_color_halo2 } finish { reflection atom_reflect_halo2 specular atom_specular_halo2 ambient atom_ambient_halo2 diffuse atom_diffuse_halo2 } no_reflection no_radiosity }\n");
 
5104
                                                mfprintf(b,"#end\n");
 
5105
 
 
5106
                                                mfprintf(b,"#if (atom_draw_halo3)\n");
 
5107
                                                mfprintf(b,"  disc { < %g - (%g) * atom_d_halo3, %g - (%g) * atom_d_halo3, %g - (%g) * atom_d_halo3 >,\n",vec1[0],vec2[0],vec1[1],vec2[1],vec1[2],vec2[2]);
 
5108
                                                mfprintf(b,"    < %g, %g, %g >, (elem_%s_r * atom_r) + atom_r_halo1 + atom_r_halo2 + atom_r_halo3, elem_%s_r * atom_r\n",vec2[0],vec2[1],vec2[2],el->m_sLabel,el->m_sLabel);
 
5109
                                                mfprintf(b,"    pigment { rgbft atom_color_halo3 } finish { reflection atom_reflect_halo3 specular atom_specular_halo3 ambient atom_ambient_halo3 diffuse atom_diffuse_halo3 } no_reflection no_radiosity }\n");
 
5110
                                                mfprintf(b,"#end\n");
 
5111
                                        }
 
5112
                                }
 
5113
                        }
 
5114
 
 
5115
                        for (z3=0;z3<sm->m_oaBonds.GetSize();z3++)
 
5116
                        {
 
5117
                                mb = (CMolBond*)sm->m_oaBonds[z3];
 
5118
                                o = mb->m_iAtomOffset[0];
 
5119
                                o2 = mb->m_iAtomOffset[1];
 
5120
 
 
5121
                                el = ((CAtom*)g_oaAtoms[g_waAtomRealElement[o]])->m_pElement;
 
5122
                                el2 = ((CAtom*)g_oaAtoms[g_waAtomRealElement[o2]])->m_pElement;
 
5123
 
 
5124
                                vec1 = m_vaCoords[o];
 
5125
                                vec1 /= 1000.0;
 
5126
 
 
5127
                                vec2 = m_vaCoords[o2];
 
5128
                                vec2 /= 1000.0;
 
5129
 
 
5130
                                if ((vec1-vec2).GetLength() > 0.3)
 
5131
                                        continue;
 
5132
 
 
5133
                                vec3 = (vec1/el->m_fRadius + vec2/el2->m_fRadius) / (1.0/el->m_fRadius+1.0/el2->m_fRadius);
 
5134
 
 
5135
                                vec3b = vec2 - vec1;
 
5136
                                vec3b.Normalize();
 
5137
 
 
5138
                                mfprintf(b,"#local vec1c = < %g + (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ),\n",vec1[0],vec3b[0],el->m_sLabel,el->m_sLabel,el->m_sLabel,el->m_sLabel);
 
5139
                                mfprintf(b,"  %g + (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ),\n",vec1[1],vec3b[1],el->m_sLabel,el->m_sLabel,el->m_sLabel,el->m_sLabel);
 
5140
                                mfprintf(b,"  %g + (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ) >;\n",vec1[2],vec3b[2],el->m_sLabel,el->m_sLabel,el->m_sLabel,el->m_sLabel);
 
5141
                                mfprintf(b,"#local vec2c = < %g - (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ),\n",vec2[0],vec3b[0],el2->m_sLabel,el2->m_sLabel,el2->m_sLabel,el2->m_sLabel);
 
5142
                                mfprintf(b,"  %g - (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ),\n",vec2[1],vec3b[1],el2->m_sLabel,el2->m_sLabel,el2->m_sLabel,el2->m_sLabel);
 
5143
                                mfprintf(b,"  %g - (%g) * ( elem_%s_r*atom_r - ( elem_%s_r*atom_r - 0.5*sqrt(4*elem_%s_r*elem_%s_r*atom_r*atom_r - 4*bond_r*bond_r ) ) ) >;\n",vec2[2],vec3b[2],el2->m_sLabel,el2->m_sLabel,el2->m_sLabel,el2->m_sLabel);
 
5144
 
 
5145
                                mfprintf(b,"#if (bond_draw)\n");
 
5146
                                mfprintf(b,"  cylinder { < %g, %g, %g >, vec1c, bond_r open\n",vec3[0],vec3[1],vec3[2]);
 
5147
                                mfprintf(b,"    pigment { rgbft m_atom_color(elem_%s_col) } finish { reflection bond_reflect specular bond_specular ambient bond_ambient diffuse bond_diffuse } }\n",el->m_sLabel);
 
5148
                                mfprintf(b,"  cylinder { < %g, %g, %g >, vec2c, bond_r open\n",vec3[0],vec3[1],vec3[2]);
 
5149
                                mfprintf(b,"    pigment { rgbft m_atom_color(elem_%s_col) } finish { reflection bond_reflect specular bond_specular ambient bond_ambient diffuse bond_diffuse } }\n",el2->m_sLabel);
 
5150
                                mfprintf(b,"#end\n");
 
5151
 
 
5152
                                vec3 = cam - (vec1 + vec2) / 2.0;
 
5153
                                vec3.Normalize();
 
5154
 
 
5155
                                vec2b = vec2-vec1;
 
5156
                                vec1b = CrossP(vec3,vec2b);
 
5157
                                vec1b.Normalize();
 
5158
 
 
5159
                                mfprintf(b,"#local vec3  = < %g, %g, %g >;\n",vec3[0],vec3[1],vec3[2]);
 
5160
                                mfprintf(b,"#local vec1b = < %g, %g, %g >;\n",vec1b[0],vec1b[1],vec1b[2]);
 
5161
 
 
5162
//                              if (shadow)
 
5163
                                {
 
5164
                                        mfprintf(b,"#if (bond_draw_halo1)\n");
 
5165
                                        mfprintf(b,"  #local vecA = vec1c + vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo1;\n");
 
5166
                                        mfprintf(b,"  #local vecB = vec2c + vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo1;\n");
 
5167
                                        mfprintf(b,"  #local vecC = vec2c + vec1b * (bond_r) - vec3 * bond_d_halo1;\n");
 
5168
                                        mfprintf(b,"  #local vecD = vec1c + vec1b * (bond_r) - vec3 * bond_d_halo1;\n");
 
5169
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
 
5170
                                        mfprintf(b,"    pigment { rgbft bond_color_halo1 } finish { reflection bond_reflect_halo1 specular bond_specular_halo1 ambient bond_ambient_halo1 diffuse bond_diffuse_halo1 } no_reflection no_radiosity }\n");
 
5171
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
 
5172
                                        mfprintf(b,"    pigment { rgbft bond_color_halo1 } finish { reflection bond_reflect_halo1 specular bond_specular_halo1 ambient bond_ambient_halo1 diffuse bond_diffuse_halo1 } no_reflection no_radiosity }\n");
 
5173
                                        mfprintf(b,"  #local vecA = vec1c - vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo1;\n");
 
5174
                                        mfprintf(b,"  #local vecB = vec2c - vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo1;\n");
 
5175
                                        mfprintf(b,"  #local vecC = vec2c - vec1b * (bond_r) - vec3 * bond_d_halo1;\n");
 
5176
                                        mfprintf(b,"  #local vecD = vec1c - vec1b * (bond_r) - vec3 * bond_d_halo1;\n");
 
5177
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
 
5178
                                        mfprintf(b,"    pigment { rgbft bond_color_halo1 } finish { reflection bond_reflect_halo1 specular bond_specular_halo1 ambient bond_ambient_halo1 diffuse bond_diffuse_halo1 } no_reflection no_radiosity }\n");
 
5179
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
 
5180
                                        mfprintf(b,"    pigment { rgbft bond_color_halo1 } finish { reflection bond_reflect_halo1 specular bond_specular_halo1 ambient bond_ambient_halo1 diffuse bond_diffuse_halo1 } no_reflection no_radiosity }\n");
 
5181
                                        mfprintf(b,"#end\n");
 
5182
                                }
 
5183
 
 
5184
//                              if (halo)
 
5185
                                {
 
5186
                                        mfprintf(b,"#if (bond_draw_halo2)\n");
 
5187
                                        mfprintf(b,"  #local vecA = vec1c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
 
5188
                                        mfprintf(b,"  #local vecB = vec2c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
 
5189
                                        mfprintf(b,"  #local vecC = vec2c + vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo2;\n");
 
5190
                                        mfprintf(b,"  #local vecD = vec1c + vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo2;\n");
 
5191
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
 
5192
                                        mfprintf(b,"    pigment { rgbft bond_color_halo2 } finish { reflection bond_reflect_halo2 specular bond_specular_halo2 ambient bond_ambient_halo2 diffuse bond_diffuse_halo2 } no_reflection no_radiosity }\n");
 
5193
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
 
5194
                                        mfprintf(b,"    pigment { rgbft bond_color_halo2 } finish { reflection bond_reflect_halo2 specular bond_specular_halo2 ambient bond_ambient_halo2 diffuse bond_diffuse_halo2 } no_reflection no_radiosity }\n");
 
5195
                                        mfprintf(b,"  #local vecA = vec1c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
 
5196
                                        mfprintf(b,"  #local vecB = vec2c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
 
5197
                                        mfprintf(b,"  #local vecC = vec2c - vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo2;\n");
 
5198
                                        mfprintf(b,"  #local vecD = vec1c - vec1b * (bond_r + bond_r_halo1) - vec3 * bond_d_halo2;\n");
 
5199
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
 
5200
                                        mfprintf(b,"    pigment { rgbft bond_color_halo2 } finish { reflection bond_reflect_halo2 specular bond_specular_halo2 ambient bond_ambient_halo2 diffuse bond_diffuse_halo2 } no_reflection no_radiosity }\n");
 
5201
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
 
5202
                                        mfprintf(b,"    pigment { rgbft bond_color_halo2 } finish { reflection bond_reflect_halo2 specular bond_specular_halo2 ambient bond_ambient_halo2 diffuse bond_diffuse_halo2 } no_reflection no_radiosity }\n");
 
5203
                                        mfprintf(b,"#end\n");
 
5204
 
 
5205
                                        mfprintf(b,"#if (bond_draw_halo3)\n");
 
5206
                                        mfprintf(b,"  #local vecA = vec1c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2 + bond_r_halo3) - vec3 * bond_d_halo2;\n");
 
5207
                                        mfprintf(b,"  #local vecB = vec2c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2 + bond_r_halo3) - vec3 * bond_d_halo2;\n");
 
5208
                                        mfprintf(b,"  #local vecC = vec2c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
 
5209
                                        mfprintf(b,"  #local vecD = vec1c + vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
 
5210
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
 
5211
                                        mfprintf(b,"    pigment { rgbft bond_color_halo3 } finish { reflection bond_reflect_halo3 specular bond_specular_halo3 ambient bond_ambient_halo3 diffuse bond_diffuse_halo3 } no_reflection no_radiosity }\n");
 
5212
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
 
5213
                                        mfprintf(b,"    pigment { rgbft bond_color_halo3 } finish { reflection bond_reflect_halo3 specular bond_specular_halo3 ambient bond_ambient_halo3 diffuse bond_diffuse_halo3 } no_reflection no_radiosity }\n");
 
5214
                                        mfprintf(b,"  #local vecA = vec1c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2 + bond_r_halo3) - vec3 * bond_d_halo2;\n");
 
5215
                                        mfprintf(b,"  #local vecB = vec2c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2 + bond_r_halo3) - vec3 * bond_d_halo2;\n");
 
5216
                                        mfprintf(b,"  #local vecC = vec2c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
 
5217
                                        mfprintf(b,"  #local vecD = vec1c - vec1b * (bond_r + bond_r_halo1 + bond_r_halo2) - vec3 * bond_d_halo2;\n");
 
5218
                                        mfprintf(b,"  triangle { vecA, vecB, vecC\n");
 
5219
                                        mfprintf(b,"    pigment { rgbft bond_color_halo3 } finish { reflection bond_reflect_halo3 specular bond_specular_halo3 ambient bond_ambient_halo3 diffuse bond_diffuse_halo3 } no_reflection no_radiosity }\n");
 
5220
                                        mfprintf(b,"  triangle { vecA, vecD, vecC\n");
 
5221
                                        mfprintf(b,"    pigment { rgbft bond_color_halo3 } finish { reflection bond_reflect_halo3 specular bond_specular_halo3 ambient bond_ambient_halo3 diffuse bond_diffuse_halo3 } no_reflection no_radiosity }\n");
 
5222
                                        mfprintf(b,"#end\n");
 
5223
                                }
 
5224
 
 
5225
//                              if (shadow)
 
5226
                                {
 
5227
                                        vec3 = vec2 - vec1;
 
5228
                                        vec3.Normalize();
 
5229
 
 
5230
                                        mfprintf(b,"#if (bond_draw_stub)\n");
 
5231
                                        mfprintf(b,"  #local vec3  = < %g, %g, %g >;\n",vec3[0],vec3[1],vec3[2]);
 
5232
                                        mfprintf(b,"  difference {\n");
 
5233
                                        mfprintf(b,"    cylinder { vec1c, vec1c + vec3 * bond_l_stub, bond_r + bond_r_stub }\n");
 
5234
                                        mfprintf(b,"    cylinder { vec1c - vec3 * (bond_l_stub+0.001), vec1c + vec3 * (bond_l_stub+0.001), bond_r }\n");
 
5235
                                        mfprintf(b,"    pigment { rgbft bond_color_stub } finish { reflection bond_reflect_stub specular bond_specular_stub ambient bond_ambient_stub diffuse bond_diffuse_stub } }\n");
 
5236
                                        mfprintf(b,"  difference {\n");
 
5237
                                        mfprintf(b,"    cylinder { vec2c, vec2c - vec3 * bond_l_stub, bond_r + bond_r_stub }\n");
 
5238
                                        mfprintf(b,"    cylinder { vec2c + vec3 * (bond_l_stub+0.001), vec2c - vec3 * (bond_l_stub+0.001), bond_r }\n");
 
5239
                                        mfprintf(b,"    pigment { rgbft bond_color_stub } finish { reflection bond_reflect_stub specular bond_specular_stub ambient bond_ambient_stub diffuse bond_diffuse_stub } }\n");
 
5240
                                        mfprintf(b,"#end\n");
 
5241
                                }
 
5242
                        }
 
5243
                }
 
5244
        }
 
5245
 
 
5246
        mfprintf(b,"\n  no_shadow\n}\n\n");
 
5247
 
 
5248
        fclose(b);
 
5249
}
 
5250
 
 
5251
 
 
5252
void CTimeStep::DumpDipoles()
 
5253
{
 
5254
        int z, z2, z3, z4, ti;
 
5255
        CMolecule *m;
 
5256
        CSingleMolecule *sm;
 
5257
        CxVector3 dc;
 
5258
 
 
5259
        if (!(g_bDipole && g_bDumpDipoleVector))
 
5260
                return;
 
5261
 
 
5262
        fprintf(g_fDumpDipole,"%lu",g_iSteps);
 
5263
        for (z=0;z<g_oaMolecules.GetSize();z++)
 
5264
        {
 
5265
                if (g_oaDumpDipoleVector[z] == NULL)
 
5266
                        continue;
 
5267
                m = (CMolecule*)g_oaMolecules[z];
 
5268
                for (z2=0;z2<((CxIntArray*)g_oaDumpDipoleVector[z])->GetSize();z2++)
 
5269
                {
 
5270
                        sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[((CxIntArray*)g_oaDumpDipoleVector[z])->GetAt(z2)]];
 
5271
                        fprintf(g_fDumpDipole,";  %10G;  %10G;  %10G",sm->m_vDipole[0],sm->m_vDipole[1],sm->m_vDipole[2]);
 
5272
                        if (g_bDumpDipoleAbs)
 
5273
                                fprintf(g_fDumpDipole,";  %10G",sm->m_vDipole.GetLength());
 
5274
                }
 
5275
        }
 
5276
        fprintf(g_fDumpDipole,"\n");
 
5277
 
 
5278
        if (g_bDumpDipoleXYZ)
 
5279
        {
 
5280
                fprintf(g_fDumpDipoleXYZ,"%d\n\n",g_iDumpDipoleXYZAtoms);
 
5281
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
5282
                {
 
5283
                        if (g_oaDumpDipoleVector[z] == NULL)
 
5284
                                continue;
 
5285
                        m = (CMolecule*)g_oaMolecules[z];
 
5286
                        for (z2=0;z2<((CxIntArray*)g_oaDumpDipoleVector[z])->GetSize();z2++)
 
5287
                        {
 
5288
                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[((CxIntArray*)g_oaDumpDipoleVector[z])->GetAt(z2)]];
 
5289
 
 
5290
                                for (z3=0;z3<m->m_baAtomIndex.GetSize();z3++)
 
5291
                                {
 
5292
                                        if (m->m_baAtomIndex[z3] == g_iVirtAtomType)
 
5293
                                                continue;
 
5294
                                        for (z4=0;z4<((CxIntArray*)sm->m_oaAtomOffset[z3])->GetSize();z4++)
 
5295
                                        {
 
5296
                                                ti = ((CxIntArray*)sm->m_oaAtomOffset[z3])->GetAt(z4);
 
5297
                                                fprintf(g_fDumpDipoleXYZ,"%s  %12f  %12f  %12f\n",((CAtom*)g_oaAtoms[m->m_baAtomIndex[z3]])->m_sName,m_vaCoords[ti][0]/100.0,m_vaCoords[ti][1]/100.0,m_vaCoords[ti][2]/100.0);
 
5298
                                        }
 
5299
                                }
 
5300
                        }
 
5301
                }
 
5302
 
 
5303
                for (z=0;z<g_oaMolecules.GetSize();z++)
 
5304
                {
 
5305
                        if (g_oaDumpDipoleVector[z] == NULL)
 
5306
                                continue;
 
5307
                        m = (CMolecule*)g_oaMolecules[z];
 
5308
                        for (z2=0;z2<((CxIntArray*)g_oaDumpDipoleVector[z])->GetSize();z2++)
 
5309
                        {
 
5310
                                sm = (CSingleMolecule*)g_oaSingleMolecules[m->m_laSingleMolIndex[((CxIntArray*)g_oaDumpDipoleVector[z])->GetAt(z2)]];
 
5311
                                dc = m_vaCoords[((CxIntArray*)sm->m_oaAtomOffset[m->m_iDipoleCenterType])->GetAt(m->m_iDipoleCenterIndex)];
 
5312
                                fprintf(g_fDumpDipoleXYZ,"B  %12f  %12f  %12f\n",dc[0]/100.0,dc[1]/100.0,dc[2]/100.0);
 
5313
                                fprintf(g_fDumpDipoleXYZ,"B  %12f  %12f  %12f\n",dc[0]/100.0+sm->m_vDipole[0]*g_fDumpDipoleScale,dc[1]/100.0+sm->m_vDipole[1]*g_fDumpDipoleScale,dc[2]/100.0+sm->m_vDipole[2]*g_fDumpDipoleScale);
 
5314
                        }
 
5315
                }
 
5316
        }
 
5317
}
 
5318
 
 
5319
 
 
5320
CTimeStep::CTimeStep()
 
5321
{
 
5322
        m_pComment = NULL;
 
5323
 
 
5324
        m_vaCoords.SetName("CTimeStep::m_vaCoords");
 
5325
        m_vaCoords_Unfolded.SetName("CTimeStep::m_vaCoords_Unfolded");
 
5326
        m_vaCoords_Original.SetName("CTimeStep::m_vaCoords_Original");
 
5327
        m_vaVelocities.SetName("CTimeStep::m_vaVelocities");
 
5328
        m_vaForces.SetName("CTimeStep::m_vaForces");
 
5329
        m_paLabels.SetName("CTimeStep::m_paLabels");
 
5330
        m_paMol2Types.SetName("CTimeStep::m_paMol2Types");
 
5331
        m_faCharge.SetName("CTimeStep::m_faCharge");
 
5332
}
 
5333
 
 
5334
 
 
5335
CTimeStep::~CTimeStep()
 
5336
{
 
5337
/*      if (m_pLabels != NULL)
 
5338
                delete[] m_pLabels;*/
 
5339
        if (m_pComment != NULL)
 
5340
                delete[] m_pComment;
 
5341
}
 
5342