Skip to content

Commit

Permalink
Scripts to generate template coords, fix pdb4amber
Browse files Browse the repository at this point in the history
Add two scripts used in RESISTOR for the star-protocol.

- gen-templ-coords.sh is for generating template coordinates.
- p4a-undo.py is for fixing the numbering and chain ID of a structure
  after pdb4amber has "fixed" deficiencies.
  • Loading branch information
gusennan committed Nov 25, 2022
1 parent 5f0931d commit 2d74cd7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/julia/resistor/gen-templ-coords.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Generates template coordinates from a PDB file's atom records.
# Can be used to generate template coordinates for, e.g., a small molecule ligand.
#
# ./gen-templ-coords.sh sch7.pdb 38Z
# (script) (structure) (residue ID in structure)

if [[ $# -ne 2 ]]; then
echo "Expecting 2 parameters: <structure-file> and <residue ID>" >&2
exit 1
fi

echo $2 $(wc --lines < $1)
tr --squeeze-repeats ' ' < $1 | cut --delimiter=' ' --fields=3,7,8,9
38 changes: 38 additions & 0 deletions src/main/julia/resistor/p4a-undo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys

# This script "fixes" residue numbers and chain IDs after using Ambertool's
# pdb4amber program to ensure an input structure PDB file can be used with
# ambertools. One of the things pdb4amber does is change all residue numbering
# to start at 1, and gives every chain the same chain ID. This script undoes
# those two changes.

# python p4a-undo.py structure.pdb renumfile.txt

def main(args):
if len(args) != 2:
print('expected two arguments: <pdb file> <renum file>', file=sys.stderr)
exit(1)

with open(args[1]) as renum_lines:
renum_dict = {
line.split()[4] : (line.split()[2], line.split()[1])
for line in renum_lines
}

with open(args[0]) as pdb_lines:
for line in pdb_lines:
if not line.strip():
continue
if line[:4] != 'ATOM' and line[:4] != 'HETA' and line[:3] != 'TER':
print(line, end='')
continue

res_name = line[17:20].strip()
res_num = line[22:26].strip()
old_num = renum_dict[res_num][0].rjust(4)
chain = renum_dict[res_num][1]
print(f'{line[:21]}{chain}{old_num}{line[26:]}'.strip())

if __name__ == '__main__':
main(sys.argv[1:])

0 comments on commit 2d74cd7

Please sign in to comment.