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 ] [ 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 
 28 // Author: Mathieu Karamitros
 29 //
 30 // The code is developed in the framework of the ESA AO7146
 31 //
 32 // We would be very happy hearing from you, send us your feedback! :)
 33 //
 34 // In order for Geant4-DNA to be maintained and still open-source,
 35 // article citations are crucial. 
 36 // If you use Geant4-DNA chemistry and you publish papers about your software, 
 37 // in addition to the general paper on Geant4-DNA:
 38 //
 39 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
 40 //
 41 // we would be very happy if you could please also cite the following
 42 // reference papers on chemistry:
 43 //
 44 // J. Comput. Phys. 274 (2014) 841-882
 45 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508
 46 
 47 #pragma once
 48 
 49 #include "globals.hh"
 50 #include "G4ThreeVector.hh"
 51 #include <fstream>
 52 #include <memory>
 53 #include "G4UImessenger.hh"
 54 #include "G4VStateDependent.hh"
 55 
 56 class G4Track;
 57 class G4DNAWaterExcitationStructure;
 58 class G4DNAWaterIonisationStructure;
 59 class G4Molecule;
 60 class G4VUserChemistryList;
 61 class G4UIcmdWithABool;
 62 class G4UIcmdWithADoubleAndUnit;
 63 class G4UIcmdWithoutParameter;
 64 class G4UIcmdWithAnInteger;
 65 class G4ITGun;
 66 class G4VPhysChemIO;
 67 
 68 enum ElectronicModification
 69 {
 70     eIonizedMolecule,
 71     eExcitedMolecule,
 72     eDissociativeAttachment
 73 };
 74 
 75 /**
 76  * WARNING: THIS CLASS IS A PROTOTYPE
 77  * G4DNAChemistryManager is called from the physics models.
 78  * It creates the water molecules and the solvated electrons and
 79  * and send them to G4ITStepManager to be treated in the chemistry stage.
 80  * For this, the fActiveChemistry flag needs to be on.
 81  * It is also possible to give already molecule's pointers already built.
 82  * G4DNAChemistryManager will then be in charge of creating the track and loading
 83  * it to the IT system.
 84  * The user can also ask to create a file containing a information about the
 85  * creation of water molecules and solvated electrons.
 86  */
 87 class G4DNAChemistryManager: public G4UImessenger,
 88                              public G4VStateDependent
 89 {
 90 protected:
 91     ~G4DNAChemistryManager() override;
 92 
 93 public:
 94     //============================================================================
 95     // STATIC METHODS
 96     //============================================================================
 97     static G4DNAChemistryManager* Instance();
 98     static G4DNAChemistryManager* GetInstanceIfExists();
 99 
100     static void DeleteInstance();
101     static G4bool IsActivated();
102 
103     //============================================================================
104     // VIRTUAL METHODS
105     //============================================================================
106     // G4VStateDependent
107     G4bool Notify(G4ApplicationState requestedState) override;
108     // G4UImessenger
109     void SetNewValue(G4UIcommand*, G4String) override;
110     G4String GetCurrentValue(G4UIcommand* pCommand) override;
111 
112     //============================================================================
113     // INITIALIZATION AND FINALIZATION METHODS
114     //============================================================================
115     G4bool IsChemistryActivated();
116     void SetChemistryActivation(G4bool);
117 
118     /** Chemistry list is managed outside the chemistry manager (eg. constructor). */
119     void SetChemistryList(G4VUserChemistryList&);
120 
121     /** Not a constructor or when used in standalone? Prefer this method. */
122     void SetChemistryList(std::unique_ptr<G4VUserChemistryList>);
123 
124     // [[deprecated]] : chemistry list should never be nullptr
125     void SetChemistryList(G4VUserChemistryList*);
126 
127     void Deregister(G4VUserChemistryList&);
128 
129     void Initialize();
130     void Run();
131     void Clear();
132 
133     /**
134      * @brief Inject custom species to the simulation
135      * @details This method should be called per thread, possibly from
136      * ActionInitialisation::Build.
137      * One can decide to set the same gun for all threads.
138      * It is the user responsibility to handle the pointer deletion.
139      */
140     void SetGun(G4ITGun* pChemSpeciesGun);
141 
142     void SetPhysChemIO(std::unique_ptr<G4VPhysChemIO> pPhysChemIO);
143 
144     void SetVerbose(G4int verbose);
145 
146     /**
147      * If the chemistry module is used in standalone (ie. without running the physics
148      * stage beforehand), the physics table still needs to be built.
149      * It is therefore necessary to flag the chemistry module as being run
150      * in standalone.
151      */
152     void UseAsStandalone(G4bool flag);
153     G4bool IsCounterResetWhenRunEnds() const;
154 
155     void ResetCounterWhenRunEnds(G4bool resetCounterWhenRunEnds);
156 
157     void ForceMasterReinitialization();
158     void TagThreadForReinitialization();
159     void ForceThreadReinitialization();
160     void ForceRebuildingPhysicsTable();
161 
162     //============================================================================
163     // FILE OPERATIONS
164     //============================================================================
165     /**
166      * Tells the chemMan to write into a file
167      * the position and electronic state of the water molecule
168      * and the position thermalized or not of the solvated electron
169      */
170     void WriteInto(const G4String&, std::ios_base::openmode mode =
171                    std::ios_base::out);
172     void AddEmptyLineInOutputFile();
173 
174     /**
175      * Close the file specified with WriteInto
176      */
177     void CloseFile();
178 
179     //============================================================================
180     // PUSH MOLECULES
181     //============================================================================
182     /**
183      * Method used by DNA physics model to create a water molecule.
184      * The ElectronicModification is a flag telling whether the molecule
185      * is ionized or excited, the electronic level is calculated by the
186      * model and the IncomingTrack is the track responsible for the creation
187      * of this molecule (electron, proton...).
188      */
189     void CreateWaterMolecule(ElectronicModification,
190                              G4int /*electronicLevel*/,
191                              const G4Track* /*pIncomingTrack*/);
192 
193     /**
194      * This method should be used by the physics model of the ElectronSolvatation
195      * process.
196      */
197     void CreateSolvatedElectron(const G4Track* /*pIncomingTrack*/,
198                                 G4ThreeVector* pFinalPosition = nullptr);
199 
200     void PushMolecule(std::unique_ptr<G4Molecule> pMolecule,
201                       G4double time,
202                       const G4ThreeVector& position,
203                       G4int parentID);
204 
205 protected:
206     void HandleStandaloneInitialization();
207     void PushTrack(G4Track*);
208     void SetGlobalTemperature(G4double temperatureKelvin);
209 
210     G4DNAWaterExcitationStructure* GetExcitationLevel();
211     G4DNAWaterIonisationStructure* GetIonisationLevel();
212     void InitializeFile();
213     void InitializeMaster();
214     void InitializeThread();
215     void InitializeThreadSharedData();
216 
217     G4DNAChemistryManager();
218 
219 private:
220     std::unique_ptr<G4UIdirectory> fpChemDNADirectory;
221     std::unique_ptr<G4UIcmdWithABool> fpActivateChem;
222     std::unique_ptr<G4UIcmdWithAnInteger> fpRunChem;
223     std::unique_ptr<G4UIcmdWithoutParameter> fpSkipReactionsFromChemList;
224     std::unique_ptr<G4UIcmdWithADoubleAndUnit> fpScaleForNewTemperature;
225     std::unique_ptr<G4UIcmdWithoutParameter> fpInitChem;
226 
227     static G4DNAChemistryManager* fgInstance;
228     G4bool fActiveChemistry{false};
229 
230     struct ThreadLocalData{
231         ThreadLocalData();
232         ~ThreadLocalData();
233         std::unique_ptr<G4VPhysChemIO> fpPhysChemIO;
234         G4bool fThreadInitialized = false;
235     };
236 
237     static G4ThreadLocal ThreadLocalData* fpThreadData;
238 
239     G4bool fMasterInitialized{false};
240     G4bool fForceThreadReinitialization{false};
241 
242     std::unique_ptr<G4DNAWaterExcitationStructure> fpExcitationLevel;
243     std::unique_ptr<G4DNAWaterIonisationStructure> fpIonisationLevel;
244 
245     std::unique_ptr<G4VUserChemistryList> fpUserChemistryList;
246     G4bool fOwnChemistryList{false};
247     G4bool fUseInStandalone{false};
248     G4bool fPhysicsTableBuilt{false};
249     G4bool fSkipReactions{false};
250 
251     G4bool fGeometryClosed{false};
252 
253     G4int fVerbose{0};
254     G4bool fResetCounterWhenRunEnds{true};
255 };
256