~ubuntu-branches/ubuntu/utopic/travis/utopic

« back to all changes in this revision

Viewing changes to src/region.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 Thomas. 
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 "region.h" 
25
 
 
26
 
#include "globalvar.h" 
27
 
#include "maintools.h" 
28
 
#include "tools.h" 
29
 
#include "xobarray.h" 
30
 
#include "xvector3.h" 
31
 
 
32
 
static CxObArray g_regions; 
33
 
 
34
 
CRegion::CRegion() { 
35
 
        mprintf("    You have to define an orthorhombic part of the simulation box\n    by entering minimum and maximum values along the x, y, and z axes.\n\n"); 
36
 
        _xmin = AskFloat("    Minimum x value in pm [0.0] ", 0.0f); 
37
 
        _xmax = AskFloat("    Maximum x value in pm [%.1f] ", g_fBoxX, g_fBoxX); 
38
 
        _ymin = AskFloat("    Minimum y value in pm [0.0] ", 0.0f); 
39
 
        _ymax = AskFloat("    Maximum y value in pm [%.1f] ", g_fBoxY, g_fBoxY); 
40
 
        _zmin = AskFloat("    Minimum z value in pm [0.0] ", 0.0f); 
41
 
        _zmax = AskFloat("    Maximum z value in pm [%.1f] ", g_fBoxZ, g_fBoxZ); 
42
 
         
43
 
        try { _centerAtomTypes = new unsigned char[g_oaMolecules.GetSize()]; } catch(...) { _centerAtomTypes = NULL; } 
44
 
        if(_centerAtomTypes == NULL) NewException((double)g_oaMolecules.GetSize()*sizeof(unsigned char), __FILE__, __LINE__, __PRETTY_FUNCTION__); 
45
 
        try { _centerAtomRealTypes = new unsigned char[g_oaMolecules.GetSize()]; } catch(...) { _centerAtomRealTypes = NULL; } 
46
 
        if(_centerAtomRealTypes == NULL) NewException((double)g_oaMolecules.GetSize()*sizeof(unsigned char), __FILE__, __LINE__, __PRETTY_FUNCTION__); 
47
 
        try { _centerAtoms = new unsigned char[g_oaMolecules.GetSize()]; } catch(...) { _centerAtoms = NULL; } 
48
 
        if(_centerAtoms == NULL) NewException((double)g_oaMolecules.GetSize()*sizeof(unsigned char), __FILE__, __LINE__, __PRETTY_FUNCTION__); 
49
 
         
50
 
        int i; 
51
 
        mprintf("\n    By default, the center of mass will be used to decide if a molecule is within the region.\n"); 
52
 
        if(AskYesNo("    Change this behavior (y/n)? [no] ", false)) { 
53
 
                char buf[256]; 
54
 
                for(i = 0; i < g_oaMolecules.GetSize(); i++) { 
55
 
                        while(true) { 
56
 
                                mprintf("    Which atom to use for %s (e.g. C1)? [#2] ", ((CMolecule*)g_oaMolecules[i])->m_sName); 
57
 
                                inpprintf("! Which atom to use for %s (e.g. C1)? [#2]\n", ((CMolecule*)g_oaMolecules[i])->m_sName); 
58
 
                                myget(buf); 
59
 
                                if(strlen(buf) == 0) { 
60
 
                                        if(!ParseAtom("#2", i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i])) { 
61
 
                                                eprintf("Weird error.\n"); 
62
 
                                                abort(); 
63
 
                                        } 
64
 
                                } else { 
65
 
                                        if(ParseAtom(buf, i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i])) 
66
 
                                                break; 
67
 
                                } 
68
 
                        } 
69
 
                } 
70
 
        } else { 
71
 
                for(i = 0; i < g_oaMolecules.GetSize(); i++) { 
72
 
                        if(!ParseAtom("#2", i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i])) { 
73
 
                                eprintf("Weird error.\n"); 
74
 
                                abort(); 
75
 
                        } 
76
 
                } 
77
 
        } 
78
 
79
 
 
80
 
