





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import OwlViTImageProcessor




class    _a  (  unittest.TestCase):

      """simple docstring"""


      def __init__(						self:	List[Any]					,  __lowerCamelCase:	Optional[int]					,  __lowerCamelCase:	Tuple=7					,  __lowerCamelCase:	str=3					,  __lowerCamelCase:	List[str]=18					,  __lowerCamelCase:	Tuple=30					,  __lowerCamelCase:	Optional[int]=400					,  __lowerCamelCase:	Tuple=True					,  __lowerCamelCase:	List[Any]=None					,  __lowerCamelCase:	Dict=True					,  __lowerCamelCase:	str=None					,  __lowerCamelCase:	Tuple=True					,  __lowerCamelCase:	Union[str, Any]=[0.48_145_466, 0.4_578_275, 0.40_821_073]					,  __lowerCamelCase:	Any=[0.26_862_954, 0.26_130_258, 0.27_577_711]					,  __lowerCamelCase:	List[str]=True					,  ):
          '''simple docstring'''


          UpperCamelCase__:					Optional[int]												=      parent
          UpperCamelCase__:					Optional[Any]												=      batch_size
          UpperCamelCase__:					Union[str, Any]												=      num_channels
          UpperCamelCase__:					Optional[int]												=      image_size
          UpperCamelCase__:					List[str]												=      min_resolution
          UpperCamelCase__:					Optional[Any]												=      max_resolution
          UpperCamelCase__:					Optional[Any]												=      do_resize
          UpperCamelCase__:					str												=      size if size is not None else {"height": 18, "width": 18}
          UpperCamelCase__:					str												=      do_center_crop
          UpperCamelCase__:					Any												=      crop_size if crop_size is not None else {"height": 18, "width": 18}
          UpperCamelCase__:					List[Any]												=      do_normalize
          UpperCamelCase__:					Dict												=      image_mean
          UpperCamelCase__:					List[str]												=      image_std
          UpperCamelCase__:					Optional[int]												=      do_convert_rgb






      def 	UpperCAmelCase_   (						self:	Tuple			):
          '''simple docstring'''


          return {
              "do_resize": self.do_resize,
              "size": self.size,
              "do_center_crop": self.do_center_crop,
              "crop_size": self.crop_size,
              "do_normalize": self.do_normalize,
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_convert_rgb": self.do_convert_rgb,
          }




