class_docstr: Bond Vocabulary Builder for Grover
  
  This module can be used to generate bond vocabulary from SMILES strings
  for the GROVER pretraining task.
  
  For assigning the vocabulary of a bond, we consider the features of the bond
  and the context of the bond. The context of bond is the feature of the bond under
  consideration and the feature of the bonds of atom in which the bond begins and ends.
  It is formed by the concatenation of atomSymbol-bondFeature-Count where atomSymbol
  is the symbol of neighboring atom, bondFeature is the type of bond and count is the
  number of such atomSymbol-bondFeature pairs in the surrounding context.
  
  The feature of a bond is determined by three sub-features: the type of bond (single or double bond),
  the RDKit StereoConfiguration of the bond and RDKit BondDir. For the C-C bond
  in CCC, the type of bond is SINGLE, its stereo is NONE and the bond does not have
  direction. Hence, the feature of the bond is SINGLE-STEREONONE-NONE.
  
  For assigning the vocabulary, we should also have to look at the neighboring bonds.
  Consider the molecule 'CC(=O)C'. It has three bonds. The C-C bond has two neighbors.
  The first C atom has no other bonds, so it contributes no context. The second C atom
  has one bond with an O atom and one bond with a C atom. Consider the C=O double bond.
  The bond feature is DOUBLE-STEREONONE-NONE. The corresponding context is
  atomSymbol-bondFeature-Count. This gives us C-(DOUBLE-STEREONONE-NONE)1.
  Similary, it also has another bond with a C atom which gives the
  context C-(SINGLE-STEREONONE-NONE)1. Hence, the vocabulary of
  the bond is '(SINGLE-STEREONONE-NONE)_C-(DOUBLE-STEREONONE-NONE)1_C-(SINGLE-STEREONONE-NONE)1'
  
  The algorithm enumerates vocabulary of all bonds in the dataset and makes a vocabulary to
  index mapping by sorting the vocabulary by frequency and then alphabetically. The `max_size`
  parameter can be used for setting the size of the vocabulary. When this parameter is set,
  the algorithm stops adding new words to the index when the vocabulary size reaches `max_size`.
  
  Parameters
  ----------
  max_size: int (optional)
      Maximum size of vocabulary
  
  Example
  -------
  >>> import tempfile
  >>> import deepchem as dc
  >>> from rdkit import Chem
  >>> file = tempfile.NamedTemporaryFile()
  >>> dataset = dc.data.NumpyDataset(X=[['CCC']])
  >>> vocab = GroverBondVocabularyBuilder()
  >>> vocab.build(dataset)
  >>> vocab.stoi
  {'<pad>': 0, '<other>': 1, '(SINGLE-STEREONONE-NONE)_C-(SINGLE-STEREONONE-NONE)1': 2}
  >>> vocab.save(file.name)
  >>> loaded_vocab = GroverBondVocabularyBuilder.load(file.name)
  >>> mol = Chem.MolFromSmiles('CCC')
  >>> loaded_vocab.encode(mol, mol.GetBondWithIdx(0))
  2
  
  Reference
  ---------
  .. Rong, Yu, et al. "Self-supervised graph transformer on large-scale molecular data." Advances in Neural Information Processing Systems 33 (2020): 12559-12571.
