My software notes

August 7, 2007

calculate proton-proton distances in a PDB

Filed under: softwares and scripts — kpwu @ 12:00 pm

Few months ago, I posted a blog article that I try to use MOLMOL + shell script to get the distance table I want. However, I always forgot how to use the syntax of MOLMOL, therefore, I wrote a shell script to carry out this purpose.

The shell script can calculate any distances between an assigned proton (e.g HB) and other protons, then gives you an output. The output is sorting by the distances or the residue numbers.

The current script DOES NOT deal with the multiple-chain PDB.

Here are the outputs (using 2GB1.pdb as an example):
1. sorting by distance:
~:>./cal-HH-distance.sh 2GB1.pdb 34 HA 3.6 yes
Res_atom <—> Res AA ATOM DIST
=================================
34-ALA-HA <—> 34 ALA 3HB 2.25
34-ALA-HA <—> 33 TYR HD1 2.48
34-ALA-HA <—> 34 ALA H 2.78
34-ALA-HA <—> 37 ASN 1HB 2.79
34-ALA-HA <—> 34 ALA 2HB 2.80
34-ALA-HA <—> 34 ALA 1HB 2.91
34-ALA-HA <—> 37 ASN 2HD2 2.95
34-ALA-HA <—> 7 LEU 2HD2 3.21
34-ALA-HA <—> 7 LEU 3HD2 3.30
34-ALA-HA <—> 39 VAL HB 3.31
34-ALA-HA <—> 35 ASN H 3.53
2. sorting by residues:
~:>./cal-HH-distance.sh 2GB1.pdb 34 HA 3.6 no
Res_atom <—> Res AA ATOM DIST
=================================
34-ALA-HA    <—>      7   LEU  2HD2    3.21
34-ALA-HA    <—>      7   LEU  3HD2    3.30
34-ALA-HA    <—>     33   TYR   HD1    2.48
34-ALA-HA    <—>     34   ALA     H    2.78
34-ALA-HA    <—>     34   ALA   1HB    2.91
34-ALA-HA    <—>     34   ALA   2HB    2.80
34-ALA-HA    <—>     34   ALA   3HB    2.25
34-ALA-HA    <—>     35   ASN     H    3.53
34-ALA-HA    <—>     37   ASN   1HB    2.79
34-ALA-HA    <—>     37   ASN  2HD2    2.95
34-ALA-HA    <—>     39   VAL    HB    3.31

Here is the shell script. If this script is helpful to you, please give me a response. Thanks.
Any comments are also welcome.

#!/bin/sh
## A program to calculate the distance of an assigned atom
## and other intramolecular atoms
## see USAGE to know how to run it
## USAGE : ./this_script [PDB] [residue_number] [proton_name] [cutoff] [yes|no]
## e.g. ./cal-HH-distance.sh 2GB1.pdb 53 H 6 no
## this will calculate all distances for resdiesu_53_NH
## and other atoms of 2GB1.pdb
## distances within 6 Ang will be output and sort by the distance
##
## VERSON 0.3 Aug. 7th, 2007
## Kuen-Phon Wu
## See update: https://kpwu.wordpress.com/

usage=”Usage: cal-HH-distance.sh [inputfile] [res_number] [proton] [cutoff] [yes|no]”
eg=”Example: ./cal-HH-distance.sh 2GB1.pdb 53 HA 6.0 yes”

if [ $# -lt 5 ] ; then
echo “$usage”
echo “$eg”
exit 1
fi

FILE=”$1″
RES=”$2″
ATOM=”$3″
cutoff=$4

## find x, y, z coordinate of the assigned atom
x=`cat $1 |grep ” $2 ” |grep “$3 ” |awk ‘/^ATOM/{print $7}’`
y=`cat $1 |grep ” $2 ” |grep “$3 ” |awk ‘/^ATOM/{print $8}’`
z=`cat $1 |grep ” $2 ” |grep “$3 ” |awk ‘/^ATOM/{print $9}’`
Res_type=`cat $1 |grep ” $2 ” |grep “$3 ” |awk ‘/^ATOM/{print $4}’`

## caluclate all distances related to the assigned atom
## filter out non H,HB,HD,HG atoms by grep
cat $1 |grep -v ” O.” | grep -v “C[ .A-Z]” |grep -v ” N ” | \
awk ‘/^ATOM/{printf “%5s%6s%6s%8.2f\n”, \
$6,$4,$3,sqrt((x1-$7)^2+(y1-$8)^2+(z1-$9)^2)}’\
x1=$x y1=$y z1=$z >_temp1

## post-editing do sorting or not sorting, control by case
##
echo “Res_atom <—> Res AA ATOM DIST”
echo “=============================================”
case “$5” in
yes)
cat _temp1 |sort -k 4 |awk ‘$4 < cut {printf “%s-%s-%s <—> %s\n”,res,aa,atom,$0;}’ \
aa=$Res_type cut=$cutoff res=$RES atom=$ATOM |grep -v 0.00

;;
no)
cat _temp1 |awk ‘$4 < cut {printf “%s-%s-%s <—> %s\n”,res,aa,atom,$0;}’ \
aa=$Res_type cut=$cutoff res=$RES atom=$ATOM |grep -v 0.00

;;
*) echo “$usage”
exit 0
;;
esac
rm -f _temp*

Advertisements

5 Comments »

  1. Actually the molecular modeling program I’m using “CNS” (as well as the very similar program XPLOR, afaik) can do the same thing with just one command (after reading in the structure).

    Reading in the structure requires 3 more commands – supposing you have a pdb file that complies with the parameter and topology files used by CNS. After that you can write things like:

    distance
    from=(chemical H*) to=(chemical H*) cuton=0.6 cutoff=6
    end

    which in this case will calculate and print all distances between hydrogen atoms (==atoms whose name starts with H) that are more than 0.6A but less than 6A apart (which are roughly the distances which can produce cross-peaks in NOESY type spectra – actually 1.8A-5A, but lets be generous with the boundaries here).

    The biggest problem here might be to have pdb names that fit names used by the parameter-files you read in – it is not a problem, if the file was generated by CNS, though. I would think other MM programs might have a similar function.

    Cheers,
    I.

    Comment by Iridos — January 26, 2009 @ 6:46 pm | Reply

  2. Dear Kpwu

    I tried to run your script on opensuse

    first I save the your script as cal-HH-distance.sh .

    I gave the executable permissions by command ( chmod +x cal-HH-distance.sh)

    after checking command ./cal-HH-distance.sh

    I am getting error as follows

    line 15 : no command not found

    could you please suggest needful to overcome it if possible

    Thanking you

    Comment by srini2201 — April 26, 2013 @ 2:09 am | Reply

  3. you don’t make the script executable. simply using chmod 777 or 711 should solve your problem

    Comment by kpwu — April 26, 2013 @ 1:48 pm | Reply

    • Thanks for your reply ! but problem not resolved as per instructions !

      However Molmol seems to be other option for my problem ! Thanking for your HELP !

      Comment by sri2201 — April 26, 2013 @ 3:16 pm | Reply

  4. Refuel Extreme

    calculate proton-proton distances in a PDB | My software notes

    Trackback by Refuel Extreme — October 27, 2014 @ 5:20 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: