Title:  		LATTPARM    A Personal Computer Program for finding
			            Lattice Parameters from Powder Data
KeyWords:  		Powder Diffraction, Lattice Parameters
Computer:        	PC, XT, AT
Operating System:     	MS(PC)-DOS
Programming Language:  	TURBO Pascal
Hardware:              	Math Co-Processor desirable
Author:                  Roy Garvey
Correspondence Address:  Department of Chemistry
                         North Dakota State University
                         Fargo, North Dakota
                         58105 - 5516     U S A
Documentation:
-----------------------------------------------------------------------------

      Using the algorithm of Visser (1969), the problem of finding the
lattice parameters from powder diffraction data is formulated with reference
to the reciprocal lattice:

(2sin(theta))2     1         ( h  k  l )  ( a*.a*  a*.b*  a*.c* ) ( h )
   --------    =  ---   =                 ( a*.b*  b*.b*  b*.c* ) ( k )  < 1 >
(   lambda  )2     d2                     ( a*.c*  b*.c*  c*.c* ) ( l )

which reduces to

                      1
                     ---  =  h2 a*2  +  k2 b*2  +  l2 c*2
                      d2
                                 +  2 k l b* c* cos(alpha*)
                                 +  2 h l a* c* cos(beta*)
                                 +  2 h k a* b* cos(gamma*)              < 2 >

Defining

  Q(hkl)  =  104 / d2  =  h2 A + k2 B + l2 C + kl D + hl D + hk F       < 3 >

(retaining the notation of Visser) the problem becomes one of finding the six
constants, A, B, C, D, E, and F.  The very fact that this relationship is
used to determine the lattice parameters means that the unknown unit cell so
derived will be triclinic.

      A perfectly general approach to the problem is to first find zones of
the lattice (net-planes of the reciprocal lattice containing the origin).
Any two such zones will have a line of intersection.  If the angle between
two such zones is found, a reciprocal lattice is determined.  Sometimes this
lattice can be reduced (described on symmetry axes in the reciprocal
lattice).

      The program LATTPARM performs the following steps:

      1)      Data entry.  The option to input data as d, Q, or 2-theta values
                is retained.  A mixed mode of input is not supported.
      2)      Test whether the base vectors should be halved.  Refine the
                parameters with a least-squares method and calculate the
                probability that the zone is found by pure chance (quality
                value).
      3)      Find pairs of zones with a common row and determine the angle
                between these zones.
      4)      Reduce the lattices found and transform if necessary so that
                the lattice is described in a standard way.
      5)      Index the first twenty lines of the pattern and repeat after a
                least-squares refinement of the parameters, note the number of
                lines actually indexed and calculate a "figure of merit".

                         F i n d i n g      Z o n e s

      Any two points in the reciprocal lattice, together with the origin,
define a plane in the reciprocal lattice corresponding to a crystallographic
zone.   Since

      ( 1 / d2hk0 )  =  h2 a*2  +  k2 b*2  +  2 h k a* b* cos(gamma*)   < 4 >

it follows that the equation of the plane has the form

                       Qhk  =  h2 Q'  +  k2 Q"  +  h k F                < 5 >

where                    F  =  2  / Q' Q"  cos(gamma*)                  < 6 >

