ImageD11.refinegrains module#

ImageD11.refinegrains.best_twin_variant(ubi, gv, intensity, tth, eta, spacegroup, sf, cell_choice='standard')#

Choose between the twin variants of a grain from its peak intensities.

The variants (sym_u.twin_variants) index the same peak positions, so only intensities tell them apart. Each one is scored by the Pearson correlation of the observed intensities, corrected by lf / polarization, with the structure factors |F|^2 it predicts for the peaks.

ubi : (3,3) orientation of the grain gv : (N,3) g-vectors of the peaks of this grain intensity : (N,) peak intensities (e.g. sum_intensity) tth, eta : (N,) peak angles in degrees spacegroup : space group number (1-230) sf : structure factors with valid_mask(hkl) and sf_values(hkl), hkl (3,N),

e.g. sinograms.sinogram.StructureFactorCorrection.from_cif(…). Reflections it does not tabulate are predicted as 0.

cell_choice: “standard” or “rhombohedral” (R groups on rhombohedral axes)

Returns (best_ubi, scores), scores holds one correlation per variant in the order of sym_u.twin_variants (nan when it cannot be computed).

ImageD11.refinegrains.compute_lp_factor(colfile, **kwds)#

We’ll assume for simplicity that wedge, chi, tilts are all zero Of course we should put that in sometime in the near future

Try using:

Table 6.2.1.1 in Volume C of international tables : (h) Rotation photograph of small crystal, volume V

1. Beam normal to axis rho = frac{ N^2 e^4 lambda^3 V} { 4 pi m^2 c^4} .

