Hide keyboard shortcuts

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

2This module provides the OrbitList class. 

3""" 

4 

5from typing import List 

6 

7import numpy as np 

8 

9from _icet import _OrbitList 

10from ase import Atoms 

11from icet.core.local_orbit_list_generator import LocalOrbitListGenerator 

12from icet.core.neighbor_list import get_neighbor_lists 

13from icet.core.matrix_of_equivalent_positions import \ 

14 _get_lattice_site_matrix_of_equivalent_positions, \ 

15 matrix_of_equivalent_positions_from_structure 

16from icet.core.structure import Structure 

17from icet.input_output.logging_tools import logger 

18 

19logger = logger.getChild('orbit_list') 

20 

21 

22class OrbitList(_OrbitList): 

23 """ 

24 The orbit list object handles an internal list of orbits. 

25 

26 An orbit has a list of equivalent sites with the restriction 

27 that at least one site is in the cell of the primitive structure. 

28 

29 Parameters 

30 ---------- 

31 structure : Atoms 

32 This structure will be used to construct a primitive 

33 structure on which all the lattice sites in the orbits 

34 are based. 

35 cutoffs : list of float 

36 the i-th element of this list is the cutoff for orbits with 

37 order i+2 

38 symprec : float 

39 tolerance imposed when analyzing the symmetry using spglib 

40 position_tolerance : float 

41 tolerance applied when comparing positions in Cartesian coordinates 

42 fractional_position_tolerance : float 

43 tolerance applied when comparing positions in fractional coordinates 

44 """ 

45 

46 def __init__(self, 

47 structure: Atoms, 

48 cutoffs: List[float], 

49 symprec: float, 

50 position_tolerance: float, 

51 fractional_position_tolerance: float) -> None: 

52 max_cutoff = np.max(cutoffs) 

53 # Set up a permutation matrix 

54 matrix_of_equivalent_positions, prim_structure, _ \ 

55 = matrix_of_equivalent_positions_from_structure(structure=structure, 

56 cutoff=max_cutoff, 

57 position_tolerance=position_tolerance, 

58 find_primitive=False, 

59 symprec=symprec) 

60 

61 logger.info('Done getting matrix_of_equivalent_positions.') 

62 

63 # Get a list of neighbor-lists 

64 neighbor_lists = get_neighbor_lists(structure=prim_structure, cutoffs=cutoffs, 

65 position_tolerance=position_tolerance) 

66 

67 logger.info('Done getting neighbor lists.') 

68 

69 # Transform matrix_of_equivalent_positions to be in lattice site format 

70 pm_lattice_sites = _get_lattice_site_matrix_of_equivalent_positions( 

71 structure=prim_structure, 

72 matrix_of_equivalent_positions=matrix_of_equivalent_positions, 

73 fractional_position_tolerance=fractional_position_tolerance, 

74 prune=True) 

75 

76 logger.info('Transformation of matrix of equivalent positions' 

77 ' to lattice neighbor format completed.') 

78 

79 _OrbitList.__init__(self, 

80 structure=prim_structure, 

81 matrix_of_equivalent_sites=pm_lattice_sites, 

82 neighbor_lists=neighbor_lists, 

83 position_tolerance=position_tolerance) 

84 logger.info('Finished construction of orbit list.') 

85 

86 @property 

87 def primitive_structure(self): 

88 """ 

89 Returns the primitive structure to which the lattice sites in 

90 the orbits are referenced to. 

91 """ 

92 return self._primitive_structure.copy() 

93 

94 def __str__(self): 

95 """String representation.""" 

96 nice_str = 'Number of orbits: {}'.format(len(self)) 

97 

98 for i, orbit in enumerate(self.orbits): 

99 cluster_str = self.orbits[i].representative_cluster.__str__() 

100 nice_str += '\norbit {} - Multiplicity {} - Cluster: {}'.format( 

101 i, len(orbit), cluster_str) 

102 return nice_str 

103 

104 def get_supercell_orbit_list(self, 

105 structure: Atoms, 

106 fractional_position_tolerance: float): 

107 """ 

108 Returns an orbit list for a supercell structure. 

109 

110 Parameters 

111 ---------- 

112 structure 

113 supercell atomic structure 

114 fractional_position_tolerance : float 

115 tolerance applied when comparing positions in fractional coordinates 

116 """ 

117 lolg = LocalOrbitListGenerator( 

118 self, 

119 structure=Structure.from_atoms(structure), 

120 fractional_position_tolerance=fractional_position_tolerance) 

121 supercell_orbit_list = lolg.generate_full_orbit_list() 

122 return supercell_orbit_list 

123 

124 def remove_inactive_orbits(self, 

125 allowed_species: List[List[str]]) -> None: 

126 """ Removes orbits with inactive sites. 

127 

128 Parameters 

129 ---------- 

130 allowed_species 

131 the list of allowed species on each site in the primitive 

132 structure 

133 """ 

134 prim_structure = self.get_primitive_structure() 

135 number_of_allowed_species = [len(sym) for sym in allowed_species] 

136 prim_structure.set_number_of_allowed_species(number_of_allowed_species) 

137 self._remove_inactive_orbits(prim_structure)