From 5595c4b8299ba5f7a1e06d03dec99591da8dc7c4 Mon Sep 17 00:00:00 2001 From: Andrew Jewett Date: Mon, 25 Jan 2021 03:01:02 -0800 Subject: [PATCH] fixed and renamed ""coords2dihedrals_inner.py"->"coords2projected_dihedrals.py" --- dlpdb/__init__.py | 6 +-- ...inner.py => coords2projected_dihedrals.py} | 49 +++++++++-------- .../extract_helix_projected_dihedrals.sh | 29 ++++++++++ ...nner.sh => extract_projected_dihedrals.sh} | 2 +- .../extract_sheet_projected_dihedrals.sh | 29 ++++++++++ .../extract_turn_projected_dihedrals.sh | 29 ++++++++++ .../README_coords2projected_dihedrals.txt | 54 +++++++++++++++++++ setup.py | 7 ++- 8 files changed, 176 insertions(+), 29 deletions(-) rename dlpdb/{coords2dihedrals_inner.py => coords2projected_dihedrals.py} (85%) create mode 100755 dlpdb/scripts/extract_helix_projected_dihedrals.sh rename dlpdb/scripts/{extract_dihedrals_inner.sh => extract_projected_dihedrals.sh} (82%) create mode 100755 dlpdb/scripts/extract_sheet_projected_dihedrals.sh create mode 100755 dlpdb/scripts/extract_turn_projected_dihedrals.sh create mode 100644 doc/extract_geometry/README_coords2projected_dihedrals.txt diff --git a/dlpdb/__init__.py b/dlpdb/__init__.py index 7ecac41..829e596 100644 --- a/dlpdb/__init__.py +++ b/dlpdb/__init__.py @@ -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 @@ -44,7 +44,7 @@ __all__ = ['closest_points', 'coords2angles', - 'coords2dihedrals_inner', + 'coords2projected_dihedrals', 'coords2dihedrals', 'coords2distances', 'coords2helixAngleOmega', diff --git a/dlpdb/coords2dihedrals_inner.py b/dlpdb/coords2projected_dihedrals.py similarity index 85% rename from dlpdb/coords2dihedrals_inner.py rename to dlpdb/coords2projected_dihedrals.py index 4771554..195ceb9 100755 --- a/dlpdb/coords2dihedrals_inner.py +++ b/dlpdb/coords2projected_dihedrals.py @@ -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: @@ -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 @@ -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, @@ -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 @@ -180,16 +188,11 @@ 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) + @@ -197,7 +200,7 @@ def main(): 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__": diff --git a/dlpdb/scripts/extract_helix_projected_dihedrals.sh b/dlpdb/scripts/extract_helix_projected_dihedrals.sh new file mode 100755 index 0000000..133ca3e --- /dev/null +++ b/dlpdb/scripts/extract_helix_projected_dihedrals.sh @@ -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 + diff --git a/dlpdb/scripts/extract_dihedrals_inner.sh b/dlpdb/scripts/extract_projected_dihedrals.sh similarity index 82% rename from dlpdb/scripts/extract_dihedrals_inner.sh rename to dlpdb/scripts/extract_projected_dihedrals.sh index ada1b63..f34cd48 100755 --- a/dlpdb/scripts/extract_dihedrals_inner.sh +++ b/dlpdb/scripts/extract_projected_dihedrals.sh @@ -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 diff --git a/dlpdb/scripts/extract_sheet_projected_dihedrals.sh b/dlpdb/scripts/extract_sheet_projected_dihedrals.sh new file mode 100755 index 0000000..63ff5ac --- /dev/null +++ b/dlpdb/scripts/extract_sheet_projected_dihedrals.sh @@ -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 + diff --git a/dlpdb/scripts/extract_turn_projected_dihedrals.sh b/dlpdb/scripts/extract_turn_projected_dihedrals.sh new file mode 100755 index 0000000..771f0b1 --- /dev/null +++ b/dlpdb/scripts/extract_turn_projected_dihedrals.sh @@ -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 + diff --git a/doc/extract_geometry/README_coords2projected_dihedrals.txt b/doc/extract_geometry/README_coords2projected_dihedrals.txt new file mode 100644 index 0000000..95000c6 --- /dev/null +++ b/doc/extract_geometry/README_coords2projected_dihedrals.txt @@ -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) diff --git a/setup.py b/setup.py index c2987d0..6e5362e 100644 --- a/setup.py +++ b/setup.py @@ -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', @@ -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',