



"""simple docstring"""
import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


_UpperCAmelCase     =			{"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

_UpperCAmelCase     =			{
    """vocab_file""": {
        """unc-nlp/lxmert-base-uncased""": """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt""",
    },
    """tokenizer_file""": {
        """unc-nlp/lxmert-base-uncased""": (
            """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json"""
        ),
    },
}

_UpperCAmelCase     =			{
    """unc-nlp/lxmert-base-uncased""": 5_1_2,
}

_UpperCAmelCase     =			{
    """unc-nlp/lxmert-base-uncased""": {"""do_lower_case""": True},
}
class 					a	(  UpperCAmelCase__       ):
  UpperCamelCase	:				int     						=					VOCAB_FILES_NAMES
  UpperCamelCase	:				List[Any]     						=					PRETRAINED_VOCAB_FILES_MAP
  UpperCamelCase	:				Dict     						=					PRETRAINED_INIT_CONFIGURATION
  UpperCamelCase	:				Optional[int]     						=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  UpperCamelCase	:				str     						=					LxmertTokenizer



  def __init__(						self :					int       ,		lowerCAmelCase :					List[Any]=None       ,		lowerCAmelCase :					List[str]=None       ,		lowerCAmelCase :					Dict=True       ,		lowerCAmelCase :					Optional[Any]="[UNK]"       ,		lowerCAmelCase :					str="[SEP]"       ,		lowerCAmelCase :					List[Any]="[PAD]"       ,		lowerCAmelCase :					Tuple="[CLS]"       ,		lowerCAmelCase :					List[Any]="[MASK]"       ,		lowerCAmelCase :					List[str]=True       ,		lowerCAmelCase :					Tuple=None       ,		**lowerCAmelCase :					Union[str, Any]       ,		)     ->					List[str]:


     '''simple docstring'''




     super().__init__(
         lowerCAmelCase       ,		tokenizer_file=lowerCAmelCase       ,		do_lower_case=lowerCAmelCase       ,		unk_token=lowerCAmelCase       ,		sep_token=lowerCAmelCase       ,		pad_token=lowerCAmelCase       ,		cls_token=lowerCAmelCase       ,		mask_token=lowerCAmelCase       ,		tokenize_chinese_chars=lowerCAmelCase       ,		strip_accents=lowerCAmelCase       ,		**lowerCAmelCase       ,		)

     SCREAMING_SNAKE_CASE_: Tuple     			=json.loads(self.backend_tokenizer.normalizer.__getstate__()		)
     if (
         normalizer_state.get("""lowercase"""       ,		lowerCAmelCase		) != do_lower_case
         or normalizer_state.get("""strip_accents"""       ,		lowerCAmelCase		) != strip_accents
         or normalizer_state.get("""handle_chinese_chars"""       ,		lowerCAmelCase		) != tokenize_chinese_chars
     ):
        SCREAMING_SNAKE_CASE_: Optional[int]     			=getattr(lowerCAmelCase       ,		normalizer_state.pop("""type"""		)		)
        SCREAMING_SNAKE_CASE_: Dict     			=do_lower_case
        SCREAMING_SNAKE_CASE_: Union[str, Any]     			=strip_accents
        SCREAMING_SNAKE_CASE_: str     			=tokenize_chinese_chars
        SCREAMING_SNAKE_CASE_: Optional[int]     			=normalizer_class(**lowerCAmelCase		)

     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=do_lower_case



  def 	lowerCamelCase__       (						self :					Tuple       ,		lowerCAmelCase :					str       ,		lowerCAmelCase :					Union[str, Any]=None		)     ->					str:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: List[Any]     			=[self.cls_token_id] + token_ids_a + [self.sep_token_id]

     if token_ids_a:
        output += token_ids_a + [self.sep_token_id]

     return output



  def 	lowerCamelCase__       (						self :					Dict       ,		lowerCAmelCase :					List[int]       ,		lowerCAmelCase :					Optional[List[int]] = None		)     ->					List[int]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Any     			=[self.sep_token_id]
     SCREAMING_SNAKE_CASE_: Any     			=[self.cls_token_id]
     if token_ids_a is None:
        return len(cls + token_ids_a + sep		) * [0]
     return len(cls + token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]





  def 	lowerCamelCase__       (						self :					Optional[int]       ,		lowerCAmelCase :					str       ,		lowerCAmelCase :					Optional[str] = None		)     ->					Tuple[str]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: int     			=self._tokenizer.model.save(lowerCAmelCase       ,		name=lowerCAmelCase		)
     return tuple(lowerCAmelCase		)








"""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      __magic_name__				(							lowercase ):
   SCREAMING_SNAKE_CASE_: Optional[Any]     			=[]
   SCREAMING_SNAKE_CASE_: List[str]     			=[]
   SCREAMING_SNAKE_CASE_: Any     			=[]

   for rt in rc.restypes:
      SCREAMING_SNAKE_CASE_: Optional[int]     			=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] )
      SCREAMING_SNAKE_CASE_: Any     			={name: i for i, name in enumerate(lowercase )}
      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 )

   SCREAMING_SNAKE_CASE_: Union[str, Any]     			=torch.tensor(
       lowercase							,			dtype=torch.intaa							,			device=protein["""aatype"""].device							,			)
   SCREAMING_SNAKE_CASE_: Optional[Any]     			=torch.tensor(
       lowercase							,			dtype=torch.intaa							,			device=protein["""aatype"""].device							,			)
   SCREAMING_SNAKE_CASE_: List[str]     			=torch.tensor(
       lowercase							,			dtype=torch.floataa							,			device=protein["""aatype"""].device							,			)
   SCREAMING_SNAKE_CASE_: 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
   SCREAMING_SNAKE_CASE_: List[str]     			=restype_atomaa_to_atomaa[protein_aatype]
   SCREAMING_SNAKE_CASE_: Any     			=restype_atomaa_mask[protein_aatype]

   SCREAMING_SNAKE_CASE_: Tuple     			=residx_atomaa_mask
   SCREAMING_SNAKE_CASE_: Dict     			=residx_atomaa_to_atomaa.long()

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

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

   SCREAMING_SNAKE_CASE_: List[str]     			=restype_atomaa_mask[protein_aatype]
   SCREAMING_SNAKE_CASE_: List[Any]     			=residx_atomaa_mask

   return protein





def      __magic_name__				(							lowercase ):
   SCREAMING_SNAKE_CASE_: Any     			=tree_map(lambda lowercase : torch.tensor(lowercase							,			device=batch["""aatype"""].device )							,			lowercase							,			np.ndarray )
   SCREAMING_SNAKE_CASE_: int     			=tensor_tree_map(lambda lowercase : np.array(lowercase )							,			make_atomaa_masks(lowercase ) )
   return out