gamma* being the angle between the directions from the origins to the points
with values Q' and Q".  Rearranging <5>

                             ( Q(hk)  -  h2 Q'  -  k2 Q" )
                     F  =   -------------------------------             < 7 >
                                         h k

Combinations of the first three with the first six lines of the Q list are
tried as Q' and Q" unless specific combinations are given in the input.

      By inserting for Q(hk) all observed Q values up to a reasonable limit,
inserting for h and k a few positive integer values, and storing the absolute
value of F, a great number of : F :  values are obtained.  Some of these
values are equal within the limits of error.

      In the program, F is multiplied by a constant factor, rounded to the
nearest integer value, and 1 is added to a corresponding ITL (tally of the
distribution) array element. If the integer exceeds the bounds of the ITL
array, an error message is placed on the screen and the point ignored. Lipson
and Steeple (1970) present a graphical interpretation of this procedure.

      When finished, the ITL array is processed in small overlapping steps,
summing the contents of six successive elements. If the sum exceeds a preset
number (e.g. 4 if Q' <> Q") then a weighted mean is calculated and stored. 
The tolerance in F has a fixed absolute value determined by the constant by
which F is multiplied, TOL1. 

      When the multiplicity-factor of a powder diffraction line is greater
than two, its Q value represents more than one significant point in the
reciprocal lattice.  Therefore it is useful to try combinations of Q values
of the type Q' = Q" (as illustrated in the expanded listing of intermediate
results "the Search for Zones commences").  In an orthorhombic lattice, for
example, each Q(hkl) with h,k,l <> 0 represents 8 points in the reciprocal
lattice.  These points define three different zones.  In the program up to
four significant values of F are accepted for the same pair Q', Q".  A
transformation of the zone axes is carried out for  F > Q' and if there are
equalities between Q', Q", and F.

      When R > Q' there is at least one reciprocal lattice point (i.e. 1, -1)
with Q = Q' + Q" - F less than that of one or both of the axes on which the
lattice was described.  In this case a transformation is carried out to
describe the zone on shorter axes.  This process is repeated as necessary.

      When there are equalities between Q', Q", and F there are pairs of Q's
which are systematically equal such that there is a mirror line in the zone.
The lattice is redefined on orthogonal axes.


                    Improvement  and  Evaluation  of  Zones

      The zones found to this point are recaluclated up to 0.8 Qmax with
Q'/4, Q"/4, and F/4 as parameters.  If as an examble the number of observed Q
values which match calculated Q values with odd h (and even k) is sufficient
then the program assumes Q'/4 is the correct parameter.  The same sort of
test is carried out for Q" (conditions:  odd k, even h) and for centering of
the old zone (conditions: h = 2n, k = 2n, h + k = 4n) and the new zone (h + k
= 2n).  With the parameters thus obtained a least-squares refinement is
carried out.  At the same time the "Zones after Evaluation" and the lines of
a zone "original values" can be printed.  A summary list of zones "Selected
for Refinement" is printed followed by a similar listing of the zone "after
refinement on two-theta".

      During this refinement process, the probability that a zone has been
found by pure chance is calculated.  Both the parameters of the zones and the
observed Q values will contain deviations from the ideal value.  When the 
difference between Qcalc and Qobs is less than TOL1 in Q = 104/d2, this near
coincidence is regarded as support for the zone.  Associated with each Qobs
in the list there is a certain range, /_ Q, of significant Q values.  Any
Qcalc falling within this range is considered to "fit".  If Qmax is the
highest observed Q value in the zone, then the probability, p, that an
arbitrary Q value fits is obtained as

                                     /_ Q
                             p  =   ------                             < 8 >
                                     Qmax

If there are Nc calculated Q values in the zone, No of which give a "fit"
then the propability that this should occur by pure chance is

                             Nc!
           chance   =  --------------  pNo ( 1 - p )Nc-No              < 9 > 
                       No! (Nc - No)!

where No and Nc should refer to significant points.

      A line, together with its higher orders is therefore counted as a
single observation, both for No and Nc.  Also the number of parameters
involved is deduced from the number of significant points to obtain No and
Nc.  The reciprocal value of c is assigned as a "quality index" of the xone.
The zones are sorted on this quality index.  Only the best six zones are used
in subsequent stages of processing by the program.
   Combination  of  Zones  and  Determination  of the  Angle  between  them

      In order to find a lattice, all possible combinations (including the
combinations of each zone with itself) of the six best zones (derived as
described above) are tried.  For each pair of zones the program seeks to find
the line of intersection and subsequently to determine the anble between
them.

      The line of intersection of two zones is a row of common points; the Q
value of the first point of this row must be a low Q value occurring in both
zones.  In order to find this point the Q values of the four points nearest
to the origin in each zone ( Q', Q", Q' + Q" + F, Q' + Q" - F) are
computed and compared with the points of the other zone.  If a common Q value
is found the zones are redefined (if necessary) with the common value as one
of the axes and the smallest remaining Q value as the other.  Provisionally
labeling the parameters of the first zone A, B and F and those of the second
zone A, C and E, equation < 3 > is used to determine the remaining parameter,
D:
                   ( Q - h2 A - k2 B - l2 C - hl E - hk F )
            D  =   ----------------------------------------            < 10 >
                                   k l

All observed Q values in the list are used with
           -2 < h < 2;   k = -2, -1, 1, 2;  l = 1, 2   (k l <> 0 !)
The actual calculation is carried out in much the same way as the selection
of values of F described in "Finding Zones" above.  Apart from the most
frequently occurring value of D, three other values are retained, but only if
they are not much less frequent that the best values.  The results are
described in lists of "Possible Combinations of Zones on which to base search"
and "Possible lattices based on the above Combination of Zones". 


                 R e d u c t i o n     of     L a t t i c e s

      Some of the sets of constants, A ... F, derived above might be
different descriptions of the same lattice.  Other lattices could be
described in a simpler way.  Therefore the lattices are reduced and brought
to a standard description.

      The reduction of the lattices is carried out in two steps.  In the
first step the shorest non-coplanar translations in the reciprocal lattice
are determined by calculating the Q values of half the number of reciprocal
lattice points close to the origin (the inversion-equivalent points are left
out), selecting the smallest Q values and storing their indices (hn, kn, ln,
n= 1,2,3).  The translations are coplanar if the determinant of the matrix

                                [ h1  k1  l1 ]
                                [ h2  k2  l2 ]    =  0
                                [ h3  k3  l3 ]

In this case the next smallest Q value is used as the third translation, etx.
until a non-coplanar set is found.  The second step in the reduction is a
test for symmetry.
      Only two kinds of symmetry relations are tested:

      a)      Two of the translational constants (A, B, C) are equal while
           the angle between their directions differs from 90o, e.g. A = B and
           F <> 0. In this case the reduced constants (primed) are:

              A' = ( A + B - F ) / 4             B' = ( A + B + F ) / 4
              C' =  C                            D' = ( D - E ) / 2
              E' = ( D + E ) / 2                 F' =  0

      b)      An angle factor is equal to one of the translational constants
           which defines one limit of the angle, e.g. F = A or F = B.
           If F = A the reduced constants are:

              A' = A / 4                         B' = B - A / 4
              C' = C                             D' = D - E / 2
              E' = E / 2                         F' = 0

      The third possible relation, e.g. D = E only leads to reduction if A = B
