Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:53

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // Authors: J. Naoki D. Kondo (UCSF, US) : 10/10/2021
0027 //          J. Ramos-Mendez and B. Faddegon (UCSF, US)
0028 //
0029 /// \file PhysGeoImport.cc
0030 /// \brief Implementation of the plasmid load methods for the geometry
0031 
0032 #include "PhysGeoImport.hh"
0033 
0034 #include "G4DNAChemistryManager.hh"
0035 #include "G4Ellipsoid.hh"
0036 #include "G4VPhysicalVolume.hh"
0037 #include "Randomize.hh"
0038 
0039 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0040 
0041 PhysGeoImport::PhysGeoImport() {}
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0044 
0045 G4LogicalVolume* PhysGeoImport::CreateLogicVolumeXYZ(G4String fileName)
0046 {
0047   G4NistManager* man = G4NistManager::Instance();
0048   fEnvelopeWater = man->FindOrBuildMaterial("G4_WATER");
0049   fpWater =
0050     man->BuildMaterialWithNewDensity("G4_WATER_MODIFIED", "G4_WATER", 1.0 * g / cm / cm / cm);
0051 
0052   ReadFile(fileName);
0053 
0054   G4double des1 = 1.1344640137963142;
0055   G4double des2 = des1 + (CLHEP::pi * .5);
0056   G4double ang = 0.6283185307179586;
0057   G4double bet1 = 0.6283185307179586 * 2;
0058   G4double posi = 1.0471975511965976;
0059   G4double sep = .1 * angstrom;
0060   // Geometries Sizes
0061   G4double PxRs = 2.9389169420478556 * angstrom;
0062   G4double PyRs = 2.9389169420478556 * angstrom;
0063   G4double PzRs = 2.9389169420478556 * angstrom;
0064   G4double PxYs = 2.7 * angstrom;
0065   G4double PyYs = 2.7 * angstrom;
0066   G4double PzYs = 2.7 * angstrom;
0067   G4double PxBp = 2.45 * angstrom;
0068   G4double PyBp = 2.45 * angstrom;
0069   G4double PzBp = 2.45 * angstrom;
0070 
0071   G4double xin = -170 * angstrom;
0072   G4double yin = -170 * angstrom;
0073   G4double zin = -170 * angstrom;
0074   G4double xfn = 170 * angstrom;
0075   G4double yfn = 170 * angstrom;
0076   G4double zfn = 170 * angstrom;
0077 
0078   G4int nVertex = fVertexes.size();
0079 
0080   // Envelope
0081 
0082   std::string boxNameSolid = fGeoName + "_solid";
0083   G4Box* box_solid =
0084     new G4Box(boxNameSolid, 0.5 * (fXMax - fXMin) + 0.5 * 3.4 * nm,
0085               0.5 * (fYMax - fYMin) + 0.5 * 3.4 * nm, 0.5 * (fZMax - fZMin) + 0.5 * 3.4 * nm);
0086 
0087   G4String boxNameLogic = fGeoName + "_logic";
0088   G4LogicalVolume* box_logic =
0089     new G4LogicalVolume(box_solid, fEnvelopeWater, boxNameLogic, 0, 0, 0);
0090 
0091   // Desoxyribose
0092 
0093   G4Ellipsoid* RSolidSugar = new G4Ellipsoid("sdeoxyribose", PxRs, PyRs, PzRs, -PzRs, .445 * PzRs);
0094   G4LogicalVolume* RSugar = new G4LogicalVolume(RSolidSugar, fpWater, "ldeoxyribose", 0, 0, 0);
0095   G4VisAttributes* MyVisAtt_Rs = new G4VisAttributes(G4Colour(G4Colour::Red()));
0096   MyVisAtt_Rs->SetForceSolid(true);
0097   RSugar->SetVisAttributes(MyVisAtt_Rs);
0098 
0099   // Phosphoric Acid
0100 
0101   G4Ellipsoid* YSolidSugar = new G4Ellipsoid("sphosphate", PxYs, PyYs, PzYs, -PzYs, .9 * angstrom);
0102 
0103   G4LogicalVolume* YSugar = new G4LogicalVolume(YSolidSugar, fpWater, "lphosphate", 0, 0, 0);
0104   G4VisAttributes* MyVisAtt_Ys = new G4VisAttributes(G4Colour(G4Colour::Yellow()));
0105   MyVisAtt_Ys->SetForceSolid(true);
0106   YSugar->SetVisAttributes(MyVisAtt_Ys);
0107 
0108   // Base Pairs
0109 
0110   G4Ellipsoid* Base1a = new G4Ellipsoid("BasePair1a", PxBp, PyBp, PzBp, -PzBp, 1.15 * angstrom);
0111   G4LogicalVolume* BaseP1a = new G4LogicalVolume(Base1a, fpWater, "BasePair1a", 0, 0, 0);
0112   G4VisAttributes* MyVisAtt_Bp1a = new G4VisAttributes(G4Colour(G4Colour::Green()));
0113   MyVisAtt_Bp1a->SetForceSolid(true);
0114   BaseP1a->SetVisAttributes(MyVisAtt_Bp1a);
0115 
0116   G4Ellipsoid* Base1b = new G4Ellipsoid("BasePair1b", PxBp, PyBp, PzBp, 1.15 * angstrom, PzBp);
0117   G4LogicalVolume* BaseP1b = new G4LogicalVolume(Base1b, fpWater, "BasePair1b", 0, 0, 0);
0118 
0119   G4VisAttributes* MyVisAtt_Bp1b = new G4VisAttributes(G4Colour(G4Colour::Green()));
0120   MyVisAtt_Bp1b->SetForceSolid(true);
0121   BaseP1b->SetVisAttributes(MyVisAtt_Bp1b);
0122 
0123   G4int index = 0;
0124   G4double cAngle = 0;
0125   G4double pi = CLHEP::pi;
0126   for (int vertex = 0; vertex < nVertex - 1; vertex++) {
0127     xin = fVertexes[vertex][0] - fOffsetX;
0128     yin = fVertexes[vertex][1] - fOffsetY;
0129     zin = fVertexes[vertex][2] - fOffsetZ;
0130     xfn = fVertexes[vertex + 1][0] - fOffsetX;
0131     yfn = fVertexes[vertex + 1][1] - fOffsetY;
0132     zfn = fVertexes[vertex + 1][2] - fOffsetZ;
0133 
0134     G4double phi0 =
0135       std::atan2(zfn - zin, std::sqrt(((xfn - xin) * (xfn - xin)) + ((yfn - yin) * (yfn - yin))));
0136     G4double theta0 = std::atan2(xfn - xin, yfn - yin);
0137     G4double lenght = std::sqrt(((xfn - xin) * (xfn - xin)) + ((yfn - yin) * (yfn - yin))
0138                                 + ((zfn - zin) * (zfn - zin)));
0139     G4double dl = 1.0 / (lenght / (3.4 * angstrom));
0140     G4int nChain = (fVertexes[vertex] - fVertexes[vertex + 1]).mag() / (0.34 * nm);
0141 
0142     for (G4int nseg = 0; nseg < nChain; nseg++) {
0143       cAngle += ang;
0144 
0145       G4double theta = cAngle;
0146       G4double x1 = 0;
0147       G4double y1 = 0;
0148       G4double z1 = ((2 * PzBp) + PzRs + sep);
0149 
0150       G4double x2 = 0;
0151       G4double y2 = 0;
0152       G4double z2 = ((2 * PzBp) + PzRs + sep);
0153 
0154       G4ThreeVector plus2 = G4ThreeVector(0, 0, (.5 * PzRs) + PzYs);
0155       plus2.rotateX(-des1);
0156       plus2.rotateZ(-posi);
0157 
0158       G4ThreeVector plus2alt = G4ThreeVector(0, 0, (.5 * PzRs) + PzYs);
0159       plus2alt.rotateX(-des1);
0160       plus2alt.rotateZ(posi);
0161 
0162       G4double x3 = 0;
0163       G4double y3 = 0;
0164       G4double z3 = PzBp + sep;
0165 
0166       G4ThreeVector position1i = G4ThreeVector(x1, y1, z1);
0167       G4ThreeVector position2i = G4ThreeVector(x2, y2, z2) + plus2;
0168       G4ThreeVector position2ialt = G4ThreeVector(x2, y2, -z2) - plus2alt;
0169       G4ThreeVector position3i = G4ThreeVector(x3, y3, z3);
0170 
0171       position1i.rotateY(theta);
0172       position2i.rotateY(theta);
0173       position2ialt.rotateY(theta);
0174       position3i.rotateY(theta);
0175 
0176       G4double x = dl * nseg * (xfn - xin) + xin;
0177       G4double y = dl * nseg * (yfn - yin) + yin;
0178       G4double z = dl * nseg * (zfn - zin) + zin;
0179 
0180       position1i.rotateX(phi0);
0181       position2i.rotateX(phi0);
0182       position2ialt.rotateX(phi0);
0183       position3i.rotateX(phi0);
0184 
0185       position1i.rotateZ(-theta0);
0186       position2i.rotateZ(-theta0);
0187       position2ialt.rotateZ(-theta0);
0188       position3i.rotateZ(-theta0);
0189 
0190       G4double yrot1 = theta;
0191       G4double xrot1 = -des1;
0192       G4RotationMatrix rotm1 = G4RotationMatrix();
0193       rotm1.rotateX(xrot1);
0194       rotm1.rotateZ(-posi);
0195       rotm1.rotateY(yrot1);
0196       rotm1.rotateX(phi0);
0197       rotm1.rotateZ(-theta0);
0198       G4ThreeVector position1 = position1i + G4ThreeVector(x, y, z);
0199       G4Transform3D transform1(rotm1, position1);
0200 
0201       G4double yrot1alt = theta + pi;
0202       G4double xrot1alt = des1;
0203       G4RotationMatrix rotm1alt = G4RotationMatrix();
0204       rotm1alt.rotateX(xrot1alt);
0205       rotm1alt.rotateZ(-posi);
0206       rotm1alt.rotateY(yrot1alt);
0207       rotm1alt.rotateX(phi0);
0208       rotm1alt.rotateZ(-theta0);
0209       G4ThreeVector position1alt = -position1i + G4ThreeVector(x, y, z);
0210       G4Transform3D transform1alt(rotm1alt, position1alt);
0211 
0212       G4double yrot2 = theta;
0213       G4double xrot2 = -des2;
0214       G4RotationMatrix rotm2 = G4RotationMatrix();
0215       rotm2.rotateX(xrot2);
0216       rotm2.rotateY(yrot2 - bet1 + 0.8726646259971648);
0217       rotm2.rotateX(phi0);
0218       rotm2.rotateZ(-theta0);
0219       G4ThreeVector position2 = position2i + G4ThreeVector(x, y, z);
0220       G4Transform3D transform2(rotm2, position2);
0221 
0222       G4double yrot2alt = theta + pi;
0223       G4double xrot2alt = des2;
0224       G4RotationMatrix rotm2alt = G4RotationMatrix();
0225       rotm2alt.rotateX(xrot2alt);
0226       rotm2alt.rotateY(yrot2alt + bet1 - 0.8726646259971648);
0227       rotm2alt.rotateX(phi0);
0228       rotm2alt.rotateZ(-theta0);
0229       G4ThreeVector position2alt = position2ialt + G4ThreeVector(x, y, z);
0230       G4Transform3D transform2alt(rotm2alt, position2alt);
0231 
0232       G4double yrot3 = theta;
0233       G4RotationMatrix rotm3 = G4RotationMatrix();
0234       rotm3.rotateX(-pi / 2);
0235       rotm3.rotateZ(-ang);
0236       rotm3.rotateY(yrot3);
0237       rotm3.rotateX(phi0);
0238       rotm3.rotateZ(-theta0);
0239       G4ThreeVector position3 = position3i + G4ThreeVector(x, y, z);
0240       G4Transform3D transform3(rotm3, position3);
0241 
0242       G4double yrot3alt = theta + pi;
0243       G4RotationMatrix rotm3alt = G4RotationMatrix();
0244       rotm3alt.rotateX(pi / 2);
0245       rotm3alt.rotateZ(-ang);
0246       rotm3alt.rotateY(yrot3alt);
0247       rotm3alt.rotateX(phi0);
0248       rotm3alt.rotateZ(-theta0);
0249       G4ThreeVector position3alt = -position3i + G4ThreeVector(x, y, z);
0250       G4Transform3D transform3alt(rotm3alt, position3alt);
0251 
0252       new G4PVPlacement(transform1, RSugar, "deoxyribose1", box_logic, false, index, false);
0253 
0254       new G4PVPlacement(transform1alt, RSugar, "deoxyribose2", box_logic, false, index, false);
0255 
0256       new G4PVPlacement(transform3, BaseP1a, "BasePair1", box_logic, false, index, false);
0257 
0258       new G4PVPlacement(transform3alt, BaseP1a, "BasePair2", box_logic, false, index, false);
0259 
0260       new G4PVPlacement(transform2, YSugar, "phosphate1", box_logic, false, index, false);
0261 
0262       new G4PVPlacement(transform2alt, YSugar, "phosphate2", box_logic, false, index, false);
0263 
0264       G4ThreeVector Deoxy1 = position1;
0265       G4ThreeVector Deoxy2 = position1alt;
0266 
0267       fSampleDNAPositions.push_back(Deoxy1);
0268       fSampleDNAPositions.push_back(Deoxy2);
0269       fSampleDNANames.push_back("Deoxyribose");
0270       fSampleDNANames.push_back("Deoxyribose");
0271       fSampleDNADetails.push_back({-1, index, 1});
0272       fSampleDNADetails.push_back({-1, index, 2});
0273 
0274       index++;
0275     }
0276   }
0277 
0278   return box_logic;
0279 }
0280 
0281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0282 
0283 void PhysGeoImport::ReadFile(G4String fileName)
0284 {
0285   G4double x, y, z;
0286   fXMin = 1 * mm, fYMin = 1 * mm, fZMin = 1 * mm;
0287   fXMax = -1 * mm, fYMax = -1 * mm, fZMax = -1 * mm;
0288   std::ifstream plasmidFile(fileName);
0289   while (true) {
0290     plasmidFile >> x >> y >> z;
0291     if (!plasmidFile.good()) break;
0292     x *= nm;
0293     y *= nm;
0294     z *= nm;
0295     fVertexes.push_back(G4ThreeVector(x, y, z));
0296     if (fXMin > x) fXMin = x;
0297     if (fXMax < x) fXMax = x;
0298     if (fYMin > y) fYMin = y;
0299     if (fYMax < y) fYMax = y;
0300     if (fZMin > z) fZMin = z;
0301     if (fZMax < z) fZMax = z;
0302   }
0303   plasmidFile.close();
0304   fOffsetX = (fXMin + fXMax) * 0.5;
0305   fOffsetY = (fYMin + fYMax) * 0.5;
0306   fOffsetZ = (fZMin + fZMax) * 0.5;
0307 
0308   std::vector<G4ThreeVector> VertRed;
0309   for (size_t i = 0; i < fVertexes.size(); i++) {
0310     if (i % 15 == 0) VertRed.push_back(fVertexes[i]);
0311   }
0312 
0313   VertRed.push_back(fVertexes[0]);
0314 
0315   fVertexes = VertRed;
0316 }
0317 
0318 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....