class_docstr: Featurizes protein-ligand complex using flat features or a 3D grid (in which
  each voxel is described with a vector of features).
class_docstr_tok: ["Featurizes","protein-ligand","complex","using","flat","features","or","a","3D","grid","(","in","which","each","voxel","is","described","with","a","vector","of","features",")","."]
docstr: Parameters
  ----------
  nb_rotations: int, optional (default 0)
      Number of additional random rotations of a complex to generate.
  feature_types: list, optional (default ['ecfp'])
      Types of features to calculate. Available types are
          flat features -> 'ecfp_ligand', 'ecfp_hashed', 'splif_hashed', 'hbond_count'
          voxel features -> 'ecfp', 'splif', 'sybyl', 'salt_bridge', 'charge', 'hbond', 'pi_stack, 'cation_pi'
      There are also 3 predefined sets of features
          'flat_combined', 'voxel_combined', and 'all_combined'.
      Calculated features are concatenated and their order is preserved
      (features in predefined sets are in alphabetical order).
  ecfp_degree: int, optional (default 2)
      ECFP radius.
  ecfp_power: int, optional (default 3)
      Number of bits to store ECFP features (resulting vector will be
      2^ecfp_power long)
  splif_power: int, optional (default 3)
      Number of bits to store SPLIF features (resulting vector will be
      2^splif_power long)
  box_width: float, optional (default 16.0)
      Size of a box in which voxel features are calculated. Box is centered on a
      ligand centroid.
  voxel_width: float, optional (default 1.0)
      Size of a 3D voxel in a grid.
  flatten: bool, optional (defaul False)
      Indicate whether calculated features should be flattened. Output is always
      flattened if flat features are specified in feature_types.
  verbose: bool, optional (defaul True)
      Verbolity for logging
  sanitize: bool, optional (defaul False)
      If set to True molecules will be sanitized. Note that calculating some
      features (e.g. aromatic interactions) require sanitized molecules.
  **kwargs: dict, optional
      Keyword arguments can be usaed to specify custom cutoffs and bins (see
      default values below).
  
  Default cutoffs and bins
  ------------------------
  hbond_dist_bins: [(2.2, 2.5), (2.5, 3.2), (3.2, 4.0)]
  hbond_angle_cutoffs: [5, 50, 90]
  splif_contact_bins: [(0, 2.0), (2.0, 3.0), (3.0, 4.5)]
  ecfp_cutoff: 4.5
  sybyl_cutoff: 7.0
  salt_bridges_cutoff: 5.0
  pi_stack_dist_cutoff: 4.4
  pi_stack_angle_cutoff: 30.0
  cation_pi_dist_cutoff: 6.5
  cation_pi_angle_cutoff: 30.0
