Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4DNAMolecularReactionTable.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// $Id: G4DNAMolecularReactionTable.cc 65022 2012-11-12 16:43:12Z gcosmo $
27//
28// Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29//
30// WARNING : This class is released as a prototype.
31// It might strongly evolve or even disapear in the next releases.
32//
33// History:
34// -----------
35// 10 Oct 2011 M.Karamitros created
36//
37// -------------------------------------------------------------------
38
39#include <iomanip>
40
43#include "G4SystemOfUnits.hh"
44#include "G4UIcommand.hh"
47
48using namespace std;
49
51
53 fReactive1(),fReactive2(),
54 fReactionRate(0.),fReducedReactionRadius(0.),
55 fProducts(0)
56{;}
57
59 const G4Molecule* reactive1,
60 const G4Molecule* reactive2):fProducts(0)
61{
62 fReactionRate = reactionRate;
63 SetReactive1(reactive1);
64 SetReactive2(reactive2);
65
66 G4double sumDiffCoeff(0.);
67
68 if(*reactive1 == *reactive2)
69 {
70 sumDiffCoeff = reactive1->GetDiffusionCoefficient();
71 fReducedReactionRadius = fReactionRate/(4*pi* reactive1->GetDiffusionCoefficient() * Avogadro);
72 }
73 else
74 {
75 sumDiffCoeff = reactive1->GetDiffusionCoefficient() + reactive2->GetDiffusionCoefficient();
76 fReducedReactionRadius = fReactionRate/(4*pi* sumDiffCoeff * Avogadro);
77 }
78}
79
81{
82 if(fProducts)
83 {
84 fProducts->clear() ;
85 delete fProducts;
86 fProducts = 0;
87 }
88}
89
91{
93}
95{
97}
99 const G4Molecule* reactive2)
100{
103}
104
106{
107 if(!fProducts) fProducts = new std::vector<G4MoleculeHandle>();
108 fProducts->push_back(G4MoleculeHandleManager::Instance()->GetMoleculeHandle(molecule));
109}
110//_____________________________________________________________________________________
112{
113 if(!fInstance)
114 {
116 }
117 return fInstance;
118}
119
121{
122 // DEBUG
123// G4cout << "G4MolecularReactionTable::DeleteInstance" << G4endl;
124 if(fInstance)
125 delete fInstance;
126 fInstance = 0;
127}
128//_____________________________________________________________________________________
130 fMoleculeHandleManager(G4MoleculeHandleManager::Instance())
131{
132// G4cout << "G4DNAMolecularReactionTable::G4DNAMolecularReactionTable()" << G4endl;
133 fVerbose = false;
134 return;
135}
136//_____________________________________________________________________________________
138{
139 // DEBUG
140// G4cout << "G4MolecularReactionTable::~G4MolecularReactionTable" << G4endl;
141 ReactionDataMap::iterator it1 = fReactionData.begin();
142
143 std::map<const G4Molecule*,
145 compMoleculeP>::iterator it2;
146
147 for(;it1!=fReactionData.end();it1++)
148 {
149 for(it2 = it1->second.begin();it2 != it1->second.end();it2++)
150 {
151 const G4DNAMolecularReactionData* reactionData = it2->second;
152 if(reactionData)
153 {
154 const G4Molecule* reactive1 = reactionData->GetReactive1();
155 const G4Molecule* reactive2 = reactionData->GetReactive2();
156
157 fReactionData[reactive1][reactive2] = 0;
158 fReactionData[reactive2][reactive1] = 0;
159
160 delete reactionData;
161 }
162 }
163 }
164
165 fReactionDataMV.clear();
166 fReactionData.clear();
167 fReactivesMV.clear();
168}
169//_____________________________________________________________________________________
171{
172 const G4Molecule* reactive1 = reactionData->GetReactive1() ;
173 const G4Molecule* reactive2 = reactionData->GetReactive2() ;
174
175 fReactionData[reactive1][reactive2] = reactionData;
176 fReactivesMV[reactive1].push_back(reactive2);
177 fReactionDataMV[reactive1].push_back(reactionData);
178
179 if(reactive1 != reactive2)
180 {
181 fReactionData[reactive2][reactive1] = reactionData;
182 fReactivesMV[reactive2].push_back(reactive1);
183 fReactionDataMV[reactive2].push_back(reactionData);
184 }
185}
186//_____________________________________________________________________________________
188 const G4Molecule* reactive1,
189 const G4Molecule* reactive2)
190{
191 G4DNAMolecularReactionData* reactionData = new G4DNAMolecularReactionData(reactionRate, reactive1, reactive2);
192 SetReaction(reactionData);
193}
194//_____________________________________________________________________________________
196{
197 // Print Reactions and Interaction radius for jump step = 3ps
198
199 if(pReactionModel)
200 {
201 if(!(pReactionModel->GetReactionTable()))
202 pReactionModel -> SetReactionTable(this);
203 }
204
205 ReactivesMV::iterator itReactives;
206
207 map<G4Molecule*,map<G4Molecule*, G4bool> > alreadyPrint;
208
209 G4cout<<"Nombre particules intervenants dans les reactions = "<< fReactivesMV.size() <<G4endl;
210
211 G4int nbPrintable = fReactivesMV.size()*fReactivesMV.size();
212
213 G4String *outputReaction = new G4String[nbPrintable];
214 G4String *outputReactionRate = new G4String[nbPrintable];
215 G4String *outputRange = new G4String[nbPrintable];
216 G4int n = 0;
217
218 for(itReactives = fReactivesMV.begin() ; itReactives != fReactivesMV.end() ; itReactives++)
219 {
220 G4Molecule* moleculeA = (G4Molecule*) itReactives->first;
221 const vector<const G4Molecule*>* reactivesVector = CanReactWith(moleculeA);
222
223 if(pReactionModel)
224 pReactionModel -> InitialiseToPrint(moleculeA);
225
226 G4int nbReactants = fReactivesMV[itReactives->first].size();
227
228 for(G4int iReact = 0 ; iReact < nbReactants ; iReact++)
229 {
230
231 G4Molecule* moleculeB = (G4Molecule*) (*reactivesVector)[iReact];
232
233 const G4DNAMolecularReactionData* reactionData = fReactionData[moleculeA][moleculeB];
234
235 //-----------------------------------------------------------
236 // Name of the reaction
237 if(!alreadyPrint[moleculeA][moleculeB])
238 {
239 outputReaction[n]=
240 moleculeA->GetName()
241 +" + " +
242 moleculeB->GetName();
243
244 G4int nbProducts = reactionData->GetNbProducts();
245
246 if(nbProducts)
247 {
248 outputReaction[n] += " -> "+ reactionData->GetProduct(0)->GetName();
249
250 for(G4int j = 1 ; j < nbProducts ; j++)
251 {
252 outputReaction[n]+=" + "+reactionData->GetProduct(j)->GetName();
253 }
254 }
255 else
256 {
257 outputReaction[n]+=" -> No product";
258 }
259
260 //-----------------------------------------------------------
261 // Interaction Rate
262 outputReactionRate[n] = G4UIcommand::ConvertToString(reactionData->GetReactionRate()/(1e-3*m3/(mole*s)));
263
264 //-----------------------------------------------------------
265 // Calculation of the Interaction Range
266 G4double interactionRange = -1;
267 if(pReactionModel)
268 interactionRange = pReactionModel->GetReactionRadius(iReact);
269
270 if(interactionRange!=-1)
271 {
272 outputRange[n] = G4UIcommand::ConvertToString(interactionRange/nanometer);
273 }
274 else
275 {
276 outputRange[n] = "";
277 }
278
279 alreadyPrint[moleculeB][moleculeA] = TRUE;
280 n++;
281 }
282 }
283 }
284 G4cout<<"Number of possible reactions: "<< n << G4endl;
285
286 ////////////////////////////////////////////////////////////////////
287 // Tableau dynamique en fonction du nombre de caractère maximal dans
288 // chaque colonne
289 ////////////////////////////////////////////////////////////////////
290
291 G4int maxlengthOutputReaction = -1;
292 G4int maxlengthOutputReactionRate = -1;
293
294 for(G4int i = 0 ; i < n ; i++)
295 {
296 if(maxlengthOutputReaction < (G4int) outputReaction[i].length())
297 {
298 maxlengthOutputReaction = outputReaction[i].length();
299 }
300 if(maxlengthOutputReactionRate < (G4int)outputReactionRate[i].length())
301 {
302 maxlengthOutputReactionRate = outputReactionRate[i].length();
303 }
304 }
305
306 maxlengthOutputReaction+=2;
307 maxlengthOutputReactionRate+=2;
308
309 if(maxlengthOutputReaction<10) maxlengthOutputReaction = 10;
310 if(maxlengthOutputReactionRate<30) maxlengthOutputReactionRate = 30;
311
312 G4String title[3];
313
314 title[0] = "Reaction";
315 title[1] = "Reaction Rate [dm3/(mol*s)]";
316 title[2] = "Interaction Range for chosen reaction model";
317
318 G4cout<< setfill(' ')
319 << setw(maxlengthOutputReaction) << left << title[0]
320 << setw(maxlengthOutputReactionRate) << left << title[1]
321 << setw(2) << left << title[2]
322 << G4endl;
323
324 G4cout.fill('-');
325 G4cout.width(maxlengthOutputReaction+2+maxlengthOutputReactionRate+2+(G4int)title[2].length());
326 G4cout<<"-"<<G4endl;
327 G4cout.fill(' ');
328
329 for(G4int i = 0 ; i < n ; i ++)
330 {
331 G4cout<< setw(maxlengthOutputReaction)<< left << outputReaction[i]
332 << setw(maxlengthOutputReactionRate) << left << outputReactionRate[i]
333 << setw(2) << left <<outputRange[i]
334 <<G4endl;
335
336 G4cout.fill('-');
337 G4cout.width(maxlengthOutputReaction+2+maxlengthOutputReactionRate+2+(G4int)title[2].length());
338 G4cout<<"-"<<G4endl;
339 G4cout.fill(' ');
340 }
341
342 delete [] outputReaction;
343 delete [] outputReactionRate;
344 delete [] outputRange;
345}
346//_____________________________________________________________________________________
347// Get/Set methods
348
351 const G4Molecule* reactive2) const
352{
353 if(fReactionData.empty())
354 {
355 G4String errMsg = "No reaction table was implemented";
356 G4Exception("G4MolecularInteractionTable::CanInteractWith","",FatalErrorInArgument, errMsg);
357 return 0;
358 }
359
360 ReactionDataMap::const_iterator it1 = fReactionData.find(reactive1);
361
362 if(it1 == fReactionData.end())
363 {
364 G4cout<<"Nom : " << reactive1->GetName()<<G4endl;
365 G4String errMsg = "No reaction table was implemented for this molecule Definition : "
366 + reactive1 -> GetName();
367 G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
368 }
369
370 std::map<const G4Molecule*,
372 compMoleculeP>::const_iterator it2 = it1->second.find(reactive2);
373
374 if(it2 == it1->second.end())
375 {
376 G4cout<<"Nom : " << reactive2->GetName()<<G4endl;
377 G4String errMsg = "No reaction table was implemented for this molecule Definition : "
378 + reactive2 -> GetName();
379 G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
380 }
381
382 return (it2->second);
383}
384
385const std::vector<const G4Molecule*>*
387{
388 if(fReactivesMV.empty())
389 {
390 G4String errMsg = "No reaction table was implemented";
391 G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
392 return 0;
393 }
394
395 ReactivesMV::const_iterator itReactivesMap = fReactivesMV.find(aMolecule) ;
396
397 if(itReactivesMap == fReactivesMV.end())
398 {
399 G4cout<<"Nom : " << aMolecule->GetName()<<G4endl;
400 G4String errMsg = "No reaction table was implemented for this molecule Definition : "
401 + aMolecule -> GetName();
402 G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
403 return 0;
404 }
405 else
406 {
407 if(fVerbose)
408 {
409 G4cout<< " G4MolecularInteractionTable::CanReactWith :"<<G4endl;
410 G4cout<<"You are checking reactants for : " << aMolecule->GetName()<<G4endl;
411 G4cout<<" the number of reactants is : " << itReactivesMap->second.size()<<G4endl;
412
413 std::vector<const G4Molecule*>::const_iterator itProductsVector =
414 itReactivesMap->second.begin();
415
416 for( ; itProductsVector != itReactivesMap->second.end(); itProductsVector++)
417 {
418 G4cout<<(*itProductsVector)->GetName()<<G4endl;
419 }
420 }
421 return &(itReactivesMap->second);
422 }
423 return 0;
424}
425
426//_____________________________________________________________________________________
427const std::map<const G4Molecule*, const G4DNAMolecularReactionData*, compMoleculeP>*
429{
430
431 if(fReactionData.empty())
432 {
433 G4String errMsg = "No reaction table was implemented";
434 G4Exception("G4MolecularInteractionTable::CanInteractWith","",FatalErrorInArgument, errMsg);
435 return 0;
436 }
437
438 ReactionDataMap::const_iterator itReactivesMap = fReactionData.find(molecule) ;
439
440 if(itReactivesMap == fReactionData.end())
441 {
442 G4cout<<"Nom : " << molecule->GetName()<<G4endl;
443 G4String errMsg = "No reaction table was implemented for this molecule Definition : "
444 + molecule -> GetName();
445 G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
446 }
447 else
448 {
449 if(fVerbose)
450 {
451 G4cout<< " G4MolecularInteractionTable::CanReactWith :"<<G4endl;
452 G4cout<<"You are checking reactants for : " << molecule->GetName()<<G4endl;
453 G4cout<<" the number of reactants is : " << itReactivesMap->second.size()<<G4endl;
454
455 std::map<const G4Molecule*,
457 compMoleculeP>::const_iterator itProductsVector =
458 itReactivesMap->second.begin();
459
460 for( ; itProductsVector != itReactivesMap->second.end(); itProductsVector++)
461 {
462 G4cout<<itProductsVector->first->GetName()<<G4endl;
463 }
464 }
465 return &(itReactivesMap->second);
466 }
467
468 return 0;
469}
470
471const std::vector<const G4DNAMolecularReactionData*>*
473{
474 if(fReactionDataMV.empty())
475 {
476 G4String errMsg = "No reaction table was implemented";
477 G4Exception("G4MolecularInteractionTable::CanInteractWith","",FatalErrorInArgument, errMsg);
478 return 0 ;
479 }
480 ReactionDataMV::const_iterator it = fReactionDataMV.find(molecule) ;
481
482 if(it == fReactionDataMV.end())
483 {
484 G4cout<<"Nom : " << molecule->GetName()<<G4endl;
485 G4String errMsg = "No reaction table was implemented for this molecule Definition : "
486 + molecule -> GetName();
487 G4Exception("G4MolecularInteractionTable::GetReactionData","",FatalErrorInArgument, errMsg);
488 return 0; // coverity
489 }
490
491 return &(it->second);
492}
@ FatalErrorInArgument
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
const G4Molecule * GetProduct(G4int i) const
void SetReactive2(const G4Molecule *reactive)
std::vector< G4MoleculeHandle > * fProducts
void AddProduct(const G4Molecule *molecule)
const G4Molecule * GetReactive2() const
void SetReactive1(const G4Molecule *reactive)
void SetReactive(const G4Molecule *reactive1, const G4Molecule *reactive2)
const G4Molecule * GetReactive1() const
static G4DNAMolecularReactionTable * GetReactionTable()
void SetReaction(G4double observedReactionRate, const G4Molecule *reactive1, const G4Molecule *reactive2)
void PrintTable(G4VDNAReactionModel *=0)
const std::map< const G4Molecule *, const G4DNAMolecularReactionData *, compMoleculeP > * GetReativesNData(const G4Molecule *aMolecule) const
const std::vector< const G4Molecule * > * CanReactWith(const G4Molecule *aMolecule) const
const G4DNAMolecularReactionData * GetReactionData(const G4Molecule *, const G4Molecule *) const
static G4DNAMolecularReactionTable * fInstance
G4MoleculeHandle GetMoleculeHandle(const G4Molecule *)
static G4MoleculeHandleManager * Instance()
const G4String & GetName() const
Definition: G4Molecule.cc:259
G4double GetDiffusionCoefficient() const
Definition: G4Molecule.cc:405
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:349
const G4DNAMolecularReactionTable * GetReactionTable()
virtual G4double GetReactionRadius(const G4Molecule *, const G4Molecule *)=0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define TRUE
Definition: globals.hh:55