Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work in progress on Geant4-DNA chemistry #364

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions core/opengate_core/g4_bindings/chemistryadaptator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* --------------------------------------------------
Copyright (C): OpenGATE Collaboration
This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
-------------------------------------------------- */

#ifndef chemistryadaptator_h
#define chemistryadaptator_h

#include <functional>

class G4DNAMolecularReactionTable;
#include <G4DNAMolecularReactionTable.hh>

template <typename C> class ChemistryAdaptator : public C {
public:
using ConstructReactionTableHook =
std::function<void(G4DNAMolecularReactionTable *)>;

public:
ChemistryAdaptator(int verbosity) {
C::SetVerboseLevel(verbosity);
_chemistryLists.push_back(this);
}

void
ConstructTimeStepModel(G4DNAMolecularReactionTable *reactionTable) override {
C::ConstructTimeStepModel(reactionTable);
reactionTable->PrintTable();
}

void
ConstructReactionTable(G4DNAMolecularReactionTable *reactionTable) override {
C::ConstructReactionTable(reactionTable);
if (_constructReactionTableHook)
_constructReactionTableHook(reactionTable);
}

static C *getChemistryList() {
for (auto *chemistryList : _chemistryLists) {
auto *ptr = dynamic_cast<C *>(chemistryList);
if (ptr != nullptr)
return ptr;
}
return nullptr;
}

template <typename T> static void setConstructReactionTableHook(T fn) {
_constructReactionTableHook = fn;
}

private:
inline static ConstructReactionTableHook _constructReactionTableHook;
inline static std::vector<G4VUserChemistryList *> _chemistryLists;
};

#endif
30 changes: 30 additions & 0 deletions core/opengate_core/g4_bindings/pyG4UserStackingAction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* --------------------------------------------------
Copyright (C): OpenGATE Collaboration
This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
-------------------------------------------------- */

#include <pybind11/pybind11.h>

namespace py = pybind11;

#include "G4UserStackingAction.hh"

class PyG4UserStackingAction : public G4UserStackingAction {
public:
/* Inherit the constructors */
using G4UserStackingAction::G4UserStackingAction;

void NewStage() override {
PYBIND11_OVERLOAD(void, G4UserStackingAction, NewStage);
}
};

void init_G4UserStackingAction(py::module &m) {

py::class_<G4UserStackingAction, PyG4UserStackingAction>(
m, "G4UserStackingAction")
.def(py::init())
.def("NewStage", &G4UserStackingAction::NewStage);
}
10 changes: 10 additions & 0 deletions core/opengate_core/g4_bindings/pyG4VUserActionInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace py = pybind11;
#include "G4SteppingVerbose.hh"
#include "G4UserEventAction.hh"
#include "G4UserRunAction.hh"
#include "G4UserStackingAction.hh"
#include "G4UserSteppingAction.hh"
#include "G4UserTrackingAction.hh"
#include "G4VUserActionInitialization.hh"
Expand Down Expand Up @@ -67,6 +68,11 @@ class PyG4VUserActionInitialization : public G4VUserActionInitialization {
G4VUserActionInitialization::SetUserAction(e);
}

void SetUserAction(G4UserStackingAction *e) {
// std::cout << "PyG4VUserActionInitialization::SetUserAction" << std::endl;
G4VUserActionInitialization::SetUserAction(e);
}

