code: def AC2BO(AC, atoms, use_graph=True):
      """
  
      implemenation of algorithm shown in Figure 2
  
      UA: unsaturated atoms
  
      DU: degree of unsaturation (u matrix in Figure)
  
      best_BO: Bcurr in Figure
  
      """
      if not check_connected(AC):
          return AC, 0
  
      global atomic_valence
  
      # make a list of valences, e.g. for CO: [[4],[2,1]]
      valences_list_of_lists = []
      AC_valence = list(AC.sum(axis=1))
  
      for _, (atomicNum, valence) in enumerate(zip(atoms, AC_valence)):
          # valence can't be smaller than number of neighbourgs
          possible_valence = [
              x for x in atomic_valence[atomicNum] if x >= valence
          ]
          if not possible_valence:
              return AC, 0
          valences_list_of_lists.append(possible_valence)
  
      # convert [[4],[2,1]] to [[4,2],[4,1]]
      valences_list = itertools.product(*valences_list_of_lists)
  
      best_BO = AC.copy()
  
      for valences in valences_list:
          UA, DU_from_AC = get_UA(valences, AC_valence)
  
          check_len = len(UA) == 0
          if check_len:
              check_bo = BO_is_OK(AC, AC, DU_from_AC, valences)
          else:
              check_bo = None
  
          if check_len and check_bo:
              return AC, 1
  
          UA_pairs_list = get_UA_pairs(UA, AC, use_graph=use_graph)
          for UA_pairs in UA_pairs_list:
              BO = get_BO(
                  AC,
                  UA,
                  DU_from_AC,
                  valences,
                  UA_pairs,
                  use_graph=use_graph,
              )
              status = BO_is_OK(BO, AC, DU_from_AC, valences)
  
              if status:
                  return BO, 1
              elif BO.sum() >= best_BO.sum() and valences_not_too_large(
                  BO, valences
              ):
                  best_BO = BO.copy()
  
      return best_BO, 1
  
imports: from rdkit import Chem
  import numpy
  import networkx
  import collections
  from collections import defaultdict
  import itertools
  import copy
  from scipy.spatial import distance_matrix
label_desc: Use image node_id 11 for calling a global function with example usage: AC2BO(AC, atoms, use_graph) and returns: best_BO,  int, AC,  int, AC,  int, AC,  int, BO,  int