which is treated above, or if F = 2 A or F = 2 B, which is impossible when
the lattice has been defined by the shortest translations.  By cyclic
permutation of the constants they are all made to pass the few simple test
described above.  In this way all orthorhombic, and most of the monoclinic
lattices are recognized as such.  Only one extra test is applied in order to
pick out a few special cases of monoclinic centered lattices.  Both symmetry
relations point to a probable centering of the lattice.  This centering is,
however, disregarded at this point of the processing.  The reduction of the
lattice will establish the Bravais type which follows from the final
indexing.  The "Lattices Reduced and put into Standard Form" are listed.


   F i n a l     T e s t     o n     t h e     L a t t i c e s     F o u n d

      With the lattices found, the program tries to index the first 20 lines.
At the same time a least-squares refinement of the parameters is performed.
By counting the number of lines that can be indexed on the basis of a
centered lattice ( A, B, C, I, of F ) the Bravais-type is established.  This
procedure is repeated once, after which the number of non-indexable lines is
noted and a "figure of Merit" (de Wolff, 1968) is calculated.  This figure of
merit is in fact the ratio of the expected average discrepancy between the
observed and calculated Q values for an arbitrary reciprocal lattice of
the same size and the actual average discrepancy.  Parameters for the "best
lattices" are printed.   If requested the lattice may be printed in layer by
layer detail where the calculated Q values that match an observed value are
marked with an x.  It is suggested that this scheme makes any additional
extinction more easily identifiable by inspection.  In a final pass through
the refinement, the "best solution is used to index all lines".
                          I M P L E M E N T A T I O N

      The executable program for the derivation of Lattice Parameters from
Powder Diffraction data is distributed in two versions.  LATTPARM.com and
LATTPARM.000 are the main machine code program file and an Overlay file
respectively requiring the presence of the "math coprocessor" for proper 
execution.  UNITCELL.com and UNITCELL.000 are the corresponding files used
when no 8087 (or 80287) is avaialble.  Not only does UNITCELL require a
longer time for execution, but the smaller dynamic range of numeric values may
also affect actual data processing. 

      Because the user of a personal computer is often impatient when longer
