surfinpy.utils

The utils module contains functions that are common and find various uses throughout the code.

surfinpy.utils.build_entgrid(z, y, ynew)[source]

Builds a 2D grip of values for the x axis.

Parameters
  • x (array_like) – One dimensional numpy array representing one dimension of phase diagram

  • y (array_like) – One dimensional numpy array representing one dimension of phase diagram

Returns

xnew – Two dimensional numpy array required for energy calculations

Return type

array_like

surfinpy.utils.build_freqgrid(z, y)[source]

Builds a 2D grip of values for the x axis.

Parameters
  • x (array_like) – One dimensional numpy array representing one dimension of phase diagram

  • y (array_like) – One dimensional numpy array representing one dimension of phase diagram

Returns

xnew – Two dimensional numpy array required for energy calculations

Return type

array_like

surfinpy.utils.build_tempgrid(z, y)[source]

Builds a 2D grip of values for the x axis.

Parameters
  • x (array_like) – One dimensional numpy array representing one dimension of phase diagram

  • y (array_like) – One dimensional numpy array representing one dimension of phase diagram

Returns

xnew – Two dimensional numpy array required for energy calculations

Return type

array_like

surfinpy.utils.build_xgrid(x, y)[source]

Builds a 2D grip of values for the x axis.

Parameters
  • x (array_like) – One dimensional numpy array representing one dimension of phase diagram

  • y (array_like) – One dimensional numpy array representing one dimension of phase diagram

Returns

xnew – Two dimensional numpy array required for energy calculations

Return type

array_like

surfinpy.utils.build_ygrid(x, y)[source]

Builds a 2D grip of values for the y axis.

Parameters
  • x (array_like) – One dimensional numpy array representing one dimension of phase diagram

  • y (array_like) – One dimensional numpy array representing one dimension of phase diagram

Returns

xnew – Two dimensional numpy array required for energy calculations

Return type

array_like

surfinpy.utils.build_zgrid(z, y)[source]

Builds a 2D grip of values for the x axis.

Parameters
  • x (array_like) – One dimensional numpy array representing one dimension of phase diagram

  • y (array_like) – One dimensional numpy array representing one dimension of phase diagram

Returns

xnew – Two dimensional numpy array required for energy calculations

Return type

array_like

surfinpy.utils.calculate_coverage(data)[source]

Calcualte the coverage of the adsorbing species on each surface.

Parameters

data (list) – list of dictionaries containing info on each surface calculation

Returns

coverage – Coverage values in units of n/nm^2

Return type

array_like

surfinpy.utils.calculate_gibbs(t, s, h)[source]

Calculate the gibbs free energy from thermochemcial data obtained from the NIST_JANAF database

Parameters
  • t (array_like) – Temperature range

  • s (array_like) – delta s values from nist

  • h (array_like) – selta h values from nist

Returns

g – gibbs energy as a function of temperature

Return type

array_like

surfinpy.utils.cs_fit(x, y, t)[source]

Fit a polynominal function to thermochemical data from NIST_JANAF

Parameters
  • x (array_like) – x axis for fit

  • y (array_like) – y axis for fit

  • t (array_like) – x axis to be fitted

Returns

shift – data fitted from x and y to t

Return type

array_like

surfinpy.utils.fit_nist(nist_file, increments=1, method='cs')[source]

Use experimental data to correct the DFT free energy of an adsorbing species to a specific temperature.

Parameters

nist_file (array_like) – numpy array containing experiemntal data from NIST_JANAF

Returns

gibbs – correct free energy

Return type

float

surfinpy.utils.get_labels(ticks, data)[source]

Reads the phase diagram data and returns the labels that correspond to the phases displayed on the phase diagram.

Parameters
Returns

labels – list of labels.

Return type

list

surfinpy.utils.get_levels(X)[source]

Builds the levels used in the contourf plot. This is neccesary to ensure that each color correpsonds to a single phase.

Parameters

X (array_like) – 2D array of ints corresponding to each phase.

Returns

levels – numpy array of ints

Return type

array_like

surfinpy.utils.get_phase_data(S, nsurfaces)[source]

Determines which surface composition is most stable at a given x and y value.

Parameters
  • S (array_like) – 2D array of surface energies

  • nsurfaces (int) – Total number of surfaces

Returns

x – array of ints corresponding to the position of the lowest phase

Return type

array_like

surfinpy.utils.get_ticks(X)[source]

Sets the tick marks to show all phases plotted on the cbar plot.

surfinpy.utils.list_colors(phases, ticks)[source]

Reads the phase diagram data and returns the colors that correspond to the phases displayed on the phase diagram.

Parameters
  • phases (list) – list of (surfinpy.data.DataSet): objects.

  • ticks (list) – Phases that are displayed.

Returns

colors – list of colors.

Return type

list

surfinpy.utils.poly_fit(x, y, t)[source]

Fit a polynominal function to thermochemical data from NIST_JANAF :param x: x axis for fit :type x: array like :param y: y axis for fit :type y: array like :param t: x axis to be fitted :type t: array like

Returns

shift – data fitted from x and y to t

Return type

array like

surfinpy.utils.pressure(chemical_potential, t)[source]

Converts chemical potential at a specific temperature (T) to a pressure value.

P = \frac{\mu}{k * T}

where P is the pressure, \mu is the chemcial potential, k is the Boltzmann constant and T is the temperature.

Parameters
  • chemical_potential (array_like) – delta mu values

  • t (int) – temperature

Returns

pressure – pressure values as a function of chemcial potential

Return type

array_like

surfinpy.utils.read_nist(File)[source]

Read a downloaded NIST_JANAF thermochemcial table

Parameters

File (str) – Filename of NIST_JANAF thermochemcial table

Returns

data – NIST_JANAF thermochemcial as an array

Return type

array_like

surfinpy.utils.read_vibdata(vib_file)[source]

Reads a yaml file containing the vribational frequencies from a DFT calculation.

Parameters

vib_file ((str):) – File name

Returns

vib_prop – Dictionary of vibrational freqencies.

Return type

dict

surfinpy.utils.temperature_correction_range(nist_file, deltaY)[source]

Use experimental data to correct the DFT free energy of an adsorbing species to a specific temperature.

Parameters
  • nist_file (array_like) – numpy array containing experiemntal data from NIST_JANAF

  • temperature (int) – Temperature to correct to

Returns

gibbs – correct free energy

Return type

float

surfinpy.utils.transform_numbers(Z, ticks)[source]

transform numbers - Takes the phase diagram array and converts the numbers to numbers scaled 0, 1, 2, etc in order to make plotting easier

Parameters
  • Z (array_like) – array of integers

  • ticks (list) – unique phases

Returns

Z – Normalised to a continuous set of numbers.

Return type

array_like