Skip to content

Commit

Permalink
fixed and renamed ""coords2dihedrals_inner.py"->"coords2projected_dih…
Browse files Browse the repository at this point in the history
…edrals.py"
  • Loading branch information
jewettaij committed Jan 25, 2021
1 parent 0405d74 commit 5595c4b
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 29 deletions.
6 changes: 3 additions & 3 deletions dlpdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from .closest_line_points import ClosestLinePoints
from .coords2angles import Coords2AnglesLengths, Coords2Angles
from .coords2dihedrals import Coords2DihedralsAnglesLengths, Coords2Dihedrals
from .coords2dihedrals_inner import Coords2DihedralsInnerLengths, Coords2DihedralsInner
from .coords2projected_dihedrals import Coords2ProjectedDihedralsLengths, Coords2ProjectedDihedrals
from .helixAngleOmega import CalcOmegaFromThetaPhi, CalcOmega

# I no longer remember why I import "main" from the executable scripts.
# Perhaps these next few lines are unnecessary, but they seem to do no harm:
from .coords2angles import main
from .coords2dihedrals_inner import main
from .coords2projected_dihedrals import main
from .coords2dihedrals import main
from .coords2distances import main
from .coords2helixAngleOmega import main
Expand Down Expand Up @@ -44,7 +44,7 @@

