vibrav.util.io module

vibrav.util.io.get_all_data(cls, path, method, f_start='', f_end='')[source]

Function to get all of the data from the files in a specific directory. It will look for all of the files that match the given f_start and f_end input parameters and try to extract the information for the given property with the cls parser class.

Note

We recommend that the convention used in creating the different files is such that there is an idex to each file to keep track of the data that corresponds to the specific file. The program, when attempting to find the index of the file, will find all of the integers in the filename and assume that the last entry is the file index. It will give a warning if it finds more than one integer group in the filename to tell the user that it will assume that the last group of integers found is the file index.

Parameters:
  • cls (class object) – Class object of the output parser of choice.

  • path (str) – Path to the directory containing all of the output files.

  • method (str) – Parsing method to use in the given class.

  • f_start (str) – Starting string to match the output files. Defaults to ''.

  • f_end (str) – Ending string to match the output files. Defaults to ''.

Returns:

data (pandas.DataFrame) – Data frame with all of the parsed data.

Raises:

ValueError – If the program cannot find any data or files that match the input parameters.

vibrav.util.io.open_txt(fp, rearrange=True, get_complex=False, fill=False, is_complex=True, tol=None, get_magnitude=False, **kwargs)[source]

Method to open a .txt file that has a separator of ‘ ‘ with the first columns ordered as [‘nrow’, ‘ncol’, ‘real’, ‘imag’]. We take care of adding the two values to generate a complex number. The program will take your data and automatically generate a matrix of complex values that has the size of the maximum of the unique values in the ‘nrow’ column and the maximum in the ‘ncol’ column. tha being said if there are missing values the program will throw ‘ValueError’ as it will not be able to determine the size of the new matrix. This works for both square and non-square matrices. We assume that the indexing is non-pythonic hence the subtraction of ‘nrow’ and ‘ncol’ columns.

Parameters:
  • fp (str) – Filepath of the file you want to open.

  • rearrange (bool, optional) – If you want to rearrange the data into a square complex matrix. Defaults to True.

  • fill (bool, optional) – Fill the missing indeces with zeros.

  • is_complex (bool, optional) – The input data is complex.

  • tol (float, optional) – Ignore any values in the matrix that are less than this threshold. Defaults to None (no values are discarded).

  • get_magnitude (bool, optional) – Calculate the magnitude of the data. Only applicable when the input data is complex. Will be ignored if rearrange=True. Defaults to False.

  • sep (str, optional) – Delimiter value. Will default to ‘ ‘.

  • skipinitialspace (bool, optional) – Pandas skipinitialspace argument in the pandas.read_csv method. Defaults to True.

  • **kwargs (optional) – Arguments that will be passed into pandas.read_csv.

Returns:

matrix (pandas.DataFrame)

Re-sized complex square matrix with the

appropriate size.

Raises:

TypeError – When there are null values found. A common place this has been an issue is when the first two columns in the ‘.txt’ files read have merged due to too many states. This was found to happen when there were over 1000 spin-orbit states.

vibrav.util.io.read_data_file(fp, nmodes, smat=False, nat=None)[source]

Open a data file generated when creating the displaced coordinates.

Note

If smat=True the script will return a data frame object

Parameters:
  • fp (str) – Filepath to file.

  • nmodes (int) – Give the number of normal modes in the molecule.

  • smat (bool, optional) – Is the data from the smatrix file. This file is special as it needs to be transformed into three columns.

  • nat (int, optional) – Required when smat=True. Give the number of atoms in the molecule.

Returns:

arr (numpy.ndarray) – Array with the values.

vibrav.util.io.uncompress_file(fp, compression='xz')[source]
vibrav.util.io.write_txt(df, fp, formatter=None, header=None, order='F', non_matrix=False, mode='w')[source]

Function to write the input data as a txt file with the set format to be read by external codes in the MCD suite.

Parameters:
  • df (pandas.DataFrame or numpy.ndarray) – Input data

  • fp (str) – File to write data to

  • formatter (list, optional) – List of formatting strings.

  • header (str, optional) – Header to place on the file.

  • order (str, optional) – Flattening order. See numpy.ndarray.flatten for more information.