Skip to main content

Alternative python bindings for Geant4 via pybind11

Project description

Python bindings for Geant4

Tests Wheel PyPI

Alternative Python bindings for Geant4 via pybind11. It is loosely based on g4py, but retains an API closer to the standard C++ API and does not require Boost.Python.

It currently includes all g4py bindings plus a large portion of very commonly used classes and functions that aren't currently present in g4py. However, it is still far off from replicating the full Geant4 API and is thus (currently) only applicable for simple simulations.

Installation

It's available on PyPI for all major platforms as a fully self-contained (i.e. statically linked) wheel.

pip install geant4-pybind

Building

Unix (Linux, OS X) prerequisits

Windows prerequisits

Note: If you haven't downloaded the required datasets yet don't worry, you can let geant4_pybind handle them.

Installation

git clone --recursive https://github.com/HaarigerHarald/geant4_pybind
pip install ./geant4_pybind

Windows notes

The above commands have to be executed in a "Developer Command Prompt for VS 2019" and require that Python3, pip and git are added to the PATH environment variable.

General notes

If the repository was cloned non-recursively you can check out the submodule with:

git -C ./geant4_pybind submodule update --init

Usage

Minimal

A minimal example that just starts a Geant4 shell:

from geant4_pybind import *
import sys

ui = G4UIExecutive(len(sys.argv), sys.argv)
ui.SessionStart()

Full examples

Check out the examples directory, which contains the Geant4 basic examples ported to Python. However, writing simulations in Python should be pretty straight forward as the API is almost identical to the C++ one. One notable exception are template classes, which have been renamed such that their type replaces the T (i.e. G4TScoreNtupleWriter<G4RootAnalysisManager> becomes G4RootScoreNtupleWriter).

Bugs?

Yes!

Though the bigger problem is probably that there is still quite a bit missing.

License

This builds upon Geant4 and g4py and thus the Geant4 license applies. The binding code uses pybind11. All my contributions are public domain.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

geant4_pybind-0.1.0b2-cp39-cp39-win_amd64.whl (11.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

geant4_pybind-0.1.0b2-cp39-cp39-manylinux2010_x86_64.whl (15.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

geant4_pybind-0.1.0b2-cp39-cp39-macosx_10_9_x86_64.whl (13.5 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

geant4_pybind-0.1.0b2-cp38-cp38-win_amd64.whl (11.3 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

geant4_pybind-0.1.0b2-cp38-cp38-manylinux2010_x86_64.whl (15.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

geant4_pybind-0.1.0b2-cp38-cp38-macosx_10_9_x86_64.whl (13.5 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

geant4_pybind-0.1.0b2-cp37-cp37m-win_amd64.whl (11.2 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

geant4_pybind-0.1.0b2-cp37-cp37m-manylinux2010_x86_64.whl (15.8 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

geant4_pybind-0.1.0b2-cp37-cp37m-macosx_10_9_x86_64.whl (13.4 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

geant4_pybind-0.1.0b2-cp36-cp36m-win_amd64.whl (11.2 MB view hashes)

Uploaded CPython 3.6m Windows x86-64

geant4_pybind-0.1.0b2-cp36-cp36m-manylinux2010_x86_64.whl (15.8 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

geant4_pybind-0.1.0b2-cp36-cp36m-macosx_10_9_x86_64.whl (13.4 MB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

geant4_pybind-0.1.0b2-cp35-cp35m-win_amd64.whl (11.2 MB view hashes)

Uploaded CPython 3.5m Windows x86-64

geant4_pybind-0.1.0b2-cp35-cp35m-manylinux2010_x86_64.whl (15.8 MB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

geant4_pybind-0.1.0b2-cp35-cp35m-macosx_10_9_x86_64.whl (13.4 MB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page