CRegion::~CRegion() { 
81
 
        delete[] _centerAtomTypes; 
82
 
        delete[] _centerAtomRealTypes; 
83
 
        delete[] _centerAtoms; 
84
 
85
 
 
86
 
bool CRegion::isInRegion(const CxVector3 &vec) { 
87
 
        if((vec[0] > _xmin) && (vec[0] < _xmax) && (vec[1] > _ymin) && (vec[1] < _ymax) && (vec[2] > _zmin) && (vec[2] < _zmax)) 
88
 
                return true; 
89
 
        return false; 
90
 
91
 
 
92
 
bool gatherRegionAnalysis() { 
93
 
        mprintf("\n"); 
94
 
        mprintf(YELLOW, ">>> Region Definition >>>\n\n"); 
95
 
        mprintf("    You can specify as many regions as you want.\n    All parts of the simulation box not contained in these regions will be region 1.\n\n"); 
96
 
         
97
 
        while(true) { 
98
 
                mprintf(YELLOW, ">>> Region %d >>>\n\n", g_regions.GetSize() + 2); 
99
 
                 
100
 
                CRegion *region; 
101
 
                try { region = new CRegion(); } catch(...) { region = NULL; } 
102
 
                if(region == NULL) NewException((double)sizeof(CRegion), __FILE__, __LINE__, __PRETTY_FUNCTION__); 
103
 
                g_regions.Add(region); 
104
 
                 
105
 
                mprintf(YELLOW, "\n<<< End Region %d <<<\n\n", g_regions.GetSize() + 1); 
106
 
                 
107
 
                if(!AskYesNo("    Add another region (y/n)? [no] ", false)) 
108
 
                        break; 
109
 
                mprintf("\n"); 
110
 
        } 
111
 
         
112
 
        mprintf(YELLOW, "\n<<< End Region Definition <<<\n\n"); 
113
 
        return true; 
114
 
115
 
 
116
 
void processRegionAnalysis(CTimeStep *ts) { 
117
 
        int i, j; 
118
 
        for(i = 0; i < g_iaSMRegion.GetSize(); i++) { 
119
 
                g_iaSMRegion[i] = 1; 
120
 
        } 
121
 
         
122
 
        for(i = 0; i < g_regions.GetSize(); i++) { 
123
 
                CRegion *region = (CRegion *)g_regions[i]; 
124
 
                for(j = 0; j < g_oaSingleMolecules.GetSize(); j++) { 
125
 
                        CSingleMolecule *sm = (CSingleMolecule *)g_oaSingleMolecules[j]; 
126
 
                        CxVector3 position = ts->m_vaCoords[((CxIntArray *)sm->m_oaAtomOffset[region->centerAtomType(sm->m_iMolType)])->GetAt(region->centerAtom(sm->m_iMolType))]; 
127
 
                        if(region->isInRegion(position)) 
128
 
                                g_iaSMRegion[j] = i + 2; 
129
 
                } 
130
 
        } 
131
 
132
 
 
133
 
void finalizeRegionAnalysis() { 
134
 
        int i; 
135
 
        for(i = 0; i < g_regions.GetSize(); i++) { 
136
 
                delete g_regions[i]; 
137
 
        } 
138
 
        g_regions.RemoveAll(); 
139
 
 
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 Thomas. 
 
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 "region.h" 
 
25
 
 
26
#include "globalvar.h" 
 
27
#include "maintools.h" 
 
28
#include "tools.h" 
 
29
#include "xobarray.h" 
 
30
#include "xvector3.h" 
 
31
 
 
32
static CxObArray g_regions; 
 
33
 
 
34
CRegion::CRegion() { 
 
35
        mprintf("    You have to define an orthorhombic part of the simulation box\n    by entering minimum and maximum values along the x, y, and z axes.\n\n"); 
 
36
        _xmin = AskFloat("    Minimum x value in pm [0.0] ", 0.0f); 
 
37
        _xmax = AskFloat("    Maximum x value in pm [%.1f] ", g_fBoxX, g_fBoxX); 
 
38
        _ymin = AskFloat("    Minimum y value in pm [0.0] ", 0.0f); 
 
39
        _ymax = AskFloat("    Maximum y value in pm [%.1f] ", g_fBoxY, g_fBoxY); 
 
40
        _zmin = AskFloat("    Minimum z value in pm [0.0] ", 0.0f); 
 
41
        _zmax = AskFloat("    Maximum z value in pm [%.1f] ", g_fBoxZ, g_fBoxZ); 
 
42
         
 
43
        try { _centerAtomTypes = new unsigned char[g_oaMolecules.GetSize()]; } catch(...) { _centerAtomTypes = NULL; } 
 
44
        if(_centerAtomTypes == NULL) NewException((double)g_oaMolecules.GetSize()*sizeof(unsigned char), __FILE__, __LINE__, __PRETTY_FUNCTION__); 
 
45
        try { _centerAtomRealTypes = new unsigned char[g_oaMolecules.GetSize()]; } catch(...) { _centerAtomRealTypes = NULL; } 
 
46
        if(_centerAtomRealTypes == NULL) NewException((double)g_oaMolecules.GetSize()*sizeof(unsigned char), __FILE__, __LINE__, __PRETTY_FUNCTION__); 
 
47
        try { _centerAtoms = new unsigned char[g_oaMolecules.GetSize()]; } catch(...) { _centerAtoms = NULL; } 
 
48
        if(_centerAtoms == NULL) NewException((double)g_oaMolecules.GetSize()*sizeof(unsigned char), __FILE__, __LINE__, __PRETTY_FUNCTION__); 
 
49
         
 
50
        int i; 
 
51
        mprintf("\n    By default, the center of mass will be used to decide if a molecule is within the region.\n"); 
 
52
        if(AskYesNo("    Change this behavior (y/n)? [no] ", false)) { 
 
53
                char buf[256]; 
 
54
                for(i = 0; i < g_oaMolecules.GetSize(); i++) { 
 
55
                        while(true) { 
 
56
                                mprintf("    Which atom to use for %s (e.g. C1)? [#2] ", ((CMolecule*)g_oaMolecules[i])->m_sName); 
 
57
                                inpprintf("! Which atom to use for %s (e.g. C1)? [#2]\n", ((CMolecule*)g_oaMolecules[i])->m_sName); 
 
58
                                myget(buf); 
 
59
                                if(strlen(buf) == 0) { 
 
60
                                        if(!ParseAtom("#2", i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i])) { 
 
61
                                                eprintf("Weird error.\n"); 
 
62
                                                abort(); 
 
63
                                        } 
 
64
                                } else { 
 
65
                                        if(ParseAtom(buf, i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i])) 
 
66
                                                break; 
 
67
                                } 
 
68
                        } 
 
69
                } 
 
70
        } else { 
 
71
                for(i = 0; i < g_oaMolecules.GetSize(); i++) { 
 
72
                        if(!ParseAtom("#2", i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i])) { 
 
73
                                eprintf("Weird error.\n"); 
 
74
                                abort(); 
 
75
                        } 
 
76
                } 
 
77
        } 
 
78
 
79
 
 
80
CRegion::~CRegion() { 
 
81
        delete[] _centerAtomTypes; 
 
82
        delete[] _centerAtomRealTypes; 
 
83
        delete[] _centerAtoms; 
 
84
 
85
 
 
86
bool CRegion::isInRegion(const CxVector3 &vec) { 
 
87
        if((vec[0] > _xmin) && (vec[0] < _xmax) && (vec[1] > _ymin) && (vec[1] < _ymax) && (vec[2] > _zmin) && (vec[2] < _zmax)) 
 
88
                return true; 
 
89
        return false; 
 
90
 
91
 
 
92
bool gatherRegionAnalysis() { 
 
93
        mprintf("\n"); 
 
94
        mprintf(YELLOW, ">>> Region Definition >>>\n\n"); 
 
95
        mprintf("    You can specify as many regions as you want.\n    All parts of the simulation box not contained in these regions will be region 1.\n\n"); 
 
96
         
 
97
        while(true) { 
 
98
                mprintf(YELLOW, ">>> Region %d >>>\n\n", g_regions.GetSize() + 2); 
 
99
                 
 
100
                CRegion *region; 
 
101
                try { region = new CRegion(); } catch(...) { region = NULL; } 
 
102
                if(region == NULL) NewException((double)sizeof(CRegion), __FILE__, __LINE__, __PRETTY_FUNCTION__); 
 
103
                g_regions.Add(region); 
 
104
                 
 
105
                mprintf(YELLOW, "\n<<< End Region %d <<<\n\n", g_regions.GetSize() + 1); 
 
106
                 
 
107
                if(!AskYesNo("    Add another region (y/n)? [no] ", false)) 
 
108
                        break; 
 
109
                mprintf("\n"); 
 
110
        } 
 
111
         
 
112
        mprintf(YELLOW, "\n<<< End Region Definition <<<\n\n"); 
 
113
        return true; 
 
114
 
115
 
 
116
void processRegionAnalysis(CTimeStep *ts) { 
 
117
        int i, j; 
 
118
        for(i = 0; i < g_iaSMRegion.GetSize(); i++) { 
 
119
                g_iaSMRegion[i] = 1; 
 
120
        } 
 
121
         
 
122
        for(i = 0; i < g_regions.GetSize(); i++) { 
 
123
                CRegion *region = (CRegion *)g_regions[i]; 
 
124
                for(j = 0; j < g_oaSingleMolecules.GetSize(); j++) { 
 
125
                        CSingleMolecule *sm = (CSingleMolecule *)g_oaSingleMolecules[j]; 
 
126
                        CxVector3 position = ts->m_vaCoords[((CxIntArray *)sm->m_oaAtomOffset[region->centerAtomType(sm->m_iMolType)])->GetAt(region->centerAtom(sm->m_iMolType))]; 
 
127
                        if(region->isInRegion(position)) 
 
128
                                g_iaSMRegion[j] = i + 2; 
 
129
                } 
 
130
        } 
 
131
 
132
 
 
133
void finalizeRegionAnalysis() { 
 
134
        int i; 
 
135
        for(i = 0; i < g_regions.GetSize(); i++) { 
 
136
                delete g_regions[i]; 
 
137
        } 
 
138
        g_regions.RemoveAll(); 
 
139