




"""simple docstring"""



from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFImageClassifierOutputWithNoAttention,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_resnet import ResNetConfig


SCREAMING_SNAKE_CASE       = logging.get_logger(__name__)

# General docstring
SCREAMING_SNAKE_CASE       = "ResNetConfig"

# Base docstring
SCREAMING_SNAKE_CASE       = "microsoft/resnet-50"
SCREAMING_SNAKE_CASE       = [1, 2048, 7, 7]

# Image classification docstring
SCREAMING_SNAKE_CASE       = "microsoft/resnet-50"
SCREAMING_SNAKE_CASE       = "tiger cat"

SCREAMING_SNAKE_CASE       = [
    "microsoft/resnet-50",
    # See all resnet models at https://huggingface.co/models?filter=resnet
]




class 			UpperCAmelCase_						(		tf.keras.layers.Layer							):




    def __init__(					self		: List[Any]			,				snake_case_		: int			,				snake_case_		: int = 3			,				snake_case_		: int = 1			,				snake_case_		: str = "relu"			,				**snake_case_		: Dict   )   ->							None:




     '''simple docstring'''

     super().__init__(**snake_case_   )
     A__ =       kernel_size // 2
     A__ =       tf.keras.layers.ConvaD(
         snake_case_			,				kernel_size=snake_case_			,				strides=snake_case_			,				padding="valid"			,				use_bias=snake_case_			,				name="convolution"   )
     # Use same default momentum and epsilon as PyTorch equivalent
     A__ =       tf.keras.layers.BatchNormalization(epsilon=1e-5			,				momentum=0.9			,				name="normalization"   )
     A__ =       ACTaFN[activation] if activation is not None else tf.keras.layers.Activation("linear"   )




    def 							__magic_name__							(					self		: Union[str, Any]			,				snake_case_		: tf.Tensor   )   ->							tf.Tensor:




     '''simple docstring'''

     A__ =       A__ =       (self.pad_value, self.pad_value)
     A__ =       tf.pad(snake_case_			,				[(0, 0), height_pad, width_pad, (0, 0)]   )
     A__ =       self.conv(snake_case_   )
     return hidden_state




    def 							__magic_name__							(					self		: Tuple			,				snake_case_		: tf.Tensor			,				snake_case_		: bool = False   )   ->							tf.Tensor:




     '''simple docstring'''

     A__ =       self.convolution(snake_case_   )
     A__ =       self.normalization(snake_case_			,				training=snake_case_   )
     A__ =       self.activation(snake_case_   )
     return hidden_state






class 			UpperCAmelCase_						(		tf.keras.layers.Layer							):




    def __init__(					self		: Any			,				snake_case_		: ResNetConfig			,				**snake_case_		: Union[str, Any]   )   ->							None:




     '''simple docstring'''

     super().__init__(**snake_case_   )
     A__ =       TFResNetConvLayer(
         config.embedding_size			,				kernel_size=7			,				stride=2			,				activation=config.hidden_act			,				name="embedder"			,				)
     A__ =       tf.keras.layers.MaxPoolaD(pool_size=3			,				strides=2			,				padding="valid"			,				name="pooler"   )
     A__ =       config.num_channels




    def 							__magic_name__							(					self		: str			,				snake_case_		: tf.Tensor			,				snake_case_		: bool = False   )   ->							tf.Tensor:




     '''simple docstring'''

     A__,   A__,   A__,   A__ =       shape_list(snake_case_   )
     if tf.executing_eagerly() and num_channels != self.num_channels:
      raise ValueError(
          "Make sure that the channel dimension of the pixel values match with the one set in the configuration."   )
     A__ =       pixel_values
     A__ =       self.embedder(snake_case_   )
     A__ =       tf.pad(snake_case_			,				[[0, 0], [1, 1], [1, 1], [0, 0]]   )
     A__ =       self.pooler(snake_case_   )
     return hidden_state






