Skip to content

Python code for rapid creation and conversion of radiation transport Monte Carlo (Geant4 and Fluka) geometries

License

Notifications You must be signed in to change notification settings

g4edge/pyg4ometry

Repository files navigation

pyg4ometry

Python code for rapid creation and conversion of radiation transport Monte Carlo (Geant4 and Fluka) geometries.

PyPI GitHub tag (latest by date) GitHub Workflow Status pre-commit Code style: black Codecov GitHub issues GitHub pull requests License DOI Read the Docs

Quick start

pyg4ometry is a very capable package to do many tasks related to Geant4/Fluka/MCNP geometry:

  • Python scripting to create and assemble geometries
  • Loading, editing and writing GDML
  • Load and tessellate CAD geometry and export to GDML
  • Load ROOT geometry and convert to GDML
  • Powerful VTK viewer of geometries
  • Converting from GDML to FLUKA and MCNP
  • Exporting mesh geometries from GDML to VTP, OBJ, VRML etc.
  • Python bindings to CGAL allowing complex mesh manipulation (e.g. hole filling, remeshing)

All with few lines of Python code!

import pyg4ometry as pg4
from g4edgetestdata import G4EdgeTestData

g4data = G4EdgeTestData()
# define a geometry registry
reg = pg4.geant4.Registry()

# build the world volume
world_s = pg4.geant4.solid.Orb("WorldAir", 1.5, reg, lunit="cm")
world_l = pg4.geant4.LogicalVolume(world_s, "G4_AIR", "WorldAir", reg)
reg.setWorld(world_l)

# import an STL file
reader = pg4.stl.Reader(g4data["stl/utah_teapot.stl"], registry=reg)
teapot_s = reader.getSolid()

# place the teapot in the world
teapot_l = pg4.geant4.LogicalVolume(teapot_s, "G4_Cu", "UtahTeapot", reg)
pg4.geant4.PhysicalVolume([0, 0, 0], [0, 0, 0], teapot_l, "UtahTeapot", world_l, reg)

# export to GDML file "geometry.gdml"
writer = pg4.gdml.Writer()
writer.addDetector(reg)
writer.write("./geometry.gdml")

# start an interactive VTK viewer instance
viewer = pg4.visualisation.VtkViewer()
viewer.addLogicalVolume(reg.getWorldVolume())
viewer.view()

Check out our video tutorial for more:

IMAGE ALT TEXT HERE

How to Install

Pre-built pyg4ometry wheels can be installed from PyPI using pip:

pip install pyg4ometry

If you cannot find wheels for your operating system / architecture, please open an issue. Building from source requires some non-Python software dependencies. More documentation can be found in the installation guide in the manual.

Many people and groups are using pyg4ometry

Referencing and Citation

To support the development and maintenance of pyg4ometry, please cite it! Any publications including simulations made using this software must cite the pyg4ometry paper:

S.D. Walker, A. Abramov, L.J. Nevay, W. Shields, S.T. Boogert, “pyg4ometry: A Python library for the creation of Monte Carlo radiation transport physical geometries”, Computer Physics Communications 272 108228 (2022). DOI: 10.1016/j.cpc.2021.108228

and the Zenodo release: DOI

Citation information can be also obtained on GitHub by selecting “Cite this repository” in the sidebar on the right.