hikari.dataframes.cif
Attributes
Classes
CifBlock object handles all data inside an individual block of Cif file. |
|
A master object which manages cif files. It utilises other Cif* classes |
|
This object is used to validate individual cif keys when parsing cif files. |
|
An abstract base class for Cif reader and writer buffers. |
|
A base class for CifRead and CifWrite. This class and its inheritors |
|
Buffer for reading data from cif file into CifReader |
|
A helper class managing reading cif files into |
|
Buffer for writing data from CifReader into cif file |
|
Module Contents
- hikari.dataframes.cif.T
- class hikari.dataframes.cif.CifBlock(dict=None, /, **kwargs)[source]
Bases:
collections.UserDictCifBlock object handles all data inside an individual block of Cif file. As a subclass of an UserDict, in python3.7+ it is ordered by design. Individual Cif items can be accessed or assigned using a dict-like syntax.
- get_as_type(key, typ, default=None)[source]
Get value of self[key] converted to typ. If value is a list, convert its contents element-wise.
- Parameters:
key (str) – key associated with accessed element
typ (Callable[[Any], T]) – type/function applied to a value or its every element
default (Any) – if given, return it on KeyError
- Returns:
value of self[key] or default converted to typ
- Return type:
T
- class hikari.dataframes.cif.CifFrame(dict=None, /, **kwargs)[source]
Bases:
collections.UserDictA master object which manages cif files. It utilises other Cif* classes to manage multiple
CifBlock`s with crystallographic information. As a subclass of an `UserDict, in python3.7+ it is ordered by design. Individual Cif blocks and items within them can be accessed or assigned using a single- or nested- dict-like syntax.Similarly to other Frame`s, `CifFrame is designed to work in-place, meaning it should be first created, and only then accessed using methods such as
read()orwrite(), but not chain assignments.Unlike dict, CifBlock always initiates empty and does not accept any parameters at creation.
- class hikari.dataframes.cif.CifValidator[source]
Bases:
collections.UserDictThis object is used to validate individual cif keys when parsing cif files. It knows the metadata about each key based on its entry in the cif core dictionary v.2.4.5 packaged with the project. Since the specification itself is written in cif format, it is also read using the same CifReader (but without CifValidator).
Upon initialization, CifValidator becomes a dictionary whose keys are all valid cif keys, according to the cif specification used. Individual values are themselves dictionaries that store information about key’s contents, _category, _type, whether they are a _list etc.
contains all keys from core cif dictionary. In order to access individual values, use .get() instead of bracket notation.
- get(key, default=None)[source]
Get the dictionary containing information about input cif key.
- Parameters:
key (str)
default (collections.UserDict)
- Return type:
collections.UserDict
- class hikari.dataframes.cif.CifIOBuffer(target)[source]
Bases:
abc.ABCAn abstract base class for Cif reader and writer buffers. Specifies that data can be added and flushed, names and values are stored in a list, output is stored in target (dict if reading, file if writing).
- Parameters:
target (Any)
- names = []
- values = []
- class hikari.dataframes.cif.CifIO(cif_file_path, validate=True)[source]
Bases:
abc.ABCA base class for CifRead and CifWrite. This class and its inheritors base on the IUCr File Syntax version 1.1 Working specification available [here](https://www.iucr.org/resources/cif/spec/version1.1/cifsyntax)
- COMMENT_REGEX
- MATCHING_QUOTES_REGEX
- MATCHING_OUTER_DELIMITERS_REGEX
- MULTILINE_QUOTE_REGEX
- WHITESPACE_SUBSTITUTES
- file_contents = ''
- file_path = ''
- file_lines = []
- validate = True
- class hikari.dataframes.cif.CifReaderBuffer(target)[source]
Bases:
CifIOBufferBuffer for reading data from cif file into CifReader
- Parameters:
target (dict)
- target: dict
- class hikari.dataframes.cif.CifReader(cif_file_path, validate=True)[source]
Bases:
CifIOA helper class managing reading cif files into
CifFrameorCifBlock.- property blocks: dict[str, int]
line numbers where they start in cif file.
- Type:
A dict of block names
- Return type:
dict[str, int]
- class State[source]
Bases:
enum.EnumThis class stores current cif reading state (e.g. inside loop etc.)
- default = 0
- loop_keys = 1
- loop_values = 2
- format_dictionary(parsed_dict_)[source]
Reformat a dictionary of parsed data so that the format of every name and value agrees with the cif core dictionary stored in CifValidator.
- Parameters:
parsed_dict – Dictionary with data pairs
parsed_dict_ (dict[str, list[str]])
- Returns:
Data dictionary with correctly formatted data names and values
- Return type:
dict[str, Union[str, list[str]]]
- parse_lines(start, end)[source]
Read the data from
linesnumbered start to end, interpret it, and return it as an instance of a dict.- Parameters:
start (int) – number of the first line which data should be read from
end (int) – number of the first line which should not be read anymore
- Returns:
ordered dictionary with name: value pairs for all parsed lines
- Return type:
dict
- read()[source]
Read the contents of cif currently pointed by
file_pathand blockdata_block_headerand return them to a dict.- Returns:
A dictionary containing information read from .cif file.
- Return type:
dict
- protect_multilines()[source]
Replace whitespace between every pair of “n;” sequences with substitutes and remove the outer semicolons in self.file_contents.
- Return type:
None
- protect_quotes()[source]
Replace whitespace between every pair of matching quotation marks (single or double) with substitutes and remove the outer quotation marks in self.contents. See stack overflow /q/46967465/ for details.
- Return type:
None
- classmethod _protect_split(split_string)[source]
- Parameters:
split_string (list[str])
- Return type:
str
- remove_comments()[source]
Replace all comment blocks (whitespace or start-of-file followed by “#”) within self.file_contents with empty strings.
- Return type:
None
- classmethod revert_delimiters_and_whitespace(string)[source]
If present, remove outer delimiters (matching quotes or semicolons) from supplied string, remove self.WHITESPACE_SUBSTITUTES and return string.
- Returns:
string without outer delimiters nor whitespace substitutes.
- Parameters:
string (str)
- Return type:
str
- class hikari.dataframes.cif.CifWriterBuffer(target)[source]
Bases:
CifIOBufferBuffer for writing data from CifReader into cif file
- Parameters:
target (TextIO)
- MAX_NAME_LENGTH = 33
- MAX_LINE_LENGTH = 80
- MIN_STEP_LENGTH = 2
- WHITESPACE
- target: TextIO
- current__category = ''
- current__list = False
- current_len = 0
- class hikari.dataframes.cif.CifWriter(cif_file_path, validate=True)[source]
Bases:
CifIOA helper class managing writing
CifFrameorCifBlockinto cif files
- hikari.dataframes.cif.cif_core_validator