<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def label_rigid_bodies(self, discrete_bodies=None, rigid_particles=None):
 """Designate which Compounds should be treated as rigid bodies If no arguments are provided, this function will treat the compound as a single rigid body by providing all particles in `self` with the same rigid_id. If `discrete_bodies` is not None, each instance of a Compound with a name found in `discrete_bodies` will be treated as a unique rigid body. If `rigid_particles` is not None, only Particles (Compounds at the bottom of the containment hierarchy) matching this name will be considered part of the rigid body. Parameters discrete_bodies : str or list of str, optional, default=None Name(s) of Compound instances to be treated as unique rigid bodies. Compound instances matching this (these) name(s) will be provided with unique rigid_ids rigid_particles : str or list of str, optional, default=None Name(s) of Compound instances at the bottom of the containment hierarchy (Particles) to be included in rigid bodies. Only Particles matching this (these) name(s) will have their rigid_ids altered to match the rigid body number. Examples -------- Creating a rigid benzene Creating a semi-rigid benzene, where only the carbons are treated as a rigid body Create a box of rigid benzenes, where each benzene has a unique rigid body ID. Create a box of semi-rigid benzenes, where each benzene has a unique rigid body ID and only the carbon portion is treated as rigid. """

        if discrete_bodies is not None:
            if isinstance(discrete_bodies, string_types):
                discrete_bodies = [discrete_bodies]
        if rigid_particles is not None:
            if isinstance(rigid_particles, string_types):
                rigid_particles = [rigid_particles]

        if self.root.max_rigid_id is not None:
            rigid_id = self.root.max_rigid_id + 1
            warn("{} rigid bodies already exist.  Incrementing 'rigid_id'"
                 "starting from {}.".format(rigid_id, rigid_id))
        else:
            rigid_id = 0

        for successor in self.successors():
            if discrete_bodies and successor.name not in discrete_bodies:
                continue
            for particle in successor.particles():
                if rigid_particles and particle.name not in rigid_particles:
                    continue
                particle.rigid_id = rigid_id
            if discrete_bodies:
                rigid_id += 1