Changeset 4473
- Timestamp:
- Jun 8, 2020 10:24:17 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIctrlGUI.py
r4431 r4473 4125 4125 if self.IsCellEditControlEnabled(): # complete any grid edits in progress 4126 4126 self.SaveEditControlValue() 4127 #self.HideCellEditControl()4128 #self.DisableCellEditControl()4127 self.HideCellEditControl() 4128 self.DisableCellEditControl() 4129 4129 4130 4130 ################################################################################ -
trunk/GSASIIphsGUI.py
r4471 r4473 9849 9849 ''' 9850 9850 9851 def assignAtoms(selDict={} ):9851 def assignAtoms(selDict={},unmatchedRBatoms=None): 9852 9852 '''Find the closest RB atoms to atoms in the structure 9853 9853 If selDict is specified, it overrides the assignments to specify … … 9866 9866 newXYZ = G2mth.UpdateRBXYZ(Bmat,rbObj,RBData,rbType)[0] 9867 9867 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 []9875 9868 # remove assigned atoms from search groups 9876 9869 for i in selDict: … … 9887 9880 # create table of fixed and found assignments 9888 9881 matchTable = [] 9882 unmatched = [] 9889 9883 for i,xyz in enumerate(newXYZ): 9890 9884 t = rbAtmTypes[i] … … 9897 9891 numLookup = [selDict[i]] 9898 9892 else: 9893 if t not in oXYZbyT: 9894 unmatched.append(i) 9895 continue 9899 9896 searchXYZ = oXYZbyT[t] 9900 9897 numLookup = atmNumByT[t] … … 9910 9907 dist[pidIndx] = 100. 9911 9908 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 9915 9912 Ids.append(atomData[pid][-1]) 9916 9913 matchTable.append([t , lbl] + list(xyz) + [pid, atomData[pid][0]] 9917 9914 + atomData[pid][cx:cx+3] + [d, Ids[-1]]) 9915 if unmatched: 9916 if unmatchedRBatoms is not None: 9917 unmatchedRBatoms[:] = unmatched 9918 return [] 9918 9919 return matchTable 9919 9920 … … 9982 9983 update displayed table 9983 9984 ''' 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 9984 9996 selDict = getSelectedAtoms() 9985 9997 matchTable = assignAtoms(selDict) … … 9987 9999 RigidBodies.atomsTable.data[i][1:4] = l[5],l[6],l[10] 9988 10000 RigidBodies.atomsGrid.ForceRefresh() 10001 if added: wx.CallLater(100,Draw) 9989 10002 return matchTable 9990 10003 … … 10004 10017 for r in range(tbl.GetRowsCount()): 10005 10018 sel = tbl.GetValue(r,4).strip() 10019 if r in rbAssignments: continue # ignore positions of new atoms 10006 10020 if sel not in labelsChoices: continue 10007 10021 atmNum = labelsChoices.index(sel)-1 … … 10059 10073 selDict = getSelectedAtoms() 10060 10074 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)', 10062 10076 style=wx.ICON_EXCLAMATION) 10063 10077 return … … 10072 10086 selDict = getSelectedAtoms() 10073 10087 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', 10075 10089 style=wx.ICON_EXCLAMATION) 10076 10090 return … … 10093 10107 selDict = getSelectedAtoms() 10094 10108 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', 10096 10110 style=wx.ICON_EXCLAMATION) 10097 10111 return … … 10106 10120 UpdateTablePlot() 10107 10121 10122 # Start of Draw() 10108 10123 if not data['testRBObj']: return 10109 # if len(data['testRBObj']):10110 # G2plt.PlotStructure(G2frame,data,True,UpdateTable)10111 10124 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() 10112 10145 mainSizer = wx.BoxSizer(wx.VERTICAL) 10113 10146 mainSizer.Add((5,5),0) … … 10184 10217 else: 10185 10218 mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'No side chain torsions'),0,WACV) 10186 matchTable = assignAtoms()10187 10219 if not matchTable: 10188 10220 OkBtn = None … … 10214 10246 colLabels = ['RB\ntype','phase\n#','phase\nlabel','delta, A','Assign as atom'] 10215 10247 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]) 10217 10253 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] 10219 10256 RigidBodies.atomsTable = G2G.Table(displayTable,rowLabels=rowLabels,colLabels=colLabels,types=Types) 10220 10257 RigidBodies.atomsGrid = G2G.GSGrid(RigidBodies) 10221 10258 10222 10259 labelsChoices = [' '] + [a[0] for a in data['Atoms']] 10223 choiceeditor = wg.GridCellChoiceEditor(labelsChoices, False) 10260 choiceeditor = wg.GridCellChoiceEditor( 10261 labelsChoices+['Create new'], False) 10224 10262 RigidBodies.atomsGrid.SetTable(RigidBodies.atomsTable,True) 10225 10263 # make all grid entries read only … … 10246 10284 btnSizer.Add((-1,20)) 10247 10285 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)...'), 10249 10287 0,wx.ALL) 10250 10288 btnSizer.Add((-1,10)) … … 10274 10312 RigidBodies.Scroll(0,0) 10275 10313 10314 # start of OnRBAssign(event) 10315 rbAssignments = {} 10276 10316 G2frame.GetStatusBar().SetStatusText('',1) 10277 10317 RBData = G2frame.GPXtree.GetItemPyData(
Note: See TracChangeset
for help on using the changeset viewer.