Changeset 4573
- Timestamp:
- Sep 21, 2020 3:43:06 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIIO.py
r4548 r4573 1159 1159 self.parmDict = {} 1160 1160 self.sigDict = {} 1161 self.fp = None 1161 1162 # updated in InitExport: 1162 1163 self.currentExportType = None # type of export that has been requested … … 1699 1700 :param str line: the text to be written. 1700 1701 ''' 1702 if self.fp is None: 1703 raise Exception('Attempt to Write without use of OpenFile') 1701 1704 self.fp.write(line+'\n') 1702 1705 … … 1707 1710 file object self.fp is closed. 1708 1711 ''' 1712 if self.fp is None: 1713 raise Exception('Attempt to CloseFile without use of OpenFile') 1709 1714 if self.fp == sys.stdout: return # debug mode 1710 1715 if fp is None: -
trunk/GSASIIconstrGUI.py
r4505 r4573 44 44 import GSASIIpy3 as G2py3 45 45 import GSASIIphsGUI as G2phG 46 import GSASIIIO as G2IO 46 47 import GSASIIscriptable as G2sc 47 48 VERY_LIGHT_GREY = wx.Colour(235,235,235) … … 2055 2056 Page2() 2056 2057 2058 if 'macromolecular' == rd.Phase['General']['Type']: 2059 # for PDB imports, lets see if a quick reformat of atoms list will work 2060 rd.Phase['Atoms'] = [a[3:] for a in rd.Phase['Atoms']] 2061 rd.Phase['General']['AtomPtrs'] = [i-3 for i in rd.Phase['General']['AtomPtrs']] 2062 rd.Phase['General']['Type'] = 'nuclear' 2057 2063 SetupDrawing(rd.Phase) # add information to reader object to allow plotting 2058 2064 atomlist = [atom[0] for atom in rd.Phase['Atoms']] … … 2267 2273 UpdateDraw() 2268 2274 2275 def onWriteXYZ(event): 2276 '''Writes selected atoms in a .xyz file for use in Avogadro, etc. 2277 ''' 2278 grid.completeEdits() 2279 center = np.array([0.,0.,0.]) 2280 count = 0 2281 for i in range(len(rd.Phase['RBselection'])): 2282 if rd.Phase['RBselection'][i]: 2283 count += 1 2284 center += rd.Phase['RBcoords'][i] 2285 if count: 2286 center /= count 2287 else: 2288 print('nothing selected') 2289 return 2290 obj = G2IO.ExportBaseclass(G2frame,'XYZ','.xyz') 2291 #obj.InitExport(None) 2292 if obj.ExportSelect(): # set export parameters; ask for file name 2293 return 2294 fp = obj.OpenFile() 2295 obj.Write(str(count)) 2296 obj.Write('') 2297 for i in range(len(rd.Phase['RBselection'])): 2298 if rd.Phase['RBselection'][i]: 2299 line = ' ' + rd.Phase['RBtypes'][i] 2300 for xyz in rd.Phase['RBcoords'][i]: 2301 line += ' ' + str(xyz) 2302 obj.Write(line) 2303 obj.CloseFile() 2304 #GSASIIpath.IPyBreak() 2305 2269 2306 def onAddVector(event): 2270 2307 '''Adds selected atoms as a new vector rigid body. … … 2381 2418 0,wx.ALL) 2382 2419 btnSizer.Add((-1,5)) 2420 btn = wx.Button(RBImpPnl, wx.ID_ANY, 'export as xyz') 2421 btn.Bind(wx.EVT_BUTTON,onWriteXYZ) 2422 btnSizer.Add(btn,0,wx.ALIGN_CENTER) 2423 btnSizer.Add((-1,10)) 2383 2424 btn = wx.Button(RBImpPnl, wx.ID_ANY, 'a Vector Body') 2384 2425 btn.Bind(wx.EVT_BUTTON,onAddVector) … … 2482 2523 else: 2483 2524 col = None 2525 return 2484 2526 finally: 2485 2527 dlg.Destroy() -
trunk/GSASIIctrlGUI.py
r4534 r4573 3470 3470 ''' 3471 3471 if not parent: parent = G2frame 3472 #if GSASIIpath.GetConfigValue('debug'): print('debug: GetImportFile from '+defaultDir) 3472 pth = GetImportPath(G2frame) 3473 #if GSASIIpath.GetConfigValue('debug'): 3474 # print('debug: GetImportFile from '+defaultDir) 3475 # print('debug: GetImportFile pth '+pth) 3473 3476 dlg = wx.FileDialog(parent, message, defaultDir, defaultFile, *args, 3474 3477 style=style, **kwargs) 3475 3478 # dlg.CenterOnParent() 3476 pth = GetImportPath(G2frame)3477 3479 if not defaultDir and pth: dlg.SetDirectory(pth) 3478 3480 try: -
trunk/GSASIIdataGUI.py
r4568 r4573 8599 8599 elif G2frame.GPXtree.GetItemText(item) == 'Constraints': 8600 8600 data = G2frame.GPXtree.GetItemPyData(item) 8601 #reload(G2cnstG) # for testing changes to GSASIIconstrGUI 8601 #import imp 8602 #imp.reload(G2cnstG) # for testing changes to GSASIIconstrGUI 8602 8603 G2cnstG.UpdateConstraints(G2frame,data) 8603 8604 elif G2frame.GPXtree.GetItemText(item) == 'Rigid bodies': 8604 8605 data = G2frame.GPXtree.GetItemPyData(item) 8606 # import imp 8607 # imp.reload(G2cnstG) # for testing changes to GSASIIconstrGUI 8608 # print('debug: reloaded',G2cnstG) 8605 8609 G2cnstG.UpdateRigidBodies(G2frame,data) 8606 8610 elif G2frame.GPXtree.GetItemText(item).startswith('IMG '): … … 8675 8679 elif G2frame.GPXtree.GetItemText(parentID) == 'Phases': 8676 8680 data = G2frame.GPXtree.GetItemPyData(item) 8681 # print('Debug: reload G2phG') 8682 # import imp 8683 # imp.reload(G2phG) 8677 8684 G2phG.UpdatePhaseData(G2frame,item,data) 8678 8685 elif G2frame.GPXtree.GetItemText(parentID) == 'Restraints': -
trunk/GSASIIddataGUI.py
r4534 r4573 27 27 import GSASIIplot as G2plt 28 28 import GSASIIpwd as G2pwd 29 import GSASIIphsGUI as G2ph sGUI29 import GSASIIphsGUI as G2phG 30 30 import GSASIIctrlGUI as G2G 31 31 import GSASIIpy3 as G2py3 … … 1057 1057 0,WACV|wx.TOP,10) 1058 1058 1059 G2ph sGUI.SetPhaseWindow(DData,mainSizer,Scroll=Scroll)1059 G2phG.SetPhaseWindow(DData,mainSizer,Scroll=Scroll) -
trunk/GSASIIphsGUI.py
r4570 r4573 7727 7727 G2plt.PlotStructure(G2frame,data) 7728 7728 7729 def NextAtom(event): 7730 'respond to a tab by cycling through the atoms' 7731 next = 0 7732 for r in drawAtoms.GetSelectedRows(): 7733 next = r + 1 7734 break 7735 if next >= drawAtoms.GetNumberRows(): 7736 next = 0 7737 drawAtoms.ClearSelection() 7738 drawAtoms.SelectRow(next,True) 7739 drawAtoms.MakeCellVisible(next,0) 7740 drawingData['selectedAtoms'] = drawAtoms.GetSelectedRows() 7741 G2plt.PlotStructure(G2frame,data) 7742 7729 7743 def RowSelect(event): 7730 7744 r,c = event.GetRow(),event.GetCol() … … 7751 7765 drawingData['selectedAtoms'] = [] 7752 7766 drawingData['selectedAtoms'] = drawAtoms.GetSelectedRows() 7753 G2plt.PlotStructure(G2frame,data) 7767 G2plt.PlotStructure(G2frame,data) 7754 7768 7755 7769 #### UpdateDrawAtoms executable code starts here … … 7799 7813 drawAtoms.Bind(wg.EVT_GRID_CELL_LEFT_DCLICK, RefreshDrawAtomGrid) 7800 7814 drawAtoms.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK, RowSelect) 7815 try: 7816 drawAtoms.Bind(wg.EVT_GRID_TABBING, NextAtom) 7817 except: # patch: for pre-2.9.5 wx 7818 pass 7801 7819 for i,atom in enumerate(drawingData['Atoms']): 7802 7820 attr = wg.GridCellAttr() #needs to be here - gets lost if outside loop! … … 8888 8906 line2Sizer.Add(showHydrogen,0,WACV) 8889 8907 8890 showRB = wx.CheckBox(drawOptions,-1,label=' Show rigid Bodies?')8908 showRB = wx.CheckBox(drawOptions,-1,label=' Show Rigid Bodies?') 8891 8909 showRB.Bind(wx.EVT_CHECKBOX, OnShowRB) 8892 8910 showRB.SetValue(drawingData['showRigidBodies']) … … 10085 10103 if refresh: 10086 10104 if RigidBodies.GetSizer(): RigidBodies.GetSizer().Clear(True) 10105 if 'testRBObj' in data: del data['testRBObj'] 10087 10106 general = data['General'] 10088 10107 cx,ct,cs,cia = general['AtomPtrs'] … … 10319 10338 10320 10339 def OnTorAngle(invalid,value,tc): 10321 #OkBtn.SetLabel('OK') 10322 #OkBtn.Enable(True) 10323 Obj = tc.event.GetEventObject() 10324 [tor,torSlide] = Indx[Obj.GetId()] 10340 '''respond to a number entered into the torsion editor. 10341 Update the slider (number is already saved) 10342 recompute atom distances 10343 ''' 10344 [tor,torSlide] = Indx[tc.GetId()] 10325 10345 torSlide.SetValue(int(value*10)) 10326 10346 UpdateTablePlot() 10327 10347 10328 10348 def OnTorSlide(event): 10329 #OkBtn.SetLabel('OK') 10330 #OkBtn.Enable(True) 10349 '''respond to the slider moving. Put value into editor & save 10350 recompute atom distances 10351 ''' 10331 10352 Obj = event.GetEventObject() 10332 10353 tor,ang = Indx[Obj.GetId()] … … 10476 10497 item.SetLabel('%10.4f'%(data['testRBObj']['rbObj']['Orient'][0][i])) 10477 10498 UpdateTablePlot() 10499 10500 def BallnSticks(event): 10501 '''Set all draw atoms in crystal structure to balls & stick 10502 ''' 10503 for a in data['Drawing']['Atoms']: a[6] = "balls & sticks" 10504 FindBondsDraw(data) 10505 G2plt.PlotStructure(G2frame,data,False,UpdateTable) 10506 RigidBodies.SetFocus() # make sure tab presses go to panel 10507 def Sticks(event): 10508 '''Set all draw atoms in crystal structure to stick 10509 ''' 10510 for a in data['Drawing']['Atoms']: a[6] = "sticks" 10511 FindBondsDraw(data) 10512 G2plt.PlotStructure(G2frame,data,False,UpdateTable) 10513 RigidBodies.SetFocus() # make sure tab presses go to panel 10514 def OnRowSelect(event): 10515 '''Respond to the selection of a rigid body atom. 10516 Highlight the atom in the body and the paired atom in the 10517 crystal 10518 ''' 10519 event.Skip() 10520 cryatom = event.GetEventObject().Table.GetValue(event.GetRow(),4) 10521 if not cryatom: 10522 cryatom = event.GetEventObject().Table.GetValue(event.GetRow(),2) 10523 data['testRBObj']['RBhighLight'] = event.GetRow() 10524 data['testRBObj']['CRYhighLight'] = [ 10525 i for i,a in enumerate(data['Atoms']) if a[0] == cryatom] 10526 G2plt.PlotStructure(G2frame,data,False,UpdateTable) 10527 data['testRBObj']['showSelect'].SetLabelText(cryatom) 10528 showAtom = [None] 10529 def showCryAtom(*args,**kwargs): 10530 '''Respond to selection of a crystal atom 10531 ''' 10532 data['testRBObj']['CRYhighLight'] = [ 10533 i for i,a in enumerate(data['Atoms']) if a[0] == showAtom[0]] 10534 G2plt.PlotStructure(G2frame,data,False,UpdateTable) 10478 10535 10479 10536 # Start of Draw() … … 10487 10544 for i in unmatchedRBatoms: 10488 10545 rbAssignments[i] = None 10489 10490 10546 mainSizer = wx.BoxSizer(wx.VERTICAL) 10491 10547 mainSizer.Add((5,5),0) … … 10497 10553 rbRef = data['testRBObj']['rbRef'] 10498 10554 Torsions = rbObj['Torsions'] 10499 refName = []10500 for ref in rbRef:10501 refName.append(data['testRBObj']['rbAtTypes'][ref]+str(ref))10555 #refName = [] 10556 #for ref in rbRef: 10557 # refName.append(data['testRBObj']['rbAtTypes'][ref]+str(ref)) 10502 10558 atNames = data['testRBObj']['atNames'] 10503 mainSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY, 10559 topSizer = wx.BoxSizer(wx.HORIZONTAL) 10560 topSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY, 10504 10561 'Locating rigid body : '+rbName), 0, WACV) 10505 mainSizer.Add((5,5),0) 10562 topSizer.Add((10,-1),0) 10563 topSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY, 10564 'Display crystal structure as:'), 0, WACV) 10565 btn = wx.Button(RigidBodies,wx.ID_ANY,"Ball && Sticks") 10566 btn.Bind(wx.EVT_BUTTON, BallnSticks) 10567 topSizer.Add(btn) 10568 btn = wx.Button(RigidBodies,wx.ID_ANY,"Sticks") 10569 btn.Bind(wx.EVT_BUTTON, Sticks) 10570 topSizer.Add(btn) 10571 mainSizer.Add(topSizer) 10572 mainSizer.Add((-1,5),0) 10506 10573 OriSizer = wx.BoxSizer(wx.HORIZONTAL) 10507 10574 OriSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'Origin: '),0,WACV) … … 10547 10614 torName = '' 10548 10615 for item in [seq[0],seq[1],seq[3][0]]: 10549 torName += data['testRBObj']['rbAtTypes'][item]+str(item)+' ' 10616 if data['testRBObj']['NameLookup'][item]: 10617 torName += data['testRBObj']['NameLookup'][item]+' ' 10618 else: 10619 torName += data['testRBObj']['rbAtTypes'][item]+str(item)+' ' 10550 10620 TorSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'Side chain torsion for rb seq: '+torName),0,WACV) 10551 10621 torSlide = wx.Slider(RigidBodies,style=wx.SL_HORIZONTAL) … … 10581 10651 10582 10652 SetPhaseWindow(RigidBodies,mainSizer) 10583 10584 10653 G2plt.PlotStructure(G2frame,data,True,UpdateTable) 10654 10655 gridSizer = wx.BoxSizer(wx.HORIZONTAL) 10585 10656 colLabels = ['RB\ntype','phase\n#','phase\nlabel','delta, A','Assign as atom'] 10586 10657 rowLabels = [l[1] for l in matchTable] … … 10601 10672 RigidBodies.atomsTable = G2G.Table(displayTable,rowLabels=rowLabels,colLabels=colLabels,types=Types) 10602 10673 RigidBodies.atomsGrid = G2G.GSGrid(RigidBodies) 10603 10604 labelsChoices = [' '] + [a[0] for a in data['Atoms'] 10674 RigidBodies.atomsGrid.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK,OnRowSelect) 10675 data['testRBObj']['RBhighLight'] = None 10676 data['testRBObj']['CRYhighLight'] = [] 10677 data['testRBObj']['availAtoms'] = [' '] + [a[0] for a in data['Atoms'] 10605 10678 if a[-1] not in rbUsedIds] 10606 10679 choiceeditor = wg.GridCellChoiceEditor( 10607 labelsChoices+['Create new'], False)10680 data['testRBObj']['availAtoms']+['Create new'], False) 10608 10681 RigidBodies.atomsGrid.SetTable(RigidBodies.atomsTable,True) 10609 10682 # make all grid entries read only … … 10623 10696 RigidBodies.atomsGrid.SetMargins(0,0) 10624 10697 10625 gridSizer = wx.BoxSizer(wx.HORIZONTAL)10626 10698 gridSizer.Add(RigidBodies.atomsGrid)#,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 10627 10699 gridSizer.Add((5,5)) 10628 10700 10629 10701 btnSizer = wx.BoxSizer(wx.VERTICAL) 10702 hSizer = wx.BoxSizer(wx.HORIZONTAL) 10703 hSizer.Add(wx.StaticText(RigidBodies,wx.ID_ANY,'Crystal Highlight: ')) 10704 data['testRBObj']['showSelect'] = G2G.G2ChoiceButton(RigidBodies, 10705 data['testRBObj']['availAtoms'], 10706 None,None,showAtom,0,showCryAtom, 10707 size=(75,-1)) 10708 hSizer.Add(data['testRBObj']['showSelect']) 10709 btnSizer.Add(hSizer) 10630 10710 btnSizer.Add((-1,20)) 10631 10711 btnSizer.Add( … … 10655 10735 RigidBodies.SendSizeEvent() 10656 10736 RigidBodies.Scroll(0,0) 10657 10737 RigidBodies.SetFocus() # make sure tab presses go to panel 10738 data['testRBObj']['UpdateTable'] = UpdateTable 10658 10739 # start of OnRBAssign(event) 10659 10740 rbAssignments = {} … … 10722 10803 data['testRBObj']['rbAtTypes'] = RBData[rbType][rbId]['rbTypes'] 10723 10804 data['testRBObj']['AtInfo'] = RBData[rbType]['AtInfo'] 10805 data['testRBObj']['NameLookup'] = RBData[rbType][rbId]['atNames'] 10724 10806 data['testRBObj']['rbType'] = rbType 10725 10807 data['testRBObj']['rbData'] = RBData … … 10728 10810 data['testRBObj']['rbRef'] = rbRef 10729 10811 refType = [] 10730 refName = []10812 #refName = [] 10731 10813 for ref in rbRef[:3]: 10732 10814 reftype = data['testRBObj']['rbAtTypes'][ref] 10733 10815 refType.append(reftype) 10734 refName.append(reftype+' '+str(rbRef[0]))10816 #refName.append(reftype+' '+str(rbRef[0])) 10735 10817 atNames = [{},{},{}] 10736 10818 AtNames = {} … … 12624 12706 G2frame.phaseDisplay.AddPage(drawAtoms,'Draw Atoms') 12625 12707 Pages.append('Draw Atoms') 12708 def rbKeyPress(event): 12709 '''Respond to a Tab to highlight the next RB or crystal atom 12710 ''' 12711 if 'testRBObj' not in data: return 12712 alt = event.GetModifiers() & wx.MOD_ALT 12713 event.Skip() 12714 try: # IsKeyInCategory not in wx 2.9 12715 if not event.IsKeyInCategory(wx.WXK_CATEGORY_TAB): return 12716 except: 12717 return 12718 if alt: # advance RB selection 12719 #GSASIIpath.IPyBreak() 12720 rows = RigidBodies.atomsGrid.GetSelectedRows() 12721 if len(rows) == 0: 12722 rows = [0] 12723 else: 12724 rows[0] += 1 12725 if rows[0] > RigidBodies.atomsGrid.GetNumberRows()-1: 12726 rows = [0] 12727 elif rows[0] < 0: 12728 rows[0] = RigidBodies.atomsGrid.GetNumberRows()-1 12729 RigidBodies.atomsGrid.SelectRow(rows[0]) 12730 RigidBodies.atomsGrid.MakeCellVisible(rows[0],0) 12731 data['testRBObj']['RBhighLight'] = rows[0] 12732 else: 12733 #GSASIIpath.IPyBreak() 12734 #return 12735 Ind = data['testRBObj'].get('CRYhighLight',[]) 12736 if len(Ind) == 0: 12737 I = -1 12738 else: 12739 I = Ind[0] 12740 wrap = False 12741 while True: 12742 I += 1 12743 if I >= len(data['Atoms']) and wrap: 12744 print('How did this happen?',Ind,I, 12745 len(data['testRBObj']['availAtoms']),len(data['Atoms'])) 12746 return 12747 elif I >= len(data['Atoms']): 12748 wrap = True 12749 I = 0 12750 if data['Atoms'][I][0] in data['testRBObj']['availAtoms']: 12751 data['testRBObj']['CRYhighLight'] = [I] 12752 data['testRBObj']['showSelect'].SetLabelText(data['Atoms'][I][0]) 12753 break 12754 G2plt.PlotStructure(G2frame,data,False,data['testRBObj']['UpdateTable']) 12626 12755 if data['General']['Type'] not in ['faulted',] and not data['General']['Modulated']: 12627 12756 RigidBodies = wx.ScrolledWindow(G2frame.phaseDisplay) 12628 12757 G2frame.phaseDisplay.AddPage(RigidBodies,'RB Models') 12758 RigidBodies.Bind(wx.EVT_CHAR,rbKeyPress) 12629 12759 Pages.append('RB Models') 12630 12760 MapPeaks = G2G.GSGrid(G2frame.phaseDisplay) -
trunk/GSASIIplot.py
r4565 r4573 8483 8483 elif G2frame.phaseDisplay.GetPageText(page) == 'Atoms': 8484 8484 Ind = G2frame.phaseDisplay.GetPage(page).GetSelectedRows() #this is the Atoms grid in Atoms 8485 elif G2frame.phaseDisplay.GetPageText(page) == 'RB Models': 8486 if 'testRBObj' not in data: return [] 8487 Ind = data['testRBObj'].get('CRYhighLight',[]) 8485 8488 return Ind 8486 8489 … … 9150 9153 if iat in Ind and G2frame.phaseDisplay.GetPageText(getSelection()) != 'Map peaks': 9151 9154 atColor = np.array(Gr)/255. 9155 bndColor = atColor 9152 9156 # color += [.25,] 9153 9157 radius = 0.5 … … 9279 9283 if showBonds: 9280 9284 RenderLines(x,y,z,mapBonds[ind],Wt) 9281 if len(testRBObj) and pageName == 'RB Models': 9285 if len(testRBObj) and pageName == 'RB Models': # plot a test rigid body as ball & [green] sticks 9282 9286 XYZ = G2mth.UpdateRBXYZ(Bmat,testRBObj['rbObj'],testRBObj['rbData'],testRBObj['rbType'])[0] 9283 9287 rbBonds = FindPeaksBonds(XYZ) 9284 9288 for ind,[x,y,z] in enumerate(XYZ): 9285 9289 aType = testRBObj['rbAtTypes'][ind] 9286 name = ' '+aType+str(ind) 9290 if testRBObj['NameLookup'][ind]: 9291 name = testRBObj['NameLookup'][ind]+' ' 9292 else: 9293 name = ' '+aType+str(ind) 9287 9294 color = np.array(testRBObj['AtInfo'][aType][1]) 9288 RenderSphere(x,y,z,0.2,color/255.) 9295 if 'RBhighLight' in testRBObj and testRBObj['RBhighLight'] == ind: # highlighted atom is green 9296 RenderSphere(x,y,z,0.2,Gr) 9297 else: 9298 RenderSphere(x,y,z,0.2,color/255.) 9289 9299 RenderBonds(x,y,z,rbBonds[ind],0.03,Gr) 9290 9300 RenderLabel(x,y,z,name,0.2,wxOrange,matRot) … … 9296 9306 RenderSphere(x,y,z,0.2,color/255.) 9297 9307 RenderBonds(x,y,z,mcsaBonds[ind],0.03,Gr/255.) 9298 RenderLabel(x,y,z,name,0. 2,wxOrange,matRot)9308 RenderLabel(x,y,z,name,0.3,wxOrange,matRot) 9299 9309 if Backbones: 9300 9310 for chain in Backbones: -
trunk/exports/G2export_PDB.py
r4415 r4573 226 226 return 227 227 filename = self.filename 228 self.OpenFile() 228 229 for phasenam in self.phasenam: 229 230 phasedict = self.Phases[phasenam] # pointer to current phase info
Note: See TracChangeset
for help on using the changeset viewer.