Skip to content

Commit 7bf8434

Browse files
Material overhaul
1 parent cc660d8 commit 7bf8434

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1958
-337
lines changed

source/analysis/accumulables/pyG4AccumulableManager.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ void export_G4AccumulableManager(py::module &m)
2020
"__deepcopy__", [](const G4AccumulableManager &self, py::dict) { return new G4AccumulableManager(self); },
2121
py::return_value_policy::reference)
2222

23-
.def("Begin", &G4AccumulableManager::Begin)
24-
.def("BeginConst", &G4AccumulableManager::BeginConst)
25-
.def("End", &G4AccumulableManager::End)
26-
.def("EndConst", &G4AccumulableManager::EndConst)
2723
.def("GetAccumulable",
2824
py::overload_cast<const G4String &, G4bool>(&G4AccumulableManager::GetAccumulable<G4double>, py::const_),
2925
py::arg("name"), py::arg("warn") = true, py::return_value_policy::reference)
@@ -38,5 +34,8 @@ void export_G4AccumulableManager(py::module &m)
3834

3935
.def("Merge", &G4AccumulableManager::Merge, py::call_guard<py::gil_scoped_release>())
4036
.def("RegisterAccumulable", &G4AccumulableManager::RegisterAccumulable<G4double>, py::arg("accumulable"))
41-
.def("Reset", &G4AccumulableManager::Reset, py::call_guard<py::gil_scoped_release>());
37+
.def("Reset", &G4AccumulableManager::Reset, py::call_guard<py::gil_scoped_release>())
38+
.def(
39+
"__iter__", [](G4AccumulableManager &self) { return py::make_iterator(self.Begin(), self.End()); },
40+
py::is_operator());
4241
}

source/digits_hits/pyG4Scorer.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,8 @@ void export_G4Scorer(py::module &m)
120120
G4int nSeg[] = {z, phi, r};
121121
self.SetNumberOfSegments(nSeg);
122122
})
123-
.def("SetNumberOfSegments", [](G4PSCellFluxForCylinder3D &self, py::list list) {
124-
G4int nSeg[3];
125-
for (size_t i = 0; i < 3; i++) {
126-
nSeg[i] = list[i].cast<G4int>();
127-
}
128-
self.SetNumberOfSegments(nSeg);
123+
.def("SetNumberOfSegments", [](G4PSCellFluxForCylinder3D &self, std::array<G4int, 3>& nSeg) {
124+
self.SetNumberOfSegments(nSeg.data());
129125
});
130126

131127
py::class_<G4PSCylinderSurfaceCurrent, G4VPrimitivePlotter>(m, "G4PSCylinderSurfaceCurrent")

source/geant4_pybind.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <G4SolidStore.hh>
1515
#include <G4Material.hh>
1616
#include <G4RunManager.hh>
17+
#include <G4SurfaceProperty.hh>
1718

1819
#include <cstdlib>
1920
#include <vector>
@@ -43,6 +44,12 @@ class G4PyCoutDestination : public G4coutDestination {
4344
}
4445
};
4546

47+
class G4NullCoutDestination : public G4coutDestination {
48+
public:
49+
G4int ReceiveG4cout(const G4String &coutString) override { return 0; }
50+
G4int ReceiveG4cerr(const G4String &cerrString) override { return 0; }
51+
};
52+
4653
void export_modG4digit_hits(py::module &);
4754
void export_modG4event(py::module &);
4855
void export_modG4geometry(py::module &);
@@ -91,8 +98,14 @@ PYBIND11_MODULE(geant4_pybind, m)
9198
py::module_ atexit = py::module_::import("atexit");
9299
atexit.attr("register")(py::cpp_function([]() {
93100
py::gil_scoped_release gil_release;
101+
G4UImanager *UImgr = G4UImanager::GetUIpointer();
102+
UImgr->SetCoutDestination(0);
94103
delete G4RunManager::GetRunManager();
95104

105+
static G4NullCoutDestination nullcout = G4NullCoutDestination();
106+
G4coutbuf.SetDestination(&nullcout);
107+
G4cerrbuf.SetDestination(&nullcout);
108+
96109
// Delete everything before the interpreter shuts down to properly clean up python objects
97110
G4LogicalVolumeStore::Clean();
98111
G4LogicalVolume::Clean();
@@ -102,9 +115,7 @@ PYBIND11_MODULE(geant4_pybind, m)
102115
G4VPhysicalVolume::Clean();
103116
G4SolidStore::Clean();
104117
G4Material::GetMaterialTable()->clear();
105-
106-
G4UImanager *UImgr = G4UImanager::GetUIpointer();
107-
UImgr->SetCoutDestination(0);
118+
G4SurfaceProperty::CleanSurfacePropertyTable();
108119
}));
109120

110121
py::dict globals = py::module_::import("__main__").attr("__dict__");

source/geometry/management/pyG4RegionStore.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void export_G4RegionStore(py::module &m)
2222
.def("IsModified", &G4RegionStore::IsModified)
2323
.def("ResetRegionModified", &G4RegionStore::ResetRegionModified)
2424
.def("UpdateMaterialList", &G4RegionStore::UpdateMaterialList,
25-
py::arg("currentWorld") = static_cast<G4VPhysicalVolume *>(0))
25+
py::arg("currentWorld") = static_cast<G4VPhysicalVolume *>(nullptr))
2626