class 			UpperCAmelCase_						(		tf.keras.layers.Layer							):




    def __init__(					self		: str			,				snake_case_		: int			,				snake_case_		: int = 2			,				**snake_case_		: List[Any]   )   ->							None:




     '''simple docstring'''

     super().__init__(**snake_case_   )
     A__ =       tf.keras.layers.ConvaD(
         snake_case_			,				kernel_size=1			,				strides=snake_case_			,				use_bias=snake_case_			,				name="convolution"   )
     # Use same default momentum and epsilon as PyTorch equivalent
     A__ =       tf.keras.layers.BatchNormalization(epsilon=1e-5			,				momentum=0.9			,				name="normalization"   )




    def 							__magic_name__							(					self		: Dict			,				snake_case_		: tf.Tensor			,				snake_case_		: bool = False   )   ->							tf.Tensor:




     '''simple docstring'''

     A__ =       x
     A__ =       self.convolution(snake_case_   )
     A__ =       self.normalization(snake_case_			,				training=snake_case_   )
     return hidden_state






class 			UpperCAmelCase_						(		tf.keras.layers.Layer							):




    def __init__(					self		: List[str]			,				snake_case_		: int			,				snake_case_		: int			,				snake_case_		: int = 1			,				snake_case_		: str = "relu"			,				**snake_case_		: Optional[Any]   )   ->							None:




     '''simple docstring'''

     super().__init__(**snake_case_   )
     A__ =       in_channels != out_channels or stride != 1
     A__ =       TFResNetConvLayer(snake_case_			,				stride=snake_case_			,				name="layer.0"   )
     A__ =       TFResNetConvLayer(snake_case_			,				activation=snake_case_			,				name="layer.1"   )
     A__ =       (
         TFResNetShortCut(snake_case_			,				stride=snake_case_			,				name="shortcut"   )
         if should_apply_shortcut
         else tf.keras.layers.Activation("linear"			,				name="shortcut"   )
     )
     A__ =       ACTaFN[activation]




    def 							__magic_name__							(					self		: List[str]			,				snake_case_		: tf.Tensor			,				snake_case_		: bool = False   )   ->							tf.Tensor:




     '''simple docstring'''

     A__ =       hidden_state
     A__ =       self.conva(snake_case_			,				training=snake_case_   )
     A__ =       self.conva(snake_case_			,				training=snake_case_   )
     A__ =       self.shortcut(snake_case_			,				training=snake_case_   )
     hidden_state += residual
     A__ =       self.activation(snake_case_   )
     return hidden_state






class 			UpperCAmelCase_						(		tf.keras.layers.Layer							):




    def __init__(					self		: Dict			,				snake_case_		: int			,				snake_case_		: int			,				snake_case_		: int = 1			,				snake_case_		: str = "relu"			,				snake_case_		: int = 4			,				**snake_case_		: Any			,				)   ->							None:




     '''simple docstring'''

     super().__init__(**snake_case_   )
     A__ =       in_channels != out_channels or stride != 1
     A__ =       out_channels // reduction
     A__ =       TFResNetConvLayer(snake_case_			,				kernel_size=1			,				name="layer.0"   )
     A__ =       TFResNetConvLayer(snake_case_			,				stride=snake_case_			,				name="layer.1"   )
     A__ =       TFResNetConvLayer(snake_case_			,				kernel_size=1			,				activation=snake_case_			,				name="layer.2"   )
     A__ =       (
         TFResNetShortCut(snake_case_			,				stride=snake_case_			,				name="shortcut"   )
         if should_apply_shortcut
         else tf.keras.layers.Activation("linear"			,				name="shortcut"   )
     )
     A__ =       ACTaFN[activation]




    def 							__magic_name__							(					self		: str			,				snake_case_		: tf.Tensor			,				snake_case_		: bool = False   )   ->							tf.Tensor:




     '''simple docstring'''

     A__ =       hidden_state
     A__ =       self.conva(snake_case_			,				training=snake_case_   )
     A__ =       self.conva(snake_case_			,				training=snake_case_   )
     A__ =       self.conva(snake_case_			,				training=snake_case_   )
     A__ =       self.shortcut(snake_case_			,				training=snake_case_   )
     hidden_state += residual
     A__ =       self.activation(snake_case_   )
     return hidden_state






