|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: UTF-8 -*- |
| 3 | + |
| 4 | +class Particle: |
| 5 | + def __init__(self, name="", position=(0.0, 0.0, 0.0), velocity=(0.0, 0.0, 0.0), spin=0.0): |
| 6 | + self.position = position |
| 7 | + self.velocity = velocity |
| 8 | + self.name = name |
| 9 | + self.spin = spin |
| 10 | + def __str__(self): |
| 11 | + pos = "({0:.2f}:{1:.2f}:{2:.2f})".format(self.position[0], self.position[1], self.position[2]) |
| 12 | + vel = "({0:.2f}:{1:.2f}:{2:.2f})".format(self.velocity[0], self.velocity[1], self.velocity[2]) |
| 13 | + the_str = "{0}\n at {1}\n with velocity {2}\n and spin {3}\n".format(self.name, pos, vel, self.spin) |
| 14 | + return the_str |
| 15 | + |
| 16 | +class MassParticle(Particle): |
| 17 | + def __init__(self, name="", position=(0.0, 0.0, 0.0), velocity=(0.0, 0.0, 0.0), spin=0.0, mass=0.0): |
| 18 | + super(MassParticle, self).__init__(name, position, velocity, spin) |
| 19 | + self.mass = mass |
| 20 | + def __str__(self): |
| 21 | + temp_str = super(MassParticle, self).__str__() |
| 22 | + temp_str = temp_str + " and mass {0}\n".format(self.mass) |
| 23 | + return temp_str |
| 24 | + |
| 25 | +class ChargeParticle(MassParticle): |
| 26 | + def __init__(self, name="", position=(0.0, 0.0, 0.0), velocity=(0.0, 0.0, 0.0), spin=0.0, mass=0.0, charge=0.0): |
| 27 | + super(ChargeParticle, self).__init__(name, position, velocity, spin, mass) |
| 28 | + self.charge = charge |
| 29 | + def __str__(self): |
| 30 | + temp_str = super(MassParticle, self).__str__() |
| 31 | + temp_str = temp_str + " and charge {0}".format(self.charge) |
| 32 | + return temp_str |
| 33 | + |
| 34 | +if __name__ == "__main__": |
| 35 | + photon = Particle(name="photon", spin=1.0) |
| 36 | + tau = ChargeParticle(name="tau", spin=0.5, charge=-1.0, mass=1.777) |
| 37 | + print(photon) |
| 38 | + print(tau) |
0 commit comments