compare.rst 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. The Matching Functions - :samp:`compare`
  2. ===============================================
  3. The index matching algorithm used by Crystal Ball Plus lies in the ``compare`` module.
  4. What the program does is:
  5. #. Comparing the *d-spacings*
  6. #. Generating the *d-spacings* report.
  7. #. Grouping the matching reflections
  8. #. Comparing the *angles*
  9. #. Generating the *angles* report
  10. Each operation can be performed automatically using the ``crystalballplus`` executable via the graphical or the text interface (see :doc:`../quickstart`), or can be performed by hand within any Python shell as e.g. `IPython <http://ipython.org/>`_.
  11. In the first step, the input and reference files are read and the results are output in a Python *dictionary of dictionaries* that has the same structure of a file system: the keys of the first dictionary represent the input files, the keys of the second dictionary (which are in fact the *values* of the first dictionary) represent the reference files and, finally, the values of the second dictionary represent the results of the matching algorithm.
  12. For example, here is a way to represent a *dictionary of dictionaries* obtained when analyzing two input and two reference files::
  13. INPUT_01
  14. |
  15. |---REF_01 : result01
  16. |
  17. |---REF_02 : result02
  18. INPUT_02
  19. |
  20. |---REF_01 : result03
  21. |
  22. |---REF_02 : result04
  23. This structure allows one to treat multiple input and reference files at the same time without losing information.
  24. .. automodule:: crystalballplus.compare
  25. Comparing the *d-spacings*
  26. ---------------------------
  27. The first step is to compare the *d-spacings*. This is done using the function ``compare.compare_d``:
  28. .. autofunction:: compare_d
  29. For example:
  30. >>> D = compare.compare_d('path/to/input.dfg', 'path/to/ref.dfg')
  31. will create a dictionary containing the possible *d-spacing* matches between **input.dfg** and **ref.dfg**.
  32. .. note::
  33. The same *d-spacing* may match more than one reflection of the reference structure. **All** the matching reflections will be loaded into the output dictionary.
  34. Grouping the reflections
  35. -------------------------
  36. Once the *d-spacings* have been matched, it is necessary to group them in pairs. This is accomplished by feeding the result of ``compare_d`` to ``compare.group_reflections``:
  37. .. autofunction:: group_reflections
  38. .. note::
  39. The reflections are grouped in at most **three pairs**. So, if our input file contained two reflections R0 and R1, we would have: (R0, R1). If we added a third reflection R2, we would have: (R0, R1), (R1, R2), (R0, R2).
  40. Comparing the *angles*
  41. -----------------------
  42. Once all the reflections are grouped in pairs, the angle between each pair can be calculated and matched against the reference structure using ``compare.compare_angles``:
  43. .. autofunction:: compare_angles