Changeset 1097
- Timestamp:
- Oct 10, 2013 10:35:50 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIImath.py
r1096 r1097 752 752 XYZ[j] -= x 753 753 tor = getRestTorsion(XYZ,Amat) 754 p ,d1 = calcTorsionEnergy(tor,Coeff)754 p1,d1 = calcTorsionEnergy(tor,Coeff) 755 755 XYZ[j] += 2*x 756 756 tor = getRestTorsion(XYZ,Amat) 757 p ,d2 = calcTorsionEnergy(tor,Coeff)757 p2,d2 = calcTorsionEnergy(tor,Coeff) 758 758 XYZ[j] -= x 759 deriv[j][i] = ( d2-d1)/(2*dx)759 deriv[j][i] = (p2-p1)/(2*dx) 760 760 return deriv.flatten() 761 761 … … 824 824 XYZ[j] -= x 825 825 phi,psi = getRestRama(XYZ,Amat) 826 p ,d1 = calcRamaEnergy(phi,psi,Coeff)826 p1,d1 = calcRamaEnergy(phi,psi,Coeff) 827 827 XYZ[j] += 2*x 828 828 phi,psi = getRestRama(XYZ,Amat) 829 p ,d2 = calcRamaEnergy(phi,psi,Coeff)829 p2,d2 = calcRamaEnergy(phi,psi,Coeff) 830 830 XYZ[j] -= x 831 deriv[j][i] = ( d2-d1)/(2*dx)831 deriv[j][i] = (p2-p1)/(2*dx) 832 832 return deriv.flatten() 833 833 -
trunk/GSASIIphsGUI.py
r1076 r1097 1639 1639 PhaseName = rd.Phase['General']['Name'] 1640 1640 print 'Read phase '+str(PhaseName)+' from file '+str(G2frame.lastimport) 1641 print rd.Phase['Atoms'] 1641 atomData = data['Atoms'] 1642 for atom in rd.Phase['Atoms'][:5]: 1643 print atom 1644 for atom in atomData[:5]: 1645 print atom 1646 1642 1647 return 1643 1648 -
trunk/GSASIIrestrGUI.py
r1077 r1097 765 765 wtBox = wx.BoxSizer(wx.HORIZONTAL) 766 766 wtBox.Add(wx.StaticText(wind,-1,'Restraint weight factor:'),0,wx.ALIGN_CENTER_VERTICAL) 767 wtfactor = wx.TextCtrl(wind,-1,value='%.2f'%(restData['wtFactor']),style=wx.TE_PROCESS_ENTER )767 wtfactor = wx.TextCtrl(wind,-1,value='%.2f'%(restData['wtFactor']),style=wx.TE_PROCESS_ENTER,size=(50,20)) 768 768 wtfactor.Bind(wx.EVT_TEXT_ENTER,OnWtFactor) 769 769 wtfactor.Bind(wx.EVT_KILL_FOCUS,OnWtFactor) … … 775 775 if 'Bonds' in restData or 'Angles' in restData: 776 776 wtBox.Add(wx.StaticText(wind,-1,'Search range:'),0,wx.ALIGN_CENTER_VERTICAL) 777 sRange = wx.TextCtrl(wind,-1,value='%.2f'%(restData['Range']),style=wx.TE_PROCESS_ENTER )777 sRange = wx.TextCtrl(wind,-1,value='%.2f'%(restData['Range']),style=wx.TE_PROCESS_ENTER,size=(50,20)) 778 778 sRange.Bind(wx.EVT_TEXT_ENTER,OnRange) 779 779 sRange.Bind(wx.EVT_KILL_FOCUS,OnRange) … … 875 875 rowLabels = [] 876 876 bad = [] 877 chisq = 0. 877 878 Types = [wg.GRID_VALUE_STRING,]+4*[wg.GRID_VALUE_FLOAT+':10,3',] 878 879 if 'macro' in General['Type']: … … 886 887 XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3)) 887 888 calc = G2mth.getRestDist(XYZ,Amat) 889 chisq += bondRestData['wtFactor']*((obs-calc)/esd)**2 888 890 table.append([name[:-3],calc,obs,esd,(obs-calc)/esd]) 889 891 rowLabels.append(str(i)) … … 899 901 XYZ = G2mth.getSyXYZ(XYZ,ops,SGData) 900 902 calc = G2mth.getRestDist(XYZ,Amat) 903 chisq += bondRestData['wtFactor']*((obs-calc)/esd)**2 901 904 table.append([names[0]+'+('+ops[0]+') - '+names[1]+'+('+ops[1]+')',calc,obs,esd,(obs-calc)/esd]) 902 905 rowLabels.append(str(i)) … … 921 924 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) 922 925 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 926 mainSizer.Add(wx.StaticText(BondRestr,-1, 927 'Bond restraints: sum(wt*(delt/sig)^2) = %.2f, mean(wt*(delt/sig)^2) = %.2f' \ 928 %(chisq,chisq/len(bondList))),0,wx.ALIGN_CENTER_VERTICAL) 923 929 mainSizer.Add(Bonds,0,) 924 930 else: … … 996 1002 rowLabels = [] 997 1003 bad = [] 1004 chisq = 0. 998 1005 Types = [wg.GRID_VALUE_STRING,]+4*[wg.GRID_VALUE_FLOAT+':10,2',] 999 1006 if 'macro' in General['Type']: … … 1007 1014 XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3)) 1008 1015 calc = G2mth.getRestAngle(XYZ,Amat) 1016 chisq += angleRestData['wtFactor']*((obs-calc)/esd)**2 1009 1017 table.append([name[:-3],calc,obs,esd,(obs-calc)/esd]) 1010 1018 rowLabels.append(str(i)) … … 1022 1030 XYZ = G2mth.getSyXYZ(XYZ,ops,SGData) 1023 1031 calc = G2mth.getRestAngle(XYZ,Amat) 1032 chisq += angleRestData['wtFactor']*((obs-calc)/esd)**2 1024 1033 table.append([name,calc,obs,esd,(obs-calc)/esd]) 1025 1034 rowLabels.append(str(i)) … … 1044 1053 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) 1045 1054 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 1055 mainSizer.Add(wx.StaticText(AngleRestr,-1, 1056 'Angle restraints: sum(wt*(delt/sig)^2) = %.2f, mean(wt*(delt/sig)^2) = %.2f' \ 1057 %(chisq,chisq/len(angleList))),0,wx.ALIGN_CENTER_VERTICAL) 1046 1058 mainSizer.Add(Angles,0,) 1047 1059 else: … … 1110 1122 rowLabels = [] 1111 1123 bad = [] 1124 chisq = 0. 1112 1125 Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',] 1113 1126 if 'macro' in General['Type']: … … 1123 1136 XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3)) 1124 1137 calc = G2mth.getRestPlane(XYZ,Amat) 1138 chisq += planeRestData['wtFactor']*((calc)/esd)**2 1125 1139 table.append([name[:-3],calc,obs,esd]) 1126 1140 rowLabels.append(str(i)) … … 1136 1150 XYZ = G2mth.getSyXYZ(XYZ,ops,SGData) 1137 1151 calc = G2mth.getRestPlane(XYZ,Amat) 1152 chisq += planeRestData['wtFactor']*((calc)/esd)**2 1138 1153 name = '' 1139 1154 for a,atom in enumerate(atoms): … … 1163 1178 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1164 1179 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 1180 mainSizer.Add(wx.StaticText(PlaneRestr,-1, 1181 'Plane restraints: sum(wt*(delt/sig)^2) = %.2f, mean(wt*(delt/sig)^2) = %.2f' \ 1182 %(chisq,chisq/len(planeList))),0,wx.ALIGN_CENTER_VERTICAL) 1165 1183 mainSizer.Add(Planes,0,) 1166 1184 else: … … 1239 1257 rowLabels = [] 1240 1258 bad = [] 1259 chisq = 0. 1241 1260 Types = [wg.GRID_VALUE_STRING,]+4*[wg.GRID_VALUE_FLOAT+':10,2',] 1242 1261 if 'macro' in General['Type']: … … 1250 1269 XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3)) 1251 1270 calc = G2mth.getRestChiral(XYZ,Amat) 1271 chisq += chiralRestData['wtFactor']*((obs-calc)/esd)**2 1252 1272 table.append([name,calc,obs,esd,(obs-calc)/esd]) 1253 1273 rowLabels.append(str(i)) … … 1265 1285 XYZ = G2mth.getSyXYZ(XYZ,ops,SGData) 1266 1286 calc = G2mth.getRestChiral(XYZ,Amat) 1287 chisq += chiralRestData['wtFactor']*((obs-calc)/esd)**2 1267 1288 table.append([name,calc,obs,esd,(obs-calc)/esd]) 1268 1289 rowLabels.append(str(i)) … … 1287 1308 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) 1288 1309 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 1310 mainSizer.Add(wx.StaticText(ChiralRestr,-1, 1311 'Chiral volume restraints: sum(wt*(delt/sig)^2) = %.2f, mean(wt*(delt/sig)^2) = %.2f' \ 1312 %(chisq,chisq/len(volumeList))),0,wx.ALIGN_CENTER_VERTICAL) 1289 1313 mainSizer.Add(Volumes,0,) 1290 1314 else: … … 1321 1345 for row in rows: 1322 1346 torsionList.remove(torsionList[row]) 1323 UpdateTorsionRestr(torsionRestData)1347 wx.CallAfter(UpdateTorsionRestr,torsionRestData) 1324 1348 1325 1349 def OnChangeEsd(event): … … 1335 1359 torsionRestData['Torsions'][r][4] = parm 1336 1360 dlg.Destroy() 1337 UpdateTorsionRestr(torsionRestData)1361 wx.CallAfter(UpdateTorsionRestr,torsionRestData) 1338 1362 1339 1363 TorsionRestr.DestroyChildren() … … 1345 1369 coeffDict = torsionRestData['Coeff'] 1346 1370 torsionList = torsionRestData['Torsions'] 1347 mainSizer.Add(wx.StaticText(TorsionRestr,-1,'Torsion restraints:'),0,wx.ALIGN_CENTER_VERTICAL)1348 1371 if len(torsionList): 1349 1372 table = [] 1350 1373 rowLabels = [] 1351 1374 bad = [] 1375 chisq = 0. 1352 1376 Types = 2*[wg.GRID_VALUE_STRING,]+4*[wg.GRID_VALUE_FLOAT+':10,2',] 1353 1377 if 'macro' in General['Type']: … … 1362 1386 tor = G2mth.getRestTorsion(XYZ,Amat) 1363 1387 restr,calc = G2mth.calcTorsionEnergy(tor,coeffDict[cofName]) 1388 chisq += torsionRestData['wtFactor']*(restr/esd)**2 1364 1389 table.append([name,cofName,tor,calc,restr,esd]) 1365 1390 rowLabels.append(str(i)) … … 1383 1408 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1384 1409 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 1410 mainSizer.Add(wx.StaticText(TorsionRestr,-1, 1411 'Torsion restraints: sum(wt*(delt/sig)^2) = %.2f, mean(wt*(delt/sig)^2) = %.2f' \ 1412 %(chisq,chisq/len(torsionList))),0,wx.ALIGN_CENTER_VERTICAL) 1385 1413 mainSizer.Add(Torsions,0,) 1386 1414 … … 1465 1493 rowLabels = [] 1466 1494 bad = [] 1495 chisq = 0. 1467 1496 Types = 2*[wg.GRID_VALUE_STRING,]+5*[wg.GRID_VALUE_FLOAT+':10,2',] 1468 1497 if 'macro' in General['Type']: … … 1477 1506 phi,psi = G2mth.getRestRama(XYZ,Amat) 1478 1507 restr,calc = G2mth.calcRamaEnergy(phi,psi,coeffDict[cofName]) 1508 chisq += ramaRestData['wtFactor']*(restr/esd)**2 1479 1509 table.append([name,cofName,phi,psi,calc,restr,esd]) 1480 1510 rowLabels.append(str(i)) … … 1498 1528 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1499 1529 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 1530 mainSizer.Add(wx.StaticText(RamaRestr,-1, 1531 'Ramachandran restraints: sum(wt*(delt/sig)^2) = %.2f, mean(wt*(delt/sig)^2) = %.2f' \ 1532 %(chisq,chisq/len(ramaList))),0,wx.ALIGN_CENTER_VERTICAL) 1500 1533 mainSizer.Add(Ramas,0,) 1501 1534 else: … … 1596 1629 rowLabels = [] 1597 1630 bad = [] 1631 chisq = 0. 1598 1632 Types = [wg.GRID_VALUE_STRING,]+5*[wg.GRID_VALUE_FLOAT+':10,2',] 1599 1633 colLabels = ['Atoms','mul*frac','factor','calc','obs','esd'] … … 1605 1639 mulfrac = mul*frac 1606 1640 calcs = mul*frac*factors 1641 chisq += chiralRestData['wtFactor']*((obs-np.sum(calcs))/esd)**2 1607 1642 for iatm,[atom,mf,fr,clc] in enumerate(zip(atoms,mulfrac,factors,calcs)): 1608 1643 table.append([atom,mf,fr,clc,'','']) … … 1642 1677 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 1643 1678 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) 1679 mainSizer.Add(wx.StaticText(ChemCompRestr,-1, 1680 'Chemical composition restraints: sum(wt*(delt/sig)^2) = %.2f, mean(wt*(delt/sig)^2) = %.2f' \ 1681 %(chisq,chisq/len(chemcompList))),0,wx.ALIGN_CENTER_VERTICAL) 1644 1682 mainSizer.Add(ChemComps,0,) 1645 1683 else: -
trunk/GSASIIstrMath.py
r1092 r1097 356 356 phi,psi = G2mth.getRestRama(XYZ,Amat) 357 357 restr,calc = G2mth.calcRamaEnergy(phi,psi,coeffDict[cofName]) 358 pVals.append( obs-calc)358 pVals.append(restr) 359 359 pWt.append(wt/esd**2) 360 pWsum[name] += wt*( (obs-calc)/esd)**2360 pWsum[name] += wt*(restr/esd)**2 361 361 elif name == 'ChemComp': 362 362 for i,[indx,factors,obs,esd] in enumerate(itemRest[rest]): … … 2003 2003 pSum = np.sum(pWt*pVals**2) 2004 2004 for name in pWsum: 2005 print ' Penalty function for % s = %.3f'%(name,pWsum[name])2005 print ' Penalty function for %8s = %.3f'%(name,pWsum[name]) 2006 2006 print 'Total penalty function: %.3f on %d terms'%(pSum,len(pVals)) 2007 2007 Nobs += len(pVals)
Note: See TracChangeset
for help on using the changeset viewer.