Debian Codegraph @

docs/drel_use.txt

raw
1 # Using dREL in PyCIFRW
2
3 ## Introduction
4
5 dREL is a language for manipulating tabular data described in [1]. A
6 CIF dictionary (DDL2/DDLm) definition can contain a piece of dREL code
7 describing how the defined data item can be calculated from other
8 dataitem values. PyCIFRW includes a dREL parser that executes these
9 calculations to provide missing values
10
11 ## Using dREL methods
12
13 Once a dictionary containing methods is assigned to a `CifBlock` using
14 `CifBlock.assign_dictionary`, any attempts to retrieve a missing
15 dataname will trigger execution of the dREL method for that dataname,
16 if available. Note that the value returned will not necessarily be a
17 string type.
18
19 ~~~{.python}
20 >>> from CifFile import CifDic, CifFile
21 >>> p = CifDic('pycifrw/drel/testing/cif_core.dic',grammar='STAR2')
22 >>> r = CifFile('pycifrw/drel/testing/data/nick.cif',grammar='STAR2')
23 >>> r = r['saly2'] # choose our testing block
24 >>> r['_cell.volume'] #should be in the file already
25 u'635.3' # Note this is a string value
26 >>> del r['_cell.volume'] # remove from the CifBlock
27 >>> r['_cell.volume'] # check that it is gone
28 KeyError: 'No such item: _cell.volume'
29 >>> r.assign_dictionary(p) # Use this dictionary for calculations
30 >>> r['_cell.volume'] # Is it there now?
31 635.2977003095574 # Note this is a floating-point number
32 ~~~
33
34 ## PyCIFRW extensions
35
36 PyCIFRW will understand multiple methods for a single definition, and run through
37 each until a successful evaluation occurs. If recursion is detected (defined
38 as a second request to evaluate a dataname in a single evaluation sequence) the
39 current definition is abandoned and the next one tried.
40
41 ## Limitations on dREL methods
42
43 dREL is a rich specification and, while the PyCIFRW implementation is relatively comprehensive,
44 a number of functionalities are not yet implemented, and testing is not complete.
45
46 1. No standard uncertainty (su) propagation. The CIF standards provide for
47 su, which would allow propagation. To be implemented.
48
49 2. Values that have been calculated are stored as their native type (not necessarily strings).
50 These values may be formatted unusually (e.g. too many decimal places) when output to a file. A
51 method will be introduced in later versions to properly format native values.
52
53 4. The Python numpy package is required for dREL-based calculations.
54
55 4. Multi-line strings in dREL are not correctly converted to Python.
56
57 [1]: http://dx.doi.org/10.1021/ci300076w