class_docstr: Model for de-novo generation of small molecules based on work of Nicola De Cao et al. [1]_.
  It uses a GAN directly on graph data and a reinforcement learning objective to induce the network to generate molecules with certain chemical properties.
  Utilizes WGAN infrastructure; uses adjacency matrix and node features as inputs.
  Inputs need to be one-hot representation.
  
  Examples
  --------
  >>>
  >> import deepchem as dc
  >> from deepchem.models import BasicMolGANModel as MolGAN
  >> from deepchem.models.optimizers import ExponentialDecay
  >> from tensorflow import one_hot
  >> smiles = ['CCC', 'C1=CC=CC=C1', 'CNC' ]
  >> # create featurizer
  >> feat = dc.feat.MolGanFeaturizer()
  >> # featurize molecules
  >> features = feat.featurize(smiles)
  >> # Remove empty objects
  >> features = list(filter(lambda x: x is not None, features))
  >> # create model
  >> gan = MolGAN(learning_rate=ExponentialDecay(0.001, 0.9, 5000))
  >> dataset = dc.data.NumpyDataset([x.adjacency_matrix for x in features],[x.node_features for x in features])
  >> def iterbatches(epochs):
  >>     for i in range(epochs):
  >>         for batch in dataset.iterbatches(batch_size=gan.batch_size, pad_batches=True):
  >>             adjacency_tensor = one_hot(batch[0], gan.edges)
  >>             node_tensor = one_hot(batch[1], gan.nodes)
  >>             yield {gan.data_inputs[0]: adjacency_tensor, gan.data_inputs[1]:node_tensor}
  >> gan.fit_gan(iterbatches(8), generator_steps=0.2, checkpoint_interval=5000)
  >> generated_data = gan.predict_gan_generator(1000)
  >> # convert graphs to RDKitmolecules
  >> nmols = feat.defeaturize(generated_data)
  >> print("{} molecules generated".format(len(nmols)))
  >> # remove invalid moles
  >> nmols = list(filter(lambda x: x is not None, nmols))
  >> # currently training is unstable so 0 is a common outcome
  >> print ("{} valid molecules".format(len(nmols)))
  
  References
  ----------
  .. [1] Nicola De Cao et al. "MolGAN: An implicit generative model
      for small molecular graphs", https://arxiv.org/abs/1805.11973
class_docstr_tok: ["Model","for","de-novo","generation","of","small","molecules","based","on","work","of","Nicola","De","Cao","et","al",".","[","1","]","_",".","It","uses","a","GAN","directly","on","graph","data","and","a","reinforcement","learning","objective","to","induce","the","network","to","generate","molecules","with","certain","chemical","properties",".","Utilizes","WGAN","infrastructure",";","uses","adjacency","matrix","and","node","features","as","inputs",".","Inputs","need","to","be","one-hot","representation",".","Examples","--","--","--","--",">",">",">",">",">","import","deepchem","as","dc",">",">","from","deepchem.models","import","BasicMolGANModel","as","MolGAN",">",">","from","deepchem.models.optimizers","import","ExponentialDecay",">",">","from","tensorflow","import","one_hot",">",">","smiles","=","[","'CCC","'",",","'C1=CC=CC=C1","'",",","'CNC","'","]",">",">","#","create","featurizer",">",">","feat","=","dc.feat.MolGanFeaturizer","(",")",">",">","#","featurize","molecules",">",">","features","=","feat.featurize","(","smiles",")",">",">","#","Remove","empty","objects",">",">","features","=","list","(","filter","(","lambda","x",":","x","is","not","None",",","features",")",")",">",">","#","create","model",">",">","gan","=","MolGAN","(","learning_rate=ExponentialDecay","(","0.001",",","0.9",",","5000",")",")",">",">","dataset","=","dc.data.NumpyDataset","(","[","x.adjacency_matrix","for","x","in","features","]",",","[","x.node_features","for","x","in","features","]",")",">",">","def","iterbatches","(","epochs",")",":",">",">","for","i","in","range","(","epochs",")",":",">",">","for","batch","in","dataset.iterbatches","(","batch_size=gan.batch_size",",","pad_batches=True",")",":",">",">","adjacency_tensor","=","one_hot","(","batch","[","0","]",",","gan.edges",")",">",">","node_tensor","=","one_hot","(","batch","[","1","]",",","gan.nodes",")",">",">","yield","{","gan.data_inputs","[","0","]",":","adjacency_tensor",",","gan.data_inputs","[","1","]",":","node_tensor","}",">",">","gan.fit_gan","(","iterbatches","(","8",")",",","generator_steps=0.2",",","checkpoint_interval=5000",")",">",">","generated_data","=","gan.predict_gan_generator","(","1000",")",">",">","#","convert","graphs","to","RDKitmolecules",">",">","nmols","=","feat.defeaturize","(","generated_data",")",">",">","print","(","``","{","}","molecules","generated","''",".format","(","len","(","nmols",")",")",")",">",">","#","remove","invalid","moles",">",">","nmols","=","list","(","filter","(","lambda","x",":","x","is","not","None",",","nmols",")",")",">",">","#","currently","training","is","unstable","so","0","is","a","common","outcome",">",">","print","(","``","{","}","valid","molecules","''",".format","(","len","(","nmols",")",")",")","References","--","--","--","--","--","..","[","1","]","Nicola","De","Cao","et","al",".","``","MolGAN",":","An","implicit","generative","model","for","small","molecular","graphs","''",",","https",":","\/\/arxiv.org\/abs\/1805.11973"]
docstr: Use the GAN to generate a batch of samples.
  
  Parameters
  ----------
  batch_size: int
      the number of samples to generate.  If either noise_input or
      conditional_inputs is specified, this argument is ignored since the batch
      size is then determined by the size of that argument.
  noise_input: array
      the value to use for the generator's noise input.  If None (the default),
      get_noise_batch() is called to generate a random input, so each call will
      produce a new set of samples.
  conditional_inputs: list of arrays
      NOT USED.
      the values to use for all conditional inputs.  This must be specified if
      the GAN has any conditional inputs.
  generator_index: int
      NOT USED.
      the index of the generator (between 0 and n_generators-1) to use for
      generating the samples.
  
  Returns
  -------
  List[GraphMatrix]
      Returns a list of GraphMatrix object that can be converted into
      RDKit molecules using MolGANFeaturizer defeaturize function.
