class_docstr: Evaluator for random generation task. Metric is validity ratio, uniqueness ratio, and novelty ratio (all represented in percentage).
docstr: Run evaluation in random generation task. Compute the validity ratio, uniqueness ratio and novelty ratio of generated molecules (all represented in percentage).
  
  Args:
      input_dict (dict): A python dict with the following items:
          "mols" --- the list of generated molecules reprsented by rdkit Chem.RWMol or Chem.Mol objects;
          "train_smiles" --- the list of SMILES strings used for training.
      
  :rtype: :class:`dict` a python dict with the following items:
              "valid_ratio" --- validity percentage;
              "unique_ratio" --- uniqueness percentage;
              "novel_ratio" --- novelty percentage.
code: def eval(input_dict):
      r"""Run evaluation in random generation task. Compute the validity ratio, uniqueness ratio and novelty ratio of generated molecules (all represented in percentage).
  
      Args:
          input_dict (dict): A python dict with the following items:
              "mols" --- the list of generated molecules reprsented by rdkit Chem.RWMol or Chem.Mol objects;
              "train_smiles" --- the list of SMILES strings used for training.
  
      :rtype: :class:`dict` a python dict with the following items:
                  "valid_ratio" --- validity percentage;
                  "unique_ratio" --- uniqueness percentage;
                  "novel_ratio" --- novelty percentage.
      """
  
      mols = input_dict["mols"]
      results = {}
      valid_mols = [mol for mol in mols if check_chemical_validity(mol)]
      print(
          "Valid Ratio: {}/{} = {:.2f}%".format(
              len(valid_mols),
              len(mols),
              len(valid_mols) / len(mols) * 100,
          )
      )
      results["valid_ratio"] = len(valid_mols) / len(mols) * 100
  
      if len(valid_mols) > 0:
          valid_smiles = [Chem.MolToSmiles(mol) for mol in valid_mols]
          unique_smiles = list(set(valid_smiles))
          print(
              "Unique Ratio: {}/{} = {:.2f}%".format(
                  len(unique_smiles),
                  len(valid_smiles),
                  len(unique_smiles) / len(valid_smiles) * 100,
              )
          )
          results["unique_ratio"] = (
              len(unique_smiles) / len(valid_smiles) * 100
          )
  
          if (
              "train_smiles" in input_dict.keys()
              and input_dict["train_smiles"] is not None
          ):
              train_smiles = input_dict["train_smiles"]
              novels = [
                  1
                  for smile in valid_smiles
                  if smile not in train_smiles
              ]
              print(
                  "Novel Ratio: {}/{} = {:.2f}%".format(
                      len(novels),
                      len(valid_smiles),
                      len(novels) / len(valid_smiles) * 100,
                  )
              )
              results["novel_ratio"] = (
                  len(novels) / len(valid_smiles) * 100
              )
  
      return results
  
file_path: DIG/dig/ggraph/evaluation/metric.py
imports: from rdkit import Chem
  import numpy
  from dig.ggraph.utils import check_chemical_validity, qed, calculate_min_plogp, reward_target_molecule_similarity
label_desc: Use image node_id 2 for calling the RandGenEvaluator obj's underlying member method code with example usage: obj.eval(input_dict) and returns: results