68 #include "CommandLineParser.hh"
72 using namespace G4DNAPARSER;
83 fNeuronFileNameSWC =
G4String(
"GranuleCell-Nr2.CNG.swc");
88 fNeuronFileNameDATA =
G4String(
"NeuralNETWORK.dat");
91 if((commandLine=CommandLineParser::GetParser()->GetCommandIfActive(
"-swc")))
94 SingleNeuronSWCfile(fNeuronFileNameSWC);
100 if ((commandLine =CommandLineParser::GetParser()->
101 GetCommandIfActive(
"-network")))
104 NeuralNetworkDATAfile(fNeuronFileNameDATA);
108 SingleNeuronSWCfile(fNeuronFileNameSWC);
131 std::ifstream infile;
132 infile.open(filename.c_str());
136 G4cout<<
"\n NeuronLoadDataFile::SingleNeuronSWCfile >> datafile "
137 <<filename<<
" not found !!!!"<<
G4endl;
144 G4cout<<
"\n NeuronLoadDataFile::SingleNeuronSWCfile >> opening filename: "
145 <<
"\n" <<
'\t'<<
'\t'<<
'\t'<<
'\t'<<
'\t'<<
"' "<<filename
151 while (getline(infile, sLine))
153 fnNn =
new G4int[nrows];
154 fpNn =
new G4int[nrows];
155 fnNd =
new G4int[nrows];
156 fpNd =
new G4int[nrows];
157 fnNa =
new G4int[nrows];
158 fpNa =
new G4int[nrows];
163 infile.open(filename.c_str());
166 fnbDendritecomp = 0 ;
169 G4double TotVolSoma, TotVolDend, TotVolAxon, TotVolSpine;
170 TotVolSoma=TotVolDend=TotVolAxon=TotVolSpine=0.;
171 G4double TotSurfSoma, TotSurfDend, TotSurfAxon, TotSurfSpine;
172 TotSurfSoma=TotSurfDend=TotSurfAxon=TotSurfSpine=0.;
181 minX=minY=minZ=1
e+09;
182 maxX=maxY=maxZ=-1
e+09;
186 fMassSomacomp =
new G4double[nrows];
192 fHeightDendcomp=
new G4double[nrows];
193 fMassDendcomp =
new G4double[nrows];
195 fDistADendSoma =
new G4double[nrows];
196 fDistBDendSoma =
new G4double[nrows];
201 fHeightAxoncomp=
new G4double[nrows];
202 fMassAxoncomp =
new G4double[nrows];
204 fDistAxonsoma =
new G4double[nrows];
207 fMassSpinecomp =
new G4double[nrows];
208 fMassSpineTot = 0.0 ;
210 fRadSpinecomp =
new G4double[nrows];
212 fRadNeuroncomp =
new G4double[nrows];
213 fHeightNeuroncomp =
new G4double[nrows];
214 fDistNeuronsoma =
new G4double[nrows];
218 fRadNeuroncomp =
new G4double[nrows];
219 fTypeN =
new G4int[nrows];
222 while (getline(infile, sLine))
224 std::istringstream form(sLine);
226 while (getline(form, token,
':'))
228 std::istringstream found(token);
229 while (found >> nNcomp >> typeNcomp >> x >> y >> z >> radius >> pNcomp)
234 if (minX > x) minX =
x;
235 if (minY > y) minY =
y;
236 if (minZ > z) minZ =
z;
237 if (maxX < x) maxX =
x;
238 if (maxY < y) maxY =
y;
239 if (maxZ < z) maxZ =
z;
241 if (maxRad < radius) maxRad =
radius;
248 G4double VolSomacomp = Piconst*pow(radius*
um,3.) ;
249 TotVolSoma = TotVolSoma + VolSomacomp;
250 G4double SurSomacomp = 3.*Piconst*pow(radius*um,2.) ;
251 TotSurfSoma = TotSurfSoma + SurSomacomp;
257 fMassSomacomp[fnbSomacomp] = density*VolSomacomp;
258 fMassSomaTot = fMassSomaTot + fMassSomacomp[fnbSomacomp];
260 fPosSomacomp [fnbSomacomp] = vSoma;
261 fRadSomacomp [fnbSomacomp]=
radius;
270 if (typeNcomp == 3 || typeNcomp == 4)
274 PosDendcomp [fnbDendritecomp] = vDend;
275 fRadDendcomp [fnbDendritecomp]=
radius;
276 fnNd[fnbDendritecomp]= nNcomp-(fnbSomacomp+fnbAxoncomp)-1;
277 fpNd[fnbDendritecomp]= pNcomp-(fnbSomacomp+fnbAxoncomp)-1;
282 G4double Dendxx= PosDendcomp[fnNd[fnbDendritecomp]].
x()+
283 PosDendcomp[fpNd[fnbDendritecomp]].
x();
284 G4double Dendyy= PosDendcomp[fnNd[fnbDendritecomp]].
y()+
285 PosDendcomp[fpNd[fnbDendritecomp]].
y();
286 G4double Dendzz= PosDendcomp[fnNd[fnbDendritecomp]].
z()+
287 PosDendcomp[fpNd[fnbDendritecomp]].
z();
289 Dendyy/2. , Dendzz/2.) ;
290 fPosDendcomp [fnbDendritecomp] = translmDend;
294 if (fpNd[fnbDendritecomp] == -fnbSomacomp)
296 Dendx= PosDendcomp[fnNd[fnbDendritecomp]].
x()-
297 (fPosSomacomp[0].x()+fRadSomacomp[0]);
298 Dendy= PosDendcomp[fnNd[fnbDendritecomp]].
y()-
299 (fPosSomacomp[0].y()+fRadSomacomp[0]);
300 Dendz= PosDendcomp[fnNd[fnbDendritecomp]].
z()-
301 (fPosSomacomp[0].z()+fRadSomacomp[0]);
305 Dendx= PosDendcomp[fnNd[fnbDendritecomp]].
x()-
306 PosDendcomp[fpNd[fnbDendritecomp]].
x();
307 Dendy= PosDendcomp[fnNd[fnbDendritecomp]].
y()-
308 PosDendcomp[fpNd[fnbDendritecomp]].
y();
309 Dendz= PosDendcomp[fnNd[fnbDendritecomp]].
z()-
310 PosDendcomp[fpNd[fnbDendritecomp]].
z();
312 G4double lengthDendcomp = std::sqrt(Dendx*Dendx+Dendy*Dendy+Dendz*Dendz);
314 fHeightDendcomp [fnbDendritecomp]= lengthDendcomp;
317 G4double DendDisx= fPosSomacomp[0].x()-
318 fPosDendcomp [fnbDendritecomp].x();
319 G4double DendDisy= fPosSomacomp[0].y()-
320 fPosDendcomp [fnbDendritecomp].y();
321 G4double DendDisz= fPosSomacomp[0].z()-
322 fPosDendcomp [fnbDendritecomp].z();
323 if (typeNcomp == 3) fDistADendSoma[fnbDendritecomp] =
324 std::sqrt(DendDisx*DendDisx + DendDisy*DendDisy + DendDisz*DendDisz);
325 if (typeNcomp == 4) fDistBDendSoma[fnbDendritecomp] =
326 std::sqrt(DendDisx*DendDisx + DendDisy*DendDisy + DendDisz*DendDisz);
330 TotVolDend = TotVolDend + VolDendcomp;
331 G4double SurDendcomp = 2.*
pi*radius*um*(radius+lengthDendcomp)*um;
332 TotSurfDend = TotSurfDend + SurDendcomp;
333 fMassDendcomp[fnbDendritecomp] = density*VolDendcomp;
334 fMassDendTot = fMassDendTot + fMassDendcomp[fnbDendritecomp];
336 Dendx=Dendx/lengthDendcomp;
337 Dendy=Dendy/lengthDendcomp;
338 Dendz=Dendz/lengthDendcomp;
374 fRotDendcomp [fnbDendritecomp]= rotmDend ;
385 PosAxoncomp [fnbAxoncomp] = vAxon;
386 fRadAxoncomp [fnbAxoncomp]=
radius;
387 fnNa[fnbAxoncomp]= nNcomp-(fnbSomacomp+fnbDendritecomp)-1;
388 fpNa[fnbAxoncomp]= pNcomp-(fnbSomacomp+fnbDendritecomp)-1;
393 G4double Axonxx= PosAxoncomp[fnNa[fnbAxoncomp]].
x()+
394 PosAxoncomp[fpNa[fnbAxoncomp]].
x();
395 G4double Axonyy= PosAxoncomp[fnNa[fnbAxoncomp]].
y()+
396 PosAxoncomp[fpNa[fnbAxoncomp]].
y();
397 G4double Axonzz= PosAxoncomp[fnNa[fnbAxoncomp]].
z()+
398 PosAxoncomp[fpNa[fnbAxoncomp]].
z();
400 Axonyy/2. , Axonzz/2.) ;
401 fPosAxoncomp [fnbAxoncomp] = translmAxon;
405 if (fpNa[fnbAxoncomp] == -(fnbSomacomp+fnbDendritecomp))
407 Axonx= PosAxoncomp[fnNa[fnbAxoncomp]].
x()-
408 (fPosSomacomp[0].x()+fRadSomacomp[0]);
409 Axony= PosAxoncomp[fnNa[fnbAxoncomp]].
y()-
410 (fPosSomacomp[0].y()+fRadSomacomp[0]);
411 Axonz= PosAxoncomp[fnNa[fnbAxoncomp]].
z()-
412 (fPosSomacomp[0].z()+fRadSomacomp[0]);
416 Axonx= PosAxoncomp[fnNa[fnbAxoncomp]].
x()-
417 PosAxoncomp[fpNa[fnbAxoncomp]].
x();
418 Axony= PosAxoncomp[fnNa[fnbAxoncomp]].
y()-
419 PosAxoncomp[fpNa[fnbAxoncomp]].
y();
420 Axonz= PosAxoncomp[fnNa[fnbAxoncomp]].
z()-
421 PosAxoncomp[fpNa[fnbAxoncomp]].
z();
423 G4double lengthAxoncomp = std::sqrt(Axonx*Axonx+Axony*Axony+Axonz*Axonz);
425 fHeightAxoncomp [fnbAxoncomp]= lengthAxoncomp;
428 G4double AxonDisx= fPosSomacomp[0].x()-
429 fPosAxoncomp [fnbAxoncomp].x();
430 G4double AxonDisy= fPosSomacomp[0].y()-
431 fPosAxoncomp [fnbAxoncomp].y();
432 G4double AxonDisz= fPosSomacomp[0].z()-
433 fPosAxoncomp [fnbAxoncomp].z();
434 fDistAxonsoma[fnbAxoncomp] = std::sqrt(AxonDisx*AxonDisx +
435 AxonDisy*AxonDisy + AxonDisz*AxonDisz);
439 TotVolAxon = TotVolAxon + VolAxoncomp;
440 G4double SurAxoncomp = 2.*
pi*radius*um*(radius+lengthAxoncomp)*um;
441 TotSurfAxon = TotSurfAxon + SurAxoncomp;
442 fMassAxoncomp[fnbAxoncomp] = density*VolAxoncomp;
443 fMassAxonTot = fMassAxonTot + fMassAxoncomp[fnbAxoncomp];
444 Axonx=Axonx/lengthAxoncomp;
445 Axony=Axony/lengthAxoncomp;
446 Axonz=Axonz/lengthAxoncomp;
460 fRotAxoncomp [fnbAxoncomp]= rotmAxon ;
466 if (typeNcomp != 1 && typeNcomp != 2 && typeNcomp != 3 && typeNcomp != 4)
468 G4cout <<
" Additional types:--> "<< typeNcomp <<
G4endl;
478 G4double VolSpinecomp = Piconst*pow(radius*
um,3.) ;
479 TotVolSpine = TotVolSpine + VolSpinecomp;
480 G4double SurSpinecomp = 3.*Piconst*pow(radius*um,2.) ;
481 TotSurfSpine = TotSurfSpine + SurSpinecomp;
482 fMassSpinecomp[fnbSpinecomp] = density*VolSpinecomp;
483 fMassSpineTot = fMassSpineTot + fMassSpinecomp[fnbSpinecomp];
488 fPosSpinecomp [fnbSpinecomp] = vSpine;
489 fRadSpinecomp [fnbSpinecomp] =
radius;
499 fTypeN[
nlines] = typeNcomp;
502 PosNeuroncomp [
nlines] = vNeuron;
511 PosNeuroncomp[fpNn[
nlines]].
x();
513 PosNeuroncomp[fpNn[
nlines]].
y();
515 PosNeuroncomp[fpNn[
nlines]].
z();
517 Neuronyy/2. , Neuronzz/2.) ;
518 fPosNeuroncomp [
nlines] = translmNeuron;
522 if (fpNn[nlines] == -2)
524 Neuronx= PosNeuroncomp[fnNn[
nlines]].
x()-
525 fPosNeuroncomp[0].x();
526 Neurony= PosNeuroncomp[fnNn[
nlines]].
y()-
527 fPosNeuroncomp[0].y();
528 Neuronz= PosNeuroncomp[fnNn[
nlines]].
z()-
529 fPosNeuroncomp[0].z();
533 Neuronx= PosNeuroncomp[fnNn[
nlines]].
x()-
534 PosNeuroncomp[fpNn[
nlines]].
x();
535 Neurony= PosNeuroncomp[fnNn[
nlines]].
y()-
536 PosNeuroncomp[fpNn[
nlines]].
y();
537 Neuronz= PosNeuroncomp[fnNn[
nlines]].
z()-
538 PosNeuroncomp[fpNn[
nlines]].
z();
540 G4double lengthNeuroncomp = std::sqrt(Neuronx*Neuronx+
541 Neurony*Neurony+Neuronz*Neuronz);
543 fHeightNeuroncomp [
nlines]= lengthNeuroncomp;
545 G4double NeuronDisx= fPosNeuroncomp[0].x()-
546 fPosNeuroncomp [
nlines].x();
547 G4double NeuronDisy= fPosNeuroncomp[0].y()-
548 fPosNeuroncomp [
nlines].y();
549 G4double NeuronDisz= fPosNeuroncomp[0].z()-
550 fPosNeuroncomp [
nlines].z();
551 fDistNeuronsoma[
nlines] = std::sqrt(NeuronDisx*NeuronDisx +
552 NeuronDisy*NeuronDisy + NeuronDisz*NeuronDisz);
562 Neuronx=Neuronx/lengthNeuroncomp;
563 Neurony=Neurony/lengthNeuroncomp;
564 Neuronz=Neuronz/lengthNeuroncomp;
574 phi_eulerNeuron+
pi/2,
578 fRotNeuroncomp [
nlines]= rotmNeuron ;
588 G4cout <<
" Total number of compartments into Neuron : "
593 fshiftX = (minX + maxX)/2. ;
594 fshiftY = (minY +
maxY)/2. ;
595 fshiftZ = (minZ +
maxZ)/2. ;
599 fwidthB = std::fabs(minX - maxX) + maxRad;
600 fheightB = std::fabs(minY - maxY) + maxRad;
601 fdepthB = std::fabs(minZ - maxZ) + maxRad;
605 fdiagnlLength = std::sqrt(fwidthB*fwidthB + fheightB*fheightB
608 fTotVolNeuron = TotVolSoma+TotVolDend+TotVolAxon;
609 fTotSurfNeuron = TotSurfSoma+TotSurfDend+TotSurfAxon;
610 fTotMassNeuron = fMassSomaTot+fMassDendTot+fMassAxonTot;
612 fTotVolSlice = fwidthB*
um*fheightB*
um*fdepthB*
um;
613 fTotSurfSlice = 2*(fwidthB*um*fheightB*um+fheightB*um*fdepthB*um+
614 fwidthB*um*fdepthB*
um);
615 fTotMassSlice = 1.0 * (
g/
cm3) *fTotVolSlice;
617 fTotVolMedium = Piconst*pow(fdiagnlLength*um/2.,3.) ;
618 fTotSurfMedium = 3.*Piconst*pow(fdiagnlLength*um/2.,2);
619 fTotMassMedium = 1.0 * (
g/
cm3) *fTotVolMedium;
624 fSomaColour->SetForceSolid(
true);
625 fSomaColour->SetVisibility(
true);
630 fDendColour->SetForceSolid(
true);
636 fAxonColour->SetForceSolid(
true);
637 fAxonColour->SetVisibility(
true);
642 fSpineColour->SetForceSolid(
true);
643 fSpineColour->SetVisibility(
true);
648 fNeuronColour->SetForceSolid(
true);
649 fNeuronColour->SetVisibility(
true);
663 std::ifstream infile;
664 infile.open(filename.c_str());
668 G4cout<<
" \n NeuronLoadDataFile::NeuralNetworkDATAfile >> datafile "
669 <<filename<<
" not found !!!!"<<
G4endl;
676 G4cout<<
" NeuronLoadDataFile::NeuralNetworkDATAfile >> opening filename: "
677 <<
"\n" <<
'\t'<<
'\t'<<
'\t'<<
'\t'<<
'\t'<<
"' "<<filename
684 fnbDendritecomp = 0 ;
687 G4double TotVolSoma, TotVolDend, TotVolAxon;
688 TotVolSoma=TotVolDend=TotVolAxon=0.;
689 G4double TotSurfSoma, TotSurfDend, TotSurfAxon;
690 TotSurfSoma=TotSurfDend=TotSurfAxon=0.;
704 while (getline(infile, sLine))
706 std::istringstream form(sLine);
709 form >> fnbNeuroncomp >> nbSoma >> nbDendrite ;
710 fMassSomacomp =
new G4double[nbSoma];
713 fRadSomacomp =
new G4double[nbSoma];
714 fRadDendcomp =
new G4double[nbDendrite];
715 fHeightDendcomp =
new G4double[nbDendrite];
716 fMassDendcomp =
new G4double[nbDendrite];
718 fDistADendSoma =
new G4double[nbDendrite];
719 fDistBDendSoma =
new G4double[nbDendrite];
725 if (nlines > 0 && nlines <= nbSoma)
727 form >> typeNcomp >> x1 >> y1 >> z1 >>
radius ;
728 if (typeNcomp !=1)
break;
730 if (maxRad < radius) maxRad =
radius;
732 G4double VolSomacomp = Piconst*pow(radius*
um,3.) ;
733 TotVolSoma = TotVolSoma + VolSomacomp;
734 G4double SurSomacomp = 3.*Piconst*pow(radius*um,2.) ;
735 TotSurfSoma = TotSurfSoma + SurSomacomp;
736 fMassSomacomp[fnbSomacomp] = density*VolSomacomp;
737 fMassSomaTot = fMassSomaTot + fMassSomacomp[fnbSomacomp];
745 fPosSomacomp [fnbSomacomp] = vSoma;
746 fRadSomacomp [fnbSomacomp]=
radius;
754 if (nlines > nbSoma && nlines <= fnbNeuroncomp)
756 form >> typeNcomp >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> radius >> height;
757 if (typeNcomp != 3 )
break;
765 Dendyy/2. , Dendzz/2.) ;
766 fPosDendcomp [fnbDendritecomp] = translmDend;
767 fRadDendcomp [fnbDendritecomp]=
radius;
770 fHeightDendcomp [fnbDendritecomp]= lengthDendcomp;
775 TotVolDend = TotVolDend + VolDendcomp;
776 G4double SurDendcomp = 2.*
pi*radius*um*(radius+lengthDendcomp)*um;
777 TotSurfDend = TotSurfDend + SurDendcomp;
778 fMassDendcomp[fnbDendritecomp] = density*VolDendcomp;
779 fMassDendTot = fMassDendTot + fMassDendcomp[fnbDendritecomp];
784 Dendx=Dendx/lengthDendcomp;
785 Dendy=Dendy/lengthDendcomp;
786 Dendz=Dendz/lengthDendcomp;
801 fRotDendcomp [fnbDendritecomp]= rotmDend ;
813 G4cout <<
" Total number of compartments into Neuron : "<<
829 fdiagnlLength = std::sqrt(fwidthB*fwidthB + fheightB*fheightB
832 fTotVolNeuron = TotVolSoma+TotVolDend+TotVolAxon;
833 fTotSurfNeuron = TotSurfSoma+TotSurfDend+TotSurfAxon;
834 fTotMassNeuron = fMassSomaTot+fMassDendTot+fMassAxonTot;
836 fTotVolSlice = fwidthB*
um*fheightB*
um*fdepthB*
um;
837 fTotSurfSlice = 2*(fwidthB*um*fheightB*um+fheightB*um*fdepthB*um+
838 fwidthB*um*fdepthB*
um);
839 fTotMassSlice = 1.0 * (
g/
cm3) *fTotVolSlice;
841 fTotVolMedium = Piconst*pow(fdiagnlLength*um/2.,3.) ;
842 fTotSurfMedium = 3.*Piconst*pow(fdiagnlLength*um/2.,2);
843 fTotMassMedium = 1.0 * (
g/
cm3) *fTotVolMedium;
853 delete[] fMassSomacomp ;
854 delete[] fPosSomacomp ;
855 delete[] fRadSomacomp ;
856 delete[] fRadDendcomp ;
857 delete[] fHeightDendcomp;
858 delete[] fMassDendcomp ;
859 delete[] fDistADendSoma ;
860 delete[] fDistBDendSoma ;
861 delete[] fPosDendcomp ;
862 delete[] fRotDendcomp ;
863 delete[] fRadAxoncomp ;
864 delete[] fHeightAxoncomp;
865 delete[] fMassAxoncomp ;
866 delete[] fDistAxonsoma ;
867 delete[] fPosAxoncomp ;
868 delete[] fRotAxoncomp ;
869 delete[] fRadNeuroncomp ;
870 delete[] fHeightNeuroncomp;
871 delete[] fMassNeuroncomp ;
872 delete[] fDistNeuronsoma ;
873 delete[] fPosNeuroncomp ;
874 delete[] fRotNeuroncomp ;
899 G4double cosX = std::sqrt (rotmNeuron.
xx()*rotmNeuron.
xx() +
900 rotmNeuron.
yx()*rotmNeuron.
yx()) ;
904 euX = std::atan2 (rotmNeuron.
zy(),rotmNeuron.
zz());
905 euY = std::atan2 (-rotmNeuron.
zx(),cosX);
906 euZ = std::atan2 (rotmNeuron.
yx(),rotmNeuron.
xx());
910 euX = std::atan2 (-rotmNeuron.
yz(),rotmNeuron.
yy());
911 euY = std::atan2 (-rotmNeuron.
zx(),cosX);
924 (fPosNeuroncomp[copyNo].
x()-fshiftX) *
um,
925 (fPosNeuroncomp[copyNo].
y()-fshiftY) * um,
926 (fPosNeuroncomp[copyNo].
z()-fshiftZ) * um