Ignore:
Timestamp:
Jan 3, 2013 4:03:22 PM (12 years ago)
Author:
vondreele
Message:

restraints development - almost done
works for bonds, angles, planes & chiral volumes
not torsions or Rama.. yet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIrestrGUI.py

    r819 r820  
    200200                        Lists[listName].append([Ids[x],Types[x],Coords[x],])
    201201        bond = 1.54
    202         dlg = G2phG.SingleFloatDialog(G2frame,'Distance','Enter restraint distance for bond',bond,[1.,4.],'%.4f')
     202        dlg = G2phG.SingleFloatDialog(G2frame,'Distance','Enter restraint distance for bond',bond,[0.01,4.],'%.4f')
    203203        if dlg.ShowModal() == wx.ID_OK:
    204204            bond = dlg.GetValue()
     
    682682           
    683683        def OnUseData(event):
     684            Obj = event.GetEventObject()
    684685            restData['Use'] = Obj.GetValue()
    685686
     
    782783            table = []
    783784            rowLabels = []
     785            bad = []
    784786            Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,3',]
    785787            if 'macro' in General['Type']:
    786788                colLabels = ['(res) A - (res) B','calc','obs','esd']
    787789                for i,[indx,ops,obs,esd] in enumerate(bondList):
    788                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
    789                     name = ''
    790                     for atom in atoms:
    791                         name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' - '
    792                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    793                     calc = G2mth.getRestDist(XYZ,Amat)
    794                     table.append([name[:-3],calc,obs,esd])
    795                     rowLabels.append(str(i))               
     790                    try:
     791                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
     792                        name = ''
     793                        for atom in atoms:
     794                            name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' - '
     795                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     796                        calc = G2mth.getRestDist(XYZ,Amat)
     797                        table.append([name[:-3],calc,obs,esd])
     798                        rowLabels.append(str(i))               
     799                    except KeyError:
     800                        print '**** WARNING - missing atom - restraint deleted ****'
     801                        bad.append(i)
    796802            else:
    797803                colLabels = ['A+SymOp - B+SymOp','calc','obs','esd']
    798                 try:
    799                     for i,[indx,ops,obs,esd] in enumerate(bondList):
     804                for i,[indx,ops,obs,esd] in enumerate(bondList):
     805                    try:
    800806                        names = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1)
    801807                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     
    804810                        table.append([names[0]+'+('+ops[0]+') - '+names[1]+'+('+ops[1]+')',calc,obs,esd])
    805811                        rowLabels.append(str(i))
    806                 except ValueError:              #patch - old restraints!
    807                     bondList = []
     812                    except KeyError:
     813                        print '**** WARNING - missing atom - restraint deleted ****'
     814                        bad.append(i)
     815            if len(bad):
     816                bad.reverse()
     817                for ibad in bad:
     818                    del bondList[ibad]
    808819            bondTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    809820            Bonds = G2gd.GSGrid(BondRestr)
     
    880891            table = []
    881892            rowLabels = []
     893            bad = []
    882894            Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',]
    883895            if 'macro' in General['Type']:
    884896                colLabels = ['(res) A - (res) B - (res) C','calc','obs','esd']
    885897                for i,[indx,ops,obs,esd] in enumerate(angleList):
    886                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
    887                     name = ''
    888                     for atom in atoms:
    889                         name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' - '
    890                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    891                     calc = G2mth.getRestAngle(XYZ,Amat)
    892                     table.append([name[:-3],calc,obs,esd])
    893                     rowLabels.append(str(i))                               
     898                    try:
     899                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
     900                        name = ''
     901                        for atom in atoms:
     902                            name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' - '
     903                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     904                        calc = G2mth.getRestAngle(XYZ,Amat)
     905                        table.append([name[:-3],calc,obs,esd])
     906                        rowLabels.append(str(i))                               
     907                    except KeyError:
     908                        print '**** WARNING - missing atom - restraint deleted ****'
     909                        bad.append(i)
    894910            else:
    895911                colLabels = ['A+SymOp - B+SymOp - C+SymOp','calc','obs','esd']
    896912                for i,[indx,ops,obs,esd] in enumerate(angleList):
    897                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1)
    898                     name = atoms[0]+'+('+ops[0]+') - '+atoms[1]+'+('+ops[1]+') - '+atoms[2]+ \
    899                     '+('+ops[2]+')'
    900                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    901                     XYZ = G2mth.getSyXYZ(XYZ,ops,SGData)
    902                     calc = G2mth.getRestAngle(XYZ,Amat)
    903                     table.append([name,calc,obs,esd])
    904                     rowLabels.append(str(i))
     913                    try:
     914                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1)
     915                        name = atoms[0]+'+('+ops[0]+') - '+atoms[1]+'+('+ops[1]+') - '+atoms[2]+ \
     916                        '+('+ops[2]+')'
     917                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     918                        XYZ = G2mth.getSyXYZ(XYZ,ops,SGData)
     919                        calc = G2mth.getRestAngle(XYZ,Amat)
     920                        table.append([name,calc,obs,esd])
     921                        rowLabels.append(str(i))
     922                    except KeyError:
     923                        print '**** WARNING - missing atom - restraint deleted ****'
     924                        bad.append(i)
     925            if len(bad):
     926                bad.reverse()
     927                for ibad in bad:
     928                    del angleList[ibad]
    905929            angleTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    906930            Angles = G2gd.GSGrid(AngleRestr)
     
    968992            table = []
    969993            rowLabels = []
     994            bad = []
    970995            Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',]
    971996            if 'macro' in General['Type']:
    972997                colLabels = ['(res) atom','calc','obs','esd']
    973998                for i,[indx,ops,obs,esd] in enumerate(planeList):
    974                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
    975                     name = ''
    976                     for a,atom in enumerate(atoms):
    977                         name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' - '
    978                         if (a+1)%3 == 0:
    979                             name += '\n'
    980                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    981                     calc = G2mth.getRestPlane(XYZ,Amat)
    982                     table.append([name[:-3],calc,obs,esd])
    983                     rowLabels.append(str(i))
     999                    try:
     1000                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
     1001                        name = ''
     1002                        for a,atom in enumerate(atoms):
     1003                            name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' - '
     1004                            if (a+1)%3 == 0:
     1005                                name += '\n'
     1006                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     1007                        calc = G2mth.getRestPlane(XYZ,Amat)
     1008                        table.append([name[:-3],calc,obs,esd])
     1009                        rowLabels.append(str(i))
     1010                    except KeyError:
     1011                        print '**** WARNING - missing atom - restraint deleted ****'
     1012                        bad.append(i)
    9841013            else:                               
    9851014                colLabels = ['atom+SymOp','calc','obs','esd']
    9861015                for i,[indx,ops,obs,esd] in enumerate(planeList):
    987                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1)
    988                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    989                     XYZ = G2mth.getSyXYZ(XYZ,ops,SGData)
    990                     calc = G2mth.getRestPlane(XYZ,Amat)
    991                     name = ''
    992                     for a,atom in enumerate(atoms):
    993                         name += atom+'+ ('+ops[a]+'),'
    994                         if (a+1)%3 == 0:
    995                             name += '\n'
    996                     table.append([name[:-1],calc,obs,esd])
    997                     rowLabels.append(str(i))
     1016                    try:
     1017                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1)
     1018                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     1019                        XYZ = G2mth.getSyXYZ(XYZ,ops,SGData)
     1020                        calc = G2mth.getRestPlane(XYZ,Amat)
     1021                        name = ''
     1022                        for a,atom in enumerate(atoms):
     1023                            name += atom+'+ ('+ops[a]+'),'
     1024                            if (a+1)%3 == 0:
     1025                                name += '\n'
     1026                        table.append([name[:-1],calc,obs,esd])
     1027                        rowLabels.append(str(i))
     1028                    except KeyError:
     1029                        print '**** WARNING - missing atom - restraint deleted ****'
     1030                        bad.append(i)
     1031            if len(bad):
     1032                bad.reverse()
     1033                for ibad in bad:
     1034                    del planeList[ibad]
    9981035            planeTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    9991036            Planes = G2gd.GSGrid(PlaneRestr)
     
    10711108            table = []
    10721109            rowLabels = []
     1110            bad = []
    10731111            Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',]
    10741112            if 'macro' in General['Type']:
    10751113                colLabels = ['(res) O (res) A (res) B (res) C','calc','obs','esd']
    10761114                for i,[indx,ops,obs,esd] in enumerate(volumeList):
    1077                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
    1078                     name = ''
    1079                     for atom in atoms:
    1080                         name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' '
    1081                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    1082                     calc = G2mth.getRestChiral(XYZ,Amat)
    1083                     table.append([name,calc,obs,esd])
    1084                     rowLabels.append(str(i))
     1115                    try:
     1116                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
     1117                        name = ''
     1118                        for atom in atoms:
     1119                            name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' '
     1120                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     1121                        calc = G2mth.getRestChiral(XYZ,Amat)
     1122                        table.append([name,calc,obs,esd])
     1123                        rowLabels.append(str(i))
     1124                    except KeyError:
     1125                        print '**** WARNING - missing atom - restraint deleted ****'
     1126                        bad.append(i)
    10851127            else:
    10861128                colLabels = ['O+SymOp  A+SymOp  B+SymOp  C+SymOp)','calc','obs','esd']
    10871129                for i,[indx,ops,obs,esd] in enumerate(volumeList):
    1088                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1)
    1089                     name = atoms[0]+'+('+ops[0]+') '+atoms[1]+'+('+ops[1]+') '+atoms[2]+ \
    1090                         '+('+ops[2]+') '+atoms[3]+'+('+ops[3]+')'
    1091                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    1092                     XYZ = G2mth.getSyXYZ(XYZ,ops,SGData)
    1093                     calc = G2mth.getRestChiral(XYZ,Amat)
    1094                     table.append([name,calc,obs,esd])
    1095                     rowLabels.append(str(i))
     1130                    try:
     1131                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1)
     1132                        name = atoms[0]+'+('+ops[0]+') '+atoms[1]+'+('+ops[1]+') '+atoms[2]+ \
     1133                            '+('+ops[2]+') '+atoms[3]+'+('+ops[3]+')'
     1134                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     1135                        XYZ = G2mth.getSyXYZ(XYZ,ops,SGData)
     1136                        calc = G2mth.getRestChiral(XYZ,Amat)
     1137                        table.append([name,calc,obs,esd])
     1138                        rowLabels.append(str(i))
     1139                    except KeyError:
     1140                        print '**** WARNING - missing atom - restraint deleted ****'
     1141                        bad.append(i)
     1142            if len(bad):
     1143                bad.reverse()
     1144                for ibad in bad:
     1145                    del volumeList[ibad]
    10961146            volumeTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    10971147            Volumes = G2gd.GSGrid(ChiralRestr)
     
    11561206            table = []
    11571207            rowLabels = []
     1208            bad = []
    11581209            Types = 2*[wg.GRID_VALUE_STRING,]+4*[wg.GRID_VALUE_FLOAT+':10,2',]
    11591210            if 'macro' in General['Type']:
    11601211                colLabels = ['(res) A  B  C  D','coef name','torsion','obs E','restr','esd']
    11611212                for i,[indx,ops,cofName,esd] in enumerate(torsionList):
    1162                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
    1163                     name = '('+atoms[2][1]+atoms[2][0].strip()+atoms[2][2]+')'
    1164                     for atom in atoms:
    1165                         name += '  '+atom[3]
    1166                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    1167                     tor = G2mth.getRestTorsion(XYZ,Amat)
    1168                     restr,calc = G2mth.calcTorsionEnergy(tor,coeffDict[cofName])
    1169                     table.append([name,cofName,tor,calc,restr,esd])
    1170                     rowLabels.append(str(i))
     1213                    try:
     1214                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
     1215                        name = '('+atoms[2][1]+atoms[2][0].strip()+atoms[2][2]+')'
     1216                        for atom in atoms:
     1217                            name += '  '+atom[3]
     1218                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     1219                        tor = G2mth.getRestTorsion(XYZ,Amat)
     1220                        restr,calc = G2mth.calcTorsionEnergy(tor,coeffDict[cofName])
     1221                        table.append([name,cofName,tor,calc,restr,esd])
     1222                        rowLabels.append(str(i))
     1223                    except KeyError:
     1224                        print '**** WARNING - missing atom - restraint deleted ****'
     1225                        bad.append(i)
     1226            if len(bad):
     1227                bad.reverse()
     1228                for ibad in bad:
     1229                    del torsionList[ibad]
    11711230            torsionTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    11721231            Torsions = G2gd.GSGrid(TorsionRestr)
     
    12491308            table = []
    12501309            rowLabels = []
     1310            bad = []
    12511311            Types = 2*[wg.GRID_VALUE_STRING,]+5*[wg.GRID_VALUE_FLOAT+':10,2',]
    12521312            if 'macro' in General['Type']:
    12531313                colLabels = ['(res) A  B  C  D  E','coef name','phi','psi','obs E','restr','esd']
    12541314                for i,[indx,ops,cofName,esd] in enumerate(ramaList):
    1255                     atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
    1256                     name = '('+atoms[3][1]+atoms[3][0].strip()+atoms[3][2]+')'
    1257                     for atom in atoms:
    1258                         name += '  '+atom[3]
    1259                     XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
    1260                     phi,psi = G2mth.getRestRama(XYZ,Amat)
    1261                     restr,calc = G2mth.calcRamaEnergy(phi,psi,coeffDict[cofName])
    1262                     table.append([name,cofName,phi,psi,calc,restr,esd])
    1263                     rowLabels.append(str(i))
     1315                    try:
     1316                        atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4)
     1317                        name = '('+atoms[3][1]+atoms[3][0].strip()+atoms[3][2]+')'
     1318                        for atom in atoms:
     1319                            name += '  '+atom[3]
     1320                        XYZ = np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cx,3))
     1321                        phi,psi = G2mth.getRestRama(XYZ,Amat)
     1322                        restr,calc = G2mth.calcRamaEnergy(phi,psi,coeffDict[cofName])
     1323                        table.append([name,cofName,phi,psi,calc,restr,esd])
     1324                        rowLabels.append(str(i))
     1325                    except KeyError:
     1326                        print '**** WARNING - missing atom - restraint deleted ****'
     1327                        bad.append(i)
     1328            if len(bad):
     1329                bad.reverse()
     1330                for ibad in bad:
     1331                    del ramaList[ibad]
    12641332            ramaTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    12651333            Ramas = G2gd.GSGrid(RamaRestr)
Note: See TracChangeset for help on using the changeset viewer.