

from typing import Dict, Optional, Tuple

import torch



def    snake_case_(_UpperCamelCase  )							->			torch.Tensor:



  """simple docstring"""






  _snake_case		=							boundaries[1] - boundaries[0]
  _snake_case		=							boundaries + step / 2
  _snake_case		=							torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1  )]				, dim=0  )
  return bin_centers



def    snake_case_(_UpperCamelCase				, _UpperCamelCase				, )							->			Tuple[torch.Tensor, torch.Tensor]:



  """simple docstring"""






  _snake_case		=							_calculate_bin_centers(_UpperCamelCase  )
  return (
      torch.sum(aligned_distance_error_probs * bin_centers				, dim=-1  ),
      bin_centers[-1],
  )



def    snake_case_(_UpperCamelCase				, _UpperCamelCase = 31				, _UpperCamelCase = 64				, **_UpperCamelCase				, )							->			Dict[str, torch.Tensor]:



  """simple docstring"""






  _snake_case		=							torch.linspace(0				, _UpperCamelCase				, steps=(no_bins - 1)				, device=logits.device  )

  _snake_case		=							torch.nn.functional.softmax(_UpperCamelCase				, dim=-1  )
  _snake_case,  _snake_case		=							_calculate_expected_aligned_error(
      alignment_confidence_breaks=_UpperCamelCase				, aligned_distance_error_probs=_UpperCamelCase				, )

  return {
      "aligned_confidence_probs": aligned_confidence_probs,
      "predicted_aligned_error": predicted_aligned_error,
      "max_predicted_aligned_error": max_predicted_aligned_error,
  }



def    snake_case_(_UpperCamelCase				, _UpperCamelCase = None				, _UpperCamelCase = 31				, _UpperCamelCase = 64				, _UpperCamelCase = 1E-8				, **_UpperCamelCase				, )							->			torch.Tensor:



  """simple docstring"""






  if residue_weights is None:
    _snake_case		=							logits.new_ones(logits.shape[-2]  )

  _snake_case		=							torch.linspace(0				, _UpperCamelCase				, steps=(no_bins - 1)				, device=logits.device  )

  _snake_case		=							_calculate_bin_centers(_UpperCamelCase  )
  torch.sum(_UpperCamelCase  )
  _snake_case		=							logits.shape[-2]
  _snake_case		=							max(_UpperCamelCase				, 19  )

  _snake_case		=							1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

  _snake_case		=							torch.nn.functional.softmax(_UpperCamelCase				, dim=-1  )

  _snake_case		=							1.0 / (1 + (bin_centers**2) / (da**2))
  _snake_case		=							torch.sum(probs * tm_per_bin				, dim=-1  )

  _snake_case		=							residue_weights / (eps + residue_weights.sum())
  _snake_case		=							torch.sum(predicted_tm_term * normed_residue_mask				, dim=-1  )

  _snake_case		=							per_alignment * residue_weights

  _snake_case		=							(weighted == torch.max(_UpperCamelCase  )).nonzero()[0]
  return per_alignment[tuple(_UpperCamelCase  )]




from collections import namedtuple

__A    	=			namedtuple('''from_to''', '''from_ to''')

__A    	=			{
    '''atm''': from_to(1, 1),
    '''pascal''': from_to(0.000_0098, 10_13_25),
    '''bar''': from_to(0.98_6923, 1.0_1325),
    '''kilopascal''': from_to(0.0098_6923, 101.325),
    '''megapascal''': from_to(9.8_6923, 0.10_1325),
    '''psi''': from_to(0.06_8046, 14.6959),
    '''inHg''': from_to(0.033_4211, 29.9213),
    '''torr''': from_to(0.0013_1579, 7_60),
}



def    snake_case_(_UpperCamelCase				, _UpperCamelCase				, _UpperCamelCase  )							->			float:



  """simple docstring"""






  if from_type not in PRESSURE_CONVERSION:
    raise ValueError(
        F"""Invalid 'from_type' value: {from_type!r}  Supported values are:\n"""
        + ''', '''.join(_UpperCamelCase  )  )
  if to_type not in PRESSURE_CONVERSION:
    raise ValueError(
        F"""Invalid 'to_type' value: {to_type!r}.  Supported values are:\n"""
        + ''', '''.join(_UpperCamelCase  )  )
  return (
      value * PRESSURE_CONVERSION[from_type].from_ * PRESSURE_CONVERSION[to_type].to
  )


if __name__ == "__main__":
 import doctest

 doctest.testmod()

