コード例 #1
0
ファイル: qutemol.py プロジェクト: MDAnalysis/pyQuteMol
def onMouseButton(button, state, x, y):
    global oldX, oldY
    global isRotating, isZooming, isClipping
    global mustDoHQ
    oldX, oldY = x, y
    if (button == GLUT_LEFT_BUTTON):
        if (state == GLUT_DOWN):
            mustDoHQ = False
            isRotating = True
        elif (state == GLUT_UP):
            mol.orien = glTrackball.quat * mol.orien
            glTrackball.reset()
            mustDoHQ = True
            isRotating = not isRotating
            glutPostRedisplay()
    elif (button == GLUT_RIGHT_BUTTON):
        keys = glutGetModifiers()
        if (keys & GLUT_ACTIVE_SHIFT):
            if (state == GLUT_DOWN):
                isClipping = True
            elif (state == GLUT_UP):
                isClipping = not isClipping
        else:
            if (state == GLUT_DOWN):
                isZooming = True
            elif (state == GLUT_UP):
                isZooming = not isZooming
コード例 #2
0
ファイル: qutemol.py プロジェクト: MDAnalysis/pyQuteMol
 def keyfunc(k, x, y):
     global run_trj, draw_axes
     if k == "q" or ord(k) == 27: # Escape
         sys.exit(0)
     elif k == "h":
         printHelp()
     elif k == "i":
         ipshell()
     elif k == "n":
         mol.read_next_frame()
         glutPostRedisplay()
     elif k == "p":
         mol.read_previous_frame()
         glutPostRedisplay()
     elif k == "j":
         print "Current frame %d, Total frames %d, select frame:"%(mol.universe.dcd.ts.frame, mol.universe.dcd.numframes)
         selection = raw_input("> ")
         try:
             frameno = int(selection)
             mol.universe.dcd[frameno]
             glutPostRedisplay()
         except:
             print "Invalid frame"
     elif k == "+":
         mol.averaging += 1
     elif k == "-":
         mol.averaging -= 1
         if mol.averaging < 1: mol.averaging = 1
     elif k == "r":
         run_trj = not run_trj
     elif k == "v":
         mol.PrepareAOSingleView(shadowmap)
         glutPostRedisplay()
     elif k == "a":
         draw_axes = not draw_axes
         glutPostRedisplay()
     elif k == "s":
         saveSnapshot(mainCanvas.GetHardRes()*2, mol)
     elif k == "g":
         shader_i[0] += 1
         if shader_i[0] == len(shaders): shader_i[0] = 0
         shaders[shader_i[0]].set(cgSettings)
         cgSettings.UpdateShaders()
         glutPostRedisplay()
     elif k == "G":
         shader_i[0] -= 1
         if shader_i[0] == -1: shader_i[0] = len(shaders)-1
         shaders[shader_i[0]].set(cgSettings)
         cgSettings.UpdateShaders()
         glutPostRedisplay()
     elif k == "o":
         mol.ResetAO()
         glutPostRedisplay()
     elif k == "m":
         makeMovie(mol)
     elif k == "k":
         print "Make selection for color change:"
         selection = raw_input("> ")
         try:
             sel = mol.universe.selectAtoms(selection)
             idx = sel.indices()
             print "input color:"
             color = raw_input("> ")
             mol.colors[idx] = convert_color(int(color,0))
             glutPostRedisplay()
         except:
             print "Invalid selection"
     elif k == "e":
         print "Make selection for exclusion:"
         selection = raw_input("> ")
         try:
             sel = mol.universe.selectAtoms(selection)
             mol.excl = sel.indices()
             mol.ResetAO()
             glutPostRedisplay()
         except:
             print "Invalid selection"
     elif k == "c":
         print "Make new selection:"
         selection = raw_input("> ")
         try:
             mol.sel = mol.universe.selectAtoms(selection)
             mol.pos = mol.sel.centerOfGeometry()
             coor = mol.sel.coordinates()
             min, max = numpy.minimum.reduce(coor), numpy.maximum.reduce(coor)
             mol.r = 0.5*numpy.sqrt(numpy.sum(numpy.power(max-min-4,2)))
             mol.min, mol.max = min, max
             mol.idx = mol.sel.indices()
             mol.ResetAO()
             glutPostRedisplay()
         except:
             print "Invalid selection"
     elif k == "x":
         mol.orien *= 0
         v = numpy.sin(numpy.pi/4.)
         mol.orien = quaternion([-.5,-.5,0.5,0.5])
         glTrackball.reset()
         glutPostRedisplay()
     elif k == "y":
         mol.orien *= 0
         v = numpy.sin(numpy.pi/4.)
         mol.orien.array += [-v,-v,0,0]
         glTrackball.reset()
         glutPostRedisplay()
     elif k == "z":
         mol.orien *= 0
         mol.orien.array[2] = -1
         glTrackball.reset()
         glutPostRedisplay()