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 Structure class. 

3""" 

4 

5from ase import Atoms 

6 

7from _icet import Structure 

8 

9 

10@classmethod 

11def _structure_from_atoms(self, conf: Atoms): 

12 """ 

13 Returns the input configuration as an icet Structure object. 

14 

15 Parameters 

16 ---------- 

17 conf 

18 input configuration 

19 

20 Returns 

21 ------- 

22 atomic configuration 

23 """ 

24 return self(conf.positions, 

25 conf.get_chemical_symbols(), 

26 conf.cell, 

27 conf.pbc.tolist()) 

28 

29 

30Structure.from_atoms = _structure_from_atoms 

31 

32 

33def _structure_to_atoms(self) -> Atoms: 

34 """ 

35 Returns the structure as an ASE Atoms object. 

36 

37 Returns 

38 ------- 

39 atomic configuration 

40 """ 

41 import ase 

42 conf = ase.Atoms(pbc=self.pbc) 

43 conf.set_cell(self.cell) 

44 for symbol, position in zip(self.chemical_symbols, self.positions): 

45 conf.append(ase.Atom(symbol, position)) 

46 return conf 

47 

48 

49Structure.to_atoms = _structure_to_atoms 

50 

51 

52def _repr_function(self) -> str: 

53 s = ['Cell:'] 

54 s += ['{}\n'.format(self.cell)] 

55 s += ['Element and positions:'] 

56 for symbol, position in zip(self.chemical_symbols, self.positions): 

57 s += ['{} [{:} {:} {:}]'.format(symbol, *position)] 

58 return '\n'.join(s) 

59 

60 

61Structure.__repr__ = _repr_function