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: Create generator model.
  Take noise data as an input and processes it through number of
  dense and dropout layers. Then data is converted into two forms
  one used for training and other for generation of compounds.
  The model has two outputs:
      1. edges
      2. nodes
  The format differs depending on intended use (training or sample generation).
  For sample generation use flag, sample_generation=True while calling generator
  i.e. gan.generators[0](noise_input, training=False, sample_generation=True).
  For training the model, set `sample_generation=False`
docstr_tok: ["Create","generator","model",".","Take","noise","data","as","an","input","and","processes","it","through","number","of","dense","and","dropout","layers",".","Then","data","is","converted","into","two","forms","one","used","for","training","and","other","for","generation","of","compounds",".","The","model","has","two","outputs",":","1.","edges","2.","nodes","The","format","differs","depending","on","intended","use","(","training","or","sample","generation",")",".","For","sample","generation","use","flag",",","sample_generation=True","while","calling","generator","i.e",".","gan.generators","[","0","]","(","noise_input",",","training=False",",","sample_generation=True",")",".","For","training","the","model",",","set","`","sample_generation=False","`"]
code: def create_generator(self) -> keras.Model:
      """
      Create generator model.
      Take noise data as an input and processes it through number of
      dense and dropout layers. Then data is converted into two forms
      one used for training and other for generation of compounds.
      The model has two outputs:
          1. edges
          2. nodes
      The format differs depending on intended use (training or sample generation).
      For sample generation use flag, sample_generation=True while calling generator
      i.e. gan.generators[0](noise_input, training=False, sample_generation=True).
      For training the model, set `sample_generation=False`
      """
      return BasicMolGANGenerator(
          vertices=self.vertices,
          edges=self.edges,
          nodes=self.nodes,
          dropout_rate=self.dropout_rate,
          embedding_dim=self.embedding_dim,
      )
  
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 4 for calling the BasicMolGANModel obj's underlying member method code with example usage: obj.create_generator() and returns: BasicMolGANGenerator