forked from madarivi/MolecularDynamics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpy_animate.py
49 lines (39 loc) · 1.79 KB
/
vpy_animate.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
__author__ = 'Kian'
from visual import *
import variables as var
import numpy as np
class VpyAnimate(object):
def __init__(self, particles, loops):
self.particles = particles
self.posMatrix = np.empty((var.numParticles, var.dimension, loops))
self.speed = 20
self.sphereRadius = var.boxSize/30.
self.init_box()
self.init_balls()
def init_balls(self):
self.balls = []
for i in range(var.numParticles):
self.balls = self.balls + [sphere(radius=self.sphereRadius, color=color.red)]
self.balls[i].pos = vector(self.particles.initposs[i,0],self.particles.initposs[i,1],self.particles.initposs[i,2])
#balls[i].velocity = vector(self.particles.initvelocc[i,0],self.particles.initvelocc[i,1],self.particles.initvelocc[i,2])
def init_box(self):
bSize = var.boxSize+self.sphereRadius
wallR = box (pos=(var.boxSize/2.,var.boxSize/2.,var.boxSize/2.), size=(bSize,bSize,bSize), color = color.blue, opacity = 0.3)
def plot_anim(self, positions):
rate(100)
self.x = positions[:,0]
self.y = positions[:,1]
self.z = positions[:,2]
for j in range(var.numParticles):
self.balls[j].pos = vector(self.x[j],self.y[j],self.z[j])
# def buildCoords(self, loopcount, positions):
# self.posMatrix[:, :, loopcount] = positions
# def plot_anim(self):
# self.x = self.posMatrix[:, 0, :] # Npoint , dimension, frame
# self.y = self.posMatrix[:, 1, :]
# self.z = self.posMatrix[:, 2, :]
# while 1:
# for i in range(np.shape(self.x)[1]):
# rate(self.speed)
# for j in range(var.numParticles):
# self.balls[j].pos = vector(self.x[j,i],self.y[j,i],self.z[j,i])