class 			UpperCAmelCase_						(		tf.keras.layers.Layer							):




    def __init__(					self		: Optional[int]			,				snake_case_		: ResNetConfig			,				snake_case_		: int			,				snake_case_		: int			,				snake_case_		: int = 2			,				snake_case_		: int = 2			,				**snake_case_		: Union[str, Any]   )   ->							None:




     '''simple docstring'''

     super().__init__(**snake_case_   )

     A__ =       TFResNetBottleNeckLayer if config.layer_type == "bottleneck" else TFResNetBasicLayer

     A__ =       [layer(snake_case_			,				snake_case_			,				stride=snake_case_			,				activation=config.hidden_act			,				name="layers.0"   )]
     layers += [
         layer(snake_case_			,				snake_case_			,				activation=config.hidden_act			,				name=F"""layers.{i + 1}"""   )
         for i in range(depth - 1   )
     ]
     A__ =       layers




    def 							__magic_name__							(					self		: Optional[Any]			,				snake_case_		: tf.Tensor			,				snake_case_		: bool = False   )   ->							tf.Tensor:




     '''simple docstring'''

     for layer in self.stage_layers:
      A__ =       layer(snake_case_			,				training=snake_case_   )
     return hidden_state






class 			UpperCAmelCase_						(		tf.keras.layers.Layer							):




    def __init__(					self		: List[Any]			,				snake_case_		: ResNetConfig			,				**snake_case_		: str   )   ->							None:




     '''simple docstring'''

     super().__init__(**snake_case_   )
     # based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
     A__ =       [
         TFResNetStage(
             snake_case_			,				config.embedding_size			,				config.hidden_sizes[0]			,				stride=2 if config.downsample_in_first_stage else 1			,				depth=config.depths[0]			,				name="stages.0"			,				)
     ]
     for i, (in_channels, out_channels, depth) in enumerate(
         zip(config.hidden_sizes			,				config.hidden_sizes[1:]			,				config.depths[1:]   )   ):
      self.stages.append(TFResNetStage(snake_case_			,				snake_case_			,				snake_case_			,				depth=snake_case_			,				name=F"""stages.{i + 1}"""   )   )




    def 							__magic_name__							(					self		: List[str]			,				snake_case_		: tf.Tensor			,				snake_case_		: bool = False			,				snake_case_		: bool = True			,				snake_case_		: bool = False			,				)   ->							TFBaseModelOutputWithNoAttention:




     '''simple docstring'''

     A__ =       () if output_hidden_states else None

     for stage_module in self.stages:
      if output_hidden_states:
       A__ =       hidden_states + (hidden_state,)

      A__ =       stage_module(snake_case_			,				training=snake_case_   )

     if output_hidden_states:
      A__ =       hidden_states + (hidden_state,)

     if not return_dict:
      return tuple(v for v in [hidden_state, hidden_states] if v is not None   )

     return TFBaseModelOutputWithNoAttention(last_hidden_state=snake_case_			,				hidden_states=snake_case_   )






class 			UpperCAmelCase_						(		A_							):
    lowercase__		      =   ResNetConfig
    lowercase__		      =   '''resnet'''
    lowercase__		      =   '''pixel_values'''




    @property
    def 							__magic_name__							(					self		: List[str]   )   ->							str:




     '''simple docstring'''

     return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)			,				dtype=tf.floataa   )}






SCREAMING_SNAKE_CASE       = r"\n    This model is a TensorFlow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular TensorFlow Module and refer to the TensorFlow documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n"


SCREAMING_SNAKE_CASE       = r"\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n"




