Structure generation
Functions for generating random glass compositions and structures, useful for building training sets.
balance_charge(amounts, atoms, charges_dict, max_iter=1)
Adjust one atom's amount so the total ionic charge of a composition is closer to zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amounts
|
List[int]
|
The (scaled integer) amounts of each atom type. |
required |
atoms
|
List[str]
|
The chemical symbols corresponding to each entry in amounts. |
required |
charges_dict
|
dict
|
A mapping from chemical symbol to oxidation state. |
required |
max_iter
|
int
|
Unused; retained for API compatibility. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
|
Tuple[List[int], float]: The (possibly adjusted) amounts, and the resulting total charge. |
Source code in src/vitrum/structure_gen.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
choose_count(weights)
Randomly choose an index (interpreted as a count) according to given weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
List[float]
|
Relative weights for each possible count, starting at 0. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
The chosen count. |
Source code in src/vitrum/structure_gen.py
64 65 66 67 68 69 70 71 72 73 74 75 | |
gen_random_glasses(modifiers, formers, anions, weights={}, num_structures=30, target_atoms=100, **kwargs)
Generate random glass structures from the atoms in given modifiers, formers and anions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modifiers
|
list
|
A list of the chemical symbols of the modifiers. |
required |
formers
|
list
|
A list of the chemical symbols of the network formers. |
required |
anions
|
list
|
A list of the chemical symbols of the anions. |
required |
weights
|
dict
|
A dictionary of weights for the number of modifiers, formers and anions. |
{}
|
num_structures
|
int
|
The number of structures to generate. Defaults to 30. |
30
|
target_atoms
|
int
|
The target number of atoms in the structure. Defaults to 100. |
100
|
**kwargs
|
Additional keyword arguments to be passed to the get_random_packed function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
compositions |
list
|
A list of random packed structures. |
Source code in src/vitrum/structure_gen.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
is_multiple(c, total, tol=1e-09)
Check whether total is (approximately) an integer multiple of c.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
float
|
The candidate divisor (e.g. an oxidation state). |
required |
total
|
float
|
The value to test. |
required |
tol
|
float
|
Absolute tolerance for the closeness check. Defaults to 1e-9. |
1e-09
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if total/c is close to an integer. |
Source code in src/vitrum/structure_gen.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
my_round(x)
Round a value to the nearest 0.01, returned with 3 decimal places of precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
The value to round. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
The rounded value. |
Source code in src/vitrum/structure_gen.py
9 10 11 12 13 14 15 16 17 18 19 | |
random_partition(x, total=10)
Randomly partition total into x positive parts, returned as fractions summing to 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
The number of parts to partition into. |
required |
total
|
int
|
The integer total to partition before normalizing. Defaults to 10. |
10
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: An array of |
Source code in src/vitrum/structure_gen.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |