1 38
import logging
2

3 38
from paprika.restraints.utils import get_restraint_values, parse_window
4

5 38
logger = logging.getLogger(__name__)
6

7

8 38
def amber_restraint_line(restraint, window):
9
    """Writes an `AMBER` NMR-style restraint line for a specific window.
10

11
    Parameters
12
    ----------
13
    restraint: :class:`paprika.restraints.DAT_restraint`
14
        The pAPRika restraint to be used.
15
    window: str
16
        The calculation window that will be used to index the restraint values.
17

18
    Returns
19
    -------
20
    string: str
21
        A string that can be written to a file that can be read by AMBER.
22

23
    Examples
24
    --------
25
    .. code-block::
26

27
        &rst iat= 3,109, r1= 0.0000, r2= 6.9665, r3= 6.9665, r4= 999.0000,
28
             rk2= 5.0000000, rk3= 5.0000000, &end
29
    Or:
30

31
    .. code-block::
32

33
        &rst iat= -1,-1, igr1=3,4,7,8,21,22,25,26,39,40,43,44,57,58,61,62,75,76,79,
34
        80,93,94,97,98, igr2=109,113,115,119,
35
        r1=     0.0000, r2=     5.9665, r3=     5.9665, r4=   999.0000,
36
        rk2=   5.0000000, rk3=   5.0000000, &end
37
    """
38

39 38
    window, phase = parse_window(window)
40 38
    if (
41
        restraint.phase[phase]["force_constants"] is None
42
        and restraint.phase[phase]["targets"] is None
43
    ):
44 0
        return ""
45

46 38
    if not restraint.group1:
47 38
        iat1 = "{},".format(restraint.index1[0])
48
    else:
49 0
        iat1 = "-1,"
50 0
        igr1 = ""
51 0
        for index in restraint.index1:
52 0
            igr1 += "{},".format(index)
53

54 38
    if not restraint.group2:
55 38
        iat2 = "{},".format(restraint.index2[0])
56
    else:
57 0
        iat2 = "-1,"
58 0
        igr2 = ""
59 0
        for index in restraint.index2:
60 0
            igr2 += "{},".format(index)
61

62 38
    iat3 = ""
63 38
    if restraint.index3 and not restraint.group3:
64 0
        iat3 = "{},".format(restraint.index3[0])
65 38
    elif restraint.group3:
66 0
        iat3 = "-1,"
67 0
        igr3 = ""
68 0
        for index in restraint.index3:
69 0
            igr3 += "{},".format(index)
70

71 38
    iat4 = ""
72 38
    if restraint.index4 and not restraint.group4:
73 0
        iat4 = "{},".format(restraint.index4[0])
74 38
    elif restraint.group4:
75 0
        iat4 = "-1,"
76 0
        igr4 = ""
77 0
        for index in restraint.index4:
78 0
            igr4 += "{},".format(index)
79

80
    # Restraint values - Amber NMR-style
81 38
    amber_restraint_values = get_restraint_values(restraint, phase, window)
82

83
    # Prepare AMBER NMR-style restraint
84 38
    atoms = "".join([iat1, iat2, iat3, iat4])
85 38
    string = "&rst iat= {:16s} ".format(atoms)
86 38
    string += (
87
        " r1= {0:10.5f},".format(amber_restraint_values["r1"])
88
        + " r2= {0:10.5f},".format(amber_restraint_values["r2"])
89
        + " r3= {0:10.5f},".format(amber_restraint_values["r3"])
90
        + " r4= {0:10.5f},".format(amber_restraint_values["r4"])
91
        + " rk2= {0:10.5f},".format(amber_restraint_values["rk2"])
92
        + " rk3= {0:10.5f},".format(amber_restraint_values["rk3"])
93
    )
94

95 38
    if any([restraint.group1, restraint.group2, restraint.group3, restraint.group4]):
96 0
        string += "\n    "
97 0
        if restraint.group1:
98 0
            string += " igr1= {}".format(igr1)
99 0
        if restraint.group2:
100 0
            string += " igr2= {}".format(igr2)
101 0
        if restraint.group3:
102 0
            string += " igr3= {}".format(igr3)
103 0
        if restraint.group4:
104 0
            string += " igr4= {}".format(igr4)
105

106 38
    string += "  &end\n"
107

108 38
    return string

Read our documentation on viewing source code .

Loading