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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

def read_force_constants(filename, format=None): 

""" 

Reads force constants from file. Several different file formats 

are supported including `phonopy`, `phono3py`, and `shengBTE`. 

 

Parameters 

---------- 

filename : str 

name of input file 

format : str 

format of input file 

 

possible values: 

``phonopy``, ``phonopy-text``, ``phonopy-hdf5``, ``phono3py``, 

``shengbte`` 

 

In the case of ``phonopy`` hiphive will attempt to infer the file 

format (hdf5 or text) from the file name. 

 

Returns 

------- 

numpy.ndarray 

second (`phonopy`) or third-order (`phono3py`, `shengBTE`) 

force constant matrix 

 

Raises 

------ 

ValueError 

if file format cannot be recognized 

""" 

from .phonopy import read_phonopy_fc2, read_phonopy_fc3 

from .shengBTE import read_shengBTE_fc3 

 

if format == 'phonopy': 

return read_phonopy_fc2(filename) 

elif format == 'phonopy-text': 

return read_phonopy_fc2(filename, format='text') 

elif format == 'phonopy-hdf5': 

return read_phonopy_fc2(filename, format='hdf5') 

elif format == 'phono3py': 

return read_phonopy_fc3(filename) 

42 ↛ 43line 42 didn't jump to line 43, because the condition on line 42 was never true elif format == 'shengbte': 

return read_shengBTE_fc3(filename) 

else: 

raise ValueError('Unrecognized file format: {}'.format(format)) 

 

 

def write_force_constants(filename, fc, format=None): 

""" 

Writes force constants to file. 

 

Parameters 

---------- 

filename : str 

name of output file 

fc : ForceConstants or numpy.ndarray 

force constant matrix 

format : str 

format of output file 

 

possible values: 

``phonopy``, ``phonopy-text``, ``phonopy-hdf5``, ``phono3py``, 

``shengbte`` 

 

In the case of `phonopy` hiphive will attempt to infer the file 

format (hdf5 or text) from the file name. 

 

Raises 

------ 

ValueError 

if file format cannot be recognized 

""" 

from .phonopy import write_phonopy_fc2, write_phonopy_fc3 

from .shengBTE import write_shengBTE_fc3 

 

if format == 'phonopy': 

write_phonopy_fc2(filename, fc) 

elif format == 'phonopy-text': 

write_phonopy_fc2(filename, fc, format='text') 

elif format == 'phonopy-hdf5': 

write_phonopy_fc2(filename, fc, format='hdf5') 

elif format == 'phono3py': 

write_phonopy_fc3(filename, fc) 

84 ↛ 85line 84 didn't jump to line 85, because the condition on line 84 was never true elif format == 'shengbte': 

write_shengBTE_fc3(filename, fc) 

else: 

raise ValueError('Unrecognized file format: {}'.format(format))