-
Notifications
You must be signed in to change notification settings - Fork 2
/
simulation.py
77 lines (72 loc) · 2.81 KB
/
simulation.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/env/python
#pomocnicze
import sys
#klasy
from atom import *
from vector import *
#algorytmy
from verlet import Verlet
from velocityVerlet import VelocityVerlet
from leapFrog import LeapFrog
#potencjały
from softWall import SoftWall
from minBarrierMin import MinBarrierMin
from lenardJones import LenardJones
#statystyki
from trajectoryAndStatistics import *
class Simulation:
def __init__(self, dim=3,n_a=3,st=0.01,sts=100,algorithm='LeapFrog',force_fields=['SoftWall','MinBarrierMin'],parameters=[[1,10],[5,10,3,0.02]]):
self.n_atoms=int(n_a)
self.atoms=[Atom(dim,st) for i in range(self.n_atoms)]
self.time_step=float(st)
self.steps=int(sts)
if algorithm=='Verlet':
self.algorithm=Verlet()
elif algorithm=='VelocityVerlet':
self.algorithm=VelocityVerlet()
elif algorithm=='LeapFrog':
self.algorithm=LeapFrog()
else:
sys.exit('Wrong algorithm name')
self.force_fields=[]
for f in range(len(force_fields)):
if force_fields[f]=='SoftWall':
self.force_fields.append(SoftWall(parameters[f]))
for a in self.atoms:
a.Recalculate(st,True)
elif force_fields[f]=='MinBarrierMin':
self.force_fields.append(MinBarrierMin(parameters[f]))
for a in self.atoms:
a.Recalculate(st,True)
elif force_fields[f]=='LenardJones':
self.force_fields.append(LenardJones(parameters[f]))
for a in self.atoms:
for i in range(a.coords_t.dim):
if a.coords_t[i]>=0:
a.coords_t[i]+=a.number
else:
a.coords_t[i]-=a.number
else:
sys.exit('Wrong potential name')
def Run(self):
for time_step in range(self.steps):
if time_step==0:
atom1=self.atoms[0]
for atom in self.atoms:
for ff in self.force_fields:
ff.Accelerate([atom])
for atom2 in self.atoms[self.atoms.index(atom):]:
if atom!=atom2:
for ff in self.force_fields:
ff.Accelerate([atom,atom2])
self.algorithm.Move(self.time_step,atom)
for i in range(atom.coords_t.dim):
if atom.coords_t[i]>500:
sys.exit(str(atom))
trajectory((time_step),self.atoms)
stats((time_step),self.atoms)
plot_stats()
def __str__(self):
return(str(self.atoms))
def __repr__(self):
return(str(self.atoms))