docstr_tok: ["Parameters","--","--","--","--","--","nb_rotations",":","int",",","optional","(","default","0",")","Number","of","additional","random","rotations","of","a","complex","to","generate",".","feature_types",":","list",",","optional","(","default","[","'ecfp","'","]",")","Types","of","features","to","calculate",".","Available","types","are","flat","features","-",">","'ecfp_ligand","'",",","'ecfp_hashed","'",",","'splif_hashed","'",",","'hbond_count'","voxel","features","-",">","'ecfp","'",",","'splif","'",",","'sybyl","'",",","'salt_bridge","'",",","'charge","'",",","'hbond","'",",","'pi_stack",",","'cation_pi'","There","are","also","3","predefined","sets","of","features","'flat_combined","'",",","'voxel_combined","'",",","and","'all_combined","'",".","Calculated","features","are","concatenated","and","their","order","is","preserved","(","features","in","predefined","sets","are","in","alphabetical","order",")",".","ecfp_degree",":","int",",","optional","(","default","2",")","ECFP","radius",".","ecfp_power",":","int",",","optional","(","default","3",")","Number","of","bits","to","store","ECFP","features","(","resulting","vector","will","be","2^ecfp_power","long",")","splif_power",":","int",",","optional","(","default","3",")","Number","of","bits","to","store","SPLIF","features","(","resulting","vector","will","be","2^splif_power","long",")","box_width",":","float",",","optional","(","default","16.0",")","Size","of","a","box","in","which","voxel","features","are","calculated",".","Box","is","centered","on","a","ligand","centroid",".","voxel_width",":","float",",","optional","(","default","1.0",")","Size","of","a","3D","voxel","in","a","grid",".","flatten",":","bool",",","optional","(","defaul","False",")","Indicate","whether","calculated","features","should","be","flattened",".","Output","is","always","flattened","if","flat","features","are","specified","in","feature_types",".","verbose",":","bool",",","optional","(","defaul","True",")","Verbolity","for","logging","sanitize",":","bool",",","optional","(","defaul","False",")","If","set","to","True","molecules","will","be","sanitized",".","Note","that","calculating","some","features","(","e.g",".","aromatic","interactions",")","require","sanitized","molecules",".","*","*","kwargs",":","dict",",","optional","Keyword","arguments","can","be","usaed","to","specify","custom","cutoffs","and","bins","(","see","default","values","below",")",".","Default","cutoffs","and","bins","--","--","--","--","--","--","--","--","--","--","--","--","hbond_dist_bins",":","[","(","2.2",",","2.5",")",",","(","2.5",",","3.2",")",",","(","3.2",",","4.0",")","]","hbond_angle_cutoffs",":","[","5",",","50",",","90","]","splif_contact_bins",":","[","(","0",",","2.0",")",",","(","2.0",",","3.0",")",",","(","3.0",",","4.5",")","]","ecfp_cutoff",":","4.5","sybyl_cutoff",":","7.0","salt_bridges_cutoff",":","5.0","pi_stack_dist_cutoff",":","4.4","pi_stack_angle_cutoff",":","30.0","cation_pi_dist_cutoff",":","6.5","cation_pi_angle_cutoff",":","30.0"]
code: def __init__(
      self,
      nb_rotations=0,
      feature_types=None,
      ecfp_degree=2,
      ecfp_power=3,
      splif_power=3,
      box_width=16.0,
      voxel_width=1.0,
      flatten=False,
      verbose=True,
      sanitize=False,
      **kwargs,
  ):
      """
      Parameters
      ----------
      nb_rotations: int, optional (default 0)
          Number of additional random rotations of a complex to generate.
      feature_types: list, optional (default ['ecfp'])
          Types of features to calculate. Available types are
              flat features -> 'ecfp_ligand', 'ecfp_hashed', 'splif_hashed', 'hbond_count'
              voxel features -> 'ecfp', 'splif', 'sybyl', 'salt_bridge', 'charge', 'hbond', 'pi_stack, 'cation_pi'
          There are also 3 predefined sets of features
              'flat_combined', 'voxel_combined', and 'all_combined'.
          Calculated features are concatenated and their order is preserved
          (features in predefined sets are in alphabetical order).
      ecfp_degree: int, optional (default 2)
          ECFP radius.
      ecfp_power: int, optional (default 3)
          Number of bits to store ECFP features (resulting vector will be
          2^ecfp_power long)
      splif_power: int, optional (default 3)
          Number of bits to store SPLIF features (resulting vector will be
          2^splif_power long)
      box_width: float, optional (default 16.0)
          Size of a box in which voxel features are calculated. Box is centered on a
          ligand centroid.
      voxel_width: float, optional (default 1.0)
          Size of a 3D voxel in a grid.
      flatten: bool, optional (defaul False)
          Indicate whether calculated features should be flattened. Output is always
          flattened if flat features are specified in feature_types.
      verbose: bool, optional (defaul True)
          Verbolity for logging
      sanitize: bool, optional (defaul False)
          If set to True molecules will be sanitized. Note that calculating some
          features (e.g. aromatic interactions) require sanitized molecules.
      **kwargs: dict, optional
          Keyword arguments can be usaed to specify custom cutoffs and bins (see
          default values below).
  
      Default cutoffs and bins
      ------------------------
      hbond_dist_bins: [(2.2, 2.5), (2.5, 3.2), (3.2, 4.0)]
      hbond_angle_cutoffs: [5, 50, 90]
      splif_contact_bins: [(0, 2.0), (2.0, 3.0), (3.0, 4.5)]
      ecfp_cutoff: 4.5
      sybyl_cutoff: 7.0
      salt_bridges_cutoff: 5.0
      pi_stack_dist_cutoff: 4.4
      pi_stack_angle_cutoff: 30.0
      cation_pi_dist_cutoff: 6.5
      cation_pi_angle_cutoff: 30.0
      """
  
      # check if user tries to set removed arguments
      deprecated_args = [
          "box_x",
          "box_y",
          "box_z",
          "save_intermediates",
          "voxelize_features",
          "parallel",
          "voxel_feature_types",
      ]
  
      # list of features that require sanitized molecules
      require_sanitized = ["pi_stack", "cation_pi", "ecfp_ligand"]
  
      # not implemented featurization types
      not_implemented = ["sybyl"]
  
      for arg in deprecated_args:
          if arg in kwargs and verbose:
              logger.warning(
                  "%s argument was removed and it is ignored,"
                  " using it will result in error in version 1.4" % arg,
                  DeprecationWarning,
              )
  
      self.verbose = verbose
      self.sanitize = sanitize
      self.flatten = flatten
  
      self.ecfp_degree = ecfp_degree
      self.ecfp_power = ecfp_power
      self.splif_power = splif_power
  
      self.nb_rotations = nb_rotations
  
      # default values
      self.cutoffs = {
          "hbond_dist_bins": [(2.2, 2.5), (2.5, 3.2), (3.2, 4.0)],
          "hbond_angle_cutoffs": [5, 50, 90],
          "splif_contact_bins": [(0, 2.0), (2.0, 3.0), (3.0, 4.5)],
          "ecfp_cutoff": 4.5,
          "sybyl_cutoff": 7.0,
          "salt_bridges_cutoff": 5.0,
          "pi_stack_dist_cutoff": 4.4,
          "pi_stack_angle_cutoff": 30.0,
          "cation_pi_dist_cutoff": 6.5,
          "cation_pi_angle_cutoff": 30.0,
      }
  
      # update with cutoffs specified by the user
      for arg, value in kwargs.items():
          if arg in self.cutoffs:
              self.cutoffs[arg] = value
  
      self.box_width = float(box_width)
      self.voxel_width = float(voxel_width)
      self.voxels_per_edge = int(self.box_width / self.voxel_width)
  
      self.sybyl_types = [
          "C3",
          "C2",
          "C1",
          "Cac",
          "Car",
          "N3",
          "N3+",
          "Npl",
          "N2",
          "N1",
          "Ng+",
          "Nox",
          "Nar",
          "Ntr",
          "Nam",
          "Npl3",
          "N4",
          "O3",
          "O-",
          "O2",
          "O.co2",
          "O.spc",
          "O.t3p",
          "S3",
          "S3+",
          "S2",
          "So2",
          "Sox" "Sac" "SO",
          "P3",
          "P",
          "P3+",
          "F",
          "Cl",
          "Br",
          "I",
      ]
  
      self.FLAT_FEATURES = [
          "ecfp_ligand",
          "ecfp_hashed",
          "splif_hashed",
          "hbond_count",
      ]
      self.VOXEL_FEATURES = [
          "ecfp",
          "splif",
          "sybyl",
          "salt_bridge",
          "charge",
          "hbond",
          "pi_stack",
          "cation_pi",
      ]
  
      if feature_types is None:
          feature_types = ["ecfp"]
  
      # each entry is a tuple (is_flat, feature_name)
      self.feature_types = []
  
      # list of features that cannot be calculated with specified parameters
      # this list is used to define <flat/voxel/all>_combined subset
      ignored_features = []
      if self.sanitize is False:
          ignored_features += require_sanitized
      ignored_features += not_implemented
  
      # parse provided feature types
      for feature_type in feature_types:
          if (
              self.sanitize is False
              and feature_type in require_sanitized
          ):
              if self.verbose:
                  logger.warning(
                      "sanitize is set to False, %s feature will be ignored"
                      % feature_type
                  )
              continue
          if feature_type in not_implemented:
              if self.verbose:
                  logger.warning(
                      "%s feature is not implemented yet and will be ignored"
                      % feature_type
                  )
              continue
  
          if feature_type in self.FLAT_FEATURES:
              self.feature_types.append((True, feature_type))
              if self.flatten is False:
                  if self.verbose:
                      logger.warning(
                          "%s feature is used, output will be flattened"
                          % feature_type
                      )
                  self.flatten = True
  
          elif feature_type in self.VOXEL_FEATURES:
              self.feature_types.append((False, feature_type))
  
          elif feature_type == "flat_combined":
              self.feature_types += [
                  (True, ftype)
                  for ftype in sorted(self.FLAT_FEATURES)
                  if ftype not in ignored_features
              ]
              if self.flatten is False:
                  if self.verbose:
                      logger.warning(
                          "Flat features are used, output will be flattened"
                      )
                  self.flatten = True
  
          elif feature_type == "voxel_combined":
              self.feature_types += [
                  (False, ftype)
                  for ftype in sorted(self.VOXEL_FEATURES)
                  if ftype not in ignored_features
              ]
          elif feature_type == "all_combined":
              self.feature_types += [
                  (True, ftype)
                  for ftype in sorted(self.FLAT_FEATURES)
                  if ftype not in ignored_features
              ]
              self.feature_types += [
                  (False, ftype)
                  for ftype in sorted(self.VOXEL_FEATURES)
                  if ftype not in ignored_features
              ]
              if self.flatten is False:
                  if self.verbose:
                      logger.warning(
                          "Flat feature are used, output will be flattened"
                      )
                  self.flatten = True
          elif self.verbose:
              logger.warning(
                  "Ignoring unknown feature %s" % feature_type
              )
  
