Changeset 4524


Ignore:
Timestamp:
Jul 18, 2020 3:26:12 PM (3 years ago)
Author:
toby
Message:

rigid bodies: error on duplicate name; update draw atoms after adding RB; better msgs. fullrmc plot fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r4523 r4524  
    10981098#### Phase editing routines
    10991099################################################################################
     1100def DrawAtomsReplaceByID(data,loc,atom,ID):
     1101    '''Replace all atoms in drawing array with an ID matching the specified value'''
     1102    atomData = data['Drawing']['Atoms']
     1103    indx = G2mth.FindAtomIndexByIDs(atomData,loc,[ID,])
     1104    for ind in indx:
     1105        atomData[ind] = MakeDrawAtom(data,atom,atomData[ind])
     1106
     1107def MakeDrawAtom(data,atom,oldatom=None):
     1108    'needs a description'
     1109    AA3letter = ['ALA','ARG','ASN','ASP','CYS','GLN','GLU','GLY','HIS','ILE',
     1110        'LEU','LYS','MET','PHE','PRO','SER','THR','TRP','TYR','VAL','MSE','HOH','WAT','UNK']
     1111    AA1letter = ['A','R','N','D','C','Q','E','G','H','I',
     1112        'L','K','M','F','P','S','T','W','Y','V','M',' ',' ',' ']
     1113    generalData = data['General']
     1114    Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])
     1115    SGData = generalData['SGData']
     1116    if generalData['Type'] in ['nuclear','faulted',]:
     1117        if oldatom:
     1118            opr = oldatom[5]
     1119            if atom[9] == 'A':                   
     1120                X,U = G2spc.ApplyStringOps(opr,SGData,atom[3:6],atom[11:17])
     1121                atomInfo = [atom[:2]+list(X)+oldatom[5:9]+atom[9:11]+list(U)+oldatom[17:]][0]
     1122            else:
     1123                X = G2spc.ApplyStringOps(opr,SGData,atom[3:6])
     1124                atomInfo = [atom[:2]+list(X)+oldatom[5:9]+atom[9:]+oldatom[17:]][0]
     1125        else:
     1126            atomInfo = [atom[:2]+atom[3:6]+['1',]+['vdW balls',]+
     1127                ['',]+[[255,255,255],]+atom[9:]+[[],[]]][0]
     1128        ct,cs = [1,8]         #type & color
     1129    elif  generalData['Type'] == 'magnetic':
     1130        if oldatom:
     1131            opr = oldatom[8]
     1132            mom = np.array(atom[7:10])
     1133            if generalData['Super']:
     1134                SSGData = generalData['SSGData']
     1135                Mom = G2spc.ApplyStringOpsMom(opr,SGData,SSGData,mom)
     1136            else:
     1137                Mom = G2spc.ApplyStringOpsMom(opr,SGData,None,mom)
     1138            if atom[12] == 'A':                   
     1139                X,U = G2spc.ApplyStringOps(opr,SGData,atom[3:6],atom[14:20])
     1140                atomInfo = [atom[:2]+list(X)+list(Mom)+oldatom[8:12]+atom[12:14]+list(U)+oldatom[20:]][0]
     1141            else:
     1142                X = G2spc.ApplyStringOps(opr,SGData,atom[3:6])
     1143                atomInfo = [atom[:2]+list(X)+list(Mom)+oldatom[8:12]+atom[12:]+oldatom[20:]][0]
     1144        else:
     1145            atomInfo = [atom[:2]+atom[3:6]+atom[7:10]+['1',]+['vdW balls',]+
     1146                ['',]+[[255,255,255],]+atom[12:]+[[],[]]][0]
     1147        ct,cs = [1,11]         #type & color
     1148    elif generalData['Type'] == 'macromolecular':
     1149        try:
     1150            oneLetter = AA3letter.index(atom[1])
     1151        except ValueError:
     1152            oneLetter = -1
     1153        atomInfo = [[atom[1].strip()+atom[0],]+
     1154            [AA1letter[oneLetter]+atom[0],]+atom[2:5]+
     1155            atom[6:9]+['1',]+['vdW balls',]+['',]+[[255,255,255],]+atom[12:]+[[],[]]][0]
     1156        ct,cs = [4,11]         #type & color
     1157    atNum = generalData['AtomTypes'].index(atom[ct])
     1158    atomInfo[cs] = list(generalData['Color'][atNum])
     1159    return atomInfo
     1160   
    11001161def getAtomSelections(AtmTbl,cn=0,action='action',includeView=False):
    11011162    '''get selected atoms from table or ask user if none are selected
     
    32953356                                atomData[r][c] = parms
    32963357                        if 'Atoms' in data['Drawing']:
    3297                             DrawAtomsReplaceByID(data['Drawing'],ui+6,atomData[r],ID)
     3358                            DrawAtomsReplaceByID(data,ui+6,atomData[r],ID)
    32983359                    wx.CallAfter(Paint)
    32993360                   
     
    33783439                if 'Atoms' in data['Drawing'] and replot:
    33793440                    ci = colLabels.index('I/A')
    3380                     DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID)
     3441                    DrawAtomsReplaceByID(data,ci+8,atomData[r],ID)
    33813442                    G2plt.PlotStructure(G2frame,data)
    33823443                if SGData['SpGrp'] != 'P 1':    #no need to update P 1 structures!
     
    34033464                ID = atomData[r][ci+8]
    34043465                if 'Atoms' in data['Drawing']:
    3405                     DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID)
     3466                    DrawAtomsReplaceByID(data,ci+8,atomData[r],ID)
    34063467                    G2plt.PlotStructure(G2frame,data)
    34073468                SetupGeneral()
     
    38513912            FillAtomsGrid(Atoms)
    38523913            ID = atomData[indx[0]][ci+8]
    3853             DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[indx[0]],ID)
     3914            DrawAtomsReplaceByID(data,ci+8,atomData[indx[0]],ID)
    38543915            G2plt.PlotStructure(G2frame,data)
    38553916        event.StopPropagation()
    3856            
    3857     def DrawAtomsReplaceByID(drawingData,loc,atom,ID):
    3858         IDs = [ID,]
    3859         atomData = drawingData['Atoms']
    3860         indx = G2mth.FindAtomIndexByIDs(atomData,loc,IDs)
    3861         for ind in indx:
    3862             atomData[ind] = MakeDrawAtom(atom,atomData[ind])
    3863                
    3864     def MakeDrawAtom(atom,oldatom=None):
    3865         AA3letter = ['ALA','ARG','ASN','ASP','CYS','GLN','GLU','GLY','HIS','ILE',
    3866             'LEU','LYS','MET','PHE','PRO','SER','THR','TRP','TYR','VAL','MSE','HOH','WAT','UNK']
    3867         AA1letter = ['A','R','N','D','C','Q','E','G','H','I',
    3868             'L','K','M','F','P','S','T','W','Y','V','M',' ',' ',' ']
    3869         generalData = data['General']
    3870         Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])
    3871         SGData = generalData['SGData']
    3872         if generalData['Type'] in ['nuclear','faulted',]:
    3873             if oldatom:
    3874                 opr = oldatom[5]
    3875                 if atom[9] == 'A':                   
    3876                     X,U = G2spc.ApplyStringOps(opr,SGData,atom[3:6],atom[11:17])
    3877                     atomInfo = [atom[:2]+list(X)+oldatom[5:9]+atom[9:11]+list(U)+oldatom[17:]][0]
    3878                 else:
    3879                     X = G2spc.ApplyStringOps(opr,SGData,atom[3:6])
    3880                     atomInfo = [atom[:2]+list(X)+oldatom[5:9]+atom[9:]+oldatom[17:]][0]
    3881             else:
    3882                 atomInfo = [atom[:2]+atom[3:6]+['1',]+['vdW balls',]+
    3883                     ['',]+[[255,255,255],]+atom[9:]+[[],[]]][0]
    3884             ct,cs = [1,8]         #type & color
    3885         elif  generalData['Type'] == 'magnetic':
    3886             if oldatom:
    3887                 opr = oldatom[8]
    3888                 mom = np.array(atom[7:10])
    3889                 if generalData['Super']:
    3890                     SSGData = generalData['SSGData']
    3891                     Mom = G2spc.ApplyStringOpsMom(opr,SGData,SSGData,mom)
    3892                 else:
    3893                     Mom = G2spc.ApplyStringOpsMom(opr,SGData,None,mom)
    3894                 if atom[12] == 'A':                   
    3895                     X,U = G2spc.ApplyStringOps(opr,SGData,atom[3:6],atom[14:20])
    3896                     atomInfo = [atom[:2]+list(X)+list(Mom)+oldatom[8:12]+atom[12:14]+list(U)+oldatom[20:]][0]
    3897                 else:
    3898                     X = G2spc.ApplyStringOps(opr,SGData,atom[3:6])
    3899                     atomInfo = [atom[:2]+list(X)+list(Mom)+oldatom[8:12]+atom[12:]+oldatom[20:]][0]
    3900             else:
    3901                 atomInfo = [atom[:2]+atom[3:6]+atom[7:10]+['1',]+['vdW balls',]+
    3902                     ['',]+[[255,255,255],]+atom[12:]+[[],[]]][0]
    3903             ct,cs = [1,11]         #type & color
    3904         elif generalData['Type'] == 'macromolecular':
    3905             try:
    3906                 oneLetter = AA3letter.index(atom[1])
    3907             except ValueError:
    3908                 oneLetter = -1
    3909             atomInfo = [[atom[1].strip()+atom[0],]+
    3910                 [AA1letter[oneLetter]+atom[0],]+atom[2:5]+
    3911                 atom[6:9]+['1',]+['vdW balls',]+['',]+[[255,255,255],]+atom[12:]+[[],[]]][0]
    3912             ct,cs = [4,11]         #type & color
    3913         atNum = generalData['AtomTypes'].index(atom[ct])
    3914         atomInfo[cs] = list(generalData['Color'][atNum])
    3915         return atomInfo
    39163917       
    39173918    def AtomInsert(indx,x,y,z,El='H',Name='UNK'):
     
    40374038                        for r in indx:
    40384039                            ID = atomData[r][ci+8]
    4039                             DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID)
     4040                            DrawAtomsReplaceByID(data,ci+8,atomData[r],ID)
    40404041                FillAtomsGrid(Atoms)
    40414042            dlg.Destroy()
     
    58615862                            title = 'g(r)-{} for {}'.format(nameId,pName)
    58625863                           
    5863                         plotList.append(title+pName)
    5864                         plotList.append('All partials of '+title+pName)
    5865                         plotList.append('Total partials of '+title+pName)
     5864                        plotList.append(title)
     5865                        plotList.append('All partials of '+title)
     5866                        plotList.append('Total partials of '+title)
    58665867                        found = True
    58675868                    elif 'BondConstraint' in sitem:
     
    60356036                    if item.__class__.__name__+' pyplot' in selectedPlots:
    60366037                        item.plot(show=True)
    6037             GSASIIpath.IPyBreak()
    6038            
     6038
     6039            # how to get std err vs steps?
     6040            #GSASIIpath.IPyBreak()
    60396041            # loglines = []
    60406042            # ilog = 0
     
    75217523           
    75227524    def DrawAtomAdd(drawingData,atom):
    7523         drawingData['Atoms'].append(MakeDrawAtom(atom))
     7525        drawingData['Atoms'].append(MakeDrawAtom(data,atom))
    75247526       
    75257527    def OnRestraint(event):
     
    84328434        event.StopPropagation()
    84338435       
    8434     def OnReloadDrawAtoms(event):
     8436    def OnReloadDrawAtoms(event=None):
    84358437        atomData = data['Atoms']
    84368438        cx,ct,cs,ci = data['General']['AtomPtrs']
    84378439        for atom in atomData:
    84388440            ID = atom[ci+8]
    8439             DrawAtomsReplaceByID(data['Drawing'],ci+8,atom,ID)
     8441            DrawAtomsReplaceByID(data,ci+8,atom,ID)
    84408442        UpdateDrawAtoms()
    84418443        drawAtoms.ClearSelection()
    84428444        G2plt.PlotStructure(G2frame,data)
    8443         event.StopPropagation()
     8445        if event:
     8446            event.StopPropagation()
    84448447       
    84458448    def DrawAtomsDeleteByIDs(IDs):
     
    1010510108        G2frame.GetStatusBar().SetStatusText('',1)
    1010610109        mainSizer = wx.BoxSizer(wx.VERTICAL)
    10107         if not data['RBModels']:
    10108             mainSizer.Add((5,5),0)
    10109             mainSizer.Add(wx.StaticText(RigidBodies,-1,'No rigid body models:'),0,WACV)
    10110             mainSizer.Add((5,5),0)
     10110        nobody = True
    1011110111        if 'Residue' in data['RBModels'] and len(data['RBModels']['Residue']):
     10112            nobody = False
    1011210113            mainSizer.Add((5,5),0)
    1011310114            mainSizer.Add(wx.StaticText(RigidBodies,-1,'Residue rigid bodies:'),0,WACV)
     
    1013210133            G2plt.PlotStructure(G2frame,data)
    1013310134        if 'Vector' in data['RBModels'] and len(data['RBModels']['Vector']):
     10135            nobody = False
    1013410136            mainSizer.Add((5,5),0)
    1013510137            mainSizer.Add(wx.StaticText(RigidBodies,-1,'Vector rigid bodies:'),0,WACV)
     
    1013710139            for RBObj in data['RBModels']['Vector']:
    1013810140                mainSizer.Add(VecrbSizer(RBObj))
    10139 
     10141        if nobody:
     10142            mainSizer.Add((5,5),0)
     10143            msg = 'Define a rigid body with the "Rigid Bodies" tree entry before adding it to the phase here'
     10144            if RBData.get('RBIds') is None:
     10145                pass
     10146            elif len(RBData['RBIds'].get('Vector',[])) + len(RBData['RBIds'].get('Residue',[])) == 0:
     10147                pass
     10148            else:
     10149                msg = 'No rigid bodies defined in phase. Use "Edit Body"/"Locate & Insert..."\ncommand to add them.'
     10150            mainSizer.Add(wx.StaticText(RigidBodies,-1,msg),0,WACV)
     10151            mainSizer.Add((5,5),0)
    1014010152        SetPhaseWindow(RigidBodies,mainSizer)
    1014110153
     
    1025510267        def Draw():
    1025610268            '''Create the window for assigning RB to atoms'''
     10269           
    1025710270            def OnAddRB(event):
    10258                 'respond to OK button, set info into phase'
    10259                 cx,ct,cs,cia = data['General']['AtomPtrs'] 
     10271                'respond to RB Add button, sets RB info in phase'
     10272                cx,ct,cs,cia = data['General']['AtomPtrs']
     10273                atomData = data['Atoms']               
    1026010274                matchTable = UpdateTable()
    1026110275                dmax = 0.
     
    1029610310                RBData[rbType][rbId]['useCount'] += 1
    1029710311                del data['testRBObj']
     10312               
     10313                # Update the draw atoms array & recompute bonds
     10314                for atom in atomData:
     10315                    ID = atom[cia+8]
     10316                    DrawAtomsReplaceByID(data,cia+8,atom,ID)
     10317                FindBondsDraw(data)
    1029810318                G2plt.PlotStructure(G2frame,data,False)
    1029910319                FillRigidBodyGrid(True)
     
    1033010350                added = False
    1033110351                selDict = getSelectedAtoms()
     10352                if selDict is None: return
    1033210353                for i,l in enumerate(RigidBodies.atomsTable.data):
    1033310354                    if l[4] == 'Create new':
     
    1039310414
    1039410415            def objectiveDeltaPos(vals,selDict,data,rbObj_in):
    10395                 '''Returns a list of distances between atom positions and
     10416                '''Objective function for minimization. 
     10417                Returns a list of distances between atom positions and
    1039610418                located rigid body positions
    1039710419
     
    1064910671            G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Rigid bodies'))
    1065010672        rbNames = {}
     10673        dups = []
    1065110674        for rbVec in RBData['Vector']:
    10652             if rbVec != 'AtInfo':
    10653                 rbNames[RBData['Vector'][rbVec]['RBname']] =['Vector',rbVec]
     10675            if rbVec == 'AtInfo': continue
     10676            key = RBData['Vector'][rbVec]['RBname']
     10677            if key in rbNames:
     10678                dups.append(key)
     10679            else:
     10680                rbNames[key] = ['Vector',rbVec]
    1065410681        for rbRes in RBData['Residue']:
    10655             if rbRes != 'AtInfo':
    10656                 rbNames[RBData['Residue'][rbRes]['RBname']] = ['Residue',rbRes]
     10682            if rbRes == 'AtInfo': continue
     10683            key = RBData['Residue'][rbRes]['RBname']
     10684            if key in rbNames:
     10685                dups.append(key)
     10686            else:
     10687                rbNames[key] = ['Residue',rbRes]
     10688        if dups:
     10689            msg = 'Two or more rigid bodies have the same name. This must be corrected before bodies can be added.'
     10690            msg += '\n\n Duplicated name(s): '
     10691            for d in dups:
     10692                msg += d
     10693                msg += ' '
     10694            G2G.G2MessageBox(G2frame,msg,'Duplicate Rigid Body Names')
     10695            return
    1065710696        if not rbNames:
    1065810697            print ('**** ERROR - no rigid bodies defined ****')
    1065910698            G2G.G2MessageBox(G2frame,
    10660                 'You must define bodies in Rigid Bodies tree item before trying to add them to a phase',
     10699                'You must define bodies in the Rigid Bodies tree item before trying to add them to a phase',
    1066110700                'No Rigid Bodies')
    1066210701            return
Note: See TracChangeset for help on using the changeset viewer.