Changeset 4605
- Timestamp:
- Oct 17, 2020 8:46:40 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIconstrGUI.py
r4604 r4605 3022 3022 the Cartesian 3023 3023 axes for rigid bodies with three atoms, A, B and C. 3024 The vector from A to B defines the x-axis and the zaxis is placed3024 The vector from A to B defines the x-axis and the y axis is placed 3025 3025 in the plane defined by A to B and A to C. 3026 3026 ''' … … 3389 3389 the Cartesian 3390 3390 axes for rigid bodies with three atoms, A, B and C. 3391 The vector from A to B defines the x-axis and the zaxis is placed3391 The vector from A to B defines the x-axis and the y axis is placed 3392 3392 in the plane defined by A to B and A to C. 3393 3393 -
trunk/GSASIIphsGUI.py
r4602 r4605 3757 3757 G2plt.PlotStructure(G2frame,data) 3758 3758 3759 def AtomAdd(x,y,z,El='H',Name='UNK' ):3759 def AtomAdd(x,y,z,El='H',Name='UNK',update=True): 3760 3760 atomData = data['Atoms'] 3761 3761 generalData = data['General'] … … 3779 3779 3780 3780 SetupGeneral() 3781 # might be better to add new atom to Draw Atoms 3781 3782 data['Drawing']['Atoms'] = [] 3782 UpdateDrawAtoms()3783 G2plt.PlotStructure(G2frame,data)3784 3783 # if 'Atoms' in data['Drawing']: 3785 3784 # DrawAtomAdd(data['Drawing'],atomData[-1]) 3785 if update: 3786 UpdateDrawAtoms() 3787 G2plt.PlotStructure(G2frame,data) 3786 3788 3787 3789 def OnAtomInsert(event): … … 10225 10227 wx.CallAfter(FillRigidBodyGrid,True) 10226 10228 10229 def assignAtoms(RBData,selDict={},unmatchedRBatoms=None): 10230 '''Find the closest RB atoms to atoms in the structure 10231 If selDict is specified, it overrides the assignments to specify 10232 atoms that should be matched. 10233 ''' 10234 general = data['General'] 10235 cx,ct = general['AtomPtrs'][:2] 10236 Amat,Bmat = G2lat.cell2AB(general['Cell'][1:7]) 10237 10238 rbType = data['testRBObj']['rbType'] 10239 rbObj = data['testRBObj']['rbObj'] 10240 rbId = rbObj['RBId'] 10241 rbAtmTypes = RBData[rbType][rbId]['rbTypes'] 10242 atomData = data['Atoms'] 10243 if 'atNames' in RBData[rbType][rbId]: 10244 rbAtmLbs = RBData[rbType][rbId]['atNames'] 10245 else: 10246 rbAtmLbs = None 10247 10248 newXYZ = G2mth.UpdateRBXYZ(Bmat,rbObj,RBData,rbType)[0] 10249 # categorize atoms by type, omitting any that are already assigned 10250 # in a rigid body 10251 atmTypes = [None if atomData[i][-1] in rbUsedIds 10252 else atomData[i][ct] 10253 for i in range(len(atomData))] 10254 # remove assigned atoms from search groups 10255 for i in selDict: 10256 if selDict[i] is None: continue 10257 atmTypes[selDict[i]] = None 10258 atmXYZ = G2mth.getAtomXYZ(atomData,cx) 10259 # separate structure's atoms by type (w/o assigned atoms) 10260 oXYZbyT = {} 10261 atmNumByT = {} 10262 for t in set(atmTypes): 10263 if t is None: continue 10264 oXYZbyT[t] = np.array([atmXYZ[i] for i in range(len(atmXYZ)) if atmTypes[i] == t]) 10265 atmNumByT[t] = [i for i in range(len(atmXYZ)) if atmTypes[i] == t] 10266 Ids = [] 10267 # create table of fixed and found assignments 10268 matchTable = [] 10269 unmatched = [] 10270 for i,xyz in enumerate(newXYZ): 10271 t = rbAtmTypes[i] 10272 if rbAtmLbs: 10273 lbl = rbAtmLbs[i] 10274 else: 10275 lbl = '' 10276 if i in selDict and selDict[i] is None: 10277 matchTable.append([t , lbl] + list(xyz)) 10278 continue 10279 elif i in selDict: 10280 searchXYZ = [atmXYZ[selDict[i]]] #assigned 10281 numLookup = [selDict[i]] 10282 else: 10283 if t not in oXYZbyT: 10284 unmatched.append(i) 10285 matchTable.append([t , lbl] + list(xyz)) 10286 continue 10287 searchXYZ = oXYZbyT[t] 10288 numLookup = atmNumByT[t] 10289 dist = G2mth.GetXYZDist(xyz,searchXYZ,Amat) 10290 while True: 10291 pidIndx = np.argmin(dist) 10292 d = dist[pidIndx] 10293 pid = numLookup[pidIndx] 10294 if atomData[pid][-1] in Ids: #duplicate - 2 atoms on same site; invalidate & look again 10295 dist[pidIndx] = 100. 10296 if min(dist) == 100: 10297 pid = None 10298 break 10299 else: 10300 break 10301 if pid is not None: 10302 Ids.append(atomData[pid][-1]) 10303 matchTable.append([t , lbl] + list(xyz) + [pid, atomData[pid][0]] 10304 + atomData[pid][cx:cx+3] + [d, Ids[-1]]) 10305 else: 10306 unmatched.append(i) 10307 matchTable.append([t , lbl] + list(xyz)) 10308 if unmatched and unmatchedRBatoms is not None: 10309 unmatchedRBatoms[:] = unmatched 10310 return matchTable 10311 10227 10312 def OnRBAssign(event): 10228 10313 '''Assign RB to atoms in a phase with tools to locate the RB in the structure 10229 10314 ''' 10230 10231 def assignAtoms(selDict={},unmatchedRBatoms=None):10232 '''Find the closest RB atoms to atoms in the structure10233 If selDict is specified, it overrides the assignments to specify10234 atoms that should be matched.10235 '''10236 rbType = data['testRBObj']['rbType']10237 rbObj = data['testRBObj']['rbObj']10238 rbId = rbObj['RBId']10239 rbAtmTypes = RBData[rbType][rbId]['rbTypes']10240 atomData = data['Atoms']10241 if 'atNames' in RBData[rbType][rbId]:10242 rbAtmLbs = RBData[rbType][rbId]['atNames']10243 else:10244 rbAtmLbs = None10245 10246 newXYZ = G2mth.UpdateRBXYZ(Bmat,rbObj,RBData,rbType)[0]10247 # categorize atoms by type, omitting any that are already assigned10248 # in a rigid body10249 atmTypes = [None if atomData[i][-1] in rbUsedIds10250 else atomData[i][ct]10251 for i in range(len(atomData))]10252 # remove assigned atoms from search groups10253 for i in selDict:10254 if selDict[i] is None: continue10255 atmTypes[selDict[i]] = None10256 atmXYZ = G2mth.getAtomXYZ(atomData,cx)10257 # separate structure's atoms by type (w/o assigned atoms)10258 oXYZbyT = {}10259 atmNumByT = {}10260 for t in set(atmTypes):10261 if t is None: continue10262 oXYZbyT[t] = np.array([atmXYZ[i] for i in range(len(atmXYZ)) if atmTypes[i] == t])10263 atmNumByT[t] = [i for i in range(len(atmXYZ)) if atmTypes[i] == t]10264 Ids = []10265 # create table of fixed and found assignments10266 matchTable = []10267 unmatched = []10268 for i,xyz in enumerate(newXYZ):10269 t = rbAtmTypes[i]10270 if rbAtmLbs:10271 lbl = rbAtmLbs[i]10272 else:10273 lbl = ''10274 if i in selDict and selDict[i] is None:10275 matchTable.append([t , lbl] + list(xyz))10276 continue10277 elif i in selDict:10278 searchXYZ = [atmXYZ[selDict[i]]] #assigned10279 numLookup = [selDict[i]]10280 else:10281 if t not in oXYZbyT:10282 unmatched.append(i)10283 matchTable.append([t , lbl] + list(xyz))10284 continue10285 searchXYZ = oXYZbyT[t]10286 numLookup = atmNumByT[t]10287 dist = G2mth.GetXYZDist(xyz,searchXYZ,Amat)10288 while True:10289 pidIndx = np.argmin(dist)10290 d = dist[pidIndx]10291 pid = numLookup[pidIndx]10292 if atomData[pid][-1] in Ids: #duplicate - 2 atoms on same site; invalidate & look again10293 dist[pidIndx] = 100.10294 if min(dist) == 100:10295 pid = None10296 break10297 else:10298 break10299 if pid is not None:10300 Ids.append(atomData[pid][-1])10301 matchTable.append([t , lbl] + list(xyz) + [pid, atomData[pid][0]]10302 + atomData[pid][cx:cx+3] + [d, Ids[-1]])10303 else:10304 unmatched.append(i)10305 matchTable.append([t , lbl] + list(xyz))10306 if unmatched and unmatchedRBatoms is not None:10307 unmatchedRBatoms[:] = unmatched10308 return matchTable10309 10315 10310 10316 def Draw(): … … 10315 10321 cx,ct,cs,cia = data['General']['AtomPtrs'] 10316 10322 atomData = data['Atoms'] 10317 matchTable = UpdateTable() 10323 if RigidBodies.atomsGrid: 10324 matchTable = UpdateTable() 10325 else: 10326 matchTable = assignAtoms(RBData) 10318 10327 dmax = 0. 10319 10328 for line in matchTable: … … 10328 10337 dlg.Destroy() 10329 10338 Ids = [] 10339 updateNeeded = False 10330 10340 for line in matchTable: 10331 10341 if len(line) < 11: … … 10334 10344 lbl = 'Rb' + elem + str(nextNum) 10335 10345 x,y,z = line[2:5] 10336 AtomAdd(x,y,z,El=elem,Name=lbl )10346 AtomAdd(x,y,z,El=elem,Name=lbl,update=False) 10337 10347 Ids.append(atomData[nextNum][-1]) 10348 updateNeeded = True 10338 10349 else: 10339 10350 atomData[line[5]][cx:cx+3] = line[2:5] 10340 10351 Ids.append(line[11]) 10352 if updateNeeded: 10353 UpdateDrawAtoms() 10354 G2plt.PlotStructure(G2frame,data) 10341 10355 10342 10356 rbType = data['testRBObj']['rbType'] … … 10391 10405 update displayed table 10392 10406 ''' 10407 if not RigidBodies.atomsGrid: return [] 10393 10408 RigidBodies.atomsGrid.completeEdits() 10394 10409 # add new atoms and reassign … … 10401 10416 rbAssignments[i] = None 10402 10417 selDict[i] = None 10403 matchTable = assignAtoms( selDict)10418 matchTable = assignAtoms(RBData,selDict) 10404 10419 for i,l in enumerate(matchTable): 10405 10420 if len(l) < 11: continue 10406 10421 RigidBodies.atomsTable.data[i][1:4] = l[5],l[6],l[10] 10407 RigidBodies.atomsGrid.ForceRefresh() 10422 if RigidBodies.atomsGrid: 10423 RigidBodies.atomsGrid.ForceRefresh() 10408 10424 if added: wx.CallLater(100,Draw) 10409 10425 return matchTable … … 10447 10463 def getSelectedAtoms(): 10448 10464 'Find the FB atoms that have been assigned to specific atoms in structure' 10465 if not RigidBodies.atomsGrid: return 10449 10466 RigidBodies.atomsGrid.completeEdits() 10450 10467 tbl = RigidBodies.atomsGrid.GetTable() … … 10594 10611 axis = np.array(axis)/nl.norm(axis) 10595 10612 data['testRBObj']['rbObj']['symAxis'] = axis 10596 UpdateTablePlot() 10613 UpdateTablePlot() 10614 10597 10615 showAtom = [None] 10598 10616 def showCryAtom(*args,**kwargs): … … 10608 10626 if RigidBodies.GetSizer(): RigidBodies.GetSizer().Clear(True) 10609 10627 unmatchedRBatoms = [] 10610 matchTable = assignAtoms( unmatchedRBatoms=unmatchedRBatoms)10628 matchTable = assignAtoms(RBData,unmatchedRBatoms=unmatchedRBatoms) 10611 10629 if unmatchedRBatoms: 10612 10630 # msg = 'There are {} atoms that will need to be added to atoms list.'.format(len(unmatchedRBatoms)) … … 10729 10747 else: 10730 10748 mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'No side chain torsions'),0) 10731 if not matchTable: # not sure if this will ever be true 10732 OkBtn = None 10733 mainSizer.Add((15,15)) 10734 mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY, 10735 'Error: unable to match atoms in rigid body to structure (see console window)'),0) 10736 else: 10737 OkBtn = wx.Button(RigidBodies,wx.ID_ANY,"Add") 10738 OkBtn.Bind(wx.EVT_BUTTON, OnAddRB) 10749 OkBtn = wx.Button(RigidBodies,wx.ID_ANY,"Add") 10750 OkBtn.Bind(wx.EVT_BUTTON, OnAddRB) 10739 10751 CancelBtn = wx.Button(RigidBodies,wx.ID_ANY,'Cancel') 10740 10752 CancelBtn.Bind(wx.EVT_BUTTON, OnCancel) … … 10758 10770 mainSizer.Layout() 10759 10771 G2plt.PlotStructure(G2frame,data,True) 10772 RigidBodies.atomsGrid = None 10760 10773 return 10761 10774 … … 12816 12829 ''' 12817 12830 if 'testRBObj' not in data: return 12831 if not RigidBodies.atomsGrid: return 12818 12832 alt = event.GetModifiers() & wx.MOD_ALT 12819 12833 event.Skip() … … 12837 12851 data['testRBObj']['RBhighLight'] = rows[0] 12838 12852 else: 12839 #GSASIIpath.IPyBreak()12840 #return12841 12853 Ind = data['testRBObj'].get('CRYhighLight',[]) 12842 12854 if len(Ind) == 0:
Note: See TracChangeset
for help on using the changeset viewer.