

from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


__UpperCAmelCase    				=     logging.get_logger(__name__)





class A__    ( A ):



 """simple docstring"""







 _lowercase     :					Optional[int]      =						['''pixel_values''']

 def __init__(		self :	List[Any]     ,						A_ :	bool = True     ,						A_ :	Optional[Dict[str, int]] = None     ,						A_ :	PILImageResampling = PILImageResampling.BILINEAR     ,						A_ :	bool = True     ,						A_ :	Dict[str, int] = None     ,						A_ :	bool = True     ,						A_ :	Union[int, float] = 1 / 2_5_5     ,						A_ :	bool = True     ,						A_ :	Optional[Union[float, List[float]]] = None     ,						A_ :	Optional[Union[float, List[float]]] = None     ,						**A_ :	Dict     ,						):






      '''simple docstring'''




      super().__init__(**A_       )
      _lowerCAmelCase   :					List[str]        =    size if size is not None else {"shortest_edge": 2_5_6}
      _lowerCAmelCase   :					int        =    get_size_dict(A_     ,						default_to_square=A_       )
      _lowerCAmelCase   :					Any        =    crop_size if crop_size is not None else {"height": 2_2_4, "width": 2_2_4}
      _lowerCAmelCase   :					Optional[Any]        =    get_size_dict(A_       )
      _lowerCAmelCase   :					Optional[int]        =    do_resize
      _lowerCAmelCase   :					Optional[Any]        =    size
      _lowerCAmelCase   :					Tuple        =    resample
      _lowerCAmelCase   :					Optional[Any]        =    do_center_crop
      _lowerCAmelCase   :					str        =    crop_size
      _lowerCAmelCase   :					Optional[Any]        =    do_rescale
      _lowerCAmelCase   :					List[Any]        =    rescale_factor
      _lowerCAmelCase   :					Union[str, Any]        =    do_normalize
      _lowerCAmelCase   :					Optional[int]        =    image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
      _lowerCAmelCase   :					Optional[int]        =    image_std if image_std is not None else IMAGENET_STANDARD_STD

 def    __magic_name__       (		self :	Dict     ,						A_ :	np.ndarray     ,						A_ :	Dict[str, int]     ,						A_ :	PILImageResampling = PILImageResampling.BICUBIC     ,						A_ :	Optional[Union[str, ChannelDimension]] = None     ,						**A_ :	int     ,						):






      '''simple docstring'''




      _lowerCAmelCase   :					Optional[Any]        =    get_size_dict(A_     ,						default_to_square=A_       )
      if "shortest_edge" not in size:
           raise ValueError(F'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'''       )
      _lowerCAmelCase   :					Optional[Any]        =    get_resize_output_image_size(A_     ,						size=size["shortest_edge"]     ,						default_to_square=A_       )
      return resize(A_     ,						size=A_     ,						resample=A_     ,						data_format=A_     ,						**A_       )

 def    __magic_name__       (		self :	List[str]     ,						A_ :	np.ndarray     ,						A_ :	Dict[str, int]     ,						A_ :	Optional[Union[str, ChannelDimension]] = None     ,						**A_ :	int     ,						):






      '''simple docstring'''




      _lowerCAmelCase   :					List[Any]        =    get_size_dict(A_       )
      return center_crop(A_     ,						size=(size["height"], size["width"])     ,						data_format=A_     ,						**A_       )

 def    __magic_name__       (		self :	List[str]     ,						A_ :	np.ndarray     ,						A_ :	float     ,						A_ :	Optional[Union[str, ChannelDimension]] = None     ,						**A_ :	Tuple       ):






      '''simple docstring'''




      return rescale(A_     ,						scale=A_     ,						data_format=A_     ,						**A_       )

 def    __magic_name__       (		self :	str     ,						A_ :	np.ndarray     ,						A_ :	Union[float, List[float]]     ,						A_ :	Union[float, List[float]]     ,						A_ :	Optional[Union[str, ChannelDimension]] = None     ,						**A_ :	Any     ,						):






      '''simple docstring'''




      return normalize(A_     ,						mean=A_     ,						std=A_     ,						data_format=A_     ,						**A_       )


 def    __magic_name__       (		self :	Optional[int]     ,						A_ :	ImageInput     ,						A_ :	Optional[bool] = None     ,						A_ :	Dict[str, int] = None     ,						A_ :	PILImageResampling = None     ,						A_ :	bool = None     ,						A_ :	Dict[str, int] = None     ,						A_ :	Optional[bool] = None     ,						A_ :	Optional[float] = None     ,						A_ :	Optional[bool] = None     ,						A_ :	Optional[Union[float, List[float]]] = None     ,						A_ :	Optional[Union[float, List[float]]] = None     ,						A_ :	Optional[Union[str, TensorType]] = None     ,						A_ :	Union[str, ChannelDimension] = ChannelDimension.FIRST     ,						**A_ :	Optional[int]     ,						):






      '''simple docstring'''




      _lowerCAmelCase   :					Dict        =    do_resize if do_resize is not None else self.do_resize
      _lowerCAmelCase   :					Optional[Any]        =    size if size is not None else self.size
      _lowerCAmelCase   :					Dict        =    get_size_dict(A_     ,						default_to_square=A_       )
      _lowerCAmelCase   :					str        =    resample if resample is not None else self.resample
      _lowerCAmelCase   :					List[str]        =    do_center_crop if do_center_crop is not None else self.do_center_crop
      _lowerCAmelCase   :					Any        =    crop_size if crop_size is not None else self.crop_size
      _lowerCAmelCase   :					int        =    get_size_dict(A_       )
      _lowerCAmelCase   :					Dict        =    do_rescale if do_rescale is not None else self.do_rescale
      _lowerCAmelCase   :					Union[str, Any]        =    rescale_factor if rescale_factor is not None else self.rescale_factor
      _lowerCAmelCase   :					Any        =    do_normalize if do_normalize is not None else self.do_normalize
      _lowerCAmelCase   :					List[Any]        =    image_mean if image_mean is not None else self.image_mean
      _lowerCAmelCase   :					Union[str, Any]        =    image_std if image_std is not None else self.image_std

      _lowerCAmelCase   :					int        =    make_list_of_images(A_       )

      if not valid_images(A_       ):
           raise ValueError(
               "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
               "torch.Tensor, tf.Tensor or jax.ndarray."       )

      if do_resize and size is None:
           raise ValueError("Size must be specified if do_resize is True."       )

      if do_center_crop and crop_size is None:
           raise ValueError("Crop size must be specified if do_center_crop is True."       )

      if do_rescale and rescale_factor is None:
           raise ValueError("Rescale factor must be specified if do_rescale is True."       )

      if do_normalize and (image_mean is None or image_std is None):
           raise ValueError("Image mean and std must be specified if do_normalize is True."       )

      # All transformations expect numpy arrays.
      _lowerCAmelCase   :					List[Any]        =    [to_numpy_array(A_       ) for image in images]

      if do_resize:
           _lowerCAmelCase   :					List[Any]        =    [self.resize(image=A_     ,						size=A_     ,						resample=A_       ) for image in images]

      if do_center_crop:
           _lowerCAmelCase   :					Dict        =    [self.center_crop(image=A_     ,						size=A_       ) for image in images]

      if do_rescale:
           _lowerCAmelCase   :					Dict        =    [self.rescale(image=A_     ,						scale=A_       ) for image in images]

      if do_normalize:
           _lowerCAmelCase   :					Dict        =    [self.normalize(image=A_     ,						mean=A_     ,						std=A_       ) for image in images]

      _lowerCAmelCase   :					int        =    [to_channel_dimension_format(A_     ,						A_       ) for image in images]

      _lowerCAmelCase   :					List[str]        =    {"pixel_values": images}
      return BatchFeature(data=A_     ,						tensor_type=A_       )









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

     """simple docstring"""







     _lowerCAmelCase   :					int        =    []
     _lowerCAmelCase   :					Tuple        =    []
     _lowerCAmelCase   :					List[Any]        =    []

     for rt in rc.restypes:
          _lowerCAmelCase   :					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]				)
          _lowerCAmelCase   :					str        =    {name: i for i, name in enumerate(SCREAMING_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] * 14				)
     restype_atomaa_to_atomaa_list.append([0] * 37				)
     restype_atomaa_mask_list.append([0.0] * 14				)

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

     _lowerCAmelCase   :					Any        =    residx_atomaa_mask
     _lowerCAmelCase   :					Dict        =    residx_atomaa_to_atomaa.long()

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

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

     _lowerCAmelCase   :					Tuple        =    restype_atomaa_mask[protein_aatype]
     _lowerCAmelCase   :					List[str]        =    residx_atomaa_mask

     return protein







def 	_snake_case		(    SCREAMING_SNAKE_CASE				)       ->      Dict[str, np.ndarray]:

     """simple docstring"""







     _lowerCAmelCase   :					Any        =    tree_map(lambda SCREAMING_SNAKE_CASE				: torch.tensor(SCREAMING_SNAKE_CASE		,							device=batch["aatype"].device				)		,							SCREAMING_SNAKE_CASE		,							np.ndarray				)
     _lowerCAmelCase   :					Optional[int]        =    tensor_tree_map(lambda SCREAMING_SNAKE_CASE				: np.array(SCREAMING_SNAKE_CASE				)		,							make_atomaa_masks(SCREAMING_SNAKE_CASE				)				)
     return out






