code: 
  
  
  
  
  
  from typing import Dict, Tuple, overload
  
  import torch
  import torch.types
  from torch import nn
  
  from . import residue_constants as rc
  from .rigid_utils import Rigid, Rotation
  from .tensor_utils import batched_gather
  
  
  @overload
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__	):
  		...
  
  
  @overload
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__	):
  		...
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__	):
  		lowerCamelCase_  :    List[str]   	=			aatype == rc.restype_order['G']
  		lowerCamelCase_  :    List[Any]   	=			rc.atom_order['CA']
  		lowerCamelCase_  :    Union[str, Any]   	=			rc.atom_order['CB']
  		lowerCamelCase_  :    Tuple   	=			torch.where(
  		    is_gly[..., None].expand(*((-1,) * len(is_gly.shape	))       ,3	)       ,all_atom_positions[..., ca_idx, :]       ,all_atom_positions[..., cb_idx, :]       ,)
  
  		if all_atom_masks is not None:
  				lowerCamelCase_  :    List[str]   	=			torch.where(
  				    lowerCAmelCase__       ,all_atom_masks[..., ca_idx]       ,all_atom_masks[..., cb_idx]       ,)
  				return pseudo_beta, pseudo_beta_mask
  		else:
  				return pseudo_beta
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__	):
  		lowerCamelCase_  :    List[str]   	=			batched_gather(
  		    lowerCAmelCase__       ,batch['residx_atom37_to_atom14']       ,dim=-2       ,no_batch_dims=len(atomaa.shape[:-2]	)       ,)
  
  		lowerCamelCase_  :    Any   	=			atomaa_data * batch['atom37_atom_exists'][..., None]
  
  		return atomaa_data
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__	):
  		lowerCamelCase_  :    Union[str, Any]   	=			template_feats['template_aatype']
  		lowerCamelCase_  :    int   	=			template_feats['template_torsion_angles_sin_cos']
  		lowerCamelCase_  :    str   	=			template_feats['template_alt_torsion_angles_sin_cos']
  		lowerCamelCase_  :    Union[str, Any]   	=			template_feats['template_torsion_angles_mask']
  		lowerCamelCase_  :    str   	=			torch.cat(
  		    [
  		        nn.functional.one_hot(lowerCAmelCase__       ,22	),
  		        torsion_angles_sin_cos.reshape(*torsion_angles_sin_cos.shape[:-2]       ,14	),
  		        alt_torsion_angles_sin_cos.reshape(*alt_torsion_angles_sin_cos.shape[:-2]       ,14	),
  		        torsion_angles_mask,
  		    ]       ,dim=-1       ,)
  
  		return template_angle_feat
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__ = False       ,lowerCAmelCase__ = 1e-20       ,lowerCAmelCase__ = 1e8       ,):
  		lowerCamelCase_  :    Any   	=			batch['template_pseudo_beta_mask']
  		lowerCamelCase_  :    Optional[Any]   	=			template_mask[..., None] * template_mask[..., None, :]
  
  		# Compute distogram (this seems to differ slightly from Alg. 5)
  		lowerCamelCase_  :    Tuple   	=			batch['template_pseudo_beta']
  		lowerCamelCase_  :    str   	=			torch.sum((tpb[..., None, :] - tpb[..., None, :, :]) ** 2       ,dim=-1       ,keepdim=lowerCAmelCase__	)
  		lowerCamelCase_  :    int   	=			torch.linspace(lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,device=tpb.device	) ** 2
  		lowerCamelCase_  :    List[Any]   	=			torch.cat([lower[1:], lower.new_tensor([inf]	)]       ,dim=-1	)
  		lowerCamelCase_  :    Tuple   	=			((dgram > lower) * (dgram < upper)).type(dgram.dtype	)
  
  		lowerCamelCase_  :    Optional[int]   	=			[dgram, template_mask_ad[..., None]]
  
  		lowerCamelCase_  :    torch.LongTensor   	=			nn.functional.one_hot(
  		    batch['template_aatype']       ,rc.restype_num + 2       ,)
  
  		lowerCamelCase_  :    Optional[int]   	=			batch['template_aatype'].shape[-1]
  		to_concat.append(aatype_one_hot[..., None, :, :].expand(*aatype_one_hot.shape[:-2]       ,lowerCAmelCase__       ,-1       ,-1	)	)
  		to_concat.append(aatype_one_hot[..., None, :].expand(*aatype_one_hot.shape[:-2]       ,-1       ,lowerCAmelCase__       ,-1	)	)
  
  		lowerCamelCase_  :    str   	=			[rc.atom_order[a] for a in ['N', 'CA', 'C']]
  		lowerCamelCase_  :    Tuple   	=			Rigid.make_transform_from_reference(
  		    n_xyz=batch['template_all_atom_positions'][..., n, :]       ,ca_xyz=batch['template_all_atom_positions'][..., ca, :]       ,c_xyz=batch['template_all_atom_positions'][..., c, :]       ,eps=lowerCAmelCase__       ,)
  		lowerCamelCase_  :    Tuple   	=			rigids.get_trans()[..., None, :, :]
  		lowerCamelCase_  :    Union[str, Any]   	=			rigids[..., None].invert_apply(lowerCAmelCase__	)
  
  		lowerCamelCase_  :    int   	=			torch.rsqrt(eps + torch.sum(rigid_vec**2       ,dim=-1	)	)
  
  		lowerCamelCase_  :    List[str]   	=			batch['template_all_atom_mask']
  		lowerCamelCase_  :    int   	=			t_aa_masks[..., n] * t_aa_masks[..., ca] * t_aa_masks[..., c]
  		lowerCamelCase_  :    Union[str, Any]   	=			template_mask[..., None] * template_mask[..., None, :]
  
  		lowerCamelCase_  :    Any   	=			inv_distance_scalar * template_mask_ad
  		lowerCamelCase_  :    int   	=			rigid_vec * inv_distance_scalar[..., None]
  
  		if not use_unit_vector:
  				lowerCamelCase_  :    List[str]   	=			unit_vector * 0.0
  
  		to_concat.extend(torch.unbind(unit_vector[..., None, :]       ,dim=-1	)	)
  		to_concat.append(template_mask_ad[..., None]	)
  
  		lowerCamelCase_  :    List[str]   	=			torch.cat(lowerCAmelCase__       ,dim=-1	)
  		lowerCamelCase_  :    List[Any]   	=			act * template_mask_ad[..., None]
  
  		return act
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__	):
  		lowerCamelCase_  :    torch.LongTensor   	=			nn.functional.one_hot(batch['extra_msa']       ,23	)
  		lowerCamelCase_  :    Dict   	=			[
  		    msa_ahot,
  		    batch['extra_has_deletion'].unsqueeze(-1	),
  		    batch['extra_deletion_value'].unsqueeze(-1	),
  		]
  		return torch.cat(lowerCAmelCase__       ,dim=-1	)
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,):
  		# [*, N, 8, 4, 4]
  		lowerCamelCase_  :    Union[str, Any]   	=			rrgdf[aatype, ...]
  
  		# [*, N, 8] transformations, i.e.
  		#   One [*, N, 8, 3, 3] rotation matrix and
  		#   One [*, N, 8, 3]    translation matrix
  		lowerCamelCase_  :    Optional[int]   	=			r.from_tensor_axa(lowerCAmelCase__	)
  
  		lowerCamelCase_  :    int   	=			alpha.new_zeros((*((1,) * len(alpha.shape[:-1]	)), 2)	)
  		lowerCamelCase_  :    int   	=			1
  
  		# [*, N, 8, 2]
  		lowerCamelCase_  :    int   	=			torch.cat([bb_rot.expand(*alpha.shape[:-2]       ,-1       ,-1	), alpha]       ,dim=-2	)
  
  		# [*, N, 8, 3, 3]
  		# Produces rotation matrices of the form:
  		# [
  		#   [1, 0  , 0  ],
  		#   [0, a_2,-a_1],
  		#   [0, a_1, a_2]
  		# ]
  		# This follows the original code rather than the supplement, which uses
  		# different indices.
  
  		lowerCamelCase_  :    Union[str, Any]   	=			alpha.new_zeros(default_r.get_rots().get_rot_mats().shape	)
  		lowerCamelCase_  :    List[str]   	=			1
  		lowerCamelCase_  :    Union[str, Any]   	=			alpha[..., 1]
  		lowerCamelCase_  :    List[str]   	=			-alpha[..., 0]
  		lowerCamelCase_  :    Optional[Any]   	=			alpha
  
  		lowerCamelCase_  :    List[Any]   	=			default_r.compose(Rigid(Rotation(rot_mats=lowerCAmelCase__	)       ,lowerCAmelCase__	)	)
  
  		lowerCamelCase_  :    int   	=			all_frames[..., 5]
  		lowerCamelCase_  :    Optional[Any]   	=			all_frames[..., 6]
  		lowerCamelCase_  :    Any   	=			all_frames[..., 7]
  
  		lowerCamelCase_  :    str   	=			all_frames[..., 4]
  		lowerCamelCase_  :    Optional[Any]   	=			chia_frame_to_bb.compose(lowerCAmelCase__	)
  		lowerCamelCase_  :    Optional[Any]   	=			chia_frame_to_bb.compose(lowerCAmelCase__	)
  		lowerCamelCase_  :    Dict   	=			chia_frame_to_bb.compose(lowerCAmelCase__	)
  
  		lowerCamelCase_  :    Union[str, Any]   	=			Rigid.cat(
  		    [
  		        all_frames[..., :5],
  		        chia_frame_to_bb.unsqueeze(-1	),
  		        chia_frame_to_bb.unsqueeze(-1	),
  		        chia_frame_to_bb.unsqueeze(-1	),
  		    ]       ,dim=-1       ,)
  
  		lowerCamelCase_  :    Optional[int]   	=			r[..., None].compose(lowerCAmelCase__	)
  
  		return all_frames_to_global
  
  
  
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,lowerCAmelCase__       ,):
  		# [*, N, 14]
  		lowerCamelCase_  :    Dict   	=			group_idx[aatype, ...]
  
  		# [*, N, 14, 8]
  		lowerCamelCase_  :    torch.LongTensor   	=			nn.functional.one_hot(
  		    lowerCAmelCase__       ,num_classes=default_frames.shape[-3]       ,)
  
  		# [*, N, 14, 8]
  		lowerCamelCase_  :    int   	=			r[..., None, :] * group_mask_one_hot
  
  		# [*, N, 14]
  		lowerCamelCase_  :    Union[str, Any]   	=			t_atoms_to_global.map_tensor_fn(lambda lowerCAmelCase__	: torch.sum(lowerCAmelCase__       ,dim=-1	)	)
  
  		# [*, N, 14, 1]
  		lowerCamelCase_  :    int   	=			atom_mask[aatype, ...].unsqueeze(-1	)
  
  		# [*, N, 14, 3]
  		lowerCamelCase_  :    List[Any]   	=			lit_positions[aatype, ...]
  		lowerCamelCase_  :    List[Any]   	=			t_atoms_to_global.apply(lowerCAmelCase__	)
  		lowerCamelCase_  :    Tuple   	=			pred_positions * atom_mask
  
  		return pred_positions
  