2727
.def("GetRegion", &G4RegionStore::GetRegion, py::arg("name"), py::arg("verbose") = true,
2828
py::return_value_policy::reference)

source/geometry/solids/Boolean/pyG4DisplacedSolid.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void export_G4DisplacedSolid(py::module &m)
155155
py::overload_cast<const G4ThreeVector &, const G4ThreeVector &, const G4bool, G4bool *, G4ThreeVector *>(
156156
&G4DisplacedSolid::DistanceToOut, py::const_),
157157
py::arg("p"), py::arg("v"), py::arg("calcNorm") = false, py::arg("validNorm") = static_cast<G4bool *>(0),
158-
py::arg("n") = static_cast<G4ThreeVector *>(0))
158+
py::arg("n") = static_cast<G4ThreeVector *>(nullptr))
159159

160160
.def("DistanceToOut", py::overload_cast<const G4ThreeVector &>(&G4DisplacedSolid::DistanceToOut, py::const_),
161161
py::arg("p"))

source/geometry/solids/Boolean/pyG4IntersectionSolid.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void export_G4IntersectionSolid(py::module &m)
158158
py::overload_cast<const G4ThreeVector &, const G4ThreeVector &, const G4bool, G4bool *, G4ThreeVector *>(
159159
&G4IntersectionSolid::DistanceToOut, py::const_),
160160
py::arg("p"), py::arg("v"), py::arg("calcNorm") = false, py::arg("validNorm") = static_cast<G4bool *>(0),
161-
py::arg("n") = static_cast<G4ThreeVector *>(0))
161+
py::arg("n") = static_cast<G4ThreeVector *>(nullptr))
162162

163163
.def("DistanceToOut", py::overload_cast<const G4ThreeVector &>(&G4IntersectionSolid::DistanceToOut, py::const_),
164164
py::arg("p"))