@keras_serializable
class 			UpperCAmelCase_						(		tf.keras.layers.Layer							):
    lowercase__		      =   ResNetConfig




    def __init__(					self		: Tuple			,				snake_case_		: ResNetConfig			,				**snake_case_		: Optional[Any]   )   ->							None:




     '''simple docstring'''

     super().__init__(**snake_case_   )
     A__ =       config
     A__ =       TFResNetEmbeddings(snake_case_			,				name="embedder"   )
     A__ =       TFResNetEncoder(snake_case_			,				name="encoder"   )
     A__ =       tf.keras.layers.GlobalAveragePoolingaD(keepdims=snake_case_   )




    @unpack_inputs
    def 							__magic_name__							(					self		: Dict			,				snake_case_		: tf.Tensor			,				snake_case_		: Optional[bool] = None			,				snake_case_		: Optional[bool] = None			,				snake_case_		: bool = False			,				)   ->							Union[Tuple[tf.Tensor], TFBaseModelOutputWithPoolingAndNoAttention]:




     '''simple docstring'''

     A__ =       (
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )
     A__ =       return_dict if return_dict is not None else self.config.use_return_dict

     # TF 2.0 image layers can't use NCHW format when running on CPU.
     # We transpose to NHWC format and then transpose back after the full forward pass.
     # (batch_size, num_channels, height, width) -> (batch_size, height, width, num_channels)
     A__ =       tf.transpose(snake_case_			,				perm=[0, 2, 3, 1]   )
     A__ =       self.embedder(snake_case_			,				training=snake_case_   )

     A__ =       self.encoder(
         snake_case_			,				output_hidden_states=snake_case_			,				return_dict=snake_case_			,				training=snake_case_   )

     A__ =       encoder_outputs[0]

     A__ =       self.pooler(snake_case_   )

     # Transpose all the outputs to the NCHW format
     # (batch_size, height, width, num_channels) -> (batch_size, num_channels, height, width)
     A__ =       tf.transpose(snake_case_			,				(0, 3, 1, 2)   )
     A__ =       tf.transpose(snake_case_			,				(0, 3, 1, 2)   )
     A__ =       ()
     for hidden_state in encoder_outputs[1:]:
      A__ =       hidden_states + tuple(tf.transpose(snake_case_			,				(0, 3, 1, 2)   ) for h in hidden_state   )

     if not return_dict:
      return (last_hidden_state, pooled_output) + hidden_states

     A__ =       hidden_states if output_hidden_states else None

     return TFBaseModelOutputWithPoolingAndNoAttention(
         last_hidden_state=snake_case_			,				pooler_output=snake_case_			,				hidden_states=snake_case_			,				)






@add_start_docstrings(
    '''The bare ResNet model outputting raw features without any specific head on top.''',     A_,     )
class 			UpperCAmelCase_						(		A_							):




    def __init__(					self		: List[str]			,				snake_case_		: ResNetConfig			,				**snake_case_		: str   )   ->							None:




     '''simple docstring'''

     super().__init__(snake_case_			,				**snake_case_   )
     A__ =       TFResNetMainLayer(config=snake_case_			,				name="resnet"   )




    @add_start_docstrings_to_model_forward(snake_case_   )
    @add_code_sample_docstrings(
        checkpoint=_CHECKPOINT_FOR_DOC			,				output_type=snake_case_			,				config_class=_CONFIG_FOR_DOC			,				modality="vision"			,				expected_output=_EXPECTED_OUTPUT_SHAPE			,				)
    @unpack_inputs
    def 							__magic_name__							(					self		: Dict			,				snake_case_		: tf.Tensor			,				snake_case_		: Optional[bool] = None			,				snake_case_		: Optional[bool] = None			,				snake_case_		: bool = False			,				)   ->							Union[Tuple[tf.Tensor], TFBaseModelOutputWithPoolingAndNoAttention]:




     '''simple docstring'''

     A__ =       (
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )
     A__ =       return_dict if return_dict is not None else self.config.use_return_dict

     A__ =       self.resnet(
         pixel_values=snake_case_			,				output_hidden_states=snake_case_			,				return_dict=snake_case_			,				training=snake_case_			,				)
     return resnet_outputs






@add_start_docstrings(
    '''
    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    ''',     A_,     )
class 			UpperCAmelCase_						(		A_,     A_							):




    def __init__(					self		: List[Any]			,				snake_case_		: ResNetConfig			,				**snake_case_		: int   )   ->							None:




     '''simple docstring'''

     super().__init__(snake_case_			,				**snake_case_   )
     A__ =       config.num_labels
     A__ =       TFResNetMainLayer(snake_case_			,				name="resnet"   )
     # classification head
     A__ =       (
         tf.keras.layers.Dense(config.num_labels			,				name="classifier.1"   )
         if config.num_labels > 0
         else tf.keras.layers.Activation("linear"			,				name="classifier.1"   )
     )




    def 							__magic_name__							(					self		: Optional[Any]			,				snake_case_		: tf.Tensor   )   ->							tf.Tensor:




     '''simple docstring'''

     A__ =       tf.keras.layers.Flatten()(snake_case_   )
     A__ =       self.classifier_layer(snake_case_   )
     return logits




    @add_start_docstrings_to_model_forward(snake_case_   )
    @add_code_sample_docstrings(
        checkpoint=_IMAGE_CLASS_CHECKPOINT			,				output_type=snake_case_			,				config_class=_CONFIG_FOR_DOC			,				expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT			,				)
    @unpack_inputs
    def 							__magic_name__							(					self		: Dict			,				snake_case_		: tf.Tensor = None			,				snake_case_		: tf.Tensor = None			,				snake_case_		: bool = None			,				snake_case_		: bool = None			,				snake_case_		: bool = False			,				)   ->							Union[Tuple[tf.Tensor], TFImageClassifierOutputWithNoAttention]:




     '''simple docstring'''

     A__ =       return_dict if return_dict is not None else self.config.use_return_dict

     A__ =       self.resnet(
         snake_case_			,				output_hidden_states=snake_case_			,				return_dict=snake_case_			,				training=snake_case_   )

     A__ =       outputs.pooler_output if return_dict else outputs[1]

     A__ =       self.classifier(snake_case_   )

     A__ =       None if labels is None else self.hf_compute_loss(snake_case_			,				snake_case_   )

     if not return_dict:
      A__ =       (logits,) + outputs[2:]
      return (loss,) + output if loss is not None else output

     return TFImageClassifierOutputWithNoAttention(loss=snake_case_			,				logits=snake_case_			,				hidden_states=outputs.hidden_states   )











