




'''simple docstring'''


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





							'''simple docstring'''


							_a      	=							[]
							_a      	=							[]
							_a      	=							[]

							for rt in rc.restypes:
														_a      	=							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] )
														_a      	=							{name: i for i, name in enumerate(UpperCamelCase )}
														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 )

							_a      	=							torch.tensor(
							    UpperCamelCase					,		dtype=torch.intaa					,		device=protein['''aatype'''].device					,		)
							_a      	=							torch.tensor(
							    UpperCamelCase					,		dtype=torch.intaa					,		device=protein['''aatype'''].device					,		)
							_a      	=							torch.tensor(
							    UpperCamelCase					,		dtype=torch.floataa					,		device=protein['''aatype'''].device					,		)
							_a      	=							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
							_a      	=							restype_atomaa_to_atomaa[protein_aatype]
							_a      	=							restype_atomaa_mask[protein_aatype]

							_a      	=							residx_atomaa_mask
							_a      	=							residx_atomaa_to_atomaa.long()

							# create the gather indices for mapping back
							_a      	=							restype_atomaa_to_atomaa[protein_aatype]
							_a      	=							residx_atomaa_to_atomaa.long()

							# create the corresponding mask
							_a      	=							torch.zeros([21, 37]					,		dtype=torch.floataa					,		device=protein['''aatype'''].device )
							for restype, restype_letter in enumerate(rc.restypes ):
														_a      	=							rc.restype_atoa[restype_letter]
														_a      	=							rc.residue_atoms[restype_name]
														for atom_name in atom_names:
																					_a      	=							rc.atom_order[atom_name]
																					_a      	=							1

							_a      	=							restype_atomaa_mask[protein_aatype]
							_a      	=							residx_atomaa_mask

							return protein

def 						snake_case_       (UpperCamelCase			:    Dict[str, torch.Tensor] ):





							'''simple docstring'''


							_a      	=							tree_map(lambda UpperCamelCase : torch.tensor(UpperCamelCase					,		device=batch['''aatype'''].device )					,		UpperCamelCase					,		np.ndarray )
							_a      	=							tensor_tree_map(lambda UpperCamelCase : np.array(UpperCamelCase )					,		make_atomaa_masks(UpperCamelCase ) )
							return out







'''simple docstring'''


from __future__ import annotations

from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass

@dataclass
class      A       :
							lowercase_							     =							42
							lowercase_							     =							42



class      A       :







							def __init__(    self			:    Optional[Any]				,     lowerCAmelCase_			:    int   )     ->				str:


														"""simple docstring"""


														_a      	=							[[] for _ in range(lowerCAmelCase_   )]
														_a      	=							size







							def __getitem__(    self			:    Any				,     lowerCAmelCase_			:    int   )     ->				Iterator[Edge]:


														"""simple docstring"""


														return iter(self._graph[vertex]   )







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


														"""simple docstring"""


														return self._size







							def   __lowerCAmelCase     (    self			:    Union[str, Any]				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    int   )     ->				Dict:


														"""simple docstring"""


														if weight not in (0, 1):
																					raise ValueError('''Edge weight must be either 0 or 1.'''   )

														if to_vertex < 0 or to_vertex >= self.size:
																					raise ValueError('''Vertex indexes must be in [0; size).'''   )

														self._graph[from_vertex].append(Edge(lowerCAmelCase_				,     lowerCAmelCase_   )   )







							def   __lowerCAmelCase     (    self			:    Tuple				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    int   )     ->				int | None:


														"""simple docstring"""


														_a      	=							deque([start_vertex]   )
														_a      	=							[None] * self.size
														_a      	=							0

														while queue:
																					_a      	=							queue.popleft()
																					_a      	=							distances[current_vertex]
																					if current_distance is None:
																												continue

																					for edge in self[current_vertex]:
																												_a      	=							current_distance + edge.weight
																												_a      	=							distances[edge.destination_vertex]
																												if (
																												    isinstance(lowerCAmelCase_				,     lowerCAmelCase_   )
																												    and new_distance >= dest_vertex_distance
																												):
																																			continue
																												_a      	=							new_distance
																												if edge.weight == 0:
																																			queue.appendleft(edge.destination_vertex   )
																												else:
																																			queue.append(edge.destination_vertex   )

														if distances[finish_vertex] is None:
																					raise ValueError('''No path from start_vertex to finish_vertex.'''   )

														return distances[finish_vertex]


if __name__ == "__main__":
				import doctest

				doctest.testmod()

