Last active
November 14, 2021 10:19
-
-
Save hostile-duck/d8ec208c6850a295e45191eb7f43ddf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| from typing import List, Tuple | |
| from scipy.spatial import distance | |
| def formula(atoms: list): | |
| SUB = str.maketrans("0123456789", "₀₁₂₃₄₅₆₇₈₉") | |
| set_atoms = list(set(atoms)) | |
| max_i = set_atoms[1] if atoms.count(set_atoms[1]) > 1 else set_atoms[0] | |
| min_i = set_atoms[1] if atoms.count(set_atoms[1]) == 1 else set_atoms[0] | |
| return f"{min_i}{max_i}{str(atoms.count(max_i)).translate(SUB)}" | |
| class Particle: | |
| def __init__( | |
| self, valency: int = 0, name: str = "", position: tuple = (0, 0) | |
| ) -> None: | |
| self.valency = valency | |
| self.name = name | |
| self.position = position | |
| def combine(self, particle) -> Tuple[List[str], int, bool]: | |
| molecule = [] | |
| energy_in = False | |
| energy = random.randint(10, 20) | |
| if particle.valency < self.valency: | |
| amount = int(self.valency / particle.valency) | |
| molecule = [particle for i in range(amount)] + [self] | |
| elif self.valency < particle.valency: | |
| amount = int(particle.valency / self.valency) | |
| molecule = [particle] + [self for i in range(amount)] | |
| elif self.valency == particle.valency: | |
| molecule = [self, particle] | |
| if (self.valency + particle.valency) >= 6: | |
| energy_in = True | |
| energy = 11 | |
| return (molecule, energy, energy_in) | |
| def __repr__(self) -> str: | |
| return self.name | |
| x = Particle(valency=1, name="x") | |
| y = Particle(valency=2, name="y") | |
| z = Particle(valency=4, name="z") | |
| print((x.combine(y))) | |
| print((x.combine(z))) | |
| print((y.combine(z))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment