Skip to content

Improve mac file for visualisation #1010

@dsarrut

Description

@dsarrut

This should work for any absolute/relative paths :
sim.visu_commands = gate.utility.read_mac_file_to_commands("my_visu_commands")


On Mon, Apr 27, 2026 at 5:24 PM David Grimbichler david.grimbichler@clermont.in2p3.fr wrote:
Hello,
Reading the source code, I think that your mac file my_visu_commands.mac should be in a "mac" subdirectory relative to your python script, and you should write only the base part of the filename :

sim.visu_commands = gate.utility.read_mac_file_to_commands("my_visu_commands")

Source code :

def read_mac_file_to_commands(filename):

def read_mac_file_to_commands(filename):
# read a file located into the 'mac' folder of the source code
# return a list of commands
resource_package = package
with resources.open_text(f"{resource_package}.mac", filename) as f:
...

Regards

De: "Machiel Kolstein" mkolstein@IFAE.ES
À: OPENGATE-L@IN2P3.FR
Envoyé: Lundi 27 Avril 2026 16:56:13
Objet: Re: [OPENGATE-L] GATE 10 vrml without trajectories

Hi,

I am sorry, something went wrong during copying/pasting. In any case, with the extra bar, the same thing happens:
ValueError: '/data/vip/common/machiel/GATE10_2026/2026_04_16_Derenzo/my_visu_commands.mac' must be only a file name

On Mon, Apr 27, 2026 at 4:38 PM Stiller, Wolfram, Dr. Wolfram.Stiller@med.uni-heidelberg.de wrote:
Hi Machiel,

Try adding another slash at the end of your folder pathname, i.e.

MYPATH = "/data/vip/common/machiel/GATE10_2026/2026_04_16_Derenzo/" instead of

MYPATH = "/data/vip/common/machiel/GATE10_2026/2026_04_16_Derenzo"

That might do the trick…

Best regards,

Wolf

171029Logo_UKHD_dt_positiv_RGB

PD Dr. Wolfram Stiller, Diplom-Physiker

Funktionsbereichsleiter „Physik & Methoden“ | Diagnostische & Interventionelle Radiologie (DIR)

Universitätsklinikum Heidelberg | Im Neuenheimer Feld 130.3 (Marsilius-Arkaden, Turm West) | 69120 Heidelberg

Tel. +49 6221 56-37240 / -6485 | Fax. +49 6221 56-6434 | E-Mail: wolfram.stiller@med.uni-heidelberg.de

http://www.klinikum.uni-heidelberg.de/radiodiagnostik

Kommunikation per E-Mail kann nicht als sicher oder fehlerfrei angesehen werden. Wir gehen davon aus, daß jeder, der mit uns per E-Mail kommuniziert, diese Risiken kennt und akzeptiert. Diese E-Mail kann vertrauliche und/oder rechtlich geschützte Informationen oder/und Unterlagen enthalten, die nur für den Adressaten dieser E-Mail bestimmt sind. Wenn Sie nicht der richtige Adressat sind oder Sie diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und löschen Sie diese E-Mail mitsamt etwaiger Anhänge sowie eventueller Sicherungskopien von Ihrem System. Das unerlaubte Kopieren, die Weitergabe sowie der unbefugte Gebrauch der in dieser E-Mail enthaltenen Informationen ist nicht gestattet.

Communication via e-mail can neither be considered to be secure nor to be error-free. We presume that anyone communicating with us via e-mail is aware of and accepts these risks. This e-mail may contain confidential and/or privileged information or documents solely intended for the addressee. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail including any attachments and backup copies from your system. Any unauthorized copying, disclosure, or distribution of the information in this e-mail or any taking of action in relation to its contents is strictly forbidden.

Von: GATE Users OPENGATE-L@IN2P3.FR Im Auftrag von Machiel Kolstein
Gesendet: Montag, 27. April 2026 10:37
An: OPENGATE-L@IN2P3.FR
Betreff: Re: [OPENGATE-L] GATE 10 vrml without trajectories

­

Hi David,

My code reads:
MYPATH = "/data/vip/common/machiel/GATE10_2026/2026_04_16_Derenzo"
myvisupath = MYPATH + "my_visu_commands.mac"
sim.visu_commands = gate.utility.read_mac_file_to_commands(myvisupath)

