diff --git a/Python/pywarpx/particle_containers.py b/Python/pywarpx/particle_containers.py index bc6b2d74106..f0b6970108b 100644 --- a/Python/pywarpx/particle_containers.py +++ b/Python/pywarpx/particle_containers.py @@ -26,7 +26,14 @@ def __init__(self, species_name): self.name = species_name # grab the desired particle container - mypc = libwarpx.warpx.multi_particle_container() + # if initialize_warpx() has not been called, libwarpx will not have a `warpx` attribute. + # We catch this error and provide the user with some useful information. + try: + mypc = libwarpx.warpx.multi_particle_container() + except AttributeError as e: + msg = "This may be caused by attempting to create a ParticleContainerWrapper before initialize_warpx has been called" + raise AttributeError(msg) from e + self.particle_container = mypc.get_particle_container_from_name(self.name) def add_particles(