Coverage for /builds/kinetik161/ase/ase/ga/__init__.py: 45.45%

22 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +0000

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""" 

8 

9 

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. 

13 

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 

24 

25 

26def get_raw_score(atoms): 

27 """Gets the raw_score of the supplied atoms object. 

28 

29 Parameters 

30 ---------- 

31 atoms : Atoms object 

32 The atoms object from which the raw_score will be returned. 

33 

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'] 

40 

41 

42def set_parametrization(atoms, parametrization): 

43 if 'data' not in atoms.info: 

44 atoms.info['data'] = {} 

45 atoms.info['data']['parametrization'] = parametrization 

46 

47 

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!') 

53 

54 

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 

59 

60 

61def get_neighbor_list(atoms): 

62 if 'neighborlist' in atoms.info['data']: 

63 return atoms.info['data']['neighborlist'] 

64 else: 

65 return None