class_docstr: Class for doing data splits based on the scaffold of small molecules.
class_docstr_tok: ["Class","for","doing","data","splits","based","on","the","scaffold","of","small","molecules","."]
docstr: Splits internal compounds into train/validation/test by scaffold.
docstr_tok: ["Splits","internal","compounds","into","train\/validation\/test","by","scaffold","."]
code: def split(
      self,
      dataset,
      frac_train=0.8,
      frac_valid=0.1,
      frac_test=0.1,
      log_every_n=1000,
  ):
      """
      Splits internal compounds into train/validation/test by scaffold.
      """
      np.testing.assert_almost_equal(
          frac_train + frac_valid + frac_test, 1.0
      )
      scaffolds = {}
      log("About to generate scaffolds", self.verbose)
      data_len = len(dataset)
      for ind, smiles in enumerate(dataset.ids):
          if ind % log_every_n == 0:
              log(
                  "Generating scaffold %d/%d" % (ind, data_len),
                  self.verbose,
              )
          scaffold = generate_scaffold(smiles)
          if scaffold not in scaffolds:
              scaffolds[scaffold] = [ind]
          else:
              scaffolds[scaffold].append(ind)
      # Sort from largest to smallest scaffold sets
      scaffolds = {
          key: sorted(value) for key, value in scaffolds.items()
      }
      scaffold_sets = [
          scaffold_set
          for (scaffold, scaffold_set) in sorted(
              scaffolds.items(),
              key=lambda x: (len(x[1]), x[1][0]),
              reverse=True,
          )
      ]
      train_cutoff = frac_train * len(dataset)
      valid_cutoff = (frac_train + frac_valid) * len(dataset)
      train_inds, valid_inds, test_inds = [], [], []
      log("About to sort in scaffold sets", self.verbose)
      for scaffold_set in scaffold_sets:
          if len(train_inds) + len(scaffold_set) > train_cutoff:
              if (
                  len(train_inds) + len(valid_inds) + len(scaffold_set)
                  > valid_cutoff
              ):
                  test_inds += scaffold_set
              else:
                  valid_inds += scaffold_set
          else:
              train_inds += scaffold_set
      return train_inds, valid_inds, test_inds
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import unicode_literals
  import tempfile
  import numpy
  import itertools
  from rdkit import Chem
  from rdkit import DataStructs
  from rdkit.Chem import AllChem
  from rdkit.ML.Cluster import Butina
  import deepchem
  from deepchem.data import DiskDataset
  from deepchem.utils import ScaffoldGenerator
  from deepchem.utils.save import log
  from deepchem.data import NumpyDataset
  from deepchem.utils.save import load_data
label_desc: Use image node_id 1 for calling the ScaffoldSplitter obj's underlying member method code with example usage: obj.split(dataset, frac_train, frac_valid, frac_test, log_every_n) and returns: train_inds,  valid_inds,  test_inds