



import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers.models.esm.modeling_esmfold import EsmForProteinFolding


class       a							:



		def __init__(     self     :Optional[int]   ,__lowercase     :Dict   ,__lowercase     :Optional[int]=1_3   ,__lowercase     :Tuple=7   ,__lowercase     :Optional[Any]=False   ,__lowercase     :Dict=True   ,__lowercase     :Any=False   ,__lowercase     :str=False   ,__lowercase     :Tuple=1_9   ,__lowercase     :int=3_2   ,__lowercase     :List[str]=5   ,__lowercase     :int=4   ,__lowercase     :str=3_7   ,__lowercase     :Union[str, Any]="gelu"   ,__lowercase     :List[Any]=0.1   ,__lowercase     :List[Any]=0.1   ,__lowercase     :str=5_1_2   ,__lowercase     :Any=1_6   ,__lowercase     :Union[str, Any]=2   ,__lowercase     :int=0.02   ,__lowercase     :int=3   ,__lowercase     :List[str]=4   ,__lowercase     :Any=None   ,):
						snake_case__	:      str     		=	parent
						snake_case__	:      Any     		=	batch_size
						snake_case__	:      Dict     		=	seq_length
						snake_case__	:      Tuple     		=	is_training
						snake_case__	:      List[str]     		=	use_input_mask
						snake_case__	:      Any     		=	use_token_type_ids
						snake_case__	:      Union[str, Any]     		=	use_labels
						snake_case__	:      List[str]     		=	vocab_size
						snake_case__	:      Dict     		=	hidden_size
						snake_case__	:      Union[str, Any]     		=	num_hidden_layers
						snake_case__	:      Any     		=	num_attention_heads
						snake_case__	:      Optional[Any]     		=	intermediate_size
						snake_case__	:      int     		=	hidden_act
						snake_case__	:      List[str]     		=	hidden_dropout_prob
						snake_case__	:      str     		=	attention_probs_dropout_prob
						snake_case__	:      Tuple     		=	max_position_embeddings
						snake_case__	:      List[str]     		=	type_vocab_size
						snake_case__	:      Optional[int]     		=	type_sequence_label_size
						snake_case__	:      Tuple     		=	initializer_range
						snake_case__	:      int     		=	num_labels
						snake_case__	:      str     		=	num_choices
						snake_case__	:      int     		=	scope



		def 	__lowerCamelCase			(     self     :int  ):
						snake_case__	:      Tuple     		=	ids_tensor([self.batch_size, self.seq_length]   ,self.vocab_size  )

						snake_case__	:      int     		=	None
						if self.use_input_mask:
										snake_case__	:      Optional[Any]     		=	random_attention_mask([self.batch_size, self.seq_length]  )

						snake_case__	:      Optional[Any]     		=	None
						snake_case__	:      Optional[int]     		=	None
						snake_case__	:      Optional[int]     		=	None
						if self.use_labels:
										snake_case__	:      List[str]     		=	ids_tensor([self.batch_size]   ,self.type_sequence_label_size  )
										snake_case__	:      List[str]     		=	ids_tensor([self.batch_size, self.seq_length]   ,self.num_labels  )
										snake_case__	:      Any     		=	ids_tensor([self.batch_size]   ,self.num_choices  )

						snake_case__	:      Tuple     		=	self.get_config()

						return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels



		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						snake_case__	:      Optional[int]     		=	EsmConfig(
						    vocab_size=3_3   ,hidden_size=self.hidden_size   ,pad_token_id=1   ,num_hidden_layers=self.num_hidden_layers   ,num_attention_heads=self.num_attention_heads   ,intermediate_size=self.intermediate_size   ,hidden_act=self.hidden_act   ,hidden_dropout_prob=self.hidden_dropout_prob   ,attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,max_position_embeddings=self.max_position_embeddings   ,type_vocab_size=self.type_vocab_size   ,initializer_range=self.initializer_range   ,is_folding_model=__lowercase   ,esmfold_config={'''trunk''': {'''num_blocks''': 2}, '''fp16_esm''': False}   ,)
						return config



		def 	__lowerCamelCase			(     self     :Any   ,__lowercase     :Union[str, Any]   ,__lowercase     :List[Any]   ,__lowercase     :Tuple   ,__lowercase     :Optional[Any]   ,__lowercase     :Union[str, Any]   ,__lowercase     :Optional[int]  ):
						snake_case__	:      List[str]     		=	EsmForProteinFolding(config=__lowercase  ).float()
						model.to(__lowercase  )
						model.eval()
						snake_case__	:      Dict     		=	model(__lowercase   ,attention_mask=__lowercase  )
						snake_case__	:      int     		=	model(__lowercase  )
						snake_case__	:      List[Any]     		=	model(__lowercase  )

						self.parent.assertEqual(result.positions.shape   ,(8, self.batch_size, self.seq_length, 1_4, 3)  )
						self.parent.assertEqual(result.angles.shape   ,(8, self.batch_size, self.seq_length, 7, 2)  )






		def 	__lowerCamelCase			(     self     :List[Any]  ):
						snake_case__	:      List[str]     		=	self.prepare_config_and_inputs()
						(
						    (
						    snake_case__						
						)		, (
						    snake_case__						
						)		, (
						    snake_case__						
						)		, (
						    snake_case__						
						)		, (
						    snake_case__						
						)		, (
						    snake_case__						
						)		, 						
						)	:      str     		=	config_and_inputs
						snake_case__	:      Union[str, Any]     		=	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
						return config, inputs_dict