style_context: 
  
  
  
  
  
  from typing import TYPE_CHECKING
  
  from ...utils import (
      OptionalDependencyNotAvailable,
      _LazyModule,
      is_flax_available,
      is_sentencepiece_available,
      is_tf_available,
      is_tokenizers_available,
      is_torch_available,
  )
  
  
  _lowercase		:     int 					={
      """configuration_marian""": ["""MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MarianConfig""", """MarianOnnxConfig"""],
  }
  
  try:
  		if not is_sentencepiece_available():
  				raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  		pass
  else:
  		_lowercase		:     Any 					=["""MarianTokenizer"""]
  
  try:
  		if not is_torch_available():
  				raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  		pass
  else:
  		_lowercase		:     Any 					=[
  		    """MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST""",
  		    """MarianForCausalLM""",
  		    """MarianModel""",
  		    """MarianMTModel""",
  		    """MarianPreTrainedModel""",
  		]
  
  try:
  		if not is_tf_available():
  				raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  		pass
  else:
  		_lowercase		:     Dict 					=["""TFMarianModel""", """TFMarianMTModel""", """TFMarianPreTrainedModel"""]
  
  try:
  		if not is_flax_available():
  				raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  		pass
  else:
  		_lowercase		:     Optional[Any] 					=["""FlaxMarianModel""", """FlaxMarianMTModel""", """FlaxMarianPreTrainedModel"""]
  
  if TYPE_CHECKING:
  		from .configuration_marian import MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP, MarianConfig, MarianOnnxConfig
  
  		try:
  				if not is_sentencepiece_available():
  						raise OptionalDependencyNotAvailable()
  		except OptionalDependencyNotAvailable:
  				pass
  		else:
  				from .tokenization_marian import MarianTokenizer
  
  		try:
  				if not is_torch_available():
  						raise OptionalDependencyNotAvailable()
  		except OptionalDependencyNotAvailable:
  				pass
  		else:
  				from .modeling_marian import (
  				    MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST,
  				    MarianForCausalLM,
  				    MarianModel,
  				    MarianMTModel,
  				    MarianPreTrainedModel,
  				)
  
  		try:
  				if not is_tf_available():
  						raise OptionalDependencyNotAvailable()
  		except OptionalDependencyNotAvailable:
  				pass
  		else:
  				from .modeling_tf_marian import TFMarianModel, TFMarianMTModel, TFMarianPreTrainedModel
  
  		try:
  				if not is_flax_available():
  						raise OptionalDependencyNotAvailable()
  		except OptionalDependencyNotAvailable:
  				pass
  		else:
  				from .modeling_flax_marian import FlaxMarianModel, FlaxMarianMTModel, FlaxMarianPreTrainedModel
  
  else:
  		import sys
  
  		_lowercase		:     List[str] 					=_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
  