computations are taking place, a visually "active screen" has been
incorporated in the latest version of the program.  In addition to rather
conventional "Program Identification", a running display of "Progress" in
processing of the data is presented along the lower line of the display
screen.  In addition, certain phases of the program present additional
information on typical data being processed.  Most screens display A, B, F,
etc, values with no identifying labels.  Should problems leading to "Run Time
Errors" cause the program to halt, a "PrtSc" dump of the screen to the
printer can be helpful in tracing the source of the error.  The following
out-line of the Visser algorithm as implemented might prove useful in
following the "Progress Line".

            LATTICE  PARAMETERS   from   POWDER  DIFFRACTION  DATA

Initiate Visser Algorithm.
      Name of System.
      Printer Output File Selection.
      Printer Output File Initialization.

Read in Control and Diffraction Data.
      Open Input Data File.
      Read Control Parameters.
      Display Screen and Print Report Headers.
      Check and Adjust Input Control Data.
      Read Diffraction Lines Data.
              Print the Observed Values.
              Compute  Q  Values.
              Print  Q  Values.
              Compute Tolerances for Input Data.
      Read Line and Lattice Combinations (if any).
      Check for systematic Zero-Shift (if requested).

Crystallographic Zone Finding.
      Initiate Probabilities.
      Search for Zones.
      Find Zones.
      Evaluate Zones.
              Normalize Zone.
              Least-Squares for Theta.
              Least_Squares for Lattice Vectors.
      Combination of Zones.

Crystallographic Lattice Finding
      Lattice Search.
              Intersect Zones.
                   TriClinic Lattice.
                   MonoClinic Lattice.
              Find Most Frequent Values.
              Best Values.
      Normalize Lattice.
      Refine Parameters.
              Generate Q Values.
              Bravais Lattice Type.
      Discard Lattices.
      Most Probable Solution.


                              Program  Initiation

      The program receives information on the InPut data file (and optionally
on the printer OutPut file) through entries on the command line.  Following
the DOS system prompt > the entry of a name matching a .COM or .EXE program
file will cause the program to be loaded into memory and execution will
begin.  If no matching program file is found, the DOS system looks for a .BAT
file of commands.  Under predetermined conditions, information typed
following these "Commands" as a "tail" can be read by the program and used
for a variety of purposes.  The execution of Lattice Parameter searches
requires that the necessary control and diffraction data be included in a
TEXT file stored on disk.  No interactive data entry is expected.

      To process the diffraction data for a file named  YOUR.dat  residing on
a diskette in drive  B  you would type the information following > assuming
that your program is in the default directory.

              default directory > LATTPARM  B:YOUR.dat

The printed output would be sent to the "device" referenced to LST:, LPT1:,
or PRN: depending upon the whim of your DOS environment.  The rather extensive
printed output can slow processing because of a slow printer.  If you have a
"spooler" or ram buffer this makes little difference.  However, as an
alternative, the program includes the option of sending the entire "printed
output, including control characters" to a disk file for later printing
and/or input to a word processor for incorporation into a report.  This is
accomplished by the following "command tail".

              default directory > LATTPARM  B:YOUR.dat  C:\REPORT\YOUR.out

C:\REPORT\  identifies that YOUR.out file will be placed in a REPORT
subdirectory found on drive C:.


                             Printer Control Codes

      An additional feature was introduced to lessen the impact wrought by
the multifarious range of printer options and control codes.  A very limited
subset of functions was selected for implementation:
              Compressed mode printing           15 - 17 cpi
              Double width printing              2 x current width
              Normal mode printing               10 or 12 cpi
The program looks on the "default drive" for a  PRINTER.$pr  file of three
lines of up to five decimal number equivalents to the CHR( n ) ASCII codes.
If found, the file is read for the codes to set your printer in the three
modes described one line each in the order listed.  On some printers this is
sufficient to include line spacing codes as well.  For example, the codes
corresponding to 15 27 48 when sent to an IBM-Epson printer will "change the
printer to compressed print mode" and "change the paper feed to 1/8 inch".

      If the PRINTER.$pr file is not found, the program forces you to select
between a standard Okidata microline and an Epson type printer.  The
corresponding printer codes are generated internal to the program.

                      D A T A      I N P U T      F i l e

      LATTPARM (or UNITCELL) reads an ASCII TEXT file of input records from
disk.  The usual input should consist of:

