Skip to content

Instantly share code, notes, and snippets.

@bougui505
Last active August 31, 2017 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bougui505/c177ad704da5b84b97bd89bd67a9caa7 to your computer and use it in GitHub Desktop.
Save bougui505/c177ad704da5b84b97bd89bd67a9caa7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# -*- coding: UTF8 -*-
# Author: Guillaume Bouvier -- guillaume.bouvier@pasteur.fr
# https://research.pasteur.fr/en/member/guillaume-bouvier/
# 2017-04-20 16:05:00 (UTC+0200)
usage ()
{
echo "Usage"
echo "$0 'selection' pdbfile.pdb"
echo "Selection string can be:"
echo " • residues: renumber the resids of the pdb"
echo " • atoms: renumber the atom numbers"
exit
}
if [ $# -ne 2 ]; then
usage
fi
SELECTION=$1
PDB=$2
awk -v SELECTION="$SELECTION" '
function printpdb(selection){
if (selection=="atoms"){
atomid+=1
printf("%-6s%5s%1s%4s%1s%3s%1s%1s%4s%1s%3s%8s%8s%8s%6s%6s%6s%4s\n", $1,atomid,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18)
}
if (selection=="residues"){
if ($9 != resid_prev){
resid+=1
resid_prev = $9
}
printf("%-6s%5s%1s%4s%1s%3s%1s%1s%4s%1s%3s%8s%8s%8s%6s%6s%6s%4s\n", $1,$2,$3,$4,$5,$6,$7,$8,resid,$10,$11,$12,$13,$14,$15,$16,$17,$18)
}
}
BEGIN{
FIELDWIDTHS = "6 5 1 4 1 3 1 1 4 1 3 8 8 8 6 6 6 4"
# $2: Atom serial number
# $4: Atom type
# $5: altLoc; alternate location indicator.
# $6: Resname
# $8: ChainID
# $9: Resid
# $12: x
# $13: y
# $14: z
atomid=0
resid=0
resid_prev=0
}
{
printpdb(SELECTION)
}' "$PDB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment