scripting

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.

pyMACS.scripting.descr_ellipse(quadric)

Helper function for resolution function calculation. Projects resolution matrix to ellipsoids. :param _E: Resolution matrix. :type _E: np.ndarray, required :param idx: Axis index. :type idx: int, required :return: [fwhms, angles, eigenvectors], The resolution ellipsoid full width at half maximum, polar angle, and eigenvectors associated with the covariance matrix. :rtype: [np.ndarray,np.ndarray,list]

pyMACS.scripting.hkl_to_labframe(h, k, l, macs)

Helper function for resolution function calculation, takes the h,k,l indices and a macs instrument object and converts to Qx, Qz.

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

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

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

  • macs (virtualMacs, required) – pyMACS instrument object.

Returns:

Qx, Qz, where x is defined as perpendicular to beam and z is along beam.

Return type:

float,float

pyMACS.scripting.calc_ellipses(Qres_Q, verbose=True)

Helper function for resolution function calculation, Requires a resolution ellipsoid.

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

  • verbose (bool, optional.) – Prints output with resolution info to terminal.

Returns:

results,M_proj, these are the results dictionary containing the resolution ellipsoid info for the Qx-Qz plane, the Qx-E plane, and the Qz-E plane. M_proj is the projected resolution matrix on each plane.

Return type:

dict, np.ndarray

pyMACS.scripting.resfunc.nearest_MACS_resfunc(h, k, l, E, macsEf, gen_plot=False, figdir='Calculated_ellipsoid_pngs/', macs_obj=None, verbose=True, macs_dirac_obj=None, calc_mode='default', return_ellips=False)

Using a prevoiusly calculated database of resolution ellipsoids, returns the nearest ellipsoid to the input h,k,l,energy point. Can optionally :param h: Miller h index. Non-integer values allowed. :type h: float, required :param k: Miller k index. :type k: float, required :param l: Miller l index. :type l: float, required :param E: Energy transfer (meV) :type E: float, required :param macsEf: MACS final energy setting, only 3.7 and 5.0 meV are currently supported. :type macsEf: float, required. :param gen_plot: Flag to trigger creation of figure summarizing the MACS resolution ellipsoid. :type gen_plot: bool, optional. :param figdir: Output folder to save summary of resolution ellipsoid. :type figdir: str, optional :param macs_obj: If the user supplies a pyMACS object, the input sample coordinate system will be used rather than the Qx, Qz frame in Ang^-1. :type macs_obj: virtualMACS, optional :param verbose: Flag to print resoultion ellipsoid information to terminal. :type verbose: bool, optional. :param macs_dirac_obj: Input virtualMACS object using the Qx, Qz frame. User shouldn’t touch this. :type macs_dirac_obj: virtualMACS, optional :param calc_mode: 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. :type calc_mode: str, optional. :param return_ellips: Flag to return projected resolution ellipsoids to overplot on data rather than full matrix. :type return_ellips: bool, optional.

Returns:

Qres_Q,[fwhm_M[0],fwhm_M[1],fwhm_M_Eres],[hpt,kpt,wpt]. A list of the resolution ellipsoid M, The Bragg fwhms in Qx (Ang^-1), Qz (Ang^-1), E (meV), and the value of the closest tabulated point in (Qx,Qz,E).

Return type:

dict, np.ndarray

pyMACS.scripting.macs_resfunc(h, k, l, E, macsEf, macsobj=False, gen_plot=True, verbose=False, calc_mode='load_cov', figdir='Calculated_ellipsoid_pngs/', return_ellips=False)

Main function that recovers the MACS resolution ellipsoid from a pre-calculated set of ellipsoids.

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)

  • macsEf (float, required.) – MACS final energy setting, only 3.7 and 5.0 meV are currently supported.

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

  • macs_obj (virtualMACS, optional) – If the user supplies a pyMACS object, the input sample coordinate system 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.

  • return_ellips (bool, optional) – Flag to return the projected resolution ellipsoids rather than the full matrix. Useful for plotting.

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

pyMACS.scripting.res_ellipses(M, Qmean, macsobj=None, n_phi=361)

Shortcut function to return resollution ellipsoids for a given resolution matrix. Essentially automates the step of projection of the resolution matrix. The projection is in the sample Qx, Qz, E frame. The value of the center of the ellipsoid must be specified, Qmean, which is in units of u, v. For example, if u=[1,1,0], v=[0,0,1], and one wants the (1,1,0) reflection, use Qmean=[1,0,0]. If one wants the resolution at the (1,1,0) position and 1 meV transfer, use Qmean = [1,0,1]. If no virtualmacs object is provided, it is assumed that we are using the lab frame.

Parameters:
  • M (np.ndarray, required) – 3x3 Resolution matrix of the specified point.

  • Qmean (np.ndarray, required.) – Center of the resolution ellipsoid, in format [h, k, l, E]. Note that if the input point is not in the scattering plane, this will give wrong results.

  • macsobj (virtualMACS, optional.) – Virtualmacs object containing sample information and orientation. If not provided, will default to the lab frame and results will be in Ang^-1

Return ellip_list,proj_ellip_list:

Returns a list contiaining np arrays for each ellipse. The arrays are structured as [[Qxpts,Qzpts],[Qxpts,Epts],[Qzpts,Epts]]

Return type:

list, list

Create a list of object parameters, like n_mono.