Geant4 Cross Reference |
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 #include "ChemistryWorld.hh" 28 29 #include "G4DNABoundingBox.hh" 30 #include "G4DNAMolecularReactionTable.hh" 31 #include "G4MoleculeTable.hh" 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 34 ChemistryWorld::ChemistryWorld() : G4VChemistryWorld(), G4UImessenger() 35 { 36 fpChemWoldDir = std::make_unique<G4UIdirectory>("/UHDR/env/", false); 37 fpChemWoldDir->SetGuidance("chemistry environment commands"); 38 39 fpAddpH = std::make_unique<G4UIcmdWithADouble>("/UHDR/env/pH", this); 40 fpAddpH->SetGuidance("Add pH for water."); 41 fpAddpH->SetParameterName("pH", false); 42 fpAddpH->SetToBeBroadcasted(false); 43 44 fpAddScavengerName = std::make_unique<G4UIcmdWithAString>("/UHDR/env/scavenger", this); 45 fpAddScavengerName->SetToBeBroadcasted(false); 46 47 fpTargetVolume = std::make_unique<G4UIcmdWithADoubleAndUnit>("/UHDR/env/volume", this); 48 fpTargetVolume->SetGuidance("Volume of water."); 49 fpTargetVolume->SetParameterName("Volume", false); 50 fpTargetVolume->AvailableForStates(G4State_PreInit); 51 fpTargetVolume->SetToBeBroadcasted(false); 52 } 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 54 55 void ChemistryWorld::ConstructChemistryBoundary() 56 { 57 fHalfBox = 1.6 * um; // halfBox 58 std::initializer_list<G4double> l{fHalfBox, -fHalfBox, fHalfBox, -fHalfBox, fHalfBox, -fHalfBox}; 59 fpChemistryBoundary = std::make_unique<G4DNABoundingBox>(l); 60 } 61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 62 63 void ChemistryWorld::SetNewValue(G4UIcommand* command, G4String newValue) 64 { 65 if (command == fpAddpH.get()) { 66 fpH = fpAddpH->GetNewDoubleValue(newValue); 67 ConstructChemistryComponents(); 68 } 69 else if (command == fpAddScavengerName.get()) { 70 std::istringstream iss(newValue); 71 G4String species; 72 iss >> species; 73 auto scavengerConf = G4MoleculeTable::Instance()->GetConfiguration(species); 74 G4double concentraion; 75 iss >> concentraion; 76 G4String unit; 77 iss >> unit; 78 if (unit == "M") { 79 G4double ConcentrationInM = concentraion / (mole * liter); 80 fpChemicalComponent[scavengerConf] = ConcentrationInM; 81 } 82 else if (unit == "mM") { 83 G4double ConcentrationInM = concentraion / (mole * liter * 1e3); 84 fpChemicalComponent[scavengerConf] = ConcentrationInM; 85 } 86 else if (unit == "uM") { 87 G4double ConcentrationInM = concentraion / (mole * liter * 1e6); 88 fpChemicalComponent[scavengerConf] = ConcentrationInM; 89 } 90 else if (unit == "%") // only for O2 91 { 92 G4double ConcentrationInM = (concentraion / 100) * 0.0013 / (mole * liter); 93 fpChemicalComponent[scavengerConf] = ConcentrationInM; 94 } 95 else { 96 throw std::runtime_error("Unit should be in Molarity"); 97 } 98 } 99 else if (command == fpTargetVolume.get()) { 100 fHalfBox = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(newValue); 101 std::initializer_list<G4double> l{fHalfBox, -fHalfBox, fHalfBox, 102 -fHalfBox, fHalfBox, -fHalfBox}; 103 fpChemistryBoundary = std::make_unique<G4DNABoundingBox>(l); 104 } 105 } 106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 107 108 void ChemistryWorld::ConstructChemistryComponents() 109 { 110 auto O2 = G4MoleculeTable::Instance()->GetConfiguration("O2"); 111 auto H2O = G4MoleculeTable::Instance()->GetConfiguration("H2O"); 112 auto H3Op = G4MoleculeTable::Instance()->GetConfiguration("H3Op(B)"); 113 auto OHm = G4MoleculeTable::Instance()->GetConfiguration("OHm(B)"); 114 115 //////////////////////////////////////////////////////////////////// 116 // Water is defined from NIST material database 117 // water 55.3 M, 9.9x10-8 M, and 9.9x10-8 M 118 // water density = 18.01528 g/mol * 55.3 M = 996.24498 g/l 119 // H3OpB density = 1 g/mol * 9.9x10-8 M 120 // OHmB density = 17.01528 g/mol * 9.9x10-8 M 121 // O2B density = 15.999 g/mol * 2.58e-4 M 122 ///////////////////////////////////////////////////////////////// 123 G4double pKw = 14; // at 25°C pK of water is 14 124 G4double waterMolarity = 55.3 / (mole * liter); // 55.3 M 125 fpChemicalComponent[H2O] = waterMolarity; 126 127 G4double H3OpBMolarity = std::pow(10, -fpH) / (mole * liter); // pH = 7 128 fpChemicalComponent[H3Op] = H3OpBMolarity; 129 130 G4double OHmBMolarity = std::pow(10, -(pKw - fpH)) / (mole * liter); // pH = 7 131 fpChemicalComponent[OHm] = OHmBMolarity; 132 // oxygen 133 G4double O2Molarity = (0. / 100) * 0.0013 / (mole * liter); 134 fpChemicalComponent[O2] = O2Molarity; 135 } 136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 137