Changeset 4524
- Timestamp:
- Jul 18, 2020 3:26:12 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIphsGUI.py
r4523 r4524 1098 1098 #### Phase editing routines 1099 1099 ################################################################################ 1100 def 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 1107 def 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 1100 1161 def getAtomSelections(AtmTbl,cn=0,action='action',includeView=False): 1101 1162 '''get selected atoms from table or ask user if none are selected … … 3295 3356 atomData[r][c] = parms 3296 3357 if 'Atoms' in data['Drawing']: 3297 DrawAtomsReplaceByID(data ['Drawing'],ui+6,atomData[r],ID)3358 DrawAtomsReplaceByID(data,ui+6,atomData[r],ID) 3298 3359 wx.CallAfter(Paint) 3299 3360 … … 3378 3439 if 'Atoms' in data['Drawing'] and replot: 3379 3440 ci = colLabels.index('I/A') 3380 DrawAtomsReplaceByID(data ['Drawing'],ci+8,atomData[r],ID)3441 DrawAtomsReplaceByID(data,ci+8,atomData[r],ID) 3381 3442 G2plt.PlotStructure(G2frame,data) 3382 3443 if SGData['SpGrp'] != 'P 1': #no need to update P 1 structures! … … 3403 3464 ID = atomData[r][ci+8] 3404 3465 if 'Atoms' in data['Drawing']: 3405 DrawAtomsReplaceByID(data ['Drawing'],ci+8,atomData[r],ID)3466 DrawAtomsReplaceByID(data,ci+8,atomData[r],ID) 3406 3467 G2plt.PlotStructure(G2frame,data) 3407 3468 SetupGeneral() … … 3851 3912 FillAtomsGrid(Atoms) 3852 3913 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) 3854 3915 G2plt.PlotStructure(G2frame,data) 3855 3916 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 & color3885 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 & color3904 elif generalData['Type'] == 'macromolecular':3905 try:3906 oneLetter = AA3letter.index(atom[1])3907 except ValueError:3908 oneLetter = -13909 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 & color3913 atNum = generalData['AtomTypes'].index(atom[ct])3914 atomInfo[cs] = list(generalData['Color'][atNum])3915 return atomInfo3916 3917 3917 3918 def AtomInsert(indx,x,y,z,El='H',Name='UNK'): … … 4037 4038 for r in indx: 4038 4039 ID = atomData[r][ci+8] 4039 DrawAtomsReplaceByID(data ['Drawing'],ci+8,atomData[r],ID)4040 DrawAtomsReplaceByID(data,ci+8,atomData[r],ID) 4040 4041 FillAtomsGrid(Atoms) 4041 4042 dlg.Destroy() … … 5861 5862 title = 'g(r)-{} for {}'.format(nameId,pName) 5862 5863 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) 5866 5867 found = True 5867 5868 elif 'BondConstraint' in sitem: … … 6035 6036 if item.__class__.__name__+' pyplot' in selectedPlots: 6036 6037 item.plot(show=True) 6037 GSASIIpath.IPyBreak() 6038 6038 6039 # how to get std err vs steps? 6040 #GSASIIpath.IPyBreak() 6039 6041 # loglines = [] 6040 6042 # ilog = 0 … … 7521 7523 7522 7524 def DrawAtomAdd(drawingData,atom): 7523 drawingData['Atoms'].append(MakeDrawAtom( atom))7525 drawingData['Atoms'].append(MakeDrawAtom(data,atom)) 7524 7526 7525 7527 def OnRestraint(event): … … 8432 8434 event.StopPropagation() 8433 8435 8434 def OnReloadDrawAtoms(event ):8436 def OnReloadDrawAtoms(event=None): 8435 8437 atomData = data['Atoms'] 8436 8438 cx,ct,cs,ci = data['General']['AtomPtrs'] 8437 8439 for atom in atomData: 8438 8440 ID = atom[ci+8] 8439 DrawAtomsReplaceByID(data ['Drawing'],ci+8,atom,ID)8441 DrawAtomsReplaceByID(data,ci+8,atom,ID) 8440 8442 UpdateDrawAtoms() 8441 8443 drawAtoms.ClearSelection() 8442 8444 G2plt.PlotStructure(G2frame,data) 8443 event.StopPropagation() 8445 if event: 8446 event.StopPropagation() 8444 8447 8445 8448 def DrawAtomsDeleteByIDs(IDs): … … 10105 10108 G2frame.GetStatusBar().SetStatusText('',1) 10106 10109 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 10111 10111 if 'Residue' in data['RBModels'] and len(data['RBModels']['Residue']): 10112 nobody = False 10112 10113 mainSizer.Add((5,5),0) 10113 10114 mainSizer.Add(wx.StaticText(RigidBodies,-1,'Residue rigid bodies:'),0,WACV) … … 10132 10133 G2plt.PlotStructure(G2frame,data) 10133 10134 if 'Vector' in data['RBModels'] and len(data['RBModels']['Vector']): 10135 nobody = False 10134 10136 mainSizer.Add((5,5),0) 10135 10137 mainSizer.Add(wx.StaticText(RigidBodies,-1,'Vector rigid bodies:'),0,WACV) … … 10137 10139 for RBObj in data['RBModels']['Vector']: 10138 10140 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) 10140 10152 SetPhaseWindow(RigidBodies,mainSizer) 10141 10153 … … 10255 10267 def Draw(): 10256 10268 '''Create the window for assigning RB to atoms''' 10269 10257 10270 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'] 10260 10274 matchTable = UpdateTable() 10261 10275 dmax = 0. … … 10296 10310 RBData[rbType][rbId]['useCount'] += 1 10297 10311 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) 10298 10318 G2plt.PlotStructure(G2frame,data,False) 10299 10319 FillRigidBodyGrid(True) … … 10330 10350 added = False 10331 10351 selDict = getSelectedAtoms() 10352 if selDict is None: return 10332 10353 for i,l in enumerate(RigidBodies.atomsTable.data): 10333 10354 if l[4] == 'Create new': … … 10393 10414 10394 10415 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 10396 10418 located rigid body positions 10397 10419 … … 10649 10671 G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Rigid bodies')) 10650 10672 rbNames = {} 10673 dups = [] 10651 10674 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] 10654 10681 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 10657 10696 if not rbNames: 10658 10697 print ('**** ERROR - no rigid bodies defined ****') 10659 10698 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', 10661 10700 'No Rigid Bodies') 10662 10701 return
Note: See TracChangeset
for help on using the changeset viewer.