






from typing import Dict, Tuple, overload

import torch
import torch.types
from torch import nn

from . import residue_constants as rc
from .rigid_utils import Rigid, Rotation
from .tensor_utils import batched_gather
@overload
def 		_a					(   a				:torch.Tensor			,							a				:torch.Tensor			,							a				:None				)							->    torch.Tensor:
 ...
@overload
def 		_a					(   a				:torch.Tensor			,							a				:torch.Tensor			,							a				:torch.Tensor				)							->    Tuple[torch.Tensor, torch.Tensor]:
 ...
def 		_a					(   a				:Any			,							a				:List[str]			,							a				:Optional[int]				)							->    Tuple:
 a							=   aatype == rc.restype_order['''G''']
 a							=   rc.atom_order['''CA''']
 a							=   rc.atom_order['''CB''']
 a							=   torch.where(
     is_gly[..., None].expand(*((-1,) * len(is_gly.shape				))			,							3				)			,							all_atom_positions[..., ca_idx, :]			,							all_atom_positions[..., cb_idx, :]			,							)

 if all_atom_masks is not None:
  a							=   torch.where(
      a			,							all_atom_masks[..., ca_idx]			,							all_atom_masks[..., cb_idx]			,							)
  return pseudo_beta, pseudo_beta_mask
 else:
  return pseudo_beta
def 		_a					(   a				:torch.Tensor			,							a				:Dict[str, torch.Tensor]				)							->    torch.Tensor:
 a							=   batched_gather(
     a			,							batch['''residx_atom37_to_atom14''']			,							dim=-2			,							no_batch_dims=len(atomaa.shape[:-2]				)			,							)

 a							=   atomaa_data * batch['''atom37_atom_exists'''][..., None]

 return atomaa_data
def 		_a					(   a				:Dict[str, torch.Tensor]				)							->    torch.Tensor:
 a							=   template_feats['''template_aatype''']
 a							=   template_feats['''template_torsion_angles_sin_cos''']
 a							=   template_feats['''template_alt_torsion_angles_sin_cos''']
 a							=   template_feats['''template_torsion_angles_mask''']
 a							=   torch.cat(
     [
         nn.functional.one_hot(a			,							22				),
         torsion_angles_sin_cos.reshape(*torsion_angles_sin_cos.shape[:-2]			,							14				),
         alt_torsion_angles_sin_cos.reshape(*alt_torsion_angles_sin_cos.shape[:-2]			,							14				),
         torsion_angles_mask,
     ]			,							dim=-1			,							)

 return template_angle_feat
def 		_a					(   a				:Dict[str, torch.Tensor]			,							a				:torch.types.Number			,							a				:torch.types.Number			,							a				:int			,							a				:bool = False			,							a				:float = 1e-20			,							a				:float = 1e8			,							)							->    torch.Tensor:
 a							=   batch['''template_pseudo_beta_mask''']
 a							=   template_mask[..., None] * template_mask[..., None, :]

 # Compute distogram (this seems to differ slightly from Alg. 5)
 a							=   batch['''template_pseudo_beta''']
 a							=   torch.sum((tpb[..., None, :] - tpb[..., None, :, :]) ** 2			,							dim=-1			,							keepdim=a				)
 a							=   torch.linspace(a			,							a			,							a			,							device=tpb.device				) ** 2
 a							=   torch.cat([lower[1:], lower.new_tensor([inf]				)]			,							dim=-1				)
 a							=   ((dgram > lower) * (dgram < upper)).type(dgram.dtype				)

 a							=   [dgram, template_mask_ad[..., None]]

 a							=   nn.functional.one_hot(
     batch['''template_aatype''']			,							rc.restype_num + 2			,							)

 a							=   batch['''template_aatype'''].shape[-1]
 to_concat.append(aatype_one_hot[..., None, :, :].expand(*aatype_one_hot.shape[:-2]			,							a			,							-1			,							-1				)				)
 to_concat.append(aatype_one_hot[..., None, :].expand(*aatype_one_hot.shape[:-2]			,							-1			,							a			,							-1				)				)

 a						,  a						,  a							=   [rc.atom_order[a] for a in ['''N''', '''CA''', '''C''']]
 a							=   Rigid.make_transform_from_reference(
     n_xyz=batch['''template_all_atom_positions'''][..., n, :]			,							ca_xyz=batch['''template_all_atom_positions'''][..., ca, :]			,							c_xyz=batch['''template_all_atom_positions'''][..., c, :]			,							eps=a			,							)
 a							=   rigids.get_trans()[..., None, :, :]
 a							=   rigids[..., None].invert_apply(a				)

 a							=   torch.rsqrt(eps + torch.sum(rigid_vec**2			,							dim=-1				)				)

 a							=   batch['''template_all_atom_mask''']
 a							=   t_aa_masks[..., n] * t_aa_masks[..., ca] * t_aa_masks[..., c]
 a							=   template_mask[..., None] * template_mask[..., None, :]

 a							=   inv_distance_scalar * template_mask_ad
 a							=   rigid_vec * inv_distance_scalar[..., None]

 if not use_unit_vector:
  a							=   unit_vector * 0.0

 to_concat.extend(torch.unbind(unit_vector[..., None, :]			,							dim=-1				)				)
 to_concat.append(template_mask_ad[..., None]				)

 a							=   torch.cat(a			,							dim=-1				)
 a							=   act * template_mask_ad[..., None]

 return act
