• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

maurergroup / dfttoolkit / 15077298886

16 May 2025 08:57PM UTC coverage: 28.848% (+7.1%) from 21.747%
15077298886

Pull #59

github

b0d5e4
web-flow
Merge 473bfe91e into e895278a4
Pull Request #59: Vibrations refactor

1162 of 4028 relevant lines covered (28.85%)

0.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
dfttoolkit/friction.py
1
from os.path import join
×
2

3
import numpy as np
×
4

5
from dfttoolkit.geometry import AimsGeometry
×
6

7

8
class FrictionTensor:
×
9
    def __init__(self, directroy):
×
10
        self.geometry = AimsGeometry(join(directroy, "geometry.in"))
×
11
        self.friction_tensor_raw = self.read_friction_tensor(
×
12
            join(directroy, "friction_tensor.out")
13
        )
14

15
    @property
×
16
    def friction_tensor(self):
×
17
        return self.friction_tensor_raw
×
18

19
    @friction_tensor.setter
×
20
    def friction_tensor(self, friction_tensor_raw) -> None:
×
21
        self.friction_tensor_raw = friction_tensor_raw
×
22

23
    def read_friction_tensor(self, filename: str):
×
24
        """
25
        Reads the friction tensor when given a calculation directroy; Saves a
26
        full size friction tensor (elements for all atoms) where atom-pairs
27
        without friction are assigned a friction value of 0.
28

29
        Parameters
30
        ----------
31
        filename : str
32
            Path to directry.
33

34
        Returns
35
        -------
36
        friction_tensor : np.array
37
            Friction tensor for all atoms.
38

39
        """
40
        atom_indices = []
×
41
        friction_tensor_0 = []
×
42

43
        with open(filename) as f:
×
44
            lines = f.readlines()
×
45

46
        for line in lines:
×
47
            if "# n_atom" in line:
×
48
                line = line.strip().split(" ")
×
49

50
                line_1 = []
×
51
                for i in line:
×
52
                    if i != "":
×
53
                        line_1.append(i)
×
54

55
                atom_index = 3 * (int(line_1[2]) - 1) + int(line_1[4]) - 1
×
56
                atom_indices.append(atom_index)
×
57

58
            elif "#" not in line:
×
59
                friction_tensor_line = [float(i) for i in line.split(" ") if i != ""]
×
60

61
                friction_tensor_0.append(friction_tensor_line)
×
62

63
        friction_tensor_0 = np.array(friction_tensor_0)
×
64

65
        n = len(self.geometry)
×
66
        friction_tensor = np.zeros((3 * n, 3 * n))
×
67

68
        for ind_0, atom_index_0 in enumerate(atom_indices):
×
69
            for ind_1, atom_index_1 in enumerate(atom_indices):
×
70
                friction_tensor[atom_index_0, atom_index_1] = friction_tensor_0[
×
71
                    ind_0, ind_1
72
                ]
73

74
        return friction_tensor
×
75

76
    def get_life_time(self, vibration):
×
77
        """Returns life time in ps."""
78
        vibration /= np.linalg.norm(vibration)
×
79

80
        force = self.friction_tensor_raw.dot(vibration)
×
81

82
        eta = vibration.dot(force)
×
83

84
        return 1 / eta
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc