Changeset 4400 for trunk


Ignore:
Timestamp:
Apr 13, 2020 5:06:27 PM (3 years ago)
Author:
vondreele
Message:

add rigid body save to make new pdb file with properly named atoms - needed for fullrmc
implement use of pdbparser (part of fullrmc) to prepare amorphous big box models from isolated molecules.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r4399 r4400  
    4141import GSASIIpy3 as G2py3
    4242VERY_LIGHT_GREY = wx.Colour(235,235,235)
     43WACV = wx.ALIGN_CENTER_VERTICAL
    4344
    4445class ConstraintDialog(wx.Dialog):
     
    15671568            G2frame.Bind(wx.EVT_MENU, AddResidueRB, id=G2G.wxID_RIGIDBODYADD)
    15681569            G2frame.Bind(wx.EVT_MENU, OnImportRigidBody, id=G2G.wxID_RIGIDBODYIMPORT)
     1570            G2frame.Bind(wx.EVT_MENU, OnSaveRigidBody, id=G2G.wxID_RIGIDBODYSAVE)
    15691571            G2frame.Bind(wx.EVT_MENU, OnDefineTorsSeq, id=G2G.wxID_RESIDUETORSSEQ) #enable only if residue RBs exist?
    15701572            G2frame.Page = [page,'rrb']
     
    16161618        elif 'Residue' in G2frame.rbBook.GetPageText(page):
    16171619            ImportResidueRB()
     1620           
     1621    def OnSaveRigidBody(event):
     1622        page = G2frame.rbBook.GetSelection()
     1623        if 'Vector' in G2frame.rbBook.GetPageText(page):
     1624            pass
     1625        elif 'Residue' in G2frame.rbBook.GetPageText(page):
     1626            SaveResidueRB()
    16181627           
    16191628    def AddVectorRB(event):
     
    17041713            while 'ATOM' not in txtStr[:6] and 'HETATM' not in txtStr[:6]:
    17051714                txtStr = text.readline()
    1706                 #print txtStr
    17071715        items = txtStr.split()
     1716        nat = 1
    17081717        while len(items):
    17091718            if 'txt' in ext:
     
    17141723                atType = items[0]
    17151724                rbXYZ.append([float(items[i]) for i in [1,2,3]])
    1716                 atName = atType+str(len(rbXYZ))
     1725                atName = '%s%d'%(atType,nat)
    17171726            elif 'mol2' in ext:
    17181727                atType = items[1]
     
    17211730            elif 'pdb' in ext:
    17221731                atType = items[-1]
    1723                 atName = items[2]
     1732                if not items[2][-1].isnumeric():
     1733                    atName = '%s%d'%(items[2],nat)
     1734                else:
     1735                    atName = '5s'%items[2]
    17241736                xyz = txtStr[30:55].split()                   
    17251737                rbXYZ.append([float(x) for x in xyz])
     
    17351747                break
    17361748            items = txtStr.split()
     1749            nat += 1
    17371750        if len(atNames) < 3:
    17381751            G2G.G2MessageBox(G2frame,'Not enough atoms in rigid body; must be 3 or more')
     
    17511764        text.close()
    17521765        UpdateResidueRB()
     1766       
     1767    def SaveResidueRB():
     1768        global rbId
     1769        pth = G2G.GetExportPath(G2frame)
     1770        dlg = wx.FileDialog(G2frame, 'Choose PDB file for Atom XYZ', pth, '',
     1771            'PDB files (*.pdb)|*.pdb',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
     1772        try:
     1773            if dlg.ShowModal() == wx.ID_OK:
     1774                filename = dlg.GetPath()
     1775                # make sure extension is .pkslst
     1776                filename = os.path.splitext(filename)[0]+'.pdb'
     1777                File = open(filename,'w')       
     1778                rbData =  data['Residue'][rbId]
     1779                for iat,xyz in enumerate(rbData['rbXYZ']):
     1780                    File.write('ATOM %6d  %-4s%3s     1    %8.3f%8.3f%8.3f  1.00  0.00          %2s\n'%(
     1781                        iat,rbData['atNames'][iat],rbData['RBname'][:3],xyz[0],xyz[1],xyz[2],rbData['rbTypes'][iat]))
     1782                File.close()
     1783                print ('Atom XYZ saved to: '+filename)
     1784        finally:
     1785            dlg.Destroy()
     1786       
    17531787       
    17541788    def FindNeighbors(Orig,XYZ,atTypes,atNames,AtInfo):
     
    20372071        def rbNameSizer(rbId,rbData):
    20382072
    2039             def OnRBName(event):
    2040                 Obj = event.GetEventObject()
    2041                 rbData['RBname'] = Obj.GetValue()
    2042                 wx.CallAfter(UpdateResidueRB)
    2043                
    20442073            def OnDelRB(event):
    20452074                Obj = event.GetEventObject()
     
    20772106            nameSizer.Add(wx.StaticText(ResidueRBDisplay,-1,'Residue name: '),
    20782107                0,wx.ALIGN_CENTER_VERTICAL)
    2079             RBname = wx.TextCtrl(ResidueRBDisplay,-1,rbData['RBname'])
    2080             Indx[RBname.GetId()] = rbId
    2081             RBname.Bind(wx.EVT_TEXT_ENTER,OnRBName)
    2082             RBname.Bind(wx.EVT_KILL_FOCUS,OnRBName)
    2083             nameSizer.Add(RBname,0,wx.ALIGN_CENTER_VERTICAL)
     2108            nameSizer.Add(G2G.ValidatedTxtCtrl(ResidueRBDisplay,rbData,'RBname'),0,WACV)
    20842109            nameSizer.Add((5,0),)
    20852110            plotRB = wx.CheckBox(ResidueRBDisplay,-1,'Plot?')
  • trunk/GSASIIdataGUI.py

    r4399 r4400  
    53235323        # Rigid bodies
    53245324        G2G.Define_wxId('wxID_RIGIDBODYADD', 'wxID_DRAWDEFINERB', 'wxID_RIGIDBODYIMPORT', 'wxID_RESIDUETORSSEQ',
    5325             'wxID_VECTORBODYADD')       
     5325            'wxID_VECTORBODYADD', 'wxID_RIGIDBODYSAVE',)       
    53265326        self.RigidBodyMenu = wx.MenuBar()
    53275327        self.PrefillDataMenu(self.RigidBodyMenu)
    53285328        self.ResidueRBMenu = wx.Menu(title='')
    53295329        self.ResidueRBMenu.Append(G2G.wxID_RIGIDBODYIMPORT,'Import XYZ','Import rigid body XYZ from file')
     5330        self.ResidueRBMenu.Append(G2G.wxID_RIGIDBODYSAVE,'Save PDB','Save rigid body to PDB file')       
    53305331        self.ResidueRBMenu.Append(G2G.wxID_RESIDUETORSSEQ,'Define sequence','Define torsion sequence')
    53315332        self.ResidueRBMenu.Append(G2G.wxID_RIGIDBODYADD,'Import residues','Import residue rigid bodies from macro file')
  • trunk/GSASIIphsGUI.py

    r4399 r4400  
    8989if '2' in platform.python_version_tuple()[0]:
    9090    GkDelta = unichr(0x0394)
     91    Angstr = unichr(0x00c5)
    9192else:
    9293    GkDelta = chr(0x0394)
     94    Angstr = chr(0x00c5)   
    9395################################################################################
    9496#### phase class definitions
     
    44314433        mainSizer.Add((5,5),0,WACV)
    44324434        if G2frame.RMCchoice == 'fullrmc':
    4433           #   try:
    4434           #       from fullrmc import Engine
    4435           #   except ModuleNotFoundError:
    4436           #       wx.MessageBox(''' fullrmc is not correctly installed for use in GSAS-II
    4437           # Install it in your python according to the instructions in
    4438           # https://bachiraoun.github.io/fullrmc/index.html. ''',
    4439           #           caption='fullrmc not installed',style=wx.ICON_INFORMATION)
    4440           #       return
     4435            try:
     4436                import fullrmc
     4437            except ModuleNotFoundError:
     4438                wx.MessageBox(''' fullrmc is not correctly installed for use in GSAS-II
     4439          Install it in your python according to the instructions in
     4440          https://bachiraoun.github.io/fullrmc/index.html. ''',
     4441                     caption='fullrmc not installed',style=wx.ICON_INFORMATION)
     4442                return
    44414443            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=''' "Fullrmc, a Rigid Body Reverse Monte Carlo Modeling Package Enabled with Machine Learning and Artificial Intelligence",     
    44424444 B. Aoun, Jour. Comp. Chem. 2016, 37, 1102-1111. doi: https://doi.org/10.1002/jcc.24304
     
    44624464                data['RMC']['fullrmc'] = {'ifBox':True,'SuperCell':[1,1,1],'Box':[10.,10.,10.],'aTypes':aTypes,
    44634465                    'atSeq':atSeq,'Pairs':Pairs,'files':files,'ReStart':[False,False],'Swaps':[],'useBVS':False,
    4464                     'AveCN':[],'FxCN':[],}
     4466                    'AveCN':[],'FxCN':[],'moleculePdb':'Select','targetDensity':1.0,'maxRecursion':10000}
    44654467            RMCPdict = data['RMC']['fullrmc']
    44664468
     
    44894491            def OnReStart(event):
    44904492                RMCPdict['ReStart'][0] = not RMCPdict['ReStart'][0]
     4493               
     4494            def OnPdbButton(event):
     4495                dlg = wx.FileDialog(G2frame.FRMC, 'Choose molecule pdb file',G2frame.LastGPXdir,
     4496                    style=wx.FD_OPEN ,wildcard='PDB file(*.pdb)|*.pdb')
     4497                if dlg.ShowModal() == wx.ID_OK:
     4498                    fpath,fName = os.path.split(dlg.GetPath())
     4499                    RMCPdict['moleculePdb'] = fName
     4500                    pdbButton.SetLabel(fName)
     4501                   
     4502            def OnMakePDB(event):
     4503                dlg = wx.MessageDialog(G2frame,'''
     4504Warning - this step can take more than an hour; do you want to proceed?
     4505It will be run as a separate process, and a result is required for fullrmc.
     4506Make sure your parameters are correctly set.
     4507                    ''','Make big box pdb file',wx.YES_NO|wx.ICON_QUESTION)
     4508                try:
     4509                    result = dlg.ShowModal()
     4510                    if result in [wx.ID_YES,]:
     4511                        pdpy = G2pwd.MakePdparse(RMCPdict)
     4512                        import subprocess as sb
     4513                        batch = open('pdbparse.bat','w')
     4514                        batch.write('CALL '+sys.exec_prefix+'\\Scripts\\activate\n')
     4515                        batch.write(sys.exec_prefix+'\\python.exe %s\n'%pdpy)
     4516                        batch.write('pause')
     4517                        batch.close()
     4518                        sb.Popen('pdbparse.bat',creationflags=sb.CREATE_NEW_CONSOLE).pid
     4519                    else:
     4520                        print(' Make PDB file for fullrmc abandonded')
     4521                finally:
     4522                    dlg.Destroy()
     4523               
    44914524#patches
    44924525            if 'useBVS' not in RMCPdict:
    44934526                RMCPdict['useBVS'] = False
     4527            if 'moleculePdb' not in RMCPdict:
     4528                RMCPdict.update({'moleculePdb':'Select','targetDensity':1.0,'maxRecursion':10000})
    44944529#end patches
    44954530            restart = wx.CheckBox(G2frame.FRMC,label=' Restart fullrmc Engine? (will clear old result!) ')
     
    45004535            lineSizer = wx.BoxSizer(wx.HORIZONTAL)
    45014536            if RMCPdict['ifBox']:
    4502                 lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Big box dimensions:'),0,WACV)               
     4537                lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Big box dimensions, %s:'%Angstr),0,WACV)               
    45034538                lineSizer.Add(GetBoxSizer(),0,WACV)
    45044539                boxBtn = wx.Button(G2frame.FRMC,label='Use super lattice')
     
    45104545            lineSizer.Add(boxBtn,0,WACV)
    45114546            mainSizer.Add(lineSizer,0,WACV)
    4512            
     4547            if RMCPdict['ifBox']:
     4548                molecSizer = wx.BoxSizer(wx.HORIZONTAL)
     4549                molecSizer.Add(wx.StaticText(G2frame.FRMC,label=' Source molecule file '),0,WACV)
     4550                pdbButton = wx.Button(G2frame.FRMC,label=RMCPdict['moleculePdb'])
     4551                pdbButton.Bind(wx.EVT_BUTTON,OnPdbButton)
     4552                molecSizer.Add(pdbButton,0,WACV)
     4553                molecSizer.Add(wx.StaticText(G2frame.FRMC,label=' target density, gm/cc '),0,WACV)
     4554                molecSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict,'targetDensity',min=0.1,size=[60,25]),0,WACV)
     4555                molecSizer.Add(wx.StaticText(G2frame.FRMC,label=' max tries '),0,WACV)
     4556                molecSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict,'maxRecursion',min=1000,max=1000000,size=[60,25]),0,WACV)
     4557                makePDB = wx.Button(G2frame.FRMC,label='Make big box PDB (slow!)')
     4558                makePDB.Bind(wx.EVT_BUTTON,OnMakePDB)
     4559                molecSizer.Add(makePDB,0,WACV)               
     4560                mainSizer.Add(molecSizer,0,WACV)
     4561               
    45134562            mainSizer.Add(GetAtmChoice(RMCPdict),0,WACV)
    45144563           
     
    50295078            else:
    50305079                print(G2pwd.MakefullrmcPDB(pName,data,RMCPdict)+ ' written')
    5031             #print(G2pwd.MakefullrmcRun(pName,data,RMCPdict)+ ' written')
    50325080            print('fullrmc file build completed')
    50335081        else:
  • trunk/GSASIIpwd.py

    r4397 r4400  
    25392539    return fname
    25402540   
    2541 def MakepdparserPDB(Name,Phase,RMCPdict):
    2542     import pdbparser as pdp
    2543     fname = Name+'.pdb'
     2541def MakePdparse(RMCPdict):
     2542    fname = 'make_pdb.py'
     2543    outName = RMCPdict['moleculePdb'].split('.')
     2544    outName[0] += 'bb'
     2545    outName = '.'.join(outName)
    25442546    fl = open(fname,'w')
    2545     fl.write('REMARK    this file to be generated using pdbparser\n')
    2546     fl.close()
     2547    fl.write('from pdbparser.pdbparser import pdbparser\n')
     2548    fl.write('from pdbparser.Utilities.Construct import AmorphousSystem\n')
     2549    fl.write("pdb = pdbparser('%s')\n"%RMCPdict['moleculePdb'])
     2550    boxstr= 'boxsize=%s'%str(RMCPdict['Box'])
     2551    recstr = 'recursionLimit=%d'%RMCPdict['maxRecursion']
     2552    denstr = 'density=%.3f'%RMCPdict['targetDensity']
     2553    fl.write('pdb = AmorphousSystem(pdb,%s,%s,%s,\n'%(boxstr,recstr,denstr))
     2554    fl.write('    priorities={"boxSize":True, "insertionNumber":False, "density":True}).construct().get_pdb()\n')
     2555    fl.write('pdb.export_pdb("%s")\n'%outName)
     2556    fl.close
    25472557    return fname
    25482558
Note: See TracChangeset for help on using the changeset viewer.