[go: up one dir, main page]

Menu

[r1130]: / trunk / src / Molecule.cpp  Maximize  Restore  History

Download this file

195 lines (161 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
// Molecule.cpp
//
// Author: Struan Robertson
// Date: 5/Jan/2003
//-------------------------------------------------------------------------------------------
#include "Molecule.h"
#include "gWellProperties.h"
#include "gDensityOfStates.h"
#include "gStructure.h"
#include "gBathProperties.h"
#include "gPopulation.h"
#include "gTransitionState.h"
using namespace std ;
using namespace Constants ;
namespace mesmer
{
//
//Constructor
//
Molecule::Molecule(const MesmerEnv& Env, MesmerFlags& Flags, const string& molType, MoleculeManager *pMoleculeManager): m_Env(Env),
m_Flags(Flags),
m_atomNumber(0),
m_ppPersist(NULL),
m_Name(),
m_Description(),
m_pMoleculeManager(pMoleculeManager),
m_molTypes(),
g_bath(NULL),
g_dos(NULL),
g_ts(NULL),
g_pop(NULL),
g_coll(NULL),
g_struc(NULL)
{
m_molTypes[molType] = true;
}
Molecule::~Molecule(){
// delete the pointers in the reverse order.
if (g_struc != NULL) delete g_struc;
if (g_coll != NULL) delete g_coll;
if (g_pop != NULL) delete g_pop;
if (g_ts != NULL) delete g_ts;
if (g_dos != NULL) delete g_dos;
if (g_bath != NULL) delete g_bath;
}
//
//Initialization
//
bool Molecule::InitializeMolecule(PersistPtr pp)
{
m_ppPersist = pp;
const char* id= m_ppPersist->XmlReadValue("id", false);
if (id) m_Name = id;
if (m_Name.empty()) {
cerr << "Molecular name is absent.";
return false;
}
const char* desc = m_ppPersist->XmlReadValue("description", optional);
if (desc)
m_Description = desc;
// no check value for description
else
if(!m_ppPersist->XmlReadValue("", false))
//Has neither description attribute nor any child elements
return false;
// check the number of atoms
PersistPtr ppAtomArray = m_ppPersist->XmlMoveTo("atomArray");
if (ppAtomArray){
PersistPtr ppAtom = ppAtomArray->XmlMoveTo("atom");
while (ppAtom){
m_atomNumber++;
ppAtom = ppAtom->XmlMoveTo("atom");
}
}
return true;
}
// Check whether the total degrees of freeedom are consistent with the number of atoms.
bool Molecule::checkDegOfFreedom(){
if (m_atomNumber < 1) // No atoms defined, so no test can be done.
return true ;
unsigned int nDOF(0) ;
if (g_dos){
nDOF = g_dos->getNoOfDegOfFreeedom() ;
} else {
// Maybe a bath gas molecule.
return true;
}
if (m_atomNumber > 1 && nDOF == 0){
cinfo << "No molecular data assigned for " << getName() << ", assuming it to be a sink term.\n";
return true;
}
// If species is a transition state, assume a imaginary frequency exists regardless if provided.
if (g_ts)
nDOF++;
// Add translational degrees of freedom.
nDOF += 3 ;
return (nDOF == (3 * m_atomNumber));
}
//Make dummy calls to initialize the MolecularComponents now, during parse, before calculation.
bool Molecule::activateRole(string molType){
// see if the molType is true in m_molTypes
if (!m_molTypes[molType])
{
m_molTypes[molType] = true;
}
if (molType == "bathGas" || molType == "modelled")
getBath();
if (molType == "transitionState")
getTS();
if (molType == "modelled" || molType == "deficientReactant" //|| molType == "sink" CM g_dos to be added later if needed for reverse ILT
|| molType == "transitionState" || molType == "excessReactant"
|| molType == "PriorCoFragment" || molType == "forThermo" )
getDOS();
if (molType == "modelled" || molType == "deficientReactant" || molType == "sink")
getPop();
if (molType == "modelled")
getColl();
if(molType == "modelled" || molType == "bathGas")
getStruc();
return true;
};
gBathProperties& Molecule::getBath() {
if (!g_bath)
g_bath = new gBathProperties(this);
return *g_bath;
}
gDensityOfStates& Molecule::getDOS() {
if (!g_dos) {
g_dos = new gDensityOfStates(this);
if (!g_dos->initialization()) {
cinfo << "gDensityOfStates initialization failed." << endl;
}
}
return *g_dos;
}
gTransitionState& Molecule::getTS() {
if (!g_ts)
g_ts = new gTransitionState(this);
return *g_ts ; }
gPopulation& Molecule::getPop() {
if (!g_pop)
g_pop = new gPopulation(this);
return *g_pop ;
}
gWellProperties& Molecule::getColl() {
if (!g_coll) {
g_coll = new gWellProperties(this);
if (!g_coll->initialization()) {
string err("Collision model parameters not defined for " + m_Name + ".\n") ;
throw std::runtime_error(err);
}
}
return *g_coll;
}
gStructure& Molecule::getStruc() {
if (!g_struc)
g_struc = new gStructure(this);
return *g_struc;
}
}//namespace