class_docstr: The method class for GraphDF algorithm proposed in the paper `GraphDF: A Discrete Flow Model for Molecular Graph Generation <https://arxiv.org/abs/2102.01189>`_. This class provides interfaces for running random generation, property
  optimization, and constrained optimization with GraphDF algorithm. Please refer to the `example codes <https://github.com/divelab/DIG/tree/dig-stable/examples/ggraph/GraphDF>`_ for usage examples.
class_docstr_tok: ["The","method","class","for","GraphDF","algorithm","proposed","in","the","paper","`","GraphDF",":","A","Discrete","Flow","Model","for","Molecular","Graph","Generation","<","https",":","\/\/arxiv.org\/abs\/2102.01189",">","`","_",".","This","class","provides","interfaces","for","running","random","generation",",","property","optimization",",","and","constrained","optimization","with","GraphDF","algorithm",".","Please","refer","to","the","`","example","codes","<","https",":","\/\/github.com\/divelab\/DIG\/tree\/dig-stable\/examples\/ggraph\/GraphDF",">","`","_","for","usage","examples","."]
docstr: Running graph generation for random generation task.
  
  Args:
      model_conf_dict (dict): The python dict for configuring the model hyperparameters.
      checkpoint_path (str): The path to the saved model checkpoint file.
      n_mols (int, optional): The number of molecules to generate. (default: :obj:`100`)
      num_min_node (int, optional): The minimum number of nodes in the generated molecular graphs. (default: :obj:`7`)
      num_max_node (int, optional): the maximum number of nodes in the generated molecular graphs. (default: :obj:`25`)
      temperature (list, optional): a list of two float numbers, the temperature parameter of prior distribution. (default: :obj:`[0.3, 0.3]`)
      atomic_num_list (list, optional): a list of integers, the list of atomic numbers indicating the node types in the generated molecular graphs. (default: :obj:`[6, 7, 8, 9]`)
  
  :rtype:
      (all_mols, pure_valids),
      all_mols is a list of generated molecules represented by rdkit Chem.Mol objects;
      pure_valids is a list of integers, all are 0 or 1, indicating whether bond resampling happens.
docstr_tok: ["Running","graph","generation","for","random","generation","task",".","Args",":","model_conf_dict","(","dict",")",":","The","python","dict","for","configuring","the","model","hyperparameters",".","checkpoint_path","(","str",")",":","The","path","to","the","saved","model","checkpoint","file",".","n_mols","(","int",",","optional",")",":","The","number","of","molecules","to","generate",".","(","default",":",":","obj",":","`","100","`",")","num_min_node","(","int",",","optional",")",":","The","minimum","number","of","nodes","in","the","generated","molecular","graphs",".","(","default",":",":","obj",":","`","7","`",")","num_max_node","(","int",",","optional",")",":","the","maximum","number","of","nodes","in","the","generated","molecular","graphs",".","(","default",":",":","obj",":","`","25","`",")","temperature","(","list",",","optional",")",":","a","list","of","two","float","numbers",",","the","temperature","parameter","of","prior","distribution",".","(","default",":",":","obj",":","`","[","0.3",",","0.3","]","`",")","atomic_num_list","(","list",",","optional",")",":","a","list","of","integers",",","the","list","of","atomic","numbers","indicating","the","node","types","in","the","generated","molecular","graphs",".","(","default",":",":","obj",":","`","[","6",",","7",",","8",",","9","]","`",")",":","rtype",":","(","all_mols",",","pure_valids",")",",","all_mols","is","a","list","of","generated","molecules","represented","by","rdkit","Chem.Mol","objects",";","pure_valids","is","a","list","of","integers",",","all","are","0","or","1",",","indicating","whether","bond","resampling","happens","."]
code: def run_rand_gen(
      self,
      model_conf_dict,
      checkpoint_path,
      n_mols=100,
      num_min_node=7,
      num_max_node=25,
      temperature=[0.3, 0.3],
      atomic_num_list=[6, 7, 8, 9],
  ):
      r"""
      Running graph generation for random generation task.
  
      Args:
          model_conf_dict (dict): The python dict for configuring the model hyperparameters.
          checkpoint_path (str): The path to the saved model checkpoint file.
          n_mols (int, optional): The number of molecules to generate. (default: :obj:`100`)
          num_min_node (int, optional): The minimum number of nodes in the generated molecular graphs. (default: :obj:`7`)
          num_max_node (int, optional): the maximum number of nodes in the generated molecular graphs. (default: :obj:`25`)
          temperature (list, optional): a list of two float numbers, the temperature parameter of prior distribution. (default: :obj:`[0.3, 0.3]`)
          atomic_num_list (list, optional): a list of integers, the list of atomic numbers indicating the node types in the generated molecular graphs. (default: :obj:`[6, 7, 8, 9]`)
  
      :rtype:
          (all_mols, pure_valids),
          all_mols is a list of generated molecules represented by rdkit Chem.Mol objects;
          pure_valids is a list of integers, all are 0 or 1, indicating whether bond resampling happens.
      """
  
      self.get_model("rand_gen", model_conf_dict, checkpoint_path)
      self.model.eval()
      all_mols, pure_valids = [], []
      cnt_mol = 0
  
      while cnt_mol < n_mols:
          mol, no_resample, num_atoms = self.model.generate(
              atom_list=atomic_num_list,
              min_atoms=num_min_node,
              max_atoms=num_max_node,
              temperature=temperature,
          )
          if num_atoms >= num_min_node:
              cnt_mol += 1
              all_mols.append(mol)
              pure_valids.append(no_resample)
              if cnt_mol % 10 == 0:
                  print("Generated {} molecules".format(cnt_mol))
  
      assert (
          cnt_mol == n_mols
      ), "number of generated molecules does not equal num"
      return all_mols, pure_valids
  
file_path: DIG/dig/ggraph/method/GraphDF/graphdf.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 5 for calling the GraphDF obj's underlying member method code with example usage: obj.run_rand_gen(model_conf_dict, checkpoint_path, n_mols, num_min_node, num_max_node, temperature, atomic_num_list) and returns: all_mols,  pure_valids