pyextal.potentialMap.synthesis ============================== .. py:module:: pyextal.potentialMap.synthesis .. autoapi-nested-parse:: Fourier synthesis of potential and charge-density maps. Both kinds of map are sampled on grids that are uniform in fractional (direct-lattice) coordinates, so a map is exactly a discrete Fourier transform on its grid points:: map[n] = sum_g F(g) exp(-2 pi i g . r_n), r_n = sum_i n_i axes[i] The structure factors are scattered into an array at their (folded) integer frequencies and transformed with one FFT. That is exact at the grid points for any grid size and costs O(N log N) whatever the number of beams; the old per-beam loop cost O(N_grid * N_beams). A 2D section whose axes are not integer lattice vectors has non-integer frequencies and falls back to a direct sum, which is still separable along the two axes. Units follow the original potential_mapping code: a potential map is the electron structure factor times `U2V` (volts), a charge map is the X-ray structure factor (`pyextal.callBloch.e2Xray`) over the cell volume (electrons / Angstrom^3). Attributes ---------- .. autoapisummary:: pyextal.potentialMap.synthesis.KINDS Classes ------- .. autoapisummary:: pyextal.potentialMap.synthesis.MapResult Functions --------- .. autoapisummary:: pyextal.potentialMap.synthesis.U2V pyextal.potentialMap.synthesis._fft_synthesis pyextal.potentialMap.synthesis._direct_2d pyextal.potentialMap.synthesis._xray pyextal.potentialMap.synthesis._coefficients pyextal.potentialMap.synthesis._finish pyextal.potentialMap.synthesis.section_shape pyextal.potentialMap.synthesis.project_2d pyextal.potentialMap.synthesis.hkl_sphere pyextal.potentialMap.synthesis.synthesize_3d pyextal.potentialMap.synthesis.fourier_synthesis Module Contents --------------- .. py:data:: KINDS :value: ('potential', 'charge') .. py:function:: U2V(kv) Factor from the structure factor U_g to the potential V_g in volts. :param kv: Accelerating voltage in volts. :type kv: float .. py:class:: MapResult A refined map, its reference and their difference. :ivar refined: Map from the refined structure factors. :vartype refined: np.ndarray :ivar reference: Map from the reference (``.dat``/IAM) ones. :vartype reference: np.ndarray :ivar diff: ``refined - reference``. :vartype diff: np.ndarray :ivar hkl: (n, 3) the beams summed. :vartype hkl: np.ndarray :ivar sf_refined, sf_reference: (n,) complex coefficient of each beam, in the map's units before the volume/voltage factor. :vartype sf_refined, sf_reference: np.ndarray :ivar source: (n,) where each refined coefficient came from: 'refined', 'friedel' or 'model' (see `LayerSF.resolve`). :vartype source: np.ndarray :ivar kind: 'potential' or 'charge'. :vartype kind: str :ivar layer: The run layer the refined map is from. :vartype layer: int :ivar axes: (ndim, 3) one grid step along each array axis, in fractional direct-lattice coordinates. :vartype axes: np.ndarray :ivar lattice: (3, 3) Cartesian lattice vectors (rows). :vartype lattice: np.ndarray :ivar settings: The arguments the map was made with. :vartype settings: dict .. py:attribute:: refined :type: numpy.ndarray .. py:attribute:: reference :type: numpy.ndarray .. py:attribute:: diff :type: numpy.ndarray .. py:attribute:: hkl :type: numpy.ndarray .. py:attribute:: sf_refined :type: numpy.ndarray .. py:attribute:: sf_reference :type: numpy.ndarray .. py:attribute:: source :type: numpy.ndarray .. py:attribute:: kind :type: str .. py:attribute:: layer :type: int .. py:attribute:: axes :type: numpy.ndarray .. py:attribute:: lattice :type: numpy.ndarray .. py:attribute:: settings :type: dict .. py:property:: ndim .. py:property:: steps (ndim, 3) Cartesian grid step along each array axis, Angstrom. .. py:method:: cartesian_grid() Cartesian position of every grid point, shape ``map.shape + (3,)``. .. py:function:: _fft_synthesis(F, freq, shape) ``sum_g F_g exp(-2 pi i freq_g . n / shape)`` on every grid point n. .. py:function:: _direct_2d(F, gy, gx, shape) Separable direct sum for non-integer frequencies on an (ny, nx) grid. .. py:function:: _xray(beams, F, to_xray) X-ray structure factor of each beam from its electron one. .. py:function:: _coefficients(ctx, layer, beams, kind, model_sf, to_xray, reference_iam) Refined and reference Fourier coefficients, and the beams' sources. .. py:function:: _finish(ctx, maps, beams, F, F_ref, source, kind, layer, axes, kv, settings) .. py:function:: section_shape(metric, x_vector, y_vector, sampling) (ny, nx) of a 2D section: ``sampling`` columns, rows by true length. :param metric: (3, 3) direct metric tensor. :type metric: np.ndarray :param x_vector: Section axes, direct-lattice indices. :type x_vector: array-like :param y_vector: Section axes, direct-lattice indices. :type y_vector: array-like :param sampling: Columns, or an explicit (ny, nx). :type sampling: int or tuple .. py:function:: project_2d(ctx, x_vector, y_vector, layer=0, beams=None, sampling=256, kind='potential', kv=None, model_sf=None, to_xray=None, reference_iam=False) Refined, reference and difference map on the section spanned by two axes. The grid point at row i, column j sits at ``i/ny * y_vector + j/nx * x_vector``. Only ``g . x_vector`` and ``g . y_vector`` enter the phase, so with the zero-order Laue zone beams this is the projected map down the zone axis. :param ctx: From `setup`. :type ctx: MapContext :param x_vector: Section axes in direct-lattice indices, e.g. ``[-1, 1, 0]`` and ``[0, 0, 1]`` for the [110] zone. :type x_vector: array-like :param y_vector: Section axes in direct-lattice indices, e.g. ``[-1, 1, 0]`` and ``[0, 0, 1]`` for the [110] zone. :type y_vector: array-like :param layer: Run layer to map. :type layer: int or LayerSF :param beams: (n, 3) beams to sum. Defaults to the ``.dat``'s beams. :type beams: array-like, optional :param sampling: Columns (rows follow the true axis lengths), or an explicit (ny, nx). :type sampling: int or tuple :param kind: 'potential' (volts) or 'charge' (e / Angstrom^3). :type kind: str :param kv: Voltage in volts for the potential; defaults to the ``.dat``'s. :type kv: float, optional :param model_sf: ``lookupSF``-format values for beams the run did not refine, or a function of the beams. :type model_sf: np.ndarray or callable, optional :param to_xray: Electron-to-X-ray conversion with the signature of `pyextal.callBloch.e2Xray` (the default). :type to_xray: callable, optional :param reference_iam: Reference from the IAM even where the ``.dat`` sets a structure factor. :type reference_iam: bool :returns: MapResult .. py:function:: hkl_sphere(gstar, g_max=None, hkl_range=None) All non-zero hkl in a box, optionally cut to ``|g| <= g_max``. :param gstar: (3, 3) reciprocal metric tensor, Angstrom^-2. :type gstar: np.ndarray :param g_max: Largest |g| in 1/Angstrom. :type g_max: float, optional :param hkl_range: (p0, p1, p2), the box ``|h| <= p0`` etc. Defaults to the smallest box that holds the ``g_max`` sphere. :type hkl_range: tuple, optional :returns: (n, 3) int. :rtype: np.ndarray .. py:function:: synthesize_3d(ctx, layer=0, sampling=(64, 64, 64), hkl_range=None, g_max=None, beams=None, kind='potential', kv=None, model_sf=None, to_xray=None, reference_iam=False) Refined, reference and difference map over the unit cell. The grid is ``sampling`` points along a, b and c; point (i, j, k) sits at fractional coordinates ``(i/N0, j/N1, k/N2)``. :param ctx: From `setup`. :type ctx: MapContext :param layer: Run layer to map. :type layer: int or LayerSF :param sampling: (N0, N1, N2). :type sampling: tuple :param hkl_range: (p0, p1, p2) box of beams to sum. :type hkl_range: tuple, optional :param g_max: Keep beams with ``|g| <= g_max`` (1/Angstrom, through the reciprocal metric, so right for any cell). :type g_max: float, optional :param beams: Explicit (n, 3) beams instead of the two above. :type beams: array-like, optional :param kind: As in `project_2d`. :param kv: As in `project_2d`. :param model_sf: As in `project_2d`. :param to_xray: As in `project_2d`. :param reference_iam: As in `project_2d`. :returns: MapResult .. py:function:: fourier_synthesis(getSF, order, sampling) 3D map from a structure-factor function, normalised by the cell volume. The engine behind the old `pyextal.densityMap.fourierSynthesis`: sums ``getSF(hkl)[0] + 1j*getSF(hkl)[1]`` over ``|h|,|k|,|l| <= order`` (excluding 000) on a ``sampling``^3 fractional grid. :param getSF: (h, k, l) -> sequence whose first two entries are the real and imaginary structure factor. :type getSF: callable :param order: Largest index. :type order: int :param sampling: Grid points per axis. :type sampling: int :returns: Real (sampling, sampling, sampling) map. :rtype: np.ndarray