Python or C++ package to write gdml files

Hi everyone,

I have a basic and general question.

My geometry becomes a bit complex and have some parts that are just copy/paste (several PMTs for example). So I would like to use a package, for example in Python, that could write my gdml files, and from which I could implement the geometry details (dimensions…).
I feel such method could be more reliable and user friendly for later modifications, rather than digging in gdml files.

I found some nice packages doing that, but I would like to know what people from REST do use. ¿There is even maybe something integrated in REST?

Thanks for your feedback!

Hello @girardcarillo, thanks for the question!

Personally I use GitHub - SciProgCentre/gdml.kt: GDML bindings for kotlin-multiplatform, which was discussed in the IAXO software meetings ~ 2 years ago. Nowadays it doesn’t recieve updates and it looks like I am one of the few users, but it still serves it’s purpose. Its a Kotlin library though, which in my opinion is well suited for this type of work, since Kotlin is a modern typed language with very good support for DSL. However most people don’t know it (I didn’t either when I started using it for this purpose).

When I was looking for a python program at the time I didn’t find a satisfactory solution, but perhaps this is different now. I think a python solution would be a better alternative because of the more widespread usage.

Another topic that is very interesting is the translation between engineering designs (CAD, .step files) and GDML. As far as I am aware there is not a widespread solution, but it should be possible in theory. For example using a CAD program (even an open source one such as FreeCAD) you can export the .step into .stl which is straightforward to convert into GDML via the tesselation primitive. In theory you could even convert some of the bodies in the engineering design into other primitives such as tubes or boxes, but I have not idea how.

In conclusion I invite you to look into GitHub - SciProgCentre/gdml.kt: GDML bindings for kotlin-multiplatform but you can probably find some other python solution. If you find something satisfactory please let us know!

1 Like

Thanks for answering!

You would have told me Kotlin was in a language I know, and/or still actively maintained, I would have jumped on it haha. But thanks for sharing, I will consider this option.

What I found in a multi-purpose Python package called pyg4ometry. Last version v1.0.3 is from 08/2022 so I guess it’s still updated. It’s developed by people from Royal Holloway, London.
I’ve not installed it yet though, so I could not recommend it for the moment, but on the paper it seems complete.

If anyone else wants to share what tool they use, it could be useful :slight_smile:

I think pyg4ometry looks awesome! and it seems it has also ways to transform between different formats. That’s a good point. Perhaps @hgomez has also good experience creating geometries.

I am sure @hgomez can provide a more detailed answer but last time we spoke they were using a propietary software to convert CAD engineering designs into gdml. I don’t remember the name of this software but I remember it was not cheap. I am sure he can provide more details if you are interested.

Sorry for my late reply, I have been not available last weeks.

Convert CAO 3D-models (usually they must be in STEP format) to GDML is becoming more and more necessary in G4 due to the increasing complexity of the experimental setups. As @lobis mentioned in theory there exists several solutions to do that, but for my experience none of them assures you 100 % success.

For example when I tried to do conversions with FreeCAD almost every time I found errors in the transformations of some of the objects. In any case I think is worth trying it.

As @lobis mentioned the most reliable solution I found was using FastRAD software. The basic package allowing the STEP → GDML conversion costs ~3k Euros/year. Using it I managed to convert the geometry of a full nuclear reactor, but at the same time it made some errors converting simpler geometries. However, it is the most reliable tool I found (That’s true I’ve never tried pyg4geometry for example).

Regarding FastRAD, if i remember well you can obtain a free demo of 30 days allowing you to convert up to 20 volumes. It only works in Windows machines.

In more general way. If you are able to work with the engineers doing the CAO, they can try to apply some “good practices” which helps a lot in the later conversion, avoiding errors. Mainly:

  • Define the whole geometry using volumes, avoid surfaces (most of the errors I found are related to surface tessellation processes)

  • Save the CAO project directly in STEP format in the engineering software (AutoCAD, SolidEDGE, Catia…)

  • All the convertors I tried lose the material information in the conversion process, so this is not a critical point when designing.

I hope it helps