The complete error message is:

ValueError Traceback (most recent call last)
Cell In[4], line 14
12 myvisupath = MYPATH + "my_visu_commands.mac"
13 # myvisupath = "my_visu_commands.mac"
---> 14 sim.visu_commands = gate.utility.read_mac_file_to_commands(myvisupath)
15 sim.random_seed = 'auto'

File /data/vip/software/PYTHON_stuff/gate/lib/python3.12/site-packages/opengate/utility.py:383, in read_mac_file_to_commands(filename)
379 def read_mac_file_to_commands(filename):
380 # read a file located into the 'mac' folder of the source code
381 # return a list of commands
382 resource_package = package
--> 383 with resources.open_text(f"{resource_package}.mac", filename) as f:
384 c = f.read()
385 commands = []

File /data/astro/software/miniforge3/lib/python3.12/importlib/resources/_legacy.py:25, in deprecated..wrapper(*args, **kwargs)
16 @functools.wraps(func)
17 def wrapper(*args, **kwargs):
18 warnings.warn(
19 f"{func.name} is deprecated. Use files() instead. "
20 "Refer to https://importlib-resources.readthedocs.io"
(...) 23 stacklevel=2,
24 )
---> 25 return func(*args, **kwargs)

File /data/astro/software/miniforge3/lib/python3.12/importlib/resources/_legacy.py:62, in open_text(package, resource, encoding, errors)
54 @deprecated
55 def open_text(
56 package: Package,
(...) 59 errors: str = 'strict',
60 ) -> TextIO:
61 """Return a file-like object opened for text reading of the resource."""
---> 62 return (_common.files(package) / normalize_path(resource)).open(
63 'r', encoding=encoding, errors=errors
64 )

File /data/astro/software/miniforge3/lib/python3.12/importlib/resources/_legacy.py:38, in normalize_path(path)
36 parent, file_name = os.path.split(str_path)
37 if parent:
---> 38 raise ValueError(f'{path!r} must be only a file name')
39 return file_name

ValueError: '/data/vip/common/machiel/GATE10_2026/2026_04_16_Derenzomy_visu_commands.mac' must be only a file name

I don't know what you mean with "set an issue"? Is there a special place for Gate-10 to report problems?

Best regards,

Machiel Kolstein

On Mon, Apr 27, 2026 at 8:48 AM David Sarrut david.sarrut@creatis.insa-lyon.fr wrote:

Hi,

I tried and it seems the command accepts an absolute path or a path relative to where the default .mac files are (... opengate/opengate/mac), can you try or set an issue if it does not work please ?

best

David

On Fri, Apr 24, 2026 at 6:30 PM Machiel Kolstein mkolstein@ifae.es wrote:

Hi,

I tried that, but it seems that command doesn't accept paths before the filename, so the file should be located inside the opengate distribution itself. In any case, I found a different solution. I keep the default option, where trajectories are drawn too, but if I want a visualisation without trajectories, simply comment out the source creation. That works fine.

Thanks,

Machiel

On Thu, Apr 23, 2026 at 8:53 PM David Sarrut david.sarrut@creatis.insa-lyon.fr wrote:

Hi Machiel,

oups, good catch ! It should be something like :

sim.visu_commands = gate.utility.read_mac_file_to_commands("my_visu_commands.mac")

best

David

On Thu, Apr 16, 2026 at 11:27 AM Machiel Kolstein mkolstein@ifae.es wrote:

Hi,

By default in GATE10, the visualisation (at least with VRML) also shows the track trajectories. How can I switch this off?
Following the manual I tried:
file_visu = open('my_visu_commands.mac', "w")
print("/vis/open VRML2FILE", file=file_visu)
print("/vis/drawVolume", file=file_visu)
sim.visu_commands = gate.read_mac_file_to_commands('my_visu_commands.mac')
But it gives me an error:
AttributeError: module 'opengate' has no attribute 'read_mac_file_to_commands'

Of course, I can edit the mac file in the installation:
opengate/mac/default_visu_commands_vrml.mac
but I don't want to change that file every time I want to the change the visualisation. (Moreover that file is shared with other users).

Best regards,

Machiel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions