~ubuntu-branches/ubuntu/wily/travis/wily-proposed

« back to all changes in this revision

Viewing changes to src/normalcoordinate.cpp

  • Committer: Package Import Robot
  • Author(s): Daniel Leidert
  • Date: 2015-05-10 11:28:34 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20150510112834-7376w30r5uor41vf
Tags: 150205-1
* New upstream release.
* debian/control (Standards-Version): Bumped to 3.9.6.
* debian/copyright: Updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
    TRAVIS - Trajectory Analyzer and Visualizer
3
3
    http://www.travis-analyzer.de/
4
4
 
5
 
    Copyright (c) 2009-2014 Martin Brehm
6
 
                  2012-2014 Martin Thomas
 
5
    Copyright (c) 2009-2015 Martin Brehm
 
6
                  2012-2015 Martin Thomas
7
7
 
8
8
    This file written by Martin Thomas.
9
9
 
31
31
#include "tools.h"
32
32
#include "xbytearray.h"
33
33
#include "xobarray.h"
 
34
#include "xstring.h"
34
35
 
35
36
#include <stdio.h>
36
37
 
54
55
                                float tf = s_values[i];
55
56
                                s_values[i] = s_values[j];
56
57
                                s_values[j] = tf;
57
 
                                float ti = sortIndex[i];
 
58
                                int ti = sortIndex[i];
58
59
                                sortIndex[i] = sortIndex[j];
59
60
                                sortIndex[j] = ti;
60
61
                        }
70
71
 
