2.4 Verifying the Installation
Table of Contents
Importing `opengate`
Once installation is complete, the first check is to see whether Python can find the GATE package.
Open a terminal and start Python. If you created a virtual or Conda environment, make sure it is activated before starting Python. At the Python prompt, type:
import opengate as gateIf this command finishes without any output or error, Python has successfully imported OpenGATE.
If you see an error such as ModuleNotFoundError: No module named 'opengate', then Python is not seeing your installation. In that case, check that you installed OpenGATE in the environment you are using and that the environment is activated.
If you see errors that refer to Geant4 libraries or missing shared libraries, then OpenGATE is installed, but Geant4 or its environment variables are not correctly configured. Recheck your Geant4 installation and the setup scripts you need to source before running Python.
To verify that gate really is the OpenGATE package and not something else with the same name, you can inspect its location:
import opengate as gate
print(gate.__file__)The printed path should point to the directory where you expect OpenGATE to be installed.
You must always be able to run import opengate in the same environment where you plan to run simulations. If this import fails, no GATE simulation will run, and you must fix your installation or environment activation before proceeding.
Checking the GATE version
Knowing the installed version is important for following tutorials and documentation. Different versions can have different features or slightly different APIs.
After successfully importing OpenGATE, run:
import opengate as gate
print(gate.__version__)You should see a version string such as:
1.3.0or another number, depending on what is current on your system.
You can also query some basic build information:
print(gate.__dict__.get("Geant4_VERSION", "Unknown Geant4 version"))This helps confirm that OpenGATE is correctly connected to a Geant4 installation.
If gate.__version__ does not exist or returns an unexpected value, you may have installed an older snapshot or a development version. In that case, compare your version with the version mentioned in the course or in the official OpenGATE documentation and, if necessary, update your installation.
Always record the OpenGATE version and the Geant4 version used for a project. This information is essential for reproducible simulations, correct debugging, and for comparing your results with examples that use a specific version.
Running a simple example
A clean import and a version number confirm that Python can see OpenGATE, but they do not test that the full simulation chain works. The final verification step is to run a very small simulation.
Below is a minimal script that creates a world, adds a simple gamma source, and runs a short simulation. Save it as test_gate_install.py in a directory of your choice.
import opengate as gate
import opengate.contrib as contrib
from opengate.contrib import units
# create the simulation
sim = gate.Simulation()
# world
world = sim.world
world.size = [1 * units.m, 1 * units.m, 1 * units.m]
world.material = "G4_AIR"
# simple gamma source at the center
source = sim.add_source("src", "GenericSource")
source.particle = "gamma"
source.energy.mono = 511 * units.keV
source.position.type = "point"
source.position.translation = [0, 0, 0]
source.direction.type = "iso"
source.activity = 1e4 * units.Bq
# statistics actor to monitor the run
stats = sim.add_actor("SimulationStatisticsActor", "stats")
stats.track_types_flag = True
# set the simulation time
sim.run_timing_intervals = [1 * units.s]
# run the simulation
sim.run()
# print statistics summary
print(sim.get_actor("stats"))Run the script from the terminal in the environment where OpenGATE is installed:
python test_gate_install.py
During execution, you should see terminal output where Geant4 starts a run, processes events, and then stops. At the end, the SimulationStatisticsActor prints a summary. A typical summary might contain the number of events, number of tracks, and number of steps.
If the script runs to completion and prints statistics, your GATE installation, Geant4 backend, and Python bindings are working correctly.
If you see errors during sim.run(), the messages help you identify what is missing. Common problems include missing Geant4 data files, incorrectly set environment variables, or incompatible versions of OpenGATE and Geant4.
To finish the verification, confirm that no output files are unexpectedly created or that any small default files are written where you expect them. This assures you that file paths and basic configuration behave as intended.
A successful test simulation that runs sim.run() to completion and prints statistics is the most reliable confirmation that GATE is correctly installed and usable. Do not skip this step before starting more complex simulations.
Views: 10
KAHIBARO