Changeset 4503 for trunk/GSASIIphsGUI.py

Ignore:
Timestamp:
Jun 20, 2020 7:39:59 PM (18 months ago)
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

File:
1 edited

Unmodified
Added
Removed
• trunk/GSASIIphsGUI.py

 r4502 atomData[i][-1] = Faces def VoidMap(data,aMax=1,bMax=1,cMax=1,gridspacing=.25,probeRadius=.5): def VoidMap(data,aMax=1,bMax=1,cMax=1,gridspacing=.25,probeRadius=.5, aMin=0,bMin=0,cMin=0): '''Compute points where there are no atoms within probeRadius A. All atoms in the Atoms list are considered, provided their Defaults to 1. :param float ,probeRadius=.5: :param float aMin: Minimum along the *a* direction (fractional units). Defaults to 0. :param float bMin: Minimum along the *b* direction (fractional units). Defaults to 0. :param float cMin: Minimum along the *c* direction (fractional units). Defaults to 0. : ''' xx,yy,zz = np.meshgrid( np.linspace(0,aMax,int(0.5+cell[0]*aMax/gridspacing),endpoint=False), np.linspace(0,cMax,int(0.5+cell[1]*bMax/gridspacing),endpoint=False), np.linspace(0,cMax,int(0.5+cell[2]*cMax/gridspacing),endpoint=False)) np.linspace(aMin,aMax,int(0.5+cell[0]*(aMax-aMin)/gridspacing),endpoint=False), np.linspace(bMin,bMax,int(0.5+cell[1]*(bMax-bMin)/gridspacing),endpoint=False), np.linspace(cMin,cMax,int(0.5+cell[2]*(cMax-cMin)/gridspacing),endpoint=False)) coordGrd = np.array([xyz for xyz in zip(xx.ravel(),yy.ravel(),zz.ravel())]) RBnames = [] for RBObj in data['RBModels']['Residue']: RBnames.append(RBObj['RBname'].split(':')[0]+RBObj['numChain']) #                RBnames.append(RBObj['RBname'].split(':')[0]+RBObj['numChain']) RBnames.append(RBObj['RBname']+RBObj['numChain']) rbName = RBnames[0] rbObj = data['RBModels']['Residue'][0] atoms that should be matched. ''' UsedIds = [] for i in data['RBModels']: for j in data['RBModels'][i]: UsedIds += j['Ids'] rbType = data['testRBObj']['rbType'] rbObj = data['testRBObj']['rbObj'] newXYZ = G2mth.UpdateRBXYZ(Bmat,rbObj,RBData,rbType)[0] atmTypes = [atomData[i][ct] for i in range(len(atomData))] # categorize atoms by type, omitting any that are already assigned # in a rigid body atmTypes = [None if atomData[i][-1] in UsedIds else atomData[i][ct] for i in range(len(atomData))] # remove assigned atoms from search groups for i in selDict: if selDict[i] is None: continue atmTypes[selDict[i]] = None atmXYZ = G2mth.getAtomXYZ(atomData,cx) else: lbl = '' if i in selDict: if i in selDict and selDict[i] is None: matchTable.append([t , lbl] + list(xyz)) continue elif i in selDict: searchXYZ = [atmXYZ[selDict[i]]] #assigned numLookup = [selDict[i]] if t not in oXYZbyT: unmatched.append(i) matchTable.append([t , lbl] + list(xyz)) continue searchXYZ = oXYZbyT[t] numLookup = atmNumByT[t] dist = G2mth.GetXYZDist(xyz,searchXYZ,Amat) repeat = True while repeat: repeat = False while True: pidIndx = np.argmin(dist) d = dist[pidIndx] pid = numLookup[pidIndx] if atomData[pid][-1] in Ids:   #duplicate - 2 atoms on same site; invalidate & look again repeat = True dist[pidIndx] = 100. if min(dist) == 100: unmatched.append(i) repeat = False continue Ids.append(atomData[pid][-1]) matchTable.append([t , lbl] + list(xyz) + [pid, atomData[pid][0]] pid = None break else: break if pid is not None: Ids.append(atomData[pid][-1]) matchTable.append([t , lbl] + list(xyz) + [pid, atomData[pid][0]] + atomData[pid][cx:cx+3] + [d, Ids[-1]]) if unmatched: if unmatchedRBatoms is not None: unmatchedRBatoms[:] = unmatched return [] else: unmatched.append(i) matchTable.append([t , lbl] + list(xyz)) if unmatched and unmatchedRBatoms is not None: unmatchedRBatoms[:] = unmatched return matchTable def Draw(): '''Create the window for assigning RB to atoms''' def OnOk(event): def OnAddRB(event): 'respond to OK button, set info into phase' cx,ct,cs,cia = data['General']['AtomPtrs'] matchTable = UpdateTable() dmax = 0. Ids = [] for line in matchTable: xyz = line[2:5] pid = line[5] dmax = max(dmax,line[10]) atomData[pid][cx:cx+3] = xyz Ids.append(line[11]) if len(line) >= 11: dmax = max(dmax,line[10]) if dmax > 1.0: msg = "Atoms may not be properly located. Are you sure you want to do this?" return dlg.Destroy() Ids = [] for line in matchTable: if len(line) < 11: elem = line[0] nextNum = len(data['Atoms']) lbl = 'Rb' + elem + str(nextNum) x,y,z = line[2:5] AtomAdd(x,y,z,El=elem,Name=lbl) Ids.append(atomData[nextNum][-1]) else: atomData[line[5]][cx:cx+3] = line[2:5] Ids.append(line[11]) rbType = data['testRBObj']['rbType'] # add new atoms and reassign added = False selDict = getSelectedAtoms() for i,l in enumerate(RigidBodies.atomsTable.data): if l[4] == 'Create new': elem = l[0] added = True lbl = 'Rb' + RigidBodies.atomsGrid.GetRowLabelValue(i) AtomAdd(0.,0.,0.,El=elem,Name=lbl) l[4] = lbl rbAssignments[i] = lbl selDict = getSelectedAtoms() rbAssignments[i] = None selDict[i] = None matchTable = assignAtoms(selDict) for i,l in enumerate(matchTable): if len(l) < 11: continue RigidBodies.atomsTable.data[i][1:4] = l[5],l[6],l[10] RigidBodies.atomsGrid.ForceRefresh() for r in range(tbl.GetRowsCount()): sel = tbl.GetValue(r,4).strip() if r in rbAssignments: continue # ignore positions of new atoms if sel == 'Create new': continue # ignore positions of new atoms if sel not in labelsChoices: continue atmNum = labelsChoices.index(sel)-1 deltaList = [] for i in selDict: if selDict[i] is None: continue deltaList.append(phaseXYZ[selDict[i]]-rbXYZ[i]) return np.array(deltaList) item.SetLabel('%10.4f'%(data['testRBObj']['rbObj']['Orient'][0][i])) UpdateTablePlot() # debug code #selDict = getSelectedAtoms() #for line in assignAtoms(selDict): print(line) def onFitBoth(event): unmatchedRBatoms = [] matchTable = assignAtoms(unmatchedRBatoms=unmatchedRBatoms) if not matchTable: dlg = wx.MessageDialog(G2frame, 'There are {} atoms that need to be added to atoms list. Do you want to add them?'.format(len(unmatchedRBatoms)),'Add atoms?', wx.YES_NO | wx.ICON_QUESTION) try: result = dlg.ShowModal() if result == wx.ID_YES: rbType = data['testRBObj']['rbType'] rbObj = data['testRBObj']['rbObj'] rbId = rbObj['RBId'] for i in unmatchedRBatoms: elem = RBData[rbType][rbId]['rbTypes'][i] lbl = 'Rb' + RBData[rbType][rbId]['atNames'][i] AtomAdd(0.,0.,0.,El=elem,Name=lbl) rbAssignments[i] = lbl wx.CallAfter(Draw) finally: dlg.Destroy() if unmatchedRBatoms: msg = 'There are {} atoms that will need to be added to atoms list.'.format(len(unmatchedRBatoms)) G2G.G2MessageBox(G2frame,msg,title='Please note') for i in unmatchedRBatoms: rbAssignments[i] = None mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add((5,5),0) refName.append(data['testRBObj']['rbAtTypes'][ref]+str(ref)) atNames = data['testRBObj']['atNames'] mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'Locate rigid body : '+rbName), 0,WACV) mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY, 'Locating rigid body : '+rbName), 0, WACV) mainSizer.Add((5,5),0) OriSizer = wx.BoxSizer(wx.HORIZONTAL) else: mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'No side chain torsions'),0,WACV) if not matchTable: if not matchTable: # not sure if this will ever be true OkBtn = None mainSizer.Add((15,15)) else: OkBtn = wx.Button(RigidBodies,wx.ID_ANY,"Add") OkBtn.Bind(wx.EVT_BUTTON, OnOk) OkBtn.Bind(wx.EVT_BUTTON, OnAddRB) CancelBtn = wx.Button(RigidBodies,wx.ID_ANY,'Cancel') CancelBtn.Bind(wx.EVT_BUTTON, OnCancel) SetPhaseWindow(RigidBodies,mainSizer) if not matchTable: mainSizer.Layout() RigidBodies.SetScrollRate(10,10) RigidBodies.SendSizeEvent() RigidBodies.Scroll(0,0) return G2plt.PlotStructure(G2frame,data,True,UpdateTable) colLabels = ['RB\ntype','phase\n#','phase\nlabel','delta, A','Assign as atom'] for i,l in enumerate(matchTable): lbl = '' if i in rbAssignments: lbl = rbAssignments[i] displayTable.append([l[0],l[5],l[6],l[10],lbl]) if i in rbAssignments: if rbAssignments[i] is None: displayTable.append([l[0],-1,'?',-1,'Create new']) else: lbl = rbAssignments[i] displayTable.append([l[0],l[5],l[6],l[10],lbl]) # TODO: think about this else: displayTable.append([l[0],l[5],l[6],l[10],lbl]) Types = [wg.GRID_VALUE_STRING, wg.GRID_VALUE_NUMBER, wg.GRID_VALUE_STRING, wg.GRID_VALUE_FLOAT+':8,3', btn = wx.Button(RigidBodies, wx.ID_ANY, 'Set Origin') btn.Bind(wx.EVT_BUTTON,onSetOrigin) btnSizer.Add(btn,0,wx.ALIGN_CENTER) btnSizer.Add((-1,5)) btn = wx.Button(RigidBodies, wx.ID_ANY, 'Set Orientation') btn.Bind(wx.EVT_BUTTON,onFitOrientation) btnSizer.Add(btn,0,wx.ALIGN_CENTER)
Note: See TracChangeset for help on using the changeset viewer.