1 2
import logging
2

3 2
import numpy as np
4

5 2
from paprika.utils import override_dict
6

7 2
logger = logging.getLogger(__name__)
8

9 2
_PI_ = np.pi
10

11

12 2
def parse_window(window):
13
    """
14
    Utility function to use a path to index a :class:`paprika.restraints.DAT_restraint` instance.
15

16
    Parameters
17
    ----------
18
    window : str
19
        A string representation of a particular simulation window
20

21
    Returns
22
    -------
23
    window : int
24
        The window number
25
    phase : str
26
        The calculation phase
27

28
    """
29 2
    if window[0] == "a":
30 2
        phase = "attach"
31 2
    elif window[0] == "p":
32 2
        phase = "pull"
33 0
    elif window[0] == "r":
34 0
        phase = "release"
35
    else:
36 0
        raise Exception("Cannot determine the phase for this restraint.")
37 2
    window = int(window[1:])
38

39 2
    return window, phase
40

41

42 2
def get_restraint_values(restraint, phase, window):
43
    """
44
    Extract the values of the restraints (Amber NMR-style) including positions
45
    and force constants. See the Amber documentation for further explanation
46
    on the NMR-style values.
47

48
    Parameters
49
    ----------
50
    restraint: DAT_restraint()
51
        Restraint object to extract the information from
52
    phase: str
53
        Current phase of APR calculation
54
    window: int
55
        Current window number
56

57
    Return
58
    ------
59
    restraint_values: dict
60
        Dictionary containing the Amber NMR-style values
61

62
    """
63 2
    lower_bound = 0.0
64 2
    upper_bound = 999.0
65

66 2
    if restraint.mask3 and not restraint.mask4:
67 0
        upper_bound = 180.0
68

69 2
    if restraint.mask3 and restraint.mask4:
70 0
        lower_bound = restraint.phase[phase]["targets"][window] - 180.0
71 0
        upper_bound = restraint.phase[phase]["targets"][window] + 180.0
72

73 2
    restraint_values = {
74
        "r1": lower_bound,
75
        "r2": restraint.phase[phase]["targets"][window],
76
        "r3": restraint.phase[phase]["targets"][window],
77
        "r4": upper_bound,
78
        "rk2": restraint.phase[phase]["force_constants"][window],
79
        "rk3": restraint.phase[phase]["force_constants"][window],
80
    }
81

82 2
    override_dict(restraint_values, restraint.custom_restraint_values)
83

84 2
    return restraint_values
85

86

87 2
def get_bias_potential_type(restraint, phase, window):
88
    """
89
    Function to determine the bias potential type for a particular restraint.
90
    The possible types of biases are: "restraint", "upper_walls" and "lower_walls"
91

92
    Parameters
93
    ----------
94
    restraint: DAT_restraints
95
        restraints to extract information from
96
    phase: str
97
        current phase of the window
98
    window: int
99
        window number
100

101
    Returns
102
    -------
103
    bias_type: str
104
        type of bias potential
105

106
    """
107

108 2
    bias_type = None
109

110 2
    amber_restraint_values = get_restraint_values(restraint, phase, window)
111

112 2
    if (
113
        amber_restraint_values["r2"] == amber_restraint_values["r3"]
114
        and amber_restraint_values["rk2"] == amber_restraint_values["rk3"]
115
    ):
116 2
        bias_type = "restraint"
117

118 2
    elif (
119
        amber_restraint_values["r2"] < amber_restraint_values["r3"]
120
        or amber_restraint_values["r2"] == 0.0
121
    ) and amber_restraint_values["rk2"] == amber_restraint_values["rk3"]:
122 2
        bias_type = "upper_walls"
123

124 2
    elif amber_restraint_values["r2"] == amber_restraint_values["r3"] and (
125
        amber_restraint_values["rk2"] < amber_restraint_values["rk3"]
126
        or amber_restraint_values["rk2"] == 0.0
127
    ):
128 2
        bias_type = "upper_walls"
129

130 2
    elif (
131
        amber_restraint_values["r2"] < amber_restraint_values["r3"]
132
        or amber_restraint_values["r2"] == 0.0
133
    ) and (
134
        amber_restraint_values["rk2"] <= amber_restraint_values["rk3"]
135
        or amber_restraint_values["rk2"] == 0.0
136
    ):
137 2
        bias_type = "upper_walls"
138

139 2
    elif (
140
        amber_restraint_values["r2"] > amber_restraint_values["r3"]
141
        or amber_restraint_values["r3"] == 0.0
142
    ) and amber_restraint_values["rk2"] == amber_restraint_values["rk3"]:
143 2
        bias_type = "lower_walls"
144

145 2
    elif amber_restraint_values["r2"] == amber_restraint_values["r3"] and (
146
        amber_restraint_values["rk2"] > amber_restraint_values["rk3"]
147
        or amber_restraint_values["rk3"] == 0.0
148
    ):
149 2
        bias_type = "lower_walls"
150

151 2
    elif (amber_restraint_values["r2"] < amber_restraint_values["r3"]) and (
152
        amber_restraint_values["rk2"] > amber_restraint_values["rk3"]
153
        or amber_restraint_values["rk3"] == 0.0
154
    ):
155 2
        bias_type = "lower_walls"
156

157 2
    if bias_type is None:
158 0
        raise Exception("Could not determine bias potential type from restraint.")
159

160 2
    return bias_type

Read our documentation on viewing source code .

Loading