source/materials/pyG4AtomicBond.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
3+
4+
#include <G4AtomicBond.hh>
5+
6+
#include "typecast.hh"
7+
#include "opaques.hh"
8+
9+
namespace py = pybind11;
10+
11+
void export_G4AtomicBond(py::module &m)
12+
{
13+
py::class_<G4AtomicBond> mG4AtomicBond(m, "G4AtomicBond");
14+
15+
py::enum_<G4AtomicBond::theBondType>(mG4AtomicBond, "theBondType")
16+
.value("Ionic", G4AtomicBond::theBondType::Ionic)
17+
.value("Covalent", G4AtomicBond::theBondType::Covalent)
18+
.value("Metallic", G4AtomicBond::theBondType::Metallic)
19+
.value("NA", G4AtomicBond::theBondType::NA)
20+
.export_values();
21+
22+
mG4AtomicBond.def("__copy__", [](const G4AtomicBond &self) { return new G4AtomicBond(self); })
23+
.def("__deepcopy__", [](const G4AtomicBond &self, py::dict) { return new G4AtomicBond(self); })
24+
.def(py::init<G4AtomicBond::theBondType, G4Element *, G4int, G4Element *, G4int>(), py::arg("aType"),
25+
py::arg("firstAtomKind"), py::arg("firstAtomNumber"), py::arg("secondAtomKind"), py::arg("secondAtomNumber"))
26+
27+
.def("GetAromaticity", &G4AtomicBond::GetAromaticity)
28+
.def("GetFirstAtomKind", &G4AtomicBond::GetFirstAtomKind, py::return_value_policy::reference)
29+
.def("GetFirstAtomNumber", &G4AtomicBond::GetFirstAtomNumber)
30+
.def("GetSecondAtomKind", &G4AtomicBond::GetSecondAtomKind, py::return_value_policy::reference)
31+
.def("GetSecondAtomNumber", &G4AtomicBond::GetSecondAtomNumber)
32+
.def("GetType", &G4AtomicBond::GetType)
33+
.def("SetAromaticity", &G4AtomicBond::SetAromaticity, py::arg("aBool"))
34+
.def("SetFirstAtomKind", &G4AtomicBond::SetFirstAtomKind, py::arg("aElement"))
35+
.def("SetFirstAtomNumber", &G4AtomicBond::SetFirstAtomNumber, py::arg("aInt"))
36+
.def("SetSecondAtomKind", &G4AtomicBond::SetSecondAtomKind, py::arg("aElement"))
37+
.def("SetSecondAtomNumber", &G4AtomicBond::SetSecondAtomNumber, py::arg("aInt"))
38+
.def("SetType", &G4AtomicBond::SetType, py::arg("aType"));
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
3+
4+
#include <G4AtomicFormFactor.hh>
5+
6+
#include "typecast.hh"
7+
#include "opaques.hh"
8+
9+
namespace py = pybind11;
10+
11+
void export_G4AtomicFormFactor(py::module &m)
12+
{
13+
py::class_<G4AtomicFormFactor>(m, "G4AtomicFormFactor")
14+
15+
.def("__copy__", [](const G4AtomicFormFactor &self) { return new G4AtomicFormFactor(self); })
16+
.def("__deepcopy__", [](const G4AtomicFormFactor &self, py::dict) { return new G4AtomicFormFactor(self); })
17+
.def("Get", &G4AtomicFormFactor::Get, py::arg("kScatteringVector"), py::arg("Z"), py::arg("charge") = 0)
18+
.def_static("GetManager", &G4AtomicFormFactor::GetManager, py::return_value_policy::reference);
19+
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#include <pybind11/pybind11.h>
2-
#include <pybind11/stl.h>
3-
4-
#include <G4AtomicShells.hh>
5-
6-
#include "typecast.hh"
7-
#include "opaques.hh"
8-
9-
namespace py = pybind11;
10-
11-
void export_G4AtomicShells(py::module &m)
12-
{
13-
py::class_<G4AtomicShells>(m, "G4AtomicShells", "Atomic subshell binding energy table")
14-
15-
.def_static("GetNumberOfShells", &G4AtomicShells::GetNumberOfShells)
16-
.def_static("GetNumberOfElectrons", &G4AtomicShells::GetNumberOfElectrons)
17-
.def_static("GetNumberOfFreeElectrons", &G4AtomicShells::GetNumberOfFreeElectrons)
18-
.def_static("GetBindingEnergy", &G4AtomicShells::GetBindingEnergy)
19-
.def_static("GetTotalBindingEnergy", &G4AtomicShells::GetTotalBindingEnergy);
20-
}
1+
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
3+
4+
#include <G4AtomicShells.hh>
5+
6+
#include "typecast.hh"
7+
#include "opaques.hh"
8+
9+
namespace py = pybind11;
10+
11+
void export_G4AtomicShells(py::module &m)
12+
{
13+
py::class_<G4AtomicShells>(m, "G4AtomicShells")
14+
15+
.def_static("GetBindingEnergy", &G4AtomicShells::GetBindingEnergy, py::arg("Z"), py::arg("SubshellNb"))
16+
.def_static("GetNumberOfElectrons", &G4AtomicShells::GetNumberOfElectrons, py::arg("Z"), py::arg("SubshellNb"))
17+
.def_static("GetNumberOfFreeElectrons", &G4AtomicShells::GetNumberOfFreeElectrons, py::arg("Z"), py::arg("th"))
18+
.def_static("GetNumberOfShells", &G4AtomicShells::GetNumberOfShells, py::arg("Z"))
19+
.def_static("GetTotalBindingEnergy", &G4AtomicShells::GetTotalBindingEnergy, py::arg("Z"));
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
3+
4+
#include <G4AtomicShells_XDB_EADL.hh>
5+
6+
#include "typecast.hh"
7+
#include "opaques.hh"
8+
9+
namespace py = pybind11;
10+
11+
void export_G4AtomicShells_XDB_EADL(py::module &m)
12+
{
13+
py::class_<G4AtomicShells_XDB_EADL>(m, "G4AtomicShells_XDB_EADL")
14+
15+
.def_static("GetBindingEnergy", &G4AtomicShells_XDB_EADL::GetBindingEnergy, py::arg("Z"), py::arg("SubshellNb"))
16+
.def_static("GetNumberOfElectrons", &G4AtomicShells_XDB_EADL::GetNumberOfElectrons, py::arg("Z"),
17+
py::arg("SubshellNb"))
18+
.def_static("GetNumberOfFreeElectrons", &G4AtomicShells_XDB_EADL::GetNumberOfFreeElectrons, py::arg("Z"),
19+
py::arg("th"))
20+
.def_static("GetNumberOfShells", &G4AtomicShells_XDB_EADL::GetNumberOfShells, py::arg("Z"))
21+
.def_static("GetTotalBindingEnergy", &G4AtomicShells_XDB_EADL::GetTotalBindingEnergy, py::arg("Z"));
22+
}

0 commit comments

Comments
 (0)