Changeset 819 for trunk/GSASIIrestrGUI.py
- Timestamp:
- Dec 21, 2012 4:50:13 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIrestrGUI.py
r818 r819 39 39 restrData = data[phaseName] 40 40 if 'Bond' not in restrData: 41 restrData['Bond'] = {'wtFactor':1.0,'Range': 0.9,'Bonds':[],'Use':True}41 restrData['Bond'] = {'wtFactor':1.0,'Range':1.1,'Bonds':[],'Use':True} 42 42 if 'Angle' not in restrData: 43 43 restrData['Angle'] = {'wtFactor':1.0,'Range':0.85,'Angles':[],'Use':True} 44 44 if 'Plane' not in restrData: 45 restrData['Plane'] = {'wtFactor':1.0,' Range':0.9,'Planes':[],'Use':True}45 restrData['Plane'] = {'wtFactor':1.0,'Planes':[],'Use':True} 46 46 if 'Chiral' not in restrData: 47 restrData['Chiral'] = {'wtFactor':1.0,' Range':0.9,'Volumes':[],'Use':True}47 restrData['Chiral'] = {'wtFactor':1.0,'Volumes':[],'Use':True} 48 48 if 'Torsion' not in restrData: 49 restrData['Torsion'] = {'wtFactor':1.0,' Range':0.9,'Coeff':{},'Torsions':[],'Use':True}49 restrData['Torsion'] = {'wtFactor':1.0,'Coeff':{},'Torsions':[],'Use':True} 50 50 if 'Rama' not in restrData: 51 restrData['Rama'] = {'wtFactor':1.0,' Range':0.9,'Coeff':{},'Ramas':[],'Use':True}51 restrData['Rama'] = {'wtFactor':1.0,'Coeff':{},'Ramas':[],'Use':True} 52 52 General = phasedata['General'] 53 53 Cell = General['Cell'][1:7] #skip flag & volume … … 168 168 elif 'Plane' in G2frame.dataDisplay.GetPageText(page): 169 169 AddPlaneRestraint(restrData['Plane']) 170 elif 'Chiral' in G2frame.dataDisplay.GetPageText(page):171 AddChiralRestraint(restrData['Chiral'])172 # elif 'Torsion' in G2frame.dataDisplay.GetPageText(page):173 # AddTorsionRestraint(restrData['Torsion'])174 # elif 'Rama' in G2frame.dataDisplay.GetPageText(page):175 # AddRamaRestraint(restrData['Rama'])176 170 177 171 def OnAddAARestraint(event): … … 191 185 192 186 def AddBondRestraint(bondRestData): 193 Radii = dict(zip(General['AtomTypes'],General['BondRadii']))194 187 Lists = {'origin':[],'target':[]} 195 188 for listName in ['origin','target']: … … 206 199 else: 207 200 Lists[listName].append([Ids[x],Types[x],Coords[x],]) 201 bond = 1.54 202 dlg = G2phG.SingleFloatDialog(G2frame,'Distance','Enter restraint distance for bond',bond,[1.,4.],'%.4f') 203 if dlg.ShowModal() == wx.ID_OK: 204 bond = dlg.GetValue() 205 dlg.Destroy() 208 206 Factor = bondRestData['Range'] 209 207 indices = (-1,0,1) … … 223 221 else: 224 222 result = G2spc.GenAtom(Tcoord,SGData,False,Move=False) 225 BsumR = (Radii[Otype]+Radii[Ttype])*Factor226 223 for Txyz,Top,Tunit in result: 227 224 Dx = (Txyz-np.array(Ocoord))+Units 228 225 dx = np.inner(Amat,Dx) 229 dist = ma.masked_less(np.sqrt(np.sum(dx**2,axis=0)), 0.5)230 IndB = ma.nonzero(ma.masked_greater(dist -BsumR,0.))226 dist = ma.masked_less(np.sqrt(np.sum(dx**2,axis=0)),bond/Factor) 227 IndB = ma.nonzero(ma.masked_greater(dist,bond*Factor)) 231 228 if np.any(IndB): 232 229 for indb in IndB: … … 237 234 else: 238 235 Topstr = str(Top) 239 newBond = [[Oid,Tid],['1',Topstr], 1.54,0.01]236 newBond = [[Oid,Tid],['1',Topstr],bond,0.01] 240 237 if newBond not in bondRestData['Bonds']: 241 238 bondRestData['Bonds'].append(newBond) … … 278 275 for tId,tCoord in zip(tIds,tCoords)[i:]: 279 276 obsd = np.sqrt(np.sum(np.inner(Amat,tCoord-oCoord)**2)) 280 if dist *Factor < obsd < dist/Factor:277 if dist/Factor < obsd < dist*Factor: 281 278 newBond = [[oId,tId],['1','1'],dist,esd] 282 279 if newBond not in bondRestData['Bonds']: … … 302 299 origAtoms.append([Ids[x],Types[x],Coords[x]]) 303 300 targAtoms = [[Ids[x+iBeg],Types[x+iBeg],Coords[x+iBeg]] for x in range(len(Names[iBeg:]))] 301 value = 109.54 302 dlg = G2phG.SingleFloatDialog(G2frame,'Angle','Enter restraint angle ',value,[30.,180.],'%.2f') 303 if dlg.ShowModal() == wx.ID_OK: 304 value = dlg.GetValue() 305 dlg.Destroy() 304 306 305 307 Factor = angleRestData['Range'] … … 340 342 ops = [vecta[4],vecta[1],vectb[4]] 341 343 XYZ = np.array([vecta[5],vecta[2],vectb[5]]) 342 angle = G2mth.getRestAngle(XYZ,Amat)344 angle = [ids,ops,value,1.0] 343 345 if angle not in angleRestData['Angles']: 344 angleRestData['Angles'].append( [ids,ops,109.5,1.0])346 angleRestData['Angles'].append(angle) 345 347 UpdateAngleRestr(angleRestData) 346 348 … … 411 413 restrData['Planes'].append(plane) 412 414 else: 413 print '**** ERROR - not enough atoms f roa plane restraint - try again ****'415 print '**** ERROR - not enough atoms for a plane restraint - try again ****' 414 416 UpdatePlaneRestr(restrData) 415 417 … … 466 468 UpdatePlaneRestr(planeRestData) 467 469 468 def AddChiralRestraint():469 print 'Chiral restraint'470 471 470 def AddAAChiralRestraint(chiralRestData): 472 471 macro = getMacroFile('chiral') … … 517 516 return Chains 518 517 519 #520 518 def AddAATorsionRestraint(torsionRestData): 521 519 macro = getMacroFile('torsion') … … 665 663 666 664 def WtBox(wind,restData): 667 if 'Range' not in restData: restData['Range'] = 0.9#patch665 if 'Range' not in restData: restData['Range'] = 1.1 #patch 668 666 669 667 def OnWtFactor(event): … … 696 694 useData.SetValue(restData['Use']) 697 695 wtBox.Add(useData,0,wx.ALIGN_CENTER_VERTICAL) 698 if 'Bond ' in restData or 'Angle' in restData:696 if 'Bonds' in restData or 'Angles' in restData: 699 697 wtBox.Add(wx.StaticText(wind,-1,'Search range:'),0,wx.ALIGN_CENTER_VERTICAL) 700 698 sRange = wx.TextCtrl(wind,-1,value='%.2f'%(restData['Range']),style=wx.TE_PROCESS_ENTER) … … 738 736 return 739 737 Bonds.ClearSelection() 740 val = bondList[rows[0]][ 3]738 val = bondList[rows[0]][2] 741 739 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new value for bond',val,[0.,5.],'%.4f') 742 740 if dlg.ShowModal() == wx.ID_OK: 743 741 parm = dlg.GetValue() 744 742 for r in rows: 745 bond List[r][3] = parm743 bondRestData['Bonds'][r][2] = parm 746 744 dlg.Destroy() 747 745 UpdateBondRestr(bondRestData) … … 752 750 return 753 751 Bonds.ClearSelection() 754 val = bondList[rows[0]][ 4]752 val = bondList[rows[0]][3] 755 753 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for bond',val,[0.,1.],'%.4f') 756 754 if dlg.ShowModal() == wx.ID_OK: 757 755 parm = dlg.GetValue() 758 756 for r in rows: 759 bond List[r][4] = parm757 bondRestData['Bonds'][r][3] = parm 760 758 dlg.Destroy() 761 759 UpdateBondRestr(bondRestData) … … 798 796 else: 799 797 colLabels = ['A+SymOp - B+SymOp','calc','obs','esd'] 800 for i,[indx,ops,obs,esd] in enumerate(bondList): 801 names = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 802 XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3)) 803 XYZ = G2mth.getSyXYZ(XYZ,ops,SGData) 804 calc = G2mth.getRestDist(XYZ,Amat) 805 table.append([names[0]+'+('+ops[0]+') - '+names[1]+'+('+ops[1]+')',calc,obs,esd]) 806 rowLabels.append(str(i)) 798 try: 799 for i,[indx,ops,obs,esd] in enumerate(bondList): 800 names = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 801 XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3)) 802 XYZ = G2mth.getSyXYZ(XYZ,ops,SGData) 803 calc = G2mth.getRestDist(XYZ,Amat) 804 table.append([names[0]+'+('+ops[0]+') - '+names[1]+'+('+ops[1]+')',calc,obs,esd]) 805 rowLabels.append(str(i)) 806 except ValueError: #patch - old restraints! 807 bondList = [] 807 808 bondTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) 808 809 Bonds = G2gd.GSGrid(BondRestr) … … 836 837 return 837 838 Angles.ClearSelection() 838 val = angleList[rows[0]][ 3]839 val = angleList[rows[0]][2] 839 840 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new value for angle',val,[0.,360.],'%.2f') 840 841 if dlg.ShowModal() == wx.ID_OK: 841 842 parm = dlg.GetValue() 842 843 for r in rows: 843 angle List[r][3] = parm844 angleRestData['Angles'][r][2] = parm 844 845 dlg.Destroy() 845 846 UpdateAngleRestr(angleRestData) … … 850 851 return 851 852 Angles.ClearSelection() 852 val = angleList[rows[0]][ 4]853 val = angleList[rows[0]][3] 853 854 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for angle',val,[0.,5.],'%.2f') 854 855 if dlg.ShowModal() == wx.ID_OK: 855 856 parm = dlg.GetValue() 856 857 for r in rows: 857 angle List[r][4] = parm858 angleRestData['Angles'][r][3] = parm 858 859 dlg.Destroy() 859 860 UpdateAngleRestr(angleRestData) … … 925 926 AngleRestr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1) 926 927 G2frame.dataFrame.SetSize(Size) 927 # G2frame.dataFrame.setSizePosLeft(Size)928 928 929 929 def UpdatePlaneRestr(planeRestData): … … 939 939 return 940 940 Planes.ClearSelection() 941 val = planeList[rows[0]][ 4]941 val = planeList[rows[0]][3] 942 942 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for plane',val,[0.,5.],'%.2f') 943 943 if dlg.ShowModal() == wx.ID_OK: 944 944 parm = dlg.GetValue() 945 945 for r in rows: 946 plane List[r][4] = parm946 planeRestData['Planes'][r][3] = parm 947 947 dlg.Destroy() 948 948 UpdatePlaneRestr(planeRestData) … … 1038 1038 return 1039 1039 Volumes.ClearSelection() 1040 val = volumeList[rows[0]][ 3]1040 val = volumeList[rows[0]][2] 1041 1041 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new value for chiral volume',val,[0.,360.],'%.2f') 1042 1042 if dlg.ShowModal() == wx.ID_OK: 1043 1043 parm = dlg.GetValue() 1044 1044 for r in rows: 1045 volumeList[r][3] = parm1045 chiralRestData['Volumes'][r][2] = parm 1046 1046 dlg.Destroy() 1047 1047 UpdateChiralRestr(chiralRestData) … … 1052 1052 return 1053 1053 Volumes.ClearSelection() 1054 val = volumeList[rows[0]][ 4]1054 val = volumeList[rows[0]][3] 1055 1055 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for chiral volume',val,[0.,5.],'%.2f') 1056 1056 if dlg.ShowModal() == wx.ID_OK: 1057 1057 parm = dlg.GetValue() 1058 1058 for r in rows: 1059 volumeList[r][4] = parm1059 chiralRestData['Volumes'][r][3] = parm 1060 1060 dlg.Destroy() 1061 1061 UpdateChiralRestr(chiralRestData) … … 1117 1117 ChiralRestr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1) 1118 1118 G2frame.dataFrame.SetSize(Size) 1119 # G2frame.dataFrame.setSizePosLeft(Size)1120 1119 1121 1120 def UpdateTorsionRestr(torsionRestData): … … 1141 1140 parm = dlg.GetValue() 1142 1141 for r in rows: 1143 volumeList[r][4] = parm1142 torsionRestData['Torsions'][r][4] = parm 1144 1143 dlg.Destroy() 1145 1144 UpdateTorsionRestr(torsionRestData) … … 1211 1210 TorsionRestr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1) 1212 1211 G2frame.dataFrame.SetSize(Size) 1213 # G2frame.dataFrame.setSizePosLeft(Size)1214 1212 1215 1213 def UpdateRamaRestr(ramaRestData): … … 1230 1228 return 1231 1229 Ramas.ClearSelection() 1232 val = ramaList[rows[0]][ 5]1230 val = ramaList[rows[0]][4] 1233 1231 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for energy',val,[0.,5.],'%.2f') 1234 1232 if dlg.ShowModal() == wx.ID_OK: 1235 1233 parm = dlg.GetValue() 1236 1234 for r in rows: 1237 rama List[r][4] = parm1235 ramaRestData['Ramas'][r][4] = parm 1238 1236 dlg.Destroy() 1239 1237 UpdateRamaRestr(ramaRestData) … … 1331 1329 elif text == 'Chiral restraints': 1332 1330 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.RestraintMenu) 1333 G2frame.dataFrame.RestraintEdit.Enable(G2gd.wxID_RESTRAINTADD, True)1331 G2frame.dataFrame.RestraintEdit.Enable(G2gd.wxID_RESTRAINTADD,False) 1334 1332 G2frame.dataFrame.RestraintEdit.Enable(G2gd.wxID_RESRCHANGEVAL,True) 1335 1333 chiralRestData = restrData['Chiral']
Note: See TracChangeset
for help on using the changeset viewer.