Пример #1
0
def on_export_menu(entry):
    if entry == 1:
        filename = "scene.pov"
    elif entry == 2:
        filename = "scene.html"
    elif entry == 3:
        filename = "scene.jpg"
    elif entry == 4:
        filename = "scene.png"
    else:
        return 1
    gr3.setquality(export_quality)
    gr3.export(filename,800,800)
    gr3.setquality(0)
    return 0
Пример #2
0
def on_export_menu(entry):
    if entry == 1:
        filename = "scene.pov"
    elif entry == 2:
        filename = "scene.html"
    elif entry == 3:
        filename = "scene.jpg"
    elif entry == 4:
        filename = "scene.png"
    else:
        return 1
    gr3.setquality(export_quality)
    gr3.export(filename, 800, 800)
    gr3.setquality(0)
    return 0
Пример #3
0
def export(molecule,
           file_name,
           width=500,
           height=500,
           show_bonds=True,
           bonds_method='radii',
           bonds_param=None,
           camera=None):
    """
    Draw the given molecule into a given file. The file type is determined by
    the file extension, e.g. '.png' or '.html'. 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 camera is None:
        if _camera is None:
            camera_distance = -max_atom_distance * 2.5
            camera = ((0, 0, camera_distance), (0, 0, 0), (0, 1, 0))
        else:
            camera = _camera
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _set_gr3_camera()
    _create_gr3_scene(molecule, show_bonds)
    glEnable(GL_DEPTH_TEST)
    gr3.setquality(gr3.GR3_Quality.GR3_QUALITY_OPENGL_16X_SSAA)
    gr3.export(file_name, width, height)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
    glDisable(GL_DEPTH_TEST)
Пример #4
0
def draw(molecule,
         xmin=0,
         xmax=1,
         ymin=0,
         ymax=1,
         width=2000,
         height=2000,
         show_bonds=True,
         bonds_method='radii',
         bonds_param=None,
         camera=None):
    """
    Draw the given molecule with the GR framework. 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 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)
    _set_gr3_camera()
    _create_gr3_scene(molecule, show_bonds)
    glEnable(GL_DEPTH_TEST)
    gr3.setquality(gr3.GR3_Quality.GR3_QUALITY_OPENGL_16X_SSAA)
    gr3.drawimage(xmin, xmax, ymin, ymax, width, height,
                  gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
    glDisable(GL_DEPTH_TEST)
Пример #5
0
def draw(molecule,
         xmin=0, xmax=1, ymin=0, ymax=1, width=500, height=500,
         show_bonds=True, bonds_method='radii', bonds_param=None,
         camera=None):
    """
    Draw the given molecule with the GR framework. 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 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)
    _set_gr3_camera()
    _create_gr3_scene(molecule, show_bonds)
    glEnable(GL_DEPTH_TEST)
    gr3.setquality(gr3.GR3_Quality.GR3_QUALITY_OPENGL_2X_SSAA)
    gr3.drawimage(xmin, xmax, ymin, ymax,
                  width, height, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
    glDisable(GL_DEPTH_TEST)
Пример #6
0
def display():
    global window_width, window_height, rx
    gr3.setbackgroundcolor(1, 1, 1, 1)
    # set up camera
    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10 * math.cos(-rx * math.pi / 2),
                     10 * math.sin(-rx * math.pi / 2), 0, 0, 0, 0, 0, 0, 1)

    gr3.drawimage(0, window_width, 0, window_height, window_width,
                  window_height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
    glViewport(0, 0, window_width, window_height)
    glDisable(GL_LIGHTING)
    glDisable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()
    glMatrixMode(GL_PROJECTION)
    glPushMatrix()
    glLoadIdentity()
    glColor4f(1, 0, 0, 1)
    x, y = 0, 0.22
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"This is a GLUT window in which GR3 renders":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.05
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"a scene. You can drag the mouse to rotate the":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.05
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"molecule or right-click to open a context menu.":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    glMatrixMode(GL_MODELVIEW)
    glPopMatrix()
    glMatrixMode(GL_PROJECTION)
    glPopMatrix()
    glutSwapBuffers()
    gr.clearws()
    selntran(0)
    gr3.setquality(4)
    gr3.drawimage(0, 0.5, 0.5, 1, 250, 250, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.settextcolorind(1)
    gr.settextfontprec(6, 0)

    x = list(range(5))
    y = list(range(5))

    nominalWindowHeight = 500.0
    pointSize = (8, 9, 10, 11, 12, 14, 18, 24, 36)
    s = "i\\hbar\\frac{\\partial\\psi}{\\partial t} = \\frac{\\hbar^2}{2m}\\nabla^2\\psi + V(\\mathbf{r})\\psi"
    x = 0.9
    y = 0.9
    gr.settextalign(3, 3)
    for i in range(8):
        gr.setcharheight(pointSize[i] / nominalWindowHeight)
        gr.mathtex(x, y, s)
        y -= 4 * pointSize[i] / nominalWindowHeight

    gr.setcharheight(0.1)
    gr.mathtex(0.9, 0.05, "Hello World!")
    gr.settextcolorind(8)
    gr.text(0.9, 0.05, "Hello World!")

    gr.updatews()

    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10 * math.cos(-rx * math.pi / 2),
                     10 * math.sin(-rx * math.pi / 2), 0, 0, 0, 0, 0, 0, 1)
Пример #7
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))
Пример #8
0
def display():
    global window_width, window_height, rx
    gr3.setbackgroundcolor(1, 1, 1, 1)
    # Kamera einstellen
    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10 * math.cos(-rx * math.pi / 2),
                     10 * math.sin(-rx * math.pi / 2), 0, 0, 0, 0, 0, 0, 1)

    gr3.drawimage(0, window_width, 0, window_height, window_width,
                  window_height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
    glViewport(0, 0, window_width, window_height)
    glDisable(GL_LIGHTING)
    glDisable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()
    glMatrixMode(GL_PROJECTION)
    glPushMatrix()
    glLoadIdentity()
    glColor4f(1, 0, 0, 1)
    x, y = 0, 0.22
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"Dies ist ein GLUT-Fenster, in dem mit GR3 eine":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.05
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"Szene gerendert wird. Mit der Maus kann man":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.05
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"das dargestellte Molekül rotieren lassen.":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.04
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"(Rechtsklick öffnet das Kontextmenü)":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, ord(c))
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    glMatrixMode(GL_MODELVIEW)
    glPopMatrix()
    glMatrixMode(GL_PROJECTION)
    glPopMatrix()
    glutSwapBuffers()
    gr.clearws()
    selntran(0)
    gr3.setquality(4)
    gr3.drawimage(0, 0.5, 0.5, 1, 250, 250, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.settextcolorind(1)
    gr.settextfontprec(6, 0)

    x = list(range(5))
    y = list(range(5))

    nominalWindowHeight = 500.0
    pointSize = (8, 9, 10, 11, 12, 14, 18, 24, 36)
    s = "i\\hbar\\frac{\\partial\\psi}{\\partial t} = \\frac{\\hbar^2}{2m}\\nabla^2\\psi + V(\\mathbf{r})\\psi"
    x = 0.9
    y = 0.9
    gr.settextalign(3, 3)
    for i in range(8):
        gr.setcharheight(pointSize[i] / nominalWindowHeight)
        gr.mathtex(x, y, s)
        y -= 4 * pointSize[i] / nominalWindowHeight

    gr.setcharheight(0.1)
    gr.mathtex(0.9, 0.05, "Hello World!")
    gr.settextcolorind(8)
    gr.text(0.9, 0.05, "Hello World!")

    gr.updatews()

    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10 * math.cos(-rx * math.pi / 2),
                     10 * math.sin(-rx * math.pi / 2), 0, 0, 0, 0, 0, 0, 1)
Пример #9
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)
Пример #10
0
def display():
    global window_width, window_height, rx
    gr3.setbackgroundcolor(1,1,1,1)
    # Kamera einstellen
    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10*math.cos(-rx*math.pi/2), 10*math.sin(-rx*math.pi/2), 0, 0, 0, 0, 0, 0, 1)

    gr3.drawimage(0, window_width, 0, window_height, window_width, window_height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
    glViewport(0,0,window_width,window_height);
    glDisable(GL_LIGHTING)
    glDisable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()
    glMatrixMode(GL_PROJECTION)
    glPushMatrix()
    glLoadIdentity()
    glColor4f(1,0,0,1)
    x, y = 0, 0.22
    glRasterPos2f(x*2-1,y*2-1)
    for c in u"Dies ist ein GLUT-Fenster, in dem mit GR3 eine":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,ord(c))
    y-=0.05
    glRasterPos2f(x*2-1,y*2-1)
    for c in u"Szene gerendert wird. Mit der Maus kann man":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,ord(c))
    y-=0.05
    glRasterPos2f(x*2-1,y*2-1)
    for c in u"das dargestellte Molekül rotieren lassen.":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,ord(c))
    y-=0.04
    glRasterPos2f(x*2-1,y*2-1)
    for c in u"(Rechtsklick öffnet das Kontextmenü)":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,ord(c))
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    glMatrixMode(GL_MODELVIEW)
    glPopMatrix()
    glMatrixMode(GL_PROJECTION)
    glPopMatrix()
    glutSwapBuffers()
    gr.clearws()
    selntran(0)
    gr3.setquality(4)
    gr3.drawimage(0, 0.5, 0.5, 1, 250, 250, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.settextcolorind(1)
    gr.settextfontprec(6,0)
    
    x = list(range(5))
    y = list(range(5))
    
    nominalWindowHeight = 500.0
    pointSize = ( 8, 9, 10, 11, 12, 14, 18, 24, 36 )
    s = "i\\hbar\\frac{\\partial\\psi}{\\partial t} = \\frac{\\hbar^2}{2m}\\nabla^2\\psi + V(\\mathbf{r})\\psi"
    x = 0.9
    y = 0.9;
    gr.settextalign(3, 3)
    for i in range(8):
        gr.setcharheight(pointSize[i] / nominalWindowHeight)
        gr.mathtex(x, y, s)
        y -= 4 * pointSize[i] / nominalWindowHeight
    
    gr.setcharheight(0.1)
    gr.mathtex(0.9, 0.05, "Hello World!")
    gr.settextcolorind(8)
    gr.text(0.9, 0.05, "Hello World!")

    gr.updatews()
    
    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10*math.cos(-rx*math.pi/2), 10*math.sin(-rx*math.pi/2), 0, 0, 0, 0, 0, 0, 1)
Пример #11
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)