parameters: (ws_foc, prm_savepath, spec_nums=None)
docstring: Save GSAS prm file for ENGINX data - for specification see manual
      https://subversion.xray.aps.anl.gov/EXPGUI/gsas/all/GSAS%20Manual.pdf
      :param ws_foc: focused workspace (used to get detector positions and diff constants)
      :param prm_savepath: path to save prm to
      :param spec_index: list of indices to save (e.g. can specify a particular bank)
docstring_summary: Save GSAS prm file for ENGINX data - for specification see manual
      https://subversion.xray.aps.anl.gov/EXPGUI/gsas/all/GSAS%20Manual.pdf
      :param ws_foc: focused workspace (used to get detector positions and diff constants)
      :param prm_savepath: path to save prm to
      :param spec_index: list of indices to save (e.g. can specify a particular bank)
docstring_tokens: Save GSAS prm file for ENGINX data - for specification see manual https : // subversion . xray . aps . anl . gov / EXPGUI / gsas / all / GSAS%20Manual . pdf : param ws_foc : focused workspace ( used to get detector positions and diff constants ) : param prm_savepath : path to save prm to : param spec_index : list of indices to save ( e . g . can specify a particular bank )
function: def write_prm_file(ws_foc, prm_savepath, spec_nums=None):
      """
      Save GSAS prm file for ENGINX data - for specification see manual
      https://subversion.xray.aps.anl.gov/EXPGUI/gsas/all/GSAS%20Manual.pdf
      :param ws_foc: focused workspace (used to get detector positions and diff constants)
      :param prm_savepath: path to save prm to
      :param spec_index: list of indices to save (e.g. can specify a particular bank)
      """
      if not spec_nums:
          spec_nums = range(ws_foc.getNumberHistograms())  # one block per spectrum in ws
      nspec = len(spec_nums)
      # read header
      with open(path.join(CALIB_DIR, "template_ENGINX_prm_header.prm")) as fheader:
          lines = fheader.readlines()
      lines[1] = lines[1].replace('2', f'{nspec}')  # replace with nspectra in header
      lines[13] = lines[13].replace('241391', f'{ws_foc.run().get("run_number").value}')  # replace run num
      # add blocks
      si = ws_foc.spectrumInfo()
      inst = ws_foc.getInstrument()
      endl = lines[0][-1]  # new line char
      for iblock, ispec in enumerate(spec_nums):
          # detector parameters
          l2 = si.l2(ispec)
          phi, tth = degrees(si.geographicalAngles(ispec))
          dc = si.diffractometerConstants(ispec)
          difa, difc, tzero = [dc[param] for param in [UnitParams.difa, UnitParams.difc, UnitParams.tzero]]
          block = [f'INS  {iblock + 1}I ITYP\t0\t1.0000\t80.0000\t0{endl}']
          block.extend(f'INS  {iblock + 1}BNKPAR\t{l2:.3f}\t{abs(tth):.3f}\t{phi:.3f}\t0.000\t0.000\t0\t0{endl}')
          block.extend(f'INS  {iblock + 1} ICONS\t{difc:.2f}\t{difa:.2f}\t{tzero:.2f}{endl}')
          # TOF peak profile parameters
          alpha0, beta0, beta1, sig0_sq, sig1_sq, sig2_sq = getParametersFromDetector(inst, ws_foc.getDetector(ispec))
          block.extend(f'INS  {iblock + 1}PRCF1 \t3\t21\t0.00050{endl}')
          block.extend(f'INS  {iblock + 1}PRCF11\t{alpha0:.6E}\t{beta0:.6E}\t{beta1:.6E}\t{sig0_sq:.6E}{endl}')
          block.extend(f'INS  {iblock + 1}PRCF12\t{sig1_sq:.6E}\t{sig2_sq:.6E}\t{0.0:.6E}\t{0.0:.6E}{endl}')
          for iblank in [3, 4, 5]:
              block.extend(f'INS  {iblock + 1}PRCF1{iblank}\t{0.0:.6E}\t{0.0:.6E}\t{0.0:.6E}\t{0.0:.6E}{endl}')
          block.extend(f'INS  {iblock + 1}PRCF16\t{0.0:.6E}{endl}')
          # append to lines
          lines.extend(block)
      # write lines to prm file
      with open(prm_savepath, 'w') as fout:
          fout.writelines(lines)
function_tokens: def write_prm_file ( ws_foc , prm_savepath , spec_nums = None ) : if not spec_nums : spec_nums = range ( ws_foc . getNumberHistograms ( ) ) # one block per spectrum in ws nspec = len ( spec_nums ) # read header with open ( path . join ( CALIB_DIR , "template_ENGINX_prm_header.prm" ) ) as fheader : lines = fheader . readlines ( ) lines [ 1 ] = lines [ 1 ] . replace ( '2' , f'{nspec}' ) # replace with nspectra in header lines [ 13 ] = lines [ 13 ] . replace ( '241391' , f'{ws_foc.run().get("run_number").value}' ) # replace run num # add blocks si = ws_foc . spectrumInfo ( ) inst = ws_foc . getInstrument ( ) endl = lines [ 0 ] [ - 1 ] # new line char for iblock , ispec in enumerate ( spec_nums ) : # detector parameters l2 = si . l2 ( ispec ) phi , tth = degrees ( si . geographicalAngles ( ispec ) ) dc = si . diffractometerConstants ( ispec ) difa , difc , tzero = [ dc [ param ] for param in [ UnitParams . difa , UnitParams . difc , UnitParams . tzero ] ] block = [ f'INS  {iblock + 1}I ITYP\t0\t1.0000\t80.0000\t0{endl}' ] block . extend ( f'INS  {iblock + 1}BNKPAR\t{l2:.3f}\t{abs(tth):.3f}\t{phi:.3f}\t0.000\t0.000\t0\t0{endl}' ) block . extend ( f'INS  {iblock + 1} ICONS\t{difc:.2f}\t{difa:.2f}\t{tzero:.2f}{endl}' ) # TOF peak profile parameters alpha0 , beta0 , beta1 , sig0_sq , sig1_sq , sig2_sq = getParametersFromDetector ( inst , ws_foc . getDetector ( ispec ) ) block . extend ( f'INS  {iblock + 1}PRCF1 \t3\t21\t0.00050{endl}' ) block . extend ( f'INS  {iblock + 1}PRCF11\t{alpha0:.6E}\t{beta0:.6E}\t{beta1:.6E}\t{sig0_sq:.6E}{endl}' ) block . extend ( f'INS  {iblock + 1}PRCF12\t{sig1_sq:.6E}\t{sig2_sq:.6E}\t{0.0:.6E}\t{0.0:.6E}{endl}' ) for iblank in [ 3 , 4 , 5 ] : block . extend ( f'INS  {iblock + 1}PRCF1{iblank}\t{0.0:.6E}\t{0.0:.6E}\t{0.0:.6E}\t{0.0:.6E}{endl}' ) block . extend ( f'INS  {iblock + 1}PRCF16\t{0.0:.6E}{endl}' ) # append to lines lines . extend ( block ) # write lines to prm file with open ( prm_savepath , 'w' ) as fout : fout . writelines ( lines )