Skip to content

Commit 170dfcf

Browse files
committed
rework launch of RMCProfile; add config var for RMCProfile location: not working on MacOS & not tested elsewhere
1 parent ce60e5a commit 170dfcf

File tree

3 files changed

+100
-44
lines changed

3 files changed

+100
-44
lines changed

GSASII/GSASIIphsGUI.py

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5740,7 +5740,7 @@ def OnReplacePhase(event):
57405740
Constraints = G2frame.GPXtree.GetItemPyData(consId)
57415741
# TODO: would be cleaner to just delete constraints w/phase data['pId']
57425742
Constraints['Phase'] = []
5743-
del data['magPhases']
5743+
if 'magPhases' in data: del data['magPhases']
57445744
data['MCSA'] = {'Models':
57455745
[{'Type': 'MD', 'Coef': [1.0, False, [0.8, 1.2]], 'axis': [0, 0, 1]}],
57465746
'Results': [], 'AtInfo': {}}
@@ -7716,11 +7716,13 @@ def AtomVarSizer():
77167716
RMCmisc['RMCnote'].SetLabel('Note that fullrmc is not installed or was not located')
77177717

77187718
def OnSetupRMC(event):
7719+
written = lambda fil: print(f' {fil} written')
77197720
generalData = data['General']
77207721
if not G2frame.GSASprojectfile: #force a project save
77217722
G2frame.OnFileSaveas(event)
77227723
dName = G2frame.LastGPXdir
77237724
os.chdir(dName)
7725+
print(f'Writing input files in directory {dName!r}')
77247726
if G2frame.RMCchoice == 'fullrmc':
77257727
RMCPdict = data['RMC']['fullrmc']
77267728
pName = G2frame.GSASprojectfile.split('.')[0] + '-' + generalData['Name']
@@ -7755,7 +7757,7 @@ def OnSetupRMC(event):
77557757
Size = data['Histograms'][histoName]['Size']
77567758
Mustrain = data['Histograms'][histoName]['Mustrain']
77577759
reset = False
7758-
print(G2pwd.MakeInst(PWDdata,pName,Size,Mustrain,RMCPdict['UseSampBrd'])+ ' written')
7760+
written(G2pwd.MakeInst(PWDdata,pName,Size,Mustrain,RMCPdict['UseSampBrd']))
77597761
backfile = G2pwd.MakeBack(PWDdata,pName)
77607762
if backfile is None:
77617763
print(' Chebyschev-1 background not used; no .back file written')
@@ -7764,20 +7766,20 @@ def OnSetupRMC(event):
77647766
G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,False)
77657767
return
77667768
else:
7767-
print(backfile+ ' written')
7768-
print(G2pwd.MakeBragg(PWDdata,pName,data)+ ' written')
7769+
written(backfile)
7770+
written(G2pwd.MakeBragg(PWDdata,pName,data))
77697771
if RMCPdict['ReStart'][0]:
77707772
if os.path.isfile(pName+'.his6f'):
77717773
os.remove(pName+'.his6f')
77727774
RMC6f,reset = G2pwd.MakeRMC6f(PWDdata,pName,data,RMCPdict)
7773-
print(RMC6f+ ' written')
7775+
written(RMC6f)
77747776
fname = G2pwd.MakeRMCPdat(PWDdata,pName,data,RMCPdict)
77757777
if 'Error' in fname:
77767778
print(fname)
77777779
wx.MessageDialog(G2frame,fname,'Missing reflection list',wx.OK).ShowModal()
77787780
G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,False)
77797781
return
7780-
print(fname+ ' written')
7782+
written(fname)
77817783
print('RMCProfile file build completed')
77827784
RMCPdict['ReStart'] = [False,False]
77837785
if reset:
@@ -7802,7 +7804,7 @@ def OnSetupRMC(event):
78027804
if fname is None:
78037805
wx.MessageDialog(G2frame,'ERROR: failure to setup PDFfit; check console','PDFfit setup failure',wx.ICON_ERROR).ShowModal()
78047806
else:
7805-
print(fname+ ' written')
7807+
written(fname)
78067808
print('PDFfit file build completed')
78077809

78087810
def RunPDFfit(event):
@@ -8122,22 +8124,8 @@ def Runfullrmc(event):
81228124
def RunRMCProfile(event):
81238125
generalData = data['General']
81248126
pName = generalData['Name'].replace(' ','_')
8125-
rmcfile = G2fil.find('rmcprofile.exe',GSASIIpath.path2GSAS2)
8126-
os_name = platform.system()
8127-
if os_name == "Darwin":
8128-
rmcexe = os.path.join(
8129-
"/Applications/RMCProfile.app/Contents/MacOS/exe/",
8130-
"rmcprofile.x"
8131-
)
8132-
else:
8133-
if rmcfile is None:
8134-
wx.MessageBox(''' RMCProfile is not correctly installed for use in GSAS-II
8135-
Obtain the zip file distribution from www.rmcprofile.org,
8136-
unzip it and place the RMCProfile main directory in the main GSAS-II directory ''',
8137-
caption='RMCProfile',style=wx.ICON_INFORMATION)
8138-
return
8139-
rmcexe = os.path.split(rmcfile)[0]
8140-
#print(rmcexe)
8127+
rmcfile = G2pwd.findrmcprofile()
8128+
81418129
wx.MessageBox(
81428130
' For use of RMCProfile, please cite:\n\n'+
81438131
G2G.GetCite("RMCProfile"),
@@ -8169,32 +8157,40 @@ def RunRMCProfile(event):
81698157
break
81708158

81718159
G2frame.OnFileSave(event)
8172-
print (' GSAS-II project saved')
8160+
print ('GSAS-II project saved')
81738161
pName = generalData['Name'].replace(' ','_')
81748162

8175-
if os_name == "Darwin":
8176-
with open('runrmc.sh', 'w') as f:
8163+
if rmcfile is None:
8164+
wx.MessageBox('''RMCProfile is not correctly installed for use in GSAS-II
8165+
This software must be downloaded separately (from
8166+
https://rmcprofile.ornl.gov/download). Install the rmcprofile or
8167+
rmcprofile.exe file in a location where GSAS-II can find it
8168+
(see config variable rmcprofile_exec in preferences.)''',
8169+
caption='RMCProfile',style=wx.ICON_INFORMATION)
8170+
return
8171+
8172+
if sys.platform == "darwin":
8173+
script_file = os.path.join(os.getcwd(), "runrmc.sh")
8174+
with open(script_file, 'w') as f:
81778175
f.write("#!/bin/bash\n")
8178-
f.write("cd " + os.getcwd() + "\n")
8179-
f.write(rmcexe + " " + pName + "\n")
8176+
f.write(f'cd "{os.getcwd()}"\n')
8177+
f.write(f'"{rmcfile}" "{pName}"\n')
81808178
os.system("chmod +x runrmc.sh")
8181-
script_file = os.path.join(os.getcwd(), "runrmc.sh")
8182-
applescript_command = 'tell app "Terminal"\n'
8183-
applescript_command += "if not (exists window 1) then\n"
8184-
applescript_command += f'do script "source {script_file}"\n'
8185-
applescript_command += "else\n"
8186-
applescript_command += f'do script "source {script_file}"'
8187-
applescript_command += " in window 1\n"
8188-
applescript_command += "end if\nactivate\nend tell"
8189-
subp.Popen(['osascript', '-e', applescript_command])
8179+
ascript_file = os.path.join(os.getcwd(), "runrmc.script")
8180+
with open(ascript_file, 'w') as f:
8181+
f.write('tell application "Terminal"\n')
8182+
f.write(f''' do script "echo 'Running RMCprofile'"\n''')
8183+
f.write(f' do script "bash {script_file}" in window 1\n')
8184+
f.write("end tell\n")
8185+
subp.Popen(['osascript', ascript_file])
81908186
else:
8191-
exstr = rmcexe+'\\rmcprofile.exe '+pName
8192-
batch = open('runrmc.bat','w')
8193-
batch.write('Title RMCProfile\n')
8194-
batch.write(exstr+'\n')
8195-
batch.write('pause\n')
8196-
batch.close()
8197-
subp.Popen('runrmc.bat',creationflags=subp.CREATE_NEW_CONSOLE)
8187+
script_file = os.path.join(os.getcwd(), "runrmc.bat")
8188+
with open(script_file,'w') as batch:
8189+
batch.write('Title RMCProfile\n') # BHT: is Title a Windows command?
8190+
batch.write(f'"{rmcfile}" "{pName}"\n')
8191+
batch.write('pause\n')
8192+
batch.close()
8193+
subp.Popen(script_file,creationflags=subp.CREATE_NEW_CONSOLE)
81988194
# Proc.wait() #for it to finish before continuing on
81998195
UpdateRMC()
82008196

GSASII/GSASIIpwd.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,51 @@ def MakeRMCPdat(PWDdata,Name,Phase,RMCPdict):
34303430
# dspaces = [0.5/np.sqrt(G2lat.calc_rDsq2(H,G)) for H in np.eye(3)]
34313431
# return min(dspaces)
34323432

3433+
def findrmcprofile():
3434+
'''Find where RMCProfile is installed. Tries the following:
3435+
3436+
1. Returns the Config var `rmcprofile_exec`, if defined. This
3437+
is the executable to run.
3438+
2. The path is checked for a RMCprofile image. Also checked are
3439+
the location where the GSAS-II Python files are found,
3440+
the location where GSAS-II binaries are found, the current
3441+
working directory and the location where the Python
3442+
interpreter is found. On MacOS the commonly-used install
3443+
locations of /Applications/RMCProfile.app/Contents/MacOS/exe/
3444+
and ~/Applications/RMCProfile.app/Contents/MacOS/exe/
3445+
are also checked.
3446+
3447+
:returns: the full path to a python executable that is assumed to
3448+
have fullrmc installed or None, if it was not found.
3449+
'''
3450+
rmcprofile_exe = GSASIIpath.GetConfigValue('rmcprofile_exec')
3451+
if rmcprofile_exe is not None:
3452+
if is_exe(rmcprofile_exe):
3453+
return rmcprofile_exe
3454+
else:
3455+
print(f'Config var rmcprofile_exec defined as {rmcprofile_exe!r} but file not found or not exe.')
3456+
pathlist = os.environ["PATH"].split(os.pathsep)
3457+
for p in (GSASIIpath.path2GSAS2,GSASIIpath.binaryPath,os.getcwd(),
3458+
os.path.split(sys.executable)[0]):
3459+
if p not in pathlist: pathlist.append(p)
3460+
if sys.platform == "win32":
3461+
lookfor = "rmcprofile.exe"
3462+
elif sys.platform == "darwin":
3463+
lookfor = "rmcprofile"
3464+
pathlist.insert(0,"/Applications/RMCProfile.app/Contents/MacOS/exe")
3465+
pathlist.insert(0,os.path.expanduser("~/Applications/RMCProfile.app/Contents/MacOS/exe"))
3466+
else:
3467+
lookfor = "rmcprofile"
3468+
for p in pathlist:
3469+
if not os.path.exists(p): continue
3470+
rmcprofile_exe = os.path.abspath(os.path.join(p,lookfor))
3471+
if is_exe(rmcprofile_exe):
3472+
if GSASIIpath.GetConfigValue('debug'):
3473+
print(f'rmcprofile found as {rmcprofile_exe!r}')
3474+
return rmcprofile_exe
3475+
if GSASIIpath.GetConfigValue('debug'):
3476+
print(f'rmcprofile not found. Path searched: {pathlist}')
3477+
34333478
def findfullrmc():
34343479
'''Find where fullrmc is installed. Tries the following:
34353480

GSASII/config_example.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,21 @@
279279
if PDFfit2 can be imported into the current Python.
280280
'''
281281

282+
rmcprofile_exec = None
283+
'''Defines the full path to a compiled executable for RMCProfile (downloaded
284+
from https://rmcprofile.ornl.gov/download) If None (the default), GSAS-II
285+
will see if RMCProfile is found in the path (or for MacOS in the standard
286+
install location of "/Applications/RMCProfile.app/Contents/MacOS/exe/rmcprofile"
287+
If that does not work, GSAS-II will search for an executable named rmcprofile
288+
(or rmcprofile.exe on Windows) in the OS search path, as well as,
289+
the location where the GSAS-II Python files are found,
290+
the location where GSAS-II binaries are found, the current
291+
working directory and the location where the Python
292+
interpreter is found. On MacOS, the commonly-used install
293+
locations of /Applications/RMCProfile.app/Contents/MacOS/exe/ and
294+
~/Applications/RMCProfile.app/Contents/MacOS/exe/ are also checked.
295+
'''
296+
282297
lastUpdateNotice = 0
283298
'''Defines the version number for the last update notice that has been
284299
shown. This should not need to be changed manually.

0 commit comments

Comments
 (0)