





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


UpperCamelCase__     =	{
    "configuration_m2m_100": ["M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP", "M2M100Config", "M2M100OnnxConfig"],
    "tokenization_m2m_100": ["M2M100Tokenizer"],
}


try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCamelCase__     =	[
					    "M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "M2M100ForConditionalGeneration",
					    "M2M100Model",
					    "M2M100PreTrainedModel",
					]


if TYPE_CHECKING:
					from .configuration_mam_aaa import M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP, MaMaaaConfig, MaMaaaOnnxConfig
					from .tokenization_mam_aaa import MaMaaaTokenizer

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_mam_aaa import (
										    M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST,
										    MaMaaaForConditionalGeneration,
										    MaMaaaModel,
										    MaMaaaPreTrainedModel,
										)


else:
					import sys

					UpperCamelCase__     =	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)











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       _UpperCamelCase       (a__				:Dict[str, torch.Tensor]    ):






							"""simple docstring"""





							UpperCamelCase__			       =     []
							UpperCamelCase__			       =     []
							UpperCamelCase__			       =     []

							for rt in rc.restypes:
														UpperCamelCase__			       =     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__			       =     {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] * 14    )
							restype_atomaa_to_atomaa_list.append([0] * 37    )
							restype_atomaa_mask_list.append([0.0] * 14    )

							UpperCamelCase__			       =     torch.tensor(
							    a__				,     dtype=torch.intaa				,     device=protein["""aatype"""].device				,     )
							UpperCamelCase__			       =     torch.tensor(
							    a__				,     dtype=torch.intaa				,     device=protein["""aatype"""].device				,     )
							UpperCamelCase__			       =     torch.tensor(
							    a__				,     dtype=torch.floataa				,     device=protein["""aatype"""].device				,     )
							UpperCamelCase__			       =     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__			       =     restype_atomaa_to_atomaa[protein_aatype]
							UpperCamelCase__			       =     restype_atomaa_mask[protein_aatype]

							UpperCamelCase__			       =     residx_atomaa_mask
							UpperCamelCase__			       =     residx_atomaa_to_atomaa.long()

							# create the gather indices for mapping back
							UpperCamelCase__			       =     restype_atomaa_to_atomaa[protein_aatype]
							UpperCamelCase__			       =     residx_atomaa_to_atomaa.long()

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

							UpperCamelCase__			       =     restype_atomaa_mask[protein_aatype]
							UpperCamelCase__			       =     residx_atomaa_mask

							return protein





def       _UpperCamelCase       (a__				:Dict[str, torch.Tensor]    ):






							"""simple docstring"""





							UpperCamelCase__			       =     tree_map(lambda a__    : torch.tensor(a__				,     device=batch["""aatype"""].device    )				,     a__				,     np.ndarray    )
							UpperCamelCase__			       =     tensor_tree_map(lambda a__    : np.array(a__    )				,     make_atomaa_masks(a__    )    )
							return out




