mdsuite.file_io.tabular_text_files module

MDSuite Tabular Text file reader module.

class mdsuite.file_io.tabular_text_files.TabularTextFileProcessor(file_path: Union[str, Path], file_format_column_names: Optional[Dict[PropertyInfo, list]] = None, custom_column_names: Optional[Dict[str, Any]] = None)[source]

Bases: FileProcessor

Parent class for all file readers that are based on tabular text data (e.g. lammps, extxyz,…).

get_configurations_generator() Iterator[TrajectoryChunkData][source]

TabularTextFiles implements the parent virtual function, but requires its children to provide the necessary information about the table contents, see self._get_tabular_text_reader_data.

property tabular_text_reader_data: TabularTextFileReaderMData
class mdsuite.file_io.tabular_text_files.TabularTextFileReaderMData(n_configs: int, species_name_to_line_idx_dict: Dict[str, list], n_particles: int, property_to_column_idx_dict: Dict[str, list], n_header_lines: int, header_lines_for_each_config: bool = False, sort_by_column_idx: Optional[int] = None)[source]

Bases: object

Class to hold the data that needs to be extracted from tabular text files before reading them.

n_configs

Number of configs in the file

Type:

int

n_particles

Total number of particles

Type:

int

species_name_to_line_idx_dict

A dict that links the species name to the line idxs at which the particles can be found within a configuration. Example: {“Na”:[0,2,4], “Cl”:[1,3,5]} for a file in which Na and Cl are written alternatingly.

Type:

Dict[str, list]

property_to_column_idx_dict

A dict that links the property name to the column idxs at which the property is listed. Usually the output of mdsuite.file_io.tabular_text_files.extract_properties_from_header

Type:

Dict[str, list]

n_header_lines

Number of header lines PER CONFIG

Type:

int

header_lines_for_each_config

Flag to indicate wether each config has its own header or if there is just one header at the top of the file.

Type:

bool

sort_by_column_idx

if None (default): no sorting needed (the particles are always in the same order within a config if int: sort the lines in the config by the column with this index (e.g., use to sort by particle id in unsorted config output)

Type:

int

header_lines_for_each_config: bool = False
n_configs: int
n_header_lines: int
n_particles: int
property_to_column_idx_dict: Dict[str, list]
sort_by_column_idx: int = None
species_name_to_line_idx_dict: Dict[str, list]
mdsuite.file_io.tabular_text_files.get_species_list_from_tabular_text_reader_data(tabular_text_reader_data: TabularTextFileReaderMData) List[SpeciesInfo][source]

Use the data collected in TabularTextFileProcessor._get_tabular_text_reader_data() to get the values necessary for TabularTextFileProcessor.metadata.

mdsuite.file_io.tabular_text_files.read_n_lines(file, n_lines: int, start_at: Optional[int] = None) list[source]

Get n_lines lines, starting at line number start_at. If start_at is None, read from the current file state :rtype: A list of strings, one string for each line.

mdsuite.file_io.tabular_text_files.skip_n_lines(file, n_lines: int) None[source]

skip n_lines in file :param file: :type file: the file where we skip lines :param n_lines: :type n_lines: the number of lines to skip.

Return type:

Nothing