Ignore:
Timestamp:
Oct 6, 2020 9:21:35 PM (14 months ago)
Author:
toby
Message:

prevent duplicate names for rigid bodies; make sure vector RB has 3+ atoms (less causes error in Orient ref sel); fix res ComboBox? selection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r4577 r4584  
    19521952        coords = np.array(coords)
    19531953        rbid = ran.randint(0,sys.maxsize)
     1954        namelist = [data['Residue'][key]['RBname'] for key in data['Residue']
     1955                        if 'RBname' in data['Residue'][key]]
     1956        name = G2obj.MakeUniqueLabel(name,namelist)
    19541957        data['Residue'][rbid] = {'RBname':name,
    19551958                'rbXYZ': coords,
     
    19641967        'Create a new vector rigid body'
    19651968        AtInfo = data['Vector']['AtInfo']
    1966         dlg = G2G.MultiIntegerDialog(G2frame,'New Rigid Body',['No. atoms','No. translations'],[1,1])
     1969        dlg = G2G.MultiIntegerDialog(G2frame,'New Rigid Body',['No. atoms','No. translations'],[3,1])
    19671970        if dlg.ShowModal() == wx.ID_OK:
    19681971            nAtoms,nTrans = dlg.GetValues()
     1972            if nAtoms < 3:
     1973                dlg.Destroy()
     1974                G2G.G2MessageBox(G2frame,'A vector rigid body must have 3 or more atoms')
     1975                return
    19691976            rbid = ran.randint(0,sys.maxsize)
    19701977            vecMag = [1.0 for i in range(nTrans)]
     
    19741981            Info = G2elem.GetAtomInfo('C')
    19751982            AtInfo['C'] = [Info['Drad'],Info['Color']]
    1976             data['Vector'][rbid] = {'RBname':'UNKRB','VectMag':vecMag,'rbXYZ':np.zeros((nAtoms,3)),
     1983            name = 'UNKRB'
     1984            namelist = [data['Vector'][key]['RBname'] for key in data['Vector']
     1985                        if 'RBname' in data['Vector'][key]]
     1986            name = G2obj.MakeUniqueLabel(name,namelist)
     1987            data['Vector'][rbid] = {'RBname':name,'VectMag':vecMag,'rbXYZ':np.zeros((nAtoms,3)),
    19771988                'rbRef':[0,1,2,False],'VectRef':vecRef,'rbTypes':rbTypes,'rbVect':vecVal,'useCount':0}
    19781989            data['RBIds']['Vector'].append(rbid)
     
    23172328                '''
    23182329                grid.completeEdits()
    2319                 rb = MakeVectorBody(os.path.split(filename)[1])
     2330                name = os.path.splitext(os.path.split(filename)[1])[0]
     2331                namelist = [data['Vector'][key]['RBname'] for key in
     2332                        data['Vector'] if 'RBname' in data['Vector'][key]]
     2333                name = G2obj.MakeUniqueLabel(name,namelist)
     2334                rb = MakeVectorBody(name)
    23202335                UpdateVectorBody(rb,True)
    23212336                if len(rb['rbTypes']) < 3: return # must have at least 3 atoms
     
    23482363                rbXYZ = np.array(rbXYZ)
    23492364                rbid = ran.randint(0,sys.maxsize)
     2365                namelist = [data['Residue'][key]['RBname'] for key in
     2366                        data['Residue'] if 'RBname' in data['Residue'][key]]
     2367                name = G2obj.MakeUniqueLabel(name,namelist)
    23502368                data['Residue'][rbid] = {'RBname':name,'rbXYZ':rbXYZ,
    23512369                    'rbTypes':rbTypes,'atNames':atNames,'rbRef':[0,1,2,False],
     
    23792397            rd.Phase['RBindex'] = list(range(len(rd.Phase['RBtypes'])))
    23802398            rd.Phase['RBselection'] = len(rd.Phase['RBtypes']) * [1]
     2399            name = 'UNKRB'
     2400            namelist = [data['Vector'][key]['RBname'] for key in
     2401                        data['Vector'] if 'RBname' in data['Vector'][key]]
     2402            name = G2obj.MakeUniqueLabel(name,namelist)
    23812403            rbData = MakeVectorBody()
    23822404            DrawCallback = G2plt.PlotRigidBody(G2frame,'Vector',
     
    27052727        vecs = [np.array(vecs[i]) for i in range(ntrans)]
    27062728        rbid = ran.randint(0,sys.maxsize)
     2729        namelist = [data['Vector'][key]['RBname'] for key in data['Vector']
     2730                        if 'RBname' in data['Vector'][key]]
     2731        name = G2obj.MakeUniqueLabel(name,namelist)
    27072732        data['Vector'][rbid] = {'RBname':name,'VectMag':vecMag,
    27082733                'rbXYZ':np.zeros((natoms,3)),
     
    27522777                        iMove = [int(macStr[i])-1 for i in range(3,nMove+3)]
    27532778                        rbSeq.append([iBeg,iFin,angle,iMove])
     2779                namelist = [data['Residue'][key]['RBname'] for key in
     2780                           data['Residue'] if 'RBname' in data['Residue'][key]]
     2781                rbName = G2obj.MakeUniqueLabel(rbName,namelist)
    27542782                data['Residue'][resRBsel] = {'RBname':rbName,'rbXYZ':rbXYZ,'rbTypes':rbTypes,
    27552783                    'atNames':atNames,'rbRef':[nOrig-1,mRef-1,nRef-1,True],'rbSeq':rbSeq,
     
    28272855            Mat = G2mth.getRBTransMat(X,Y)
    28282856            rbXYZ = np.inner(Mat,rbXYZ).T
    2829             data['Residue'][resRBsel] = {'RBname':'UNKRB','rbXYZ':rbXYZ,'rbTypes':rbTypes,
     2857            name = 'UNKRB'
     2858            namelist = [data['Residue'][key]['RBname'] for key in data['Residue']
     2859                        if 'RBname' in data['Residue'][key]]
     2860            name = G2obj.MakeUniqueLabel(name,namelist)
     2861            data['Residue'][resRBsel] = {'RBname':name,'rbXYZ':rbXYZ,'rbTypes':rbTypes,
    28302862                'atNames':atNames,'rbRef':[0,1,2,False],'rbSeq':[],'SelSeq':[0,0],'useCount':0}
    28312863            data['RBIds']['Residue'].append(resRBsel)
     
    29212953
    29222954    def UpdateVectorRB(Scroll=0):
    2923         AtInfo = data['Vector']['AtInfo']
    2924         refChoice = {}
    2925         if 'DELETED' in str(G2frame.GetStatusBar()):   #seems to be no other way to do this (wx bug)
    2926             if GSASIIpath.GetConfigValue('debug'):
    2927                 print ('DBG_wx error: Rigid Body/Status not cleanly deleted after Refine')
    2928             return
    2929         SetStatusLine(' You may use e.g. "c60" or "s60" for a vector entry')
     2955        '''Display & edit a selected Vector RB
     2956        '''
    29302957        def rbNameSizer(rbid,rbData):
    29312958
     
    29332960                event.Skip()
    29342961                Obj = event.GetEventObject()
    2935                 rbData['RBname'] = Obj.GetValue()
     2962                name = Obj.GetValue()
     2963                namelist = [data['Vector'][key]['RBname'] for key in
     2964                        data['Vector'] if 'RBname' in data['Vector'][key]]
     2965                name = G2obj.MakeUniqueLabel(name,namelist)
     2966                rbData['RBname'] = name
    29362967               
    29372968            def OnDelRB(event):
     
    29522983            RBname = wx.TextCtrl(VectorRBDisplay,-1,rbData['RBname'])
    29532984            Indx[RBname.GetId()] = rbid
     2985            RBname.Bind(wx.EVT_LEAVE_WINDOW, OnRBName)
    29542986            RBname.Bind(wx.EVT_TEXT_ENTER,OnRBName)
    29552987            RBname.Bind(wx.EVT_KILL_FOCUS,OnRBName)
     
    31053137            rbRef = rbData.get('rbRef',[-1,-1,-1,False])
    31063138            for i in range(3):
    3107                 choiceIds.remove(rbRef[i])
     3139                if rbRef[i] in choiceIds: choiceIds.remove(rbRef[i])
    31083140            refChoice[rbid] = [choiceIds[:],choiceIds[:],choiceIds[:]]
    31093141            for i in range(3):
    31103142                refChoice[rbid][i].append(rbRef[i])
    3111                 refChoice[rbid][i].sort()     
    3112            
     3143                refChoice[rbid][i].sort()
     3144               
     3145        # beginning of UpdateVectorRB
     3146        AtInfo = data['Vector']['AtInfo']
     3147        refChoice = {}
     3148        if 'DELETED' in str(G2frame.GetStatusBar()):   #seems to be no other way to do this (wx bug)
     3149            if GSASIIpath.GetConfigValue('debug'):
     3150                print ('DBG_wx error: Rigid Body/Status not cleanly deleted after Refine')
     3151            return
     3152        SetStatusLine(' You may use e.g. "c60" or "s60" for a vector entry')
    31133153        if VectorRB.GetSizer(): VectorRB.GetSizer().Clear(True)
    31143154        VectorRBSizer = wx.BoxSizer(wx.VERTICAL)
    31153155        first = True
    31163156        for rbid in data['RBIds']['Vector']:
    3117             if rbid != 'AtInfo':
    3118                 rbData = data['Vector'][rbid]
    3119                 FillRefChoice(rbid,rbData)
    3120                 if not first:
    3121                     G2G.HorizontalLine(VectorRBSizer,VectorRBDisplay)
    3122                 VectorRBSizer.Add(rbNameSizer(rbid,rbData),0)
    3123                 VectorRBSizer.Add(rbRefAtmSizer(rbid,rbData),0)
    3124                 XYZ = np.array([[0.,0.,0.] for Ty in rbData['rbTypes']])
    3125                 for imag,mag in enumerate(rbData['VectMag']):
    3126                     XYZ += mag*rbData['rbVect'][imag]
    3127                     VectorRBSizer.Add(rbVectMag(rbid,imag,rbData),0)
    3128                     VectorRBSizer.Add(rbVectors(rbid,imag,mag,XYZ,rbData),0)
    3129                 VectorRBSizer.Add((5,5),0)
    3130                 data['Vector'][rbid]['rbXYZ'] = XYZ       
    3131                 first = False
     3157            if rbid == 'AtInfo': continue
     3158            rbData = data['Vector'][rbid]
     3159            FillRefChoice(rbid,rbData)
     3160            if not first:
     3161                G2G.HorizontalLine(VectorRBSizer,VectorRBDisplay)
     3162            VectorRBSizer.Add(rbNameSizer(rbid,rbData),0)
     3163            VectorRBSizer.Add(rbRefAtmSizer(rbid,rbData),0)
     3164            XYZ = np.array([[0.,0.,0.] for Ty in rbData['rbTypes']])
     3165            for imag,mag in enumerate(rbData['VectMag']):
     3166                XYZ += mag*rbData['rbVect'][imag]
     3167                VectorRBSizer.Add(rbVectMag(rbid,imag,rbData),0)
     3168                VectorRBSizer.Add(rbVectors(rbid,imag,mag,XYZ,rbData),0)
     3169            VectorRBSizer.Add((5,5),0)
     3170            data['Vector'][rbid]['rbXYZ'] = XYZ       
     3171            first = False
    31323172        VectorRBSizer.Layout()   
    31333173        VectorRBDisplay.SetSizer(VectorRBSizer,True)
     
    31443184        global resRBsel
    31453185        def rbNameSizer(rbid,rbData):
    3146 
     3186            def OnRBName(event):
     3187                event.Skip()
     3188                Obj = event.GetEventObject()
     3189                name = Obj.GetValue()
     3190                if name == rbData['RBname']: return # no change
     3191                namelist = [data['Residue'][key]['RBname'] for key in
     3192                        data['Residue'] if 'RBname' in data['Residue'][key]]
     3193                name = G2obj.MakeUniqueLabel(name,namelist)
     3194                rbData['RBname'] = name
     3195                wx.CallAfter(UpdateResidueRB)
     3196               
    31473197            def OnDelRB(event):
    31483198                Obj = event.GetEventObject()
     
    31703220                G2plt.PlotRigidBody(G2frame,'Residue',AtInfo,rbData,plotDefaults)
    31713221                wx.CallAfter(UpdateResidueRB)
    3172                    
     3222
    31733223            def OnPlotRB(event):
    31743224                Obj = event.GetEventObject()
     
    31793229            nameSizer.Add(wx.StaticText(ResidueRBDisplay,-1,'Residue name: '),
    31803230                0,wx.ALIGN_CENTER_VERTICAL)
    3181             nameSizer.Add(G2G.ValidatedTxtCtrl(ResidueRBDisplay,rbData,'RBname'),0,WACV)
     3231            RBname = wx.TextCtrl(ResidueRBDisplay,-1,rbData['RBname'])
     3232            RBname.Bind(wx.EVT_LEAVE_WINDOW, OnRBName)
     3233            RBname.Bind(wx.EVT_TEXT_ENTER,OnRBName)
     3234            RBname.Bind(wx.EVT_KILL_FOCUS,OnRBName)
     3235            nameSizer.Add(RBname,0,wx.ALIGN_CENTER_VERTICAL)
    31823236            nameSizer.Add((5,0),)
    31833237            plotRB =  wx.Button(ResidueRBDisplay,wx.ID_ANY,'Plot',style=wx.BU_EXACTFIT)
     
    34173471                refChoice[rbid][i].sort()
    34183472               
    3419         def OnSelect(event):
     3473        def OnRBSelect(event):
    34203474            global resRBsel
    3421             sel = select.GetSelection()
     3475            sel = rbSelect.GetSelection()
    34223476            if sel == 0: return # 1st entry is blank
    34233477            rbname = rbchoice[sel-1]
     
    34433497            return
    34443498        rbchoice = list(RBnames.keys())
     3499        rbchoice.sort()
    34453500        if GS:
    34463501            ResidueRBSizer = GS
    34473502        else:
    34483503            ResidueRBSizer = wx.BoxSizer(wx.VERTICAL)
     3504        if resRBsel not in data['RBIds']['Residue']:
     3505            resRBsel = RBnames[rbchoice[0]]
    34493506        if len(RBnames) > 1:
    34503507            selSizer = wx.BoxSizer(wx.HORIZONTAL)
    34513508            selSizer.Add(wx.StaticText(ResidueRBDisplay,
    34523509                                label=' Select residue to view:'),0)
    3453             rbchoice.sort()
    3454             select = wx.ComboBox(ResidueRBDisplay,choices=['']+rbchoice)
    3455             select.Bind(wx.EVT_COMBOBOX,OnSelect)
    3456             selSizer.Add(select,0)
     3510            rbSelect = wx.ComboBox(ResidueRBDisplay,choices=['']+rbchoice)
     3511            name = data['Residue'][resRBsel]['RBname']
     3512            rbSelect.SetSelection(1+rbchoice.index(name))
     3513            rbSelect.Bind(wx.EVT_COMBOBOX,OnRBSelect)
     3514            selSizer.Add(rbSelect,0)
    34573515            ResidueRBSizer.Add(selSizer,0)
    3458         if resRBsel not in data['RBIds']['Residue']:
    3459             resRBsel = RBnames[rbchoice[0]]
    34603516        rbData = data['Residue'][resRBsel]
    34613517        FillRefChoice(resRBsel,rbData)
Note: See TracChangeset for help on using the changeset viewer.