1.    A Title record containing up to 80 characters.

2.    A parameter record including the following.  All variables must be given
        appropriate values.  The numbers are all "place holders" and are read
        format free except for the requirement that at least one space
        separate adjacent numerical values.  Zeros must be entered.

      MaxSoln  --  The maximum number of solutions for which a list of
         (indexed) reflections is printed.  The corresponding Q-scheme is only
         printed when intermediate results are requested ( ENL below) and the
         figure of merit is larger than 4.0.   4 is a reasonable value.

      Nsyst[1]  --  Orthorhombic      Used to indicate that the solution must
      Nsyst[2]  --  Monoclinic           belong to a certain crystal system.
      Nsust[3]  --  Triclinic      =  0  means your are indifferent.
                                   = +1  indicates you are confident that the
                                            solution belongs to this system.
                                   = -1  means the opposite.
            This option works only on the last part of the data processing and
           doubles the tolerances there.  Only the three crystal systems are
           included.  Generally the 0 is used.

      Tol2  --  Tolerance range for 2-dimensional search.  3.0 Q-units is
                  generally used.  When you have very good data (0.01 degree
                  two-theta) on a fairly large unit cell, you might lower it
                  to 2.5 or 2.0. With a small unit cell you might increase it
                  somewhat to say 4.0.

      Tol3  --  Tolerance range for 3-dimensional search.  4.5 Q-units is
                  generally satisfactory.  Tol3 is the same kind of tolerance,
                  but now on the trial value of  D  in the search for
                  lattices. Its value can be changed in the same manner as
                  that described for Tol2.

      Lambda  --  X-ray wavelength used in recording the diffraction pattern.
                    Values are given in Angstrom units.

      LinCombo  --  Generally = 0.  For value greater than zero, the value
                    represents the number of line-combination records (or
                    zones) you will enter. When non-zero, the program expects
                    records (after the lines records + "-1 record").  See
                    below for more information.

      Lzerck  --  > 0  the program checks on "zero-errors" .

      Enl  --  Program prints "intermediate" results for a non-zero value.

      Nq1  --  Determine the numbers of lines to be used in combinations
      Nq2  --    for finding zones.  Values of 3 and 6 respectively are good.

      Nz1  --  Determine the numbers of zones to be used in combinations to
      Nz2  --    find lattices.  Values of 6 and 6 respectively are good.

      Nr  --  Generally zero.  For positive non-zero value, the program
                 expects records for Nr trial lattices (entered after the
                 lines records + "-1 record").  See below for further details.

      List  --  The number of "best solutions" to be printed.  Among other
                 information, the program will produce a list of all observed
                 and calcualted lines, sorted on two-theta, unless it would be
                 too long (more than 100 calculated lines).  Generally List is
                 set at 1.

      MolMass  --  If the formula mol mass is entered, calculated density and
                     number of units in the cell are printed.  Enter zero if
                     no experimental value is available.

      Density  --  Observed density.  Used with volume of calculated unit
                     cell and MolMass to estimate  Z.  If no value is
                     available, enter zero.

      Tolg  --  Tolerance on the match between the calculated and the
                  observed two-theta values.  A value of 6 is generally
                  acceptable. Values are expressed in hundredths of a degree
                  two-theta and apply to both the zone and lattice searches
                  and the lattice refinement. For very accurate data it can be
                  advantageous to use a value of 4.0 to 3.5. For inaccurate
                  data the value can be increased, but such data is not
                  usually worth processing unless the cell is very small.


3.    A second parameter record with the numeric values for:

      ZeroCorr  --  Zero correction (as degrees two-theta) to be applied to
                      all lines.

      PrintMerit  --  The minimum figure of merit for a lattice to be
                        printed.  The value of 4.0 must be considered as an
                        absolute minimum for a lattice that has a chance to
                        imporve its performance.

      PrintLine  --  The minimum number of indexed lines for a lattice to be
                       printed.  Lattices with a lower number of indexed lines
                       are sometimes a sub-lattice of the true lattice.  A
                       lattice can only be considered as satisfactory when it
                       explains all lines. A value of 14 is considred minimal.
                       Note that this parameter is entered with no decimal
                       point.


4.     Diffraction Lines.

            Observed diffraction lines, one to a line.
              May be input as "D-vlaues", "Q-values" or as "two-theta" values.

