class_docstr: Atom Vocabulary Builder for Grover
  
  This module can be used to generate atom vocabulary from SMILES strings for
  the GROVER pretraining task. For each atom in a molecule, the vocabulary context is the
  node-edge-count of the atom where node is the neighboring atom, edge is the type of bond (single
  bond or double bound) and count is the number of such node-edge pairs for the atom in its
  neighborhood. For example, for the molecule 'CC(=O)C', the context of the first carbon atom is
  C-SINGLE1 because it's neighbor is C atom, the type of bond is SINGLE bond and the count of such
  bonds is 1. The context of the second carbon atom is C-SINGLE2 and O-DOUBLE1 because
  it is connected to two carbon atoms by a single bond and 1 O atom by a double bond.
  The vocabulary of an atom is then computed as the `atom-symbol_contexts` where the contexts
  are sorted in alphabetical order when there are multiple contexts. For example, the
  vocabulary of second C is `C_C-SINGLE2_O-DOUBLE1`. The algorithm enumerates vocabulary of all atoms
  in the dataset and makes a vocabulary to index mapping by sorting the vocabulary
  by frequency and then alphabetically.
  
  The algorithm enumerates vocabulary of all atoms 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'], ['CC(=O)C']])
  >>> vocab = GroverAtomVocabularyBuilder()
  >>> vocab.build(dataset)
  >>> vocab.stoi
  {'<pad>': 0, '<other>': 1, 'C_C-SINGLE1': 2, 'C_C-SINGLE2': 3, 'C_C-SINGLE2_O-DOUBLE1': 4, 'O_C-DOUBLE1': 5}
  >>> vocab.save(file.name)
  >>> loaded_vocab = GroverAtomVocabularyBuilder.load(file.name)
  >>> mol = Chem.MolFromSmiles('CC(=O)C')
  >>> loaded_vocab.encode(mol, mol.GetAtomWithIdx(1))
  4
  
  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: ["Atom","Vocabulary","Builder","for","Grover","This","module","can","be","used","to","generate","atom","vocabulary","from","SMILES","strings","for","the","GROVER","pretraining","task",".","For","each","atom","in","a","molecule",",","the","vocabulary","context","is","the","node-edge-count","of","the","atom","where","node","is","the","neighboring","atom",",","edge","is","the","type","of","bond","(","single","bond","or","double","bound",")","and","count","is","the","number","of","such","node-edge","pairs","for","the","atom","in","its","neighborhood",".","For","example",",","for","the","molecule","'CC","(","=O",")","C","'",",","the","context","of","the","first","carbon","atom","is","C-SINGLE1","because","it","'s","neighbor","is","C","atom",",","the","type","of","bond","is","SINGLE","bond","and","the","count","of","such","bonds","is","1",".","The","context","of","the","second","carbon","atom","is","C-SINGLE2","and","O-DOUBLE1","because","it","is","connected","to","two","carbon","atoms","by","a","single","bond","and","1","O","atom","by","a","double","bond",".","The","vocabulary","of","an","atom","is","then","computed","as","the","`","atom-symbol_contexts","`","where","the","contexts","are","sorted","in","alphabetical","order","when","there","are","multiple","contexts",".","For","example",",","the","vocabulary","of","second","C","is","`","C_C-SINGLE2_O-DOUBLE1","`",".","The","algorithm","enumerates","vocabulary","of","all","atoms","in","the","dataset","and","makes","a","vocabulary","to","index","mapping","by","sorting","the","vocabulary","by","frequency","and","then","alphabetically",".","The","algorithm","enumerates","vocabulary","of","all","atoms","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","'","]",",","[","'CC","(","=O",")","C","'","]","]",")",">",">",">","vocab","=","GroverAtomVocabularyBuilder","(",")",">",">",">","vocab.build","(","dataset",")",">",">",">","vocab.stoi","{","'","<","pad",">","'",":","0",",","'","<","other",">","'",":","1",",","'C_C-SINGLE1","'",":","2",",","'C_C-SINGLE2","'",":","3",",","'C_C-SINGLE2_O-DOUBLE1","'",":","4",",","'O_C-DOUBLE1","'",":","5","}",">",">",">","vocab.save","(","file.name",")",">",">",">","loaded_vocab","=","GroverAtomVocabularyBuilder.load","(","file.name",")",">",">",">","mol","=","Chem.MolFromSmiles","(","'CC","(","=O",")","C","'",")",">",">",">","loaded_vocab.encode","(","mol",",","mol.GetAtomWithIdx","(","1",")",")","4","Reference","--","--","--","--","-","..","Rong",",","Yu",",","et","al",".","``","Self-supervised","graph","transformer","on","large-scale","molecular","data",".","''","Advances","in","Neural","Information","Processing","Systems","33","(","2020",")",":","12559-12571","."]
docstr: Builds vocabulary from csv file
  
  Parameters
  ----------
  csv_path: str
      Path to csv file containing smiles string
  smiles_field: str
      Name of column containing smiles string
  log_every_n: int, default 1000
      Logs vocabulary building progress every `log_every_n` steps.
docstr_tok: ["Builds","vocabulary","from","csv","file","Parameters","--","--","--","--","--","csv_path",":","str","Path","to","csv","file","containing","smiles","string","smiles_field",":","str","Name","of","column","containing","smiles","string","log_every_n",":","int",",","default","1000","Logs","vocabulary","building","progress","every","`","log_every_n","`","steps","."]
code: def build_from_csv(
      self, csv_path: str, smiles_field: str, log_every_n: int = 1000
  ) -> None:
      """Builds vocabulary from csv file
  
      Parameters
      ----------
      csv_path: str
          Path to csv file containing smiles string
      smiles_field: str
          Name of column containing smiles string
      log_every_n: int, default 1000
          Logs vocabulary building progress every `log_every_n` steps.
      """
      counter: Dict[str, int] = Counter()
      logger.info("Starting to build atom vocabulary")
      chunksize = 8196
      for i, df in enumerate(
          pd.read_csv(csv_path, chunksize=chunksize)
      ):
          for index, row in df.iterrows():
              if (i * chunksize + index) % log_every_n == 0:
                  logger.info(
                      "Computing contextual property of atoms in molecule %i"
                      % i
                  )
              smiles = row[smiles_field]
              mol = Chem.MolFromSmiles(smiles)
              for atom in mol.GetAtoms():
                  v = self.atom_to_vocab(mol, atom)
                  counter[v] += 1
  
      logger.info(
          "Completed enumeration of atom contextual properties."
      )
      # sort first by frequency, then alphabetically
      words_and_frequencies = sorted(
          counter.items(), key=lambda tup: tup[0]
      )
      words_and_frequencies.sort(key=lambda tup: tup[1], reverse=True)
      for word, freq in words_and_frequencies:
          if len(self.itos) == self.size:
              break
          self.itos.append(word)
      if self.size is None:
          self.size = len(self.itos)
      self.stoi = self._make_reverse_mapping(self.itos)
      logger.info("Completed building of atom vocabulary")
  
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 3 for calling the GroverAtomVocabularyBuilder obj's underlying member method code with example usage: obj.build_from_csv(csv_path, smiles_field, log_every_n) without return types