frac{ 1 + cos^2{theta} } { sin{2theta } . frac{ cos{theta} { sqrt{ cos^2{psi} - sin^2{theta} } } p’ |F|^2

rho is Integrated reflection power ratio from a crystal element e, m Electronic charge and mass c Speed of light lambda Wavelength of radiation 2theta Angle between incident and diffracted beams psi in (h), latitude of reciprocal-lattice point relative to axis of rotation V Volume of crystal, or of irradiated part of powder sample N Number of unit cells per unit volume F Structure factor of hkl reflection p’ Multiplicity factor for single-crystal methods

nb - what is this ? Hopefully would be 1 ?

From this we will take the (1+cos^2(2t))cos(2t)/sqrt(cos^2p-sin^2t)/sin2t

ImageD11.refinegrains.compute_total_intensity(colfile, indices, tth_range, ntrim=2, quiet=False)#

Add up the intensity in colfile for peaks given in indices

ImageD11.refinegrains.consistent_twin_variants(ubis, gvs, intensities, spacegroup, cell_choice='standard', niter=3, min_common=10)#

Choose the twin variant of every grain so that all grains agree on their intensities, without knowing the structure: an R-merge across grains.

The grain with the most peaks is the reference and keeps its own variant. Each other grain takes the variant (sym_u.twin_variants) whose intensities, scaled to the merged table, give the lowest R-merge = sum|I_merged - k I| / sum I_merged over the unique reflections (Laue class and Friedel pairs) they share. The merged table is then rebuilt from all grains and the choice repeated niter times.

The result is consistent, not absolute: without a structure the reference may itself be the twin of the true orientation. best_twin_variant with structure factors on the reference, or on the merged table, settles that.

ubis : list of (3,3) orientations gvs : list of (N_i,3) g-vectors of the peaks of each grain intensities : list of (N_i,) corrected intensities (e.g. sum_intensity * lf / polarization) spacegroup : space group number (1-230) cell_choice : “standard” or “rhombohedral” (R groups on rhombohedral axes) min_common : fewest shared unique reflections to compute an R-merge

Returns (chosen ubis, variant index per grain, rmerge (ngrains, nvariants), nan where it cannot be computed)

ImageD11.refinegrains.cubic(cp)#

a=b=c, alpha=beta=gamma=90

ImageD11.refinegrains.get_options(parser)#
ImageD11.refinegrains.hexagonal(cp)#

a=b,c, alpha=beta=90,gamma=120

ImageD11.refinegrains.lf(tth, eta)#

INPUT: 2*theta and eta in degrees. Can be floats or numpy arrays.

OUTPUT: Lorentz scaling factor for intensity. Same data type as input.

EXPLANATION: Compute the Lorentz Factor defined for 3DXRD as

L( theta,eta ) = sin( 2*theta )*|sin( eta )|

This is verified by:

  • Kabsch, W. (1988). Evaluation of single-crystal X-ray di

raction data

from a position-sensitive detector

  • Poulsen, H. F. (2004). 3DXRD { a new probe for materials science. Roskilde: Riso National Laboratory

and can be derived with support of
  • Als-Nielsen, J. and McMorrow, D. (2017). Elements of Modern X-ray Physics

MODIFIED: 7 Feb 2019 by Axel Henningsson.

ImageD11.refinegrains.monoclinic_a(cp)#
ImageD11.refinegrains.monoclinic_b(cp)#
ImageD11.refinegrains.monoclinic_c(cp)#
ImageD11.refinegrains.orthorhombic(cp)#

a=b, c, 90,90,90

ImageD11.refinegrains.polarization(tth, eta, eta0=0, factor=1.0)#

Effect of beam polarisation

Kahn, J. Appl. Cryst. (1982) 15, 330-337 Azaroff Acta Cryst (1955) 8 701.

# Inspired by H. Sorensens code in polyxsim

class ImageD11.refinegrains.refinegrains(tolerance=0.01, intensity_tth_range=(6.1, 6.3), latticesymmetry=<function triclinic>, OmFloat=True, OmSlop=0.25)#

Bases: object

Class to refine the position and orientation of grains and also the detector parameters

applyargs(args)#
assignlabels(quiet=False)#

Fill out the appropriate labels for the spots

compute_gv(thisgrain, update_columns=False)#

Makes self.gv refer be g-vectors computed for this grain in this scan

estimate_steps(gof, guess, steps)#
fit(maxiters=100)#

Fit the global parameters

generate_grains()#
getgrains()#
gof(args)#

<drlv> for all of the grains in all of the scans

loadfiltered(filename)#

Read in file containing filtered and merged peak positions

loadparameters(filename)#
makeuniq(symmetry)#

Flip orientations to a particular choice

Be aware that if the unit cell is distorted and you do this, you might have problems…

pars = {'cell__a': 4.1569162, 'cell__b': 4.1569162, 'cell__c': 4.1569162, 'cell_alpha': 90.0, 'cell_beta': 90.0, 'cell_gamma': 90.0, 'cell_lattice_[P,A,B,C,I,F,R]': 'P', 'chi': 0.0, 'distance': 7367.8452302, 'fit_tolerance': 0.5, 'o11': 1, 'o12': 0, 'o21': 0, 'o22': 1, 'omegasign': 1, 't_x': 33.0198146824, 't_y': 14.6384893741, 't_z': 0.0, 'tilt_x': 0.0, 'tilt_y': 0.0623952920101, 'tilt_z': 0.00995011461696, 'wavelength': 0.2646, 'wedge': 0.0, 'y_center': 732.950204632, 'y_size': 4.6, 'z_center': 517.007049626, 'z_size': 4.6}#
printresult(arg)#
readubis(filename)#

Read ubi matrices from a text file

refine(ubi, quiet=True)#

Fit the matrix without changing the peak assignments

refinepositions(quiet=True, maxiters=100)#
refineubis(quiet=True, scoreonly=False)#
reset_labels(scanname)#
savegrains(filename, sort_npks=True)#

Save the refined grains

saveparameters(filename)#
set_translation(gr, sc)#
stepsizes = {'chi': np.float64(0.0017453292519943296), 'distance': 200.0, 't_x': 0.2, 't_y': 0.2, 't_z': 0.2, 'tilt_x': np.float64(0.0017453292519943296), 'tilt_y': np.float64(0.0017453292519943296), 'tilt_z': np.float64(0.0017453292519943296), 'wavelength': 0.001, 'wedge': np.float64(0.0017453292519943296), 'y_center': 0.2, 'y_size': 0.2, 'z_center': 0.2, 'z_size': 0.2}#
update_columns(sort_npks=True)#

Fill the per peak columns (gx, h, hr, tth_per_grain, …) from the refined grains and count their unique reflections (nuniq). Returns [(grain, key), …] in the order savegrains writes them.

ImageD11.refinegrains.test_benoit()#
ImageD11.refinegrains.test_nac()#
ImageD11.refinegrains.tetragonal(cp)#

a=b, c, 90,90,90

ImageD11.refinegrains.triclinic(cp)#
ImageD11.refinegrains.trigonalH(cp)#

a=b,c, alpha=beta=90,gamma=120

ImageD11.refinegrains.trigonalP(cp)#

a=b=c, alpha=beta=gamma