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(
    visualization_opengl.KeyboardButtonEvent(
        'u', visualization_opengl.KeyboardFireEvent.Hold, increaseTemp))
visualizer.keyboardManager.register_button(
    visualization_opengl.KeyboardButtonEvent(
        'j', visualization_opengl.KeyboardFireEvent.Hold, decreaseTemp))

# Set initial position
spin()

# Start the visualizer and run the integration thread
visualizer.run(1)
    Vz += 3
    for p in system.part:
        p.ext_force = [0, 0, p.q * Vz * Vz_to_Ez]
    print('Potential difference: {:.0f}'.format(Vz))


def decreaseElectricField():
    global Vz
    Vz -= 3
    for p in system.part:
        p.ext_force = [0, 0, p.q * Vz * Vz_to_Ez]
    print('Potential difference: {:.0f}'.format(Vz))


# Register buttons
visualizer.keyboard_manager.register_button(visualization_opengl.KeyboardButtonEvent(
    'u', visualization_opengl.KeyboardFireEvent.Hold, increaseElectricField))
visualizer.keyboard_manager.register_button(visualization_opengl.KeyboardButtonEvent(
    'j', visualization_opengl.KeyboardFireEvent.Hold, decreaseElectricField))


def main():
    print("\n--->Integration")
    system.time = 0.0

    while True:
        system.integrator.run(1)
        visualizer.update()


# Start simulation in separate thread
t = Thread(target=main)
Exemple #3
0
        p.ext_force = [0, 0, p.q * Vz * Vz_to_Ez]
    print('Potential difference: {:.0V}'.format(Vz))


def decreaseElectricField():
    global Ez
    Vz -= 3
    for p in system.part:
        p.ext_force = [0, 0, p.q * Vz * Vz_to_Ez]
    print('Potential difference: {:.0V}'.format(Vz))


# Register buttons
visualizer.keyboardManager.register_button(
    visualization_opengl.KeyboardButtonEvent(
        'u', visualization_opengl.KeyboardFireEvent.Hold,
        increaseElectricField))
visualizer.keyboardManager.register_button(
    visualization_opengl.KeyboardButtonEvent(
        'j', visualization_opengl.KeyboardFireEvent.Hold,
        decreaseElectricField))


def main():
    print("\n--->Integration")
    system.time = 0.0

    while True:
        system.integrator.run(1)
        visualizer.update()

def decreaseTemp():
    global temperature
    temperature -= 10

    if temperature > 0:
        system.thermostat.set_langevin(kT=temperature, gamma=1.0)
    else:
        temperature = 0
        system.thermostat.turn_off()
    print("T = {:.0f} K".format(temperature))


# Register buttons
visualizer.keyboardManager.register_button(visualization_opengl.KeyboardButtonEvent(
    't', visualization_opengl.KeyboardFireEvent.Hold, increaseTemp))
visualizer.keyboardManager.register_button(visualization_opengl.KeyboardButtonEvent(
    'g', visualization_opengl.KeyboardFireEvent.Hold, decreaseTemp))


print("\n--->Setup system")

# System parameters
n_ppside = 10
n_part = int(n_ppside**3)
n_ionpairs = n_part / 2
density = 1.5736
time_step = 0.001823
temp = 298.0
gamma = 20.0
#l_bjerrum = 0.885^2 * e^2/(4*pi*epsilon_0*k_B*T)