pyextal.potentialMap ==================== .. py:module:: pyextal.potentialMap .. autoapi-nested-parse:: Potential and charge-density maps from refined structure factors. Reads a JAX refinement run from the dataset's HDF5 file, extends its refined structure factors over the ``.dat``'s beams by symmetry, and synthesises 2D sections/projections and 3D maps of the refined crystal, of the reference (``.dat``/IAM) crystal and of their difference. Maps can be written back under the run (`pyextal.hdf5io.save_map`) or exported for VESTA. Example:: from pyextal import hdf5io, potentialMap as pm run = hdf5io.load_refinement_run("sub1/ri_3_ro5-7.h5") # latest run ctx = pm.setup(run) # parses the run's .dat, groups beams proj = pm.project_2d(ctx, [-1, 1, 0], [0, 0, 1], kind='potential') hdf5io.save_map(run, "proj110_potential", proj) vol = pm.synthesize_3d(ctx, sampling=(64, 64, 64), g_max=1.2) s = pm.structure_from_bloch() pm.write_chgcar("diff.CHGCAR", vol.diff, s.lattice, s.atoms) Needs only the core dependencies (no JAX). Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pyextal/potentialMap/analysis/index /autoapi/pyextal/potentialMap/export/index /autoapi/pyextal/potentialMap/structure/index /autoapi/pyextal/potentialMap/structureFactors/index /autoapi/pyextal/potentialMap/synthesis/index /autoapi/pyextal/potentialMap/viz/index Classes ------- .. autoapisummary:: pyextal.potentialMap.LayerSF pyextal.potentialMap.MapContext pyextal.potentialMap.MapResult pyextal.potentialMap.PeakShift pyextal.potentialMap.Structure Functions --------- .. autoapisummary:: pyextal.potentialMap.setup pyextal.potentialMap.lattice_vectors pyextal.potentialMap.project_2d pyextal.potentialMap.synthesize_3d pyextal.potentialMap.fourier_synthesis pyextal.potentialMap.hkl_sphere pyextal.potentialMap.section_shape pyextal.potentialMap.U2V pyextal.potentialMap.find_atom_peaks pyextal.potentialMap.charge_density pyextal.potentialMap.charge_from_potential pyextal.potentialMap.line_profile pyextal.potentialMap.integrated_profile pyextal.potentialMap.structure_from_bloch pyextal.potentialMap.write_chgcar pyextal.potentialMap.read_chgcar pyextal.potentialMap.write_cube pyextal.potentialMap.read_cube pyextal.potentialMap.plot_map_comparison pyextal.potentialMap.plot_peak_shifts pyextal.potentialMap.plot_slices pyextal.potentialMap.plot_isosurface Package Contents ---------------- .. py:class:: LayerSF One layer's refined structure factors, resolvable for any beam. :ivar gvectors: (n, 3) refined reflections. :vartype gvectors: np.ndarray :ivar sf: (n, 4) ``[xfre, xfim, afre, afim]``, physical units. :vartype sf: np.ndarray :ivar sym: Space-group grouping; None for Friedel only. :vartype sym: GroupSymmetry or None :ivar layer: Layer index in the run. :vartype layer: int .. py:attribute:: gvectors :type: numpy.ndarray .. py:attribute:: sf :type: numpy.ndarray .. py:attribute:: sym :type: object :value: None .. py:attribute:: layer :type: int :value: 0 .. py:attribute:: _lookup :type: dict :value: None .. py:method:: __post_init__() .. py:method:: _refined(g) F(g) from the refined set, or None. .. py:method:: resolve(beams, model_sf=None) Electron structure factor (elastic part) for each beam. :param beams: (n, 3) Miller indices. :type beams: array-like :param model_sf: (n, 4) ``lookupSF`` format (amplitude, phase in degrees, ...) for the beams that are neither refined nor Friedel mates of refined ones. Defaults to ``lookupSF(beams)``. :type model_sf: np.ndarray, optional :returns: ``(F, source)`` -- complex (n,) and a str array (n,) of 'refined', 'friedel' or 'model'. :rtype: tuple .. py:class:: MapContext The crystal a run was refined against, loaded into the Bloch engine. :ivar run: The refinement run. :vartype run: RefinedRun :ivar dat: The ``.dat`` that was parsed. :vartype dat: Path :ivar beams: (n, 3) the ``.dat``'s beams, (0,0,0) excluded. :vartype beams: np.ndarray :ivar sym: Grouping of those beams, or None for a Friedel-only run. :vartype sym: GroupSymmetry or None :ivar cell: a, b, c, alpha, beta, gamma. :vartype cell: np.ndarray :ivar lattice: (3, 3) Cartesian lattice vectors (rows). :vartype lattice: np.ndarray :ivar metric: (3, 3) direct metric tensor, Angstrom^2. :vartype metric: np.ndarray :ivar volume: Cell volume, Angstrom^3. :vartype volume: float :ivar kv: Accelerating voltage in volts, from the ``.dat``. :vartype kv: float .. py:attribute:: run :type: object .. py:attribute:: dat :type: pathlib.Path .. py:attribute:: beams :type: numpy.ndarray .. py:attribute:: sym :type: object .. py:attribute:: cell :type: numpy.ndarray .. py:attribute:: lattice :type: numpy.ndarray .. py:attribute:: metric :type: numpy.ndarray .. py:attribute:: volume :type: float .. py:attribute:: kv :type: float .. py:method:: layer(i=0) The `LayerSF` of layer ``i``. .. py:function:: setup(run, dat=None, symmetry=None) Parses the run's ``.dat`` and groups its beams by symmetry. :param run: From `pyextal.hdf5io.load_refinement_run`. :type run: RefinedRun :param dat: The ``.dat`` to use. Defaults to the one embedded in the run (`pyextal.hdf5io.dat_for`). :type dat: path-like, optional :param symmetry: 'SpaceGroup' or 'Friedel'. Defaults to the run's ``symmetry_constraint``. :type symmetry: str, optional :returns: MapContext .. py:function:: lattice_vectors(cell) Cartesian direct-lattice vectors (rows a, b, c) in Angstrom. a along x, b in the xy plane -- the convention VESTA and VASP use. :param cell: a, b, c (Angstrom), alpha, beta, gamma (degrees). :type cell: sequence :returns: (3, 3), one lattice vector per row. :rtype: np.ndarray .. 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:: 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:: 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 .. 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:: 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:: 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:: PeakShift A reference-map peak and the refined-map maximum near it. :ivar ref: Grid index of the reference peak. :vartype ref: tuple :ivar refined: Grid index of the refined maximum. :vartype refined: tuple :ivar ref_val, refined_val: Map values there. :vartype ref_val, refined_val: float :ivar shift: Signed index offset, refined minus reference, wrapped to the nearest image. :vartype shift: tuple :ivar distance_A: Length of ``shift`` in Angstrom, through the map's grid steps (right for non-orthogonal axes). :vartype distance_A: float .. py:attribute:: ref :type: tuple .. py:attribute:: refined :type: tuple .. py:attribute:: ref_val :type: float .. py:attribute:: refined_val :type: float .. py:attribute:: shift :type: tuple .. py:attribute:: distance_A :type: float .. py:property:: distance_px Length of ``shift`` in grid steps. .. py:function:: find_atom_peaks(result, threshold_rel=0.5, min_distance=5, search_radius=5) Peaks of the reference map, each paired with the refined maximum nearby. Works on 2D and 3D maps; the grid is periodic. :param result: The maps. :type result: MapResult :param threshold_rel: Keep reference maxima above this fraction of the reference map's maximum. :type threshold_rel: float :param min_distance: Size of the local-maximum filter, in grid steps. :type min_distance: int :param search_radius: Half-width of the window searched in the refined map, in grid steps. :type search_radius: int :returns: list of PeakShift .. py:function:: charge_density(volume, steps=None, spacings=None) ``-laplacian(volume)``: the charge density, up to a constant, of a potential. :param volume: Periodic potential map. :type volume: np.ndarray :param steps: (ndim, 3) Cartesian grid steps (`MapResult.steps`). Uses an exact spectral Laplacian, right for oblique axes; result in map units per Angstrom^2. :type steps: np.ndarray, optional :param spacings: Per-axis spacing for the original 3-point finite-difference Laplacian, which assumes orthogonal axes. Used when ``steps`` is None (all 1.0 if both are None). :type spacings: tuple, optional :returns: Same shape as ``volume``. :rtype: np.ndarray .. py:function:: charge_from_potential(result, method='spectral', spacings=None) Converts a potential `MapResult` into charge density by Poisson's equation. :param result: Potential maps. :type result: MapResult :param method: 'spectral' (exact, uses the grid geometry) or 'finite_difference' (the original 3-point stencil with ``spacings``, default 1.0 per axis). :type method: str :param spacings: For 'finite_difference'. :type spacings: tuple, optional :returns: ``kind='charge'``, the maps replaced by ``-laplacian``. :rtype: MapResult .. py:function:: line_profile(volume, start, end, num_points=100) Values of a 3D periodic map along a straight line. :param volume: 3D map on a fractional grid. :type volume: np.ndarray :param start: End points in fractional coordinates (any image; wrapped into the cell). :type start: array-like :param end: End points in fractional coordinates (any image; wrapped into the cell). :type end: array-like :param num_points: Samples along the line. :type num_points: int :returns: ``(distance, values)``, the distance in fractional units. :rtype: tuple .. py:function:: integrated_profile(volume, start, end, radius, num_points=100, grid_points=21, lattice=None) A 3D map integrated over discs perpendicular to a line, along that line. :param volume: 3D map on a fractional grid. :type volume: np.ndarray :param start: End points in fractional coordinates. :type start: array-like :param end: End points in fractional coordinates. :type end: array-like :param radius: Disc radius: fractional units, or Angstrom when ``lattice`` is given. :type radius: float :param num_points: Steps along the line. :type num_points: int :param grid_points: Samples across each disc diameter. :type grid_points: int :param lattice: (3, 3) Cartesian lattice vectors. With it the discs are perpendicular, and round, in real space -- needed for a non-cubic cell. Without it they are built in fractional coordinates (the original behaviour). :type lattice: np.ndarray, optional :returns: ``(distance, profile, points)``. ``distance`` along the line (as the radius), ``points`` the fractional sampling positions before wrapping, shape ``(num_points, grid_points, grid_points, 3)``. :rtype: tuple .. py:class:: Structure Atoms of the conventional cell. :ivar lattice: (3, 3) Cartesian lattice vectors (rows), Angstrom. :vartype lattice: np.ndarray :ivar symbols: Element of each atom. :vartype symbols: list of str :ivar frac: (n, 3) fractional coordinates in [0, 1). :vartype frac: np.ndarray :ivar numbers: (n,) atomic numbers. :vartype numbers: np.ndarray .. py:attribute:: lattice :type: numpy.ndarray .. py:attribute:: symbols :type: list .. py:attribute:: frac :type: numpy.ndarray .. py:attribute:: numbers :type: numpy.ndarray .. py:property:: atoms ``[(symbol, [x, y, z]), ...]``, the form `write_chgcar` takes. .. py:function:: structure_from_bloch() Expands the asymmetric unit in the engine's ``cryst`` block to the full cell. Needs a ``.dat`` parsed first (`pyextal.callBloch.bloch_parse`, or `pyextal.potentialMap.setup`). :returns: Structure .. py:function:: write_chgcar(path, volume, lattice, atoms=None, origin_shift=None) Writes a 3D map as a VASP CHGCAR (values times the cell volume). :param path: Output file. :type path: path-like :param volume: (Nx, Ny, Nz) map on the fractional grid. :type volume: np.ndarray :param lattice: (3, 3) Cartesian lattice vectors (rows), Angstrom. :type lattice: np.ndarray :param atoms: ``[(symbol, [x, y, z]), ...]`` fractional, e.g. `Structure.atoms`. Without atoms a dummy H at the origin is written so viewers still draw the cell. :type atoms: list, optional :param origin_shift: Fractional shift applied to the atoms and, rounded to whole grid steps, to the map. :type origin_shift: array-like, optional .. py:function:: read_chgcar(path) Reads a CHGCAR written by `write_chgcar` (or VASP). :returns: ``(volume, lattice, atoms)``, the map divided back by the cell volume. :rtype: tuple .. py:function:: write_cube(path, volume, structure=None, comment='Generated by pyextal') Writes a 3D map as a Gaussian cube file (lengths in Bohr). :param path: Output file. :type path: path-like :param volume: (Nx, Ny, Nz) map on the fractional grid. :type volume: np.ndarray :param structure: Cell and atoms; defaults to `structure_from_bloch()`. :type structure: Structure, optional :param comment: Second header line. :type comment: str .. py:function:: read_cube(path) Reads a cube file written by `write_cube`. :returns: ``(volume, lattice, numbers, cart)``, lattice and atom positions in Angstrom. :rtype: tuple .. py:function:: plot_map_comparison(result, line_center=None, label=None, save_dir=None) Refined, reference and difference maps of a 2D result, with a line profile. :param result: A 2D map. :type result: MapResult :param line_center: Column of the vertical line profile; defaults to the middle. :type line_center: int, optional :param label: Title suffix and file-name stem; defaults to ``layer``. :type label: str, optional :param save_dir: Writes ``map_comparison_