



from typing import Dict, Optional, Tuple

import torch
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						torch.Tensor					)->torch.Tensor:
      _lowerCAmelCase			      =	boundaries[1] - boundaries[0]
      _lowerCAmelCase			      =	boundaries + step / 2
      _lowerCAmelCase			      =	torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1					)]  ,					dim=0					)
      return bin_centers
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						torch.Tensor  ,					_SCREAMING_SNAKE_CASE :						torch.Tensor  ,					)->Tuple[torch.Tensor, torch.Tensor]:
      _lowerCAmelCase			      =	_calculate_bin_centers(_SCREAMING_SNAKE_CASE					)
      return (
          torch.sum(aligned_distance_error_probs * bin_centers  ,					dim=-1					),
          bin_centers[-1],
      )
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						torch.Tensor  ,					_SCREAMING_SNAKE_CASE :						int = 3_1  ,					_SCREAMING_SNAKE_CASE :						int = 6_4  ,					**_SCREAMING_SNAKE_CASE :						Tuple  ,					)->Dict[str, torch.Tensor]:
      _lowerCAmelCase			      =	torch.linspace(0  ,					_SCREAMING_SNAKE_CASE  ,					steps=(no_bins - 1)  ,					device=logits.device					)

      _lowerCAmelCase			      =	torch.nn.functional.softmax(_SCREAMING_SNAKE_CASE  ,					dim=-1					)
      _lowerCAmelCase      , _lowerCAmelCase			      =	_calculate_expected_aligned_error(
          alignment_confidence_breaks=_SCREAMING_SNAKE_CASE  ,					aligned_distance_error_probs=_SCREAMING_SNAKE_CASE  ,					)

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


def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						torch.Tensor  ,					_SCREAMING_SNAKE_CASE :						Optional[torch.Tensor] = None  ,					_SCREAMING_SNAKE_CASE :						int = 3_1  ,					_SCREAMING_SNAKE_CASE :						int = 6_4  ,					_SCREAMING_SNAKE_CASE :						float = 1e-8  ,					**_SCREAMING_SNAKE_CASE :						str  ,					)->torch.Tensor:
      if residue_weights is None:
            _lowerCAmelCase			      =	logits.new_ones(logits.shape[-2]					)

      _lowerCAmelCase			      =	torch.linspace(0  ,					_SCREAMING_SNAKE_CASE  ,					steps=(no_bins - 1)  ,					device=logits.device					)

      _lowerCAmelCase			      =	_calculate_bin_centers(_SCREAMING_SNAKE_CASE					)
      torch.sum(_SCREAMING_SNAKE_CASE					)
      _lowerCAmelCase			      =	logits.shape[-2]
      _lowerCAmelCase			      =	max(_SCREAMING_SNAKE_CASE  ,					1_9					)

      _lowerCAmelCase			      =	1.24 * (clipped_n - 1_5) ** (1.0 / 3) - 1.8

      _lowerCAmelCase			      =	torch.nn.functional.softmax(_SCREAMING_SNAKE_CASE  ,					dim=-1					)

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

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

      _lowerCAmelCase			      =	per_alignment * residue_weights

      _lowerCAmelCase			      =	(weighted == torch.max(_SCREAMING_SNAKE_CASE					)).nonzero()[0]
      return per_alignment[tuple(_SCREAMING_SNAKE_CASE					)]




def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						float  ,					_SCREAMING_SNAKE_CASE :						float					)->float:
      _lowerCAmelCase			      =	float()
      try:
            _lowerCAmelCase			      =	mass * acceleration
      except Exception:
            return -0.0
      return force


if __name__ == "__main__":
    import doctest

    # run doctest
    doctest.testmod()

    # demo
    UpperCAmelCase_          =				12.5
    UpperCAmelCase_          =				1_0
    UpperCAmelCase_          =				newtons_second_law_of_motion(mass, acceleration)
    print("The force is ", force, "N")