示例#1
0
    def doit(self, atom1, atom2, angle, mov_atoms, returnVal=0):
        mol = atom1.top
        if mov_atoms is None:
            mov_atoms = mol.subTree(atom1, atom2, mol.allAtoms)
        assert len(mov_atoms)
        mov_coords = Numeric.array(mov_atoms.coords)
        lenCoords = len(mov_coords)
        x = Numeric.array(atom1.coords)
        y = Numeric.array(atom2.coords)
        rot = (angle * 3.14159 / 180.) % (2 * Numeric.pi)
        matrix = rotax(x, y, rot)
        _ones = Numeric.ones(lenCoords, 'f')
        _ones.shape = (lenCoords, 1)
        mov_coords = Numeric.concatenate((mov_coords, _ones), 1)
        newcoords = Numeric.dot(mov_coords, matrix)
        nc = newcoords[:, :3].astype('f')
        for i in range(lenCoords):
            at = mov_atoms[i]
            at._coords[at.conformation] = nc[i].tolist()

        event = EditAtomsEvent('coords', mov_atoms)
        self.vf.dispatchEvent(event)

        #have to return nc for setTorsionGC
        if returnVal:
            return nc
    def doit(self, mobAtoms):
        """
mobAtoms: AtomSet that is being frozen.
Assuming the AtomSet are from same molecule
        """

        # fixme: need checking for mat (matrix) and mobAtoms
        geomContainer = mobAtoms[0].top.geomContainer
        mGeom = geomContainer.masterGeom
        mat = mGeom.rotation
        mat = Numeric.reshape(mat, (4, 4))

        # update coords
        mobAtoms = mobAtoms.findType(Atom)
        coords = mobAtoms.coords
        hCoords = Numeric.concatenate((coords,Numeric.ones((len(coords),1),\
                                                            'd')), 1)
        tCoords = Numeric.dot(hCoords, mat)[:, :3]
        tCoords = tCoords.tolist()
        mobAtoms.updateCoords(tCoords, 0)  # overwritten the original coords

        # reset the rotation matrix of masterGeom
        identity = Numeric.identity(4, 'f').ravel()
        mGeom.SetRotation(Numeric.identity(4, 'f').ravel())

        event = EditAtomsEvent('coords', mobAtoms)
        self.vf.dispatchEvent(event)

        mGeom.viewer.Redraw()

        return
示例#3
0
文件: pmvAction.py 项目: skcsd/ePMV
 def __call__(self, opt):
     #opt is the optimizer object either cg, md etc...
     #opt.atmsel give acces to the current data model
     #opt.current_e give acces to the current energy
     #print "action"
     indices, model = opt.atmsel.get_atom_indices()
     self.updatePmvCoord(self.idConf, model)
     event = EditAtomsEvent('coords', self.pmvModel.allAtoms)
     self.mv.dispatchEvent(event)
     #should we update other geom? at least one chain to test
     if self.epmv is not None:
         self.epmv.updateDataGeom(self.pmvModel)
     #self.epmv.helper.updatePoly(self.pmvModel.name+":"+self.pmvModel.chains[0].name+"_cloud",
     #                            vertices=self.pmvModel.chains[0].residues.atoms.coords)
     #try tu update viewer ?
     if self.redraw:
         #print "redraw",self.mv.hasGui
         if self.mv.hasGui:
             #print "update"
             #self.mv.GUI.VIEWER.update()
             self.mv.GUI.VIEWER.OneRedraw()
             self.mv.GUI.VIEWER.update()
             #self.GUI.ROOT.after(5, self.mv.GUI.VIEWER.OneRedraw)
         if self.epmv is not None:
             self.epmv.helper.update()
     if self.store:
         #add a conformation for modeller
         self.pmvModel.allAtoms.addConformation(
             self.pmvModel.allAtoms.coords[:])
         self.idConf = len(self.pmvModel.allAtoms[0]._coords) - 1
示例#4
0
    def doit(self, atom1, atom2):
        #Have to find the bond first

        theBond = None
        for b in atom1.bonds:
            at2 = b.atom1
            if at2 == atom1:
                at2 = b.atom2
            if at2 == atom2:
                #remove this bond
                theBond = b
                atom2.bonds.remove(theBond)
                #this may not be possible
                atom1.bonds.remove(theBond)
                atom1.parent.hasBonds = 0
                if atom2.parent != atom1.parent:
                    atom2.parent.hasBonds = 0
                    if atom1.parent.parent:
                        atom1.parent.parent.hasBonds = 0
                    if atom2.parent.parent:
                        atom2.parent.parent.hasBonds = 0
                    break

        if not theBond:
            from warnings import warn
            warn('bond not found %s-%s' % (atom1, atom2))
            return 'ERROR'
        else:
            event = EditAtomsEvent('coords', AtomSet([atom1, atom2]))
            self.vf.dispatchEvent(event)
