<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def partition_chem_env(self, n_sphere=4, use_lookup=None):
 """This function partitions the molecule into subsets of the same chemical environment. A chemical environment is specified by the number of surrounding atoms of a certain kind around an atom with a certain atomic number represented by a tuple of a string and a frozenset of tuples. The ``n_sphere`` option determines how many branches the algorithm follows to determine the chemical environment. Example: A carbon atom in ethane has bonds with three hydrogen (atomic number 1) and one carbon atom (atomic number 6). If ``n_sphere=1`` these are the only atoms we are interested in and the chemical environment is:: ('C', frozenset([('H', 3), ('C', 1)])) If ``n_sphere=2`` we follow every atom in the chemical enviromment of ``n_sphere=1`` to their direct neighbours. In the case of ethane this gives:: ('C', frozenset([('H', 6), ('C', 1)])) In the special case of ethane this is the whole molecule; in other cases you can apply this operation recursively and stop after ``n_sphere`` or after reaching the end of branches. Args: n_sphere (int):
 use_lookup (bool):
 Use a lookup variable for :meth:`~chemcoord.Cartesian.get_bonds`. The default is specified in ``settings['defaults']['use_lookup']`` Returns: dict: The output will look like this:: { (element_symbol, frozenset([tuples])) : set([indices]) } A dictionary mapping from a chemical environment to the set of indices of atoms in this environment. """

        if use_lookup is None:
            use_lookup = settings['defaults']['use_lookup']

        def get_chem_env(self, i, n_sphere):
            env_index = self.get_coordination_sphere(
                i, n_sphere=n_sphere, only_surface=False,
                give_only_index=True, use_lookup=use_lookup)
            env_index.remove(i)
            atoms = self.loc[env_index, 'atom']
            environment = frozenset(collections.Counter(atoms).most_common())
            return (self.loc[i, 'atom'], environment)

        chemical_environments = collections.defaultdict(set)
        for i in self.index:
            chemical_environments[get_chem_env(self, i, n_sphere)].add(i)
        return dict(chemical_environments)