"""simple docstring"""



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     (							lowercase_    ,				lowercase_    ,				lowercase_		)		->	torch.Tensor:
 ...







@overload
def 						_SCREAMING_SNAKE_CASE     (							lowercase_    ,				lowercase_    ,				lowercase_		)		->	Tuple[torch.Tensor, torch.Tensor]:
 ...







def 						_SCREAMING_SNAKE_CASE     (							lowercase_    ,				lowercase_    ,				lowercase_		)		->	Dict:
 A__ =       aatype == rc.restype_order["G"]
 A__ =       rc.atom_order["CA"]
 A__ =       rc.atom_order["CB"]
 A__ =       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:
  A__ =       torch.where(
      lowercase_    ,				all_atom_masks[..., ca_idx]    ,				all_atom_masks[..., cb_idx]    ,				)
  return pseudo_beta, pseudo_beta_mask
 else:
  return pseudo_beta







def 						_SCREAMING_SNAKE_CASE     (							lowercase_    ,				lowercase_		)		->	torch.Tensor:
 A__ =       batched_gather(
     lowercase_    ,				batch["residx_atom37_to_atom14"]    ,				dim=-2    ,				no_batch_dims=len(atomaa.shape[:-2]		)    ,				)

 A__ =       atomaa_data * batch["atom37_atom_exists"][..., None]

 return atomaa_data







