virtualMACS

This is a python object that is the main wrapper for all of the methods of pyMACS. It requires only a few details to initialize - a .cif file to specify the sample being simulated, and a few instrumental settings.

class pyMACS.virtualMACS.VirtualMACS(exptName, cifName=None, useOld=False)

Bases: object

This class encompasses the virtual MACS experiment and contains various subclasses to handle the various elements of its operation. The object itself mostly contains information regarding just simulation parameters like neutron simulated count and directories.

Parameters:
  • exptName (str, required) – A string that describes the experiment. Used to make directories for this simulation.

  • cifName (str, required) – A string that denotes the filename of the .cif file assosciated with your sample. Must be in working directory.

  • useOld (bool, optional) – Bool denoting if old instrument files should be preserved. Default False.

  • n_sample ((int/float) optional) – Number of neutrons to simulate at sample position. Default 1e5

  • n_mono ((int/float) optional) – (int) Number of neutrons to simulate at monochromator position. Default 1e6

  • kidney_angle_resolution ((float) optional) – Angular resolution of detectors in the kidney scan / A4 angle, default 1.0 degrees

  • A3_angle (float) – Current sample A3 rotation angle.

clean_expt_directory()

Removes old simulation files, use with care.

clear_ramdisk()

Unmounts the ramdisk. Should be done after simulation is over to free memory.

compileInstr(verbose=True)

Runs the instrument compiler before beginnning scan.

compileMonochromator(verbose=True)

Compiles monochromator McStas files.

edit_instr_file(verbose=False)

Updates the instrument file to match the current sample and instrument configuration. Will require a recompilation of the instrument.

load_res_fwhm_interp_objects()

Using a previously tabulated list of resolution ellipsoid calculations, returns the closest resolution ellipsoid to the input h,k,l,E point. This variant uses a linear interpolation between the tabulated points to quickly get the FWHM in the principle axes, Qx, Qz, E, in (Ang^-1, Ang^-1, meV) The returned objects are scipy interpolators, which take input such as

  • dE = interp_dE(qx,qz,E)

The interpolation objects is a RegularGridInterpolator, and also accepts np.ndarrays of shape (N,4), where N is the number of points.

Returns:

interp_dQx, interp_dQz, interp_dE, scipy.interpolate.RegularGridInterpolator obejcts that return the macs Bragg widhths in the respective directions for arbitrary h,k,l,E, for the Ef=3.7 or Ef=5.0 settings.

Return type:

scipy.interpolate.RegularGridInterpolator, scipy.interpolate.RegularGridInterpolator, scipy.interpolate.RegularGridInterpolator

mount_ramdisk(verbose=False)

Mounts a disk based in memory. Disk operations are too slow, users are not intended to access the ramdisk.

mount_ramdisk_old()

Mounts a disk based in memory. Disk operations are too slow, users are not intended to access the ramdisk.

prepare_expt_directory()

Automatically prepares the McStas instrument files and output directories. Will require that instruments be recompiled. Takes into consideration the various sample options allowed.

prepare_old_expt_directory()

Prepares an experiment using previously generated and/or compiled .instr files. Used to resume a simulation that was interrupted or should be appended.

resmat(h, k, l, E, sampleFrame=True, gen_plot=False, verbose=False, figdir='Calculated_ellipsoid_pngs/')

Using a previously tabulated list of resolution ellipsoid calculations, returns the closest resolution ellipsoid to the input h,k,l,E point. More granular execution of this method is available in the scripting subclass, but for almost all use cases this should be enough. The only configurations that have been pre-calculated are the double-focusing Ef=3.7 and Ef=5.0 modes. There are some minor bugs, such as a few missing ellipsoids where one would expect one and some poorly fitted ellipsoids at low momentum transfers, but overall it behaves well. The ellipsoid is always returned in the (Qx, Qz, E) frame, in units of Ang^-1, Ang^-1, meV. This function also returns the same reslevant FWHM’s, which is what most users probably want.

Parameters:
  • h (float, required) – Miller h index. Non-integer values allowed.

  • k (float, required) – Miller k index.

  • l (float, required) – Miller l index.

  • E (float, required) – Energy transfer (meV)

  • gen_plot (bool, optional.) – Flag to trigger creation of figure summarizing the MACS resolution ellipsoid.

  • sampleFrame (bool, optional) – If true, the input sample coordinate system of the virtualMACS object will be used rather than the Qx, Qz frame in Ang^-1.

  • verbose (bool, optional.) – Flag to print resoultion ellipsoid information to terminal.

  • calc_mode (str, optional.) – There are three options, “default”, “load_cov”, and “Covariance”. Users should only use “load_cov”, or “default” if they have the correct csv files available. “Covariance” was a developer option, and returns just the covariance matrix.

