Changeset 3079


Ignore:
Timestamp:
Sep 18, 2017 8:52:24 AM (6 years ago)
Author:
vondreele
Message:

implement rigid body reference vectors

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r3065 r3079  
    15141514        else:
    15151515            rbXYZ = np.array(rbXYZ)-np.array(rbXYZ[0])
     1516            Xxyz = rbXYZ[1]
     1517            X = Xxyz/np.sqrt(np.sum(Xxyz**2))
     1518            Yxyz = rbXYZ[2]
     1519            Y = Yxyz/np.sqrt(np.sum(Yxyz**2))
     1520            Mat = G2mth.getRBTransMat(X,Y)
     1521            rbXYZ = np.inner(Mat,rbXYZ).T
    15161522            data['Residue'][rbId] = {'RBname':'UNKRB','rbXYZ':rbXYZ,'rbTypes':rbTypes,
    15171523                'atNames':atNames,'rbRef':[0,1,2,False],'rbSeq':[],'SelSeq':[0,0],'useCount':0}
     
    18501856                    rbData['rbTypes'] = newTypes
    18511857                    rbData['rbXYZ'] = newXYZ
     1858                G2plt.PlotRigidBody(G2frame,'Residue',AtInfo,rbData,plotDefaults)
    18521859                wx.CallAfter(UpdateResidueRB)
    18531860                   
     
    19171924
    19181925            def OnRefSel(event):
     1926               
    19191927                Obj = event.GetEventObject()
    19201928                iref,res,jref = Indx[Obj.GetId()]
     
    19271935                for i,ref in enumerate(RefObjs[jref]):
    19281936                    ref.SetItems([atNames[j] for j in refChoice[rbId][i]])
    1929                     ref.SetValue(atNames[rbData['rbRef'][i]])
     1937                    ref.SetValue(atNames[rbData['rbRef'][i]])                   
     1938                rbXYZ = rbData['rbXYZ']
    19301939                if not iref:     #origin change
    1931                     rbXYZ = rbData['rbXYZ']
    19321940                    rbXYZ -= rbXYZ[ind]
    1933                     res.ClearSelection()
    1934                     resTable = res.GetTable()
    1935                     for r in range(res.GetNumberRows()):
    1936                         row = resTable.GetRowValues(r)
    1937                         row[2:4] = rbXYZ[r]
    1938                         resTable.SetRowValues(r,row)
    1939                     res.ForceRefresh()
    1940                     G2plt.PlotRigidBody(G2frame,'Residue',AtInfo,rbData,plotDefaults)
     1941                #TODO - transform all atom XYZ by axis choices
     1942                Xxyz = rbXYZ[rbData['rbRef'][1]]
     1943                X = Xxyz/np.sqrt(np.sum(Xxyz**2))
     1944                Yxyz = rbXYZ[rbData['rbRef'][2]]
     1945                Y = Yxyz/np.sqrt(np.sum(Yxyz**2))
     1946                Mat = G2mth.getRBTransMat(X,Y)
     1947                rbXYZ = np.inner(Mat,rbXYZ).T
     1948                rbData['rbXYZ'] = rbXYZ
     1949                res.ClearSelection()
     1950                resTable = res.GetTable()
     1951                for r in range(res.GetNumberRows()):
     1952                    row = resTable.GetRowValues(r)
     1953                    row[2:4] = rbXYZ[r]
     1954                    resTable.SetRowValues(r,row)
     1955                res.ForceRefresh()
     1956                G2plt.PlotRigidBody(G2frame,'Residue',AtInfo,rbData,plotDefaults)
    19411957               
    19421958            Types = 2*[wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,5',]
  • trunk/GSASIImath.py

    r3048 r3079  
    825825    return np.array(XYZ)
    826826
     827def getRBTransMat(X,Y):
     828    '''Get transformation for Cartesian axes given 2 vectors
     829    X will  be parallel to new X-axis; X cross Y will be new Z-axis &
     830    (X cross Y) cross Y will be new Y-axis
     831    Useful for rigid body axes definintion
     832   
     833    :param array X: normalized vector
     834    :param array Y: normalized vector
     835   
     836    :returns: array M: transformation matrix
     837    use as XYZ' = np.inner(M,XYZ) where XYZ are Cartesian
     838   
     839    '''
     840    Mat2 = np.cross(X,Y)      #UxV-->Z
     841    Mat2 /= np.sqrt(np.sum(Mat2**2))
     842    Mat3 = np.cross(Mat2,X)        #(UxV)xU-->Y
     843    Mat3 /= np.sqrt(np.sum(Mat3**2))
     844    return np.array([X,Mat3,Mat2])       
     845               
    827846def RotateRBXYZ(Bmat,Cart,oriQ):
    828847    '''rotate & transform cartesian coordinates to crystallographic ones
  • trunk/GSASIIphsGUI.py

    r3058 r3079  
    75247524            rbsizer.Add(rbsizer2)   
    75257525            if model['Type'] == 'Residue':
    7526                 atNames = RBData['Residue'][model['RBId']]['atNames']
    7527                 rbsizer.Add(wx.StaticText(G2frame.MCSA,-1,'Torsions:'),0,WACV)
    7528                 rbsizer3 = wx.FlexGridSizer(0,8,5,5)
    7529                 for it,tor in enumerate(model['Tor'][0]):
    7530                     iBeg,iFin = RBData['Residue'][model['RBId']]['rbSeq'][it][:2]
    7531                     name = atNames[iBeg]+'-'+atNames[iFin]
    7532                     torRef = wx.CheckBox(G2frame.MCSA,-1,label=' %s: '%(name))
    7533                     torRef.SetValue(model['Tor'][1][it])
    7534                     torRef.Bind(wx.EVT_CHECKBOX,OnPosRef)
    7535                     Indx[torRef.GetId()] = [model,'Tor',it]
    7536                     rbsizer3.Add(torRef,0,WACV)
    7537                     torVal = G2G.ValidatedTxtCtrl(G2frame.MCSA,model['Tor'][0],it,nDig=(10,4),OnLeave=OnPosVal)
    7538                     rbsizer3.Add(torVal,0,WACV)
    7539                     rbsizer3.Add(wx.StaticText(G2frame.MCSA,-1,' Range: '),0,WACV)
    7540                     rmin,rmax = model['Tor'][2][it]
    7541                     torRange = wx.TextCtrl(G2frame.MCSA,-1,'%.3f %.3f'%(rmin,rmax),style=wx.TE_PROCESS_ENTER)
    7542                     Indx[torRange.GetId()] = [model,'Tor',it]
    7543                     torRange.Bind(wx.EVT_TEXT_ENTER,OnPosRange)
    7544                     torRange.Bind(wx.EVT_KILL_FOCUS,OnPosRange)
    7545                     rbsizer3.Add(torRange,0,WACV)
    7546                 rbsizer.Add(rbsizer3)
    7547                
     7526                try:
     7527                    atNames = RBData['Residue'][model['RBId']]['atNames']
     7528                    rbsizer.Add(wx.StaticText(G2frame.MCSA,-1,'Torsions:'),0,WACV)
     7529                    rbsizer3 = wx.FlexGridSizer(0,8,5,5)
     7530                    for it,tor in enumerate(model['Tor'][0]):
     7531                        iBeg,iFin = RBData['Residue'][model['RBId']]['rbSeq'][it][:2]
     7532                        name = atNames[iBeg]+'-'+atNames[iFin]
     7533                        torRef = wx.CheckBox(G2frame.MCSA,-1,label=' %s: '%(name))
     7534                        torRef.SetValue(model['Tor'][1][it])
     7535                        torRef.Bind(wx.EVT_CHECKBOX,OnPosRef)
     7536                        Indx[torRef.GetId()] = [model,'Tor',it]
     7537                        rbsizer3.Add(torRef,0,WACV)
     7538                        torVal = G2G.ValidatedTxtCtrl(G2frame.MCSA,model['Tor'][0],it,nDig=(10,4),OnLeave=OnPosVal)
     7539                        rbsizer3.Add(torVal,0,WACV)
     7540                        rbsizer3.Add(wx.StaticText(G2frame.MCSA,-1,' Range: '),0,WACV)
     7541                        rmin,rmax = model['Tor'][2][it]
     7542                        torRange = wx.TextCtrl(G2frame.MCSA,-1,'%.3f %.3f'%(rmin,rmax),style=wx.TE_PROCESS_ENTER)
     7543                        Indx[torRange.GetId()] = [model,'Tor',it]
     7544                        torRange.Bind(wx.EVT_TEXT_ENTER,OnPosRange)
     7545                        torRange.Bind(wx.EVT_KILL_FOCUS,OnPosRange)
     7546                        rbsizer3.Add(torRange,0,WACV)
     7547                    rbsizer.Add(rbsizer3)
     7548                except KeyError:    #Missing RB - clear all away!
     7549                    data['MCSA'] = {'Models':[{'Type':'MD','Coef':[1.0,False,[.8,1.2],],'axis':[0,0,1]}],'Results':[],'AtInfo':{}}
     7550                    wx.CallAfter(UpdateMCSA)
    75487551            return rbsizer
    75497552           
     
    77967799            return
    77977800        time1 = time.time()
    7798         if process == 'single':
     7801        nprocs = GSASIIpath.GetConfigValue('Multiprocessing_cores',0)
     7802        if process == 'single' or not nprocs:
    77997803            pgbar = wx.ProgressDialog('MC/SA','Residual Rcf =',101.0,
    78007804                style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT)
     
    78097813            tsf = 0.
    78107814            nCyc = mcsaControls['Cycles']
    7811             if process == 'single':
     7815            if process == 'single' or not nprocs:
    78127816                for i in range(nCyc):
    78137817                    pgbar.SetTitle('MC/SA run '+str(i+1)+' of '+str(nCyc))
     
    78217825                    Title='Reflection covariance matrix',zrange=[-1.,1.],color='RdYlGn')
    78227826            else:
    7823                 nprocs = GSASIIpath.GetConfigValue('Multiprocessing_cores')
    78247827                Results,sftime,numsf = G2mth.MPmcsaSearch(nCyc,data,RBdata,reflType,reflData,covData,nprocs)
    78257828                MCSAdata['Results'] += Results   #+= to  any saved ones
    78267829                print ' Total SF time: %.2fs MC/SA run time: %.2fs Nsfcalc: %d'%(sftime,time.time()-time1,numsf)
    78277830        finally:
    7828             if process == 'single':
     7831            if process == 'single' or not nprocs:
    78297832                pgbar.Destroy()
    78307833        MCSAdata['Results'] = G2mth.sortArray(MCSAdata['Results'],2,reverse=False)
Note: See TracChangeset for help on using the changeset viewer.