Version 4 (modified by toby, 11 years ago) (diff) |
---|

## Lattice Computation Codes

GSAS-II provides a number of routines for computation of tensors related to the direct and reciprocal unit cell. Also included are two reflection generation routines. These routines require the NumPy package, but are otherwise pure python code. This code is contained in file GSASIIlattice.py, which can be used as an independent module, or can also be used with the GSASIIspc.py space group module.

For these routines, a variety of transformation routines are provided to convert between the unit cell constants and many other commonly used values. The unit cell is specified as a tuple of 6 values, corresponding to a, b, c in angstroms and alpha, beta and gamma as angles in degrees. Also used for these computations are the real and reciprocal lattice metric tensor (g and G, respectively) which are 3x3 tensors. Also used is an "A" vector, which is closely related to the G tensor and is used to compute d-spacings from h,k,l values using:

1/D

^{2}=h^{2}*A(1) +k^{2}*A(2) +l^{2}*A(3) +h*k*A(4) +h*l*A(5) +k*l*A(6)

In addition, A and B are used to define a pair of 3x3 transformation matrices, where A*x converts Cartesian coordinates x into fractional ones and B does the inverse transform.

Routine **GenHBravais** is used to compute the unique reflection positions for a given Bravais lattice type. This is intended to provide a list of unique d-spacings for a given unit cell and centering setting. If two crystallographically distinct reflections, for example the (300) and the (122) reflections in a cubic cell,
only one of the two will be returned. Routine GetBraviasNum is provided to translate output from GSASIIspc to the Bravais lattice numbers (0-13) used in GenHBravais. Note that only the standard settings for centering are accepted by this routine (C-centering, monoclinic b-unique).
A sample code fragment that uses these routines is:

import GSASIIlattice as latt import GSASIIspc as spc dmin = 1 cell = (4.1,4.1,5.2,90,90,90) spg = 'P 4/m m m' spdict = spc.SpcGroup(spg)[1] bravcode = latt.GetBraviasNum(spdict['SGLatt'], spdict['SGSys']) for h,k,l,d,num in latt.GenHBravais(dmin, bravcode, latt.cell2A(cell)): print (h,k,l),d

Routine **GenHLaue** is used to compute all crystallographically distinct reflections (assuming Freidel's law is obeyed) for a given unit cell, Laue group and centering condition. Note that this routine is general and will allow use of non-standard settings, including any center and for monoclinic cells, any axis may be unique. Rhombohedral settings for trigonal cells are also allowed.
A sample code fragment that uses these routines is:

import GSASIIlattice as latt import GSASIIspc as spc spgroup = 'C m m m' cell = (9.98035, 13.0512, 7.6772, 90, 90, 90) dmin = 3.0 spdict = spc.SpcGroup(spgroup)[1] center = spdict['SGLatt'] Laue = spdict['SGLaue'] Axis = spdict['SGUniq'] for h,k,l,d in latt.GenHLaue(dmin,Laue,center,Axis,latt.cell2A(cell)): print (h,k,l),d

The files used in this module are:

- GSASIIlattice.py: The lattice routines
- testinp/: contains a file used for running some of the unit tests on GSASIIlattice.py (sgtbxlattinp.py). The contents of this file is created using genhkltest.py.

### Unit Tests

Unit tests are provided that check that the results from all major routines are identical across platforms and match those computed independently (using cctbx).

The unit tests can be run by simply invoking the GSASIIlattice.py file directly (`python GSASIIlattice.py`). Alternately the
python package `nosetests` which will run file unit_tests.py will test all defined unit tests in GSAS-II. Note that unit tests require as input files
sgtbxlattinp.py in directory
testinp/.