'''simple docstring'''


from typing import Dict

import numpy as np
import torch

from . import residue_constants as rc
from .tensor_utils import tensor_tree_map, tree_map


def  _lowerCamelCase   (				lowerCamelCase_ :							Dict[str, torch.Tensor]       ):



     """simple docstring"""





     UpperCAmelCase_							:       Optional[Any]       =				[]
     UpperCAmelCase_							:       Dict       =				[]
     UpperCAmelCase_							:       Optional[Any]       =				[]

     for rt in rc.restypes:
          UpperCAmelCase_							:       Union[str, Any]       =				rc.restype_name_to_atomaa_names[rc.restype_atoa[rt]]
          restype_atomaa_to_atomaa_list.append([(rc.atom_order[name] if name else 0) for name in atom_names]       )
          UpperCAmelCase_							:       Any       =				{name: i for i, name in enumerate(lowerCamelCase_       )}
          restype_atomaa_to_atomaa_list.append(
              [(atom_name_to_idxaa[name] if name in atom_name_to_idxaa else 0) for name in rc.atom_types]       )

          restype_atomaa_mask_list.append([(1.0 if name else 0.0) for name in atom_names]       )

     # Add dummy mapping for restype 'UNK'
     restype_atomaa_to_atomaa_list.append([0] * 14       )
     restype_atomaa_to_atomaa_list.append([0] * 37       )
     restype_atomaa_mask_list.append([0.0] * 14       )

     UpperCAmelCase_							:       List[str]       =				torch.tensor(
         lowerCamelCase_     ,					dtype=torch.intaa     ,					device=protein['aatype'].device     ,					)
     UpperCAmelCase_							:       int       =				torch.tensor(
         lowerCamelCase_     ,					dtype=torch.intaa     ,					device=protein['aatype'].device     ,					)
     UpperCAmelCase_							:       Tuple       =				torch.tensor(
         lowerCamelCase_     ,					dtype=torch.floataa     ,					device=protein['aatype'].device     ,					)
     UpperCAmelCase_							:       Optional[Any]       =				protein['aatype'].to(torch.long       )

     # create the mapping for (residx, atom14) --> atom37, i.e. an array
     # with shape (num_res, 14) containing the atom37 indices for this protein
     UpperCAmelCase_							:       Tuple       =				restype_atomaa_to_atomaa[protein_aatype]
     UpperCAmelCase_							:       List[Any]       =				restype_atomaa_mask[protein_aatype]

     UpperCAmelCase_							:       Tuple       =				residx_atomaa_mask
     UpperCAmelCase_							:       Union[str, Any]       =				residx_atomaa_to_atomaa.long()

     # create the gather indices for mapping back
     UpperCAmelCase_							:       Tuple       =				restype_atomaa_to_atomaa[protein_aatype]
     UpperCAmelCase_							:       int       =				residx_atomaa_to_atomaa.long()

     # create the corresponding mask
     UpperCAmelCase_							:       Tuple       =				torch.zeros([21, 37]     ,					dtype=torch.floataa     ,					device=protein['aatype'].device       )
     for restype, restype_letter in enumerate(rc.restypes       ):
          UpperCAmelCase_							:       str       =				rc.restype_atoa[restype_letter]
          UpperCAmelCase_							:       List[Any]       =				rc.residue_atoms[restype_name]
          for atom_name in atom_names:
               UpperCAmelCase_							:       Dict       =				rc.atom_order[atom_name]
               UpperCAmelCase_							:       Optional[Any]       =				1

     UpperCAmelCase_							:       Union[str, Any]       =				restype_atomaa_mask[protein_aatype]
     UpperCAmelCase_							:       Optional[Any]       =				residx_atomaa_mask

     return protein





def  _lowerCamelCase   (				lowerCamelCase_ :							Dict[str, torch.Tensor]       ):



     """simple docstring"""





     UpperCAmelCase_							:       List[str]       =				tree_map(lambda lowerCamelCase_       : torch.tensor(lowerCamelCase_     ,					device=batch['aatype'].device       )     ,					lowerCamelCase_     ,					np.ndarray       )
     UpperCAmelCase_							:       Union[str, Any]       =				tensor_tree_map(lambda lowerCamelCase_       : np.array(lowerCamelCase_       )     ,					make_atomaa_masks(lowerCamelCase_       )       )
     return out







'''simple docstring'''


from typing import Optional, Union

import torch
from torch import nn

from ...configuration_utils import ConfigMixin, register_to_config
from ...models.modeling_utils import ModelMixin






class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_						,     lowerCamelCase_	):







  '''simple docstring'''






  @register_to_config
  def __init__(			self				,		snake_case_ = 7_6_8				,		):




       '''simple docstring'''

       super().__init__()

       UpperCAmelCase_							:       int       =				nn.Parameter(torch.zeros(1				,		snake_case_						)						)
       UpperCAmelCase_							:       str       =				nn.Parameter(torch.ones(1				,		snake_case_						)						)


  def _UpperCamelCase					(			self				,		snake_case_ = None				,		snake_case_ = None				,		):




       '''simple docstring'''

       UpperCAmelCase_							:       int       =				nn.Parameter(self.mean.to(snake_case_						).to(snake_case_						)						)
       UpperCAmelCase_							:       Tuple       =				nn.Parameter(self.std.to(snake_case_						).to(snake_case_						)						)
       return self


  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       Dict       =				(embeds - self.mean) * 1.0 / self.std
       return embeds






  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       List[Any]       =				(embeds * self.std) + self.mean
       return embeds