file_path: deepchem/deepchem/feat/complex_featurizers/rdkit_grid_featurizer.py
imports: import logging
  import time
  from deepchem.utils.rdkit_utils import MoleculeLoadException, load_molecule, compute_ecfp_features
  from deepchem.utils.geometry_utils import rotate_molecules, compute_pairwise_distances, compute_centroid, subtract_centroid
  from deepchem.utils.hash_utils import hash_ecfp, hash_ecfp_pair, hash_sybyl, vectorize
  from deepchem.utils.noncovalent_utils import compute_hydrogen_bonds, compute_salt_bridges, compute_binding_pocket_cation_pi
  from deepchem.utils.voxel_utils import convert_atom_to_voxel, convert_atom_pair_to_voxel, voxelize, voxelize_pi_stack
  from deepchem.feat.complex_featurizers.contact_fingerprints import featurize_contacts_ecfp, featurize_binding_pocket_sybyl
  from deepchem.feat.complex_featurizers.splif_fingerprints import featurize_splif
  from deepchem.feat.complex_featurizers.grid_featurizers import compute_charge_dictionary
  import numpy
  from deepchem.feat import ComplexFeaturizer
label_desc: Use image node_id 1 to create a new RdkitGridFeaturizer object from inherited base classes: ComplexFeaturizer with example: obj = RdkitGridFeaturizer(nb_rotations, feature_types, ecfp_degree, ecfp_power, splif_power, box_width, voxel_width, flatten, verbose, sanitize)