/
ion.py
52 lines (43 loc) · 1.54 KB
/
ion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
A module to represent an Ion Class
"""
import math
import numpy as np
from numpy import dot
from numpy.linalg import norm
from element import Element
class Ion(Element):
"""
Representation of an ion
input:
position [x, y, z]
velocity [u, v, w]
energy e (electron volts eV)
element Element(args)
"""
id_counter = 0
def __init__(self, position, velocity, element):
Element.__init__(self, element.symbol, element.atomicNumber, element.mass)
self.position = position
self.velocity = velocity
self.element = element
self.id = Ion.id_counter
Ion.id_counter += 1
def moveIonByDistance(self, distance):
"""
Given the current velocity direction
displace the atom a given distance
"""
unitDirection = self.velocity / norm(self.velocity, 2)
self.position = self.position + distance * unitDirection
def energy(self):
return 0.5 * self.mass * (self.velocity[0] * self.velocity[0] + \
self.velocity[1] * self.velocity[1] + \
self.velocity[2] * self.velocity[2] )
def __str__(self):
return "Position:" + str(self.position) + \
"Velocity:" + str(self.velocity) + \
"Energy: " + str(self.energy) + \
"Element:\nSymbol: " + self.symbol + \
"Atomic Number: " + str(self.atomicNumber) + \
"Mass: " + str(self.mass)