code: def construct_mol(x, A, atomic_num_list):
      mol = Chem.RWMol()
      atoms = np.argmax(x, axis=1)
      atoms_exist = atoms != len(atomic_num_list) - 1
      atoms = atoms[atoms_exist]
  
      for atom in atoms:
          mol.AddAtom(Chem.Atom(int(atomic_num_list[atom])))
  
      # A (edge_type, num_node, num_node)
      adj = np.argmax(A, axis=0)
      adj = np.array(adj)
      adj = adj[atoms_exist, :][:, atoms_exist]
      adj[adj == 3] = -1
      adj += 1
      for start, end in zip(*np.nonzero(adj)):
          if start > end:
              mol.AddBond(
                  int(start), int(end), bond_decoder_m[adj[start, end]]
              )
              # add formal charge to atom: e.g. [O+], [N+] [S+]
              # not support [O-], [N-] [S-]  [NH+] etc.
              flag, atomid_valence = check_valency(mol)
              if flag:
                  continue
              else:
                  assert len(atomid_valence) == 2
                  idx = atomid_valence[0]
                  v = atomid_valence[1]
                  an = mol.GetAtomWithIdx(idx).GetAtomicNum()
                  if an in (7, 8, 16) and (v - ATOM_VALENCY[an]) == 1:
                      mol.GetAtomWithIdx(idx).SetFormalCharge(1)
      return mol
  
imports: import re
  import numpy
  from rdkit import Chem
label_desc: Use image node_id 1 for calling a global function with example usage: construct_mol(x, A, atomic_num_list) and returns: mol