



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 A__   (					UpperCAmelCase_							):
						_UpperCamelCase :		str			    =       []
						_UpperCamelCase :		str			    =       []
						_UpperCamelCase :		Optional[int]			    =       []

						for rt in rc.restypes:
												_UpperCamelCase :		Tuple			    =       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 :		int			    =       {name: i for i, name in enumerate(_a							)}
												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							)

						_UpperCamelCase :		Tuple			    =       torch.tensor(
						    _a  ,  dtype=torch.intaa  ,  device=protein['aatype'].device  ,  )
						_UpperCamelCase :		List[str]			    =       torch.tensor(
						    _a  ,  dtype=torch.intaa  ,  device=protein['aatype'].device  ,  )
						_UpperCamelCase :		Tuple			    =       torch.tensor(
						    _a  ,  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 :		str			    =       restype_atomaa_to_atomaa[protein_aatype]
						_UpperCamelCase :		List[Any]			    =       restype_atomaa_mask[protein_aatype]

						_UpperCamelCase :		Tuple			    =       residx_atomaa_mask
						_UpperCamelCase :		Optional[Any]			    =       residx_atomaa_to_atomaa.long()

						# create the gather indices for mapping back
						_UpperCamelCase :		Any			    =       restype_atomaa_to_atomaa[protein_aatype]
						_UpperCamelCase :		Union[str, Any]			    =       residx_atomaa_to_atomaa.long()

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

						_UpperCamelCase :		List[str]			    =       restype_atomaa_mask[protein_aatype]
						_UpperCamelCase :		Dict			    =       residx_atomaa_mask

						return protein






def A__   (					UpperCAmelCase_							):
						_UpperCamelCase :		Optional[int]			    =       tree_map(lambda UpperCAmelCase_							: torch.tensor(_a  ,  device=batch['aatype'].device							)  ,  _a  ,  np.ndarray							)
						_UpperCamelCase :		Optional[Any]			    =       tensor_tree_map(lambda UpperCAmelCase_							: np.array(_a							)  ,  make_atomaa_masks(_a							)							)
						return out







'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


snake_case_			:     Optional[Any]  	=  {
    'configuration_clip': [
        'CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'CLIPConfig',
        'CLIPOnnxConfig',
        'CLIPTextConfig',
        'CLIPVisionConfig',
    ],
    'processing_clip': ['CLIPProcessor'],
    'tokenization_clip': ['CLIPTokenizer'],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     Optional[int]  	=  ['CLIPTokenizerFast']

try:
					if not is_vision_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     Optional[int]  	=  ['CLIPFeatureExtractor']
					snake_case_			:     Dict  	=  ['CLIPImageProcessor']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     Tuple  	=  [
					    'CLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'CLIPModel',
					    'CLIPPreTrainedModel',
					    'CLIPTextModel',
					    'CLIPTextModelWithProjection',
					    'CLIPVisionModel',
					    'CLIPVisionModelWithProjection',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     List[Any]  	=  [
					    'TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFCLIPModel',
					    'TFCLIPPreTrainedModel',
					    'TFCLIPTextModel',
					    'TFCLIPVisionModel',
					]

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     Optional[int]  	=  [
					    'FlaxCLIPModel',
					    'FlaxCLIPPreTrainedModel',
					    'FlaxCLIPTextModel',
					    'FlaxCLIPTextPreTrainedModel',
					    'FlaxCLIPVisionModel',
					    'FlaxCLIPVisionPreTrainedModel',
					]


if TYPE_CHECKING:
					from .configuration_clip import (
					    CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    CLIPConfig,
					    CLIPOnnxConfig,
					    CLIPTextConfig,
					    CLIPVisionConfig,
					)
					from .processing_clip import CLIPProcessor
					from .tokenization_clip import CLIPTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_clip_fast import CLIPTokenizerFast

					try:
										if not is_vision_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .feature_extraction_clip import CLIPFeatureExtractor
										from .image_processing_clip import CLIPImageProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_clip import (
										    CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
										    CLIPModel,
										    CLIPPreTrainedModel,
										    CLIPTextModel,
										    CLIPTextModelWithProjection,
										    CLIPVisionModel,
										    CLIPVisionModelWithProjection,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_clip import (
										    TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFCLIPModel,
										    TFCLIPPreTrainedModel,
										    TFCLIPTextModel,
										    TFCLIPVisionModel,
										)

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_clip import (
										    FlaxCLIPModel,
										    FlaxCLIPPreTrainedModel,
										    FlaxCLIPTextModel,
										    FlaxCLIPTextPreTrainedModel,
										    FlaxCLIPVisionModel,
										    FlaxCLIPVisionPreTrainedModel,
										)


else:
					import sys

					snake_case_			:     str  	=  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