docstr_tok: ["Use","the","GAN","to","generate","a","batch","of","samples",".","Parameters","--","--","--","--","--","batch_size",":","int","the","number","of","samples","to","generate",".","If","either","noise_input","or","conditional_inputs","is","specified",",","this","argument","is","ignored","since","the","batch","size","is","then","determined","by","the","size","of","that","argument",".","noise_input",":","array","the","value","to","use","for","the","generator","'s","noise","input",".","If","None","(","the","default",")",",","get_noise_batch","(",")","is","called","to","generate","a","random","input",",","so","each","call","will","produce","a","new","set","of","samples",".","conditional_inputs",":","list","of","arrays","NOT","USED",".","the","values","to","use","for","all","conditional","inputs",".","This","must","be","specified","if","the","GAN","has","any","conditional","inputs",".","generator_index",":","int","NOT","USED",".","the","index","of","the","generator","(","between","0","and","n_generators-1",")","to","use","for","generating","the","samples",".","Returns","--","--","--","-","List","[","GraphMatrix","]","Returns","a","list","of","GraphMatrix","object","that","can","be","converted","into","RDKit","molecules","using","MolGANFeaturizer","defeaturize","function","."]
code: def predict_gan_generator(
      self,
      batch_size: int = 1,
      noise_input: Optional[List] = None,
      conditional_inputs: List = [],
      generator_index: int = 0,
  ) -> List[GraphMatrix]:
      """
      Use the GAN to generate a batch of samples.
  
      Parameters
      ----------
      batch_size: int
          the number of samples to generate.  If either noise_input or
          conditional_inputs is specified, this argument is ignored since the batch
          size is then determined by the size of that argument.
      noise_input: array
          the value to use for the generator's noise input.  If None (the default),
          get_noise_batch() is called to generate a random input, so each call will
          produce a new set of samples.
      conditional_inputs: list of arrays
          NOT USED.
          the values to use for all conditional inputs.  This must be specified if
          the GAN has any conditional inputs.
      generator_index: int
          NOT USED.
          the index of the generator (between 0 and n_generators-1) to use for
          generating the samples.
  
      Returns
      -------
      List[GraphMatrix]
          Returns a list of GraphMatrix object that can be converted into
          RDKit molecules using MolGANFeaturizer defeaturize function.
      """
  
      if noise_input is not None:
          batch_size = len(noise_input)
      if noise_input is None:
          noise_input = self.get_noise_batch(batch_size)
      print(f"Generating {batch_size} samples")
      adjacency_matrix, nodes_features = self.generators[0](
          noise_input, training=False, sample_generation=True
      )
      graphs = [
          GraphMatrix(i, j)
          for i, j in zip(
              adjacency_matrix.numpy(), nodes_features.numpy()
          )
      ]
      return graphs
  
file_path: deepchem/deepchem/models/molgan.py
imports: from typing import Optional, List, Tuple, Any
  import tensorflow
  from deepchem.feat.molecule_featurizers.molgan_featurizer import GraphMatrix
  from deepchem.models import WGAN
  from deepchem.models.layers import MolGANEncoderLayer
  from tensorflow import keras
  from tensorflow.keras import layers
label_desc: Use image node_id 6 for calling the BasicMolGANModel obj's underlying member method code with example usage: obj.predict_gan_generator(batch_size, noise_input, conditional_inputs, generator_index) and returns: graphs