Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 /// \file ChemGeoImport.cc 28 /// \brief Implementation of the ChemGeoImport 29 30 #include "ChemGeoImport.hh" 31 #include "G4Filesystem.hh" 32 #include "G4DNAMolecule.hh" 33 34 ChemGeoImport::ChemGeoImport() 35 { 36 GetVoxelDefFilePathList(); 37 fpGun = new UserMoleculeGun(); 38 } 39 40 //....oooOO0OOooo........oooOO0OOooo........oo 41 42 ChemGeoImport::~ChemGeoImport() 43 { 44 if(fpGun) 45 delete fpGun; 46 } 47 48 //....oooOO0OOooo........oooOO0OOooo........oo 49 50 void ChemGeoImport::InsertMoleculeInWorld() 51 { 52 // The idea is to add all the molecules sp 53 54 if(fIsParsed) 55 { 56 // Create the molecules 57 58 // Loop on all the parsed molecules 59 for(G4int i=0, ie=fMolecules.size(); i 60 { 61 // Retrieve general molecule infor 62 // 63 G4String name = fMolecules[i].fNam 64 65 G4ThreeVector moleculePosition = f 66 G4int copyNum = fMolecules[i].fCop 67 68 G4int strand = fMolecules[i].fStra 69 ChemMolecule Bmolecule(name, copyN 70 71 if(name=="phosphate1" || name=="ph 72 { 73 name=G4Phosphate::Definition() 74 Bmolecule.fName=name; 75 } 76 else if(name=="deoxyribose1" || na 77 { 78 name=G4Deoxyribose::Definition 79 Bmolecule.fName=name; 80 } 81 else if(name=="base_adenine") 82 { 83 name=G4Adenine::Definition()-> 84 Bmolecule.fName=name; 85 } 86 else if(name=="base_guanine") 87 { 88 name=G4Guanine::Definition()-> 89 Bmolecule.fName=name; 90 } 91 else if(name=="base_thymine") 92 { 93 name=G4Thymine::Definition()-> 94 Bmolecule.fName=name; 95 } 96 else if(name=="base_cytosine") 97 { 98 name=G4Cytosine::Definition()- 99 Bmolecule.fName=name; 100 } 101 else if(name=="histone") 102 { 103 name=G4Histone::Definition()-> 104 Bmolecule.fName=name; 105 } 106 else if(name=="solvatedElectron") 107 { 108 name=G4Electron_aq::Definition 109 } 110 else if(name=="water") 111 { 112 name=G4H2O::Definition()->GetN 113 } 114 else 115 { 116 G4String msg = 117 "The name "+ name+" is not spe 118 G4Exception("ChemGeoImport::Bu 119 } 120 121 // Check if the molecule is on the 122 G4bool toBeRemoved = IsMoleculeInT 123 if(!toBeRemoved) 124 { 125 // Molecule is not in the "rem 126 // Check the molecule to be ad 127 if(name != G4H2O::Definition() 128 fpGun->AddMolecule(name, m 129 else // Water molecule case 130 fpGun->AddWaterMolecule(mo 131 ElectronicModification 132 fMolecules.at(i).fElec 133 } 134 135 } 136 G4DNAChemistryManager::Instance()->Set 137 } 138 else 139 { 140 G4String msg = 141 "ChemGeoImport::InsertMoleculeInWorld: 142 G4Exception("ChemGeoImport::ChemGeoImp 143 } 144 } 145 146 //....oooOO0OOooo........oooOO0OOooo........oo 147 148 void ChemGeoImport::Reset() 149 { 150 // Clear the containers 151 if(fpGun){ 152 delete fpGun; 153 fpGun = new UserMoleculeGun(); 154 } 155 fMolecules.clear(); 156 fMolecules.shrink_to_fit(); 157 fToBeRemovedMol.clear(); 158 fIsParsed = false; 159 fFactor = 1.; 160 } 161 162 //....oooOO0OOooo........oooOO0OOooo........oo 163 164 void ChemGeoImport::ParseFiles(const G4String& 165 { 166 G4fs::path aP{std::string(chemInputFile)}; 167 if (G4fs::exists(aP)) { 168 Reset(); 169 ParseChemInputFile(chemInputFile); 170 auto geoPathFileName = GetVoxelDefFile 171 172 ParseGeoFile(geoPathFileName); 173 fIsParsed = true; 174 } 175 } 176 177 //....oooOO0OOooo........oooOO0OOooo........oo 178 179 void ChemGeoImport::ParseChemInputFile(const G 180 { 181 // Setup the input stream 182 std::ifstream file; 183 file.open(fileName.c_str() ); 184 185 if(!file.good() ) 186 { 187 // Geant4 exception 188 G4String msg = fileName+" could not be 189 G4Exception("ChemGeoImport::ParseChemI 190 } 191 192 // Define the line string variable 193 G4String line; 194 195 // Read the file line per line 196 while(std::getline(file, line) ) 197 { 198 // Check the line to determine if it i 199 if(line.empty() ) 200 continue; // skip the line if it i 201 202 // Data string stream 203 std::istringstream issLine(line); 204 205 // String to determine the first lette 206 G4String firstItem; 207 208 // Put the first letter/word within th 209 issLine >> firstItem; 210 211 // Check first letter to determine if 212 if(firstItem=="#") 213 continue; // skip the line if it i 214 215 else if(firstItem=="_input") 216 { 217 G4int type(-1), state(-1), electro 218 G4double x, y, z; 219 issLine >> type >> state >> electr 220 issLine >> x >> y >> z; 221 issLine >> parentTrackId; 222 223 x *= fFactor*nm; 224 y *= fFactor*nm; 225 z *= fFactor*nm; 226 227 G4String name; 228 if(type==1) 229 name="water"; 230 else if(type==2) 231 name="solvatedElectron"; 232 else 233 { 234 G4ExceptionDescription descrip 235 description << "The type " << 236 G4Exception("ChemGeoImport::Pa 237 } 238 239 ChemMolecule molecule(name, -1, G4 240 state, electronicLevel, parent 241 242 fMolecules.push_back(molecule); 243 } 244 245 else if(firstItem=="_remove") 246 { 247 G4String name; 248 issLine >> name; 249 250 G4int copyNumber; 251 issLine >> copyNumber; 252 253 G4int strand; 254 issLine >> strand; 255 256 fToBeRemovedMol.push_back(ChemMole 257 } 258 259 else if(firstItem=="_eventNum") 260 { 261 // Nothing 262 } 263 264 else if(firstItem=="_voxelType") 265 { 266 issLine >> fGeoNameFromChemInput; 267 } 268 269 else if(firstItem=="_voxelCopyNumber") 270 { 271 // Nothing 272 } 273 274 else if(firstItem=="_Version") 275 { 276 // Nothing 277 } 278 279 else 280 { 281 // Geant4 exception 282 G4String msg = 283 firstItem+" is not defined in the 284 G4Exception("ChemGeoImport::ParseC 285 } 286 } 287 file.close(); 288 } 289 290 //....oooOO0OOooo........oooOO0OOooo........oo 291 292 void ChemGeoImport::ParseGeoFile(const G4Strin 293 { 294 // Setup the input stream 295 std::ifstream file(fileName.c_str()); 296 297 // Check if the file was correctly opened 298 if(!file.is_open() ) 299 { 300 // Geant4 exception 301 G4String msg = fileName+" could not be 302 G4Exception("ChemGeoImport::ParseGeoFi 303 } 304 305 // Define the line string variable 306 G4String line; 307 308 // Read the file line per line 309 while(std::getline(file, line) ) 310 { 311 // Check the line to determine if it i 312 if(line.empty() ) 313 continue; // skip the line if it i 314 315 // Data string stream 316 std::istringstream issLine(line); 317 318 // String to determine the first lette 319 G4String firstItem; 320 321 // Put the first letter/word within th 322 issLine >> firstItem; 323 324 // Check first letter to determine if 325 if(firstItem=="#") 326 continue; // skip the line if it i 327 328 // Use the file 329 else if(firstItem=="_Name") 330 { 331 G4String name; 332 issLine >> name; 333 } 334 else if(firstItem=="_Size") 335 { 336 G4double size; 337 issLine >> size; 338 size *= fFactor*nm; 339 340 fSize = size; 341 } 342 else if(firstItem=="_Number") 343 { 344 // Nothing 345 } 346 else if(firstItem=="_Radius") 347 { 348 // Nothing 349 } 350 else if(firstItem=="_Version") 351 { 352 // Nothing 353 } 354 else if(firstItem=="_pl") 355 { 356 G4String name; 357 issLine >> name; 358 359 G4String material; 360 issLine >> material; 361 362 G4int strand; 363 issLine >> strand; 364 365 G4int copyNumber; 366 issLine >> copyNumber; 367 368 G4double x; 369 issLine >> x; 370 x *= fFactor*nm; 371 372 G4double y; 373 issLine >> y; 374 y *= fFactor*nm; 375 376 G4double z; 377 issLine >> z; 378 z *= fFactor*nm; 379 380 ChemMolecule molecule(name, copyNu 381 382 fMolecules.push_back(molecule); 383 } 384 385 else 386 { 387 // Geant4 exception 388 G4String msg = 389 firstItem+" is not defined in the 390 G4Exception("ChemGeoImport::ParseG 391 } 392 } 393 file.close(); 394 } 395 396 //....oooOO0OOooo........oooOO0OOooo........oo 397 398 G4bool ChemGeoImport::IsMoleculeInTheRemoveTab 399 { 400 if(std::find(fToBeRemovedMol.begin(),fToBe 401 return true; 402 else 403 return false; 404 } 405 406 //....oooOO0OOooo........oooOO0OOooo........oo 407 408 G4String ChemGeoImport::GetVoxelDefFilePath(G4 409 { 410 G4String strRes = ""; 411 for (auto const &entry : fVoxelDefFilesLis 412 G4fs::path voxelP{std::string(entry)}; 413 if (voxelP.stem().string() == bareName 414 strRes = entry; 415 } 416 } 417 return strRes; 418 } 419 420 //....oooOO0OOooo........oooOO0OOooo........oo 421 422 void ChemGeoImport::GetVoxelDefFilePathList() 423 { 424 G4fs::path thisP = G4fs::current_path(); 425 G4bool doesWantedFileExist = false; 426 for (const auto &entry : G4fs::directory_i 427 if (entry.path().filename() == "imp.in 428 std::ifstream file(entry.path().c_ 429 if(!file.good() ){ 430 G4String msg = 431 "File imp.info is broken. Chec 432 G4Exception("ChemGeoImport::Ge 433 } 434 doesWantedFileExist = true; 435 G4String line; 436 while(std::getline(file, line) ){ 437 std::istringstream iss(line); 438 G4String flag; 439 G4String voxelDefFile; 440 iss >> flag; 441 if ( flag == "_geovolxelpath") 442 iss >> voxelDefFile; 443 fVoxelDefFilesList.insert( 444 } 445 } 446 file.close(); 447 } 448 } 449 450 if (!doesWantedFileExist) { 451 G4String msg = "File imp.info does not 452 G4Exception("ChemGeoImport::GetVoxelDe 453 } 454 } 455 456 //....oooOO0OOooo........oooOO0OOooo........oo