Changeset 4951 for trunk/GSASIIpwd.py
- Timestamp:
- Jun 11, 2021 8:42:20 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIpwd.py
r4919 r4951 576 576 data['Ruland'],data['Sample Bkg.']['Mult'],res['fun'],msg)) 577 577 else: 578 G2fil.G2Print(' end: Flat Bkg={:.1f}, BackRatio={:.3f}, Ruland={:.3f} ) *** {} ***\n'.format(578 G2fil.G2Print(' end: Flat Bkg={:.1f}, BackRatio={:.3f}, Ruland={:.3f} RMS:{:.4f}) *** {} ***\n'.format( 579 579 data['Flat Bkg'],data['BackRatio'],data['Ruland'],res['fun'],msg)) 580 580 return res … … 2880 2880 # dspaces = [0.5/np.sqrt(G2lat.calc_rDsq2(H,G)) for H in np.eye(3)] 2881 2881 # return min(dspaces) 2882 2882 2883 def findfullrmc(): 2884 '''Find where fullrmc is installed. Tries the following: 2885 2886 1. Returns the Config var 'fullrmc_exec', if defined. No check 2887 is done that the interpreter has fullrmc 2888 2. The current Python interpreter if fullrmc can be imported 2889 and fullrmc is version 5+ 2890 3. The path is checked for a fullrmc image as named by Bachir 2891 2892 :returns: the full path to a python executable that is assumed to 2893 have fullrmc installed or None, if it was not found. 2894 ''' 2895 is_exe = lambda fpath: os.path.isfile(fpath) and os.access(fpath, os.X_OK) 2896 if GSASIIpath.GetConfigValue('fullrmc_exec') is not None and is_exe( 2897 GSASIIpath.GetConfigValue('fullrmc_exec')): 2898 return GSASIIpath.GetConfigValue('fullrmc_exec') 2899 try: 2900 import fullrmc 2901 if int(fullrmc.__version__.split('.')[0]) >= 5: 2902 return sys.executable 2903 except: 2904 pass 2905 pathlist = os.environ["PATH"].split(os.pathsep) 2906 for p in (GSASIIpath.path2GSAS2,GSASIIpath.binaryPath,os.getcwd(), 2907 os.path.split(sys.executable)[0]): 2908 if p not in pathlist: pathlist.insert(0,p) 2909 import glob 2910 for p in pathlist: 2911 if sys.platform == "darwin": 2912 lookfor = "fullrmc*macOS*i386-64bit" 2913 elif sys.platform == "win32": 2914 lookfor = "fullrmc*.exe" 2915 else: 2916 lookfor = "fullrmc*" 2917 fl = glob.glob(lookfor) 2918 if len(fl) > 0: 2919 return os.path.abspath(sorted(fl)[0]) 2920 2883 2921 def MakefullrmcRun(pName,Phase,RMCPdict): 2922 '''Creates a script to run fullrmc. Returns the name of the file that was 2923 created. 2924 ''' 2884 2925 BondList = {} 2885 2926 for k in RMCPdict['Pairs']: … … 2893 2934 angle[i] = angle[i].strip() 2894 2935 AngleList.append(angle) 2895 rmin = RMCPdict['min Contact']2936 # rmin = RMCPdict['min Contact'] 2896 2937 cell = Phase['General']['Cell'][1:7] 2897 2938 SymOpList = G2spc.AllOps(Phase['General']['SGData'])[0] … … 2901 2942 el = ''.join([i for i in atom[ct] if i.isalpha()]) 2902 2943 atomsList.append([el] + atom[cx:cx+4]) 2903 rname = pName+'-fullrmc.py' 2944 projDir,projName = os.path.split(pName) 2945 scrname = pName+'-fullrmc.py' 2904 2946 restart = '%s_restart.pdb'%pName 2905 2947 Files = RMCPdict['files'] 2906 2948 rundata = '' 2907 rundata += '#### fullrmc %s file; edit by hand if you so choose #####\n'% rname2949 rundata += '#### fullrmc %s file; edit by hand if you so choose #####\n'%scrname 2908 2950 rundata += '# created in '+__file__+" v"+filversion.split()[1] 2909 2951 rundata += dt.datetime.strftime(dt.datetime.now()," at %Y-%m-%dT%H:%M\n") … … 2912 2954 import os,glob 2913 2955 import time 2914 #import matplotlib.pyplot as plt 2956 import pickle 2915 2957 import numpy as np 2916 2958 from fullrmc.Core import Collection … … 2923 2965 from fullrmc.Constraints.DihedralAngleConstraints import DihedralAngleConstraint 2924 2966 from fullrmc.Generators.Swaps import SwapPositionsGenerator 2925 2926 ### When True, erases an existing enging to provide a fresh start 2927 FRESH_START = {} 2967 def writeHeader(ENGINE,statFP): 2968 statFP.write('generated-steps, total-error, ') 2969 for c in ENGINE.constraints: 2970 statFP.write(c.constraintName) 2971 statFP.write(', ') 2972 statFP.write('\\n') 2973 statFP.flush() 2974 2975 def writeCurrentStatus(ENGINE,statFP,plotF): 2976 statFP.write(str(ENGINE.generated)) 2977 statFP.write(', ') 2978 statFP.write(str(ENGINE.totalStandardError)) 2979 statFP.write(', ') 2980 for c in ENGINE.constraints: 2981 statFP.write(str(c.standardError)) 2982 statFP.write(', ') 2983 statFP.write('\\n') 2984 statFP.flush() 2985 mpl.use('agg') 2986 fp = open(plotF,'wb') 2987 for c in ENGINE.constraints: 2988 p = c.plot(show=False) 2989 p[0].canvas.draw() 2990 image = p[0].canvas.buffer_rgba() 2991 pickle.dump(c.constraintName,fp) 2992 pickle.dump(np.array(image),fp) 2993 fp.close() 2994 ''' 2995 rundata += ''' 2996 ### When True, erases an existing engine to provide a fresh start 2997 FRESH_START = {:} 2998 dirName = "{:}" 2999 prefix = "{:}" 3000 project = prefix + "-fullrmc" 2928 3001 time0 = time.time() 2929 '''.format(RMCPdict['ReStart'][0] )3002 '''.format(RMCPdict['ReStart'][0],projDir,projName) 2930 3003 2931 3004 rundata += '# setup structure\n' … … 2936 3009 2937 3010 rundata += '\n# initialize engine\n' 2938 rundata += 'engineFileName = "%s.rmc"\n'%pName 2939 2940 rundata += '''\n# check Engine exists if so (and not FRESH_START) load it 3011 rundata += ''' 3012 engineFileName = os.path.join(dirName, project + '.rmc') 3013 projectStats = os.path.join(dirName, project + '.stats') 3014 projectPlots = os.path.join(dirName, project + '.plots') 3015 pdbFile = os.path.join(dirName, project + '_restart.pdb') 3016 # check Engine exists if so (and not FRESH_START) load it 2941 3017 # otherwise build it 2942 3018 ENGINE = Engine(path=None) … … 2965 3041 sfwt = 'atomicNumber' 2966 3042 if 'G(r)' in File: 2967 rundata += ' GR = np.loadtxt( "%s").T\n'%filDat[0]3043 rundata += ' GR = np.loadtxt(os.path.join(dirName,"%s")).T\n'%filDat[0] 2968 3044 if filDat[3] == 0: 2969 3045 rundata += ''' # read and xform G(r) as defined in RMCProfile … … 2982 3058 rundata += ' GofR.set_limits((None, rmax))\n' 2983 3059 elif '(Q)' in File: 2984 rundata += ' SOQ = np.loadtxt( "%s").T\n'%filDat[0]3060 rundata += ' SOQ = np.loadtxt(os.path.join(dirName,"%s")).T\n'%filDat[0] 2985 3061 if filDat[3] == 0: 2986 3062 rundata += ' # Read & xform F(Q) as defined in RMCProfile to S(Q)-1\n' … … 3015 3091 '("element","{1}","{0}","{2}",{5},{6},{5},{6},{3},{4}),\n'.format(*item)) 3016 3092 rundata += ' ])\n' 3017 rundata += ' for f in glob.glob("{}_*.log"): os.remove(f)\n'.format(pName)3018 3093 rundata += ''' 3094 for f in glob.glob(os.path.join(dirName,prefix+"_*.log")): os.remove(f) 3019 3095 ENGINE.save() 3020 3096 else: 3021 3097 ENGINE = ENGINE.load(path=engineFileName) 3098 rmax = min( [ENGINE.boundaryConditions.get_a(), ENGINE.boundaryConditions.get_b(), ENGINE.boundaryConditions.get_c()] ) /2. 3099 3100 ENGINE.set_log_file(os.path.join(dirName,prefix)) 3022 3101 ''' 3023 rundata += 'ENGINE.set_log_file("{}")\n'.format(pName)3024 3102 if RMCPdict['Swaps']: 3025 3103 rundata += '\n#set up for site swaps\n' … … 3055 3133 rundata += 'for c in ENGINE.constraints: # loop over predefined constraints\n' 3056 3134 rundata += ' if type(c) is fPDF.PairDistributionConstraint:\n' 3057 rundata += ' c.set_variance_squared(1./wtDict["Pair-"+c.weighting])\n'3135 # rundata += ' c.set_variance_squared(1./wtDict["Pair-"+c.weighting])\n' 3058 3136 rundata += ' c.set_limits((None,rmax))\n' 3059 3137 if RMCPdict['FitScale']: 3060 3138 rundata += ' c.set_adjust_scale_factor((10, 0.01, 100.))\n' 3061 rundata += ' elif type(c) is ReducedStructureFactorConstraint:\n' 3062 rundata += ' c.set_variance_squared(1./wtDict["Struct-"+c.weighting])\n' 3139 # rundata += ' c.set_variance_squared(1./wtDict["Struct-"+c.weighting])\n' 3063 3140 if RMCPdict['FitScale']: 3141 rundata += ' elif type(c) is ReducedStructureFactorConstraint:\n' 3064 3142 rundata += ' c.set_adjust_scale_factor((10, 0.01, 100.))\n' 3065 3143 # torsions difficult to implement, must be internal to cell & named with … … 3073 3151 # rundata += ' %s\n'%str(tuple(torsion)) 3074 3152 # rundata += ' ]})\n' 3075 rundata += '\n# setup runs for fullrmc\n' 3076 3077 rundata += 'steps = 10000\n' 3153 rundata += ''' 3154 if FRESH_START: 3155 # initialize engine with one step to get starting config energetics 3156 ENGINE.run(restartPdb=pdbFile,numberOfSteps=1, saveFrequency=1) 3157 statFP = open(projectStats,'w') 3158 writeHeader(ENGINE,statFP) 3159 writeCurrentStatus(ENGINE,statFP,projectPlots) 3160 else: 3161 statFP = open(projectStats,'a') 3162 3163 # setup runs for fullrmc 3164 ''' 3165 rundata += 'steps = {}\n'.format(RMCPdict['Steps/cycle']) 3078 3166 rundata += 'for _ in range({}):\n'.format(RMCPdict['Cycles']) 3079 3167 rundata += ' ENGINE.set_groups_as_atoms()\n' 3080 3168 rundata += ' expected = ENGINE.generated+steps\n' 3081 3169 3082 rundata += ' ENGINE.run(restartPdb="%s",numberOfSteps=steps, saveFrequency=1000)\n'%restart 3170 rundata += ' ENGINE.run(restartPdb=pdbFile,numberOfSteps=steps, saveFrequency=steps)\n' 3171 rundata += ' writeCurrentStatus(ENGINE,statFP,projectPlots)\n' 3083 3172 rundata += ' if ENGINE.generated != expected: break # run was stopped\n' 3173 rundata += 'statFP.close()\n' 3084 3174 rundata += 'print("ENGINE run time %.2f s"%(time.time()-time0))\n' 3085 rfile = open( rname,'w')3175 rfile = open(scrname,'w') 3086 3176 rfile.writelines(rundata) 3087 3177 rfile.close() 3088 return rname3178 return scrname 3089 3179 3090 3180 def GetRMCBonds(general,RMCPdict,Atoms,bondList): … … 4324 4414 G2fil.G2Print ("OK") 4325 4415 plotter.StartEventLoop() 4416 4417 # GSASIIpath.SetBinaryPath(True,False) 4418 # print('found',findfullrmc())
Note: See TracChangeset
for help on using the changeset viewer.