1 4
import logging
2

3 4
import numpy as np
4 4
from paprika.utils import override_dict
5

6 4
logger = logging.getLogger(__name__)
7

8 4
_PI_ = np.pi
9

10

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

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

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

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

38 4
    return window, phase
39

40

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

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

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

61
    """
62 4
    lower_bound = 0.0
63 4
    upper_bound = 999.0
64

65 4
    if restraint.mask3 and not restraint.mask4:
66 0
        upper_bound = 180.0
67

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

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

81 4
    override_dict(restraint_values, restraint.custom_restraint_values)
82

83 4
    return restraint_values
84

85

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

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

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

105
    """
106

107 4
    bias_type = None
108

109 4
    amber_restraint_values = get_restraint_values(restraint, phase, window)
110

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

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

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

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

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

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

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

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

159 4
    return bias_type

Read our documentation on viewing source code .

Loading