class_docstr: Class for doing data splits by molecular weight.
  
  Note
  ----
  This class requires RDKit to be installed.
  
  Examples
  --------
  >>> import deepchem as dc
  >>> import numpy as np
  >>> # creation of demo data set with some smiles strings
  >>> smiles= ['C', 'CC', 'CCC', 'CCCC', 'CCCCC']
  >>> Xs = np.zeros(len(smiles))
  >>> # creation of a deepchem dataset with the smile codes in the ids field
  >>> dataset = dc.data.DiskDataset.from_numpy(X=Xs,ids=smiles)
  >>> molecularweightsplitter = dc.splits.MolecularWeightSplitter()
  >>> train_dataset, test_dataset = molecularweightsplitter.train_test_split(dataset)
  >>> print(train_dataset.ids)
  ['C' 'CC' 'CCC' 'CCCC']
  >>> print(test_dataset.ids)
  ['CCCCC']
class_docstr_tok: ["Class","for","doing","data","splits","by","molecular","weight",".","Note","--","--","This","class","requires","RDKit","to","be","installed",".","Examples","--","--","--","--",">",">",">","import","deepchem","as","dc",">",">",">","import","numpy","as","np",">",">",">","#","creation","of","demo","data","set","with","some","smiles","strings",">",">",">","smiles=","[","'","C","'",",","'CC","'",",","'CCC","'",",","'CCCC","'",",","'CCCCC","'","]",">",">",">","Xs","=","np.zeros","(","len","(","smiles",")",")",">",">",">","#","creation","of","a","deepchem","dataset","with","the","smile","codes","in","the","ids","field",">",">",">","dataset","=","dc.data.DiskDataset.from_numpy","(","X=Xs",",","ids=smiles",")",">",">",">","molecularweightsplitter","=","dc.splits.MolecularWeightSplitter","(",")",">",">",">","train_dataset",",","test_dataset","=","molecularweightsplitter.train_test_split","(","dataset",")",">",">",">","print","(","train_dataset.ids",")","[","'","C","'","'CC","'","'CCC","'","'CCCC","'","]",">",">",">","print","(","test_dataset.ids",")","[","'CCCCC","'","]"]
docstr: Splits on molecular weight.
  
  Splits internal compounds into train/validation/test using the MW
  calculated by SMILES string.
  
  Parameters
  ----------
  dataset: Dataset
      Dataset to be split.
  frac_train: float, optional (default 0.8)
      The fraction of data to be used for the training split.
  frac_valid: float, optional (default 0.1)
      The fraction of data to be used for the validation split.
  frac_test: float, optional (default 0.1)
      The fraction of data to be used for the test split.
  seed: int, optional (default None)
      Random seed to use.
  log_every_n: int, optional (default None)
      Log every n examples (not currently used).
  
  Returns
  -------
  Tuple[np.ndarray, np.ndarray, np.ndarray]
      A tuple of train indices, valid indices, and test indices.
      Each indices is a numpy array.
docstr_tok: ["Splits","on","molecular","weight",".","Splits","internal","compounds","into","train\/validation\/test","using","the","MW","calculated","by","SMILES","string",".","Parameters","--","--","--","--","--","dataset",":","Dataset","Dataset","to","be","split",".","frac_train",":","float",",","optional","(","default","0.8",")","The","fraction","of","data","to","be","used","for","the","training","split",".","frac_valid",":","float",",","optional","(","default","0.1",")","The","fraction","of","data","to","be","used","for","the","validation","split",".","frac_test",":","float",",","optional","(","default","0.1",")","The","fraction","of","data","to","be","used","for","the","test","split",".","seed",":","int",",","optional","(","default","None",")","Random","seed","to","use",".","log_every_n",":","int",",","optional","(","default","None",")","Log","every","n","examples","(","not","currently","used",")",".","Returns","--","--","--","-","Tuple","[","np.ndarray",",","np.ndarray",",","np.ndarray","]","A","tuple","of","train","indices",",","valid","indices",",","and","test","indices",".","Each","indices","is","a","numpy","array","."]
code: def split(
      self,
      dataset: Dataset,
      frac_train: float = 0.8,
      frac_valid: float = 0.1,
      frac_test: float = 0.1,
      seed: Optional[int] = None,
      log_every_n: Optional[int] = None,
  ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
      """Splits on molecular weight.
  
      Splits internal compounds into train/validation/test using the MW
      calculated by SMILES string.
  
      Parameters
      ----------
      dataset: Dataset
          Dataset to be split.
      frac_train: float, optional (default 0.8)
          The fraction of data to be used for the training split.
      frac_valid: float, optional (default 0.1)
          The fraction of data to be used for the validation split.
      frac_test: float, optional (default 0.1)
          The fraction of data to be used for the test split.
      seed: int, optional (default None)
          Random seed to use.
      log_every_n: int, optional (default None)
          Log every n examples (not currently used).
  
      Returns
      -------
      Tuple[np.ndarray, np.ndarray, np.ndarray]
          A tuple of train indices, valid indices, and test indices.
          Each indices is a numpy array.
      """
      try:
          from rdkit import Chem
      except ModuleNotFoundError:
          raise ImportError(
              "This function requires RDKit to be installed."
          )
  
      np.testing.assert_almost_equal(
          frac_train + frac_valid + frac_test, 1.0
      )
      if seed is not None:
          np.random.seed(seed)
  
      mws = []
      for smiles in dataset.ids:
          mol = Chem.MolFromSmiles(smiles)
          mw = Chem.rdMolDescriptors.CalcExactMolWt(mol)
          mws.append(mw)
  
      # Sort by increasing MW
      sortidx = np.argsort(mws)
  
      train_cutoff = int(frac_train * len(sortidx))
      valid_cutoff = int((frac_train + frac_valid) * len(sortidx))
  
      return (
          sortidx[:train_cutoff],
          sortidx[train_cutoff:valid_cutoff],
          sortidx[valid_cutoff:],
      )
  
imports: import inspect
  import itertools
  import logging
  import os
  import random
  import tempfile
  from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple, Union
  import deepchem
  import numpy
  import pandas
  from deepchem.data import Dataset, DiskDataset
  from deepchem.utils import get_print_threshold
label_desc: Use image node_id 1 for calling the MolecularWeightSplitter obj's underlying member method code with example usage: obj.split(dataset, frac_train, frac_valid, frac_test, seed, log_every_n) and returns: sortidx,  sortidx,  sortidx