utils

Miscellaneous functions.

utils.is_string_value(x, val)[source]

Check if x is str and then whether its value is val.

utils.isfilename(s)[source]

Guess if string is a file name.

True if s contains a dot and no space.

utils.kd(a, b)[source]

Kronecker delta.

Returns 1 if a = b, 0 otherwise.

utils.format_element_symbol(s)[source]

Format string to match valid element symbol.

utils.count_combinations(n)[source]

Count p-size combinations in n-size set, with p up to 3.

Parameters:

n (int) – Size of set.

Returns:

res{k: val for k in keys} with the following keys:

  • ’unaries’ : n.

  • ’binaries’ : C(n, 2).

  • ’ternaries’ : C(n, 3).

  • ’mix’ : binaries + ternaries.

  • ’all’ : unaries + binaries + ternaries.

Return type:

dict of ints

utils.make_combinations(constituents)[source]

Make combinations of constituents up to size 3 (unary, binary, ternary).

The combinations are stored as concatenated strings, for example “AuAg”.

Parameters:

constituents (list of str) – Constituents.

Returns:

res{k: list_of_strings for k in keys} with the following keys:

  • ’unaries’ : Constituents.

  • ’binaries’ : All binary subsystems.

  • ’ternaries’ : All ternary subsystems.

  • ’mix’ : All binary and ternary subsystems.

  • ’all’ : All subsystems.

Return type:

dict of lists

utils.index_binary_combination(i, j, n)[source]

Compute index of binary combination in n-size system.

Combination (i, j) where i and j start at 0.

Example with n = 3: ===== ==== index i, j ===== ==== 0 0, 1 1 0, 2 2 1, 2 ===== ====

utils.index_ternary_combination(i, j, k, n)[source]

Compute index of ternary combination in n-size system.

Combination (i, j, k) where i, j and k start at 0.

Example with n = 4: ===== ======= index i, j, k ===== ======= 0 0, 1, 2 1 0, 1, 3 2 0, 2, 3 3 1, 2, 3 ===== =======

utils.make_permutations_samesize(solvent)[source]

Make all permutations of constituents in solvent, preserving size.

Parameters:

solvent (str) – Constituents concatenated to string. A constituent is defined by one uppercase letter followed by any number of lowercase letters.

Returns:

res – All permutations, with same syntax as input.

Return type:

list of str

utils.integrate(f, u, F0, geometry)[source]

Compute radial vector field from its divergence.

The field is evaluated along one space coordinate, in either of 3 geometric configurations (planar, cylindrical, spherical).

The f values are evaluated at midpoints of the u array. Ensures minimum error when composed with div().

Parameters:
  • f (1D array) – Divergence of the radial field, shape (u.size - 1,).

  • u (1D array) – Coordinates where the field is evaluated, shape (u.size,).

  • F0 (float) – Integration constant.

  • geometry (int) – Indicates the geometry (planar, cylindrical, spherical).

Returns:

Radial field, shape (u.size,).

Return type:

1D array

utils.div(F, u, geometry)[source]

Compute the divergence of a radial vector field.

The field is evaluated along one space coordinate, in either of 3 geometric configurations (planar, cylindrical, spherical).

Ensures minimum error when composed with integrate().

Parameters:
  • F (1D array) – Radial field, shape (u.size,).

  • u (1D array) – Coordinates where the field is evaluated, shape (u.size,).

  • geometry (int) – Indicates the geometry (planar, cylindrical, spherical).

Returns:

Divergence of the field, shape (u.size - 1,).

Return type:

1D array

exception utils.AtomFractionError(n)[source]

Bases: Exception

Exception raised when an atom fraction is invalid.

exception utils.UserInputError(msg)[source]

Bases: Exception

Exception raised when a user input is invalid.

exception utils.ResultsError(msg)[source]

Bases: Exception

Exception raised when a user request to access results is invalid.