@require_torch
@require_vision
class    _a  (  UpperCamelCase__		,	unittest.TestCase):

      """simple docstring"""


      UpperCamelCase__       						=   OwlViTImageProcessor if is_vision_available() else None






      def 	UpperCAmelCase_   (						self:	str			):
          '''simple docstring'''


          UpperCamelCase__:					List[str]												=      OwlViTImageProcessingTester(self			)






      @property
      def 	UpperCAmelCase_   (						self:	Union[str, Any]			):
          '''simple docstring'''


          return self.image_processor_tester.prepare_image_processor_dict()






      def 	UpperCAmelCase_   (						self:	Optional[int]			):
          '''simple docstring'''


          UpperCamelCase__:					str												=      self.image_processing_class(**self.image_processor_dict			)
          self.assertTrue(hasattr(__lowerCamelCase					,  "do_resize"			)			)
          self.assertTrue(hasattr(__lowerCamelCase					,  "size"			)			)
          self.assertTrue(hasattr(__lowerCamelCase					,  "do_center_crop"			)			)
          self.assertTrue(hasattr(__lowerCamelCase					,  "center_crop"			)			)
          self.assertTrue(hasattr(__lowerCamelCase					,  "do_normalize"			)			)
          self.assertTrue(hasattr(__lowerCamelCase					,  "image_mean"			)			)
          self.assertTrue(hasattr(__lowerCamelCase					,  "image_std"			)			)
          self.assertTrue(hasattr(__lowerCamelCase					,  "do_convert_rgb"			)			)






      def 	UpperCAmelCase_   (						self:	Optional[Any]			):
          '''simple docstring'''


          UpperCamelCase__:					Any												=      self.image_processing_class.from_dict(self.image_processor_dict			)
          self.assertEqual(image_processor.size					,  {"height": 18, "width": 18}			)
          self.assertEqual(image_processor.crop_size					,  {"height": 18, "width": 18}			)

          UpperCamelCase__:					Optional[Any]												=      self.image_processing_class.from_dict(self.image_processor_dict					,  size=42					,  crop_size=84			)
          self.assertEqual(image_processor.size					,  {"height": 42, "width": 42}			)
          self.assertEqual(image_processor.crop_size					,  {"height": 84, "width": 84}			)






      def 	UpperCAmelCase_   (						self:	Dict			):
          '''simple docstring'''


          UpperCamelCase__:					Tuple												=      self.image_processing_class(**self.image_processor_dict			)
          # create random PIL images
          UpperCamelCase__:					List[Any]												=      prepare_image_inputs(self.image_processor_tester					,  equal_resolution=__lowerCamelCase			)

          for image in image_inputs:
              self.assertIsInstance(__lowerCamelCase					,  Image.Image			)

          # Test not batched input
          UpperCamelCase__:					Optional[Any]												=      image_processing(image_inputs[0]					,  return_tensors="pt"			).pixel_values
          self.assertEqual(
              encoded_images.shape					,  (
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )					,  )

          # Test batched
          UpperCamelCase__:					Any												=      image_processing(__lowerCamelCase					,  return_tensors="pt"			).pixel_values
          self.assertEqual(
              encoded_images.shape					,  (
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )					,  )






      def 	UpperCAmelCase_   (						self:	str			):
          '''simple docstring'''


          UpperCamelCase__:					Union[str, Any]												=      self.image_processing_class(**self.image_processor_dict			)
          # create random numpy tensors
          UpperCamelCase__:					List[Any]												=      prepare_image_inputs(self.image_processor_tester					,  equal_resolution=__lowerCamelCase					,  numpify=__lowerCamelCase			)
          for image in image_inputs:
              self.assertIsInstance(__lowerCamelCase					,  np.ndarray			)

          # Test not batched input
          UpperCamelCase__:					str												=      image_processing(image_inputs[0]					,  return_tensors="pt"			).pixel_values
          self.assertEqual(
              encoded_images.shape					,  (
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )					,  )

          # Test batched
          UpperCamelCase__:					Union[str, Any]												=      image_processing(__lowerCamelCase					,  return_tensors="pt"			).pixel_values
          self.assertEqual(
              encoded_images.shape					,  (
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )					,  )






      def 	UpperCAmelCase_   (						self:	int			):
          '''simple docstring'''


          UpperCamelCase__:					str												=      self.image_processing_class(**self.image_processor_dict			)
          # create random PyTorch tensors
          UpperCamelCase__:					Optional[Any]												=      prepare_image_inputs(self.image_processor_tester					,  equal_resolution=__lowerCamelCase					,  torchify=__lowerCamelCase			)
          for image in image_inputs:
              self.assertIsInstance(__lowerCamelCase					,  torch.Tensor			)

          # Test not batched input
          UpperCamelCase__:					str												=      image_processing(image_inputs[0]					,  return_tensors="pt"			).pixel_values
          self.assertEqual(
              encoded_images.shape					,  (
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )					,  )

          # Test batched
          UpperCamelCase__:					Tuple												=      image_processing(__lowerCamelCase					,  return_tensors="pt"			).pixel_values
          self.assertEqual(
              encoded_images.shape					,  (
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )					,  )








from .chunk_utils import chunk_layer
from .data_transforms import make_atomaa_masks
from .feats import atomaa_to_atomaa, frames_and_literature_positions_to_atomaa_pos, torsion_angles_to_frames
from .loss import compute_predicted_aligned_error, compute_tm
from .protein import Protein as OFProtein
from .protein import to_pdb
from .rigid_utils import Rigid, Rotation
from .tensor_utils import dict_multimap, flatten_final_dims, permute_final_dims

