1
/*****************************************************************************
2
TRAVIS - Trajectory Analyzer and Visualizer
3
http://www.travis-analyzer.de/
5
Copyright (c) 2009-2013 Martin Brehm
6
2012-2013 Martin Thomas
8
This file written by Martin Thomas.
10
This program is free software: you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*****************************************************************************/
26
#include "globalvar.h"
27
#include "maintools.h"
32
static CxObArray g_regions;
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);
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__);
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)) {
54
for(i = 0; i < g_oaMolecules.GetSize(); i++) {
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);
59
if(strlen(buf) == 0) {
60
if(!ParseAtom("#2", i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i])) {
61
eprintf("Weird error.\n");
65
if(ParseAtom(buf, i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i]))
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");
81
delete[] _centerAtomTypes;
82
delete[] _centerAtomRealTypes;
83
delete[] _centerAtoms;
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))
92
bool gatherRegionAnalysis() {
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");
98
mprintf(YELLOW, ">>> Region %d >>>\n\n", g_regions.GetSize() + 2);
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);
105
mprintf(YELLOW, "\n<<< End Region %d <<<\n\n", g_regions.GetSize() + 1);
107
if(!AskYesNo(" Add another region (y/n)? [no] ", false))
112
mprintf(YELLOW, "\n<<< End Region Definition <<<\n\n");
116
void processRegionAnalysis(CTimeStep *ts) {
118
for(i = 0; i < g_iaSMRegion.GetSize(); i++) {
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;
133
void finalizeRegionAnalysis() {
135
for(i = 0; i < g_regions.GetSize(); i++) {
138
g_regions.RemoveAll();
1
/*****************************************************************************
2
TRAVIS - Trajectory Analyzer and Visualizer
3
http://www.travis-analyzer.de/
5
Copyright (c) 2009-2014 Martin Brehm
6
2012-2014 Martin Thomas
8
This file written by Martin Thomas.
10
This program is free software: you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*****************************************************************************/
26
#include "globalvar.h"
27
#include "maintools.h"
32
static CxObArray g_regions;
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);
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__);
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)) {
54
for(i = 0; i < g_oaMolecules.GetSize(); i++) {
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);
59
if(strlen(buf) == 0) {
60
if(!ParseAtom("#2", i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i])) {
61
eprintf("Weird error.\n");
65
if(ParseAtom(buf, i, _centerAtomTypes[i], _centerAtomRealTypes[i], _centerAtoms[i]))
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");
81
delete[] _centerAtomTypes;
82
delete[] _centerAtomRealTypes;
83
delete[] _centerAtoms;
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))
92
bool gatherRegionAnalysis() {
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");
98
mprintf(YELLOW, ">>> Region %d >>>\n\n", g_regions.GetSize() + 2);
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);
105
mprintf(YELLOW, "\n<<< End Region %d <<<\n\n", g_regions.GetSize() + 1);
107
if(!AskYesNo(" Add another region (y/n)? [no] ", false))
112
mprintf(YELLOW, "\n<<< End Region Definition <<<\n\n");
116
void processRegionAnalysis(CTimeStep *ts) {
118
for(i = 0; i < g_iaSMRegion.GetSize(); i++) {
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;
133
void finalizeRegionAnalysis() {
135
for(i = 0; i < g_regions.GetSize(); i++) {
138
g_regions.RemoveAll();