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 chemical validity ratio (represented in percentage).
  
  Args:
      mol_dicts (dict): 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. 
      
  :rtype: :class:`dict` a python dict with the following items:
              "valid_ratio" --- chemical validity percentage;
docstr_tok: ["Run","evaluation","in","random","generation","task",".","Compute","the","chemical","validity","ratio","(","represented","in","percentage",")",".","Args",":","mol_dicts","(","dict",")",":","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",".",":","rtype",":",":","class",":","`","dict","`","a","python","dict","with","the","following","items",":","``","valid_ratio","''","--","-","chemical","validity","percentage",";"]
code: def eval_validity(mol_dicts):
      r"""Run evaluation in random generation task. Compute the chemical validity ratio (represented in percentage).
  
      Args:
          mol_dicts (dict): 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.
  
      :rtype: :class:`dict` a python dict with the following items:
                  "valid_ratio" --- chemical validity percentage;
      """
  
      num_generated, num_valid = 0, 0
      results = {}
  
      for num_atoms in mol_dicts:
          atomic_numbers, positions = (
              mol_dicts[num_atoms]["_atomic_numbers"],
              mol_dicts[num_atoms]["_positions"],
          )
          num_generated += len(atomic_numbers)
  
          for atomic_number, position in zip(atomic_numbers, positions):
              _, valid = xyz2mol(atomic_number, position)
              num_valid += 1 if valid else 0
  
      print(
          "Valid Ratio: {}/{} = {:.2f}%".format(
              num_valid, num_generated, num_valid / num_generated * 100
          )
      )
      results["valid_ratio"] = num_valid / num_generated * 100
  
      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 2 for calling the RandGenEvaluator obj's underlying member method code with example usage: obj.eval_validity(mol_dicts) and returns: results