class_docstr: Evaluator for constrained optimization task. Metric is the average property improvements, similarities and success rates under the similarity threshold 0.0, 0.2, 0.4, 0.6.
docstr: Run evaluation in constrained optimization task. Compute the average property improvements, similarities and success rates under the similarity threshold 0.0, 0.2, 0.4, 0.6.
  
  Args:
      input_dict (dict): A python dict with the following items:
          "mols_0", "mols_2", "mols_4", "mols_6" --- the list of optimized molecules under the similarity threshold 0.0, 0.2, 0.4, 0.6, all represented by rdkit Chem.RWMol or Chem.Mol objects;
          "inp_smiles" --- the list of SMILES strings of input molecules to be optimized.
      
  :rtype: :class:`dict` a python dict with the following items:
              0, 2, 4, 6 --- the metric values under the similarity threshold 0.0, 0.2, 0.4, 0.6.
              The metric values are given in the form of a tuple (success rate, mean of similarity, standard deviation of similarity,
              mean of property improvement, standard deviation of property improvement).
code: def eval(input_dict):
      r"""Run evaluation in constrained optimization task. Compute the average property improvements, similarities and success rates under the similarity threshold 0.0, 0.2, 0.4, 0.6.
  
      Args:
          input_dict (dict): A python dict with the following items:
              "mols_0", "mols_2", "mols_4", "mols_6" --- the list of optimized molecules under the similarity threshold 0.0, 0.2, 0.4, 0.6, all represented by rdkit Chem.RWMol or Chem.Mol objects;
              "inp_smiles" --- the list of SMILES strings of input molecules to be optimized.
  
      :rtype: :class:`dict` a python dict with the following items:
                  0, 2, 4, 6 --- the metric values under the similarity threshold 0.0, 0.2, 0.4, 0.6.
                  The metric values are given in the form of a tuple (success rate, mean of similarity, standard deviation of similarity,
                  mean of property improvement, standard deviation of property improvement).
      """
  
      inp_smiles = input_dict["inp_smiles"]
      inp_mols = [Chem.MolFromSmiles(s) for s in inp_smiles]
      inp_props = [calculate_min_plogp(mol) for mol in inp_mols]
      mols_0, mols_2, mols_4, mols_6 = (
          input_dict["mols_0"],
          input_dict["mols_2"],
          input_dict["mols_4"],
          input_dict["mols_6"],
      )
  
      results = {}
  
      sims_0 = [
          reward_target_molecule_similarity(inp_mols[i], mols_0[i])
          for i in range(len(mols_0))
          if mols_0[i] is not None
      ]
      sims_2 = [
          reward_target_molecule_similarity(inp_mols[i], mols_2[i])
          for i in range(len(mols_2))
          if mols_2[i] is not None
      ]
      sims_4 = [
          reward_target_molecule_similarity(inp_mols[i], mols_4[i])
          for i in range(len(mols_4))
          if mols_4[i] is not None
      ]
      sims_6 = [
          reward_target_molecule_similarity(inp_mols[i], mols_6[i])
          for i in range(len(mols_6))
          if mols_6[i] is not None
      ]
  
      imps_0 = [
          calculate_min_plogp(mols_0[i]) - inp_props[i]
          for i in range(len(mols_0))
          if mols_0[i] is not None
      ]
      imps_2 = [
          calculate_min_plogp(mols_2[i]) - inp_props[i]
          for i in range(len(mols_2))
          if mols_2[i] is not None
      ]
      imps_4 = [
          calculate_min_plogp(mols_4[i]) - inp_props[i]
          for i in range(len(mols_4))
          if mols_4[i] is not None
      ]
      imps_6 = [
          calculate_min_plogp(mols_6[i]) - inp_props[i]
          for i in range(len(mols_6))
          if mols_6[i] is not None
      ]
  
      suc_rate = len(imps_0) / len(inp_mols) * 100
      sim_avg, sim_std = np.mean(sims_0), np.std(sims_0)
      imp_avg, imp_std = np.mean(imps_0), np.std(imps_0)
      print(
          "Under similarity threshold 0.0, the success rate is {:.2f}%, the average similarity is {:.2f}+-{:.2f}, the average improvement is {:.2f}+-{:.2f}".format(
              suc_rate, sim_avg, sim_std, imp_avg, imp_std
          )
      )
      results[0] = (suc_rate, sim_avg, sim_std, imp_avg, imp_std)
  
      suc_rate = len(imps_2) / len(inp_mols) * 100
      sim_avg, sim_std = np.mean(sims_2), np.std(sims_2)
      imp_avg, imp_std = np.mean(imps_2), np.std(imps_2)
      print(
          "Under similarity threshold 0.2, the success rate is {:.2f}%, the average similarity is {:.2f}+-{:.2f}, the average improvement is {:.2f}+-{:.2f}".format(
              suc_rate, sim_avg, sim_std, imp_avg, imp_std
          )
      )
      results[2] = (suc_rate, sim_avg, sim_std, imp_avg, imp_std)
  
      suc_rate = len(imps_4) / len(inp_mols) * 100
      sim_avg, sim_std = np.mean(sims_4), np.std(sims_4)
      imp_avg, imp_std = np.mean(imps_4), np.std(imps_4)
      print(
          "Under similarity threshold 0.4, the success rate is {:.2f}%, the average similarity is {:.2f}+-{:.2f}, the average improvement is {:.2f}+-{:.2f}".format(
              suc_rate, sim_avg, sim_std, imp_avg, imp_std
          )
      )
      results[4] = (suc_rate, sim_avg, sim_std, imp_avg, imp_std)
  
      suc_rate = len(imps_6) / len(inp_mols) * 100
      sim_avg, sim_std = np.mean(sims_6), np.std(sims_6)
      imp_avg, imp_std = np.mean(imps_6), np.std(imps_6)
      print(
          "Under similarity threshold 0.6, the success rate is {:.2f}%, the average similarity is {:.2f}+-{:.2f}, the average improvement is {:.2f}+-{:.2f}".format(
              suc_rate, sim_avg, sim_std, imp_avg, imp_std
          )
      )
      results[6] = (suc_rate, sim_avg, sim_std, imp_avg, imp_std)
  
      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 ConstPropOptEvaluator obj's underlying member method code with example usage: obj.eval(input_dict) and returns: results