class_docstr: Evaluator for random generation task. Metric is the chemical validity ratio (represented in percentage) and the MMD distances of bond length distribution between the generated molecular geometries and those in the dataset.
docstr: Run evaluation in random generation task. Compute the MMD distances of bond length distribution between the generated molecular geometries and those in the dataset.
  
  Args:
      input_dict (dict): A python dict with the following items:
          "mol_dicts" --- A python dict where the key is the number of atoms, and the value indexed by that key is another python dict storing the atomic
          number matrix (indexed by the key '_atomic_numbers') and the coordinate tensor (indexed by the key '_positions') of all generated molecular geometries with that atom number.
          "target_bond_dists" --- A python dict where the key is the bond type, and the value indexed by that key is the list of all lengths of that bond in the dataset.
      
  :rtype: :class:`dict` a python dict where the key is the bond type, and the value indexed by that key is the MMD distance metric of that bond.
docstr_tok: ["Run","evaluation","in","random","generation","task",".","Compute","the","MMD","distances","of","bond","length","distribution","between","the","generated","molecular","geometries","and","those","in","the","dataset",".","Args",":","input_dict","(","dict",")",":","A","python","dict","with","the","following","items",":","``","mol_dicts","''","--","-","A","python","dict","where","the","key","is","the","number","of","atoms",",","and","the","value","indexed","by","that","key","is","another","python","dict","storing","the","atomic","number","matrix","(","indexed","by","the","key","'_atomic_numbers","'",")","and","the","coordinate","tensor","(","indexed","by","the","key","'_positions","'",")","of","all","generated","molecular","geometries","with","that","atom","number",".","``","target_bond_dists","''","--","-","A","python","dict","where","the","key","is","the","bond","type",",","and","the","value","indexed","by","that","key","is","the","list","of","all","lengths","of","that","bond","in","the","dataset",".",":","rtype",":",":","class",":","`","dict","`","a","python","dict","where","the","key","is","the","bond","type",",","and","the","value","indexed","by","that","key","is","the","MMD","distance","metric","of","that","bond","."]
code: def eval_bond_mmd(input_dict):
      r"""Run evaluation in random generation task. Compute the MMD distances of bond length distribution between the generated molecular geometries and those in the dataset.
  
      Args:
          input_dict (dict): A python dict with the following items:
              "mol_dicts" --- A python dict where the key is the number of atoms, and the value indexed by that key is another python dict storing the atomic
              number matrix (indexed by the key '_atomic_numbers') and the coordinate tensor (indexed by the key '_positions') of all generated molecular geometries with that atom number.
              "target_bond_dists" --- A python dict where the key is the bond type, and the value indexed by that key is the list of all lengths of that bond in the dataset.
  
      :rtype: :class:`dict` a python dict where the key is the bond type, and the value indexed by that key is the MMD distance metric of that bond.
      """
  
      mol_dicts, target_bond_dists = (
          input_dict["mol_dicts"],
          input_dict["target_bond_dists"],
      )
      bond_types = [
          (1, 8, 1),
          (1, 7, 1),
          (6, 7, 1),
          (6, 8, 1),
          (6, 6, 1),
          (1, 6, 1),
      ]
      atom_type_to_symbol = {1: "H", 6: "C", 7: "N", 8: "O"}
      results = {}
  
      valid_list, con_mat_list = [], []
      for num_atoms in mol_dicts:
          atomic_numbers, positions = (
              mol_dicts[num_atoms]["_atomic_numbers"],
              mol_dicts[num_atoms]["_positions"],
          )
          for atomic_number, position in zip(atomic_numbers, positions):
              con_mat, valid = xyz2mol(atomic_number, position)
              valid_list.append(valid)
              con_mat_list.append(con_mat)
  
      source_bond_dists = collect_bond_dists(
          mol_dicts, valid_list, con_mat_list
      )
  
      for bond_type in bond_types:
          if bond_type in source_bond_dists:
              mmd = compute_mmd(
                  torch.tensor(source_bond_dists[bond_type]),
                  torch.tensor(target_bond_dists[bond_type]),
              )
              print(
                  "The MMD distance of {}-{} bond length distributions is {}".format(
                      atom_type_to_symbol[bond_type[0]],
                      atom_type_to_symbol[bond_type[1]],
                      mmd,
                  )
              )
              results[bond_type] = mmd
  
      return results
  
file_path: DIG/dig/ggraph3D/evaluation/metric.py
imports: import torch
  import numpy
  from dig.ggraph3D.utils import xyz2mol, collect_bond_dists, compute_mmd, compute_prop
label_desc: Use image node_id 3 for calling the RandGenEvaluator obj's underlying member method code with example usage: obj.eval_bond_mmd(input_dict) and returns: results