MDMC.readers.observables package

Submodules

MDMC.readers.observables.LAMPPDF module

Reader for pair distribution function data from LAMP’s ascii files

class MDMC.readers.observables.LAMPPDF.LAMPPDF(file_name: str, pdf_col: int = 3, partial_strings: list[tuple] = None)[source]

Bases: PDFReader

A class for reading files from LAMP that contain pair distribution function (PDF) data. LAMP’s ascii output uses a single file, with the expected file structure being: Row-Number Distance pdf-total pdf1 pdf2 … pdfN

The column file format above is the default with the total PDF data contained in the 3 column. When initialising instances of this class it is possible to change this using the pdf_col parameter to select which data column contains the total PDF. The remaining columns (if they exist) are assumed to be partial PDFs.

Parameters:
  • file_name (str) – File containing the pair distribution function data

  • pdf_col (int, optional >= 3) – Column that contains the data to be saved as the total PDF (PairDistributionFunction.PDF). Optional, default value is 3 as columns 1 and 2 are reserved for the row-counter and the distance value.

  • partial_strings (list of tuples) – List of tuples to specify the labels of the partial pairs to be saved as such in PairDistributionFunction.partial_pdfs. All columns in the data file apart from the row-counter (column 1), distance values (column 2) and the one for the total PDF (pdf_col) are saved as partial_pdfs. The labels are applied in numerical order. If no labels are specified, the column header in the data file is used as the label.

assign(observable: PairDistributionFunction) None[source]

Method to assign the data parsed by the LAMPPDF reader to a PDF Observable.

Parameters:

observable (PairDistributionFunction) – The PairDistributionFunction to which the parsed information should be assiged.

parse(**settings: dict) None[source]

Parse the file information

r is the radial distance (in Angstrom), expected in column 2 of the file PDF is the total pair distribution function (in barn), by default expected in column 3 of the file, but can be specified by pdf_col setting. partial_pairs are the partial PDFs (in barn), imported from the remaining columns with the labels of the partial pairs either specified by partial_strings or taken from the column headers.

MDMC.readers.observables.LAMPSQw module

Readers for dynamic data

class MDMC.readers.observables.LAMPSQw.LAMPSQw(file_name: str)[source]

Bases: SQwReader

A class for reading SQw files from LAMP

LAMP’s ascii output uses three files: 1 for independent variables and parameters (…_LAMP), another for dependent variables (…_LAMPascii), and a third for the errors in the dependent variables (…LAMPascii_e)

file_indep

File containing the independent variables

Type:

file

file_dep

File containing the dependent variables

Type:

file

file_dep_err

File containing the errors on the dependent variables

Type:

file

parse(**settings: dict) None[source]

Parse into SQw format

E is the energy transfer (in meV) Q is wavevector transfer (in Ang^-1)

parse_dep_var(file: IO) ndarray[source]

Parses the dependent variables or their errors.

Parameters:

file (file) – Open file containing independent data

Returns:

A 2d array with dimensions of the two independent variables

Return type:

numpy.ndarray

parse_indep_var(file: IO) tuple[ndarray, ndarray][source]

Parses the independent variables

Splits the file so that the data can be extracted into a array by self._get_data

Parameters:

file (file) – Open file containing independent data

Returns:

(X, Y) where X and Y are arrays of the two independent variables

Return type:

tuple

MDMC.readers.observables.MDANSESQw module

Readers for dynamic data

class MDMC.readers.observables.MDANSESQw.MDANSESQw(file_name: str)[source]

Bases: SQwReader

A class for reading SQw files from MDANSE’s trajectory analysis

The output from MDANSE analysis of trajectories is a .csv file with some lines of comments describing the dataset and columns/rows, followed by an array of numbers. The first row and column of the array define the axes of the data, where the role and physical unit of each axis is described in the comment lines preceding the data. The [0,0] element of the array is always 0.0 and is not used, while all the remaining points are the S(Q,w) at each corresponding Q and w.

file_variables

numpy array containing all the data

Type:

ndarray

parse(**settings: dict) None[source]

Parse into SQw format, creates an error on SQw 1% of the value of SQw, since MDANSE does not yet output an error. This should be changed once it is possible to read an error.

E is the energy transfer (in meV) Q is wavevector transfer (in Ang^-1)

parse_header()[source]

Reads the header part of the file to get the labels of the data axes.

MDMC.readers.observables.MantidSQw module

Readers for dynamic data

class MDMC.readers.observables.MantidSQw.MantidSQw(file_name: str)[source]

Bases: SQwReader

A class for reading SQw files from Mantid

Mantid’s ascii output uses one or two files, either:
  • A file containing the SQw data and error for the range of energy values measured at each Q with file_name or

  • A file containing the SQw data and error for the range of energy values measured at each detector (or group of detectors) ID with file_name and a file giving the momentum value associated with each detector (or group of detectors) ID, with the name given by file_name + '_detectors'

If a single file is supplied, then it is assumed that the Q values are included in the data, this is the typical output of Mantid reduced ISIS data. An example reduction script is included in doc/tutorials/data/water_reduction_IRIS.py If there are two files then it is assumed that the second file links the detector ID’s with the corresponding Q’s

ID_or_Q

File containing the ID’s of the detectors, default=None

Type:

file, optional

file_detectors

File containing the errors on the dependent variables, default=None

Type:

file, optional

file_variables

File containing the variables for each detector ID or Q

Type:

file

parse(**settings: dict) None[source]

Parse into SQw format

E is the energy transfer (in meV) Q is wavevector transfer (in Ang^-1)

parse_detectors(file: IO) ndarray[source]

Parses the detector momenta values.

Parameters:

file (file) – Open file containing detector IDs and momenta

Returns:

A 1D array of momenta values

