parameters: (metadata, component_results)
return_statement: return results
docstring: Assembles N-body components into interaction quantities according to requested BSSE procedure(s).
  
      Parameters
      -----------
      metadata : dict of str
          Dictionary of N-body metadata.
  
          Required ``'key': value`` pairs:
              ``'ptype'``: {'energy', 'gradient', 'hessian'}
                     Procedure which has generated the N-body components to be combined.
              ``'bsse_type_list'``: list of str
                     List of requested BSSE treatments.  Possible values include lowercase ``'cp'``, ``'nocp'``,
                     and ``'vmfc'``.
              ``'max_nbody'``: int
                     Maximum number of bodies to include in the N-Body treatment.
                     Possible: `max_nbody` <= `max_frag`
                     Default: `max_nbody` = `max_frag`
              ``'max_frag'``: int
                     Number of distinct fragments comprising full molecular supersystem.
              ``'energies_dict'``: dict of set: float64
                     Dictionary containing all energy components required for given N-body procedure.
              ``'ptype_dict'``: dict of set: float64 or dict of set: psi4.Matrix
                     Dictionary of returned quantities from calls of function `func` during N-body computations
              ``'compute_dict'``: dict of str: dict
                     Dictionary containing {int: set} subdicts enumerating compute lists for each possible
                     BSSE treatment.
              ``'kwargs'``: dict
                     Arbitrary keyword arguments.
      component_results : dict of str: dict
          Dictionary containing computed N-body components.
  
          Required ``'key': value`` pairs:
          ``'energies'``: dict of set: float64
                 Dictionary containing all energy components required for given N-body procedure.
          ``'ptype'``: dict of set: float64 or dict of set: psi4.Matrix
                 Dictionary of returned quantities from calls of function `func` during N-body computations
          ``'intermediates'``: dict of str: float64
                 Dictionary of psivars for intermediate N-body computations to be set at the end of the
                 N-body procedure.
      Returns
      -------
      results : dict of str
          Dictionary of all N-body results.
  
          Contents:
          ``'ret_energy'``: float64
              Interaction data requested.  If multiple BSSE types requested in `bsse_type_list`, the interaction data associated with the *first* BSSE
              type in the list is returned.
          ``'nbody_dict'``: dict of str: float64
              Dictionary of relevant N-body psivars to be set
          ``'energy_body_dict'``: dict of int: float64
              Dictionary of total energies at each N-body level, i.e., ``results['energy_body_dict'][2]`` is the sum of all 2-body total energies
              for the supersystem. May be empty if ``return_total_data`` is ``False``.
          ``'ptype_body_dict'``: dict or dict of int: array_like
              Empty dictionary if `ptype is ``'energy'``, or dictionary of total ptype
              arrays at each N-body level; i.e., ``results['ptype_body_dict'][2]``
              for `ptype` ``'gradient'``is the total 2-body gradient.
docstring_summary: Assembles N-body components into interaction quantities according to requested BSSE procedure(s).
docstring_tokens: Assembles N - body components into interaction quantities according to requested BSSE procedure ( s ) .
function: def assemble_nbody_components(metadata, component_results):
      """Assembles N-body components into interaction quantities according to requested BSSE procedure(s).
  
      Parameters
      -----------
      metadata : dict of str
          Dictionary of N-body metadata.
  
          Required ``'key': value`` pairs:
              ``'ptype'``: {'energy', 'gradient', 'hessian'}
                     Procedure which has generated the N-body components to be combined.
              ``'bsse_type_list'``: list of str
                     List of requested BSSE treatments.  Possible values include lowercase ``'cp'``, ``'nocp'``,
                     and ``'vmfc'``.
              ``'max_nbody'``: int
                     Maximum number of bodies to include in the N-Body treatment.
                     Possible: `max_nbody` <= `max_frag`
                     Default: `max_nbody` = `max_frag`
              ``'max_frag'``: int
                     Number of distinct fragments comprising full molecular supersystem.
              ``'energies_dict'``: dict of set: float64
                     Dictionary containing all energy components required for given N-body procedure.
              ``'ptype_dict'``: dict of set: float64 or dict of set: psi4.Matrix
                     Dictionary of returned quantities from calls of function `func` during N-body computations
              ``'compute_dict'``: dict of str: dict
                     Dictionary containing {int: set} subdicts enumerating compute lists for each possible
                     BSSE treatment.
              ``'kwargs'``: dict
                     Arbitrary keyword arguments.
      component_results : dict of str: dict
          Dictionary containing computed N-body components.
  
          Required ``'key': value`` pairs:
          ``'energies'``: dict of set: float64
                 Dictionary containing all energy components required for given N-body procedure.
          ``'ptype'``: dict of set: float64 or dict of set: psi4.Matrix
                 Dictionary of returned quantities from calls of function `func` during N-body computations
          ``'intermediates'``: dict of str: float64
                 Dictionary of psivars for intermediate N-body computations to be set at the end of the
                 N-body procedure.
      Returns
      -------
      results : dict of str
          Dictionary of all N-body results.
  
          Contents:
          ``'ret_energy'``: float64
              Interaction data requested.  If multiple BSSE types requested in `bsse_type_list`, the interaction data associated with the *first* BSSE
              type in the list is returned.
          ``'nbody_dict'``: dict of str: float64
              Dictionary of relevant N-body psivars to be set
          ``'energy_body_dict'``: dict of int: float64
              Dictionary of total energies at each N-body level, i.e., ``results['energy_body_dict'][2]`` is the sum of all 2-body total energies
              for the supersystem. May be empty if ``return_total_data`` is ``False``.
          ``'ptype_body_dict'``: dict or dict of int: array_like
              Empty dictionary if `ptype is ``'energy'``, or dictionary of total ptype
              arrays at each N-body level; i.e., ``results['ptype_body_dict'][2]``
              for `ptype` ``'gradient'``is the total 2-body gradient.
      """
      # Unpack metadata
      kwargs = metadata['kwargs']
  
      nbody_range = range(1, metadata['max_nbody'] + 1)
  
      # Unpack compute list metadata
      compute_list = metadata['compute_dict']['all']
      cp_compute_list = metadata['compute_dict']['cp']
      nocp_compute_list = metadata['compute_dict']['nocp']
      vmfc_compute_list = metadata['compute_dict']['vmfc_compute']
      vmfc_level_list = metadata['compute_dict']['vmfc_levels']
  
  
      # Build size and slices dictionaries
      fragment_size_dict = {
          frag: metadata['molecule'].extract_subsets(frag).natom()
          for frag in range(1, metadata['max_frag'] + 1)
      }
      start = 0
      fragment_slice_dict = {}
      for k, v in fragment_size_dict.items():
          fragment_slice_dict[k] = slice(start, start + v)
          start += v
  
      molecule_total_atoms = sum(fragment_size_dict.values())
  
      # Final dictionaries
      cp_energy_by_level = {n: 0.0 for n in nbody_range}
      nocp_energy_by_level = {n: 0.0 for n in nbody_range}
  
      cp_energy_body_dict = {n: 0.0 for n in nbody_range}
      nocp_energy_body_dict = {n: 0.0 for n in nbody_range}
      vmfc_energy_body_dict = {n: 0.0 for n in nbody_range}
  
      # Build out ptype dictionaries if needed
      if metadata['ptype'] != 'energy':
          if metadata['ptype'] == 'gradient':
              arr_shape = (molecule_total_atoms, 3)
          elif metadata['ptype'] == 'hessian':
              arr_shape = (molecule_total_atoms * 3, molecule_total_atoms * 3)
          else:
              raise KeyError("N-Body: ptype '%s' not recognized" % ptype)
  
          cp_ptype_by_level = {n: np.zeros(arr_shape) for n in nbody_range}
          nocp_ptype_by_level = {n: np.zeros(arr_shape) for n in nbody_range}
          vmfc_ptype_by_level = {n: np.zeros(arr_shape) for n in nbody_range}
  
          cp_ptype_body_dict = {n: np.zeros(arr_shape) for n in nbody_range}
          nocp_ptype_body_dict = {n: np.zeros(arr_shape) for n in nbody_range}
          vmfc_ptype_body_dict = {n: np.zeros(arr_shape) for n in nbody_range}
      else:
          cp_ptype_by_level, cp_ptype_body_dict = {}, {}
          nocp_ptype_by_level, nocp_ptype_body_dict = {}, {}
          vmfc_ptype_body_dict = {}
  
      # Sum up all of the levels
      nbody_dict = {}
      for n in nbody_range:
  
          # Energy
          # Extract energies for monomers in monomer basis for CP total data
          if n == 1:
              monomers_in_monomer_basis = [v for v in nocp_compute_list[1] if len(v[1]) == 1]
              monomer_energies = 0.0
              monomer_energy_list = []
              for i in monomers_in_monomer_basis:
                  monomer_energy_list.append(component_results['energies'][i])
                  monomer_energies += component_results['energies'][i]
  
  
          cp_energy_by_level[n] = sum(component_results['energies'][v] for v in cp_compute_list[n])
          nocp_energy_by_level[n] = sum(component_results['energies'][v] for v in nocp_compute_list[n])
  
          # Special vmfc case
          if n > 1:
              vmfc_energy_body_dict[n] = vmfc_energy_body_dict[n - 1]
          for tup in vmfc_level_list[n]:
              vmfc_energy_body_dict[n] += ((-1)**(n - len(tup[0]))) * component_results['energies'][tup]
  
          # Do ptype
          if metadata['ptype'] != 'energy':
              _sum_cluster_ptype_data(metadata['ptype'], component_results['ptype'], cp_compute_list[n],
                                      fragment_slice_dict, fragment_size_dict, cp_ptype_by_level[n])
              _sum_cluster_ptype_data(metadata['ptype'], component_results['ptype'], nocp_compute_list[n],
                                      fragment_slice_dict, fragment_size_dict, nocp_ptype_by_level[n])
              _sum_cluster_ptype_data(
                  metadata['ptype'],
                  component_results['ptype'],
                  vmfc_level_list[n],
                  fragment_slice_dict,
                  fragment_size_dict,
                  vmfc_ptype_by_level[n],
                  vmfc=True,
                  n=n)
  
      if metadata['ptype'] != 'energy':
          # Extract ptype data for monomers in monomer basis for CP total data
          monomer_ptype = np.zeros(arr_shape)
          _sum_cluster_ptype_data(metadata['ptype'], component_results['ptype'], monomers_in_monomer_basis,
                                  fragment_slice_dict, fragment_size_dict, monomer_ptype)
  
      # Compute cp energy and ptype
      if 'cp' in metadata['bsse_type_list']:
          for n in nbody_range:
              if n == metadata['max_frag']:
                  cp_energy_body_dict[n] = cp_energy_by_level[n] - bsse
                  if metadata['ptype'] != 'energy':
                      cp_ptype_body_dict[n][:] = cp_ptype_by_level[n] - bsse_ptype
                  continue
  
              for k in range(1, n + 1):
                  take_nk = nCr(metadata['max_frag'] - k - 1, n - k)
                  sign = ((-1)**(n - k))
                  value = cp_energy_by_level[k]
                  cp_energy_body_dict[n] += take_nk * sign * value
  
                  if metadata['ptype'] != 'energy':
                      value = cp_ptype_by_level[k]
                      cp_ptype_body_dict[n] += take_nk * sign * value
  
              if n == 1:
                  bsse = cp_energy_body_dict[n] - monomer_energies
                  cp_energy_body_dict[n] = monomer_energies
                  if metadata['ptype'] != 'energy':
                      bsse_ptype = cp_ptype_body_dict[n] - monomer_ptype
                      cp_ptype_body_dict[n] = monomer_ptype.copy()
  
              else:
                  cp_energy_body_dict[n] -= bsse
                  if metadata['ptype'] != 'energy':
                      cp_ptype_body_dict[n] -= bsse_ptype
  
          cp_interaction_energy = cp_energy_body_dict[metadata['max_nbody']] - cp_energy_body_dict[1]
          nbody_dict['Counterpoise Corrected Interaction Energy'] = cp_interaction_energy
  
          for n in nbody_range[1:]:
              var_key = 'CP-CORRECTED %d-BODY INTERACTION ENERGY' % n
              nbody_dict[var_key] = cp_energy_body_dict[n] - cp_energy_body_dict[1]
  
          _print_nbody_energy(cp_energy_body_dict, "Counterpoise Corrected (CP)", metadata['embedding_charges'])
          cp_interaction_energy = cp_energy_body_dict[metadata['max_nbody']] - cp_energy_body_dict[1]
          if monomer_energies != 0.0:
              nbody_dict['Counterpoise Corrected Total Energy'] = cp_energy_body_dict[metadata['max_nbody']]
          nbody_dict['Counterpoise Corrected Interaction Energy'] = cp_interaction_energy
  
      # Compute nocp energy and ptype
      if 'nocp' in metadata['bsse_type_list']:
          for n in nbody_range:
              if n == metadata['max_frag']:
                  nocp_energy_body_dict[n] = nocp_energy_by_level[n]
                  if metadata['ptype'] != 'energy':
                      nocp_ptype_body_dict[n][:] = nocp_ptype_by_level[n]
                  continue
  
              for k in range(1, n + 1):
                  take_nk = nCr(metadata['max_frag'] - k - 1, n - k)
                  sign = ((-1)**(n - k))
                  value = nocp_energy_by_level[k]
                  nocp_energy_body_dict[n] += take_nk * sign * value
  
                  if metadata['ptype'] != 'energy':
                      value = nocp_ptype_by_level[k]
                      nocp_ptype_body_dict[n] += take_nk * sign * value
  
          _print_nbody_energy(nocp_energy_body_dict, "Non-Counterpoise Corrected (NoCP)", metadata['embedding_charges'])
          nocp_interaction_energy = nocp_energy_body_dict[metadata['max_nbody']] - nocp_energy_body_dict[1]
          nbody_dict['Non-Counterpoise Corrected Total Energy'] = nocp_energy_body_dict[metadata['max_nbody']]
          nbody_dict['Non-Counterpoise Corrected Interaction Energy'] = nocp_interaction_energy
  
          for n in nbody_range[1:]:
              var_key = 'NOCP-CORRECTED %d-BODY INTERACTION ENERGY' % n
              nbody_dict[var_key] = nocp_energy_body_dict[n] - nocp_energy_body_dict[1]
  
      # Compute vmfc ptype
      if 'vmfc' in metadata['bsse_type_list']:
          if metadata['ptype'] != 'energy':
              for n in nbody_range:
                  if n > 1:
                      vmfc_ptype_body_dict[n] = vmfc_ptype_by_level[n - 1]
                  vmfc_ptype_body_dict[n] += vmfc_ptype_by_level[n]
  
          _print_nbody_energy(vmfc_energy_body_dict, "Valiron-Mayer Function Couterpoise (VMFC)",
                              metadata['embedding_charges'])
          vmfc_interaction_energy = vmfc_energy_body_dict[metadata['max_nbody']] - vmfc_energy_body_dict[1]
          nbody_dict['Valiron-Mayer Function Couterpoise Total Energy'] = vmfc_energy_body_dict[metadata['max_nbody']]
          nbody_dict['Valiron-Mayer Function Couterpoise Interaction Energy'] = vmfc_interaction_energy
  
          for n in nbody_range[1:]:
              var_key = 'VMFC-CORRECTED %d-BODY INTERACTION ENERGY' % n
              nbody_dict[var_key] = vmfc_energy_body_dict[n] - vmfc_energy_body_dict[1]
  
      # Returns
      results = {}
      results['nbody'] = nbody_dict
      for b in ['cp', 'nocp', 'vmfc']:
          if monomer_energies != 0.0:
              results['%s_energy_body_dict' % b] = eval('%s_energy_body_dict' % b)
              results['%s_energy_body_dict' % b] = {str(i) + b: j for i, j in results['%s_energy_body_dict' % b].items()}
          else:
              results['%s_energy_body_dict' % b] = {}
  
      # Figure out and build return types
      return_method = metadata['bsse_type_list'][0]
  
      if return_method == 'cp':
          results['ptype_body_dict'] = cp_ptype_body_dict
          results['energy_body_dict'] = cp_energy_body_dict
      elif return_method == 'nocp':
          results['ptype_body_dict'] = nocp_ptype_body_dict
          results['energy_body_dict'] = nocp_energy_body_dict
      elif return_method == 'vmfc':
          results['ptype_body_dict'] = vmfc_ptype_body_dict
          results['energy_body_dict'] = vmfc_energy_body_dict
      else:
          raise ValidationError(
              "N-Body Wrapper: Invalid return type. Should never be here, please post this error on github.")
  
      if metadata['return_total_data']:
          results['ret_energy'] = results['energy_body_dict'][metadata['max_nbody']]
      else:
          results['ret_energy'] = results['energy_body_dict'][metadata['max_nbody']]
          results['ret_energy'] -= results['energy_body_dict'][1]
  
      if metadata['ptype'] != 'energy':
          if metadata['return_total_data']:
              np_final_ptype = results['ptype_body_dict'][metadata['max_nbody']].copy()
          else:
              np_final_ptype = results['ptype_body_dict'][metadata['max_nbody']].copy()
              np_final_ptype -= results['ptype_body_dict'][1]
  
          results['ret_ptype'] = core.Matrix.from_array(np_final_ptype)
      else:
          results['ret_ptype'] = results['ret_energy']
  
      if monomer_energies == 0.0:
          del results['energy_body_dict']
  
      return results
function_tokens: def assemble_nbody_components ( metadata , component_results ) : # Unpack metadata kwargs = metadata [ 'kwargs' ] nbody_range = range ( 1 , metadata [ 'max_nbody' ] + 1 ) # Unpack compute list metadata compute_list = metadata [ 'compute_dict' ] [ 'all' ] cp_compute_list = metadata [ 'compute_dict' ] [ 'cp' ] nocp_compute_list = metadata [ 'compute_dict' ] [ 'nocp' ] vmfc_compute_list = metadata [ 'compute_dict' ] [ 'vmfc_compute' ] vmfc_level_list = metadata [ 'compute_dict' ] [ 'vmfc_levels' ] # Build size and slices dictionaries fragment_size_dict = { frag : metadata [ 'molecule' ] . extract_subsets ( frag ) . natom ( ) for frag in range ( 1 , metadata [ 'max_frag' ] + 1 ) } start = 0 fragment_slice_dict = { } for k , v in fragment_size_dict . items ( ) : fragment_slice_dict [ k ] = slice ( start , start + v ) start += v molecule_total_atoms = sum ( fragment_size_dict . values ( ) ) # Final dictionaries cp_energy_by_level = { n : 0.0 for n in nbody_range } nocp_energy_by_level = { n : 0.0 for n in nbody_range } cp_energy_body_dict = { n : 0.0 for n in nbody_range } nocp_energy_body_dict = { n : 0.0 for n in nbody_range } vmfc_energy_body_dict = { n : 0.0 for n in nbody_range } # Build out ptype dictionaries if needed if metadata [ 'ptype' ] != 'energy' : if metadata [ 'ptype' ] == 'gradient' : arr_shape = ( molecule_total_atoms , 3 ) elif metadata [ 'ptype' ] == 'hessian' : arr_shape = ( molecule_total_atoms * 3 , molecule_total_atoms * 3 ) else : raise KeyError ( "N-Body: ptype '%s' not recognized" % ptype ) cp_ptype_by_level = { n : np . zeros ( arr_shape ) for n in nbody_range } nocp_ptype_by_level = { n : np . zeros ( arr_shape ) for n in nbody_range } vmfc_ptype_by_level = { n : np . zeros ( arr_shape ) for n in nbody_range } cp_ptype_body_dict = { n : np . zeros ( arr_shape ) for n in nbody_range } nocp_ptype_body_dict = { n : np . zeros ( arr_shape ) for n in nbody_range } vmfc_ptype_body_dict = { n : np . zeros ( arr_shape ) for n in nbody_range } else : cp_ptype_by_level , cp_ptype_body_dict = { } , { } nocp_ptype_by_level , nocp_ptype_body_dict = { } , { } vmfc_ptype_body_dict = { } # Sum up all of the levels nbody_dict = { } for n in nbody_range : # Energy # Extract energies for monomers in monomer basis for CP total data if n == 1 : monomers_in_monomer_basis = [ v for v in nocp_compute_list [ 1 ] if len ( v [ 1 ] ) == 1 ] monomer_energies = 0.0 monomer_energy_list = [ ] for i in monomers_in_monomer_basis : monomer_energy_list . append ( component_results [ 'energies' ] [ i ] ) monomer_energies += component_results [ 'energies' ] [ i ] cp_energy_by_level [ n ] = sum ( component_results [ 'energies' ] [ v ] for v in cp_compute_list [ n ] ) nocp_energy_by_level [ n ] = sum ( component_results [ 'energies' ] [ v ] for v in nocp_compute_list [ n ] ) # Special vmfc case if n > 1 : vmfc_energy_body_dict [ n ] = vmfc_energy_body_dict [ n - 1 ] for tup in vmfc_level_list [ n ] : vmfc_energy_body_dict [ n ] += ( ( - 1 ) ** ( n - len ( tup [ 0 ] ) ) ) * component_results [ 'energies' ] [ tup ] # Do ptype if metadata [ 'ptype' ] != 'energy' : _sum_cluster_ptype_data ( metadata [ 'ptype' ] , component_results [ 'ptype' ] , cp_compute_list [ n ] , fragment_slice_dict , fragment_size_dict , cp_ptype_by_level [ n ] ) _sum_cluster_ptype_data ( metadata [ 'ptype' ] , component_results [ 'ptype' ] , nocp_compute_list [ n ] , fragment_slice_dict , fragment_size_dict , nocp_ptype_by_level [ n ] ) _sum_cluster_ptype_data ( metadata [ 'ptype' ] , component_results [ 'ptype' ] , vmfc_level_list [ n ] , fragment_slice_dict , fragment_size_dict , vmfc_ptype_by_level [ n ] , vmfc = True , n = n ) if metadata [ 'ptype' ] != 'energy' : # Extract ptype data for monomers in monomer basis for CP total data monomer_ptype = np . zeros ( arr_shape ) _sum_cluster_ptype_data ( metadata [ 'ptype' ] , component_results [ 'ptype' ] , monomers_in_monomer_basis , fragment_slice_dict , fragment_size_dict , monomer_ptype ) # Compute cp energy and ptype if 'cp' in metadata [ 'bsse_type_list' ] : for n in nbody_range : if n == metadata [ 'max_frag' ] : cp_energy_body_dict [ n ] = cp_energy_by_level [ n ] - bsse if metadata [ 'ptype' ] != 'energy' : cp_ptype_body_dict [ n ] [ : ] = cp_ptype_by_level [ n ] - bsse_ptype continue for k in range ( 1 , n + 1 ) : take_nk = nCr ( metadata [ 'max_frag' ] - k - 1 , n - k ) sign = ( ( - 1 ) ** ( n - k ) ) value = cp_energy_by_level [ k ] cp_energy_body_dict [ n ] += take_nk * sign * value if metadata [ 'ptype' ] != 'energy' : value = cp_ptype_by_level [ k ] cp_ptype_body_dict [ n ] += take_nk * sign * value if n == 1 : bsse = cp_energy_body_dict [ n ] - monomer_energies cp_energy_body_dict [ n ] = monomer_energies if metadata [ 'ptype' ] != 'energy' : bsse_ptype = cp_ptype_body_dict [ n ] - monomer_ptype cp_ptype_body_dict [ n ] = monomer_ptype . copy ( ) else : cp_energy_body_dict [ n ] -= bsse if metadata [ 'ptype' ] != 'energy' : cp_ptype_body_dict [ n ] -= bsse_ptype cp_interaction_energy = cp_energy_body_dict [ metadata [ 'max_nbody' ] ] - cp_energy_body_dict [ 1 ] nbody_dict [ 'Counterpoise Corrected Interaction Energy' ] = cp_interaction_energy for n in nbody_range [ 1 : ] : var_key = 'CP-CORRECTED %d-BODY INTERACTION ENERGY' % n nbody_dict [ var_key ] = cp_energy_body_dict [ n ] - cp_energy_body_dict [ 1 ] _print_nbody_energy ( cp_energy_body_dict , "Counterpoise Corrected (CP)" , metadata [ 'embedding_charges' ] ) cp_interaction_energy = cp_energy_body_dict [ metadata [ 'max_nbody' ] ] - cp_energy_body_dict [ 1 ] if monomer_energies != 0.0 : nbody_dict [ 'Counterpoise Corrected Total Energy' ] = cp_energy_body_dict [ metadata [ 'max_nbody' ] ] nbody_dict [ 'Counterpoise Corrected Interaction Energy' ] = cp_interaction_energy # Compute nocp energy and ptype if 'nocp' in metadata [ 'bsse_type_list' ] : for n in nbody_range : if n == metadata [ 'max_frag' ] : nocp_energy_body_dict [ n ] = nocp_energy_by_level [ n ] if metadata [ 'ptype' ] != 'energy' : nocp_ptype_body_dict [ n ] [ : ] = nocp_ptype_by_level [ n ] continue for k in range ( 1 , n + 1 ) : take_nk = nCr ( metadata [ 'max_frag' ] - k - 1 , n - k ) sign = ( ( - 1 ) ** ( n - k ) ) value = nocp_energy_by_level [ k ] nocp_energy_body_dict [ n ] += take_nk * sign * value if metadata [ 'ptype' ] != 'energy' : value = nocp_ptype_by_level [ k ] nocp_ptype_body_dict [ n ] += take_nk * sign * value _print_nbody_energy ( nocp_energy_body_dict , "Non-Counterpoise Corrected (NoCP)" , metadata [ 'embedding_charges' ] ) nocp_interaction_energy = nocp_energy_body_dict [ metadata [ 'max_nbody' ] ] - nocp_energy_body_dict [ 1 ] nbody_dict [ 'Non-Counterpoise Corrected Total Energy' ] = nocp_energy_body_dict [ metadata [ 'max_nbody' ] ] nbody_dict [ 'Non-Counterpoise Corrected Interaction Energy' ] = nocp_interaction_energy for n in nbody_range [ 1 : ] : var_key = 'NOCP-CORRECTED %d-BODY INTERACTION ENERGY' % n nbody_dict [ var_key ] = nocp_energy_body_dict [ n ] - nocp_energy_body_dict [ 1 ] # Compute vmfc ptype if 'vmfc' in metadata [ 'bsse_type_list' ] : if metadata [ 'ptype' ] != 'energy' : for n in nbody_range : if n > 1 : vmfc_ptype_body_dict [ n ] = vmfc_ptype_by_level [ n - 1 ] vmfc_ptype_body_dict [ n ] += vmfc_ptype_by_level [ n ] _print_nbody_energy ( vmfc_energy_body_dict , "Valiron-Mayer Function Couterpoise (VMFC)" , metadata [ 'embedding_charges' ] ) vmfc_interaction_energy = vmfc_energy_body_dict [ metadata [ 'max_nbody' ] ] - vmfc_energy_body_dict [ 1 ] nbody_dict [ 'Valiron-Mayer Function Couterpoise Total Energy' ] = vmfc_energy_body_dict [ metadata [ 'max_nbody' ] ] nbody_dict [ 'Valiron-Mayer Function Couterpoise Interaction Energy' ] = vmfc_interaction_energy for n in nbody_range [ 1 : ] : var_key = 'VMFC-CORRECTED %d-BODY INTERACTION ENERGY' % n nbody_dict [ var_key ] = vmfc_energy_body_dict [ n ] - vmfc_energy_body_dict [ 1 ] # Returns results = { } results [ 'nbody' ] = nbody_dict for b in [ 'cp' , 'nocp' , 'vmfc' ] : if monomer_energies != 0.0 : results [ '%s_energy_body_dict' % b ] = eval ( '%s_energy_body_dict' % b ) results [ '%s_energy_body_dict' % b ] = { str ( i ) + b : j for i , j in results [ '%s_energy_body_dict' % b ] . items ( ) } else : results [ '%s_energy_body_dict' % b ] = { } # Figure out and build return types return_method = metadata [ 'bsse_type_list' ] [ 0 ] if return_method == 'cp' : results [ 'ptype_body_dict' ] = cp_ptype_body_dict results [ 'energy_body_dict' ] = cp_energy_body_dict elif return_method == 'nocp' : results [ 'ptype_body_dict' ] = nocp_ptype_body_dict results [ 'energy_body_dict' ] = nocp_energy_body_dict elif return_method == 'vmfc' : results [ 'ptype_body_dict' ] = vmfc_ptype_body_dict results [ 'energy_body_dict' ] = vmfc_energy_body_dict else : raise ValidationError ( "N-Body Wrapper: Invalid return type. Should never be here, please post this error on github." ) if metadata [ 'return_total_data' ] : results [ 'ret_energy' ] = results [ 'energy_body_dict' ] [ metadata [ 'max_nbody' ] ] else : results [ 'ret_energy' ] = results [ 'energy_body_dict' ] [ metadata [ 'max_nbody' ] ] results [ 'ret_energy' ] -= results [ 'energy_body_dict' ] [ 1 ] if metadata [ 'ptype' ] != 'energy' : if metadata [ 'return_total_data' ] : np_final_ptype = results [ 'ptype_body_dict' ] [ metadata [ 'max_nbody' ] ] . copy ( ) else : np_final_ptype = results [ 'ptype_body_dict' ] [ metadata [ 'max_nbody' ] ] . copy ( ) np_final_ptype -= results [ 'ptype_body_dict' ] [ 1 ] results [ 'ret_ptype' ] = core . Matrix . from_array ( np_final_ptype ) else : results [ 'ret_ptype' ] = results [ 'ret_energy' ] if monomer_energies == 0.0 : del results [ 'energy_body_dict' ] return results