hikari.dataframes.hkl
Classes
Metaclass for HklKey`s which registers them if they define `name. |
|
Base Class for every subsequent HklKey. |
|
Base Class for every subsequent HklKey. |
|
Base Class for every subsequent HklKey. |
|
Base Class for every subsequent HklKey. |
|
Reciprocal lattice Miller index h |
|
Reciprocal lattice Miller index k |
|
Reciprocal lattice Miller index l |
|
Crystallographic structure factor F |
|
Crystallographic intensity I_obs |
|
Crystallographic calculated intensity I_calc |
|
Uncertainty of intensity I determination |
|
Uncertainty of structure factor F determination |
|
Structure factor to its uncertainty ratio |
|
Batch or run number |
|
Crystal domain or twin number |
|
Multiplicity i.e. how many observation contributed to this reflection |
|
Wavelength expressed in Angstrom |
|
Reflection phase expressed in radians |
|
Distance from 000 node, i.e. double the sin(th)/la resolution in A^-1 |
|
Absorption-weighted transmission path length in centimeters |
|
Direction cosines of a vector (unused, see XD manual for reference) |
|
Direction cosines of a vector (unused, see XD manual for reference) |
|
Direction cosines of a vector (unused, see XD manual for reference) |
|
Direction cosines of a vector (unused, see XD manual for reference) |
|
Direction cosines of a vector (unused, see XD manual for reference) |
|
Direction cosines of a vector (unused, see XD manual for reference) |
|
Reciprocal space coordinate x* |
|
Reciprocal space coordinate x* |
|
Reciprocal space coordinate x* |
|
weighted diff. in observed I - calculated Ic intensity |
|
weighted diff. in observed I - calculated Ic intensity, squared |
|
Calculated intensity of reflection divided by experimental sigma |
|
Observed intensity of reflection divided by experimental sigma |
|
Integer unique for each set of symmetrically equivalent reflections |
|
Dummy column for loading or holding irrelevant string data |
|
A master object which manages single-crystal diffraction files. |
|
A helper class supporting HklFrame. Manages reading and writing hkl files |
|
A helper class for HklFrame, |
|
A helper class for HklFrame, |
|
A class responsible for representing hkl data using .res format |
Module Contents
- class hikari.dataframes.hkl.HklKeyRegistrar[source]
Bases:
typeMetaclass for HklKey`s which registers them if they define `name.
- REGISTRY
- default: None
- dtype: numpy.dtype
- property IMPERATIVES
- class hikari.dataframes.hkl.HklKey[source]
Base Class for every subsequent HklKey.
- name: str = ''
- default = None
- dtype: str = ''
- imperative: bool = False
- reduce_behaviour: str = 'keep'
- type: HklKey.type
- class hikari.dataframes.hkl.HklKeyImperativeInt8[source]
Bases:
HklKeyBase Class for every subsequent HklKey.
- default = 0
- dtype
- imperative = True
- class hikari.dataframes.hkl.HklKeyAveragedFloat64[source]
Bases:
HklKeyBase Class for every subsequent HklKey.
- default = 0.0
- dtype
- reduce_behaviour = 'average'
- class hikari.dataframes.hkl.HklKeyKeptFloat64[source]
Bases:
HklKeyBase Class for every subsequent HklKey.
- default = 0.0
- dtype
- reduce_behaviour = 'keep'
- class hikari.dataframes.hkl.HklKeyIndexH[source]
Bases:
HklKeyImperativeInt8Reciprocal lattice Miller index h
- name = 'h'
- class hikari.dataframes.hkl.HklKeyIndexK[source]
Bases:
HklKeyImperativeInt8Reciprocal lattice Miller index k
- name = 'k'
- class hikari.dataframes.hkl.HklKeyIndexL[source]
Bases:
HklKeyImperativeInt8Reciprocal lattice Miller index l
- name = 'l'
- class hikari.dataframes.hkl.HklKeyStructureFactor[source]
Bases:
HklKeyAveragedFloat64Crystallographic structure factor F
- name = 'F'
- default = 1.0
- class hikari.dataframes.hkl.HklKeyIntensity[source]
Bases:
HklKeyAveragedFloat64Crystallographic intensity I_obs
- name = 'I'
- default = 1.0
- class hikari.dataframes.hkl.HklKeyIntensityCalculated[source]
Bases:
HklKeyAveragedFloat64Crystallographic calculated intensity I_calc
- name = 'Ic'
- default = 1.0
- class hikari.dataframes.hkl.HklKeyIntensityUncertainty[source]
Bases:
HklKeyAveragedFloat64Uncertainty of intensity I determination
- name = 'si'
- class hikari.dataframes.hkl.HklKeyStructureFactorUncertainty[source]
Bases:
HklKeyAveragedFloat64Uncertainty of structure factor F determination
- name = 'sf'
- class hikari.dataframes.hkl.HklKeyStructureFactorToUncertaintyRatio[source]
Bases:
HklKeyAveragedFloat64Structure factor to its uncertainty ratio
- name = 'u'
- class hikari.dataframes.hkl.HklKeyBatchNumber[source]
Bases:
HklKeyBatch or run number
- name = 'b'
- default = 0
- dtype
- reduce_behaviour = 'discard'
- class hikari.dataframes.hkl.HklKeyCrystalNumber[source]
Bases:
HklKeyCrystal domain or twin number
- name = 'c'
- default = 0
- dtype
- reduce_behaviour = 'discard'
- class hikari.dataframes.hkl.HklKeyMultiplicity[source]
Bases:
HklKeyMultiplicity i.e. how many observation contributed to this reflection
- name = 'm'
- default = 1
- dtype
- imperative = True
- reduce_behaviour = 'add'
- class hikari.dataframes.hkl.HklKeyWavelength[source]
Bases:
HklKeyWavelength expressed in Angstrom
- name = 'la'
- default = 0.0
- dtype
- reduce_behaviour = 'discard'
- class hikari.dataframes.hkl.HklKeyPhase[source]
Bases:
HklKeyAveragedFloat64Reflection phase expressed in radians
- name = 'ph'
- default = 0.0
- class hikari.dataframes.hkl.HklKeyRadius[source]
Bases:
HklKeyDistance from 000 node, i.e. double the sin(th)/la resolution in A^-1
- name = 'r'
- dtype
- class hikari.dataframes.hkl.HklKeyTransmissionPathLength[source]
Bases:
HklKeyKeptFloat64Absorption-weighted transmission path length in centimeters
- name = 't'
- class hikari.dataframes.hkl.HklKeyCosineU1[source]
Bases:
HklKeyKeptFloat64Direction cosines of a vector (unused, see XD manual for reference)
- name = 'u1'
- class hikari.dataframes.hkl.HklKeyCosineU2[source]
Bases:
HklKeyKeptFloat64Direction cosines of a vector (unused, see XD manual for reference)
- name = 'u2'
- class hikari.dataframes.hkl.HklKeyCosineU3[source]
Bases:
HklKeyKeptFloat64Direction cosines of a vector (unused, see XD manual for reference)
- name = 'u3'
- class hikari.dataframes.hkl.HklKeyCosineV1[source]
Bases:
HklKeyKeptFloat64Direction cosines of a vector (unused, see XD manual for reference)
- name = 'v1'
- class hikari.dataframes.hkl.HklKeyCosineV2[source]
Bases:
HklKeyKeptFloat64Direction cosines of a vector (unused, see XD manual for reference)
- name = 'v2'
- class hikari.dataframes.hkl.HklKeyCosineV3[source]
Bases:
HklKeyKeptFloat64Direction cosines of a vector (unused, see XD manual for reference)
- name = 'v3'
- class hikari.dataframes.hkl.HklKeyCoordinateX[source]
Bases:
HklKeyKeptFloat64Reciprocal space coordinate x*
- name = 'x'
- dtype
- class hikari.dataframes.hkl.HklKeyCoordinateY[source]
Bases:
HklKeyKeptFloat64Reciprocal space coordinate x*
- name = 'y'
- dtype
- class hikari.dataframes.hkl.HklKeyCoordinateZ[source]
Bases:
HklKeyKeptFloat64Reciprocal space coordinate x*
- name = 'z'
- dtype
- class hikari.dataframes.hkl.HklKeyZeta[source]
Bases:
HklKeyAveragedFloat64weighted diff. in observed I - calculated Ic intensity
- name = 'ze'
- class hikari.dataframes.hkl.HklKeyZetaSquared[source]
Bases:
HklKeyAveragedFloat64weighted diff. in observed I - calculated Ic intensity, squared
- name = 'ze2'
- class hikari.dataframes.hkl.HklKeyCalculatedIntensityToSigma[source]
Bases:
HklKeyAveragedFloat64Calculated intensity of reflection divided by experimental sigma
- name = 'Icsi'
- default = 1.0
- class hikari.dataframes.hkl.HklKeyObservedIntensityToSigma[source]
Bases:
HklKeyAveragedFloat64Observed intensity of reflection divided by experimental sigma
- name = 'Iosi'
- default = 1.0
- class hikari.dataframes.hkl.HklKeyEquivalenceCode[source]
Bases:
HklKeyInteger unique for each set of symmetrically equivalent reflections
- name = 'equiv'
- default = 0
- dtype
- class hikari.dataframes.hkl.HklKeyDummy[source]
Bases:
HklKeyDummy column for loading or holding irrelevant string data
- name = 'None'
- default = ''
- dtype
- class hikari.dataframes.hkl.HklFrame[source]
Bases:
hikari.dataframes.BaseFrameA master object which manages single-crystal diffraction files. It utilises other Hkl* classes to import, store, manipulate and output information about single-crystal diffraction patterns.
HklFrame acts as a container which stores the diffraction data (Pandas dataframe,
table) and elementary crystal cell data (hikari.dataframes.Base). Demanding methods belonging to this class are vectorized, providing relatively satisfactory performance and high memory capacity. HklFrame methods are designed to work in-place, so the work strategy is to create a new instance of HklFrame for each reflection dataset, manipulate it using methods, eg.merge()ortrim(), andcopy()to other object or output usingwrite()if needed.The HklFrame always initiates empty and does not accept any arguments. Some magic methods, such as
__len__()and__add__()are defined and describe/operate on theframe.- HKL_LIMIT = 127
Highest absolute value of h, k or l index, which can be interpreted correctly by current version of the software.
- __la = 0.71069
Wavelength of radiation used in experiment.
- table
Pandas dataframe containing diffraction data information. Each row represents one reflection observation, while each column has one piece of information about the reflections. For a list of available keys, see
HklKeys, whose instance is used to menage the keys of this table.
- property la
Wavelength of radiation used in the diffraction experiment. Can be set using popular abbreviations such as “MoKa” or “CuKb”, where a and b stand for alpha and beta. Implemented cathode materials include: “Ag”, “Co”, “Cr”, “Cu”, “Fe”, “Mn”, “Mo”, “Ni”, “Pd”, “Rh”, “Ti”, “Zn” and have been imported from International Tables of Crystallography, Volume C, Table 4.2.4.1, 3rd Edition.
- Returns:
wavelength of radiation used in experiment
- Return type:
float
- dac_trim(opening_angle=35.0, vector=None)[source]
Remove reflections outside the opening_angle DAC-accessible volume. Sample/DAC orientation can be supplied either via specifying crystal orientation in
hikari.dataframes.BaseFrame, inorientationor providing a xyz* vector perpendicular to the dac-accessible disc. For further details, see *Tchoń & Makal, IUCrJ 8, 1006-1017 (2021)*.- Parameters:
opening_angle (float) – DAC single opening angle in degrees, default 35.
vector (tuple[float]) – Provides information about orientation of crystal relative to DAC. If None,
orientationis used instead.
- Returns:
HklFrame containing only reflections in dac-accessible region.
- Return type:
- dacs_count(opening_angle=35.0, vectors=np.array((1, 0, 0)))[source]
Count unique dac-accessible reflections for n crystals placed such that vector n is perpendicular to diamond. For details see
dac_trim().- Parameters:
opening_angle (float) – DAC single opening angle in degrees, default 35.
vectors (np.array) – Array with rotational axes of available DAC-discs.
- Returns:
Array with numbers of unique reflns in DAC-accessible region.
- Return type:
np.array
- extinct(space_group=SG['P1'])[source]
Removes from dataframe reflections which should be extinct based on space
hikari.symmetry.group.Group. For ref. see ITC-A12.3.5.- Parameters:
space_group (hikari.symmetry.group.Group) – Space group used to extinct the reflections.
- find_equivalents(point_group=PG['1'])[source]
Assign each reflection its symmetry equivalence identifier and store it in the hikari.dataframes.HklFrame.data[‘equiv’] column. The ID is an integer unique for each set of equivalent reflections.
In order to provide an information about equivalence, a point_group of reciprocal space must be provided (default PG[‘1’]). Point groups and their notation can be found in
hikari.symmetrysub-package.- Parameters:
point_group (hikari.symmetry.Group) – Point group used to determine symmetry equivalence
- from_dict(dictionary)[source]
Construct the self.data using information stored in dictionary. The dictionary keys must be valid strings, see
HklKeysfor a list of valid keys. The dictionary values must be iterable of equal size, preferably numpy.ndarray.- Parameters:
dictionary (Dict[str, numpy.ndarray]) – Dictionary with “key - iterable of values” pairs.
- fill(radius=2.0)[source]
Fill dataframe with all reflections within radius from space origin.
- Parameters:
radius (float) – Maximum distance from the reciprocal space origin to placed reflection (in reciprocal Angstrom).
- Return type:
None
- stats(bins=10, space_group=SG['P1'])[source]
Returns completeness, redundancy, number of all, unique & theoretically possible reflections within equal-volume bins in given space group.
- Parameters:
bins (int) – Number of equal-volume bins to divide the data into.
space_group (hikari.symmetry.Group) – Group used to calculate equivalence and extinctions
- Returns:
String containing table with stats as a function of resolution
- Return type:
str
- merge(point_group=PG['1'])[source]
Average down each set of redundant reflections present in the table, to one reflection. The redundancy is determined using the
find_equivalents()method with appropriate point group. Thus, the merging can be used in different ways depending on point group:For PG[‘1’], only reflections with exactly the same h, k, l indices will be merged. Resulting dataframe will not contain any duplicates.
For PG[‘-1’] reflections with the same h, k and l as well as their Friedel pairs will be merged together to one reflection.
For PG[‘mmm’] all equivalent reflections of “mmm” point group will be merged. Since “mmm” is centrosymmetric, Friedel pairs will be merged.
For PG[‘mm2’] symmetry-equivalent reflections within the “mmm” point group will be merged, but the Friedel pairs will be preserved.
The procedure will have a different effect on different dataframe keys, depending on their “reduce_behaviour” specified in
HklKeys. Fixed parameters h, k, l, x, y, z, r and equiv will be preserved; Floating points such as intensity I, structure factor F and their uncertainties si and sf will be averaged using arithmetic mean; Multiplicity m will be summed; Other parameters which would lose their meaning such as batch number b will be discarded.The merging inevitably removes some information from the dataframe, but it can be necessary for some operations. For example, the drawing procedures work faster and provide clearer image if multiple points occupying the same position in space are reduced to one instance.
- Parameters:
point_group (hikari.symmetry.Group) – Point Group used to determine symmetry equivalence
- place()[source]
Assign reflections their positions in reciprocal space (“x”, “y”, “z”) and calculate their distance from origin (“r”) in reciprocal Angstrom. Save four new keys and their values into the dataframe.
- calculate_fcf_statistics()[source]
Calculate values of zeta (I - Ic) / si on other stats based on contents of fcf files. Save new key and its values into the dataframe.
- read(hkl_path, hkl_format='shelx_4')[source]
Read the contents of .hkl file as specified by path and format, and store them in the pandas dataframe in self.data. For a list of all available .hkl formats, please refer to
hikari.dataframes.HklIo.format.- Parameters:
hkl_path (str) – Absolute or relative path to the .hkl file.
hkl_format (union[int, str, dict]) – Format of provided .hkl file.
- _recalculate_structure_factors_and_intensities()[source]
Calculate ‘I’ and ‘si’ or ‘F’ and ‘sf’, depending on which are missing.
- _recalculate_structure_factors_from_intensities()[source]
Recalculate the structure factor F and its uncertainty sf.
Structure factor is calculated as follows: F = signum(I) * sqrt(abs(I)).
Structure factor’s uncertainty is calculated as follows: sf = si / (2 * sqrt(abs(I))).
- _recalculate_intensities_from_structure_factors()[source]
Recalculate the intensity I and its uncertainty si.
Intensity is calculated as follows: I = signum(F) * F ** 2.
Intensity’s uncertainty is calculated as follows: si = 2 * sf * abs(F).
- transform(operations)[source]
Apply a symmetry operation or list of symmetry operations to transform the diffraction pattern.
If one symmetry operation (3x3 or 4x4 numpy array) is provided, it effectively multiplies the hkl matrix by the operation matrix and accordingly alters the self.data dataframe. As a result, the length of self.data before and after transformation is the same.
However, the function behaves slightly counter-intuitively if two or more operation matrices are provided. In such case the method applies the transformation procedure independently for each operation, and then concatenates resulting matrices. Resulting self.data is len(operations) times longer than the initial.
The function can use 3x3 or larger (e.g. 4x4) matrices, as it selects only the upper-left 3x3 segment for the sake of calculations. Also, while reconstructing the symmetry of merged reflection file it is important to use all symmetry operations, not only generators.
Single symmetry operations or their lists belonging to certain point groups can be imported from
hikari.symmetrymodule.- Parameters:
operations (Union[Iterable[np.ndarray], np.ndarray]) – Iterable of operation matrices to be applied
- thin_out(target_cplt=1.0)[source]
Randomly remove reflections from dataframe in order to decrease the completeness to target_cplt (relatively to initial completeness).
- Parameters:
target_cplt (float) – Percentage of data not removed from dataframe
- to_res(path='hkl.res', colored='m')[source]
Export the reflection information from table to .res file, so that a software used to visualize .res files can be used to visualize a diffraction data in three dimensions.
- Parameters:
colored (str) – Which key of dataframe should be visualized using color
path (str) – Absolute or relative path where the file should be saved
- trim(limit)[source]
Remove reflections further than limit from reciprocal space origin.
- Parameters:
limit (float) – Radius of the trimming sphere in reciprocal Angstrom
- write(hkl_path, hkl_format='shelx_4')[source]
Write the contents of dataframe to a .hkl file using specified path and format. For a list of all available .hkl formats, please refer to
hikari.dataframes.HklIo.format.- Parameters:
hkl_path (str) – Absolute or relative path to the .hkl file.
hkl_format (union[int, str, dict]) – Desired format of .hkl file.
- class hikari.dataframes.hkl.HklIo(hkl_file_path, hkl_file_format)[source]
A helper class supporting HklFrame. Manages reading and writing hkl files into and out of HklFrame’s dataframe.
- use_separator = True
- file_path = ''
- formats_defined
- formats_aliases
- __format = 'shelx_4'
- property format
Return a name of currently used hkl file format. Available file formats and their aliases are defined internally in .json files and have been presented in a table below:
Name
Aliases
Contents (format string)
Prefix
Suffix
Free format
free_2
h -4 k -4 l -4 I -8 si -8 b -4 la -8
NO
YES (a)
YES
free_3
h -4 k -4 l -4 F -8 sf -8 b -4
NO
YES (a)
YES
free_4
h -4 k -4 l -4 I -8 si -8 b -4
NO
YES (a)
YES
free_40
free
h -4 k -4 l -4 I -8 si -8
NO
YES (a)
YES
free_5
h -4 k -4 l -4 I -8 si -8 c -4
NO
YES (a)
YES
free_6
h -4 k -4 l -4 I -8 si -8 m -4
NO
YES (a)
YES
m80
h 4 k 4 l 4 b 4 F 12 None 132
YES (b)
YES (b)
NO
shelx_2
2
h 4 k 4 l 4 I 8 si 8 b 4 la 8
NO
YES (a)
NO
shelx_3
3
h 4 k 4 l 4 F 8 sf 8 b 4
NO
YES (a)
NO
shelx_4
4
h 4 k 4 l 4 I 8 si 8 b 4
NO
YES (a)
NO
shelx_40
40
h 4 k 4 l 4 I 8 si 8
NO
YES (a)
NO
shelx_5
5
h 4 k 4 l 4 I 8 si 8 c 4
NO
YES (a)
NO
shelx_6
6
h 4 k 4 l 4 I 8 si 8 m 4
NO
YES (a)
NO
shelx_fcf
fcf
h 4 k 4 l 4 Ic 14 I 14 si 13
YES (*)
NO
NO
tonto_F
h -4 k -4 l -4 F -8 sf -8
YES (c)
YES (c)
YES
tonto_I
tonto
h -4 k -4 l -4 I -8 si -8
YES (c)
YES (c)
YES
xd_F6
h -4 k -4 l -4 b -3 F -13 sf -13
YES (d)
NO
YES
xd_F7
h -4 k -4 l -4 b -3 F -13 sf -13 t -10
YES (d)
NO
YES
xd_F-7
h -4 k -4 l -4 b -3 F -13 sf -13 ph -10
YES (d)
NO
YES
xd_F13
h -4 k -4 l -4 b -3 F -13 sf -13 t -10 u1 -10 u2 -10 u3 -10 v1 -10 v2 -10 v3 -10
YES (d)
NO
YES
xd_I6
xd
h -4 k -4 l -4 b -3 I -13 si -13
YES (d)
NO
YES
xd_I7
h -4 k -4 l -4 b -3 I -13 si -13 t -10
YES (d)
NO
YES
xd_I-7
h -4 k -4 l -4 b -3 I -13 si -13 ph -10
YES (d)
NO
YES
xd_I13
h -4 k -4 l -4 b -3 I -13 si -13 t -10 u1 -10 u2 -10 u3 -10 v1 -10 v2 -10 v3 -10
YES (d)
NO
YES
custom
custom string as above with keys and widths
NO
NO
if all widths in format are <0
Three different types of prefix / suffix are supported at the moment:
Suffix (a) is a zero-line: a shelx ending line with h = k = l = 0,
Prefix and suffix (b) express a superflip-style block/start end,
Prefix and suffix (c) are tonto-characteristic beginning/end of file,
Prefix (d) is an xd-characteristic line with info about file content.
Pre/suffixes denoted with (*) are not supported in terms of writing. A custom hkl file format can be defined by providing a format string instead of ‘Name’. The string should look like the ones in column “contents”. For the meaning of keys (‘I’, ‘b’, ‘c’ etc.), please refer to
HklKeys.- Returns:
Returns a name of currently used format.
- Return type:
str
- _build_line_formatter()[source]
Prepare
line_formatter()to format hkl data while writing.- Returns:
String for str.format() to format hkl data while writing.
- Return type:
str
- property _format_dict
A dictionary with details concerning current format.
- property _line_formatter
A string used by string.format() method to print hkl data.
- _import_custom_format(custom_format_string)[source]
Import format string such as ‘h 4 k 4 l 4 I 8 si 8’ as format ‘custom’.
- Parameters:
custom_format_string (str) – string containing alternating data labels and column widths (all negative if free format) separated using ‘ ‘
- Returns:
None
- property is_current_format_free
Return true if currently defined format is free, i.e. the columns are separated by whitespace.
- Returns:
True if all format widths are negative; False otherwise.
- Return type:
bool
- class hikari.dataframes.hkl.HklReader(hkl_file_path, hkl_file_format)[source]
Bases:
HklIoA helper class for HklFrame, Manages reading hkl files and importing data and keys from them
- _parse_fixed_line(line)[source]
Parse data from a line, where data from each label has fixed width.
- Parameters:
line (str) – string to be parsed based on format dictionary.
- Returns:
list of strings extracted from parsed line
- Return type:
list
- class hikari.dataframes.hkl.HklWriter(hkl_file_path, hkl_file_format)[source]
Bases:
HklIoA helper class for HklFrame, Manages writing hkl files and exporting data to them
- class hikari.dataframes.hkl.HklToResConverter(hkl_dataframe)[source]
A class responsible for representing hkl data using .res format
- MIN_DISTANCE = 10.0
- ELEMENTS = ('H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl',...
- MIN_U = 1e-05
- MAX_U = 4.99999
- df
- property abc_scale_factor
- property largest_absolute_hkl
- property x
- property y
- property z
- property u
- property c
- property res_header
- property atom_list