




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


			"""simple docstring"""
			__UpperCAmelCase	: Optional[int]		=					[]
			__UpperCAmelCase	: Union[str, Any]		=					[]
			__UpperCAmelCase	: str		=					[]

			for rt in rc.restypes:
						__UpperCAmelCase	: str		=					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	: List[Any]		=					{name: i for i, name in enumerate(UpperCamelCase							)}
						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(
			    UpperCamelCase				,       dtype=torch.intaa				,       device=protein["aatype"].device				,       )
			__UpperCAmelCase	: Optional[Any]		=					torch.tensor(
			    UpperCamelCase				,       dtype=torch.intaa				,       device=protein["aatype"].device				,       )
			__UpperCAmelCase	: str		=					torch.tensor(
			    UpperCamelCase				,       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	: Optional[Any]		=					restype_atomaa_to_atomaa[protein_aatype]
			__UpperCAmelCase	: List[str]		=					restype_atomaa_mask[protein_aatype]

			__UpperCAmelCase	: str		=					residx_atomaa_mask
			__UpperCAmelCase	: List[Any]		=					residx_atomaa_to_atomaa.long()

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

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

			__UpperCAmelCase	: List[str]		=					restype_atomaa_mask[protein_aatype]
			__UpperCAmelCase	: Union[str, Any]		=					residx_atomaa_mask

			return protein





def 					_UpperCamelCase    (			UpperCamelCase							)			->			Dict[str, np.ndarray]:


			"""simple docstring"""
			__UpperCAmelCase	: Any		=					tree_map(lambda UpperCamelCase							: torch.tensor(UpperCamelCase				,       device=batch["aatype"].device							)				,       UpperCamelCase				,       np.ndarray							)
			__UpperCAmelCase	: Tuple		=					tensor_tree_map(lambda UpperCamelCase							: np.array(UpperCamelCase							)				,       make_atomaa_masks(UpperCamelCase							)							)
			return out








"""simple docstring"""





from typing import Optional

import pyspark

from .. import Features, NamedSplit
from ..download import DownloadMode
from ..packaged_modules.spark.spark import Spark
from .abc import AbstractDatasetReader



class      a__				(	__magic_name__   ):


			def __init__(      self      :    List[Any]      ,  UpperCamelCase_      :    pyspark.sql.DataFrame      ,  UpperCamelCase_      :    Optional[NamedSplit] = None      ,  UpperCamelCase_      :    Optional[Features] = None      ,  UpperCamelCase_      :    bool = True      ,  UpperCamelCase_      :    str = None      ,  UpperCamelCase_      :    bool = False      ,  UpperCamelCase_      :    str = None      ,  UpperCamelCase_      :    bool = True      ,  UpperCamelCase_      :    str = "arrow"      ,  **UpperCamelCase_      :    Tuple      ,  ):


						"""simple docstring"""




						super().__init__(
						    split=UpperCamelCase_      ,  features=UpperCamelCase_      ,  cache_dir=UpperCamelCase_      ,  keep_in_memory=UpperCamelCase_      ,  streaming=UpperCamelCase_      ,  **UpperCamelCase_      ,  )
						__UpperCAmelCase	: List[Any]		=					load_from_cache_file
						__UpperCAmelCase	: List[Any]		=					file_format
						__UpperCAmelCase	: str		=					Spark(
						    df=UpperCamelCase_      ,  features=UpperCamelCase_      ,  cache_dir=UpperCamelCase_      ,  working_dir=UpperCamelCase_      ,  **UpperCamelCase_      ,  )


			def       a_     (      self      :    Union[str, Any]):


						"""simple docstring"""




						if self.streaming:
									return self.builder.as_streaming_dataset(split=self.split)
						__UpperCAmelCase	: List[Any]		=					None if self._load_from_cache_file else DownloadMode.FORCE_REDOWNLOAD
						self.builder.download_and_prepare(
						    download_mode=UpperCamelCase_      ,  file_format=self._file_format      ,  )
						return self.builder.as_dataset(split=self.split)


