1"""
2    Chi extension
3
4    Print the backbone chi angle for each residue in the structure.
5    Chi angle is determined by the coordinates of the N, CA, CB (if
6    available), and CG/OG/SG atoms (if available).
7
8    Author:  Todd Dolinsky
9"""
10
11__date__ = "17 February 2006"
12__author__ = "Todd Dolinsky"
13
14from src.utilities import getDihedral
15
16def usage():
17    return 'Print the per-residue backbone chi angle to {output-path}.chi'
18
19def run_extension(routines, outroot, options):
20    """
21        Print the list of psi angles
22
23        Parameters
24            routines:  A link to the routines object
25            outroot:   The root of the output name
26            options:   options object
27    """
28
29    outname = outroot + ".chi"
30    outfile = open(outname, "w")
31
32    routines.write("\nPrinting chi angles for each residue...\n")
33    routines.write("Residue     chi\n")
34    routines.write("----------------\n")
35
36    # Initialize some variables
37
38    protein = routines.protein
39
40    for residue in protein.getResidues():
41        if residue.hasAtom("N"):
42            ncoords = residue.getAtom("N").getCoords()
43        else:
44            continue
45
46        if residue.hasAtom("CA"):
47            cacoords = residue.getAtom("CA").getCoords()
48        else:
49            continue
50
51        if residue.hasAtom("CB"):
52            cbcoords = residue.getAtom("CB").getCoords()
53        else:
54            continue
55
56        if residue.hasAtom("CG"):
57            gcoords = residue.getAtom("CG").getCoords()
58        elif residue.hasAtom("OG"):
59            gcoords = residue.getAtom("OG").getCoords()
60        elif residue.hasAtom("SG"):
61            gcoords = residue.getAtom("SG").getCoords()
62        else:
63            continue
64
65        chi = getDihedral(ncoords, cacoords, cbcoords, gcoords)
66        routines.write("%s\t%.4f\n" % (residue, chi))
67        outfile.write("%s\t%.4f\n" % (residue, chi))
68
69    routines.write("\n")
70    outfile.close()
71