@require_torch
class       a							(			A__  ,							A__  ,							unittest.TestCase				):
		__lowerCAmelCase	:    Any											=					False

		__lowerCAmelCase	:    Any											=					(EsmForProteinFolding,) if is_torch_available() else ()
		__lowerCAmelCase	:    Any											=					()
		__lowerCAmelCase	:    List[Any]											=					{} if is_torch_available() else {}
		__lowerCAmelCase	:    Optional[int]											=					False



		def 	__lowerCamelCase			(     self     :Tuple  ):
						snake_case__	:      Any     		=	EsmFoldModelTester(self  )
						snake_case__	:      str     		=	ConfigTester(self   ,config_class=__lowercase   ,hidden_size=3_7  )



		def 	__lowerCamelCase			(     self     :List[str]  ):
						self.config_tester.run_common_tests()



		def 	__lowerCamelCase			(     self     :List[Any]  ):
						snake_case__	:      Optional[int]     		=	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__lowercase  )



		@unittest.skip('''Does not support attention outputs'''  )
		def 	__lowerCamelCase			(     self     :Optional[Any]  ):
						pass



		@unittest.skip
		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						pass



		@unittest.skip('''Esm does not support embedding resizing'''  )
		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						pass



		@unittest.skip('''Esm does not support embedding resizing'''  )
		def 	__lowerCamelCase			(     self     :List[Any]  ):
						pass



		@unittest.skip('''ESMFold does not support passing input embeds!'''  )
		def 	__lowerCamelCase			(     self     :Tuple  ):
						pass



		@unittest.skip('''ESMFold does not support head pruning.'''  )
		def 	__lowerCamelCase			(     self     :Tuple  ):
						pass



		@unittest.skip('''ESMFold does not support head pruning.'''  )
		def 	__lowerCamelCase			(     self     :Dict  ):
						pass



		@unittest.skip('''ESMFold does not support head pruning.'''  )
		def 	__lowerCamelCase			(     self     :int  ):
						pass



		@unittest.skip('''ESMFold does not support head pruning.'''  )
		def 	__lowerCamelCase			(     self     :Any  ):
						pass



		@unittest.skip('''ESMFold does not support head pruning.'''  )
		def 	__lowerCamelCase			(     self     :Any  ):
						pass



		@unittest.skip('''ESMFold does not output hidden states in the normal way.'''  )
		def 	__lowerCamelCase			(     self     :Optional[Any]  ):
						pass



		@unittest.skip('''ESMfold does not output hidden states in the normal way.'''  )
		def 	__lowerCamelCase			(     self     :Dict  ):
						pass



		@unittest.skip('''ESMFold only has one output format.'''  )
		def 	__lowerCamelCase			(     self     :Tuple  ):
						pass



		@unittest.skip('''This test doesn\'t work for ESMFold and doesn\'t test core functionality'''  )
		def 	__lowerCamelCase			(     self     :Optional[Any]  ):
						pass



		@unittest.skip('''ESMFold does not support input chunking.'''  )
		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						pass



		@unittest.skip('''ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'''  )
		def 	__lowerCamelCase			(     self     :Union[str, Any]  ):
						pass



		@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''  )
		def 	__lowerCamelCase			(     self     :Tuple  ):
						pass



		@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''  )
		def 	__lowerCamelCase			(     self     :List[Any]  ):
						pass



		@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''  )
		def 	__lowerCamelCase			(     self     :Optional[Any]  ):
						pass



		@unittest.skip('''ESMFold doesn\'t support data parallel.'''  )
		def 	__lowerCamelCase			(     self     :Any  ):
						pass






		@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''  )
		def 	__lowerCamelCase			(     self     :Any  ):
						pass


@require_torch
class       a							(			A__				):



		@slow
		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						snake_case__	:      Union[str, Any]     		=	EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''  ).float()
						model.eval()
						snake_case__	:      Optional[int]     		=	torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]  )
						snake_case__	:      List[str]     		=	model(__lowercase  )['''positions''']
						snake_case__	:      str     		=	torch.tensor([2.5828, 0.7993, -10.9334]   ,dtype=torch.floataa  )
						self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]   ,__lowercase   ,atol=1e-4  )  )









from math import asin, atan, cos, radians, sin, sqrt, tan

A__	:			Optional[int]			   = 637_8137.0
A__	:			List[str]			   = 635_6752.31_4245
A__	:			Union[str, Any]			   = 6_37_81_37






def   a			(						lowerCamelCase_		,   lowerCamelCase_		,   lowerCamelCase_		,   lowerCamelCase_				):






				'''simple docstring'''
				lowercase__    =			(AXIS_A - AXIS_B) / AXIS_A
				lowercase__    =			atan((1 - flattening) * tan(radians(lowerCamelCase_				)				)				)
				lowercase__    =			atan((1 - flattening) * tan(radians(lowerCamelCase_				)				)				)
				lowercase__    =			radians(lowerCamelCase_				)
				lowercase__    =			radians(lowerCamelCase_				)
				# Equation
				lowercase__    =			sin((phi_a - phi_a) / 2				)
				lowercase__    =			sin((lambda_a - lambda_a) / 2				)
				# Square both values
				sin_sq_phi *= sin_sq_phi
				sin_sq_lambda *= sin_sq_lambda
				lowercase__    =			sqrt(sin_sq_phi + (cos(lowerCamelCase_				) * cos(lowerCamelCase_				) * sin_sq_lambda)				)
				return 2 * RADIUS * asin(lowerCamelCase_				)


if __name__ == "__main__":
							import doctest

							doctest.testmod()




