@@ -65,6 +65,9 @@ def generate_atom_list(cfg: GenerateConfig, verbosity: int = 1) -> np.ndarray:
6565 """
6666 Generate a random molecule with a random number of atoms.
6767 """
68+ # initialize a default random number generator
69+ rng = np .random .default_rng ()
70+
6871 # Define a new set of all elements that can be included
6972 set_all_elem = set (range (0 , MAX_ELEM ))
7073 if cfg .forbidden_elements :
@@ -166,17 +169,17 @@ def add_random(min_adds: int, max_adds: int, min_nat: int, max_nat: int):
166169 """
167170 Default random atom generation.
168171 """
169- numatoms_all = np . random . randint (
170- min_adds , max_adds
172+ numatoms_all = rng . integers (
173+ low = min_adds , high = max_adds
171174 ) # with range(1, 7) -> mean value: 3.5
172175 for _ in range (numatoms_all ):
173176 # Define the atom type to be added via a random choice from the set of valid elements
174- ati = np . random .choice (list (valid_elems ))
177+ ati = rng .choice (list (valid_elems ))
175178 if verbosity > 1 :
176179 print (f"Adding atom type { ati } ..." )
177180 # Add a random number of atoms of the defined type
178- natoms [ati ] = natoms [ati ] + np . random . randint (
179- min_nat , max_nat
181+ natoms [ati ] = natoms [ati ] + rng . integers (
182+ low = min_nat , high = max_nat
180183 ) # with range(0, 3) -> mean value: 1
181184 # max value of this section with commented settings: 12
182185
@@ -193,11 +196,11 @@ def add_organic(num_adds: int, min_nat: int, max_nat: int) -> None:
193196 return
194197 for _ in range (num_adds ): # with range(5) -> mean value 1.5
195198 # go through the elements B to F (4-9 in 0-based indexing)
196- ati = np . random .choice (valid_organic )
199+ ati = rng .choice (valid_organic )
197200 if verbosity > 1 :
198201 print (f"Adding atom type { ati } ..." )
199- natoms [ati ] = natoms [ati ] + np . random . randint (
200- min_nat , max_nat
202+ natoms [ati ] = natoms [ati ] + rng . integers (
203+ low = min_nat , high = max_nat
201204 ) # with range(0, 3) -> mean value: 1
202205 # max value of this section with commented settings: 8
203206
@@ -243,7 +246,7 @@ def add_hydrogen():
243246 # If no H is included, add H atoms
244247 if natoms [0 ] == 0 :
245248 nat = np .sum (natoms )
246- randint = np .random . rand ()
249+ randint = rng .random ()
247250 j = 1 + round (randint * nat * 1.2 )
248251 natoms [0 ] = natoms [0 ] + j
249252 # Example: For 5 atoms at this point,
@@ -257,7 +260,7 @@ def check_min_max_atoms():
257260 f"Minimal number of atoms: { cfg .min_num_atoms } ; "
258261 + f"Actual number of atoms: { np .sum (natoms )} .\n Adding atoms..."
259262 )
260- ati = np . random .choice (list (valid_elems ))
263+ ati = rng .choice (list (valid_elems ))
261264 max_limit = cfg .element_composition .get (ati , (None , None ))[1 ]
262265 if max_limit is not None and natoms [ati ] >= max_limit :
263266 continue
@@ -285,7 +288,7 @@ def check_min_max_atoms():
285288 # randomly select an atom type from the list, thereby weighting the selection
286289 # for reduction by the current occurrence
287290 # generate a random number between 0 and the number of atoms in the list
288- random_index = np . random . randint ( len (atom_list ))
291+ random_index = rng . integers ( 0 , len (atom_list ))
289292 i = atom_list [int (random_index )]
290293 if natoms [i ] > 0 :
291294 min_limit = cfg .element_composition .get (i , (None , None ))[0 ]
@@ -361,13 +364,15 @@ def generate_random_coordinates(at: np.ndarray) -> tuple[np.ndarray, np.ndarray]
361364 atilist : list [int ] = []
362365 xyz = np .zeros ((sum (at ), 3 ))
363366 numatoms = 0
367+ rng = np .random .default_rng ()
364368 for elem , count in enumerate (at ):
365369 for m in range (count ):
366370 # different rules for hydrogen
367371 if elem == 0 :
368- xyz [numatoms + m , :] = np .random . rand (3 ) * 3 - 1.5
372+ xyz [numatoms + m , :] = rng .random (3 ) * 3 - 1.5
369373 else :
370- xyz [numatoms + m , :] = np .random .rand (3 ) * 2 - 1
374+ xyz [numatoms + m , :] = rng .random (3 ) * 2 - 1
375+
371376 atilist .append (elem )
372377
373378 numatoms += count
0 commit comments