def 		_a					(   a				:Dict[str, torch.Tensor]				)							->    torch.Tensor:
 a							=   nn.functional.one_hot(batch['''extra_msa''']			,							23				)
 a							=   [
     msa_ahot,
     batch['''extra_has_deletion'''].unsqueeze(-1				),
     batch['''extra_deletion_value'''].unsqueeze(-1				),
 ]
 return torch.cat(a			,							dim=-1				)
def 		_a					(   a				:Rigid			,							a				:torch.Tensor			,							a				:torch.Tensor			,							a				:torch.Tensor			,							)							->    Rigid:
 # [*, N, 8, 4, 4]
 a							=   rrgdf[aatype, ...]

 # [*, N, 8] transformations, i.e.
 #   One [*, N, 8, 3, 3] rotation matrix and
 #   One [*, N, 8, 3]    translation matrix
 a							=   r.from_tensor_axa(a				)

 a							=   alpha.new_zeros((*((1,) * len(alpha.shape[:-1]				)), 2)				)
 a							=   1

 # [*, N, 8, 2]
 a							=   torch.cat([bb_rot.expand(*alpha.shape[:-2]			,							-1			,							-1				), alpha]			,							dim=-2				)

 # [*, N, 8, 3, 3]
 # Produces rotation matrices of the form:
 # [
 #   [1, 0  , 0  ],
 #   [0, a_2,-a_1],
 #   [0, a_1, a_2]
 # ]
 # This follows the original code rather than the supplement, which uses
 # different indices.

 a							=   alpha.new_zeros(default_r.get_rots().get_rot_mats().shape				)
 a							=   1
 a							=   alpha[..., 1]
 a							=   -alpha[..., 0]
 a							=   alpha

 a							=   default_r.compose(Rigid(Rotation(rot_mats=a				)			,							a				)				)

 a							=   all_frames[..., 5]
 a							=   all_frames[..., 6]
 a							=   all_frames[..., 7]

 a							=   all_frames[..., 4]
 a							=   chia_frame_to_bb.compose(a				)
 a							=   chia_frame_to_bb.compose(a				)
 a							=   chia_frame_to_bb.compose(a				)

 a							=   Rigid.cat(
     [
         all_frames[..., :5],
         chia_frame_to_bb.unsqueeze(-1				),
         chia_frame_to_bb.unsqueeze(-1				),
         chia_frame_to_bb.unsqueeze(-1				),
     ]			,							dim=-1			,							)

 a							=   r[..., None].compose(a				)

 return all_frames_to_global

