httk.io.cif.cif_parser¶
Classes¶
What a CIF number claims about its own precision, beyond its value. |
Functions¶
Parse a CIF numeric field. |
|
|
Convert a CIF numeric token (e.g., '123(4)', '3E2', '1.0E3') to an int using the central value. |
|
expr: e.g. 'x-y', '-z+1/2', 'x', 'y', 'z-1', 'x-2y', '3x+1/2' |
|
op: e.g. 'x-y,x,-z+1/2' |
|
|
|
The numeric part of a CIF value, as text, with any uncertainty estimate removed. |
|
|
|
Extract structural superspace modulation information from a standard CIF. |
|
|
|
Read a CIF and return its asymmetric units as a neutral, tagged payload. |
Module Contents¶
- class httk.io.cif.cif_parser.CifMeta[source]¶
Bases:
TypedDictWhat a CIF number claims about its own precision, beyond its value.
Both are exact rationals, or
Nonewhen the token makes no such claim.Noneis not the same as claiming exactness: a value written1/3states an exact number and reportsNonefor both, while?states nothing at all and also reportsNone.precisionis implied by the digits written (0.3333is good to1/10000);esdis the standard uncertainty a file states explicitly, so0.3333(7)reports a precision of1/10000and an esd of7/10000. They measure different things and the coarser of the two is the honest claim.- esd: fractions.Fraction | None[source]¶
- precision: fractions.Fraction | None[source]¶
- httk.io.cif.cif_parser.parse_cif_float(token: str, *, meta: Literal[False] = ..., pragmatic: bool = ...) float | None[source]¶
- httk.io.cif.cif_parser.parse_cif_float(token: str, *, meta: Literal[True], pragmatic: bool = ...) tuple[float | None, CifMeta]
Parse a CIF numeric field.
- If meta=False:
return float_value or None.
- If meta=True:
return
(float_value_or_None, CifMeta)— the value plus what the token claims about its own precision. SeeCifMeta; both of its fields are exact rationals orNone.
- httk.io.cif.cif_parser.parse_cif_int(token: str, *, strict: bool = True, allow_round: bool = False) int[source]¶
Convert a CIF numeric token (e.g., ‘123(4)’, ‘3E2’, ‘1.0E3’) to an int using the central value. - strict=True: require the value to be exactly integral; otherwise raise ValueError. - allow_round=True (only if strict=False): round half-even to the nearest int.
- httk.io.cif.cif_parser.parse_linear_expr(expr, use_fractions=False)[source]¶
expr: e.g. ‘x-y’, ‘-z+1/2’, ‘x’, ‘y’, ‘z-1’, ‘x-2y’, ‘3x+1/2’ Returns (row, const) where row is [ax, ay, az] (integers or Fractions), and const is a float or Fraction depending on use_fractions.
- httk.io.cif.cif_parser.parse_xyz_op(op, use_fractions=False)[source]¶
op: e.g. ‘x-y,x,-z+1/2’ Returns (R, t) where R is 3x3 (list of rows), t is length-3 float list
- httk.io.cif.cif_parser.cif_exact_token(token: str) str | None[source]¶
The numeric part of a CIF value, as text, with any uncertainty estimate removed.
"0.3333(5)"becomes"0.3333";"?"and"."becomeNone. The point of keeping the text rather than a float is fidelity: a consumer that wants an exact value can read0.3333as the rational 3333/10000, which is what the file says, whereasfloat("0.3333")is a binary approximation whose exact rational value is 6004199023210345/18014398509481984 and says something the file did not.
- httk.io.cif.cif_parser.parse_structural_modulation(cifblock)[source]¶
Extract structural superspace modulation information from a standard CIF.
Returns a tuple
(structural_q, mod_dim, has_struct_mod, struct_mod_atoms)wherestructural_qis a list of q-vectors orNone,mod_dimis the modulation dimension (0 if absent),has_struct_modis a bool, andstruct_mod_atomsis a sorted list of atom-site labels.
- httk.io.cif.cif_parser.read_cif_asus(fs)[source]¶
Read a CIF and return its asymmetric units as a neutral, tagged payload.
This is what
httk.core.loadreturns for a.ciffile: a mapping withformatset to"cif",blocksholding one asymmetric-unit mapping per data block that describes a structure, andheaderthe file’s leading comment. The tag lets a consumer dispatch on the file type without knowing which reader produced the payload.Loading never fails on account of a block that is not a structure. CIF is a general-purpose format and a file may hold bibliographic entries, powder patterns, or an incomplete draft alongside — or instead of — anything crystallographic. Blocks without atom sites are simply not structures and are passed over; blocks that have atom sites but cannot be interpreted are collected in
unparsed, each with the reason, so that nothing is dropped silently and the failure surfaces when a structure is actually asked for.The mapping stays neutral — plain lists, strings, and exact
Fractionsymmetry operations, with no domain objects — so httk-io need not know about httk-atomistic. Turning it into a structure ishttk.atomistic.asu_structure_from_cif.