Changeset 822
- Timestamp:
- Jan 7, 2013 4:13:44 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIImath.py
r820 r822 313 313 return sum,Eval 314 314 315 def getRestRama(XYZ,Amat,Coeff=[]): 315 def getTorsionDeriv(XYZ,Amat,Coeff): 316 deriv = np.zeros((len(XYZ),3)) 317 dx = 0.00001 318 for j,xyz in enumerate(XYZ): 319 for i,x in enumerate(np.array([[dx,0,0],[0,dx,0],[0,0,dx]])): 320 XYZ[j] += x 321 tor = getRestTorsion(XYZ,Amat) 322 p,d1 = calcTorsionEnergy(tor,Coeff) 323 XYZ[j] -= 2*x 324 tor = getRestTorsion(XYZ,Amat) 325 p,d2 = calcTorsionEnergy(tor,Coeff) 326 XYZ[j] += x 327 deriv[j][i] = (d1-d2)/(2*dx) 328 return deriv.flatten() 329 330 def getRestRama(XYZ,Amat): 316 331 phi = getRestTorsion(XYZ[:5],Amat) 317 332 psi = getRestTorsion(XYZ[1:],Amat) … … 334 349 sum = Eval-pMax 335 350 return sum,Eval 351 352 def getRamaDeriv(XYZ,Amat,Coeff): 353 deriv = np.zeros((len(XYZ),3)) 354 dx = 0.00001 355 for j,xyz in enumerate(XYZ): 356 for i,x in enumerate(np.array([[dx,0,0],[0,dx,0],[0,0,dx]])): 357 XYZ[j] += x 358 phi,psi = getRestRama(XYZ,Amat) 359 p,d1 = calcRamaEnergy(phi,psi,Coeff) 360 XYZ[j] -= 2*x 361 phi,psi = getRestRama(XYZ,Amat) 362 p,d2 = calcRamaEnergy(phi,psi,Coeff) 363 XYZ[j] += x 364 deriv[j][i] = (d1-d2)/(2*dx) 365 return deriv.flatten() 336 366 337 367 def getDistDerv(Oxyz,Txyz,Amat,Tunit,Top,SGData): -
trunk/GSASIIrestrGUI.py
r820 r822 50 50 if 'Rama' not in restrData: 51 51 restrData['Rama'] = {'wtFactor':1.0,'Coeff':{},'Ramas':[],'Use':True} 52 if 'Texture' not in restrData: 53 restrData['Texture'] = {'wtFactor':1.0,'HKLs':[],'Use':True} 54 if 'ChemComp' not in restrData: 55 restrData['ChemComp'] = {'wtFactor':1.0,'Sites':[],'Use':True} 52 56 General = phasedata['General'] 53 57 Cell = General['Cell'][1:7] #skip flag & volume 54 58 Amat,Bmat = G2lat.cell2AB(Cell) 55 59 SGData = General['SGData'] 56 cx,ct = General['AtomPtrs'][:2]60 cx,ct,cs = General['AtomPtrs'][:3] 57 61 Atoms = phasedata['Atoms'] 58 62 AtLookUp = G2mth.FillAtomLookUp(Atoms) … … 168 172 elif 'Plane' in G2frame.dataDisplay.GetPageText(page): 169 173 AddPlaneRestraint(restrData['Plane']) 174 elif 'Chem' in G2frame.dataDisplay.GetPageText(page): 175 AddChemCompRestraint(restrData['ChemComp']) 170 176 171 177 def OnAddAARestraint(event): … … 199 205 else: 200 206 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,[0.01,4.],'%.4f') 203 if dlg.ShowModal() == wx.ID_OK: 204 bond = dlg.GetValue() 205 dlg.Destroy() 207 else: 208 break 209 if len(Lists['origin']) and len(Lists['target']): 210 bond = 1.54 211 dlg = G2phG.SingleFloatDialog(G2frame,'Distance','Enter restraint distance for bond',bond,[0.01,4.],'%.4f') 212 if dlg.ShowModal() == wx.ID_OK: 213 bond = dlg.GetValue() 214 dlg.Destroy() 206 215 Factor = bondRestData['Range'] 207 216 indices = (-1,0,1) … … 283 292 UpdateBondRestr(bondRestData) 284 293 294 # def AddAngleRestraint(angleRestData): 295 # Radii = dict(zip(General['AtomTypes'],zip(General['BondRadii'],General['AngleRadii']))) 296 # origAtoms = [] 297 # dlg = wx.MultiChoiceDialog(G2frame,'Select atom B for angle A-B-C for '+General['Name'], 298 # 'Select angle restraint origin atoms',Names) 299 # if dlg.ShowModal() == wx.ID_OK: 300 # sel = dlg.GetSelections() 301 # for x in sel: 302 # if 'all' in Names[x]: 303 # allType = Types[x] 304 # for name,Type,coords,id in zip(Names,Types,Coords,Ids): 305 # if Type == allType and 'all' not in name: 306 # origAtoms.append([id,Type,coords]) 307 # else: 308 # origAtoms.append([Ids[x],Types[x],Coords[x]]) 309 # targAtoms = [[Ids[x+iBeg],Types[x+iBeg],Coords[x+iBeg]] for x in range(len(Names[iBeg:]))] 310 # value = 109.54 311 # dlg = G2phG.SingleFloatDialog(G2frame,'Angle','Enter restraint angle ',value,[30.,180.],'%.2f') 312 # if dlg.ShowModal() == wx.ID_OK: 313 # value = dlg.GetValue() 314 # dlg.Destroy() 315 # 316 # Factor = angleRestData['Range'] 317 # indices = (-1,0,1) 318 # Units = np.array([[h,k,l] for h in indices for k in indices for l in indices]) 319 # VectA = [] 320 # for Oid,Otype,Ocoord in origAtoms: 321 # IndBlist = [] 322 # VectB = [] 323 # for Tid,Ttype,Tcoord in targAtoms: 324 # result = G2spc.GenAtom(Tcoord,SGData,False,Move=False) 325 # BsumR = (Radii[Otype][0]+Radii[Ttype][0])*Factor 326 # AsumR = (Radii[Otype][1]+Radii[Ttype][1])*Factor 327 # for Txyz,Top,Tunit in result: 328 # Dx = (Txyz-Ocoord)+Units 329 # dx = np.inner(Amat,Dx) 330 # dist = ma.masked_less(np.sqrt(np.sum(dx**2,axis=0)),0.5) 331 # IndB = ma.nonzero(ma.masked_greater(dist-BsumR,0.)) 332 # if np.any(IndB): 333 # for indb in IndB: 334 # for i in range(len(indb)): 335 # if str(dx.T[indb][i]) not in IndBlist: 336 # IndBlist.append(str(dx.T[indb][i])) 337 # unit = Units[indb][i]+Tunit 338 # if np.any(unit): 339 # Topstr = '%d+%d,%d,%d'%(Top,unit[0],unit[1],unit[2]) 340 # else: 341 # Topstr = str(Top) 342 # tunit = '[%2d%2d%2d]'%(unit[0]+Tunit[0],unit[1]+Tunit[1],unit[2]+Tunit[2]) 343 # Dist = ma.getdata(dist[indb])[i] 344 # if (Dist-AsumR) <= 0.: 345 # VectB.append([Oid,'1',Ocoord,Tid,Topstr,Tcoord,Dist]) 346 # VectA.append(VectB) 347 # for Vects in VectA: 348 # for i,vecta in enumerate(Vects): 349 # for vectb in Vects[:i]: 350 # ids = [vecta[3],vecta[0],vectb[3]] 351 # ops = [vecta[4],vecta[1],vectb[4]] 352 # XYZ = np.array([vecta[5],vecta[2],vectb[5]]) 353 # angle = [ids,ops,value,1.0] 354 # if angle not in angleRestData['Angles']: 355 # angleRestData['Angles'].append(angle) 356 # UpdateAngleRestr(angleRestData) 357 285 358 def AddAngleRestraint(angleRestData): 286 359 Radii = dict(zip(General['AtomTypes'],zip(General['BondRadii'],General['AngleRadii']))) 287 origAtoms = [] 288 dlg = wx.MultiChoiceDialog(G2frame,'Select atom B for angle A-B-C for '+General['Name'], 289 'Select angle restraint origin atoms',Names) 290 if dlg.ShowModal() == wx.ID_OK: 291 sel = dlg.GetSelections() 292 for x in sel: 293 if 'all' in Names[x]: 294 allType = Types[x] 295 for name,Type,coords,id in zip(Names,Types,Coords,Ids): 296 if Type == allType and 'all' not in name: 297 origAtoms.append([id,Type,coords]) 298 else: 299 origAtoms.append([Ids[x],Types[x],Coords[x]]) 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() 360 Lists = {'A-atom':[],'B-atom':[],'C-atom':[]} 361 for listName in ['A-atom','B-atom']: 362 dlg = wx.MultiChoiceDialog(G2frame,'Select '+listName+' for angle A-B-C for '+General['Name'] , 363 'Select angle restraint '+listName,Names) 364 if dlg.ShowModal() == wx.ID_OK: 365 sel = dlg.GetSelections() 366 for x in sel: 367 if 'all' in Names[x]: 368 allType = Types[x] 369 for name,Type,coords,id in zip(Names,Types,Coords,Ids): 370 if Type == allType and 'all' not in name: 371 if 'A' in listName: 372 Lists[listName].append(Type) 373 else: 374 Lists[listName].append([id,Type,coords]) 375 else: 376 if 'A' in listName: 377 Lists[listName].append(Types[x]) 378 else: 379 Lists[listName].append([Ids[x],Types[x],Coords[x],]) 380 else: 381 break 382 targAtoms = [[Ids[x+iBeg],Types[x+iBeg],Coords[x+iBeg]] for x in range(len(Names[iBeg:]))] 383 if len(Lists['B-atom']): 384 value = 109.54 385 dlg = G2phG.SingleFloatDialog(G2frame,'Angle','Enter restraint angle ',value,[30.,180.],'%.2f') 386 if dlg.ShowModal() == wx.ID_OK: 387 value = dlg.GetValue() 388 dlg.Destroy() 306 389 307 390 Factor = angleRestData['Range'] … … 309 392 Units = np.array([[h,k,l] for h in indices for k in indices for l in indices]) 310 393 VectA = [] 311 for Oid,Otype,Ocoord in origAtoms:394 for Oid,Otype,Ocoord in Lists['B-atom']: 312 395 IndBlist = [] 313 396 VectB = [] … … 320 403 dx = np.inner(Amat,Dx) 321 404 dist = ma.masked_less(np.sqrt(np.sum(dx**2,axis=0)),0.5) 322 IndB = ma.nonzero(ma.masked_greater(dist -BsumR,0.))405 IndB = ma.nonzero(ma.masked_greater(dist,BsumR)) 323 406 if np.any(IndB): 324 407 for indb in IndB: … … 331 414 else: 332 415 Topstr = str(Top) 333 tunit = '[%2d%2d%2d]'%(unit[0]+Tunit[0],unit[1]+Tunit[1],unit[2]+Tunit[2]) 334 Dist = ma.getdata(dist[indb])[i] 335 if (Dist-AsumR) <= 0.: 336 VectB.append([Oid,'1',Ocoord,Tid,Topstr,Tcoord,Dist]) 416 Dist = ma.getdata(dist[indb])[i] 417 if (Dist-AsumR) <= 0.: 418 VectB.append([Oid,'1',Ocoord,Ttype,Tid,Topstr,Tcoord,Dist]) 337 419 VectA.append(VectB) 338 for Vects in VectA: 339 for i,vecta in enumerate(Vects): 340 for vectb in Vects[:i]: 341 ids = [vecta[3],vecta[0],vectb[3]] 342 ops = [vecta[4],vecta[1],vectb[4]] 343 XYZ = np.array([vecta[5],vecta[2],vectb[5]]) 420 for Vects in VectA: 421 for i,vecta in enumerate(Vects): 422 for vectb in Vects[:i]: 423 if vecta[3] in Lists['A-atom']: 424 ids = [vecta[4],vecta[0],vectb[4]] 425 ops = [vecta[5],vecta[1],vectb[5]] 426 XYZ = np.array([vecta[6],vecta[2],vectb[6]]) 344 427 angle = [ids,ops,value,1.0] 345 428 if angle not in angleRestData['Angles']: … … 660 743 macStr = macro.readline() 661 744 macro.close() 662 UpdateRamaRestr(ramaRestData) 745 UpdateRamaRestr(ramaRestData) 746 747 def AddChemCompRestraint(chemcompRestData): 748 ids = [] 749 factors = [] 750 dlg = wx.MultiChoiceDialog(G2frame,'Select atoms for chemical restraint in '+General['Name'], 751 'Select atoms',Names) 752 if dlg.ShowModal() == wx.ID_OK: 753 sel = dlg.GetSelections() 754 for x in sel: 755 if 'all' in Names[x]: 756 allType = Types[x] 757 for name,Type,id in zip(Names,Types,Ids): 758 if Type == allType and 'all' not in name: 759 ids.append(id) 760 factors.append(1.0) 761 else: 762 ids.append(Ids[x]) 763 factors.append(1.0) 764 dlg.Destroy() 765 if len(ids) > 2: 766 value = 1.0 767 dlg = G2phG.SingleFloatDialog(G2frame,'Angle','Enter unit cell sum ',value,[-1.e6,1.e6],'%.2f') 768 if dlg.ShowModal() == wx.ID_OK: 769 value = dlg.GetValue() 770 comp = [ids,factors,value,0.01] 771 if comp not in chemcompRestData['Sites']: 772 chemcompRestData['Sites'].append(comp) 773 UpdateChemcompRestr(chemcompRestData) 774 else: 775 print '**** ERROR - not enough atoms for a composition restraint - try again ****' 776 777 def AddTextureRestraint(textureRestData): 778 print 'Add texture restraint' 663 779 664 780 def WtBox(wind,restData): … … 729 845 Obj.ClearSelection() 730 846 Obj.SelectRow(r,True) 847 731 848 732 849 def UpdateBondRestr(bondRestData): 733 850 851 def OnCellChange(event): 852 r,c = event.GetRow(),event.GetCol() 853 val = bondRestData['Bonds'][r][c] 854 try: 855 new = float(bondTable.GetValue(r,c)) 856 if new <= 0.: 857 raise ValueError 858 bondRestData['Bonds'][r][c] = new 859 except ValueError: 860 pass 861 wx.CallAfter(UpdateBondRestr,bondRestData) 862 734 863 def OnChangeValue(event): 735 864 rows = Bonds.GetSelectedRows() … … 826 955 Bonds.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 827 956 Bonds.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK,OnRowSelect) 957 Bonds.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 828 958 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 829 959 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) … … 843 973 def UpdateAngleRestr(angleRestData): 844 974 975 def OnCellChange(event): 976 r,c = event.GetRow(),event.GetCol() 977 val = angleRestData['Angles'][r][c] 978 try: 979 new = float(angleTable.GetValue(r,c)) 980 if new <= 0. or new > 180.: 981 raise ValueError 982 angleRestData['Angles'][r][c] = new 983 except ValueError: 984 pass 985 wx.CallAfter(UpdateAngleRestr,angleRestData) 986 845 987 def OnChangeValue(event): 846 988 rows = Angles.GetSelectedRows() … … 936 1078 Angles.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 937 1079 Angles.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK,OnRowSelect) 1080 Angles.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 938 1081 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 939 1082 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) … … 958 1101 item.Enable(False) 959 1102 1103 def OnCellChange(event): 1104 r,c = event.GetRow(),event.GetCol() 1105 val = planeRestData['Planes'][r][c] 1106 try: 1107 new = float(planeTable.GetValue(r,c)) 1108 if new <= 0.: 1109 raise ValueError 1110 planeRestData['Planes'][r][c] = new 1111 except ValueError: 1112 pass 1113 wx.CallAfter(UpdatePlaneRestr,planeRestData) 1114 960 1115 def OnChangeEsd(event): 961 1116 rows = Planes.GetSelectedRows() … … 1043 1198 Planes.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1044 1199 Planes.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK,OnRowSelect) 1200 Planes.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1045 1201 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1046 1202 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) … … 1060 1216 def UpdateChiralRestr(chiralRestData): 1061 1217 1218 def OnCellChange(event): 1219 r,c = event.GetRow(),event.GetCol() 1220 val = chiralRestData['Volumes'][r][c] 1221 try: 1222 new = float(volumeTable.GetValue(r,c)) 1223 if new <= 0.: 1224 raise ValueError 1225 chiralRestData['Volumes'][r][c] = new 1226 except ValueError: 1227 pass 1228 wx.CallAfter(UpdateChiralRestr,chiralRestData) 1229 1062 1230 def OnDeleteRestraint(event): 1063 1231 rows = Volumes.GetSelectedRows() … … 1153 1321 Volumes.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1154 1322 Volumes.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK,OnRowSelect) 1323 Volumes.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1155 1324 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1156 1325 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) … … 1170 1339 def UpdateTorsionRestr(torsionRestData): 1171 1340 1341 def OnCellChange(event): 1342 r,c = event.GetRow(),event.GetCol() 1343 val = torsionRestData['Torsions'][r][c] 1344 try: 1345 new = float(torsionTable.GetValue(r,c)) 1346 if new <= 0. or new > 5.: 1347 raise ValueError 1348 torsionRestData['Torsions'][r][3] = new #only esd is editable 1349 except ValueError: 1350 pass 1351 wx.CallAfter(UpdateTorsionRestr,torsionRestData) 1352 1172 1353 def OnDeleteRestraint(event): 1173 1354 rows = Torsions.GetSelectedRows() … … 1233 1414 Torsions.AutoSizeColumns(False) 1234 1415 for r in range(len(torsionList)): 1235 for c in range( 2):1416 for c in range(5): 1236 1417 Torsions.SetReadOnly(r,c,True) 1237 1418 Torsions.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1238 1419 Torsions.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK,OnRowSelect) 1420 Torsions.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1239 1421 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1240 1422 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) … … 1272 1454 def UpdateRamaRestr(ramaRestData): 1273 1455 1456 def OnCellChange(event): 1457 r,c = event.GetRow(),event.GetCol() 1458 val = ramaRestData['Ramas'][r][c] 1459 try: 1460 new = float(ramaTable.GetValue(r,c)) 1461 if new <= 0. or new > 5.: 1462 raise ValueError 1463 ramaRestData['Ramas'][r][4] = new #only esd is editable 1464 except ValueError: 1465 pass 1466 wx.CallAfter(UpdateRamaRestr,ramaRestData) 1467 1274 1468 def OnDeleteRestraint(event): 1275 1469 rows = Ramas.GetSelectedRows() … … 1335 1529 Ramas.AutoSizeColumns(False) 1336 1530 for r in range(len(ramaList)): 1337 for c in range( 2):1531 for c in range(6): 1338 1532 Ramas.SetReadOnly(r,c,True) 1339 1533 Ramas.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1340 1534 Ramas.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK,OnRowSelect) 1535 Ramas.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1341 1536 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1342 1537 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) … … 1372 1567 RamaRestr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1) 1373 1568 G2frame.dataFrame.SetSize(Size) 1374 # G2frame.dataFrame.setSizePosLeft(Size) 1569 1570 def UpdateChemcompRestr(chemcompRestData): 1571 1572 def OnCellChange(event): 1573 r,c = event.GetRow(),event.GetCol() 1574 rowLabl = ChemComps.GetRowLabelValue(r) 1575 row = int(rowLabl.split(':')[1]) 1576 if 'Restr' in rowLabl: 1577 try: 1578 new = float(chemcompTable.GetValue(r,c)) 1579 chemcompRestData['Sites'][row][c-2] = new #obsd or esd 1580 except ValueError: 1581 pass 1582 else: 1583 try: 1584 new = float(chemcompTable.GetValue(r,c)) 1585 id = int(rowLabl.split(':')[2]) 1586 chemcompRestData['Sites'][row][1][id] = new #only factor 1587 except ValueError: 1588 pass 1589 wx.CallAfter(UpdateChemcompRestr,chemcompRestData) 1590 1591 def OnDeleteRestraint(event): 1592 r = ChemComps.GetSelectedRows()[0] 1593 if not rows: 1594 return 1595 rowLabl = ChemComps.GetRowLabelValue(r) 1596 row = int(rowLabl.split(':')[1]) 1597 if 'Restr' in rowLabl: 1598 del chemcompList[row] 1599 else: 1600 term = int(rowLabl.split(':')[2]) 1601 del chemcompList[row][0][term] 1602 del chemcompList[row][1][term] 1603 UpdateChemcompRestr(chemcompRestData) 1604 1605 def OnChangeValue(event): 1606 rows = ChemComps.GetSelectedRows() 1607 if not rows: 1608 return 1609 ChemComps.ClearSelection() 1610 dlg = G2phG.SingleFloatDialog(G2frame,'New value', 1611 'Enter new value for restraint multiplier',1.0,[-1.e6,1.e6],'%.2f') 1612 if dlg.ShowModal() == wx.ID_OK: 1613 parm = dlg.GetValue() 1614 for r in rows: 1615 rowLabl = ChemComps.GetRowLabelValue(r) 1616 if 'term' in rowLabl: 1617 items = rowLabl.split(':') 1618 chemcompRestData['Sites'][int(items[1])][1][int(items[2])] = parm 1619 dlg.Destroy() 1620 UpdateChemcompRestr(chemcompRestData) 1621 1622 ChemCompRestr.DestroyChildren() 1623 dataDisplay = wx.Panel(ChemCompRestr) 1624 mainSizer = wx.BoxSizer(wx.VERTICAL) 1625 mainSizer.Add((5,5),0) 1626 mainSizer.Add(WtBox(ChemCompRestr,chemcompRestData),0,wx.ALIGN_CENTER_VERTICAL) 1627 mainSizer.Add(wx.StaticText(ChemCompRestr,-1, 1628 'NB: The chemical restraint sum is over the unit cell contents'),0,wx.ALIGN_CENTER_VERTICAL) 1629 mainSizer.Add((5,5),0) 1630 1631 chemcompList = chemcompRestData['Sites'] 1632 if len(chemcompList): 1633 table = [] 1634 rowLabels = [] 1635 bad = [] 1636 Types = [wg.GRID_VALUE_STRING,]+5*[wg.GRID_VALUE_FLOAT+':10,2',] 1637 colLabels = ['Atoms','mul*frac','factor','calc','obs','esd'] 1638 for i,[indx,factors,obs,esd] in enumerate(chemcompList): 1639 try: 1640 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 1641 mul = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cs+1)) 1642 frac = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cs-1)) 1643 mulfrac = mul*frac 1644 calcs = mul*frac*factors 1645 for iatm,[atom,mf,fr,clc] in enumerate(zip(atoms,mulfrac,factors,calcs)): 1646 table.append([atom,mf,fr,clc,'','']) 1647 rowLabels.append('term:'+str(i)+':'+str(iatm)) 1648 table.append(['Sum','','',np.sum(calcs),obs,esd]) 1649 rowLabels.append('Restr:'+str(i)) 1650 except KeyError: 1651 print '**** WARNING - missing atom - restraint deleted ****' 1652 bad.append(i) 1653 if len(bad): 1654 bad.reverse() 1655 for ibad in bad: 1656 del chemcompList[ibad] 1657 chemcompTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) 1658 ChemComps = G2gd.GSGrid(ChemCompRestr) 1659 ChemComps.SetTable(chemcompTable, True) 1660 ChemComps.AutoSizeColumns(False) 1661 for r in range(chemcompTable.GetNumberRows()): 1662 for c in range(2): 1663 ChemComps.SetReadOnly(r,c,True) 1664 ChemComps.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1665 if 'Restr' in ChemComps.GetRowLabelValue(r): 1666 for c in range(4): 1667 ChemComps.SetReadOnly(r,c,True) 1668 ChemComps.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1669 for c in [1,2]: 1670 ChemComps.SetCellTextColour(r,c,VERY_LIGHT_GREY) 1671 else: 1672 for c in [3,4,5]: 1673 ChemComps.SetReadOnly(r,c,True) 1674 ChemComps.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1675 for c in [4,5]: 1676 ChemComps.SetCellTextColour(r,c,VERY_LIGHT_GREY) 1677 1678 1679 ChemComps.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK,OnRowSelect) 1680 ChemComps.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1681 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1682 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) 1683 mainSizer.Add(ChemComps,0,) 1684 else: 1685 mainSizer.Add(wx.StaticText(ChemCompRestr,-1,'No chemical composition restraints for this phase'),0,) 1686 1687 ChemCompRestr.SetSizer(mainSizer) 1688 Size = mainSizer.Fit(G2frame.dataFrame) 1689 Size[0] = 600 1690 Size[1] += 50 #make room for tab 1691 ChemCompRestr.SetSize(Size) 1692 ChemCompRestr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1) 1693 G2frame.dataFrame.SetSize(Size) 1694 1695 1696 def UpdateTextureRestr(textureRestData): 1697 1698 def OnCellChange(event): 1699 r,c = event.GetRow(),event.GetCol() 1700 val = chiralRestData['Volumes'][r][c] 1701 try: 1702 new = float(volumeTable.GetValue(r,c)) 1703 if new <= 0.: 1704 raise ValueError 1705 chiralRestData['Volumes'][r][c] = new 1706 except ValueError: 1707 pass 1708 wx.CallAfter(UpdateChiralRestr,chiralRestData) 1709 1710 pass 1375 1711 1376 1712 def OnPageChanged(event): 1377 1713 page = event.GetSelection() 1378 1714 text = G2frame.dataDisplay.GetPageText(page) 1715 G2frame.dataFrame.RestraintEdit.SetLabel(G2gd.wxID_RESRCHANGEVAL,'Change value') 1379 1716 if text == 'Bond restraints': 1380 1717 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.RestraintMenu) … … 1416 1753 UpdateRamaRestr(ramaRestData) 1417 1754 G2plt.PlotRama(G2frame,phaseName,rama,ramaName) 1755 elif text == 'Chem. comp. restraints': 1756 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.RestraintMenu) 1757 G2frame.dataFrame.RestraintEdit.Enable(G2gd.wxID_RESTRAINTADD,True) 1758 G2frame.dataFrame.RestraintEdit.SetLabel(G2gd.wxID_RESRCHANGEVAL,'Change factor') 1759 G2frame.dataFrame.RestraintEdit.Enable(G2gd.wxID_RESRCHANGEVAL,True) 1760 G2frame.dataFrame.RestraintEdit.Enable(G2gd.wxID_RESTCHANGEESD,False) 1761 chemcompRestData = restrData['ChemComp'] 1762 UpdateChemcompRestr(chemcompRestData) 1763 elif text == 'Texture restraints': 1764 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.RestraintMenu) 1765 G2frame.dataFrame.RestraintEdit.Enable(G2gd.wxID_RESTRAINTADD,True) 1766 G2frame.dataFrame.RestraintEdit.Enable(G2gd.wxID_RESRCHANGEVAL,True) 1767 textureRestData = restrData['Texture'] 1768 UpdateTextureRestr(textureRestData) 1769 1418 1770 event.Skip() 1419 1771 … … 1454 1806 RamaRestr = wx.ScrolledWindow(G2frame.dataDisplay) 1455 1807 G2frame.dataDisplay.AddPage(RamaRestr,'Ramachandran restraints') 1808 ChemCompRestr = wx.ScrolledWindow(G2frame.dataDisplay) 1809 G2frame.dataDisplay.AddPage(ChemCompRestr,'Chem. comp. restraints') 1810 TextureRestr = wx.ScrolledWindow(G2frame.dataDisplay) 1811 G2frame.dataDisplay.AddPage(TextureRestr,'Texture restraints') 1456 1812 1457 1813 UpdateBondRestr(restrData['Bond']) -
trunk/GSASIIstruct.py
r821 r822 2097 2097 deriv = G2mth.getRestDeriv(G2mth.getRestChiral,XYZ,Amat,ops,SGData) 2098 2098 else: 2099 coeffDict = itemRest['Coeff'] 2100 for indx,ops,obs,esd in itemRest[id]: 2101 XYZ = np.array(G2mth.GetAtomCoordsByID(pId,parmDict,AtLookup,indx)) 2102 # if name == 'Torsion': 2103 # tor = G2mth.getRestTorsion(XYZ,Amat) 2104 # restr,calc = G2mth.calcTorsionEnergy(tor,coeffDict[cofName]) 2105 # else: 2106 # phi,psi = G2mth.getRestRama(XYZ,Amat) 2107 # restr,calc = G2mth.calcRamaEnergy(phi,psi,coeffDict[cofName]) 2099 coffDict = itemRest['Coeff'] 2100 indx,ops,cofName,esd = itemRest[names[name]][id] 2101 dNames = [] 2102 for ind in indx: 2103 dNames += [str(pId)+'::dA'+Xname+':'+str(AtLookup[ind]) for Xname in ['x','y','z']] 2104 XYZ = np.array(G2mth.GetAtomCoordsByID(pId,parmDict,AtLookup,indx)) 2105 if name == 'Torsion': 2106 deriv = G2mth.getTorsionDeriv(XYZ,Amat,coffDict[cofName]) 2107 else: 2108 deriv = G2mth.getRamaDeriv(XYZ,Amat,coffDict[cofName]) 2108 2109 for dName,drv in zip(dNames,deriv): 2109 2110 try:
Note: See TracChangeset
for help on using the changeset viewer.