Commit 79f854c6 authored by abster12's avatar abster12
Browse files

integrating the model to deepchem

parent 41af486a
Loading
Loading
Loading
Loading
+37 −14
Original line number Diff line number Diff line
@@ -5,17 +5,33 @@ from deepchem.models.tensorgraph.layers import ReduceMean, InputFifoQueue, ReLU,
from deepchem.models.tensorgraph.tensor_graph import TensorGraph


class Scscore(TensorGraph):
class SCScore(Tensorgraph):

  tg = dc.models.TensorGraph(
      tensorboard=True, model_dir='/tmp/scscore', use_queue=True)
  def __init__(self,
               FP_len=1024,
               FP_rad=2,
               score_scale=5.0,
               offset_loss=0.25,
               **kwargs):

  reactant_features = Feature()
  product_features = Feature()
    self.FP_len = FP_len
    self.FP_rad = FP_rad
    self.score_scale = score_scale
    self.offset_loss = offset_loss
    super(SCScore, self).__init__(**kwargs)
    self.build_graph()

  def build_graph(self):

    self.reactant_features = Feature(shape=())
    self.product_features = Feature(shape=())

    in_layer_reactant = self.reactant_features
    in_layer_product = self.product_features

  dense_reactant_1 = Dense(
      out_channels=300, in_layers=[reactant_features], activation_fn=tf.nn.relu)
  dense_product_1 = dense_reactant_1.shared(in_layers=[product_features])
      out_channels=300, in_layers=[in_layer_reactant], activation_fn=tf.nn.relu)
  dense_product_1 = dense_reactant_1.shared(in_layers=[in_layer_product])
  dense_reactant_2 = Dense(
      out_channels=300, in_layers=[dense_reactant_1], activation_fn=tf.nn.relu)
  dense_product_2 = dense_reactant_2.shared(in_layers=[dense_product_1])
@@ -26,15 +42,22 @@ class Scscore(TensorGraph):
      out_channels=300, in_layers=[dense_reactant_3], activation_fn=tf.nn.relu)
  dense_product_4 = dense_reactant_4.shared(in_layers=[dense_product_3])
  dense_reactant_5 = Dense(
      out_channels=300, in_layers=[dense_reactant_4], activation_fn=tf.nn.relu)
      out_channels=1, in_layers=[dense_reactant_4], activation_fn=tf.nn.relu)
  dense_product_5 = dense_reactant_5.shared(in_layers=[dense_product_4])

  output_reactant = Sigmoid(in_layers=[dense_reactant_5])
  output_product = Sigmoid(in_layers=[dense_product_5])
  output = tf.subtract(output_product, output_reactant)
  tg.add_output(output)
  output_score_reactant = Sigmoid(in_layers=[dense_reactant_5])
  output_score_product = Sigmoid(in_layers=[dense_product_5])

  scaled_score_reactant = 1.0 + (self.score_scale - 1.0) * output_score_reactant
  scaled_score_product = 1.0 + (self.score_scale - 1.0) * output_score_product

  output = scaled_score_product - scaled_score_reactant
  self.add_output(output)

  label = Label(shape=(None, 1))
  self.my_labels.append(label)

  modified_output = output + 0.75

  loss = Hingeloss(in_layers=[output_product, output_reactant])
  tg.set_loss(loss)
  loss = Hingeloss(in_layers=[self.my_labels, modified_output])
  self.set_loss(loss)