Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Functions that are important for the genetic algorithm.
2Shorthand for setting and getting
3- the raw_score
4- the neighbor_list
5- the parametrization
6of an atoms object.
7"""
10def set_raw_score(atoms, raw_score):
11 """Set the raw_score of an atoms object in the
12 atoms.info['key_value_pairs'] dictionary.
14 Parameters
15 ----------
16 atoms : Atoms object
17 The atoms object that corresponds to this raw_score
18 raw_score : float or int
19 Independent calculation of how fit the candidate is.
20 """
21 if 'key_value_pairs' not in atoms.info:
22 atoms.info['key_value_pairs'] = {}
23 atoms.info['key_value_pairs']['raw_score'] = raw_score
26def get_raw_score(atoms):
27 """Gets the raw_score of the supplied atoms object.
29 Parameters
30 ----------
31 atoms : Atoms object
32 The atoms object from which the raw_score will be returned.
34 Returns
35 -------
36 raw_score : float or int
37 The raw_score set previously.
38 """
39 return atoms.info['key_value_pairs']['raw_score']
42def set_parametrization(atoms, parametrization):
43 if 'data' not in atoms.info:
44 atoms.info['data'] = {}
45 atoms.info['data']['parametrization'] = parametrization
48def get_parametrization(atoms):
49 if 'parametrization' in atoms.info['data']:
50 return atoms.info['data']['parametrization']
51 else:
52 raise ValueError('Trying to get the parametrization before it is set!')
55def set_neighbor_list(atoms, neighbor_list):
56 if 'data' not in atoms.info:
57 atoms.info['data'] = {}
58 atoms.info['data']['neighborlist'] = neighbor_list
61def get_neighbor_list(atoms):
62 if 'neighborlist' in atoms.info['data']:
63 return atoms.info['data']['neighborlist']
64 else:
65 return None