Question about using custom particle sources.

I want to set up a custom particle source for OpenMC to use. In this particle source, each particle is custom and comes from the simulation result of the last OpenMC program. So I used the following code to generate a separate particle source

settings = openmc.Settings()
settings.sourcepoint = {'separate': True}
...
settings.export_to_xml()

However, this code fails when the run mode is fixed source mode and cannot generate a separate source particle file. So I choose to read the particle tracks from the last OpenMC run result and use the following functions

openmc.SourceParticle(r=(0.0, 0.0, 0.0), u=(0.0, 0.0, 1.0), E=1000000.0, time=0.0, wgt=1.0, delayed_group=0, surf_id=0, particle=ParticleType.NEUTRON)

openmc.write_source_file(source_particles, filename, **kwargs)

to generate the external source file. The result fails with the following code.

import openmc
from h5py import Dataset, File
with File('tracks.h5', 'r') as f:
    source_particles_list = []
    for k in f.keys():
        if isinstance(f[k], Dataset):
            locals()[f'tuple_{k}'] = f[k][()]
            locals()[f'tuple_{k}_len'] = len(locals()[f'tuple_{k}']) 
            temp_len = locals()[f'tuple_{k}_len']  
            time_location = 1 #Do not care about this, there is no point
            print(locals()[f'tuple_{k}'][temp_len - time_location][0]) 
            r_temp = locals()[f'tuple_{k}'][temp_len - time_location][0]
            u_temp = locals()[f'tuple_{k}'][temp_len - time_location][1]
            E_temp = locals()[f'tuple_{k}'][temp_len - time_location][2]
            time_temp = locals()[f'tuple_{k}'][temp_len - time_location][3]
            wgt_temp = locals()[f'tuple_{k}'][temp_len - time_location][4]
            print(r_temp,u_temp,E_temp,time_temp,wgt_temp)
            particle_temp = openmc.SourceParticle(r=r_temp, u=u_temp, E=E_temp, time=time_temp, wgt=wgt_temp, delayed_group=0, surf_id=0,particle=0)                                 
            source_particles_list.append(particle_temp)

openmc.write_source_file(source_particles_list,"my_source.h5")





Traceback (most recent call last):
  File "/home/lugaoqi/桌面/openmc-test/121231.py", line 21, in <module>
    openmc.write_source_file(source_particles_list,"my_source.h5")
  File "/home/lugaoqi/.local/lib/python3.10/site-packages/openmc/source.py", line 350, in write_source_file
    arr = np.array([s.to_tuple() for s in source_particles], dtype=source_dtype)
  File "/home/lugaoqi/.local/lib/python3.10/site-packages/openmc/source.py", line 350, in <listcomp>
    arr = np.array([s.to_tuple() for s in source_particles], dtype=source_dtype)
  File "/home/lugaoqi/.local/lib/python3.10/site-packages/openmc/source.py", line 315, in to_tuple
    self.delayed_group, self.surf_id, self.particle.value)
AttributeError: 'int' object has no attribute 'value'

I want to know what is my problem?

I also noticed that the separate particle source file I generated in the default run mode does not have the time property.But in the description of the documentation “source_bank” has the time attribute

2. Source File Format¶
Normally, source data is stored in a state point file. However, it is possible to request that the source be written separately, in which case the format used is that documented here.

When surface source writing is triggered, a source file named surface_source.h5 is written with only the sources on specified surfaces, following the same format.

/

Attributes
filetype (char[]) – String indicating the type of file.

Datasets
source_bank (Compound type) – Source bank information for each particle. The compound type has fields r, u, E, time, wgt, delayed_group, surf_id and particle, which represent the position, direction, energy, time, weight, delayed group, surface ID, and particle type (0=neutron, 1=photon, 2=electron, 3=positron), respectively.

Part of my test generated independent particle source file data

source_bank
[((-3.45960911, -1.71811343e+00, 3.63275206e-01), (-8.04197939e-01, -5.62528212e-01, 1.91905408e-01), 1342676.35792691, 1., 0, 0, 0)
((-3.45960911, -1.71811343e+00, 3.63275206e-01), ( 5.11654330e-01, -7.27346754e-01, 4.57358225e-01), 1902526.30863024, 1., 0, 0, 0)