示例#5
0
    def updateMindy(self):
        from ARViewer import util
        import numpy.oldnumeric as Numeric
        imdheader = self.imd_recv_header(self.sock)
        vmd_length = imdheader.length
        imdtype = imdheader.imdtype
        if imdtype == IMD_FCOORDS:
            print "recv fcoords ", vmd_length
            test = self.imd_recv_fcoords(vmd_length, self.imd_coords)
            print self.imd_coords[0]
            b = 0
            n1 = 0
            for i, m in enumerate(self.mol):
                n1 += len(m.allAtoms.coords)
                try:
                    #should apply the inverse matrix? to get back to the origin before going on the marker..
                    if hasattr(self.vf, 'art'):
                        M = matrix(m.pat.mat_transfo.reshape(4, 4))
                        vt = util.ApplyMatrix(
                            Numeric.array(self.imd_coords[b:n1]),
                            numpy.array(M.I))
                        print "update coords but back in CS"
                        print vt[0]
                        m.allAtoms.updateCoords(vt, self.slot[i])
                        print m.allAtoms.coords[0]
                    else:
                        m.allAtoms.updateCoords(self.imd_coords[b:n1],
                                                self.slot[i])
                except:
                    print "coord update failed"
                b = n1
            #print m.allAtoms._coords[0]
            #print "ipdate coords events"
            from Pmv.moleculeViewer import EditAtomsEvent
            for i, m in enumerate(self.mol):
                event = EditAtomsEvent('coords', m.allAtoms)
                try:
                    self.vf.dispatchEvent(event)
                except:
                    print "event failed"
            #here we should update from AR....which is apply the marker transformation
            #one marker per mol...should have some mol.mat_transfo attributes
            #get the maker position transfo

            coords = []
            for m in self.mol:
                if hasattr(self.vf, 'art'):
                    M = m.pat.mat_transfo
                    vt = []
                    vt = util.ApplyMatrix(Numeric.array(m.allAtoms.coords), M)
                else:
                    vt = m.allAtoms.coords[:]
                coords.extend(vt)
            self.imd_send_fcoords(self.N, coords)
示例#6
0
 def repeat_transTors(self, event=None):
     deltaAngle = self.extslider.get()
     if self.torsionType.get() != '1':
         self.transformCoords(deltaAngle)
     #this is here in order to create a log message
     nc = self.vf.setRelativeTorsion(self.atomList[1],
                                     self.atomList[2],
                                     deltaAngle,
                                     self.mov_atoms,
                                     returnVal=1)
     event = EditAtomsEvent('coords', self.mov_atoms)
     self.vf.dispatchEvent(event)
示例#7
0
def pmv_show(pose, self):
    from Pmv.moleculeViewer import EditAtomsEvent
    global pmv_state
    import time
    #if not with_pmv: return
    model = self.getMolFromName("test")
    model.allAtoms.setConformation(1)
    coord = {}
    print pose.n_residue(), len(model.chains.residues)
    for resi in range(1, pose.n_residue() + 1):
        res = pose.residue(resi)
        resn = pose.pdb_info().number(resi)
        #print resi,res.natoms(),len(model.chains.residues[resi-1].atoms)
        k = 0
        for atomi in range(1, res.natoms() + 1):
            name = res.atom_name(atomi).strip()
            if name != 'NV':
                a = model.chains.residues[resi - 1].atoms[k]
                pmv_name = a.name
                k = k + 1
                if name != pmv_name:
                    if name[1:] != pmv_name[:-1]:
                        print name, pmv_name
                    else:
                        coord[(resn, pmv_name)] = res.atom(atomi).xyz()
                        cood = res.atom(atomi).xyz()
                        a._coords[1] = [cood.x, cood.y, cood.z]

                else:
                    coord[(resn, name)] = res.atom(atomi).xyz()
                    cood = res.atom(atomi).xyz()
                    a._coords[1] = [cood.x, cood.y, cood.z]  #return coord
    event = EditAtomsEvent('coords', model.allAtoms)
    self.dispatchEvent(event)
    #modEvent = ModificationEvent('edit','coords', mol.allAtoms)
    #mol.geomContainer.updateGeoms(modEvent)
    #PMV
    #self.GUI.VIEWER.Redraw()
    #time.sleep(.1)
    #Blender
    epmv.insertKeys(model.geomContainer.geoms['cpk'], 1)
    epmv.getCurrentScene().update()
    Draw.Redraw()
    Draw.Redraw(1)
    Blender.Redraw()
