• 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

8.0
/CodeEntropy/ConformationFunctions.py
1
import numpy as np
3✔
2

3
# from MDAnalysis.analysis.dihedrals import Dihedral
4

5

6
def assign_conformation(
3✔
7
    data_container, dihedral, number_frames, bin_width, start, end, step
8
):
9
    """
10
    Create a state vector, showing the state in which the input dihedral is
11
    as a function of time. The function creates a histogram from the timeseries of the
12
    dihedral angle values and identifies points of dominant occupancy
13
    (called CONVEX TURNING POINTS).
14
    Based on the identified TPs, states are assigned to each configuration of the
15
    dihedral.
16

17
    Input
18
    -----
19
    dihedral_atom_group : the group of 4 atoms defining the dihedral
20
    number_frames : number of frames in the trajectory
21
    bin_width : the width of the histogram bit, default 30 degrees
22
    start : int, starting frame, will default to 0
23
    end : int, ending frame, will default to -1 (last frame in trajectory)
24
    step : int, spacing between frames, will default to 1
25

26
    Return
27
    ------
28
    A timeseries with integer labels describing the state at each point in time.
29

30
    """
NEW
31
    conformations = np.zeros(number_frames)
×
NEW
32
    phi = np.zeros(number_frames)
×
33

34
    # get the values of the angle for the dihedral
35
    # dihedral angle values have a range from -180 to 180
36
    for timestep in data_container.trajectory[start:end:step]:
×
37
        value = dihedral.value()
×
38
        # we want postive values in range 0 to 360 to make the peak assignment work
39
        # using the fact that dihedrals have circular symetry
40
        # (i.e. -15 degrees = +345 degrees)
41
        if value < 0:
×
42
            value += 360
×
43
        phi[timestep.frame] = value
×
44

45
    # create a histogram using numpy
NEW
46
    number_bins = int(360 / bin_width)
×
NEW
47
    popul, bin_edges = np.histogram(a=phi, bins=number_bins, range=(0, 360))
×
NEW
48
    bin_value = [0.5 * (bin_edges[i] + bin_edges[i + 1]) for i in range(0, len(popul))]
×
49

50
    # identify "convex turning-points" and populate a list of peaks
51
    # peak : a bin whose neighboring bins have smaller population
52
    # NOTE might have problems if the peak is wide with a flat or sawtooth top
53
    peak_values = []
×
54

55
    for bin_index in range(number_bins):
×
56
        # if there is no dihedrals in a bin then it cannot be a peak
57
        if popul[bin_index] == 0:
×
58
            pass
×
59
        # being careful of the last bin
60
        # (dihedrals have circular symmetry, the histogram does not)
NEW
61
        elif (
×
62
            bin_index == number_bins - 1
63
        ):  # the -1 is because the index starts with 0 not 1
NEW
64
            if (
×
65
                popul[bin_index] >= popul[bin_index - 1]
66
                and popul[bin_index] >= popul[0]
67
            ):
68
                peak_values.append(bin_value[bin_index])
×
69
        else:
NEW
70
            if (
×
71
                popul[bin_index] >= popul[bin_index - 1]
72
                and popul[bin_index] >= popul[bin_index + 1]
73
            ):
74
                peak_values.append(bin_value[bin_index])
×
75

76
    # go through each frame again and assign conformation state
77
    for frame in range(number_frames):
×
78
        # find the TP that the snapshot is least distant from
79
        distances = [abs(phi[frame] - peak) for peak in peak_values]
×
NEW
80
        conformations[frame] = np.argmin(distances)
×
81

82
    return conformations
×
83

84

85
# END assign_conformation
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