Changeset 4605


Ignore:
Timestamp:
Oct 17, 2020 8:46:40 PM (2 years ago)
Author:
toby
Message:

fix AddRB with no matchTable

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r4604 r4605  
    30223022the Cartesian
    30233023axes for rigid bodies with three atoms, A, B and C.
    3024 The vector from A to B defines the x-axis and the z axis is placed
     3024The vector from A to B defines the x-axis and the y axis is placed
    30253025in the plane defined by A to B and A to C.
    30263026'''
     
    33893389the Cartesian
    33903390axes for rigid bodies with three atoms, A, B and C.
    3391 The vector from A to B defines the x-axis and the z axis is placed
     3391The vector from A to B defines the x-axis and the y axis is placed
    33923392in the plane defined by A to B and A to C.
    33933393
  • trunk/GSASIIphsGUI.py

    r4602 r4605  
    37573757        G2plt.PlotStructure(G2frame,data)
    37583758               
    3759     def AtomAdd(x,y,z,El='H',Name='UNK'):
     3759    def AtomAdd(x,y,z,El='H',Name='UNK',update=True):
    37603760        atomData = data['Atoms']
    37613761        generalData = data['General']
     
    37793779           
    37803780        SetupGeneral()
     3781        # might be better to add new atom to Draw Atoms
    37813782        data['Drawing']['Atoms'] = []
    3782         UpdateDrawAtoms()
    3783         G2plt.PlotStructure(G2frame,data)
    37843783#        if 'Atoms' in data['Drawing']:           
    37853784#            DrawAtomAdd(data['Drawing'],atomData[-1])
     3785        if update:
     3786            UpdateDrawAtoms()
     3787            G2plt.PlotStructure(G2frame,data)
    37863788
    37873789    def OnAtomInsert(event):
     
    1022510227        wx.CallAfter(FillRigidBodyGrid,True)
    1022610228               
     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       
    1022710312    def OnRBAssign(event):
    1022810313        '''Assign RB to atoms in a phase with tools to locate the RB in the structure
    1022910314        '''
    10230        
    10231         def assignAtoms(selDict={},unmatchedRBatoms=None):
    10232             '''Find the closest RB atoms to atoms in the structure
    10233             If selDict is specified, it overrides the assignments to specify
    10234             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 = None
    10245                
    10246             newXYZ = G2mth.UpdateRBXYZ(Bmat,rbObj,RBData,rbType)[0]
    10247             # categorize atoms by type, omitting any that are already assigned
    10248             # in a rigid body
    10249             atmTypes = [None if atomData[i][-1] in rbUsedIds
    10250                             else atomData[i][ct]
    10251                             for i in range(len(atomData))]
    10252             # remove assigned atoms from search groups
    10253             for i in selDict:
    10254                 if selDict[i] is None: continue
    10255                 atmTypes[selDict[i]] = None
    10256             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: continue
    10262                 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 assignments
    10266             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                     continue
    10277                 elif i in selDict:
    10278                     searchXYZ = [atmXYZ[selDict[i]]] #assigned
    10279                     numLookup = [selDict[i]]
    10280                 else:
    10281                     if t not in oXYZbyT:
    10282                         unmatched.append(i)
    10283                         matchTable.append([t , lbl] + list(xyz))
    10284                         continue
    10285                     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 again
    10293                         dist[pidIndx] = 100.
    10294                         if min(dist) == 100:
    10295                             pid = None
    10296                             break
    10297                     else:
    10298                         break
    10299                 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[:] = unmatched
    10308             return matchTable
    1030910315           
    1031010316        def Draw():
     
    1031510321                cx,ct,cs,cia = data['General']['AtomPtrs']
    1031610322                atomData = data['Atoms']               
    10317                 matchTable = UpdateTable()
     10323                if RigidBodies.atomsGrid:
     10324                    matchTable = UpdateTable()
     10325                else:
     10326                    matchTable = assignAtoms(RBData)
    1031810327                dmax = 0.
    1031910328                for line in matchTable:
     
    1032810337                    dlg.Destroy()
    1032910338                Ids = []
     10339                updateNeeded = False
    1033010340                for line in matchTable:
    1033110341                    if len(line) < 11:
     
    1033410344                        lbl = 'Rb' + elem + str(nextNum)
    1033510345                        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)
    1033710347                        Ids.append(atomData[nextNum][-1])
     10348                        updateNeeded = True
    1033810349                    else:
    1033910350                        atomData[line[5]][cx:cx+3] = line[2:5]
    1034010351                        Ids.append(line[11])
     10352                if updateNeeded:
     10353                    UpdateDrawAtoms()
     10354                    G2plt.PlotStructure(G2frame,data)
    1034110355                   
    1034210356                rbType = data['testRBObj']['rbType']
     
    1039110405                update displayed table
    1039210406                '''
     10407                if not RigidBodies.atomsGrid: return []
    1039310408                RigidBodies.atomsGrid.completeEdits()
    1039410409                # add new atoms and reassign
     
    1040110416                        rbAssignments[i] = None
    1040210417                        selDict[i] = None
    10403                 matchTable = assignAtoms(selDict)
     10418                matchTable = assignAtoms(RBData,selDict)
    1040410419                for i,l in enumerate(matchTable):
    1040510420                    if len(l) < 11: continue
    1040610421                    RigidBodies.atomsTable.data[i][1:4] = l[5],l[6],l[10]
    10407                 RigidBodies.atomsGrid.ForceRefresh()
     10422                if RigidBodies.atomsGrid:
     10423                    RigidBodies.atomsGrid.ForceRefresh()
    1040810424                if added: wx.CallLater(100,Draw)
    1040910425                return matchTable
     
    1044710463            def getSelectedAtoms():
    1044810464                'Find the FB atoms that have been assigned to specific atoms in structure'
     10465                if not RigidBodies.atomsGrid: return
    1044910466                RigidBodies.atomsGrid.completeEdits()
    1045010467                tbl = RigidBodies.atomsGrid.GetTable()
     
    1059410611                    axis = np.array(axis)/nl.norm(axis)
    1059510612                data['testRBObj']['rbObj']['symAxis'] = axis
    10596                 UpdateTablePlot()               
     10613                UpdateTablePlot()
     10614               
    1059710615            showAtom = [None]
    1059810616            def showCryAtom(*args,**kwargs):
     
    1060810626            if RigidBodies.GetSizer(): RigidBodies.GetSizer().Clear(True)
    1060910627            unmatchedRBatoms = []
    10610             matchTable = assignAtoms(unmatchedRBatoms=unmatchedRBatoms)
     10628            matchTable = assignAtoms(RBData,unmatchedRBatoms=unmatchedRBatoms)
    1061110629            if unmatchedRBatoms:
    1061210630                # msg = 'There are {} atoms that will need to be added to atoms list.'.format(len(unmatchedRBatoms))
     
    1072910747            else:
    1073010748                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)
    1073910751            CancelBtn = wx.Button(RigidBodies,wx.ID_ANY,'Cancel')
    1074010752            CancelBtn.Bind(wx.EVT_BUTTON, OnCancel)
     
    1075810770                mainSizer.Layout()
    1075910771                G2plt.PlotStructure(G2frame,data,True)
     10772                RigidBodies.atomsGrid = None
    1076010773                return
    1076110774           
     
    1281612829        '''
    1281712830        if 'testRBObj' not in data: return
     12831        if not RigidBodies.atomsGrid: return
    1281812832        alt = event.GetModifiers() & wx.MOD_ALT
    1281912833        event.Skip()
     
    1283712851            data['testRBObj']['RBhighLight'] = rows[0]
    1283812852        else:
    12839             #GSASIIpath.IPyBreak()
    12840             #return
    1284112853            Ind = data['testRBObj'].get('CRYhighLight',[])
    1284212854            if len(Ind) == 0:
Note: See TracChangeset for help on using the changeset viewer.