71
72
CReferenceStructure::CReferenceStructure(int showMol, const char *basename, bool calcIR) {
72
73
        int i, j;
 
74
        CxString buf;
 
75
 
73
76
        _calcIR = calcIR;
74
77
        
75
78
        try { _singleMol = new CSingleMolecule(); } catch(...) { _singleMol = NULL; }
79
82
        if(_refTimestep == NULL) NewException((double)sizeof(CTimeStep), __FILE__, __LINE__, __PRETTY_FUNCTION__);
80
83
        
81
84
        while(true) {
82
 
                char buf[BUF_SIZE];
83
 
                AskString_ND("    Filename for reference structure: ", buf);
 
85
//              char buf[BUF_SIZE];
 
86
                AskString_ND("    Filename for reference structure: ", &buf);
84
87
                FILE *refFile = fopen(buf, "r");
85
88
                if(refFile == NULL) {
86
89
                        mprintf(RED, "Could not open reference structure file: %s\n", strerror(errno));
118
121
                                internal->SetSize(4);
119
122
                                mprintf("\n");
120
123
                                for(i = 0; i < 4; i++) {
121
 
                                        char buf[BUF_SIZE];
 
124
//                                      char buf[BUF_SIZE];
122
125
                                        unsigned char parse[3];
123
126
                                        do
124
 
                                                AskString_ND("      Enter the %d. atom (e.g. C7): ", buf, i+1);
 
127
                                                AskString_ND("      Enter the %d. atom (e.g. C7): ", &buf, i+1);
125
128
                                        while(!ParseAtom(buf, showMol, parse[0], parse[1], parse[2]));
126
129
                                        internal->GetAt(i) = -1;
127
130
                                        for(j = 0; j < _singleMol->m_oaMolAtoms.GetSize(); j++) {
149
152
        }
150
153
        
151
154
        if(g_iTrajSteps != -1) {
152
 
                _correlationDepth = 0.75 * g_iTrajSteps;
 
155
                _correlationDepth = (int)(0.75 * g_iTrajSteps);
153
156
                if(_correlationDepth > 4096)
154
157
                        _correlationDepth = 4096;
155
158
                if(g_fTimestepLength > 1.0f)
205
208
        mprintf("    This results in a spectral resolution of %.2f cm^-1.\n", _specResolution);
206
209
        mprintf("\n    A time step length of %.2f fs allows a spectral range up to %.2f cm^-1.\n", g_fTimestepLength, possibleRange);
207
210
        float specLimit = AskRangeFloat("\n    Calculate spectrum up to which wave number (cm^-1)? [%.2f cm^-1] ", 0, possibleRange, (possibleRange < 5000.0f) ? possibleRange : 5000.0f, (possibleRange < 5000.0f) ? possibleRange : 5000.0f);
208
 
        _specSize = specLimit / _specResolution;
 
211
        _specSize = (int)(specLimit / _specResolution);
209
212
        mprintf("\n");
210
213
        
211
214
        _convergenceThreshold = AskFloat("    Relative convergence threshold for diagonalization: [1.0e-6] ", 1.0e-6f);
237
240
        _numSteps = 0;
238
241
        int n;
239
242
        if(g_iTrajSteps != -1)
240
 
                n = 1.1 * g_iTrajSteps / g_iStride;
 
243
                n = (int)(1.1 * g_iTrajSteps / g_iStride);
241
244
        else
242
245
                n = 10000;
243
246
        
248
251
                try { a = new CxFloatArray(); } catch(...) { a = NULL; }
249
252
                if(a == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
250
253
                a->SetMaxSize(n);
251
 
                a->SetGrow(0.1 * n);
 
254
                a->SetGrow((int)(0.1 * n));
252
255
                _distanceTimedev.Add(a);
253
256
        }
254
257
        
279
282
                try { a = new CxVec3Array(); } catch(...) { a = NULL; }
280
283
                if(a == NULL) NewException((double)sizeof(CxVec3Array), __FILE__, __LINE__, __PRETTY_FUNCTION__);
281
284
                a->SetMaxSize(n);
282
 
                a->SetGrow(0.1 * n);
 
285
                a->SetGrow((int)(0.1 * n));
283
286
                _velocityCache.Add(a);
284
287
        }
285
288
        if(_calcIR) {
289
292
                        try { a = new CxVec3Array(); } catch(...) { a = NULL; }
290
293
                        if(a == NULL) NewException((double)sizeof(CxVec3Array), __FILE__, __LINE__, __PRETTY_FUNCTION__);
291
294
                        a->SetMaxSize(n);
292
 
                        a->SetGrow(0.1 * n);
 
295
                        a->SetGrow((int)(0.1 * n));
293
296
                        _dipoleDerivativeCache.Add(a);
294
297
                }
295
298
        }
1532
1535
        CxByteArray baAtomIndex;
1533
1536
        baAtomIndex.SetSize(ts->m_iGesAtomCount);
1534
1537
        for(i = 0; (unsigned int)i < ts->m_iGesAtomCount; i++) {
1535
 
                char buf[64];
1536
 
                strncpy(buf, (char *)(ts->m_paLabels[i]), 64);
1537
 
                buf[63] = 0;
1538
 
                ReplaceDigits(buf);
 
1538
//              char buf[64];
 
1539
                CxString buf;
 
1540
 
 
1541
//              strncpy(buf, (char *)(ts->m_paLabels[i]), 64);
 
1542
//              buf[63] = 0;
 
1543
 
 
1544
                buf.strcpy((char *)(ts->m_paLabels[i]));
 
1545
                ReplaceDigits(&buf);
 
1546
 
1539
1547
                baAtomIndex[i] = 255;
1540
1548
                for(j = 0; j < g_oaAtoms.GetSize(); j++) {
1541
1549
                        if(mystricmp(buf, ((CAtom *)g_oaAtoms[j])->m_sName) == 0) {
1547
1555
                        }
1548
1556
                }
1549
1557
                if(baAtomIndex[i] == 255) {
1550
 
                        mprintf(RED, "Atom type \"%s\" not known\n", buf);
 
1558
                        mprintf(RED, "Atom type \"%s\" not known\n", (const char*)buf);
1551
1559
                        ok = false;
1552
1560
                }
1553
1561
        }
1916
1924
}
1917
1925
 
1918
1926
void CReferenceStructure::createPermutationsRecursion(int start, CxIntArray *permutation, CxIntArray *permutationActions) {
 
1927
        CxString buf;
 
1928
 
1919
1929
//      mprintf(RED, "createPermutationsRecursion (%d):", start);
1920
1930
//      for(int i = 0; i < permutation->GetSize(); i++) {
1921
1931
//              mprintf(RED, " %d", permutation->GetAt(i));
1970
1980
                                        try { newPermutation = new CxIntArray(); } catch(...) { newPermutation = NULL; }
1971
1981
                                        if(newPermutation == NULL) NewException((double)sizeof(CxIntArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
1972
1982
                                        newPermutation->CopyFrom(permutation);
1973
 
                                        char buf[BUF_SIZE];
 
1983
//                                      char buf[BUF_SIZE];
1974
1984
                                        const char delim[] = ", ";
1975
 
                                        AskString("    Enter permutation: ", buf, "");
 
1985
                                        AskString("    Enter permutation: ", &buf, "");
1976
1986
                                        if(strlen(buf) == 0)
1977
1987
                                                break;
1978
 
                                        char *tok = strtok(buf, delim);
 
1988
                                        char *tok = strtok(buf.GetWritePointer(), delim);
1979
1989
                                        while(tok != NULL) {
1980
1990
                                                int n;
1981
1991
                                                if(sscanf(tok, "%d", &n) == 1) {
2082
2092
}
2083
2093
 
2084
2094
CNormalCoordinateObservation::CNormalCoordinateObservation() {
2085
 
        char buf[BUF_SIZE];
2086
 
        char buf2[BUF_SIZE];
2087
 
        size_t remaining = BUF_SIZE;
 
2095
//      char buf[BUF_SIZE];
 
2096
//      char buf2[BUF_SIZE];
 
2097
//      size_t remaining = BUF_SIZE;
 
2098
        CxString buf, buf2, name;
2088
2099
        int i, j;
 
2100
 
2089
2101
        if(g_oaMolecules.GetSize() > 1) {
2090
 
#ifdef TARGET_LINUX
 
2102
/*#ifdef TARGET_LINUX
2091
2103
                remaining -= snprintf(buf, remaining, "    Which molecule should be observed (");
2092
2104
#else
2093
2105
                remaining -= sprintf(buf, "    Which molecule should be observed (");
2094
 
#endif
 
2106
#endif*/
 
2107
 
 
2108
                buf.sprintf("    Which molecule should be observed (");
 
2109
 
2095
2110
                for(i = 0; i < g_oaMolecules.GetSize(); i++) {
2096
 
                        if(remaining < 1)
 
2111
 
 
2112
/*                      if(remaining < 1)
2097
2113
                                break;
2098
2114
#ifdef TARGET_LINUX
2099
2115
                        size_t length = snprintf(buf2, remaining, "%s=%d", ((CMolecule *)g_oaMolecules[i])->m_sName, i+1);
2101
2117
                        size_t length = sprintf(buf2, "%s=%d", ((CMolecule *)g_oaMolecules[i])->m_sName, i+1);
2102
2118
#endif
2103
2119
                        strncat(buf, buf2, remaining - 1);
2104
 
                        remaining -= length;
 
2120
                        remaining -= length;*/
 
2121
 
 
2122
                        buf2.sprintf("%s=%d", ((CMolecule *)g_oaMolecules[i])->m_sName, i+1);
 
2123
                        buf.strcat(buf2);
 
2124
 
2105
2125
                        if(i < g_oaMolecules.GetSize() - 1) {
2106
 
#ifdef TARGET_LINUX
 
2126
/*#ifdef TARGET_LINUX
2107
2127
                                length = snprintf(buf2, remaining, ", ");
2108
2128
#else
2109
2129
                                length = sprintf(buf2, ", ");
2110
2130
#endif
2111
2131
                                strncat(buf, buf2, remaining - 1);
2112
 
                                remaining -= length;
 
2132
                                remaining -= length;*/
 
2133
 
 
2134
                                buf2.sprintf(", ");
 
2135
                                buf.strcat(buf2);
2113
2136
                        }
2114
2137
                }
2115
 
                strncat(buf, ")? ", remaining - 1);
 
2138
//              strncat(buf, ")? ", remaining - 1);
 
2139
                buf.strcat(")? ");
 
2140
 
2116
2141
                m_iShowMol = AskRangeInteger_ND(buf, 1, g_oaMolecules.GetSize()) - 1;
2117
2142
        } else {
2118
2143
                m_iShowMol = 0;
2131
2156
                _refCount++;
2132
2157
                mprintf(YELLOW, ">>> Reference Structure %d >>>\n\n", _refStructures.GetSize()+1);
2133
2158
                
2134
 
                char name[BUF_SIZE];
 
2159
/*              char name[BUF_SIZE];
2135
2160
#ifdef TARGET_LINUX
2136
2161
                snprintf(name, BUF_SIZE, "normalcoordinate_%s_r%d", ((CMolecule *)g_oaMolecules[m_iShowMol])->m_sName, _refCount);
2137
2162
#else
2138
2163
                sprintf(name, "normalcoordinate_%s_r%d", ((CMolecule *)g_oaMolecules[m_iShowMol])->m_sName, _refCount);
2139
 
#endif
 
2164
#endif*/
 
2165
                name.sprintf("normalcoordinate_%s_r%d", ((CMolecule *)g_oaMolecules[m_iShowMol])->m_sName, _refCount);
 
2166
 
2140
2167
                CReferenceStructure *refStruct;
2141
2168
                try { refStruct = new CReferenceStructure(m_iShowMol, name, _calcIR); } catch(...) { refStruct = NULL; }
2142
2169
                if(refStruct == NULL) NewException((double)sizeof(CReferenceStructure), __FILE__, __LINE__, __PRETTY_FUNCTION__);
2174
2201
                                internal->SetSize(4);
2175
2202
                                mprintf("\n");
2176
2203
                                for(i = 0; i < 4; i++) {
2177
 
                                        char buf[BUF_SIZE];
 
2204
//                                      char buf[BUF_SIZE];
2178
2205
                                        unsigned char parse[3];
2179
2206
                                        do
2180
 
                                                AskString_ND("      Enter the %d. atom (e.g. C7): ", buf, i+1);
 
2207
                                                AskString_ND("      Enter the %d. atom (e.g. C7): ", &buf, i+1);
2181
2208
                                        while(!ParseAtom(buf, m_iShowMol, parse[0], parse[1], parse[2]));
2182
2209
                                        internal->GetAt(i) = -1;
2183
2210
                                        for(j = 0; j < ((CSingleMolecule *)g_oaSingleMolecules[((CMolecule *)g_oaMolecules[m_iShowMol])->m_laSingleMolIndex[0]])->m_oaMolAtoms.GetSize(); j++) {
2283
2310
        
2284
2311
        int n;
2285
2312
        if(g_iTrajSteps != -1)
2286
 
                n = 1.1 * g_iTrajSteps / g_iStride;
 
2313
                n = (int)(1.1 * g_iTrajSteps / g_iStride);
2287
2314
        else
2288
2315
                n = 10000;
2289
2316
        
2294
2321
                try { a = new CxFloatArray(); } catch(...) { a = NULL; }
2295
2322
                if(a == NULL) NewException((double)sizeof(CxFloatArray), __FILE__, __LINE__, __PRETTY_FUNCTION__);
2296
2323
                a->SetMaxSize(n);
2297
 
                a->SetGrow(0.1 * n);
 
2324
                a->SetGrow((int)(0.1 * n));
2298
2325
                _distanceTimedev.Add(a);
2299
2326
        }
2300
2327
 
2664
2691
}
2665
2692
 
2666
2693
CEckartReferenceStructure::CEckartReferenceStructure() {
 
2694
        CxString buf;
 
2695
 
2667
2696
        try { _singleMol = new CSingleMolecule(); } catch(...) { _singleMol = NULL; }
2668
2697
        if(_singleMol == NULL) NewException((double)sizeof(CSingleMolecule), __FILE__, __LINE__, __PRETTY_FUNCTION__);
2669
2698
        
2674
2703
        if(_mapAtoms == NULL) NewException((double)sizeof(CAtomGroup), __FILE__, __LINE__, __PRETTY_FUNCTION__);
2675
2704
        
2676
2705
        while(true) {
2677
 
                char buf[BUF_SIZE];
2678
 
                AskString_ND("    Filename for reference structure: ", buf);
 
2706
//              char buf[BUF_SIZE];
 
2707
                AskString_ND("    Filename for reference structure: ", &buf);
2679
2708
                FILE *refFile = fopen(buf, "r");
2680
2709
                if(refFile == NULL) {
2681
2710
                        mprintf(RED, "Could not open reference structure file: %s\n", strerror(errno));
2706
2735
        while(true) {
2707
2736
                mprintf("    Which atom(s) to map (e.g. \"C1,C3-5,H\", \"*\"=all)? [*] ");
2708
2737
                inpprintf("! Which atom(s) to map (e.g. \"C1,C3-5,H\", \"*\"=all)? [*]\n");
2709
 
                char buf[BUF_SIZE];
2710
 
                myget(buf);
 
2738
//              char buf[BUF_SIZE];
 
2739
                myget(&buf);
2711
2740
                if(strlen(buf) == 0) {
2712
2741
                        if(!_mapAtoms->ParseAtoms((CMolecule *)g_oaMolecules[_singleMol->m_iMolType], "*")) {
2713
2742
                                eprintf("Weird error.\n");
2883
2912
        CxByteArray baAtomIndex;
2884
2913
        baAtomIndex.SetSize(ts->m_iGesAtomCount);
2885
2914
        for(i = 0; (unsigned int)i < ts->m_iGesAtomCount; i++) {
2886
 
                char buf[64];
2887
 
                strncpy(buf, (char *)(ts->m_paLabels[i]), 64);
2888
 
                buf[63] = 0;
2889
 
                ReplaceDigits(buf);
 
2915
//              char buf[64];
 
2916
                CxString buf;
 
2917
//              strncpy(buf, (char *)(ts->m_paLabels[i]), 64);
 
2918
//              buf[63] = 0;
 
2919
 
 
2920
                buf.strcpy((char *)(ts->m_paLabels[i]));
 
2921
                ReplaceDigits(&buf);
 
2922
 
2890
2923
                baAtomIndex[i] = 255;
2891
2924
                for(j = 0; j < g_oaAtoms.GetSize(); j++) {
2892
2925
                        if(mystricmp(buf, ((CAtom *)g_oaAtoms[j])->m_sName) == 0) {
2898
2931
                        }
2899
2932
                }
2900
2933
                if(baAtomIndex[i] == 255) {
2901
 
                        mprintf(RED, "Atom type \"%s\" not known\n", buf);
 
2934
                        mprintf(RED, "Atom type \"%s\" not known\n", (const char*)buf);
2902
2935
                        ok = false;
2903
2936
                }
2904
2937
        }