utils
Miscellaneous functions.
- 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) with i > j.
Example with n = 3:
i
j
index
0
1
0
0
2
1
1
2
2
- utils.index_ternary_combination(i, j, k, n)[source]
Compute index of ternary combination in n-size system.
Combination (i, j, k) with i > j > k.
Example with n = 4:
i
j
k
index
0
1
2
0
0
1
3
1
0
2
3
2
1
2
3
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:
ExceptionException raised when an atom fraction is invalid.