<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rigid_particles(self, rigid_id=None):
 """Generate all particles in rigid bodies. If a rigid_id is specified, then this function will only yield particles with a matching rigid_id. Parameters rigid_id : int, optional Include only particles with this rigid body ID Yields ------ mb.Compound The next particle with a rigid_id that is not None, or the next particle with a matching rigid_id if specified """

        for particle in self.particles():
            if rigid_id is not None:
                if particle.rigid_id == rigid_id:
                    yield particle
            else:
                if particle.rigid_id is not None:
                    yield particle