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

CCPBioSim / CodeEntropy / 13726590978

07 Mar 2025 06:07PM UTC coverage: 1.726%. First build
13726590978

push

github

web-flow
Merge pull request #45 from CCPBioSim/39-implement-ci-pipeline-pre-commit-hooks

Implement CI pipeline pre-commit hooks

27 of 1135 new or added lines in 23 files covered. (2.38%)

53 of 3071 relevant lines covered (1.73%)

0.05 hits per line

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

0.0
/CodeEntropy/poseidon/extractData/dihedrals.py
1
#!/usr/bin/env python
2

3
# import math
4
# import sys
5

NEW
6
import numpy as np
×
7

NEW
8
from CodeEntropy.poseidon.extractData.generalFunctions import distance, vector
×
9

10

11
def calculateDihedrals(all_data, dimensions):
×
12
    """
13
    In-place modification of all_data to calculate dihedrals
14
    For each dihedral in system, find what conformation it is in
15
    Dihedrals:
16

17

18
               X4
19
               /
20
              /
21
       X2---X3
22
      /
23
     /
24
    X1
25

26

27
    b1 = vector(X1, X2)
28
    b2 = vector(X2, X3)
29
    b3 = vector(X3, X4)
30

31
    source = https://math.stackexchange.com/questions/47059/
32
        how-do-i-calculate-a-dihedral-angle-given-cartesian-coordinates
33

34
    Args:
35
        all_data (list of poseidon.atom_info): Container for all atom info
36
        dimensions (numpy array of size (1,3)): dimension of box of current frame
37
    """
38

NEW
39
    rad2deg = float(180) / float(np.pi)
×
40

41
    dihedrals = []
×
42
    all_atom_nums_list = []
×
43

NEW
44
    max_atom_num = max(all_data[x].atom_num for x in range(0, len(all_data)))
×
45

46
    for x in range(0, len(all_data)):
×
47
        atom = all_data[x]
×
NEW
48
        if (
×
49
            atom.mass > 1.1
50
            and len(atom.dihedral_list) != 0
51
            and atom.atom_num not in all_atom_nums_list
52
        ):
53

NEW
54
            Mdihedrals = []  # unique dihedrals for each atom in molecule
×
55
            lowest_atom_num = max_atom_num + 1
×
56
            for molecule_atom in atom.molecule_atomNums:
×
57
                Matom = all_data[molecule_atom]
×
58
                all_atom_nums_list.append(Matom.atom_num)
×
59
                # get lowest atom num for renumbering
60
                for dih in Matom.dihedral_list:
×
61
                    for d in dih:
×
62
                        if all_data[d].resid == atom.resid:
×
63
                            if d < lowest_atom_num:
×
64
                                lowest_atom_num = d
×
65
                            else:
66
                                continue
×
67

68
            for molecule_atom in atom.molecule_atomNums:
×
69
                Matom = all_data[molecule_atom]
×
70
                for dih in Matom.dihedral_list:
×
71

72
                    inside_resid = True
×
73
                    for d in dih:
×
74
                        if all_data[d].resid != atom.resid:
×
75
                            inside_resid = False
×
76

NEW
77
                    if dih not in dihedrals and inside_resid is True:
×
78
                        # only analyse dihedral once
79
                        dihedrals.append(dih)
×
80

NEW
81
                        d_atoms = []
×
NEW
82
                        atom_nums = []  # 1,2,3,4
×
NEW
83
                        for d in dih:  # calc dih angles for each dih
×
84
                            atom2 = all_data[d]
×
85
                            d_atoms.append(atom2)
×
86
                            atom_nums.append(atom2.atom_num)
×
87

88
                        # re-number atom_nums
89
                        renumbered_atom_nums = []
×
90
                        for num in atom_nums:
×
91
                            renumbered = (num - lowest_atom_num) + 1
×
92
                            renumbered_atom_nums.append(renumbered)
×
93

94
                        # get vectors
NEW
95
                        b1_vector = vector(
×
96
                            d_atoms[0].coords, d_atoms[1].coords, dimensions
97
                        )
NEW
98
                        b1_dist = distance(
×
99
                            d_atoms[0].coords, d_atoms[1].coords, dimensions
100
                        )
101
                        b1_norm = np.divide(b1_vector, b1_dist)
×
102

NEW
103
                        b2_vector = vector(
×
104
                            d_atoms[1].coords, d_atoms[2].coords, dimensions
105
                        )
NEW
106
                        b2_dist = distance(
×
107
                            d_atoms[1].coords, d_atoms[2].coords, dimensions
108
                        )
109
                        b2_norm = np.divide(b2_vector, b2_dist)
×
110

NEW
111
                        b3_vector = vector(
×
112
                            d_atoms[2].coords, d_atoms[3].coords, dimensions
113
                        )
NEW
114
                        b3_dist = distance(
×
115
                            d_atoms[2].coords, d_atoms[3].coords, dimensions
116
                        )
117
                        b3_norm = np.divide(b3_vector, b3_dist)
×
118

119
                        # get normals
120
                        n1 = np.cross(b1_norm, b2_norm)
×
121
                        n2 = np.cross(b2_norm, b3_norm)
×
122
                        m = np.cross(n1, b2_norm)
×
123

124
                        # get dot products
125
                        x = np.dot(n1, n2)
×
126
                        y = np.dot(m, n2)
×
127

128
                        phi = rad2deg * np.arctan2(y, x)
×
129
                        dih_type = None
×
130

131
                        # only needed for fixed-dihedrals
132
                        if phi >= 120 or phi < -120:
×
NEW
133
                            dih_type = [0, "trans"]
×
134

135
                        if phi >= 0 and phi < 120:
×
NEW
136
                            dih_type = [1, "g-"]
×
137

138
                        if phi >= -120 and phi < 0:
×
NEW
139
                            dih_type = [2, "g+"]
×
140

NEW
141
                        Mdihedrals.append(
×
142
                            [renumbered_atom_nums, int(round(phi, 0)), dih_type]
143
                        )
144

145
                    else:
146
                        continue
×
147

148
            atom.dihedral_phi_type = Mdihedrals
×
149

150
        else:
151
            continue
×
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