Returns:

M, M_diag, Q_hkw. The resolution matrix, the diagonal elements / fwhm in Qx, Qz, E, and the (Qx, Qz, E) position of the closest tabulated point.

Return type:

np.ndarray, np.ndarray, np.ndarray

resmat_Elist(h, k, l, elist, sampleFrame=True)

Using a previously tabulated list of resolution ellipsoid calculations, returns the closest resolution ellipsoid to the input h,k,l,E points.

runKidneyScan(append_data_matrix=True, Ei_set=False, Ef_set=False, kidney_set=False, A3_set=False, beta_1_set=False, beta_2_set=False, scan_suffix=False, PTAI_det=3)

For current parameters, runs a kidney scan.

Parameters:
  • Ei_set (float, optional) – Ei setting for monochromator

  • Ef_set (float, optional) – Ef setting for kidney

  • kidney_set (float, optional) – Kidney angle setting for kidney.

  • beta_1_set (float, optional) – Beta 1 angle in degrees.

  • beta_2_set (float, optional.) – Beta 2 angle in degrees.

  • scan_suffix (string, optional) – Short descriptor of the current scan. Will be in output filenames.

runMonoScan(Ei_set=False, Ef_set=False, kidney_set=False, A3_set=False, beta_1_set=False, beta_2_set=False, verbose=False)

For a particular configuration, runs a monochromator scan. Automatically moves files to correct location afterwards.

Parameters:
  • Ei_set (float, optional) – Ei setting for monochromator

  • Ef_set (float, optional) – Ef setting for kidney

  • kidney_set (float, optional) – Kidney angle setting for kidney.

  • beta_1_set (float, optional) – Beta 1 angle in degrees.

  • beta_2_set (float, optional.) – Beta 2 angle in degrees.

script_powder_scan(Ei_list=False, num_threads=1, scan_title=False)
Provided with a list of A3 angles, a kidney angle resolution, optionally a list

of incident energies, simulates a MACS scan over the full range. Num-threads parameter is for parallelization. Simply just calls script_scan but fixes A3 to 0

Parameters:
  • Ei_list (list) – List of incident energies to run.

  • num_threads (int) – If parallelization is being used, number of threads to use.

  • scan_title (str) – Name assosciated with this particular scan.

script_scan(A3_list, Ei_list=False, num_threads=1, scan_title=False, verbose=False)
Provided with a list of A3 angles, a kidney angle resolution, optionally a list

of incident energies, simulates a MACS scan over the full range.

Parameters:
  • A3_list (list) – List of desired A3 angles for the scan.

  • Ei_list (list) – List of desired incident energies. Final energy is specified using virtualMACS.kidney.Ef_all = Ef.

  • num_threads (int) – If parallelization is being used, specifies number of threads.

  • scan_title (str) – If desired, can attach a particular name to the scan. Useful when emulating ng0 files.

simulate_ng0(ng0_file, in_scan=False, n_threads=1)

Provided an ng0 file or the path to an ng0 file, emulates a scan identically with the following parameters:

A3, Ei, Ef, beta1, beta1, kidney_angle, PTAI

Saves the result to its own ng0 file if not part of a larger scan. The result should match the input ng0 file point by point when viewed using MSlice or the built in tools.

Parameters:

ng0_file (str) – Input file or path to file. Must be a MACS ng0 file.

simulate_ng0dir(ng0_dir, n_threads=1)

Provided a director of only ng0 files, emulates all scans identically with the following parameters:

A3, Ei, Ef, beta1, beta1, kidney_angle, PTAI

Saves the result to its own ng0 file if not part of a larger scan. The result should match the input ng0 file point by point when viewed using MSlice or the built in tools.

Parameters:
  • ng0_dir (list of strs) – List of input files or path to files. Must be MACS ng0 files.

  • n_threads (int) – If parallelization is being used, number of threads to use.

unmount_ramdisk()

Unmounts the ramdisk. Should be done after simulation is over to free memory.

write_kidney_paramfile_from_current_params()

Write the parameter text file for a kidney simulation

write_mono_paramfile_from_current_params()

Writes the parmeter text file for monochromator simulation

Create a list of object parameters, like n_mono.