Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 74551 2013-10-14 12:59:14Z 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 
42 #include "G4PhysicalConstants.hh"
43 #include "G4SystemOfUnits.hh"
44 #include "G4UIcommand.hh"
45 #include "G4VDNAReactionModel.hh"
47 
48 using namespace std;
49 
51 //G4ThreadLocal G4DNAMolecularReactionTable* G4DNAMolecularReactionTable::fInstance(0);
52 
54  fReactive1(),fReactive2(),
55  fReactionRate(0.),fReducedReactionRadius(0.),
56  fProducts(0)
57 {;}
58 
60  const G4Molecule* reactive1,
61  const G4Molecule* reactive2):fProducts(0)
62 {
63  fReactionRate = reactionRate;
64  SetReactive1(reactive1);
65  SetReactive2(reactive2);
66 
67  G4double sumDiffCoeff(0.);
68 
69  if(*reactive1 == *reactive2)
70  {
71  sumDiffCoeff = reactive1->GetDiffusionCoefficient();
73  }
74  else
75  {
76  sumDiffCoeff = reactive1->GetDiffusionCoefficient() + reactive2->GetDiffusionCoefficient();
77  fReducedReactionRadius = fReactionRate/(4*pi* sumDiffCoeff * Avogadro);
78  }
79 }
80 
82 {
83  if(fProducts)
84  {
85  fProducts->clear() ;
86  delete fProducts;
87  fProducts = 0;
88  }
89 }
90 
92 {
94 }
96 {
98 }
100  const G4Molecule* reactive2)
101 {
104 }
105 
107 {
108  if(!fProducts) fProducts = new std::vector<G4MoleculeHandle>();
109  fProducts->push_back(G4MoleculeHandleManager::Instance()->GetMoleculeHandle(molecule));
110 }
111 //_____________________________________________________________________________________
113 {
114  if(!fInstance)
115  {
117  }
118  return fInstance;
119 }
120 
122 {
123  // DEBUG
124 // G4cout << "G4MolecularReactionTable::DeleteInstance" << G4endl;
125  if(fInstance)
126  delete fInstance;
127  fInstance = 0;
128 }
129 //_____________________________________________________________________________________
131  fMoleculeHandleManager(G4MoleculeHandleManager::Instance())
132 {
133 // G4cout << "G4DNAMolecularReactionTable::G4DNAMolecularReactionTable()" << G4endl;
134  fVerbose = false;
135  return;
136 }
137 //_____________________________________________________________________________________
139 {
140  // DEBUG
141 // G4cout << "G4MolecularReactionTable::~G4MolecularReactionTable" << G4endl;
142  ReactionDataMap::iterator it1 = fReactionData.begin();
143 
144  std::map<const G4Molecule*,
146  compMoleculeP>::iterator it2;
147 
148  for(;it1!=fReactionData.end();it1++)
149  {
150  for(it2 = it1->second.begin();it2 != it1->second.end();it2++)
151  {
152  const G4DNAMolecularReactionData* reactionData = it2->second;
153  if(reactionData)
154  {
155  const G4Molecule* reactive1 = reactionData->GetReactive1();
156  const G4Molecule* reactive2 = reactionData->GetReactive2();
157 
158  fReactionData[reactive1][reactive2] = 0;
159  fReactionData[reactive2][reactive1] = 0;
160 
161  delete reactionData;
162  }
163  }
164  }
165 
166  fReactionDataMV.clear();
167  fReactionData.clear();
168  fReactivesMV.clear();
169 }
170 //_____________________________________________________________________________________
172 {
173  const G4Molecule* reactive1 = reactionData->GetReactive1() ;
174  const G4Molecule* reactive2 = reactionData->GetReactive2() ;
175 
176  fReactionData[reactive1][reactive2] = reactionData;
177  fReactivesMV[reactive1].push_back(reactive2);
178  fReactionDataMV[reactive1].push_back(reactionData);
179 
180  if(reactive1 != reactive2)
181  {
182  fReactionData[reactive2][reactive1] = reactionData;
183  fReactivesMV[reactive2].push_back(reactive1);
184  fReactionDataMV[reactive2].push_back(reactionData);
185  }
186 }
187 //_____________________________________________________________________________________
189  const G4Molecule* reactive1,
190  const G4Molecule* reactive2)
191 {
192  G4DNAMolecularReactionData* reactionData = new G4DNAMolecularReactionData(reactionRate, reactive1, reactive2);
193  SetReaction(reactionData);
194 }
195 //_____________________________________________________________________________________
197 {
198  // Print Reactions and Interaction radius for jump step = 3ps
199 
200  if(pReactionModel)
201  {
202  if(!(pReactionModel->GetReactionTable()))
203  pReactionModel -> SetReactionTable(this);
204  }
205 
206  ReactivesMV::iterator itReactives;
207 
208  map<G4Molecule*,map<G4Molecule*, G4bool> > alreadyPrint;
209 
210  G4cout<<"Nombre particules intervenants dans les reactions = "<< fReactivesMV.size() <<G4endl;
211 
212  G4int nbPrintable = fReactivesMV.size()*fReactivesMV.size();
213 
214  G4String *outputReaction = new G4String[nbPrintable];
215  G4String *outputReactionRate = new G4String[nbPrintable];
216  G4String *outputRange = new G4String[nbPrintable];
217  G4int n = 0;
218 
219  for(itReactives = fReactivesMV.begin() ; itReactives != fReactivesMV.end() ; itReactives++)
220  {
221  G4Molecule* moleculeA = (G4Molecule*) itReactives->first;
222  const vector<const G4Molecule*>* reactivesVector = CanReactWith(moleculeA);
223 
224  if(pReactionModel)
225  pReactionModel -> InitialiseToPrint(moleculeA);
226 
227  G4int nbReactants = fReactivesMV[itReactives->first].size();
228 
229  for(G4int iReact = 0 ; iReact < nbReactants ; iReact++)
230  {
231 
232  G4Molecule* moleculeB = (G4Molecule*) (*reactivesVector)[iReact];
233 
234  const G4DNAMolecularReactionData* reactionData = fReactionData[moleculeA][moleculeB];
235 
236  //-----------------------------------------------------------
237  // Name of the reaction
238  if(!alreadyPrint[moleculeA][moleculeB])
239  {
240  outputReaction[n]=
241  moleculeA->GetName()
242  +" + " +
243  moleculeB->GetName();
244 
245  G4int nbProducts = reactionData->GetNbProducts();
246 
247  if(nbProducts)
248  {
249  outputReaction[n] += " -> "+ reactionData->GetProduct(0)->GetName();
250 
251  for(G4int j = 1 ; j < nbProducts ; j++)
252  {
253  outputReaction[n]+=" + "+reactionData->GetProduct(j)->GetName();
254  }
255  }
256  else
257  {
258  outputReaction[n]+=" -> No product";
259  }
260 
261  //-----------------------------------------------------------
262  // Interaction Rate
263  outputReactionRate[n] = G4UIcommand::ConvertToString(reactionData->GetReactionRate()/(1e-3*m3/(mole*s)));
264 
265  //-----------------------------------------------------------
266  // Calculation of the Interaction Range
267  G4double interactionRange = -1;
268  if(pReactionModel)
269  interactionRange = pReactionModel->GetReactionRadius(iReact);
270 
271  if(interactionRange!=-1)
272  {
273  outputRange[n] = G4UIcommand::ConvertToString(interactionRange/nanometer);
274  }
275  else
276  {
277  outputRange[n] = "";
278  }
279 
280  alreadyPrint[moleculeB][moleculeA] = TRUE;
281  n++;
282  }
283  }
284  }
285  G4cout<<"Number of possible reactions: "<< n << G4endl;
286 
287  ////////////////////////////////////////////////////////////////////
288  // Tableau dynamique en fonction du nombre de caractere maximal dans
289  // chaque colonne
290  ////////////////////////////////////////////////////////////////////
291 
292  G4int maxlengthOutputReaction = -1;
293  G4int maxlengthOutputReactionRate = -1;
294 
295  for(G4int i = 0 ; i < n ; i++)
296  {
297  if(maxlengthOutputReaction < (G4int) outputReaction[i].length())
298  {
299  maxlengthOutputReaction = outputReaction[i].length();
300  }
301  if(maxlengthOutputReactionRate < (G4int)outputReactionRate[i].length())
302  {
303  maxlengthOutputReactionRate = outputReactionRate[i].length();
304  }
305  }
306 
307  maxlengthOutputReaction+=2;
308  maxlengthOutputReactionRate+=2;
309 
310  if(maxlengthOutputReaction<10) maxlengthOutputReaction = 10;
311  if(maxlengthOutputReactionRate<30) maxlengthOutputReactionRate = 30;
312 
313  G4String title[3];
314 
315  title[0] = "Reaction";
316  title[1] = "Reaction Rate [dm3/(mol*s)]";
317  title[2] = "Interaction Range for chosen reaction model";
318 
319  G4cout<< setfill(' ')
320  << setw(maxlengthOutputReaction) << left << title[0]
321  << setw(maxlengthOutputReactionRate) << left << title[1]
322  << setw(2) << left << title[2]
323  << G4endl;
324 
325  G4cout.fill('-');
326  G4cout.width(maxlengthOutputReaction+2+maxlengthOutputReactionRate+2+(G4int)title[2].length());
327  G4cout<<"-"<<G4endl;
328  G4cout.fill(' ');
329 
330  for(G4int i = 0 ; i < n ; i ++)
331  {
332  G4cout<< setw(maxlengthOutputReaction)<< left << outputReaction[i]
333  << setw(maxlengthOutputReactionRate) << left << outputReactionRate[i]
334  << setw(2) << left <<outputRange[i]
335  <<G4endl;
336 
337  G4cout.fill('-');
338  G4cout.width(maxlengthOutputReaction+2+maxlengthOutputReactionRate+2+(G4int)title[2].length());
339  G4cout<<"-"<<G4endl;
340  G4cout.fill(' ');
341  }
342 
343  delete [] outputReaction;
344  delete [] outputReactionRate;
345  delete [] outputRange;
346 }
347 //_____________________________________________________________________________________
348 // Get/Set methods
349 
352  const G4Molecule* reactive2) const
353 {
354  if(fReactionData.empty())
355  {
356  G4String errMsg = "No reaction table was implemented";
357  G4Exception("G4MolecularInteractionTable::CanInteractWith","",FatalErrorInArgument, errMsg);
358  return 0;
359  }
360 
361  ReactionDataMap::const_iterator it1 = fReactionData.find(reactive1);
362 
363  if(it1 == fReactionData.end())
364  {
365  G4cout<<"Nom : " << reactive1->GetName()<<G4endl;
366  G4String errMsg = "No reaction table was implemented for this molecule Definition : "
367  + reactive1 -> GetName();
368  G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
369  }
370 
371  std::map<const G4Molecule*,
373  compMoleculeP>::const_iterator it2 = it1->second.find(reactive2);
374 
375  if(it2 == it1->second.end())
376  {
377  G4cout<<"Nom : " << reactive2->GetName()<<G4endl;
378  G4String errMsg = "No reaction table was implemented for this molecule Definition : "
379  + reactive2 -> GetName();
380  G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
381  }
382 
383  return (it2->second);
384 }
385 
386 const std::vector<const G4Molecule*>*
388 {
389  if(fReactivesMV.empty())
390  {
391  G4String errMsg = "No reaction table was implemented";
392  G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
393  return 0;
394  }
395 
396  ReactivesMV::const_iterator itReactivesMap = fReactivesMV.find(aMolecule) ;
397 
398  if(itReactivesMap == fReactivesMV.end())
399  {
400  G4cout<<"Nom : " << aMolecule->GetName()<<G4endl;
401  G4String errMsg = "No reaction table was implemented for this molecule Definition : "
402  + aMolecule -> GetName();
403  G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
404  return 0;
405  }
406  else
407  {
408  if(fVerbose)
409  {
410  G4cout<< " G4MolecularInteractionTable::CanReactWith :"<<G4endl;
411  G4cout<<"You are checking reactants for : " << aMolecule->GetName()<<G4endl;
412  G4cout<<" the number of reactants is : " << itReactivesMap->second.size()<<G4endl;
413 
414  std::vector<const G4Molecule*>::const_iterator itProductsVector =
415  itReactivesMap->second.begin();
416 
417  for( ; itProductsVector != itReactivesMap->second.end(); itProductsVector++)
418  {
419  G4cout<<(*itProductsVector)->GetName()<<G4endl;
420  }
421  }
422  return &(itReactivesMap->second);
423  }
424  return 0;
425 }
426 
427 //_____________________________________________________________________________________
428 const std::map<const G4Molecule*, const G4DNAMolecularReactionData*, compMoleculeP>*
430 {
431 
432  if(fReactionData.empty())
433  {
434  G4String errMsg = "No reaction table was implemented";
435  G4Exception("G4MolecularInteractionTable::CanInteractWith","",FatalErrorInArgument, errMsg);
436  return 0;
437  }
438 
439  ReactionDataMap::const_iterator itReactivesMap = fReactionData.find(molecule) ;
440 
441  if(itReactivesMap == fReactionData.end())
442  {
443  G4cout<<"Nom : " << molecule->GetName()<<G4endl;
444  G4String errMsg = "No reaction table was implemented for this molecule Definition : "
445  + molecule -> GetName();
446  G4Exception("G4MolecularInteractionTable::CanReactWith","",FatalErrorInArgument, errMsg);
447  }
448  else
449  {
450  if(fVerbose)
451  {
452  G4cout<< " G4MolecularInteractionTable::CanReactWith :"<<G4endl;
453  G4cout<<"You are checking reactants for : " << molecule->GetName()<<G4endl;
454  G4cout<<" the number of reactants is : " << itReactivesMap->second.size()<<G4endl;
455 
456  std::map<const G4Molecule*,
458  compMoleculeP>::const_iterator itProductsVector =
459  itReactivesMap->second.begin();
460 
461  for( ; itProductsVector != itReactivesMap->second.end(); itProductsVector++)
462  {
463  G4cout<<itProductsVector->first->GetName()<<G4endl;
464  }
465  }
466  return &(itReactivesMap->second);
467  }
468 
469  return 0;
470 }
471 
472 const std::vector<const G4DNAMolecularReactionData*>*
474 {
475  if(fReactionDataMV.empty())
476  {
477  G4String errMsg = "No reaction table was implemented";
478  G4Exception("G4MolecularInteractionTable::CanInteractWith","",FatalErrorInArgument, errMsg);
479  return 0 ;
480  }
481  ReactionDataMV::const_iterator it = fReactionDataMV.find(molecule) ;
482 
483  if(it == fReactionDataMV.end())
484  {
485  G4cout<<"Nom : " << molecule->GetName()<<G4endl;
486  G4String errMsg = "No reaction table was implemented for this molecule Definition : "
487  + molecule -> GetName();
488  G4Exception("G4MolecularInteractionTable::GetReactionData","",FatalErrorInArgument, errMsg);
489  return 0; // coverity
490  }
491 
492  return &(it->second);
493 }
std::vector< G4MoleculeHandle > * fProducts
void AddProduct(const G4Molecule *molecule)
G4MoleculeHandle GetMoleculeHandle(const G4Molecule *)
void SetReactive1(const G4Molecule *reactive)
const XML_Char * s
void SetReactive(const G4Molecule *reactive1, const G4Molecule *reactive2)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:357
G4double GetDiffusionCoefficient() const
Definition: G4Molecule.cc:389
int G4int
Definition: G4Types.hh:78
float Avogadro
Definition: hepunit.py:253
static G4DNAMolecularReactionTable * GetReactionTable()
int nanometer
Definition: hepunit.py:35
const G4String & GetName() const
Definition: G4Molecule.cc:243
const G4Molecule * GetProduct(G4int i) const
G4GLOB_DLL std::ostream G4cout
void SetReactive2(const G4Molecule *reactive)
const G4Molecule * GetReactive2() const
void PrintTable(G4VDNAReactionModel *=0)
#define TRUE
Definition: globals.hh:55
const G4int n
static G4DNAMolecularReactionTable * fInstance
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetReaction(G4double observedReactionRate, const G4Molecule *reactive1, const G4Molecule *reactive2)
subroutine title(NA, NB, NCA, NCB)
Definition: dpm25nuc7.f:1744
const G4DNAMolecularReactionData * GetReactionData(const G4Molecule *, const G4Molecule *) const
virtual G4double GetReactionRadius(const G4Molecule *, const G4Molecule *)=0
#define G4endl
Definition: G4ios.hh:61
const G4DNAMolecularReactionTable * GetReactionTable()
double G4double
Definition: G4Types.hh:76
const std::vector< const G4Molecule * > * CanReactWith(const G4Molecule *aMolecule) const
static G4MoleculeHandleManager * Instance()
const G4Molecule * GetReactive1() const
const std::map< const G4Molecule *, const G4DNAMolecularReactionData *, compMoleculeP > * GetReativesNData(const G4Molecule *aMolecule) const