"""simple docstring"""
from random import randint, random





def    lowerCAmelCase__    (			_UpperCamelCase       :				int ,			_UpperCamelCase       :				int ,			_UpperCamelCase       :				int ,			_UpperCamelCase       :				bool = False ,			_UpperCamelCase       :				bool = False ,			_UpperCamelCase       :				int = 5 ,			)					->				list:





						"""simple docstring"""






						snake_case								=			[[-1] * number_of_cells]  # Create a highway without any car
						snake_case								=			0
						snake_case								=			max(_UpperCamelCase ,			0					)
						while i < number_of_cells:
												snake_case								=			(
												    randint(0 ,			_UpperCamelCase					) if random_speed else initial_speed
												)  # Place the cars
												i += (
												    randint(1 ,			max_speed * 2					) if random_frequency else frequency
												)  # Arbitrary number, may need tuning
						return highway





def    lowerCAmelCase__    (			_UpperCamelCase       :				list ,			_UpperCamelCase       :				int					)					->				int:





						"""simple docstring"""






						snake_case								=			0
						snake_case								=			highway_now[car_index + 1 :]
						for cell in range(len(_UpperCamelCase					)					):  # May need a better name for this
												if cells[cell] != -1:  # If the cell is not empty then
																		return distance  # we have the distance we wanted
												distance += 1
						# Here if the car is near the end of the highway
						return distance + get_distance(_UpperCamelCase ,			-1					)





def    lowerCAmelCase__    (			_UpperCamelCase       :				list ,			_UpperCamelCase       :				float ,			_UpperCamelCase       :				int					)					->				list:





						"""simple docstring"""






						snake_case								=			len(_UpperCamelCase					)
						# Beforce calculations, the highway is empty
						snake_case								=			[-1] * number_of_cells

						for car_index in range(_UpperCamelCase					):
												if highway_now[car_index] != -1:
																		# Add 1 to the current speed of the car and cap the speed
																		snake_case								=			min(highway_now[car_index] + 1 ,			_UpperCamelCase					)
																		# Number of empty cell before the next car
																		snake_case								=			get_distance(_UpperCamelCase ,			_UpperCamelCase					) - 1
																		# We can't have the car causing an accident
																		snake_case								=			min(next_highway[car_index] ,			_UpperCamelCase					)
																		if random() < probability:
																								# Randomly, a driver will slow down
																								snake_case								=			max(next_highway[car_index] - 1 ,			0					)
						return next_highway





def    lowerCAmelCase__    (			_UpperCamelCase       :				list ,			_UpperCamelCase       :				int ,			_UpperCamelCase       :				float ,			_UpperCamelCase       :				int					)					->				list:





						"""simple docstring"""






						snake_case								=			len(highway[0]					)

						for i in range(_UpperCamelCase					):
												snake_case								=			update(highway[i] ,			_UpperCamelCase ,			_UpperCamelCase					)
												snake_case								=			[-1] * number_of_cells

												for car_index in range(_UpperCamelCase					):
																		snake_case								=			next_speeds_calculated[car_index]
																		if speed != -1:
																								# Change the position based on the speed (with % to create the loop)
																								snake_case								=			(car_index + speed) % number_of_cells
																								# Commit the change of position
																								snake_case								=			speed
												highway.append(_UpperCamelCase					)

						return highway


if __name__ == "__main__":
					import doctest

					doctest.testmod()



"""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    lowerCAmelCase__    (			_UpperCamelCase       :				Dict[str, torch.Tensor]					)					->				Dict[str, torch.Tensor]:





						"""simple docstring"""






						snake_case								=			[]
						snake_case								=			[]
						snake_case								=			[]

						for rt in rc.restypes:
												snake_case								=			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]					)
												snake_case								=			{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] * 1_4					)
						restype_atomaa_to_atomaa_list.append([0] * 3_7					)
						restype_atomaa_mask_list.append([0.0] * 1_4					)

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

						snake_case								=			residx_atomaa_mask
						snake_case								=			residx_atomaa_to_atomaa.long()

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

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

						snake_case								=			restype_atomaa_mask[protein_aatype]
						snake_case								=			residx_atomaa_mask

						return protein





def    lowerCAmelCase__    (			_UpperCamelCase       :				Dict[str, torch.Tensor]					)					->				Dict[str, np.ndarray]:





						"""simple docstring"""






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


