code: def mmtf_to_df(mmtf_obj: MMTFDecoder) -> pd.DataFrame:
      data: Dict[
          str, Union[List[str], List[int], List[float], np.ndarray]
      ] = {
          "record_name": [],
          "residue_name": [],
          "atom_name": [],
          "element_symbol": [],
          "charge": [],
          "x_coord": mmtf_obj.x_coord_list,
          "y_coord": mmtf_obj.y_coord_list,
          "z_coord": mmtf_obj.z_coord_list,
          "alt_loc": mmtf_obj.alt_loc_list,
          "b_factor": mmtf_obj.b_factor_list,
          "insertion": [],
          "residue_number": [],
          "occupancy": mmtf_obj.occupancy_list,
          "chain_id": [],
          "atom_number": mmtf_obj.atom_id_list,
          "model_id": [],
      }
  
      chain_indices = mmtf_obj.groups_per_chain
  
      for i, _ in enumerate(chain_indices):
          if i == 0:
              continue
          else:
              chain_indices[i] = chain_indices[i] + chain_indices[i - 1]
      model_indices = mmtf_obj.chains_per_model
      model_indices = [
          sum(model_indices[: i + 1]) for i in range(len(model_indices))
      ]
      ch_idx = 0
  
      entity_types = {}
      for i in mmtf_obj.entity_list:
          for chain in i["chainIndexList"]:
              entity_types[chain] = i["type"]
  
      ch_idx_iter = iter(sorted(list(entity_types.keys())))
      ch_idx = next(ch_idx_iter)
      for idx, i in enumerate(mmtf_obj.group_type_list):
          res = mmtf_obj.group_list[i]
          # record = "HETATM" if res["chemCompType"] == "NON-POLYMER" else "ATOM"
          # record = (
          #    "ATOM"
          #    if res["chemCompType"] in ["L-PEPTIDE LINKING", "PEPTIDE LINKING"]
          #    else "HETATM"
          # )
          if idx == chain_indices[ch_idx]:
              # ch_idx += 1
              ch_idx = next(ch_idx_iter)
          record = (
              "ATOM" if entity_types[ch_idx] == "polymer" else "HETATM"
          )
  
          for _ in res["atomNameList"]:
              data["residue_name"].append(res["groupName"])
              data["residue_number"].append(mmtf_obj.group_id_list[idx])
              # data["chain_id"].append([mmtf_obj.chain_name_list[ch_idx]])
              data["chain_id"].append(
                  [mmtf_obj.chain_name_list[ch_idx]]
              )
              data["model_id"].append(
                  int(np.argwhere(np.array(model_indices) > ch_idx)[0])
                  + 1
              )
              data["record_name"].append(record)
              data["insertion"].append(mmtf_obj.ins_code_list[idx])
          data["atom_name"].append(res["atomNameList"])
          data["element_symbol"].append(res["elementList"])
          data["charge"].append(res["formalChargeList"])
  
      for k, v in data.items():
          if k in [
              "residue_name",
              "x_coord",
              "y_coord",
              "z_coord",
              "alt_loc",
              "b_factor",
              "residue_number",
              "occupancy",
              "record_name",
              "insertion",
              "atom_number",
              "model_id",
          ]:
              continue
          data[k] = [i for sublist in v for i in sublist]
  
      df = pd.DataFrame.from_dict(data).sort_values(
          by=["model_id", "atom_number"]
      )
      df.alt_loc = df.alt_loc.str.replace("\x00", "")
      df.insertion = df.insertion.str.replace("\x00", "")
      return df
  
imports: from __future__ import annotations
  import os
  import copy
  import gzip
  import warnings
  from string import ascii_uppercase
  from typing import Any, Dict, List, Union
  from warnings import warn
  import numpy
  import pandas
  from looseversion import LooseVersion
  from mmtf import MMTFDecoder, MMTFEncoder, fetch, parse, parse_gzip
  from biopandas.constants import protein_letters_3to1_extended
  from ..pdb.engines import amino3to1dict, pdb_df_columns, pdb_records
label_desc: Use image node_id 3 for calling a global function with example usage: mmtf_to_df(mmtf_obj) and returns: df