Return type:

numpy.ndarray

parse_variables(file: IO) tuple[float][source]

Parses the values for energy, SQw and its error for each detector, or momentum value if it is defined instead of detector_ID

Parameters:

file (file) – Open file containing the variables

Returns:

(X, Y, E) where X is the independent variable (energy), Y is the dependent variable (SQw) and E is the errors of Y

Return type:

tuple

MDMC.readers.observables.netCDFPDF module

A reader for netcdf PDF data

class MDMC.readers.observables.netCDFPDF.netCDFPDF(file_name: str)[source]

Bases: PDFReader

Currently only setup for parsing MMTK/nMOLDYN SQw netcdf files

file

The netCDF input file

Type:

file

extract_partial_pdf() None[source]

Automatically detects the partial PDF names within the file and extracts them nMOLDYN saves partial pdfs in the following format: “pdf-[element1]-[element2]”

parse(**settings: dict) None[source]

Parse into PDF format

MDMC.readers.observables.netCDFSQw module

A reader for netcdf SQw data

class MDMC.readers.observables.netCDFSQw.netCDFSQw(file_name: str)[source]

Bases: SQwReader

Currently only setup for parsing MMTK/nMOLDYN SQw netcdf files

file

The netCDF input file

Type:

file

parse(**settings: dict) None[source]

Parse into SQw format

E is the energy transfer (in meV) Q is wavevector transfer (in Ang^-1)

MDMC.readers.observables.obs_reader module

Module for observable reader abstract class

class MDMC.readers.observables.obs_reader.ObservableReader(file_name: str)[source]

Bases: Reader

Abstract class that defines methods common to all readers for observables

ObservableReaders are created using ObservableReaderFactory

assign(observable: Observable) None[source]

Abstract method to assign the parsed information into the Observable

Parameters:

observable (Observable) – An MDMC Observable that will be assigned the data parsed by the reader.

property data: dict

A dictionary of dictionaries containing the independent variables, dependent variables and the associated errors.

Returns:

The independent variables, dependent variables and the errors on the dependent variables

Return type:

dict

abstract property dependent_variables: None

The dependent variables

Returns:

A dictionary of the dependent variables

Return type:

dict

abstract property errors: None

The errors on the dependent variables

Returns:

A dictionary of the errors on the dependent variables

Return type:

dict

abstract property independent_variables: dict

The independent variables

Returns:

A dictionary of the independent variables

Return type:

dict

class MDMC.readers.observables.obs_reader.PDFReader(file_name: str)[source]

Bases: ObservableReader, ABC

Abstract base subclass that adds attributes & methods common to all PDF readers

property PDF: ndarray

Get or set the total pair distribution function between pairs (in barn) :returns: total pair distribution function (in barn) :rtype: numpy.ndarray

property PDF_err: ndarray

Get or set the error on the total pair distribution function between pairs (in barn) :returns: error on the total pair distribution function (in barn) :rtype: numpy.ndarray

property dependent_variables: dict

Get the dependent variable PDF, the pair distribution function (in barn)

Returns:

The dependent variable, PDF (in barn)

Return type:

dict

property errors: dict

Get the errors on the dependent variable

Returns:

The error on PDF (in barn)

Return type:

dict

property independent_variables: dict

Get the independent variable r (in Ang^-1)

Returns:

The independent variable r (in Ang^-1)

Return type:

dict

property r: float

Get or set the value of the atomic separation distance (in Ang)

class MDMC.readers.observables.obs_reader.SQwReader(file_name: str)[source]

Bases: ObservableReader, ABC

Abstract base subclass that adds attributes & methods common to all SQw readers

property E: float

Get or set the energy transfer, E, in meV

Returns:

Energy transfer, E, in meV

Return type:

array

property Q: float

Get or set the momentum transfer, Q, in Ang^-1

Returns:

Momentum transfer, Q, in Ang^-1

Return type:

array

property dependent_variables: dict

Get the dependent variables, SQw (in arb)

Returns:

The dependent variables, SQw (in arb)

Return type:

dict

property errors: dict

Get the errors on the dependent variables

Returns:

The error on SQw (in arb)

Return type:

dict

property independent_variables: dict

Get the independent variables, Q (in Ang^-1) and E (meV)

Returns:

The independent variables Q and E

Return type:

dict

property w: float

Get or set the energy transfer expressed in angular frequency, w, in 1 / ps

Returns:

Energy transfer as angular frequency, w, in 1 / ps

Return type:

array

MDMC.readers.observables.obs_reader_factory module

Factory class for generating readers for observables

class MDMC.readers.observables.obs_reader_factory.ObservableReaderFactory[source]

Bases: ReaderFactory

Provides a factory for creating readers. Any module within the readers submodule can be created with a string of the class name, as long as it is a subclass of Reader.

static base_class() ObservableReader[source]

This should be implemented to return the base class of objects returned by the ReaderFactory

MDMC.readers.observables.xml_SQw module

XML reader for SQw data

class MDMC.readers.observables.xml_SQw.XML_SQw(file_name: str)[source]

Bases: SQwReader

An XML reader for SQw data

static dict_from_element(element: TextIO) dict[source]

Creates a dictionary from an XML element

Parameters:

element (Element) – An XML element. Must have items method, which must return a list of 2 element tuples.

Returns:

For each tuple from the xml Element, The first index is the key and the second element is the value.

Return type:

dict

parse(**settings: dict) None[source]

Parses the xml file

Currently only parses SQw files

E is the energy transfer (in meV) Q is wavevector transfer (in Ang^-1)

Module contents

Modules for reading experimental observables

Contents

LAMPSQw LAMPPDF MantidSQw MDANSEQSw netCDFSQw netCDFPDF obs_reader_factory obs_reader xml_SQw