Changeset 4473


Ignore:
Timestamp:
Jun 8, 2020 10:24:17 PM (3 years ago)
Author:
toby
Message:

allow adding of rigid body atoms to atoms list

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrlGUI.py

    r4431 r4473  
    41254125        if self.IsCellEditControlEnabled(): # complete any grid edits in progress
    41264126            self.SaveEditControlValue()
    4127             #self.HideCellEditControl()
    4128             #self.DisableCellEditControl()
     4127            self.HideCellEditControl()
     4128            self.DisableCellEditControl()
    41294129               
    41304130################################################################################           
  • trunk/GSASIIphsGUI.py

    r4471 r4473  
    98499849        '''
    98509850       
    9851         def assignAtoms(selDict={}):
     9851        def assignAtoms(selDict={},unmatchedRBatoms=None):
    98529852            '''Find the closest RB atoms to atoms in the structure
    98539853            If selDict is specified, it overrides the assignments to specify
     
    98669866            newXYZ = G2mth.UpdateRBXYZ(Bmat,rbObj,RBData,rbType)[0]
    98679867            atmTypes = [atomData[i][ct] for i in range(len(atomData))]
    9868             notfound = []
    9869             for t in rbAtmTypes:
    9870                 if t not in atmTypes and t not in notfound:
    9871                     notfound.append(t)
    9872             if notfound:
    9873                 print('Rigid body atom type(s) not in structure',notfound)
    9874                 return []
    98759868            # remove assigned atoms from search groups
    98769869            for i in selDict:
     
    98879880            # create table of fixed and found assignments
    98889881            matchTable = []
     9882            unmatched = []
    98899883            for i,xyz in enumerate(newXYZ):
    98909884                t = rbAtmTypes[i]
     
    98979891                    numLookup = [selDict[i]]
    98989892                else:
     9893                    if t not in oXYZbyT:
     9894                        unmatched.append(i)
     9895                        continue
    98999896                    searchXYZ = oXYZbyT[t]
    99009897                    numLookup = atmNumByT[t]
     
    99109907                        dist[pidIndx] = 100.
    99119908                        if min(dist) == 100:
    9912                             print('no atom matches, how could this happen?')
    9913                             if GSASIIpath.GetConfigValue('debug'): GSASIIpath.IPyBreak()
    9914                             return []
     9909                            unmatched.append(i)
     9910                            repeat = False
     9911                            continue
    99159912                Ids.append(atomData[pid][-1])
    99169913                matchTable.append([t , lbl] + list(xyz) + [pid, atomData[pid][0]]
    99179914                                      + atomData[pid][cx:cx+3] + [d, Ids[-1]])
     9915            if unmatched:
     9916                if unmatchedRBatoms is not None:
     9917                    unmatchedRBatoms[:] = unmatched
     9918                return []
    99189919            return matchTable
    99199920           
     
    99829983                update displayed table
    99839984                '''
     9985                RigidBodies.atomsGrid.completeEdits()
     9986                # add new atoms and reassign
     9987                added = False
     9988                for i,l in enumerate(RigidBodies.atomsTable.data):
     9989                    if l[4] == 'Create new':
     9990                        elem = l[0]
     9991                        added = True
     9992                        lbl = 'Rb' + RigidBodies.atomsGrid.GetRowLabelValue(i)
     9993                        AtomAdd(0.,0.,0.,El=elem,Name=lbl)
     9994                        l[4] = lbl
     9995                        rbAssignments[i] = lbl
    99849996                selDict = getSelectedAtoms()
    99859997                matchTable = assignAtoms(selDict)
     
    99879999                    RigidBodies.atomsTable.data[i][1:4] = l[5],l[6],l[10]
    998810000                RigidBodies.atomsGrid.ForceRefresh()
     10001                if added: wx.CallLater(100,Draw)
    998910002                return matchTable
    999010003               
     
    1000410017                for r in range(tbl.GetRowsCount()):
    1000510018                    sel = tbl.GetValue(r,4).strip()
     10019                    if r in rbAssignments: continue # ignore positions of new atoms
    1000610020                    if sel not in labelsChoices: continue
    1000710021                    atmNum = labelsChoices.index(sel)-1
     
    1005910073                selDict = getSelectedAtoms()
    1006010074                if len(selDict) < 1:
    10061                     wx.MessageBox('No atoms were selected',caption='Select Atom(s)',
     10075                    wx.MessageBox('No existing atoms were selected',caption='Select Atom(s)',
    1006210076                                      style=wx.ICON_EXCLAMATION)
    1006310077                    return
     
    1007210086                selDict = getSelectedAtoms()
    1007310087                if len(selDict) < 2:
    10074                     wx.MessageBox('At least two atoms must be selected',caption='Select Atoms',
     10088                    wx.MessageBox('At least two existing atoms must be selected',caption='Select Atoms',
    1007510089                                      style=wx.ICON_EXCLAMATION)
    1007610090                    return
     
    1009310107                selDict = getSelectedAtoms()
    1009410108                if len(selDict) < 3:
    10095                     wx.MessageBox('At least three atoms must be selected',caption='Select Atoms',
     10109                    wx.MessageBox('At least three existing atoms must be selected',caption='Select Atoms',
    1009610110                                      style=wx.ICON_EXCLAMATION)
    1009710111                    return
     
    1010610120                UpdateTablePlot()
    1010710121
     10122            # Start of Draw()
    1010810123            if not data['testRBObj']: return
    10109 #            if len(data['testRBObj']):
    10110 #                G2plt.PlotStructure(G2frame,data,True,UpdateTable)
    1011110124            if RigidBodies.GetSizer(): RigidBodies.GetSizer().Clear(True)
     10125            unmatchedRBatoms = []
     10126            matchTable = assignAtoms(unmatchedRBatoms=unmatchedRBatoms)
     10127            if not matchTable:
     10128                dlg = wx.MessageDialog(G2frame,
     10129                    'There are {} atoms that need to be added to atoms list. Do you want to add them?'.format(len(unmatchedRBatoms)),'Add atoms?',
     10130                    wx.YES_NO | wx.ICON_QUESTION)
     10131                try:
     10132                    result = dlg.ShowModal()
     10133                    if result == wx.ID_YES:
     10134                        rbType = data['testRBObj']['rbType']
     10135                        rbObj = data['testRBObj']['rbObj']
     10136                        rbId = rbObj['RBId']
     10137                        for i in unmatchedRBatoms:
     10138                            elem = RBData[rbType][rbId]['rbTypes'][i]
     10139                            lbl = 'Rb' + RBData[rbType][rbId]['atNames'][i]
     10140                            AtomAdd(0.,0.,0.,El=elem,Name=lbl)
     10141                            rbAssignments[i] = lbl
     10142                        wx.CallAfter(Draw)
     10143                finally:
     10144                    dlg.Destroy()
    1011210145            mainSizer = wx.BoxSizer(wx.VERTICAL)
    1011310146            mainSizer.Add((5,5),0)
     
    1018410217            else:
    1018510218                mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'No side chain torsions'),0,WACV)
    10186             matchTable = assignAtoms()
    1018710219            if not matchTable:
    1018810220                OkBtn = None
     
    1021410246            colLabels = ['RB\ntype','phase\n#','phase\nlabel','delta, A','Assign as atom']
    1021510247            rowLabels = [l[1] for l in matchTable]
    10216             displayTable = [[l[0],l[5],l[6],l[10],''] for l in matchTable]
     10248            displayTable = []
     10249            for i,l in enumerate(matchTable):
     10250                lbl = ''
     10251                if i in rbAssignments: lbl = rbAssignments[i]
     10252                displayTable.append([l[0],l[5],l[6],l[10],lbl])
    1021710253            Types = [wg.GRID_VALUE_STRING, wg.GRID_VALUE_NUMBER,
    10218                     wg.GRID_VALUE_STRING, wg.GRID_VALUE_FLOAT+':8,3', wg.GRID_VALUE_STRING]
     10254                    wg.GRID_VALUE_STRING, wg.GRID_VALUE_FLOAT+':8,3',
     10255                    wg.GRID_VALUE_STRING]
    1021910256            RigidBodies.atomsTable = G2G.Table(displayTable,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    1022010257            RigidBodies.atomsGrid = G2G.GSGrid(RigidBodies)
    1022110258
    1022210259            labelsChoices = ['         '] + [a[0] for a in data['Atoms']]
    10223             choiceeditor = wg.GridCellChoiceEditor(labelsChoices, False)
     10260            choiceeditor = wg.GridCellChoiceEditor(
     10261                labelsChoices+['Create new'], False)
    1022410262            RigidBodies.atomsGrid.SetTable(RigidBodies.atomsTable,True)
    1022510263            # make all grid entries read only
     
    1024610284            btnSizer.Add((-1,20))
    1024710285            btnSizer.Add(
    10248                 wx.StaticText(RigidBodies,wx.ID_ANY,'Actions with fixed\natom(s)...'),
     10286                wx.StaticText(RigidBodies,wx.ID_ANY,'Actions with assigned\natom(s)...'),
    1024910287                0,wx.ALL)
    1025010288            btnSizer.Add((-1,10))
     
    1027410312            RigidBodies.Scroll(0,0)
    1027510313
     10314        # start of OnRBAssign(event)
     10315        rbAssignments = {}
    1027610316        G2frame.GetStatusBar().SetStatusText('',1)
    1027710317        RBData = G2frame.GPXtree.GetItemPyData(   
Note: See TracChangeset for help on using the changeset viewer.