__lowercase											=      {
    '''a''': '''AAAAA''',
    '''b''': '''AAAAB''',
    '''c''': '''AAABA''',
    '''d''': '''AAABB''',
    '''e''': '''AABAA''',
    '''f''': '''AABAB''',
    '''g''': '''AABBA''',
    '''h''': '''AABBB''',
    '''i''': '''ABAAA''',
    '''j''': '''BBBAA''',
    '''k''': '''ABAAB''',
    '''l''': '''ABABA''',
    '''m''': '''ABABB''',
    '''n''': '''ABBAA''',
    '''o''': '''ABBAB''',
    '''p''': '''ABBBA''',
    '''q''': '''ABBBB''',
    '''r''': '''BAAAA''',
    '''s''': '''BAAAB''',
    '''t''': '''BAABA''',
    '''u''': '''BAABB''',
    '''v''': '''BBBAB''',
    '''w''': '''BABAA''',
    '''x''': '''BABAB''',
    '''y''': '''BABBA''',
    '''z''': '''BABBB''',
    ''' ''': ''' ''',
}


__lowercase											=      {value: key for key, value in encode_dict.items()}



def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :List[Any]    						=	''''''
    for letter in word.lower():
        if letter.isalpha() or letter == " ":
            encoded += encode_dict[letter]
        else:
            raise Exception('''encode() accepts only letters of the alphabet and spaces'''			)
    return encoded



def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    if set(SCREAMING_SNAKE_CASE			) - {"A", "B", " "} != set():
        raise Exception('''decode() accepts only \'A\', \'B\' and spaces'''			)
    __UpperCamelCase  :Dict    						=	''''''
    for word in coded.split():
        while len(SCREAMING_SNAKE_CASE			) != 0:
            decoded += decode_dict[word[:5]]
            __UpperCamelCase  :Any    						=	word[5:]
        decoded += " "
    return decoded.strip()


if __name__ == "__main__":
    from doctest import testmod

    testmod()






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 			lowerCamelCase_  :






    '''simple docstring'''






    def __init__(			self				,				__lowercase				,				__lowercase=13				,				__lowercase=7				,				__lowercase=False				,				__lowercase=True				,				__lowercase=False				,				__lowercase=False				,				__lowercase=19				,				__lowercase=32				,				__lowercase=5				,				__lowercase=4				,				__lowercase=37				,				__lowercase="gelu"				,				__lowercase=0.1				,				__lowercase=0.1				,				__lowercase=512				,				__lowercase=16				,				__lowercase=2				,				__lowercase=0.02				,				__lowercase=3				,				__lowercase=4				,				__lowercase=None				,				) ->			Optional[Any]:
        __UpperCamelCase  :Dict    						=	parent
        __UpperCamelCase  :Optional[Any]    						=	batch_size
        __UpperCamelCase  :Any    						=	seq_length
        __UpperCamelCase  :List[str]    						=	is_training
        __UpperCamelCase  :Any    						=	use_input_mask
        __UpperCamelCase  :Optional[int]    						=	use_token_type_ids
        __UpperCamelCase  :List[str]    						=	use_labels
        __UpperCamelCase  :Tuple    						=	vocab_size
        __UpperCamelCase  :List[Any]    						=	hidden_size
        __UpperCamelCase  :Optional[Any]    						=	num_hidden_layers
        __UpperCamelCase  :List[Any]    						=	num_attention_heads
        __UpperCamelCase  :Dict    						=	intermediate_size
        __UpperCamelCase  :List[str]    						=	hidden_act
        __UpperCamelCase  :Any    						=	hidden_dropout_prob
        __UpperCamelCase  :Union[str, Any]    						=	attention_probs_dropout_prob
        __UpperCamelCase  :Optional[Any]    						=	max_position_embeddings
        __UpperCamelCase  :List[Any]    						=	type_vocab_size
        __UpperCamelCase  :int    						=	type_sequence_label_size
        __UpperCamelCase  :str    						=	initializer_range
        __UpperCamelCase  :Optional[Any]    						=	num_labels
        __UpperCamelCase  :int    						=	num_choices
        __UpperCamelCase  :Optional[Any]    						=	scope







    def     UpperCamelCase__     (			self) ->			List[Any]:
        __UpperCamelCase  :int    						=	ids_tensor([self.batch_size, self.seq_length]				,				self.vocab_size)

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

        __UpperCamelCase  :Dict    						=	None
        __UpperCamelCase  :List[Any]    						=	None
        __UpperCamelCase  :Tuple    						=	None
        if self.use_labels:
            __UpperCamelCase  :Union[str, Any]    						=	ids_tensor([self.batch_size]				,				self.type_sequence_label_size)
            __UpperCamelCase  :Union[str, Any]    						=	ids_tensor([self.batch_size, self.seq_length]				,				self.num_labels)
            __UpperCamelCase  :str    						=	ids_tensor([self.batch_size]				,				self.num_choices)

        __UpperCamelCase  :Optional[Any]    						=	self.get_config()

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







    def     UpperCamelCase__     (			self) ->			Optional[int]:
        __UpperCamelCase  :int    						=	EsmConfig(
            vocab_size=33				,				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     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase) ->			Union[str, Any]:
        __UpperCamelCase  :int    						=	EsmForProteinFolding(config=__lowercase).float()
        model.to(__lowercase)
        model.eval()
        __UpperCamelCase  :Tuple    						=	model(__lowercase				,				attention_mask=__lowercase)
        __UpperCamelCase  :Any    						=	model(__lowercase)
        __UpperCamelCase  :Optional[Any]    						=	model(__lowercase)

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







    def     UpperCamelCase__     (			self) ->			Optional[Any]:
        __UpperCamelCase  :Dict    						=	self.prepare_config_and_inputs()
        (
            (
            __UpperCamelCase
        )						, (
            __UpperCamelCase
        )						, (
            __UpperCamelCase
        )						, (
            __UpperCamelCase
        )						, (
            __UpperCamelCase
        )						, (
            __UpperCamelCase
        )						, 
        )  :List[str]    						=	config_and_inputs
        __UpperCamelCase  :Tuple    						=	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
        return config, inputs_dict


