Esempio n. 1
0
def keyboard(key, *args):
    if not isinstance(key, str):
        key = key.decode('utf-8')
    if key == 'p':
        gr3.export("test.pov", 0, 0)
    elif key == 'j':
        gr3.export("test.html", 800, 800)
    elif key == 'n':
        gr3.export("test.png", 800, 800)
    elif key == 'm':
        gr3.export("test.jpg", 800, 800)
    elif key == ' ':
        gr3.terminate()
        glutDestroyWindow(window_id)
        sys.exit()
    elif key == '0':
        gr3.setquality(0)
    elif key == '1':
        gr3.setquality(2)
    elif key == '2':
        gr3.setquality(4)
    elif key == '3':
        gr3.setquality(8)
    elif key == '4':
        gr3.setquality(3)
    elif key == '5':
        gr3.setquality(5)
    elif key == '6':
        gr3.setquality(9)
    else:
        print(key, ord(key))
Esempio n. 2
0
def show(molecule,
         width=500,
         height=500,
         show_bonds=True,
         bonds_method='radii',
         bonds_param=None,
         camera=None,
         title='mogli'):
    """
    Interactively show the given molecule with OpenGL. By default, bonds are
    drawn, if this is undesired the show_bonds parameter can be set to False.
    For information on the bond calculation, see Molecule.calculate_bonds.
    If you pass a tuple of camera position, center of view and an up vector to
    the camera parameter, the camera will be set accordingly. Otherwise the
    molecule will be viewed in the direction of the z axis, with the y axis
    pointing upward.
    """
    global _camera
    molecule.positions -= np.mean(molecule.positions, axis=0)
    max_atom_distance = np.max(la.norm(molecule.positions, axis=1))
    if show_bonds:
        molecule.calculate_bonds(bonds_method, bonds_param)

    # If GR3 was initialized earlier, it would use a different context, so
    # it will be terminated first.
    gr3.terminate()

    # Initialize GLFW and create an OpenGL context
    glfw.init()
    glfw.window_hint(glfw.SAMPLES, 16)
    window = glfw.create_window(width, height, title, None, None)
    glfw.make_context_current(window)
    glEnable(GL_MULTISAMPLE)

    # Set up the camera (it will be changed during mouse rotation)
    if camera is None:
        camera_distance = -max_atom_distance * 2.5
        camera = ((0, 0, camera_distance), (0, 0, 0), (0, 1, 0))
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _create_gr3_scene(molecule, show_bonds)
    # Configure GLFW
    glfw.set_cursor_pos_callback(window, _mouse_move_callback)
    glfw.set_mouse_button_callback(window, _mouse_click_callback)
    glfw.swap_interval(1)
    # Start the GLFW main loop
    while not glfw.window_should_close(window):
        glfw.poll_events()
        width, height = glfw.get_window_size(window)
        glViewport(0, 0, width, height)
        _set_gr3_camera()
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        gr3.drawimage(0, width, 0, height, width, height,
                      gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
        glfw.swap_buffers(window)
    glfw.terminate()
    gr3.terminate()
Esempio n. 3
0
def keyboard(key, *args):
    if key == 'p':
        gr3.export("test.pov", 0, 0)
    elif key == 'j':
        gr3.export("test.html", 800, 800)
    elif key == 'n':
        gr3.export("test.png", 800, 800)
    elif key == 'm':
        gr3.export("test.jpg", 800, 800)
    elif key == ' ':
        gr3.terminate()
        sys.exit()
    elif key == '0':
        gr3.setquality(0)
    elif key == '1':
        gr3.setquality(2)
    elif key == '2':
        gr3.setquality(4)
    elif key == '3':
        gr3.setquality(8)
    elif key == '4':
        gr3.setquality(3)
    elif key == '5':
        gr3.setquality(5)
    elif key == '6':
        gr3.setquality(9)
    else:
        print key, ord(key)
Esempio n. 4
0
def keyboard(key, *args):
    if key == 'p':
        gr3.export("test.pov",0,0)
    elif key == 'j':
        gr3.export("test.html",800,800)
    elif key == 'n':
        gr3.export("test.png",800,800)
    elif key == 'm':
        gr3.export("test.jpg",800,800)
    elif key == ' ':
        gr3.terminate()
        sys.exit()
    elif key == '0':
        gr3.setquality(0)
    elif key == '1':
        gr3.setquality(2)
    elif key == '2':
        gr3.setquality(4)
    elif key == '3':
        gr3.setquality(8)
    elif key == '4':
        gr3.setquality(3)
    elif key == '5':
        gr3.setquality(5)
    elif key == '6':
        gr3.setquality(9)
    else:
        print key, ord(key)
Esempio n. 5
0
def show(molecule, width=500, height=500,
         show_bonds=True, bonds_method='radii', bonds_param=None,
         camera=None, title='mogli'):
    """
    Interactively show the given molecule with OpenGL. By default, bonds are
    drawn, if this is undesired the show_bonds parameter can be set to False.
    For information on the bond calculation, see Molecule.calculate_bonds.
    If you pass a tuple of camera position, center of view and an up vector to
    the camera parameter, the camera will be set accordingly. Otherwise the
    molecule will be viewed in the direction of the z axis, with the y axis
    pointing upward.
    """
    global _camera
    molecule.positions -= np.mean(molecule.positions, axis=0)
    max_atom_distance = np.max(la.norm(molecule.positions, axis=1))
    if show_bonds:
        molecule.calculate_bonds(bonds_method, bonds_param)

    # If GR3 was initialized earlier, it would use a different context, so
    # it will be terminated first.
    gr3.terminate()

    # Initialize GLFW and create an OpenGL context
    glfw.init()
    glfw.window_hint(glfw.SAMPLES, 16)
    window = glfw.create_window(width, height, title, None, None)
    glfw.make_context_current(window)
    glEnable(GL_MULTISAMPLE)

    # Set up the camera (it will be changed during mouse rotation)
    if camera is None:
        camera_distance = -max_atom_distance*2.5
        camera = ((0, 0, camera_distance),
                  (0, 0, 0),
                  (0, 1, 0))
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _create_gr3_scene(molecule, show_bonds)
    # Configure GLFW
    glfw.set_cursor_pos_callback(window, _mouse_move_callback)
    glfw.set_mouse_button_callback(window, _mouse_click_callback)
    glfw.swap_interval(1)
    # Start the GLFW main loop
    while not glfw.window_should_close(window):
        glfw.poll_events()
        width, height = glfw.get_window_size(window)
        glViewport(0, 0, width, height)
        _set_gr3_camera()
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        gr3.drawimage(0, width, 0, height,
                      width, height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
        glfw.swap_buffers(window)
    glfw.terminate()
    gr3.terminate()
Esempio n. 6
0
theta = 110.0  # initial angle
gamma = 0.1  # damping coefficient
L = 1  # pendulum length

t = 0
dt = 0.04
state = array([theta * pi / 180, 0])

gr3.init()
gr3.setcameraprojectionparameters(45, 1, 100)
gr3.cameralookat(0, -2, 6, 0, -2, 0, 0, 1, 0)
gr3.setbackgroundcolor(1, 1, 1, 1)
gr3.setlightdirection(1, 1, 10)

now = time.clock()

while t < 30:
    start = now

    t, state = rk4(t, dt, state, damped_pendulum_deriv)
    theta, omega = state
    acceleration = sqrt(2 * g * L * (1 - cos(theta)))
    pendulum(t, theta, omega, acceleration)

    now = time.clock()
    if start + dt > now:
        time.sleep(start + dt - now)

gr3.terminate()
Esempio n. 7
0
def on_main_menu(entry):
    gr3.terminate()
    glutDestroyWindow(window_id)
    sys.exit()
Esempio n. 8
0
def draw(mesh, x=None, y=None, z=None):
    gr3.clear()
    gr3.drawmesh(mesh, 1, (0,0,0), (0,0,1), (0,1,0), (1,1,1), (1,1,1))
    gr3.drawslicemeshes(data,  x=x, y=y, z=z)
    gr.clearws()
    gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.updatews()

data = np.fromfile("mri.raw", np.uint16)
data = data.reshape((64, 64, 93))
data[data > 2000] = 2000
data[:, :, :] = data / 2000.0 * np.iinfo(np.uint16).max

gr.setviewport(0, 1, 0, 1)
gr3.init()
gr3.cameralookat(-3, 2, -2, 0, 0, 0, 0, 0, -1)
mesh = gr3.createisosurfacemesh(data, isolevel=40000)

gr.setcolormap(1)
for z in np.linspace(0, 1, 300):
    draw(mesh, x=0.9, z=z)
for y in np.linspace(1, 0.5, 300):
    draw(mesh, x=0.9, y=y, z=1)
gr.setcolormap(19)
for x in np.linspace(0.9, 0, 300):
    draw(mesh, x=x, y=0.5, z=1)
for x in np.linspace(0, 0.9, 300):
    draw(mesh, x=x, z=1)

gr3.terminate()
Esempio n. 9
0
def on_main_menu(entry):
    gr3.terminate()
    sys.exit()
    return 0
Esempio n. 10
0
def on_main_menu(entry):
    gr3.terminate()
    sys.exit()
    return 0