class_docstr_tok: ["Bond","Vocabulary","Builder","for","Grover","This","module","can","be","used","to","generate","bond","vocabulary","from","SMILES","strings","for","the","GROVER","pretraining","task",".","For","assigning","the","vocabulary","of","a","bond",",","we","consider","the","features","of","the","bond","and","the","context","of","the","bond",".","The","context","of","bond","is","the","feature","of","the","bond","under","consideration","and","the","feature","of","the","bonds","of","atom","in","which","the","bond","begins","and","ends",".","It","is","formed","by","the","concatenation","of","atomSymbol-bondFeature-Count","where","atomSymbol","is","the","symbol","of","neighboring","atom",",","bondFeature","is","the","type","of","bond","and","count","is","the","number","of","such","atomSymbol-bondFeature","pairs","in","the","surrounding","context",".","The","feature","of","a","bond","is","determined","by","three","sub-features",":","the","type","of","bond","(","single","or","double","bond",")",",","the","RDKit","StereoConfiguration","of","the","bond","and","RDKit","BondDir",".","For","the","C-C","bond","in","CCC",",","the","type","of","bond","is","SINGLE",",","its","stereo","is","NONE","and","the","bond","does","not","have","direction",".","Hence",",","the","feature","of","the","bond","is","SINGLE-STEREONONE-NONE",".","For","assigning","the","vocabulary",",","we","should","also","have","to","look","at","the","neighboring","bonds",".","Consider","the","molecule","'CC","(","=O",")","C","'",".","It","has","three","bonds",".","The","C-C","bond","has","two","neighbors",".","The","first","C","atom","has","no","other","bonds",",","so","it","contributes","no","context",".","The","second","C","atom","has","one","bond","with","an","O","atom","and","one","bond","with","a","C","atom",".","Consider","the","C=O","double","bond",".","The","bond","feature","is","DOUBLE-STEREONONE-NONE",".","The","corresponding","context","is","atomSymbol-bondFeature-Count",".","This","gives","us","C-","(","DOUBLE-STEREONONE-NONE",")","1",".","Similary",",","it","also","has","another","bond","with","a","C","atom","which","gives","the","context","C-","(","SINGLE-STEREONONE-NONE",")","1",".","Hence",",","the","vocabulary","of","the","bond","is","'","(","SINGLE-STEREONONE-NONE",")","_C-","(","DOUBLE-STEREONONE-NONE",")","1_C-","(","SINGLE-STEREONONE-NONE",")","1'","The","algorithm","enumerates","vocabulary","of","all","bonds","in","the","dataset","and","makes","a","vocabulary","to","index","mapping","by","sorting","the","vocabulary","by","frequency","and","then","alphabetically",".","The","`","max_size","`","parameter","can","be","used","for","setting","the","size","of","the","vocabulary",".","When","this","parameter","is","set",",","the","algorithm","stops","adding","new","words","to","the","index","when","the","vocabulary","size","reaches","`","max_size","`",".","Parameters","--","--","--","--","--","max_size",":","int","(","optional",")","Maximum","size","of","vocabulary","Example","--","--","--","-",">",">",">","import","tempfile",">",">",">","import","deepchem","as","dc",">",">",">","from","rdkit","import","Chem",">",">",">","file","=","tempfile.NamedTemporaryFile","(",")",">",">",">","dataset","=","dc.data.NumpyDataset","(","X=","[","[","'CCC","'","]","]",")",">",">",">","vocab","=","GroverBondVocabularyBuilder","(",")",">",">",">","vocab.build","(","dataset",")",">",">",">","vocab.stoi","{","'","<","pad",">","'",":","0",",","'","<","other",">","'",":","1",",","'","(","SINGLE-STEREONONE-NONE",")","_C-","(","SINGLE-STEREONONE-NONE",")","1","'",":","2","}",">",">",">","vocab.save","(","file.name",")",">",">",">","loaded_vocab","=","GroverBondVocabularyBuilder.load","(","file.name",")",">",">",">","mol","=","Chem.MolFromSmiles","(","'CCC","'",")",">",">",">","loaded_vocab.encode","(","mol",",","mol.GetBondWithIdx","(","0",")",")","2","Reference","--","--","--","--","-","..","Rong",",","Yu",",","et","al",".","``","Self-supervised","graph","transformer","on","large-scale","molecular","data",".","''","Advances","in","Neural","Information","Processing","Systems","33","(","2020",")",":","12559-12571","."]
code: def __init__(self, max_size: Optional[int] = None):
      self.specials = ("<pad>", "<other>")
      self.min_freq = 1
      self.size = max_size
      self.itos = list(self.specials)
      self.stoi = self._make_reverse_mapping(self.itos)
      self.pad_index = 0
      self.other_index = 1
  
imports: import json
  import logging
  import numpy
  import pandas
  from typing import Dict, Optional
  from collections import Counter
  from rdkit import Chem
  from deepchem.data import Dataset
  from deepchem.feat.base_classes import Featurizer
  from deepchem.utils.typing import RDKitMol, RDKitAtom, RDKitBond
  from deepchem.feat.vocabulary_builders.vocabulary_builder import VocabularyBuilder
label_desc: Use image node_id 1 to create a new GroverBondVocabularyBuilder object from inherited base classes: VocabularyBuilder with example: obj = GroverBondVocabularyBuilder(max_size)