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.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 //
 27 // Author: Mathieu Karamitros
 28 
 29 // The code is developed in the framework of the ESA AO7146
 30 //
 31 // We would be very happy hearing from you, send us your feedback! :)
 32 //
 33 // In order for Geant4-DNA to be maintained and still open-source,
 34 // article citations are crucial. 
 35 // If you use Geant4-DNA chemistry and you publish papers about your software, 
 36 // in addition to the general paper on Geant4-DNA:
 37 //
 38 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
 39 //
 40 // we would be very happy if you could please also cite the following
 41 // reference papers on chemistry:
 42 //
 43 // J. Comput. Phys. 274 (2014) 841-882
 44 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508 
 45 
 46 #ifndef G4MolecularConfiguration_
 47 #define G4MolecularConfiguration_ 1
 48 
 49 #include <vector>
 50 #include <map>
 51 #include "G4Threading.hh"
 52 #include "G4ElectronOccupancy.hh"
 53 #include <cassert>
 54 #include <functional>
 55 
 56 class G4MolecularDissociationChannel;
 57 class G4MoleculeDefinition;
 58 class G4Material;
 59 class G4MolecularConfiguration;
 60 
 61 struct comparator
 62 {
 63   bool operator()(const G4ElectronOccupancy& occ1,
 64                   const G4ElectronOccupancy& occ2) const
 65   {
 66     G4int totalOcc1 = occ1.GetTotalOccupancy();
 67     G4int totalOcc2 = occ2.GetTotalOccupancy();
 68     if (totalOcc1 != totalOcc2)
 69     {
 70       return totalOcc1 < totalOcc2;
 71     }
 72 
 73     G4int occupancy1 = -1;
 74     G4int occupancy2 = -1;
 75     const G4int sizeOrbit = occ1.GetSizeOfOrbit();
 76     for (G4int i = 0; i < sizeOrbit; i++)
 77     {
 78       occupancy1 = occ1.GetOccupancy(i);
 79       occupancy2 = occ2.GetOccupancy(i);
 80 
 81       if (occupancy1 != occupancy2)
 82       {
 83         return occupancy1 < occupancy2;
 84       }
 85     }
 86     
 87     return false;
 88   }
 89 };
 90 
 91 /** The pointer G4MolecularConfiguration will be shared by all the
 92  * molecules having the same molecule definition and the same
 93  * electron occupancy
 94  * BE CAREFUlL !!! : If you change the mass for instance of a OH^-,
 95  * this will affect all the OH^- molecule diffusing around
 96  */
 97 class G4MolecularConfiguration
 98 {
 99 public:
100 
101   using G4DiffCoeffParam = std::function<double (const G4Material *, double, const G4MolecularConfiguration *)>;
102 
103   //____________________________________________________________________________
104   // Static methods
105 
106   /////////////////////////////////////////////////
107   // CREATE FINALIZED SPECIES
108   // Get ground state electronic configuration
109   static G4MolecularConfiguration*
110   GetOrCreateMolecularConfiguration(const G4MoleculeDefinition*);
111 
112   // Get for a given moleculeDefinition and a given electronic configuration,
113   // the molecular configuration
114   static G4MolecularConfiguration*
115   GetOrCreateMolecularConfiguration(const G4MoleculeDefinition*,
116                                     const G4ElectronOccupancy& eOcc);
117 
118   // Get for a given moleculeDefinition and a given electronic configuration,
119   // the molecular configuration
120   static G4MolecularConfiguration*
121   GetOrCreateMolecularConfiguration(const G4MoleculeDefinition*, int charge);
122 
123   /////////////////////////////////////////////////
124   // CREATE UNFINALIZED SPECIES
125   // Create ground state electronic configuration - to be finalized
126   static G4MolecularConfiguration*
127     CreateMolecularConfiguration(const G4String& userIdentifier,
128                                  const G4MoleculeDefinition*,
129                                  bool& wasAlreadyCreated);
130 
131   static G4MolecularConfiguration*
132     CreateMolecularConfiguration(const G4String& userIdentifier,
133                                  const G4MoleculeDefinition*,
134                                  const G4String& label,
135                                  const G4ElectronOccupancy& eOcc,
136                                  bool& wasAlreadyCreated);
137 
138   static G4MolecularConfiguration*
139     CreateMolecularConfiguration(const G4String& userIdentifier,
140                                  const G4MoleculeDefinition*,
141                                  int charge,
142                                  const G4String& label,
143                                  bool& wasAlreadyCreated);
144 
145   static G4MolecularConfiguration*
146     CreateMolecularConfiguration(const G4String& userIdentifier,
147                                  const G4MoleculeDefinition*,
148                                  const G4String& label,
149                                  bool& wasAlreadyCreated);
150 
151   /////////////////////////////////////////////////
152   // GET MOL CONF
153   //
154   static G4MolecularConfiguration*
155     GetMolecularConfiguration(const G4MoleculeDefinition*,
156                               const G4String& label);
157 
158   static G4MolecularConfiguration*
159     GetMolecularConfiguration(int moleculeID);
160 
161   static G4MolecularConfiguration*
162     GetMolecularConfiguration(const G4String& userID);
163 
164   static int GetNumberOfSpecies();
165 
166   static std::map<G4String, G4MolecularConfiguration*>& GetUserIDTable()
167   {
168     return GetManager()->GetUserIDTable();
169   }
170 
171   // Release memory of the mol conf manager
172   static void DeleteManager();
173 
174   static double DiffCoeffWater(double temperature_K);
175 
176   void AddDiffCoeffParameterization(const G4DiffCoeffParam&);
177 
178   //____________________________________________________________________________
179 
180   const G4MoleculeDefinition* GetDefinition() const;
181 
182   /** Returns the name of the molecule
183    */
184   const G4String& GetName() const;
185 
186   /** Returns the formated name of the molecule
187    */
188   const G4String& GetFormatedName() const;
189 
190   /** Returns the nomber of atoms compouning the molecule
191    */
192   G4int GetAtomsNumber() const;
193 
194   /** Method used in Geant4-DNA to excite water molecules
195    */
196   G4MolecularConfiguration* ExciteMolecule(G4int) const;
197 
198   /** Method used in Geant4-DNA to ionize water molecules
199    */
200   G4MolecularConfiguration* IonizeMolecule(G4int) const;
201 
202   /** Add n electrons to a given orbit.
203    * Note : You can add as many electrons to a given orbit, the result
204    * may be unrealist.
205    */
206   G4MolecularConfiguration* AddElectron(G4int orbit, G4int n = 1) const;
207 
208   /** Remove n electrons to a given orbit.
209    */
210   G4MolecularConfiguration* RemoveElectron(G4int, G4int number = 1) const;
211 
212   /** Move one electron from an orbit to another.
213    */
214   G4MolecularConfiguration* MoveOneElectron(G4int /*orbit*/, G4int /*orbit*/) const;
215 
216   /** Returns the number of electron.
217    */
218   G4double GetNbElectrons() const;
219 
220   /** Display the electronic state of the molecule.
221    */
222   void PrintState() const;
223 
224   const std::vector<const G4MolecularDissociationChannel*>* GetDissociationChannels() const;
225 
226   G4int GetFakeParticleID() const;
227 
228   inline G4int GetMoleculeID() const;
229 
230   /** Sets the diffusion coefficient D of the molecule used in diffusion
231    * processes to calculate the mean square jump distance between two
232    * changes of direction. In three dimension : <x^2> = 6 D t where t is
233    * the mean jump time between two changes of direction.
234    *
235    * Note : Diffusion Coefficient in one medium only
236    * For the time being, we will consider only one diffusion
237    * coefficient for the all simulation => diffusion in one medium only
238    * If the user needs to use the diffusion in different materials,
239    * she/he should contact the developers/maintainers of this package
240    */
241   inline void SetDiffusionCoefficient(G4double);
242 
243   /** Returns the diffusion coefficient D.
244    */
245   inline G4double GetDiffusionCoefficient() const;
246 
247   inline G4double GetDiffusionCoefficient(const G4Material*,
248                                           double temperature) const;
249 
250   /** Set the decay time of the molecule.
251    */
252   inline void SetDecayTime(G4double);
253 
254   /** Returns the decay time of the molecule.
255    */
256   inline G4double GetDecayTime() const;
257 
258   /** The Van Der Valls Radius of the molecule
259    */
260   inline void SetVanDerVaalsRadius(G4double);
261   inline G4double GetVanDerVaalsRadius() const;
262 
263   /** Returns the object ElectronOccupancy describing the electronic
264    * configuration of the molecule.
265    */
266   inline const G4ElectronOccupancy* GetElectronOccupancy() const;
267 
268   /** Returns the charge of molecule.
269    */
270   inline G4int GetCharge() const;
271 
272   /** Set the total mass of the molecule.
273    */
274   inline void SetMass(G4double);
275 
276   /** Returns the total mass of the molecule.
277    */
278   inline G4double GetMass() const;
279 
280   /*
281    * Adds a label to the molecular configuration
282    * (Can be used for vibrational states for instance)
283    */
284   inline void SetLabel(const G4String&);
285 
286   /*
287    * Returns the label assigned by the user
288    */
289   inline const G4String& GetLabel() const;
290 
291   inline void Finalize();
292   static void FinalizeAll();
293   static void PrintAll(); //hoang added
294   inline void UnFinalize();
295   void SetUserID(const G4String& userID);//hoang moved it to public
296 
297   inline const G4String& GetUserID() const;
298 
299   static void SetGlobalTemperature(G4double);
300   static G4double GetGlobalTemperature();
301 
302   //___________________________________________________________________________
303   // EXPERIMENTAL
304 
305   static G4MolecularConfiguration* Load(std::istream&);
306 
307   void Serialize(std::ostream&);
308   void Unserialize(std::istream&);
309   //___________________________________________________________________________
310 
311 
312 protected:
313   G4MolecularConfiguration(const G4MoleculeDefinition*,
314                            const G4ElectronOccupancy&,
315                            const G4String& label = "");
316 
317   G4MolecularConfiguration(const G4MoleculeDefinition*,
318                            int charge);
319 
320   G4MolecularConfiguration(const G4MoleculeDefinition*,
321                            const G4String& label,
322                            int charge);
323 
324   G4MolecularConfiguration(std::istream&);
325 
326   G4MolecularConfiguration(const G4MolecularConfiguration&);
327   G4MolecularConfiguration & operator=(G4MolecularConfiguration &right);
328   ~G4MolecularConfiguration();
329   G4MolecularConfiguration* ChangeConfiguration(const G4ElectronOccupancy& newElectronOccupancy) const;
330   G4MolecularConfiguration* ChangeConfiguration(int charge) const;
331 
332   void CheckElectronOccupancy(const char* line) const;
333   void MakeExceptionIfFinalized();
334 
335   void CreateDefaultDiffCoeffParam();
336   static void ScaleAllDiffusionCoefficientsOnWater(double temperature_K);
337 
338 public:
339   class G4MolecularConfigurationManager
340   {
341   public:
342     G4MolecularConfigurationManager()
343     {
344       fLastMoleculeID = -1;
345     }
346     ~G4MolecularConfigurationManager();
347 
348     int GetNumberOfCreatedSpecies()
349     {
350       return fLastMoleculeID+1;
351     }
352 
353     //------------------------------------------------------------------------
354     // CALLED FROM CONSTRUCTORS
355     G4int Insert(const G4MoleculeDefinition* molDef,
356                  const G4ElectronOccupancy& eOcc,
357                  G4MolecularConfiguration* molConf);
358 
359     G4int Insert(const G4MoleculeDefinition* molDef,
360                  int charge,
361                  G4MolecularConfiguration* molConf);
362 
363     G4int Insert(const G4MoleculeDefinition* molDef,
364                  const G4String& label,
365                  G4MolecularConfiguration* molConf);
366 
367     //------------------------------------------------------------------------
368     // CALLED WHEN USER ADD SPECIES
369     void AddUserID(const G4String& name,
370                    G4MolecularConfiguration* molecule);
371 
372     void RecordNewlyLabeledConfiguration(G4MolecularConfiguration* molConf);
373 
374     const G4ElectronOccupancy*
375       FindCommonElectronOccupancy(const G4MoleculeDefinition* molDef,
376                                   const G4ElectronOccupancy& eOcc);
377 
378     G4MolecularConfiguration*
379       GetMolecularConfiguration(const G4MoleculeDefinition* molDef,
380                                 const G4ElectronOccupancy& eOcc);
381 
382     G4MolecularConfiguration*
383       GetMolecularConfiguration(const G4MoleculeDefinition* molDef,
384                                 int charge);
385 
386     G4MolecularConfiguration*
387       GetMolecularConfiguration(const G4MoleculeDefinition* molDef,
388                                 const G4String& label);
389 
390     G4MolecularConfiguration* GetMolecularConfiguration(int moleculeID);
391 
392     G4MolecularConfiguration* GetMolecularConfiguration(const G4String& userID);
393 
394     G4MolecularConfiguration*
395       GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef,
396                                         const G4ElectronOccupancy& eOcc);
397 
398     G4MolecularConfiguration*
399       GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef,
400                                         int charge);
401 
402     static G4Mutex fManagerCreationMutex;
403 
404     void RemoveMolecularConfigurationFromTable(G4MolecularConfiguration*);
405 
406     const std::vector<G4MolecularConfiguration*>& GetAllSpecies()
407     {
408       return fMolConfPerID;
409     }
410 
411     std::map<G4String, G4MolecularConfiguration*>& GetUserIDTable()
412     {
413       return fUserIDTable;
414     }
415 
416   private:
417 
418     //__________________________________________________________________________
419     using ElectronOccupancyTable = std::map<G4ElectronOccupancy, G4MolecularConfiguration *, comparator>;
420     using MolElectronConfTable = std::map<const G4MoleculeDefinition *, ElectronOccupancyTable>;
421     MolElectronConfTable fElecOccTable;
422 
423     //__________________________________________________________________________
424     using ChargeTable = std::map<int, G4MolecularConfiguration *>;
425     using MolChargeConfTable = std::map<const G4MoleculeDefinition *, ChargeTable>;
426     MolChargeConfTable fChargeTable;
427 
428     //__________________________________________________________________________
429     using LabelTable = std::map<const G4String, G4MolecularConfiguration *>;
430     using MolLabelConfTable = std::map<const G4MoleculeDefinition *, std::map<const G4String, G4MolecularConfiguration *>>;
431     MolLabelConfTable fLabelTable;
432 
433     //__________________________________________________________________________
434     using UserIDTable = std::map<G4String, G4MolecularConfiguration *>;
435     UserIDTable fUserIDTable;
436 
437     //__________________________________________________________________________
438     std::vector<G4MolecularConfiguration*> fMolConfPerID;
439     // Indexed by molecule ID
440 
441     //__________________________________________________________________________
442     G4int fLastMoleculeID;
443     G4Mutex fMoleculeCreationMutex;
444   };
445 
446 protected:
447   static G4MolecularConfigurationManager* fgManager;
448   static G4MolecularConfigurationManager* GetManager();
449 
450   const G4MoleculeDefinition* fMoleculeDefinition;
451   const G4ElectronOccupancy* fElectronOccupancy;
452 
453   mutable G4String* fLabel;
454 
455   G4double fDynDiffusionCoefficient;
456   G4double fDynVanDerVaalsRadius;
457   G4double fDynDecayTime;
458   G4double fDynMass;
459   G4int fDynCharge;
460   G4int fMoleculeID;
461   /*mutable*/ G4String fFormatedName;
462   /*mutable*/ G4String fName;
463   G4String fUserIdentifier;
464   G4bool fIsFinalized;
465 
466   G4DiffCoeffParam fDiffParam;
467   static /*G4ThreadLocal*/double fgTemperature;
468 
469   static double ReturnDefaultDiffCoeff(const G4Material*,
470                                        double,
471                                        const G4MolecularConfiguration*
472                                        molConf);
473 };
474 
475 inline const G4MoleculeDefinition* G4MolecularConfiguration::GetDefinition() const
476 {
477   return fMoleculeDefinition;
478 }
479 
480 inline const G4ElectronOccupancy* G4MolecularConfiguration::GetElectronOccupancy() const
481 {
482   return fElectronOccupancy;
483 }
484 
485 inline void G4MolecularConfiguration::SetDiffusionCoefficient(G4double dynDiffusionCoefficient)
486 {
487   MakeExceptionIfFinalized();
488   fDynDiffusionCoefficient = dynDiffusionCoefficient;
489 }
490 
491 inline G4double G4MolecularConfiguration::GetDiffusionCoefficient() const
492 {
493   return fDynDiffusionCoefficient;
494 }
495 
496 inline void G4MolecularConfiguration::SetDecayTime(G4double dynDecayTime)
497 {
498   MakeExceptionIfFinalized();
499   fDynDecayTime = dynDecayTime;
500 }
501 
502 inline G4double G4MolecularConfiguration::GetDecayTime() const
503 {
504   return fDynDecayTime;
505 }
506 
507 inline void G4MolecularConfiguration::SetVanDerVaalsRadius(G4double dynVanDerVaalsRadius)
508 {
509   MakeExceptionIfFinalized();
510   fDynVanDerVaalsRadius = dynVanDerVaalsRadius;
511 }
512 
513 inline G4double G4MolecularConfiguration::GetVanDerVaalsRadius() const
514 {
515   return fDynVanDerVaalsRadius;
516 }
517 
518 inline G4int G4MolecularConfiguration::GetCharge() const
519 {
520   return fDynCharge;
521 }
522 
523 inline void G4MolecularConfiguration::SetMass(G4double aMass)
524 {
525   MakeExceptionIfFinalized();
526   fDynMass = aMass;
527 }
528 
529 inline G4double G4MolecularConfiguration::GetMass() const
530 {
531   return fDynMass;
532 }
533 
534 inline G4int G4MolecularConfiguration::GetMoleculeID() const
535 {
536   return fMoleculeID;
537 }
538 
539 inline void G4MolecularConfiguration::SetLabel(const G4String& label)
540 {
541   assert(fLabel == 0 || *fLabel == "");
542   if(fLabel == nullptr)
543   {
544     fLabel = new G4String(label);
545   }
546   else
547   {
548     *fLabel = label;
549   }
550   fgManager->RecordNewlyLabeledConfiguration(this);
551 }
552 
553 inline const G4String& G4MolecularConfiguration::GetLabel() const
554 {
555   if(fLabel == nullptr)
556     fLabel = new G4String();
557 
558   return (*fLabel);
559 }
560 
561 inline void G4MolecularConfiguration::Finalize()
562 {
563   CreateDefaultDiffCoeffParam();
564   fIsFinalized = true;
565 }
566 
567 inline const G4String& G4MolecularConfiguration::GetUserID() const
568 {
569   return fUserIdentifier;
570 }
571 
572 inline void G4MolecularConfiguration::AddDiffCoeffParameterization
573 (const G4DiffCoeffParam& para)
574 {
575   fDiffParam = para;
576 }
577 
578 inline G4double
579 G4MolecularConfiguration::GetDiffusionCoefficient(const G4Material* material,
580                                                   double temperature) const
581 {
582   return fDiffParam(material, temperature, this);
583 }
584 
585 inline void G4MolecularConfiguration::UnFinalize()
586 {
587   fIsFinalized = false;
588 }
589 
590 #endif
591