5.    -1       used to indicate end of diffraction lines data.

6.    Trial Lattices can be input at this point.  There must be six fields of
        data for each record.  The first field of the last record must be -1.
        The six data fields of a record correspond to the coefficients A, B,
        C, D, E, and F of

            Q  =  1000 / ( d * d )
               =  H*H*A  +  K*K*B  +  L*L*C  +  K*L*D  +  L*H*E  +  H*K*F

             where  d  is the interplanar spacing in Angstroms.

7.    Line combinations or Zone input.  Each record must have four entries.
        You may enter any number of zones (less than 40), but must end the set
        with a -1 for the first of the four values.  When you enter only two
        non-zero values (separated from adjacent numbers by at least one blank
        space) the program interprets this as a combination of lines to be
        tried for finding zones.  When you enter three non zero values, the
        program will treat these as a zone and will evaluate it.  If you want
        to enter a rectangular zone, you must set this third constant at 0.08,
        otherwise the program will treat this as a line combination.  If you
        want to ensure that a specified zone will be included in the search
        for complete lattices, you should also enter a high quality figure
        (fourth value of the record).  If the program does not find the
        solution automatically, it can often be helped by adding zones in this
        way.  Zones which are correct, although having a low quality figure,
        can sometimes be recognized in the listing of intermediate results
        (ENL <> 0) by their small area ( i e, large *A* and *B*) and good
        coverage near the origin (i e, most of the low angle calculated lines
        have been matched with observed lines). Zones from oriented specimens
        or fibers, or from electron diffraction studies, can also be used.


                               Acknowledgements

      The author wishes to thank JCPDS-ICDD for financial support for the
initiation of the project leading to generation of the Lattice Parameter
programme.  Special acknowledgement is accorded Dr G McCarthy, his students
who used earlier versions of the program, and especially to Paul Maistrelli
whose kind comments and criticisms guided evolution of the "people interface"
to the computer programme and prompted generation of this document.

                              R E F E R E N C E S

Azaroff, L V and M J Buerger (1958) "The Powder Method in X-ray
     Crystallography", McGraw-Hill Book Company, Chapter 10.

Lipsom, H and H Steeple (1971) "Interpretation of X-ray Powder Diffraction
     Patterns", MacMillan, Chapter 5.

Visser, J W (1969) "A fully automated program for finding the unit cell from
     powder data", J Appl Cryst, 2, 89-95.

de Wolff, P M (1968), J appl Cryst, 1, 108.


****   Sample DATA input file:

PDF  29-0733  Ilmenite test data set.
4  0  0  0  3.000  4.500  1.54060  0  0  0  3  6  6  6  0  1  0.0  0.0  6.0
0.000  4.0  14
   3.7370
   2.7540
   2.5440
   2.3490
   2.2370
   2.1772
   2.1032
   1.8683
   1.8309
   1.7261
   1.6535
   1.6354
   1.6206
   1.5057
   1.4686
   1.4342
   1.3757
   1.3421
   1.3337
   1.2834
   1.2719
   1.2453
   1.2279
   1.2101
   1.2040
   1.1871
   1.1744
   1.1547
   1.1185
   1.0884
   1.0758
   1.0663
   1.0516
   1.0156
   1.0042
   0.9872
   0.9813
   0.9719
   0.9617
   0.9421
   -1
END

NOTE:   The  LATTPARM.scr  file must be decreased in size to be compatible
 with the memory segment limitation of Turbo Pascal 2. and 3. (I do not yet
 have a copy of version 4. so I do not know of the limitations).  Using the
 non-document mode of your favorite word processor, <block> and save the last
 60K of the file as  LATTPAR2.scr.  Delete this block from the active 
 workspace.  Next add the line
                        {$I LATTPAR2.scr }
 as the last line of the active workspace and block the remaining first 50K of
 source statements.  Save this BLOCK as the file LATTPARM.pas.  Terminate your
 wordProcessor program [but do not save the changes to disk].

      Initialize TURBO Pascal.  Make the working file  LATTPARM.pas  and
 compile your version of LATTPARM.  Section headers in the source code
 suggest segmentation of the program used in its development.  Each segment
 was stored in an individual file and these were {$I  included  } into a 
 master supervisor file.

-----------------------------------------------------------------------------
End of File