class_docstr: The method class for GraphAF algorithm proposed in the paper `GraphAF: a Flow-based Autoregressive Model for Molecular Graph Generation <https://arxiv.org/abs/2001.09382>`_. This class provides interfaces for running random generation, property
  optimization, and constrained optimization with GraphAF. Please refer to the `example codes <https://github.com/divelab/DIG/tree/dig-stable/examples/ggraph/GraphAF>`_ for usage examples.
class_docstr_tok: ["The","method","class","for","GraphAF","algorithm","proposed","in","the","paper","`","GraphAF",":","a","Flow-based","Autoregressive","Model","for","Molecular","Graph","Generation","<","https",":","\/\/arxiv.org\/abs\/2001.09382",">","`","_",".","This","class","provides","interfaces","for","running","random","generation",",","property","optimization",",","and","constrained","optimization","with","GraphAF",".","Please","refer","to","the","`","example","codes","<","https",":","\/\/github.com\/divelab\/DIG\/tree\/dig-stable\/examples\/ggraph\/GraphAF",">","`","_","for","usage","examples","."]
docstr: Running molecule optimization for constrained optimization task.
  
  Args:
      dataset: The dataset class for loading molecules to be optimized. It is supposed to use dig.ggraph.dataset.ZINC800 as the dataset class.
      model_conf_dict (dict): The python dict for configuring the model hyperparameters.
      checkpoint_path (str): The path to the saved model checkpoint file.
      repeat_time (int, optional): The maximum number of optimization times for each molecule before successfully optimizing it under the threshold 0.6.  (default: :obj:`200`)
      min_optim_time (int, optional): The minimum number of optimization times for each molecule. (default: :obj:`50`)
      num_max_node (int, optional): The maximum number of nodes in the optimized molecular graphs. (default: :obj:`25`)
      temperature (float, optional): A float numbers, the temperature parameter of prior distribution. (default: :obj:`0.75`)
      atomic_num_list (list, optional): A list of integers, the list of atomic numbers indicating the node types in the optimized molecular graphs. (default: :obj:`[6, 7, 8, 9]`)
  
  :rtype:
      (mols_0, mols_2, mols_4, mols_6), they are lists of optimized molecules (represented by rdkit Chem.Mol objects) under the threshold 0.0, 0.2, 0.4, 0.6, respectively.
