# Geometry xml file fail

**URL:** <https://openmc.discourse.group/t/geometry-xml-file-fail/4174>\
**Category:** User Support\
**Created:** [April 18, 2024, 9:18am UTC](https://openmc.discourse.group/t/geometry-xml-file-fail/4174 "2024-04-18T09:18:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gglamzn](https://avatars.discourse-cdn.com/v4/letter/g/e19adc/32.png) [@gglamzn](https://openmc.discourse.group/u/gglamzn)\
**Post date:** [April 18, 2024, 9:18am UTC](https://openmc.discourse.group/t/geometry-xml-file-fail/4174/1 "2024-04-18T09:18:22Z")

</div>

Hi ,

I want to undergo OPENMC simulations from .step files such as Catia.

First I did a fuction in order to convert my .step file , using cad\_to\_dagmc

The code:

#Libraries  
import cadquery as cq  
from cad\_to\_dagmc import CadToDagmc  
import os  
import openmc

def step\_to\_openmc\_h5m(input\_step\_file\_path: str, output\_file\_name: str, output\_dir: str) → str:  
“”"Converts a STEP file to a DAGMC h5m file usable for simulations on OpenMC.

```auto
Args:
    input_step_file_path (str): The path to the input STEP file.
    output_file_name (str): The desired name of the output h5m file.
    output_dir (str): The directory where the output h5m file will be saved.

Returns:
    str: The path to the generated h5m file.
"""
try:
    
    converter = CadToDagmc()# Initialize CadToDagmc instance

    # Add the STEP file to the converter
    converter.add_stp_file(input_step_file_path,material_tags=["mat_air"]) #fill the geometry with a defined material

    # Generate the output h5m file path
    output_h5m_file_path = os.path.join(output_dir, output_file_name)

    # Export the DAGMC h5m file
    converter.export_dagmc_h5m_file(filename=output_h5m_file_path)

    return output_h5m_file_path
except Exception as e:
    print(f"Error occurred while converting the STEP file: {e}")
    return ""

```

I tried with a basic .step file and It’s successfull

Then i want to do a simple simulation but first I have to get my xml file with all the parameters :

def create\_simulation\_file(h5m\_file\_path,output\_directory):

```
# Define the number of particles
n_particles = 1000

# Create settings for neutron simulation
my_neutron_settings = openmc.Settings()
my_neutron_settings.run_mode = "fixed source"
my_neutron_settings.particles = n_particles
my_neutron_settings.batches = 10
my_neutron_settings.photon_transport = False

# Create a neutron source
my_source = openmc.IndependentSource()
my_source.space = openmc.stats.Point((0, 0, 0))
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14.06e6], [1])
my_source.particle = "neutron"

# Assign the source to settings
my_neutron_settings.source = my_source

# Create tallies for neutron flux
tally = openmc.Tally()
tally.scores = ['flux']
tallies = openmc.Tallies([tally])

# Create materials
mat_air = openmc.Material(name="Air")
mat_air.add_element("N", 0.784431)
mat_air.add_element("O", 0.210748)
mat_air.add_element("Ar", 0.0046)
mat_air.set_density("g/cc", 0.001205)
materials = openmc.Materials([mat_air])

# Create geometry with h5m file
geometry = openmc.Geometry()
geometry.file = h5m_file_path

# Create an OpenMC Model
model = openmc.model.Model(geometry=geometry, 
                   materials=materials, 
                   settings=my_neutron_settings, 
                   tallies=tallies)

model.export_to_model_xml(output_directory)

```

this xml file is aimed to umdergo the simulation in an another function.

I unfortunately get this error , compiling create\_simulation\_file :

AttributeError Traceback (most recent call last)  
Cell In[15], line 50  
48 # Export the model to XML  
49 output\_directory =“/home/gauthier/Stage/Catia/”  
—\> 50 model.export\_to\_model\_xml(output\_directory)

File ~/miniforge3/envs/openmc-env/lib/python3.12/site-packages/openmc/model/model.py:506, in Model.export\_to\_model\_xml(self, path, remove\_surfs)  
504 mesh\_memo = set()  
505 settings\_element = self.settings.to\_xml\_element(mesh\_memo)  
→ 506 geometry\_element = self.geometry.to\_xml\_element()  
508 xml.clean\_indentation(geometry\_element, level=1)  
509 xml.clean\_indentation(settings\_element, level=1)

File ~/miniforge3/envs/openmc-env/lib/python3.12/site-packages/openmc/geometry.py:137, in Geometry.to\_xml\_element(self, remove\_surfs)  
135 # Create XML representation  
136 element = ET.Element(“geometry”)  
→ 137 self.root\_universe.create\_xml\_subelement(element, memo=set())  
139 # Sort the elements in the file  
140 element[:] = sorted(element, key=lambda x: (  
141 x.tag, int(x.get(‘id’))))

AttributeError: ‘NoneType’ object has no attribute ‘create\_xml\_subelement’

and I dont really know how to fix it.  
Does somebody knows why it does this?

Best regards.

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [April 19, 2024, 8:15am UTC](https://openmc.discourse.group/t/geometry-xml-file-fail/4174/2 "2024-04-19T08:15:08Z")

</div>

Great to see [cad-to-dagmc](https://github.com/fusion-energy/cad_to_dagmc) is working for you.

I think the issue here is that the way you are loading the dagmc file into openmc.

This part looks like the error

```auto
geometry = openmc.Geometry()
geometry.file = h5m_file_path

```

Try this instead, I grabbed it from the neutronics-workshop repo.

```auto
bound_dag_univ = openmc.DAGMCUniverse(filename='dagmc.h5m').bounded_universe()
geometry = openmc.Geometry(root=bound_dag_univ)

```

By the way i hope to update the cad based neutronics examples in the [neutronics workshop](https://github.com/fusion-energy/neutronics-workshop/tree/main/tasks) soon