def 						_SCREAMING_SNAKE_CASE     (							lowercase_		)		->	torch.Tensor:
 A__ =       template_feats["template_aatype"]
 A__ =       template_feats["template_torsion_angles_sin_cos"]
 A__ =       template_feats["template_alt_torsion_angles_sin_cos"]
 A__ =       template_feats["template_torsion_angles_mask"]
 A__ =       torch.cat(
     [
         nn.functional.one_hot(lowercase_    ,				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     (							lowercase_    ,				lowercase_    ,				lowercase_    ,				lowercase_    ,				lowercase_ = False    ,				lowercase_ = 1E-20    ,				lowercase_ = 1E8    ,				)		->	torch.Tensor:
 A__ =       batch["template_pseudo_beta_mask"]
 A__ =       template_mask[..., None] * template_mask[..., None, :]

 # Compute distogram (this seems to differ slightly from Alg. 5)
 A__ =       batch["template_pseudo_beta"]
 A__ =       torch.sum((tpb[..., None, :] - tpb[..., None, :, :]) ** 2    ,				dim=-1    ,				keepdim=lowercase_		)
 A__ =       torch.linspace(lowercase_    ,				lowercase_    ,				lowercase_    ,				device=tpb.device		) ** 2
 A__ =       torch.cat([lower[1:], lower.new_tensor([inf]		)]    ,				dim=-1		)
 A__ =       ((dgram > lower) * (dgram < upper)).type(dgram.dtype		)

 A__ =       [dgram, template_mask_ad[..., None]]

 A__ =       nn.functional.one_hot(
     batch["template_aatype"]    ,				rc.restype_num + 2    ,				)

 A__ =       batch["template_aatype"].shape[-1]
 to_concat.append(aatype_one_hot[..., None, :, :].expand(*aatype_one_hot.shape[:-2]    ,				lowercase_    ,				-1    ,				-1		)		)
 to_concat.append(aatype_one_hot[..., None, :].expand(*aatype_one_hot.shape[:-2]    ,				-1    ,				lowercase_    ,				-1		)		)

 A__,   A__,   A__ =       [rc.atom_order[a] for a in ["N", "CA", "C"]]
 A__ =       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=lowercase_    ,				)
 A__ =       rigids.get_trans()[..., None, :, :]
 A__ =       rigids[..., None].invert_apply(lowercase_		)

 A__ =       torch.rsqrt(eps + torch.sum(rigid_vec**2    ,				dim=-1		)		)

 A__ =       batch["template_all_atom_mask"]
 A__ =       t_aa_masks[..., n] * t_aa_masks[..., ca] * t_aa_masks[..., c]
 A__ =       template_mask[..., None] * template_mask[..., None, :]

 A__ =       inv_distance_scalar * template_mask_ad
 A__ =       rigid_vec * inv_distance_scalar[..., None]

 if not use_unit_vector:
  A__ =       unit_vector * 0.0

 to_concat.extend(torch.unbind(unit_vector[..., None, :]    ,				dim=-1		)		)
 to_concat.append(template_mask_ad[..., None]		)

 A__ =       torch.cat(lowercase_    ,				dim=-1		)
 A__ =       act * template_mask_ad[..., None]

 return act







def 						_SCREAMING_SNAKE_CASE     (							lowercase_		)		->	torch.Tensor:
 A__ =       nn.functional.one_hot(batch["extra_msa"]    ,				23		)
 A__ =       [
     msa_ahot,
     batch["extra_has_deletion"].unsqueeze(-1		),
     batch["extra_deletion_value"].unsqueeze(-1		),
 ]
 return torch.cat(lowercase_    ,				dim=-1		)







def 						_SCREAMING_SNAKE_CASE     (							lowercase_    ,				lowercase_    ,				lowercase_    ,				lowercase_    ,				)		->	Rigid:
 # [*, N, 8, 4, 4]
 A__ =       rrgdf[aatype, ...]

 # [*, N, 8] transformations, i.e.
 #   One [*, N, 8, 3, 3] rotation matrix and
 #   One [*, N, 8, 3]    translation matrix
 A__ =       r.from_tensor_axa(lowercase_		)

 A__ =       alpha.new_zeros((*((1,) * len(alpha.shape[:-1]		)), 2)		)
 A__ =       1

 # [*, N, 8, 2]
 A__ =       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.

 A__ =       alpha.new_zeros(default_r.get_rots().get_rot_mats().shape		)
 A__ =       1
 A__ =       alpha[..., 1]
 A__ =       -alpha[..., 0]
 A__ =       alpha

 A__ =       default_r.compose(Rigid(Rotation(rot_mats=lowercase_		)    ,				lowercase_		)		)

 A__ =       all_frames[..., 5]
 A__ =       all_frames[..., 6]
 A__ =       all_frames[..., 7]

 A__ =       all_frames[..., 4]
 A__ =       chia_frame_to_bb.compose(lowercase_		)
 A__ =       chia_frame_to_bb.compose(lowercase_		)
 A__ =       chia_frame_to_bb.compose(lowercase_		)

 A__ =       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    ,				)

 A__ =       r[..., None].compose(lowercase_		)

 return all_frames_to_global







def 						_SCREAMING_SNAKE_CASE     (							lowercase_    ,				lowercase_    ,				lowercase_    ,				lowercase_    ,				lowercase_    ,				lowercase_    ,				)		->	torch.Tensor:
 # [*, N, 14]
 A__ =       group_idx[aatype, ...]

 # [*, N, 14, 8]
 A__ =       nn.functional.one_hot(
     lowercase_    ,				num_classes=default_frames.shape[-3]    ,				)

 # [*, N, 14, 8]
 A__ =       r[..., None, :] * group_mask_one_hot

 # [*, N, 14]
 A__ =       t_atoms_to_global.map_tensor_fn(lambda lowercase_		: torch.sum(lowercase_    ,				dim=-1		)		)

 # [*, N, 14, 1]
 A__ =       atom_mask[aatype, ...].unsqueeze(-1		)

 # [*, N, 14, 3]
 A__ =       lit_positions[aatype, ...]
 A__ =       t_atoms_to_global.apply(lowercase_		)
 A__ =       pred_positions * atom_mask

 return pred_positions