__all__ = ['closest_points',
'coords2angles',
'coords2dihedrals_inner',
'coords2projected_dihedrals',
'coords2dihedrals',
'coords2distances',
'coords2helixAngleOmega',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
"""
Typical Usage:
coords2dihedrals_inner.py 180 < 12column_text_file.dat
coords2dihedrals_projected.py 180 < 12column_text_file.dat
This script reads a 12-column numeric text file representing the positions
of 4 atoms. Then it calculates the "inner dihedral", which I define
of 4 atoms. Then it calculates the "projected dihedral", which I define
as the difference in direction between two infinitely long lines:
-The first line passes through the first two atoms,
-The other line (the "last line") passes through the last two atoms.
The "inner dihedral" angle can be thought of as the largest possible
The "projected dihedral" angle can be thought of as the largest possible
apparent angle between these two lines when viewed from all possible
viewing directions. A pair of points (one on each line) is determined
that are closest to each other. The "inner dihedral" angle is the angle
that are closest to each other. The "projected dihedral" angle is the angle
one sees when viewing these two lines from direction of the axis connecting
these two closest points. Note: If these two lines are parallel to each other
or if these 4 points are coplanar, the "inner" dihedral angle is undefined.
or if these 4 points are coplanar, the "projected" dihedral angle is undefined.
Example input file:
Expand All @@ -29,7 +29,7 @@
(This is the format of the files generated by the "pdb2coords.py" script.)
For each line containing 12 numbers, this script returns a tuple
containing 4 numbers:
-The "inner dihedral" angle for these 4 atoms (in degrees)
-The "projected dihedral" angle for these 4 atoms (in degrees)
-The distance from the first atom to the first closest point
(IE The point on the first line that is closest to the last line)
-The distance between the pair of points on each line that are closest
Expand Down Expand Up @@ -74,21 +74,29 @@



def Coords2DihedralsInnerLengths(r0, r1, r2, r3, branch_of_log=pi):
def Coords2ProjectedDihedralsLengths(r0, r1, r2, r3, branch_of_log=pi):
"""
Calculate the "inner" dihedral angle from the position of 4 atoms. I
Calculate the "projected" dihedral angle from the position of 4 atoms. I
define this as the difference in direction between two infinitely long lines
-The first line passes through the first two atoms (r0,r1).
-The other line (the "last line") passes through the last two atoms (r2,r3).
The "inner dihedral" angle can be thought of as the largest possible
The "projected dihedral" angle can be thought of as the largest possible
apparent angle between these two lines when viewed from all possible
viewing directions. A pair of points (one on each line) is determined
that are closest to each other. The "inner dihedral" angle is the angle
that are closest to each other. The "projected dihedral" angle is the angle
one sees when viewing these two lines from direction of the axis connecting
these two closest points. If these 4 points are coplanar, the
"inner" dihedral angle between them is undefined.
"projected" dihedral angle between them is undefined.
"""
R1, R2 = ClosestPoints(r0, r2, r10, r32)

r10 = [r1[0]-r0[0],
r1[1]-r0[1],
r1[2]-r0[2]]
r32 = [r3[0]-r2[0],
r3[1]-r2[1],
r3[2]-r2[2]]

R1, R2 = ClosestLinePoints(r0, r2, r10, r32)

phi,theta0,theta1,l10,l21,l32 = Coords2DihedralsAnglesLengths(r0,
R1,
Expand All @@ -101,8 +109,8 @@ def Coords2DihedralsInnerLengths(r0, r1, r2, r3, branch_of_log=pi):



def Coords2DihedralsInner(r0, r1, r2, r3, branch_of_log=pi):
phi,l01,l21,l32 = Coords2DihedralsInnerLengths(r0, r1, r2, r3)
def Coords2ProjectedDihedrals(r0, r1, r2, r3, branch_of_log=pi):
phi,l01,l21,l32 = Coords2ProjectedDihedralsLengths(r0, r1, r2, r3)
return phi


Expand Down Expand Up @@ -180,24 +188,19 @@ def main():
r3 = [coords_list[i][3*3+0],
coords_list[i][3*3+1],
coords_list[i][3*3+2]]
r10 = [r1[0]-r0[0],
r1[1]-r0[1],
r1[2]-r0[2]]
r32 = [r3[0]-r2[0],
r3[1]-r2[1],
r3[2]-r2[2]]

phi,l10,l21,l32 = Coords2ProjectedDihedralsLengths(r0, r1, r2, r3,
branch_of_log)

sys.stdout.write(str(phi*180.0/pi) + ' ' +
str(theta0*180.0/pi) + ' ' +
str(theta1*180.0/pi) + ' ' +
str(l10) + ' ' +
str(l21) + ' ' +
str(l32) +
'\n')
else:
# Otherwise, we write out an impossible values to let the caller
# know that this particular dihedral angle could not be computed
sys.stdout.write('-720 -360 -360 -1 -1 -1\n')
sys.stdout.write('-720 -1 -1 -1\n')


if __name__ == "__main__":
Expand Down
29 changes: 29 additions & 0 deletions dlpdb/scripts/extract_helix_projected_dihedrals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

BRANCH_OF_LOG="180.0"
if [ "$#" -eq 2 ]; then
BRANCH_OF_LOG="$1"
shift 1
fi
ATOM_SELECTION="$@"

if [ -z "${EXTRACTCOORDS}" ]
then
EXTRACTCOORDS="pdb2coords.py ${ATOM_SELECTION} -blank"
fi


while read pdb_file_name; do
#echo "pdb_file = \"${pdb_file_name}\""
echo "${0##*/} processing $pdb_file_name" >&2
pdb2helix.py < "$pdb_file_name" > helix_intervals_projected_dihedrals.tmp
while read interval; do
command="select_interval.py $interval < \"$pdb_file_name\" | ${EXTRACTCOORDS} | coords2projected_dihedrals.py $BRANCH_OF_LOG | tr \"\n\" \" \""
#echo "${command}"
eval "$command"
echo ""
done < helix_intervals_projected_dihedrals.tmp
done

rm -f helix_intervals_projected_dihedrals.tmp

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ while read pdb_file_name; do
echo "${0##*/} processing $pdb_file_name" >&2
print_coords_command="${EXTRACTCOORDS} ${ATOM_SELECTION} < $pdb_file_name"
#eval "$print_coords_command" | coords2dihedrals.py $BRANCH_OF_LOG
eval "$print_coords_command" | coords2dihedrals_inner.py $BRANCH_OF_LOG | awk '{print $1}' | tr "\n" " "
eval "$print_coords_command" | coords2projected_dihedrals.py $BRANCH_OF_LOG | awk '{print $1}' | tr "\n" " "
# You can pipe the results to sed -e 's/\s\+/\n/g' to put on separate lines
echo ""
done
Expand Down
29 changes: 29 additions & 0 deletions dlpdb/scripts/extract_sheet_projected_dihedrals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

BRANCH_OF_LOG="360.0"
if [ "$#" -eq 2 ]; then
BRANCH_OF_LOG="$1"
shift 1
fi
ATOM_SELECTION="$@"

if [ -z "${EXTRACTCOORDS}" ]
then
EXTRACTCOORDS="pdb2coords.py ${ATOM_SELECTION} -blank"
fi


while read pdb_file_name; do
#echo "pdb_file = \"${pdb_file_name}\""
echo "${0##*/} processing $pdb_file_name" >&2
pdb2sheet.py < "$pdb_file_name" > sheet_intervals_projected_dihedrals.tmp
while read interval; do
command="select_interval.py $interval < \"$pdb_file_name\" | ${EXTRACTCOORDS} | coords2projected_dihedrals.py $BRANCH_OF_LOG | tr \"\n\" \" \""
#echo "${command}"
eval "$command"
echo ""
done < sheet_intervals_projected_dihedrals.tmp
done

rm -f sheet_intervals_projected_dihedrals.tmp

29 changes: 29 additions & 0 deletions dlpdb/scripts/extract_turn_projected_dihedrals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

BRANCH_OF_LOG=""
if [ "$#" -eq 2 ]; then
BRANCH_OF_LOG="$1"
shift 1
fi
ATOM_SELECTION="$@"

if [ -z "${EXTRACTCOORDS}" ]
then
EXTRACTCOORDS="pdb2coords.py ${ATOM_SELECTION} -blank"
fi


while read pdb_file_name; do
#echo "pdb_file = \"${pdb_file_name}\""
echo "${0##*/} processing $pdb_file_name" >&2
pdb2turn.py < "$pdb_file_name" > turn_intervals_projected_dihedrals.tmp
while read interval; do
command="select_interval.py $interval < \"$pdb_file_name\" | ${EXTRACTCOORDS} | coords2projected_dihedrals.py $BRANCH_OF_LOG | tr \"\n\" \" \""
#echo "${command}"
eval "$command"
echo ""
done < turn_intervals_projected_dihedrals.tmp
done

rm -f turn_intervals_projected_dihedrals.tmp

54 changes: 54 additions & 0 deletions doc/extract_geometry/README_coords2projected_dihedrals.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Typical Usage:

coords2dihedrals.py 180 < 12column_text_file.dat

This script reads a 12-column numeric text file representing the positions
of 4 atoms. Then it calculates the "projected dihedral", which I define
as the difference in direction between two infinitely long lines:
-The first line passes through the first two atoms,
-The other line (the "last line") passes through the last two atoms.
The "projected dihedral" angle can be thought of as the largest possible
apparent angle between these two lines when viewed from all possible
viewing directions. A pair of points (one on each line) is determined
that are closest to each other. The "projected dihedral" angle is the angle
one sees when viewing these two lines from direction of the axis connecting
these two closest points. Note: If these two lines are parallel to each other
or if these 4 points are coplanar, the "projected" dihedral angle is undefined.

Example input file:

30.13 11.46 15.12 35.28 -2.32 12.61 30.68 -4.45 16.30 28.68 8.46 10.24
28.68 8.42 10.24 30.68 -4.45 16.30 25.22 -4.75 19.42 27.57 3.37 8.06
27.57 3.37 8.06 25.22 -4.75 19.42 20.45 -1.27 20.09 25.80 -2.26 6.61
25.80 -2.23 6.61 20.45 -1.27 20.09 15.47 1.36 18.12 21.67 -5.88 7.17
:
The 12 numbers on each line represent the x,y,z coordinates of 4 atoms.
(This is the format of the files generated by the "pdb2coords.py" script.)
For each line containing 12 numbers, this script returns a tuple
containing 4 numbers:
-The "projected dihedral" angle for these 4 atoms (in degrees)
-The distance from the first atom to the first closest point
(IE The point on the first line that is closest to the last line)
-The distance between the pair of points on each line that are closest
to each other,
-The distance from the last atom to the last closest point
(IE The point on the last line that is closest to the first line)
(When a line contains the wrong number of numbers,
the script prints out a list of 4 impossibe negative values:
"-720 -1 -1 -1" to let the caller know that
this particular angle could not be computed.)

Note:
The "IUPAC/IUB" dihedral-angle convention is used:
4 atoms in the "trans" conformation have a dihedral angle of 180 degrees.
By default, dihedral angles are calculated in the range from 0 to 360.0 degrees.
(This means there is discontinuity in the angle at 0 degrees.)
However this may be a bad choice for polymers which can alternate between
helical conformations which are left and right handed.
In some cases, you may want to have the discontinuity appear at 180 degrees.
(or some other angle which is sparsely populated).

So you can supply an optional argument (the "branch_of_log") which indicates
where the discontinuity in the dihedral angle will appear.
Dihedral angles returned by this program will lie in the range:
[branch_of_log-360, branch_of_log)
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@

scripts=['dlpdb/scripts/extract_angles.sh',
'dlpdb/scripts/extract_dihedrals.sh',
'dlpdb/scripts/extract_dihedrals_inner.sh',
'dlpdb/scripts/extract_projected_dihedrals.sh',
'dlpdb/scripts/extract_distances.sh',
'dlpdb/scripts/extract_helix_angles.sh',
'dlpdb/scripts/extract_helix_dihedrals.sh',
'dlpdb/scripts/extract_helix_projected_dihedrals.sh',
'dlpdb/scripts/extract_helix_distances.sh',
'dlpdb/scripts/extract_helix_resAveDistances.sh',
'dlpdb/scripts/extract_resAveDistances.sh',
'dlpdb/scripts/extract_sheet_angles.sh',
'dlpdb/scripts/extract_sheet_dihedrals.sh',
'dlpdb/scripts/extract_sheet_projected_dihedrals.sh',
'dlpdb/scripts/extract_sheet_distances.sh',
'dlpdb/scripts/extract_sheet_resAveDistances.sh',
'dlpdb/scripts/extract_turn_angles.sh',
'dlpdb/scripts/extract_turn_dihedrals.sh',
'dlpdb/scripts/extract_turn_projected_dihedrals.sh',
'dlpdb/scripts/extract_turn_distances.sh',
'dlpdb/scripts/extract_turn_resAveDistances.sh',
'dlpdb/scripts/move_membrane_proteins.sh',
Expand All @@ -60,7 +63,7 @@
entry_points={
'console_scripts': ['coords2angles.py=dlpdb.coords2angles:main',
'coords2dihedrals.py=dlpdb.coords2dihedrals:main',
'coords2dihedrals_inner.py=dlpdb.coords2dihedrals_inner:main',
'coords2projected_dihedrals.py=dlpdb.coords2projected_dihedrals:main',
'coords2distances.py=dlpdb.coords2distances:main',
'coords2helixAngleOmega.py=dlpdb.coords2helixAngleOmega:main',
'dlpisces.py=dlpdb.dlpisces:main',
Expand Down

0 comments on commit 5595c4b

Please sign in to comment.