示例#8
0
 def mindyGet(self):
     from ARViewer import util
     import numpy.oldnumeric as Numeric
     imdheader = self.imd_recv_header(self.sock)
     vmd_length = imdheader.length
     imdtype = imdheader.imdtype
     if imdtype == IMD_FCOORDS:
         #print "recv fcoords ",vmd_length
         test = self.imd_recv_fcoords(vmd_length, self.imd_coords)
         #print self.imd_coords[0]
         b = 0
         n1 = 0
         for i, m in enumerate(self.mol):
             n1 += len(m.allAtoms.coords)
             try:
                 #should apply the inverse matrix? to get back to the origin
                 #before going on the marker..
                 #but problem of scaleFactor
                 if hasattr(self.vf, 'art'):
                     M = matrix(m.pat.mat_transfo.reshape(4, 4))
                     vt = util.ApplyMatrix(Numeric.array(
                         self.imd_coords[b:n1]),
                                           Numeric.array(M.I),
                                           transpose=False)
                     #print "update coords but back in CS"
                     #print vt[0]
                     if True in numpy.isnan(vt[0]):
                         vt = map(lambda x: x[0], m.allAtoms._coords)
                     m.allAtoms.updateCoords(vt, self.slot[i])
                     #print m.allAtoms.coords[0]
                 else:
                     m.allAtoms.updateCoords(self.imd_coords[b:n1],
                                             self.slot[i])
             except:
                 print "coord update failed"
             b = n1
         from Pmv.moleculeViewer import EditAtomsEvent
         for i, m in enumerate(self.mol):
             event = EditAtomsEvent('coords', m.allAtoms)
             try:
                 self.vf.dispatchEvent(event)
             except:
                 print "event failed"
示例#9
0
    def applyState(self, ind):
        """None<-applyState(ind)"""
        mol = self.mol
        # -1 is key for go back to original
        if int(ind)==-1:
            mol.allAtoms.setConformation(0)
            conf = None
        else:
            #in this case want to get new coords
            #coords = self.traj.coords["frame%d"%ind]
            coords = self.traj.coords[ind]
            coordsarr = (Numeric.array(coords)*10).astype("f")
            allAtoms = self.mol.allAtoms
            allAtoms.updateCoords(coordsarr[:], self.coordSlot)

        if not self.vf.hasGui: return
        event = EditAtomsEvent('coords', mol.allAtoms)
        self.vf.dispatchEvent(event)
        #modEvent = ModificationEvent('edit','coords', mol.allAtoms)
        #mol.geomContainer.updateGeoms(modEvent)
        self.vf.GUI.VIEWER.Redraw()
示例#10
0
    def applyState(self, ind):
        """None<-applyState(ind)"""
        mol = self.mol
        viewer = None # self.vf.GUI.VIEWER
        if self.vf.hasGui:
            viewer = self.vf.GUI.VIEWER
        cache_list = False
        # check if we can cache the display list for this frame 
        if self.dpyLists.has_key(ind):
            if self.dpyLists[ind] is not None:
                cache_list = True
                viewer.currentCamera.dpyList = self.dpyLists[ind]
                #viewer.dpyList = self.dpyLists[ind]
                if self.vf.hasGui:
                    viewer.OneRedraw()
                #viewer.Redraw()
            else:
               self.dpyLists.pop(ind) 

        if not cache_list:
            if int(ind)==-1: # -1 is key for go back to original
                mol.allAtoms.setConformation(0)
            else:
                #in this case we want to get new coords
                coords = self.traj.coords[ind]
                coordsarr = (Numeric.array(coords)*10).astype("f")
                allAtoms = self.mol.allAtoms
                allAtoms.updateCoords(coordsarr[:], self.coordSlot)
            #if not self.vf.hasGui: return
            if self.vf.hasGui: 
                self.vf.GUI.VIEWER.singleDpyList = True
            event = EditAtomsEvent('coords', mol.allAtoms)
            self.vf.dispatchEvent(event)
            if self.vf.hasGui: 
                viewer.OneRedraw()
                #viewer.Redraw()
                self.dpyLists[ind] = viewer.currentCamera.dpyList #viewer.dpyList
                viewer.currentCamera.dpyList = None
                #viewer.dpyList = None
                self.vf.GUI.VIEWER.singleDpyList = False
示例#11
0
 def transformCoords(self, deltaAngle):
     """ deltaAngle is NOW not final angle wanted but relative"""
     #mov_coords is the array of the coords of the atoms to be moved,
     #x2 and x3 are atoms which define the axis of the transformation
     #by deltaAngle. NB: effect is that mov_atoms.coords
     #are transformed...
     if not hasattr(self, 'mov_atoms'): return
     if not len(self.mov_atoms): return
     x1, x2, x3, x4 = self.atomList
     nc = self.vf.setRelativeTorsion.doit(x2,
                                          x3,
                                          deltaAngle,
                                          self.mov_atoms,
                                          returnVal=1)
     mol = x2.top
     #mov_atoms = mol.subTree(x2, x3, mol.allAtoms)
     for i in range(len(nc)):
         at = self.mov_atoms[i]
         at._coords[at.conformation] = nc[i].tolist()
     event = EditAtomsEvent('coords', self.mov_atoms)
     self.vf.dispatchEvent(event)
     self.update()
示例#12
0
 def doit(self, atom1, atom2, **kw):
     origin = kw['origin']
     bondOrder = kw['bondOrder']
     bond = Bond(atom1, atom2, origin=origin, bondOrder=bondOrder)
     event = EditAtomsEvent('coords', AtomSet([atom1, atom2]))
     self.vf.dispatchEvent(event)