docstr_tok: ["Running","molecule","optimization","for","constrained","optimization","task",".","Args",":","dataset",":","The","dataset","class","for","loading","molecules","to","be","optimized",".","It","is","supposed","to","use","dig.ggraph.dataset.ZINC800","as","the","dataset","class",".","model_conf_dict","(","dict",")",":","The","python","dict","for","configuring","the","model","hyperparameters",".","checkpoint_path","(","str",")",":","The","path","to","the","saved","model","checkpoint","file",".","repeat_time","(","int",",","optional",")",":","The","maximum","number","of","optimization","times","for","each","molecule","before","successfully","optimizing","it","under","the","threshold","0.6",".","(","default",":",":","obj",":","`","200","`",")","min_optim_time","(","int",",","optional",")",":","The","minimum","number","of","optimization","times","for","each","molecule",".","(","default",":",":","obj",":","`","50","`",")","num_max_node","(","int",",","optional",")",":","The","maximum","number","of","nodes","in","the","optimized","molecular","graphs",".","(","default",":",":","obj",":","`","25","`",")","temperature","(","float",",","optional",")",":","A","float","numbers",",","the","temperature","parameter","of","prior","distribution",".","(","default",":",":","obj",":","`","0.75","`",")","atomic_num_list","(","list",",","optional",")",":","A","list","of","integers",",","the","list","of","atomic","numbers","indicating","the","node","types","in","the","optimized","molecular","graphs",".","(","default",":",":","obj",":","`","[","6",",","7",",","8",",","9","]","`",")",":","rtype",":","(","mols_0",",","mols_2",",","mols_4",",","mols_6",")",",","they","are","lists","of","optimized","molecules","(","represented","by","rdkit","Chem.Mol","objects",")","under","the","threshold","0.0",",","0.2",",","0.4",",","0.6",",","respectively","."]
code: def run_cons_optim(
      self,
      dataset,
      model_conf_dict,
      checkpoint_path,
      repeat_time=200,
      min_optim_time=50,
      num_max_node=25,
      temperature=0.7,
      atomic_num_list=[6, 7, 8, 9],
  ):
      r"""
      Running molecule optimization for constrained optimization task.
  
      Args:
          dataset: The dataset class for loading molecules to be optimized. It is supposed to use dig.ggraph.dataset.ZINC800 as the dataset class.
          model_conf_dict (dict): The python dict for configuring the model hyperparameters.
          checkpoint_path (str): The path to the saved model checkpoint file.
          repeat_time (int, optional): The maximum number of optimization times for each molecule before successfully optimizing it under the threshold 0.6.  (default: :obj:`200`)
          min_optim_time (int, optional): The minimum number of optimization times for each molecule. (default: :obj:`50`)
          num_max_node (int, optional): The maximum number of nodes in the optimized molecular graphs. (default: :obj:`25`)
          temperature (float, optional): A float numbers, the temperature parameter of prior distribution. (default: :obj:`0.75`)
          atomic_num_list (list, optional): A list of integers, the list of atomic numbers indicating the node types in the optimized molecular graphs. (default: :obj:`[6, 7, 8, 9]`)
  
      :rtype:
          (mols_0, mols_2, mols_4, mols_6), they are lists of optimized molecules (represented by rdkit Chem.Mol objects) under the threshold 0.0, 0.2, 0.4, 0.6, respectively.
      """
  
      self.get_model("const_prop_opt", model_conf_dict, checkpoint_path)
      self.model.eval()
  
      data_len = len(dataset)
      optim_success_dict = {}
      mols_0, mols_2, mols_4, mols_6 = [], [], [], []
      for batch_cnt in range(data_len):
          best_mol = [None, None, None, None]
          best_score = [-100.0, -100.0, -100.0, -100.0]
          final_sim = [-1.0, -1.0, -1.0, -1.0]
  
          batch_data = dataset[
              batch_cnt
          ]  # dataloader is dataset object
  
          inp_node_features = batch_data.x.unsqueeze(
              0
          )  # (1, N, node_dim)
          inp_adj_features = batch_data.adj.unsqueeze(0)  # (1, 4, N, N)
  
          raw_smile = batch_data.smile  # (1)
          mol_size = batch_data.num_atom
          bfs_perm_origin = batch_data.bfs_perm_origin
  
          for cur_iter in range(repeat_time):
              if raw_smile not in optim_success_dict:
                  optim_success_dict[raw_smile] = [
                      0,
                      -1,
                  ]  # (try_time, imp)
              if (
                  optim_success_dict[raw_smile][0] > min_optim_time
                  and optim_success_dict[raw_smile][1] > 0
              ):  # reach min time and imp is positive
                  continue  # not optimize this one
  
              (
                  best_mol0246,
                  best_score0246,
                  final_sim0246,
              ) = self.run_cons_optim_one_mol(
                  inp_adj_features,
                  inp_node_features,
                  raw_smile,
                  mol_size,
                  bfs_perm_origin,
                  num_max_node,
                  temperature,
                  atomic_num_list,
              )
              if best_score0246[0] > best_score[0]:
                  best_score[0] = best_score0246[0]
                  best_mol[0] = best_mol0246[0]
                  final_sim[0] = final_sim0246[0]
  
              if best_score0246[1] > best_score[1]:
                  best_score[1] = best_score0246[1]
                  best_mol[1] = best_mol0246[1]
                  final_sim[1] = final_sim0246[1]
  
              if best_score0246[2] > best_score[2]:
                  best_score[2] = best_score0246[2]
                  best_mol[2] = best_mol0246[2]
                  final_sim[2] = final_sim0246[2]
  
              if best_score0246[3] > best_score[3]:
                  best_score[3] = best_score0246[3]
                  best_mol[3] = best_mol0246[3]
                  final_sim[3] = final_sim0246[3]
  
              if best_score[3] > 0:  # imp > 0
                  optim_success_dict[raw_smile][1] = best_score[3]
              optim_success_dict[raw_smile][0] += 1  # try time + 1
  
          mols_0.append(best_mol[0])
          mols_2.append(best_mol[1])
          mols_4.append(best_mol[2])
          mols_6.append(best_mol[3])
  
          if batch_cnt % 1 == 0:
              print("Optimized {} molecules".format(batch_cnt + 1))
  
      return mols_0, mols_2, mols_4, mols_6
  
file_path: DIG/dig/ggraph/method/GraphAF/graphaf.py
imports: import os
  import torch
  import torch.nn
  from rdkit import Chem
  from dig.ggraph.method import Generator
  from .model import GraphFlowModel, GraphFlowModel_rl, GraphFlowModel_con_rl
  from .train_utils import adjust_learning_rate, DataIterator
label_desc: Use image node_id 10 for calling the GraphAF obj's underlying member method code with example usage: obj.run_cons_optim(dataset, model_conf_dict, checkpoint_path, repeat_time, min_optim_time, num_max_node, temperature, atomic_num_list) and returns: mols_0,  mols_2,  mols_4,  mols_6