{"id":19105764,"url":"https://github.com/lobis/geant4-python-application","last_synced_at":"2025-04-30T16:29:47.767Z","repository":{"id":209764544,"uuid":"724433149","full_name":"lobis/geant4-python-application","owner":"lobis","description":"A Generic Geant4 Application with Python Bindings","archived":false,"fork":false,"pushed_at":"2025-04-28T17:46:05.000Z","size":1105,"stargazers_count":3,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-28T18:41:39.580Z","etag":null,"topics":["awkward-array","geant4","pybind11"],"latest_commit_sha":null,"homepage":"https://github.com/lobis/geant4-python-application","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lobis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-11-28T04:06:06.000Z","updated_at":"2024-10-29T20:38:16.000Z","dependencies_parsed_at":"2023-12-25T20:24:13.393Z","dependency_job_id":"e3bb0367-76b6-46c7-b4d0-182435748db2","html_url":"https://github.com/lobis/geant4-python-application","commit_stats":null,"previous_names":["lobis/geant4-pythonic-application"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lobis%2Fgeant4-python-application","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lobis%2Fgeant4-python-application/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lobis%2Fgeant4-python-application/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lobis%2Fgeant4-python-application/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lobis","download_url":"https://codeload.github.com/lobis/geant4-python-application/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251742122,"owners_count":21636389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["awkward-array","geant4","pybind11"],"created_at":"2024-11-09T04:01:26.045Z","updated_at":"2025-04-30T16:29:47.178Z","avatar_url":"https://github.com/lobis.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Geant4 Python Application\n\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/lobis/geant4-python-application/HEAD?labpath=attenuation.ipynb)\n[![Binder](https://binderhub.ssl-hep.org/badge_logo.svg)](https://binderhub.ssl-hep.org/v2/gh/lobis/geant4-python-application/HEAD?labpath=attenuation.ipynb)\n\n[![Wheels](https://github.com/lobis/geant4-python-application/actions/workflows/wheels.yaml/badge.svg)](https://github.com/lobis/geant4-python-application/actions/workflows/wheels.yaml)\n[![Build and Test](https://github.com/lobis/geant4-python-application/actions/workflows/build-test.yaml/badge.svg)](https://github.com/lobis/geant4-python-application/actions/workflows/test.yaml)\n\nThis is an experiment at providing a pythonic interface to Geant4.\n\nThe goal is not to provide a full python interface to Geant4, but rather to\nprovide a high-level interface to a generic Geant4 application which is highly\nconfigurable.\n\nIf you are looking for a full set of python bindings for Geant4, I recommend\nlooking at [geant4_pybind](https://github.com/HaarigerHarald/geant4_pybind).\n\n## Overview\n\n- Configurable Geant4 application written in C++\n- Python interface to the application via\n  [pybind11](https://github.com/pybind/pybind11)\n- The complete event data is available as an\n  [awkward array](https://github.com/scikit-hep/awkward)\n\n## Installation\n\nThe package is pip installable and should work on all major platforms. Geant4 is\nnot required to be installed on the system as the PyPI distribution includes a\nstatically linked version of Geant4.\n\nHowever, for the time being, it's recommended to install from the GitHub\nrepository to get the latest version, which makes Geant4 a necessary dependency.\n\nGeant4 is available on conda-forge and can be installed with:\n\n```bash\nconda install -c conda-forge geant4=11.2.2\n```\n\nThis project can then be installed via pip:\n\n```bash\npython -m pip install git+https://github.com/lobis/geant4-python-application\n```\n\nYou may need additional dependencies to perform the build. I found that these\nare usually enuough:\n\n```bash\nconda install cmake ninja gxx_linux-64\n```\n\nThe provided `Dockerfile` can be used for development purposes and as\ndocumentation on the required dependencies. To build the image run from the root\ndirectory:\n\n```bash\ndocker build -t geant4-python-application .\n```\n\nGeant4 can be installed using conda:\n\n```bash\nconda install -c conda-forge geant4\n```\n\nFor development purposes however, it's recommended to install Geant4 from source\nwith a similar configuration to the one used in the CI:\n\n```bash\ngit clone https://github.com/Geant4/geant4.git ./geant4-source --depth 1 --branch v11.2.2\n\ncmake -B ./geant4-build -S ./geant4-source -DCMAKE_INSTALL_PREFIX=./geant4-install -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DGEANT4_USE_GDML=ON -DGEANT4_INSTALL_EXAMPLES=OFF -DGEANT4_INSTALL_DATA=OFF -DGEANT4_BUILD_TLS_MODEL=global-dynamic -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -DGEANT4_USE_SYSTEM_EXPAT=OFF\ncmake --build ./geant4-build --parallel $(nproc) --config Release --target install\n```\n\nOne common installation issue is the dependency `xerces-c`. You may be able to\ninstall it from your package manager (e.g. `apt-get install libxerces-c-dev) but\nit's also possible to build it from source. In this case make sure the\ninstallation directory is accessible or just use the default system path.\n\n```bash\ngit clone https://github.com/apache/xerces-c.git ./xerces-source\ngit -C ./xerces-source checkout tags/v3.2.5\ncmake -B ./xerces-build -S ./xerces-source -DCMAKE_INSTALL_PREFIX=./xerces-install  -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -Dnetwork-accessor=socket -Dtranscoder=iconv\ncmake --build ./xerces-build --parallel $(nproc) --config Release --target install\n```\n\nAfter all dependencies are met, you should be able to install the package by\nrunning the following command from the root directory:\n\n```bash\npip install .\n```\n\n### Geant4 data files\n\nGeant4 comes with a large set of data files which are required in order to run.\nThe data files are the bulk of the Geant4 installation and can be quite large.\nThese data files are not included in the Python wheels for this package due to\nits size.\n\nThe python package automatically manages the download of the data files. To\ncheck the location of the data files, run the following command:\n\n```bash\npython -c \"import geant4_python_application; print(geant4_python_application.get_data_path())\"\n```\n\n**Uninstalling the package will not remove the data files. The user is\nresponsible for removing them manually.**\n\n#### Overriding the default data path\n\nThe default data path can be overridden by calling `application_directory`. This\nshould be done before the application is initialized.\n\n```python\nfrom geant4_python_application import application_directory\n\napplication_directory(\"/some/other/path\")\n```\n\nOverriding the default data directory is encouraged when submitting batch jobs\nto a cluster in order to avoid downloading the data files multiple times. In\nthis case the application directory should point to some shared location.\n\n#### Using a temporary directory\n\nA temporary directory can be used by calling:\n\n```python\nfrom geant4_python_application import application_directory\n\napplication_directory(temp=True)\n```\n\nThe operating system should take care of cleaning up the temporary directory.\n\nIt is possible that the operating system will delete only some of the files in\nthe temporary directory which can lead to a Geant4 runtime error. In this case\nit's recommended to delete the temporary directory manually and let the\napplication recreate it again.\n\n## Usage\n\n```python\nimport geant4_python_application as g4\n\n# Use a temporary directory for the Geant4 data files (remove this line to use the default location)\ng4.application_directory(temp=True)\n\nwith g4.Application(gdml=g4.basic_gdml, seed=137) as app:\n    events = app.run(n_events=100)\n\nprint(events)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flobis%2Fgeant4-python-application","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flobis%2Fgeant4-python-application","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flobis%2Fgeant4-python-application/lists"}