void SetUserAction(G4UserSteppingAction *e) {
// std::cout << "PyG4VUserActionInitialization::SetUserAction" << std::endl;
G4VUserActionInitialization::SetUserAction(e);
Expand Down Expand Up @@ -113,6 +119,10 @@ void init_G4VUserActionInitialization(py::module &m) {
(void(G4VUserActionInitialization::*)(G4UserTrackingAction *)) &
PyG4VUserActionInitialization::SetUserAction)

.def("SetUserAction",
(void(G4VUserActionInitialization::*)(G4UserStackingAction *)) &
PyG4VUserActionInitialization::SetUserAction)

.def("SetUserAction",
(void(G4VUserActionInitialization::*)(G4UserEventAction *)) &
PyG4VUserActionInitialization::SetUserAction)
Expand Down
36 changes: 36 additions & 0 deletions core/opengate_core/g4_bindings/pyPhysicsLists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
-------------------------------------------------- */
#include <G4VUserChemistryList.hh>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

Expand Down Expand Up @@ -41,6 +42,14 @@ namespace py = pybind11;
#include "G4EmStandardPhysics_option4.hh"

#include "G4EmDNAPhysics.hh"
#include "G4EmDNAPhysics_option1.hh"
#include "G4EmDNAPhysics_option2.hh"
#include "G4EmDNAPhysics_option3.hh"
#include "G4EmDNAPhysics_option4.hh"
#include "G4EmDNAPhysics_option5.hh"
#include "G4EmDNAPhysics_option6.hh"
#include "G4EmDNAPhysics_option7.hh"
#include "G4EmDNAPhysics_option8.hh"
#include "G4EmLivermorePhysics.hh"
#include "G4EmLivermorePolarizedPhysics.hh"
#include "G4EmLowEPPhysics.hh"
Expand All @@ -52,10 +61,17 @@ namespace py = pybind11;
#include "G4DecayPhysics.hh"
#include "G4RadioactiveDecayPhysics.hh"

#include "G4EmDNAChemistry.hh"
#include "G4EmDNAChemistry_option1.hh"
#include "G4EmDNAChemistry_option2.hh"
#include "G4EmDNAChemistry_option3.hh"

#include "G4VModularPhysicsList.hh"
#include "G4VPhysicsConstructor.hh"
#include "G4VUserPhysicsList.hh"

#include "chemistryadaptator.h"

// macro for adding physics lists: no parameter
// #define ADD_PHYSICS_LIST0(m, plname) \
// py::class_<plname, G4VModularPhysicsList>(m, #plname).def(py::init<>()); \
Expand All @@ -80,6 +96,13 @@ namespace py = pybind11;
std::unique_ptr<plname, py::nodelete>>(m, #plname) \
.def(py::init<G4int>());

// copied from ADD_PHYSICS_CONSTRUCTOR, adapted to chemistry
#define ADD_CHEMISTRY_CONSTRUCTOR(clname) \
py::class_<ChemistryAdaptator<clname>, G4VPhysicsConstructor, \
std::unique_ptr<ChemistryAdaptator<clname>, py::nodelete>>( \
m, #clname) \
.def(py::init<G4int>());

// FIXME ? A bit different for the biasing classe which do not take as argument
// a int. Moreover, we need at least the function PhysicsBias to put a bias, so
// this constructor needs probably its own function ?.
Expand Down Expand Up @@ -163,12 +186,25 @@ void init_G4PhysicsLists(py::module &m) {
ADD_PHYSICS_CONSTRUCTOR(G4EmLivermorePolarizedPhysics)
ADD_PHYSICS_CONSTRUCTOR(G4EmPenelopePhysics)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics_option1)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics_option2)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics_option3)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics_option4)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics_option5)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics_option6)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics_option7)
ADD_PHYSICS_CONSTRUCTOR(G4EmDNAPhysics_option8)
ADD_PHYSICS_CONSTRUCTOR(G4OpticalPhysics)
ADD_PHYSICS_CONSTRUCTOR_BIASING(G4GenericBiasingPhysics)

ADD_PHYSICS_CONSTRUCTOR(G4DecayPhysics)
ADD_PHYSICS_CONSTRUCTOR(G4RadioactiveDecayPhysics)

ADD_CHEMISTRY_CONSTRUCTOR(G4EmDNAChemistry)
ADD_CHEMISTRY_CONSTRUCTOR(G4EmDNAChemistry_option1)
ADD_CHEMISTRY_CONSTRUCTOR(G4EmDNAChemistry_option2)
ADD_CHEMISTRY_CONSTRUCTOR(G4EmDNAChemistry_option3)

// sort PL vector
std::sort(plList.begin(), plList.end());
}
12 changes: 12 additions & 0 deletions core/opengate_core/opengate_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void init_G4UserEventAction(py::module &);

void init_G4UserTrackingAction(py::module &);

void init_G4UserStackingAction(py::module &);

void init_G4UserSteppingAction(py::module &);

void init_G4Track(py::module &);
Expand Down Expand Up @@ -296,6 +298,10 @@ void init_GateFluenceActor(py::module &m);

void init_GateLETActor(py::module &m);

void init_GateChemistryActor(py::module &m);

void init_GateChemistryLongTimeActor(py::module &m);

void init_GateARFActor(py::module &m);

void init_GateARFTrainingDatasetActor(py::module &m);
Expand Down Expand Up @@ -332,6 +338,8 @@ void init_GateEventAction(py::module &);

void init_GateTrackingAction(py::module &);

void init_GateStackingAction(py::module &);

void init_GateSimulationStatisticsActor(py::module &);

void init_GatePhaseSpaceActor(py::module &);
Expand Down Expand Up @@ -426,6 +434,7 @@ PYBIND11_MODULE(opengate_core, m) {
init_G4PrimaryVertex(m);
init_G4UserEventAction(m);
init_G4UserTrackingAction(m);
init_G4UserStackingAction(m);
init_G4StepPoint(m);
init_G4Track(m);
init_G4Step(m);
Expand Down Expand Up @@ -553,9 +562,12 @@ PYBIND11_MODULE(opengate_core, m) {
init_GateRunAction(m);
init_GateEventAction(m);
init_GateTrackingAction(m);
init_GateStackingAction(m);
init_GateDoseActor(m);
init_GateFluenceActor(m);
init_GateLETActor(m);
init_GateChemistryActor(m);
init_GateChemistryLongTimeActor(m);
init_GateSimulationStatisticsActor(m);
init_GatePhaseSpaceActor(m);
// init_GateComptonSplittingActor(m);
Expand Down
Loading
Loading