Created
November 10, 2022 23:46
-
-
Save UnixJunkie/015f53febb985c99e9e605be611ad4a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# extract ligand lines from given PDB_CHAIN_LIG triplet | |
# e.g. 1yom_A_P01 | |
import os, sys | |
#"HETATM 4172 CL1 P01 A 1 8.995 -11.569 -2.901 1.00 52.76" | |
# 0 17 21 | |
pdb_chain_lig = sys.argv[1] | |
tokens = pdb_chain_lig.split('_') | |
pdb_base_fn = tokens[0] | |
pdb_fn = pdb_base_fn + ".pdb" | |
chain_letter = tokens[1] | |
lig_res = tokens[2] | |
# debug | |
print(pdb_base_fn) | |
print(chain_letter) | |
print(lig_res) | |
# D/L the PDB file | |
os.system('wget https://files.rcsb.org/download/%s.pdb' % pdb_base_fn) | |
with open(pdb_fn, 'r') as input: | |
lig_fn = pdb_base_fn + "_lig.pdb" | |
with open(lig_fn, 'w') as output: | |
for line in input.readlines(): | |
if (line[0:6] == "HETATM" and line[21:22] == chain_letter and | |
line[17:20] == lig_res): | |
print("%s" % line, file=output, end='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment