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 discriminator model based on MolGAN layers.
  Takes two inputs:
      1. adjacency tensor, containing bond information
      2. nodes tensor, containing atom information
  The input vectors need to be in one-hot encoding format.
  Use MolGAN featurizer for that purpose. It will be simplified
  in the future release.
docstr_tok: ["Create","discriminator","model","based","on","MolGAN","layers",".","Takes","two","inputs",":","1.","adjacency","tensor",",","containing","bond","information","2.","nodes","tensor",",","containing","atom","information","The","input","vectors","need","to","be","in","one-hot","encoding","format",".","Use","MolGAN","featurizer","for","that","purpose",".","It","will","be","simplified","in","the","future","release","."]
code: def create_discriminator(self) -> keras.Model:
      """
      Create discriminator model based on MolGAN layers.
      Takes two inputs:
          1. adjacency tensor, containing bond information
          2. nodes tensor, containing atom information
      The input vectors need to be in one-hot encoding format.
      Use MolGAN featurizer for that purpose. It will be simplified
      in the future release.
      """
      adjacency_tensor = layers.Input(
          shape=(self.vertices, self.vertices, self.edges)
      )
      node_tensor = layers.Input(shape=(self.vertices, self.nodes))
  
      graph = MolGANEncoderLayer(
          units=[(128, 64), 128],
          dropout_rate=self.dropout_rate,
          edges=self.edges,
      )([adjacency_tensor, node_tensor])
      dense = layers.Dense(units=128, activation="tanh")(graph)
      dense = layers.Dropout(self.dropout_rate)(dense)
      dense = layers.Dense(units=64, activation="tanh")(dense)
      dense = layers.Dropout(self.dropout_rate)(dense)
      output = layers.Dense(units=1)(dense)
  
      return keras.Model(
          inputs=[
              adjacency_tensor,
              node_tensor,
          ],
          outputs=[output],
      )
  
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 5 for calling the BasicMolGANModel obj's underlying member method code with example usage: obj.create_discriminator() and returns: keras