def 		_a					(   a				:Rigid			,							a				:torch.Tensor			,							a				:torch.Tensor			,							a				:torch.Tensor			,							a				:torch.Tensor			,							a				:torch.Tensor			,							)							->    torch.Tensor:
 # [*, N, 14]
 a							=   group_idx[aatype, ...]

 # [*, N, 14, 8]
 a							=   nn.functional.one_hot(
     a			,							num_classes=default_frames.shape[-3]			,							)

 # [*, N, 14, 8]
 a							=   r[..., None, :] * group_mask_one_hot

 # [*, N, 14]
 a							=   t_atoms_to_global.map_tensor_fn(lambda a				: torch.sum(a			,							dim=-1				)				)

 # [*, N, 14, 1]
 a							=   atom_mask[aatype, ...].unsqueeze(-1				)

 # [*, N, 14, 3]
 a							=   lit_positions[aatype, ...]
 a							=   t_atoms_to_global.apply(a				)
 a							=   pred_positions * atom_mask

 return pred_positions










import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding






class 	lowercase_      (			lowercase     ):






      '''simple docstring'''




      __snake_case  						=						['''image_processor''', '''tokenizer''']
      __snake_case  						=						'''AutoImageProcessor'''
      __snake_case  						=						'''AutoTokenizer'''







      def __init__(   self   :		Any				,      __UpperCAmelCase   :		Union[str, Any]=None				,      __UpperCAmelCase   :		int=None				,      **__UpperCAmelCase   :		Union[str, Any]						)					->Dict:




       """simple docstring"""


       a							=   None
       if "feature_extractor" in kwargs:
        warnings.warn(
            '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
            ''' instead.'''				,      __UpperCAmelCase				,      )
        a							=   kwargs.pop('''feature_extractor'''						)

       a							=   image_processor if image_processor is not None else feature_extractor
       if image_processor is None:
        raise ValueError('''You have to specify an image_processor.'''						)
       if tokenizer is None:
        raise ValueError('''You have to specify a tokenizer.'''						)

       super().__init__(__UpperCAmelCase				,      __UpperCAmelCase						)
       a							=   self.image_processor







      def __call__(   self   :		List[Any]				,      __UpperCAmelCase   :		Optional[Any]=None				,      __UpperCAmelCase   :		Optional[int]=None				,      __UpperCAmelCase   :		str=None				,      **__UpperCAmelCase   :		List[Any]						)					->Dict:




       """simple docstring"""


       if text is None and images is None:
        raise ValueError('''You have to specify either text or images. Both cannot be none.'''						)

       if text is not None:
        a							=   self.tokenizer(__UpperCAmelCase				,      return_tensors=__UpperCAmelCase				,      **__UpperCAmelCase						)

       if images is not None:
        a							=   self.image_processor(__UpperCAmelCase				,      return_tensors=__UpperCAmelCase				,      **__UpperCAmelCase						)

       if text is not None and images is not None:
        a							=   image_features.pixel_values
        return encoding
       elif text is not None:
        return encoding
       else:
        return BatchEncoding(data=dict(**__UpperCAmelCase						)				,      tensor_type=__UpperCAmelCase						)







      def    __lowerCAmelCase      (   self   :		List[Any]				,      *__UpperCAmelCase   :		Optional[Any]				,      **__UpperCAmelCase   :		List[str]						)					->Optional[Any]:




       """simple docstring"""


       return self.tokenizer.batch_decode(*__UpperCAmelCase				,      **__UpperCAmelCase						)







      def    __lowerCAmelCase      (   self   :		str				,      *__UpperCAmelCase   :		List[Any]				,      **__UpperCAmelCase   :		Optional[Any]						)					->Union[str, Any]:




       """simple docstring"""


       return self.tokenizer.decode(*__UpperCAmelCase				,      **__UpperCAmelCase						)







      @property
      def    __lowerCAmelCase      (   self   :		str						)					->str:




       """simple docstring"""


       a							=   self.tokenizer.model_input_names
       a							=   self.image_processor.model_input_names
       return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names						)						)







      @property
      def    __lowerCAmelCase      (   self   :		str						)					->Optional[Any]:




       """simple docstring"""


       warnings.warn(
           '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''				,      __UpperCAmelCase				,      )
       return self.image_processor_class







      @property
      def    __lowerCAmelCase      (   self   :		int						)					->Optional[Any]:




       """simple docstring"""


       warnings.warn(
           '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'''				,      __UpperCAmelCase				,      )
       return self.image_processor


