






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   __lowercase       (			snake_case			):







				"""simple docstring"""






				__magic_name__		:Tuple   =   []
				__magic_name__		:Tuple   =   []
				__magic_name__		:Any   =   []

				for rt in rc.restypes:
								__magic_name__		:List[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]			)
								__magic_name__		:List[Any]   =   {name: i for i, name in enumerate(snake_case			)}
								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] * 1_4			)
				restype_atomaa_to_atomaa_list.append([0] * 3_7			)
				restype_atomaa_mask_list.append([0.0] * 1_4			)

				__magic_name__		:int   =   torch.tensor(
				    snake_case,	dtype=torch.intaa,	device=protein['''aatype'''].device,	)
				__magic_name__		:Any   =   torch.tensor(
				    snake_case,	dtype=torch.intaa,	device=protein['''aatype'''].device,	)
				__magic_name__		:List[Any]   =   torch.tensor(
				    snake_case,	dtype=torch.floataa,	device=protein['''aatype'''].device,	)
				__magic_name__		:Optional[int]   =   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
				__magic_name__		:List[str]   =   restype_atomaa_to_atomaa[protein_aatype]
				__magic_name__		:str   =   restype_atomaa_mask[protein_aatype]

				__magic_name__		:int   =   residx_atomaa_mask
				__magic_name__		:Any   =   residx_atomaa_to_atomaa.long()

				# create the gather indices for mapping back
				__magic_name__		:Dict   =   restype_atomaa_to_atomaa[protein_aatype]
				__magic_name__		:List[str]   =   residx_atomaa_to_atomaa.long()

				# create the corresponding mask
				__magic_name__		:int   =   torch.zeros([2_1, 3_7],	dtype=torch.floataa,	device=protein['''aatype'''].device			)
				for restype, restype_letter in enumerate(rc.restypes			):
								__magic_name__		:str   =   rc.restype_atoa[restype_letter]
								__magic_name__		:Dict   =   rc.residue_atoms[restype_name]
								for atom_name in atom_names:
												__magic_name__		:Dict   =   rc.atom_order[atom_name]
												__magic_name__		:Optional[int]   =   1

				__magic_name__		:str   =   restype_atomaa_mask[protein_aatype]
				__magic_name__		:List[str]   =   residx_atomaa_mask

				return protein

def   __lowercase       (			snake_case			):







				"""simple docstring"""






				__magic_name__		:Tuple   =   tree_map(lambda snake_case			: torch.tensor(snake_case,	device=batch['''aatype'''].device			),	snake_case,	np.ndarray			)
				__magic_name__		:Optional[int]   =   tensor_tree_map(lambda snake_case			: np.array(snake_case			),	make_atomaa_masks(snake_case			)			)
				return out














from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowerCamelCase__       		=  logging.get_logger(__name__)

lowerCamelCase__       		=  {
    """microsoft/focalnet-tiny""": """https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json""",
}




class       snake_case__ (				lowercase_						,     lowercase_):

       '''simple docstring'''
       lowerCamelCase				:					List[Any]								=			"focalnet"



       def __init__(				self      ,    a__=2_24      ,    a__=4      ,    a__=3      ,    a__=96      ,    a__=False      ,    a__=[1_92, 3_84, 7_68, 7_68]      ,    a__=[2, 2, 6, 2]      ,    a__=[2, 2, 2, 2]      ,    a__=[3, 3, 3, 3]      ,    a__="gelu"      ,    a__=4.0      ,    a__=0.0      ,    a__=0.1      ,    a__=False      ,    a__=1e-4      ,    a__=False      ,    a__=False      ,    a__=False      ,    a__=0.02      ,    a__=1e-5      ,    a__=32      ,    a__=None      ,    a__=None      ,    **a__      ,    )			->   Tuple:






            '''simple docstring'''





            super().__init__(**a__     )

            __snake_case      :Optional[Any] 							=    image_size
            __snake_case      :Dict 							=    patch_size
            __snake_case      :Tuple 							=    num_channels
            __snake_case      :List[str] 							=    embed_dim
            __snake_case      :Any 							=    use_conv_embed
            __snake_case      :List[Any] 							=    hidden_sizes
            __snake_case      :str 							=    depths
            __snake_case      :List[Any] 							=    focal_levels
            __snake_case      :int 							=    focal_windows
            __snake_case      :Any 							=    hidden_act
            __snake_case      :List[str] 							=    mlp_ratio
            __snake_case      :str 							=    hidden_dropout_prob
            __snake_case      :List[str] 							=    drop_path_rate
            __snake_case      :int 							=    use_layerscale
            __snake_case      :int 							=    layerscale_value
            __snake_case      :Tuple 							=    use_post_layernorm
            __snake_case      :Dict 							=    use_post_layernorm_in_modulation
            __snake_case      :Union[str, Any] 							=    normalize_modulator
            __snake_case      :List[str] 							=    initializer_range
            __snake_case      :Optional[Any] 							=    layer_norm_eps
            __snake_case      :Tuple 							=    encoder_stride
            __snake_case      :List[str] 							=    ["""stem"""] + [F'''stage{idx}''' for idx in range(1      ,    len(self.depths     ) + 1     )]
            __snake_case							,			__snake_case      :str 							=    get_aligned_output_features_output_indices(
                out_features=a__      ,    out_indices=a__      ,    stage_names=self.stage_names     )


