def rotateSelectedScene(self, dx, dy): newDx = vectorDistance(self.eye, self.center) * abs( tan(pi * self.eyeZoom)) * dx / float(self.width()) newDy = vectorDistance(self.eye, self.center) * abs( tan(pi * self.eyeZoom)) * dy / float(self.height()) moveLength = vectorAdd(vectorScalarMultiply(-newDy, self.up), vectorScalarMultiply(newDx, self.right)) moveDirection = vectorNormalize(moveLength) rotationAxis = vectorCrossProduct(moveDirection, self.look) rotationAxis3D = Vector3DFloat(rotationAxis[0], rotationAxis[1], rotationAxis[2]) centerOfMass = Vector3DFloat(0, 0, 0) totalCount = 0 for s in self.scene: objectCount = s.renderer.selectionObjectCount() if (objectCount > 0): totalCount = totalCount + objectCount centerOfMass = centerOfMass + ( s.objectToWorldCoordinatesVector( s.renderer.selectionCenterOfMass()) * float(objectCount)) if (totalCount > 0): centerOfMass = centerOfMass * float(1.0 / totalCount) for s in self.scene: selectionCOM = s.worldToObjectCoordinatesVector(centerOfMass) selectionAxis = s.worldToObjectCoordinatesVector(rotationAxis3D) if (s.renderer.selectionRotate(selectionCOM, selectionAxis, vectorSize(moveLength))): s.emitModelChanged()
def is_linear(self, atom_list): start_pt = Vector3DFloat(0, 0, 0) end_pt = Vector3DFloat(0, 0, 0) positions = [atom.getPosition() for atom in atom_list] LinearSolver.findBestFitLine(start_pt, end_pt, positions) avg_ortho_distance = sqrt( LinearSolver.sumDistSqrd(start_pt, end_pt, positions)) / len(positions) return avg_ortho_distance <= self.pt_line_dist_thresh
def moveSelectedScene(self, dx, dy): newDx = vectorDistance(self.eye, self.center) * abs( tan(pi * self.eyeZoom)) * dx / float(self.width()) newDy = vectorDistance(self.eye, self.center) * abs( tan(pi * self.eyeZoom)) * dy / float(self.height()) moveDirection = vectorAdd(vectorScalarMultiply(-newDy, self.up), vectorScalarMultiply(newDx, self.right)) dirVec = Vector3DFloat(moveDirection[0], moveDirection[1], moveDirection[2]) for s in self.scene: if (s.renderer.selectionMove(dirVec)): s.emitModelChanged()
def setLoopAtoms(self, startIndex, endIndex): self.engine.clearAtomList() self.engine.clearCurrentPath() for i in range(startIndex, endIndex + 1): if (i in self.chain.residueRange()): atom = self.chain[i].getAtom('CA') if (not atom): raw = PDBAtom(self.chain.getPdbID(), self.chain.getChainID(), i, 'CA') raw.setPosition(Vector3DFloat(0, 0, 0)) atom = self.calphaViewer.renderer.addAtom(raw) atom.setVisible(False) print atom self.chain[i].addAtomObject(atom) self.chain[i].setCAlphaColorToDefault() bondBefore = None bondAfter = None if i - 1 in self.chain.residueRange(): prevCAlpha = self.chain[i - 1].getAtom('CA') if prevCAlpha: print "adding a bond before" bondBefore = PDBBond() bondBefore.setAtom0Ix(prevCAlpha.getHashKey()) bondBefore.setAtom1Ix(atom.getHashKey()) if i + 1 in self.chain.residueRange(): nextCAlpha = self.chain[i + 1].getAtom('CA') if nextCAlpha: print "adding a bond after" bondAfter = PDBBond() bondAfter.setAtom0Ix(nextCAlpha.getHashKey()) bondAfter.setAtom1Ix(atom.getHashKey()) if bondBefore: self.calphaViewer.renderer.addBond(bondBefore) if bondAfter: self.calphaViewer.renderer.addBond(bondAfter) self.engine.addAtom(atom.getHashKey()) if not self.calphaViewer.loaded: self.calphaViewer.loaded = True self.calphaViewer.emitModelLoaded() else: self.calphaViewer.emitModelChanged()
def addAtom(self, atomName, x, y, z, element="", serialNo=None, occupancy=None, tempFactor=None, charge=""): '''Adds a new PDBAtom to the residue.''' residueIndex = self.chain.findIndexForRes(self) rawAtom = PDBAtom(self.chain.getPdbID(), self.chain.getChainID(), residueIndex, atomName) rawAtom.setPosition(Vector3DFloat(x, y, z)) if not element: element = atomName[0] rawAtom.setElement(element) if serialNo != None: rawAtom.setSerial(serialNo) if occupancy != None: rawAtom.setOccupancy(occupancy) if tempFactor != None: rawAtom.setTempFactor(tempFactor) if charge: rawAtom.setCharge(charge) self.__atoms[atomName] = rawAtom #print "%s PDBAtom added to %s Residue" %(atomName,self) ''' #Add atom to viewer and update --Mike's addition #self.chain.getViewer().renderer.addAtom(rawAtom) ''' ''' if(not self.chain.getViewer().loaded): self.chain.getViewer().loaded = True self.chain.getViewer().emitModelLoaded() self.chain.getViewer().dirty = True self.chain.getViewer().emitModelChanged() ''' return rawAtom
def undo(self): self.editor.undoInProgress = True if self.doTranslate: self.renderer.selectionMove( Vector3DFloat(-self.translateVector.x(), -self.translateVector.y(), -self.translateVector.z())) if self.doRotate: self.renderer.selectionRotate( self.rotateCenter, self.rotateAxis, self.rotateOldAngle - self.rotateNewAngleValue) if (self.rotateFieldNum == 'roll'): self.editor.roll = self.rotateNewAngleValue elif (self.rotateFieldNum == 'pitch'): self.editor.pitch = self.rotateNewAngleValue elif (self.rotateFieldNum == 'yaw'): self.editor.yaw = self.rotateNewAngleValue self.editor.posMoveDict[self.rotateFieldNum].setValue( self.rotateOldAngle) self.viewer.emitModelChanged() self.editor.undoInProgress = False
#!/usr/bin/python import sys from libpyGORGON import PDBAtom,Vector3DFloat from PyQt4 import QtGui, QtCore from window_manager import WindowManager from main_window_form import MainWindowForm app = QtGui.QApplication(sys.argv) window = MainWindowForm("2.0") window.addModule(WindowManager(window)) window.showMaximized() cAlphaViewer=window.viewers['calpha'] rawAtom=PDBAtom('AAAA', 'A', 1, 'CA') rawAtom.setPosition(Vector3DFloat(-1, 0, 0)) rawAtom = cAlphaViewer.renderer.addAtom(rawAtom) a = PDBAtom('AAAA', 'A', 2, 'CA') a.setPosition(Vector3DFloat(1, 0, 0)) print 'a:', a b = cAlphaViewer.renderer.addAtom(a) print 'b-1:', b if not cAlphaViewer.loaded: cAlphaViewer.loaded = True cAlphaViewer.emitModelLoaded() del a #This line causes a segmentation fault later on, which is weird because we never use the atom at this location in memory after this #Thus, unless there's a change, I'll have to be extremely careful about Python's garbage collection rawAtom.setColor(1, 0, 0, 1) #Red
def worldToObjectCoordinatesVector(self, worldCoords): coords = self.worldToObjectCoordinates([worldCoords.x(), worldCoords.y(), worldCoords.z()]) return Vector3DFloat(coords[0], coords[1], coords[2])
def objectToWorldCoordinatesVector(self, objectCoords): coords = self.objectToWorldCoordinates([objectCoords.x(), objectCoords.y(), objectCoords.z()]) return Vector3DFloat(coords[0], coords[1], coords[2])
from window_manager import WindowManager from main_window_form import MainWindowForm from seq_model.Chain import Chain # Create the application object required by Qt app = QtGui.QApplication(sys.argv) # Create Gorgon's main window and get a handle on the CAlpha Viewer window = MainWindowForm("2.0") window.addModule(WindowManager(window)) window.showMaximized() cAlphaViewer = window.viewers['calpha'] # Instantiate an Atom rawAtom = PDBAtom('AAAA', 'A', 1, 'CA') rawAtom.setPosition(Vector3DFloat(-.5, -0.5, -0.5)) rawAtom = cAlphaViewer.renderer.addAtom( rawAtom ) #A new PDBAtom is returned by this function, and rawAtom needs to refer to it # Instantiate an Second Atom rawAtom2 = PDBAtom('AAAA', 'A', 2, 'CA') rawAtom2.setPosition(Vector3DFloat(.5, 0.5, 0.5)) rawAtom2 = cAlphaViewer.renderer.addAtom(rawAtom2) # Confirm that these accessor functions are working key = rawAtom2.getHashKey() atom = cAlphaViewer.renderer.getAtom(key) print atom.getPDBId() print atom.getChainId()
# Create the application object required by Qt app = QtGui.QApplication(sys.argv) # Create Gorgon's main window and get a handle on the CAlpha Viewer window = MainWindowForm("2.0") window.addModule(WindowManager(window)) window.showMaximized() cAlphaViewer = window.viewers['calpha'] startPos = (-20, -10, -5) stopPos = (20, 10, 5) # Instantiate an Atom rawAtom = PDBAtom('AAAA', 'A', 1, 'CA') rawAtom.setPosition(Vector3DFloat(*startPos)) rawAtom.setAtomRadius(2) rawAtom.setColor(0, 1, 0, 1) rawAtom = cAlphaViewer.renderer.addAtom( rawAtom ) #A new PDBAtom is returned by this function, and rawAtom needs to refer to it # Instantiate a Second Atom rawAtom2 = PDBAtom('AAAA', 'A', 2, 'CA') rawAtom2.setPosition(Vector3DFloat(*stopPos)) rawAtom2.setAtomRadius(2) rawAtom2.setColor(1, 0, 0, 1) rawAtom2 = cAlphaViewer.renderer.addAtom(rawAtom2) # Get coordinates for helix with axis starting and ending at startPos and stopPos coordList = helixEndpointsToCAlphaPositions(startPos, stopPos)