-
Notifications
You must be signed in to change notification settings - Fork 8
/
getPDB.sh
executable file
·83 lines (72 loc) · 1.87 KB
/
getPDB.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
get_curl() {
# get_curl will download a PDB file with the 4-letter code given as the only
# argument using 'curl' (for when wget is unavailable)
if [ $# -ne 1 ]; then
echo "Bad usage: get_curl <PDB ID>"
exit 1
fi
pdbcode=`python -c "print('$1'.lower())"`
mid=`python -c "print(\"$pdbcode\"[1:3])"`
url=ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/pdb/$mid/pdb$pdbcode.ent.gz
curl $url > $1.pdb.gz
retcode=$?
if [ $retcode -eq 78 ]; then
echo "Could not find PDB $1!"
exit 1
elif [ $retcode -ne 0 ]; then
echo "Unknown error in downloading PDB $1!"
exit 1
else
gunzip $1.pdb.gz
fi
}
get_wget() {
# get_wget will use wget to download a PDB file specified by the 4-letter
# code
if [ $# -ne 1 ]; then
echo "Bad usage: wget <PDB ID>"
exit 1
fi
pdbcode=`python -c "print('$1'.lower())"`
mid=`python -c "print('$pdbcode'[1:3])"`
url=ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/pdb/$mid/pdb$pdbcode.ent.gz
wget $url
retcode=$?
if [ $retcode -eq 8 ]; then
echo "Could not find PDB $1!"
exit 1
elif [ $retcode -ne 0 ]; then
echo "Unknown error in downloading PDB $1!"
exit 1
else
gunzip pdb$pdbcode.ent.gz && mv pdb$pdbcode.ent $1.pdb
fi
}
usage() {
echo "`basename $0` <PDB ID> [<PDB ID> [<PDB ID> [...]]]"
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
wget_="F"
curl_="F"
# See if we have wget and/or curl
(which wget 2>&1) > /dev/null
test $? -eq 0 && wget_="T"
(which curl 2>&1) > /dev/null
test $? -eq 0 && curl_="T"
if [ "$wget_" = "F" -a "$curl_" = "F" ]; then
echo "You must have either 'curl' or 'wget' to download PDBs!"
exit 1
fi
# Now go through all arguments and download them all
while [ $# -gt 0 ]; do
if [ "$wget_" = "T" ]; then
get_wget $1
else
get_curl $1
fi
shift
done