File size: 1,920 Bytes
1512437 | 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 | from __future__ import print_function
import espressomd
from espressomd import thermostat
from espressomd import integrate
import numpy as np
from threading import Thread
from math import *
from espressomd.visualization_opengl import *
# Minimal interactive OpenGL visualization for ESPResSo
print("Press u/j to change temperature")
box_l = 10.0
system = espressomd.System(box_l=[box_l] * 3)
visualizer = openGLLive(system, drag_enabled=True, drag_force=100)
system.time_step = 0.00001
system.cell_system.skin = 3.0
N = 50
for i in range(N):
system.part.add(pos=[0, 0, 0])
system.thermostat.set_langevin(kT=1.0, gamma=1.0)
# Callback for particle positions/velocities
def spin():
system.part[:].pos = [[box_l * 0.5, box_l *
(i + 1) / (N + 2), box_l * 0.5] for i in range(N)]
system.part[:].v = [
[np.sin(10.0 * i / N) * 20, 0, np.cos(10.0 * i / N) * 20] for i in range(N)]
# Register timed callback
visualizer.register_callback(spin, interval=5000)
# Callbacks to control temperature
temperature = 1.0
def increaseTemp():
global temperature
temperature += 0.1
system.thermostat.set_langevin(kT=temperature, gamma=1.0)
print("T =", system.thermostat.get_state()[0]['kT'])
def decreaseTemp():
global temperature
temperature -= 0.1
if temperature > 0:
system.thermostat.set_langevin(kT=temperature, gamma=1.0)
print("T =", system.thermostat.get_state()[0]['kT'])
else:
temperature = 0
system.thermostat.turn_off()
print("T = 0")
# Register button callbacks
visualizer.keyboardManager.register_button(
KeyboardButtonEvent('u', KeyboardFireEvent.Hold, increaseTemp))
visualizer.keyboardManager.register_button(
KeyboardButtonEvent('j', KeyboardFireEvent.Hold, decreaseTemp))
# Set initial position
spin()
# Start the visualizer and run the integration thread
visualizer.run(1)
|