@require_torch
class 			lowerCamelCase_  (     UpperCAmelCase_		,			UpperCAmelCase_		,			unittest.TestCase				):






    '''simple docstring'''






    a__			:		Optional[int]      			=   False

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







    def     UpperCamelCase__     (			self) ->			Tuple:
        __UpperCamelCase  :Dict    						=	EsmFoldModelTester(self)
        __UpperCamelCase  :Dict    						=	ConfigTester(self				,				config_class=__lowercase				,				hidden_size=37)







    def     UpperCamelCase__     (			self) ->			List[Any]:
        self.config_tester.run_common_tests()







    def     UpperCamelCase__     (			self) ->			List[str]:
        __UpperCamelCase  :Any    						=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__lowercase)







    @unittest.skip('''Does not support attention outputs''')
    def     UpperCamelCase__     (			self) ->			Any:
        pass







    @unittest.skip
    def     UpperCamelCase__     (			self) ->			Any:
        pass







    @unittest.skip('''Esm does not support embedding resizing''')
    def     UpperCamelCase__     (			self) ->			Union[str, Any]:
        pass







    @unittest.skip('''Esm does not support embedding resizing''')
    def     UpperCamelCase__     (			self) ->			Optional[Any]:
        pass







    @unittest.skip('''ESMFold does not support passing input embeds!''')
    def     UpperCamelCase__     (			self) ->			List[Any]:
        pass







    @unittest.skip('''ESMFold does not support head pruning.''')
    def     UpperCamelCase__     (			self) ->			Optional[int]:
        pass







    @unittest.skip('''ESMFold does not support head pruning.''')
    def     UpperCamelCase__     (			self) ->			Optional[Any]:
        pass







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







    @unittest.skip('''ESMFold does not support head pruning.''')
    def     UpperCamelCase__     (			self) ->			Optional[Any]:
        pass







    @unittest.skip('''ESMFold does not support head pruning.''')
    def     UpperCamelCase__     (			self) ->			Optional[int]:
        pass







    @unittest.skip('''ESMFold does not output hidden states in the normal way.''')
    def     UpperCamelCase__     (			self) ->			str:
        pass







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







    @unittest.skip('''ESMFold only has one output format.''')
    def     UpperCamelCase__     (			self) ->			Union[str, Any]:
        pass







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







    @unittest.skip('''ESMFold does not support input chunking.''')
    def     UpperCamelCase__     (			self) ->			List[Any]:
        pass







    @unittest.skip('''ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.''')
    def     UpperCamelCase__     (			self) ->			int:
        pass







    @unittest.skip('''ESMFold doesn\'t support torchscript compilation.''')
    def     UpperCamelCase__     (			self) ->			str:
        pass







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







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







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







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


@require_torch
class 			lowerCamelCase_  (     UpperCAmelCase_				):






    '''simple docstring'''






    @slow
    def     UpperCamelCase__     (			self) ->			Tuple:
        __UpperCamelCase  :Optional[Any]    						=	EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1''').float()
        model.eval()
        __UpperCamelCase  :Tuple    						=	torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]])
        __UpperCamelCase  :List[Any]    						=	model(__lowercase)['''positions''']
        __UpperCamelCase  :Optional[int]    						=	torch.tensor([2.58_28, 0.79_93, -10.93_34]				,				dtype=torch.floataa)
        self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]				,				__lowercase				,				atol=1E-4))





