Changeset 4503


Ignore:
Timestamp:
Jun 20, 2020 7:39:59 PM (3 years ago)
Author:
toby
Message:

fix problems wit multiple instances of a single RB and with adding atoms via a RB; do not allow an atom to be used in 2 RBs; after SaveAs? put name into recents; fix editing in Residue RB table

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r4492 r4503  
    31633163                            if El not in AtInfo:
    31643164                                Info = G2elem.GetAtomInfo(El)
    3165                                 AtInfo[El] = [Info['Drad']['Color']]
     3165                                AtInfo[El] = [Info['Drad'],Info['Color']]
    31663166                            rbData['rbTypes'][r] = El
    31673167                            resGrid.SetCellValue(r,c,El)
     
    31773177                        pass
    31783178                       
    3179             def RowSelect(event):
    3180                 r,c =  event.GetRow(),event.GetCol()
    3181                 if c < 0:                   #only row clicks
    3182                     for iGrid in resList:
    3183                         iGrid.ClearSelection()
    3184                     resGrid.SelectRow(r,True)
    3185 
    31863179            def OnRefSel(event):
    31873180                Obj = event.GetEventObject()
     
    32333226                resGrid.Bind(wg.EVT_GRID_CELL_CHANGE, ChangeCell)
    32343227            resGrid.Bind(wg.EVT_GRID_CELL_LEFT_DCLICK, TypeSelect)
    3235             resGrid.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK, RowSelect)
    3236             attr = wx.grid.GridCellAttr()
    3237             attr.IncRef()
    3238             attr.SetEditor(G2G.GridFractionEditor(resGrid))
    3239             for c in range(3):
     3228            for c in range(2,5):
     3229                attr = wx.grid.GridCellAttr()
    32403230                attr.IncRef()
     3231                attr.SetEditor(G2G.GridFractionEditor(resGrid))
    32413232                resGrid.SetColAttr(c, attr)
    32423233            for row in range(vecTable.GetNumberRows()):
    3243                 for col in range(5):
    3244                     resGrid.SetCellStyle(row,col,VERY_LIGHT_GREY,True)
     3234                resGrid.SetReadOnly(row,1,True)
    32453235            resGrid.AutoSizeColumns(False)
    32463236            vecSizer = wx.BoxSizer()
  • trunk/GSASIIdataGUI.py

    r4492 r4503  
    43384338                self.SetTitleByGPX()
    43394339                os.chdir(dlg.GetDirectory())           # to get Mac/Linux to change directory!
     4340                config = G2G.GetConfigValsDocs()
     4341                GSASIIpath.addPrevGPX(self.GSASprojectfile,config)
    43404342                return True
    43414343            else:
  • trunk/GSASIIphsGUI.py

    r4502 r4503  
    14021402                    atomData[i][-1] = Faces
    14031403                       
    1404 def VoidMap(data,aMax=1,bMax=1,cMax=1,gridspacing=.25,probeRadius=.5):
     1404def VoidMap(data,aMax=1,bMax=1,cMax=1,gridspacing=.25,probeRadius=.5,
     1405                aMin=0,bMin=0,cMin=0):
    14051406    '''Compute points where there are no atoms within probeRadius A.
    14061407    All atoms in the Atoms list are considered, provided their
     
    14171418       Defaults to 1.
    14181419    :param float ,probeRadius=.5:
    1419    
     1420    :param float aMin: Minimum along the *a* direction (fractional units).
     1421       Defaults to 0.
     1422    :param float bMin: Minimum along the *b* direction (fractional units).
     1423       Defaults to 0.
     1424    :param float cMin: Minimum along the *c* direction (fractional units).
     1425       Defaults to 0.
     1426    :
    14201427    '''
    14211428
     
    14271434
    14281435    xx,yy,zz = np.meshgrid(
    1429         np.linspace(0,aMax,int(0.5+cell[0]*aMax/gridspacing),endpoint=False),
    1430         np.linspace(0,cMax,int(0.5+cell[1]*bMax/gridspacing),endpoint=False),
    1431         np.linspace(0,cMax,int(0.5+cell[2]*cMax/gridspacing),endpoint=False))
     1436        np.linspace(aMin,aMax,int(0.5+cell[0]*(aMax-aMin)/gridspacing),endpoint=False),
     1437        np.linspace(bMin,bMax,int(0.5+cell[1]*(bMax-bMin)/gridspacing),endpoint=False),
     1438        np.linspace(cMin,cMax,int(0.5+cell[2]*(cMax-cMin)/gridspacing),endpoint=False))
    14321439    coordGrd = np.array([xyz for xyz in zip(xx.ravel(),yy.ravel(),zz.ravel())])
    14331440
     
    99849991            RBnames = []
    99859992            for RBObj in data['RBModels']['Residue']:
    9986                 RBnames.append(RBObj['RBname'].split(':')[0]+RBObj['numChain'])
     9993#                RBnames.append(RBObj['RBname'].split(':')[0]+RBObj['numChain'])
     9994                RBnames.append(RBObj['RBname']+RBObj['numChain'])
    99879995            rbName = RBnames[0]
    99889996            rbObj = data['RBModels']['Residue'][0]
     
    1004710055            atoms that should be matched.
    1004810056            '''
     10057            UsedIds = []
     10058            for i in data['RBModels']:
     10059                for j in data['RBModels'][i]:
     10060                    UsedIds += j['Ids']
    1004910061            rbType = data['testRBObj']['rbType']
    1005010062            rbObj = data['testRBObj']['rbObj']
     
    1005810070               
    1005910071            newXYZ = G2mth.UpdateRBXYZ(Bmat,rbObj,RBData,rbType)[0]
    10060             atmTypes = [atomData[i][ct] for i in range(len(atomData))]
     10072            # categorize atoms by type, omitting any that are already assigned
     10073            # in a rigid body
     10074            atmTypes = [None if atomData[i][-1] in UsedIds
     10075                            else atomData[i][ct]
     10076                            for i in range(len(atomData))]
    1006110077            # remove assigned atoms from search groups
    1006210078            for i in selDict:
     10079                if selDict[i] is None: continue
    1006310080                atmTypes[selDict[i]] = None
    1006410081            atmXYZ = G2mth.getAtomXYZ(atomData,cx)
     
    1008010097                else:
    1008110098                    lbl = ''
    10082                 if i in selDict:
     10099                if i in selDict and selDict[i] is None:
     10100                    matchTable.append([t , lbl] + list(xyz))
     10101                    continue
     10102                elif i in selDict:
    1008310103                    searchXYZ = [atmXYZ[selDict[i]]] #assigned
    1008410104                    numLookup = [selDict[i]]
     
    1008610106                    if t not in oXYZbyT:
    1008710107                        unmatched.append(i)
     10108                        matchTable.append([t , lbl] + list(xyz))
    1008810109                        continue
    1008910110                    searchXYZ = oXYZbyT[t]
    1009010111                    numLookup = atmNumByT[t]
    1009110112                dist = G2mth.GetXYZDist(xyz,searchXYZ,Amat)
    10092                 repeat = True
    10093                 while repeat:
    10094                     repeat = False
     10113                while True:
    1009510114                    pidIndx = np.argmin(dist)
    1009610115                    d = dist[pidIndx]
    1009710116                    pid = numLookup[pidIndx]
    1009810117                    if atomData[pid][-1] in Ids:   #duplicate - 2 atoms on same site; invalidate & look again
    10099                         repeat = True
    1010010118                        dist[pidIndx] = 100.
    1010110119                        if min(dist) == 100:
    10102                             unmatched.append(i)
    10103                             repeat = False
    10104                             continue
    10105                 Ids.append(atomData[pid][-1])
    10106                 matchTable.append([t , lbl] + list(xyz) + [pid, atomData[pid][0]]
     10120                            pid = None
     10121                            break
     10122                    else:
     10123                        break
     10124                if pid is not None:
     10125                    Ids.append(atomData[pid][-1])
     10126                    matchTable.append([t , lbl] + list(xyz) + [pid, atomData[pid][0]]
    1010710127                                      + atomData[pid][cx:cx+3] + [d, Ids[-1]])
    10108             if unmatched:
    10109                 if unmatchedRBatoms is not None:
    10110                     unmatchedRBatoms[:] = unmatched
    10111                 return []
     10128                else:
     10129                    unmatched.append(i)
     10130                    matchTable.append([t , lbl] + list(xyz))
     10131            if unmatched and unmatchedRBatoms is not None:
     10132                unmatchedRBatoms[:] = unmatched
    1011210133            return matchTable
    1011310134           
    1011410135        def Draw():
    1011510136            '''Create the window for assigning RB to atoms'''
    10116             def OnOk(event):
     10137            def OnAddRB(event):
    1011710138                'respond to OK button, set info into phase'
     10139                cx,ct,cs,cia = data['General']['AtomPtrs'] 
    1011810140                matchTable = UpdateTable()
    1011910141                dmax = 0.
    10120                 Ids = []
    1012110142                for line in matchTable:
    10122                     xyz = line[2:5]
    10123                     pid = line[5]
    10124                     dmax = max(dmax,line[10])
    10125                     atomData[pid][cx:cx+3] = xyz
    10126                     Ids.append(line[11])
     10143                    if len(line) >= 11:
     10144                        dmax = max(dmax,line[10])
    1012710145                if dmax > 1.0:
    1012810146                    msg = "Atoms may not be properly located. Are you sure you want to do this?"
     
    1013210150                        return
    1013310151                    dlg.Destroy()
     10152                Ids = []
     10153                for line in matchTable:
     10154                    if len(line) < 11:
     10155                        elem = line[0]
     10156                        nextNum = len(data['Atoms'])
     10157                        lbl = 'Rb' + elem + str(nextNum)
     10158                        x,y,z = line[2:5]
     10159                        AtomAdd(x,y,z,El=elem,Name=lbl)
     10160                        Ids.append(atomData[nextNum][-1])
     10161                    else:
     10162                        atomData[line[5]][cx:cx+3] = line[2:5]
     10163                        Ids.append(line[11])
    1013410164                   
    1013510165                rbType = data['testRBObj']['rbType']
     
    1017910209                # add new atoms and reassign
    1018010210                added = False
     10211                selDict = getSelectedAtoms()
    1018110212                for i,l in enumerate(RigidBodies.atomsTable.data):
    1018210213                    if l[4] == 'Create new':
    10183                         elem = l[0]
    10184                         added = True
    10185                         lbl = 'Rb' + RigidBodies.atomsGrid.GetRowLabelValue(i)
    10186                         AtomAdd(0.,0.,0.,El=elem,Name=lbl)
    10187                         l[4] = lbl
    10188                         rbAssignments[i] = lbl
    10189                 selDict = getSelectedAtoms()
     10214                        rbAssignments[i] = None
     10215                        selDict[i] = None
    1019010216                matchTable = assignAtoms(selDict)
    1019110217                for i,l in enumerate(matchTable):
     10218                    if len(l) < 11: continue
    1019210219                    RigidBodies.atomsTable.data[i][1:4] = l[5],l[6],l[10]
    1019310220                RigidBodies.atomsGrid.ForceRefresh()
     
    1021010237                for r in range(tbl.GetRowsCount()):
    1021110238                    sel = tbl.GetValue(r,4).strip()
    10212                     if r in rbAssignments: continue # ignore positions of new atoms
     10239                    if sel == 'Create new': continue # ignore positions of new atoms
    1021310240                    if sel not in labelsChoices: continue
    1021410241                    atmNum = labelsChoices.index(sel)-1
     
    1023910266                deltaList = []
    1024010267                for i in selDict:
     10268                    if selDict[i] is None: continue
    1024110269                    deltaList.append(phaseXYZ[selDict[i]]-rbXYZ[i])
    1024210270                return np.array(deltaList)
     
    1028810316                    item.SetLabel('%10.4f'%(data['testRBObj']['rbObj']['Orient'][0][i]))
    1028910317                UpdateTablePlot()
    10290                 # debug code
    10291                 #selDict = getSelectedAtoms()
    10292                 #for line in assignAtoms(selDict): print(line)
    1029310318               
    1029410319            def onFitBoth(event):
     
    1031810343            unmatchedRBatoms = []
    1031910344            matchTable = assignAtoms(unmatchedRBatoms=unmatchedRBatoms)
    10320             if not matchTable:
    10321                 dlg = wx.MessageDialog(G2frame,
    10322                     'There are {} atoms that need to be added to atoms list. Do you want to add them?'.format(len(unmatchedRBatoms)),'Add atoms?',
    10323                     wx.YES_NO | wx.ICON_QUESTION)
    10324                 try:
    10325                     result = dlg.ShowModal()
    10326                     if result == wx.ID_YES:
    10327                         rbType = data['testRBObj']['rbType']
    10328                         rbObj = data['testRBObj']['rbObj']
    10329                         rbId = rbObj['RBId']
    10330                         for i in unmatchedRBatoms:
    10331                             elem = RBData[rbType][rbId]['rbTypes'][i]
    10332                             lbl = 'Rb' + RBData[rbType][rbId]['atNames'][i]
    10333                             AtomAdd(0.,0.,0.,El=elem,Name=lbl)
    10334                             rbAssignments[i] = lbl
    10335                         wx.CallAfter(Draw)
    10336                 finally:
    10337                     dlg.Destroy()
     10345            if unmatchedRBatoms:
     10346                msg = 'There are {} atoms that will need to be added to atoms list.'.format(len(unmatchedRBatoms))
     10347                G2G.G2MessageBox(G2frame,msg,title='Please note')
     10348                for i in unmatchedRBatoms:
     10349                    rbAssignments[i] = None
     10350
    1033810351            mainSizer = wx.BoxSizer(wx.VERTICAL)
    1033910352            mainSizer.Add((5,5),0)
     
    1034910362                refName.append(data['testRBObj']['rbAtTypes'][ref]+str(ref))
    1035010363            atNames = data['testRBObj']['atNames']
    10351             mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'Locate rigid body : '+rbName),
    10352                 0,WACV)
     10364            mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,
     10365                                'Locating rigid body : '+rbName), 0, WACV)
    1035310366            mainSizer.Add((5,5),0)
    1035410367            OriSizer = wx.BoxSizer(wx.HORIZONTAL)
     
    1041010423            else:
    1041110424                mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'No side chain torsions'),0,WACV)
    10412             if not matchTable:
     10425            if not matchTable: # not sure if this will ever be true
    1041310426                OkBtn = None
    1041410427                mainSizer.Add((15,15))
     
    1041810431            else:
    1041910432                OkBtn = wx.Button(RigidBodies,wx.ID_ANY,"Add")
    10420                 OkBtn.Bind(wx.EVT_BUTTON, OnOk)
     10433                OkBtn.Bind(wx.EVT_BUTTON, OnAddRB)
    1042110434            CancelBtn = wx.Button(RigidBodies,wx.ID_ANY,'Cancel')
    1042210435            CancelBtn.Bind(wx.EVT_BUTTON, OnCancel)
     
    1042910442               
    1043010443            SetPhaseWindow(RigidBodies,mainSizer)
    10431            
    10432             if not matchTable:
    10433                 mainSizer.Layout()
    10434                 RigidBodies.SetScrollRate(10,10)
    10435                 RigidBodies.SendSizeEvent()
    10436                 RigidBodies.Scroll(0,0)
    10437                 return
     10444
    1043810445            G2plt.PlotStructure(G2frame,data,True,UpdateTable)
    1043910446            colLabels = ['RB\ntype','phase\n#','phase\nlabel','delta, A','Assign as atom']
     
    1044210449            for i,l in enumerate(matchTable):
    1044310450                lbl = ''
    10444                 if i in rbAssignments: lbl = rbAssignments[i]
    10445                 displayTable.append([l[0],l[5],l[6],l[10],lbl])
     10451                if i in rbAssignments:
     10452                    if rbAssignments[i] is None:
     10453                        displayTable.append([l[0],-1,'?',-1,'Create new'])
     10454                    else:
     10455                        lbl = rbAssignments[i]
     10456                        displayTable.append([l[0],l[5],l[6],l[10],lbl]) # TODO: think about this
     10457                else:
     10458                    displayTable.append([l[0],l[5],l[6],l[10],lbl])
    1044610459            Types = [wg.GRID_VALUE_STRING, wg.GRID_VALUE_NUMBER,
    1044710460                    wg.GRID_VALUE_STRING, wg.GRID_VALUE_FLOAT+':8,3',
     
    1048610499
    1048710500            btn = wx.Button(RigidBodies, wx.ID_ANY, 'Set Origin')
    10488 
    1048910501            btn.Bind(wx.EVT_BUTTON,onSetOrigin)
    1049010502            btnSizer.Add(btn,0,wx.ALIGN_CENTER)
    1049110503            btnSizer.Add((-1,5))
    1049210504            btn = wx.Button(RigidBodies, wx.ID_ANY, 'Set Orientation')
    10493 
    1049410505            btn.Bind(wx.EVT_BUTTON,onFitOrientation)
    1049510506            btnSizer.Add(btn,0,wx.ALIGN_CENTER)
Note: See TracChangeset for help on using the changeset viewer.