def setCAlphaSizeToDefault(self): '''' Sets the residue's C-alpha atom to the default size. This is useful if the size has been changed somewhere. ''' try: temp = PDBAtom('____', '9', 1, 'CA') defaultSize = temp.getAtomRadius() del temp atom = self.getAtom('CA') atom.setAtomRadius(defaultSize) except: pass
def setCAlphaColorToDefault(self): '''' Sets the residue's C-alpha atom to the default color. This is useful if the color has been changed somewhere. ''' try: temp = PDBAtom('____', '9', 1, 'CA') defaultColor = (temp.getColorR(), temp.getColorG(), temp.getColorB(), temp.getColorA()) del temp atom = self.getAtom('CA') atom.setColor(*defaultColor) except: pass
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 redo(self): """ In addition to being called to redo an action, this is called the first time the action occurs. """ raw = PDBAtom(self.currentChainModel.getPdbID(), self.currentChainModel.getChainID(), self.resSeqNum, 'CA') raw.setPosition(self.chosenCoordinates) atom = self.viewer.renderer.addAtom(raw) self.currentChainModel[self.resSeqNum].addAtomObject(atom) self.currentChainModel[self.resSeqNum].setCAlphaColorToDefault() bondBefore = None bondAfter = None if self.resSeqNum - 1 in self.currentChainModel.residueRange(): prevCAlpha = self.currentChainModel[self.resSeqNum - 1].getAtom('CA') if prevCAlpha: bondBefore = PDBBond() bondBefore.setAtom0Ix(prevCAlpha.getHashKey()) bondBefore.setAtom1Ix(atom.getHashKey()) if self.resSeqNum + 1 in self.currentChainModel.residueRange(): nextCAlpha = self.currentChainModel[self.resSeqNum + 1].getAtom('CA') if nextCAlpha: bondAfter = PDBBond() bondAfter.setAtom0Ix(nextCAlpha.getHashKey()) bondAfter.setAtom1Ix(atom.getHashKey()) if bondBefore: self.viewer.renderer.addBond(bondBefore) if bondAfter: self.viewer.renderer.addBond(bondAfter) self.viewer.emitModelChanged() self.structureEditor.atomJustAdded = atom if self.structureEditor.atomicBackwardRadioButton.isChecked(): self.structureEditor.atomPrevButtonPress() elif self.structureEditor.atomicForwardRadioButton.isChecked(): self.structureEditor.atomNextButtonPress()
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
#!/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
from PyQt4 import QtGui 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()