-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsilentsketchparamsfrompdbs
More file actions
executable file
·97 lines (70 loc) · 2.6 KB
/
Copy pathsilentsketchparamsfrompdbs
File metadata and controls
executable file
·97 lines (70 loc) · 2.6 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
import os
import sys
# if you pip installed this is wrong but you have silent_tools installed anyways
silent_tools_dir = os.path.dirname(os.path.realpath(__file__))
if silent_tools_dir not in sys.path:
sys.path.append(silent_tools_dir)
import silent_tools
from silent_tools import eprint
import stat
import math
import shutil
import io
from Bio.PDB import MMCIFParser, PDBIO
# Don't throw an error when someone uses head
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
pdb_buffers = []
if ( stat.S_ISFIFO(os.stat("/dev/stdin").st_mode) ):
pdb_buffers += sys.stdin.readlines()
pdb_buffers += sys.argv[1:]
if (len(pdb_buffers) == 0):
eprint("")
eprint('silentsketchparamsfrompdbs by bcov - generates really sketchy params files for pdbs WITHOUT rosetta')
eprint("Usage:")
eprint(" cat list_of_pdbs.list | silentsketchparamsfrompdbs")
eprint(" or")
eprint(" silentsketchparamsfrompdbs 1.pdb 2.pdb 3.pdb ")
sys.exit(1)
pdbs = []
for line in pdb_buffers:
line = line.strip()
if (len(line) == 0):
continue
sp = line.split(" ")
for pdb in sp:
pdbs.append(pdb)
pre_tags = [os.path.basename(pdbs) for pdbs in pdbs]
if (len(pdbs) != len(set(pdbs))):
eprint("silentsketchparamsfrompdbs: Warning: %i duplicate paths specified"%(len(pdbs) - len(set(pdbs))))
written_params = {}
to_print = []
first = True
for pdb in pdbs:
try:
pdb_lines = open(pdb).readlines()
except:
eprint("silentsketchparamsfrompdbs: Error! pdb couldn't be opened", pdb)
continue
if pdb.endswith('.cif'):
parser = MMCIFParser(QUIET=True)
structure = parser.get_structure(pdb, io.StringIO(''.join(pdb_lines)))
for residue in structure.get_residues():
if len(residue.resname) > 3:
residue.resname = residue.resname[:3]
pdb_io = PDBIO()
pdb_io.set_structure(structure)
pdb_buffer = io.StringIO()
pdb_io.save(pdb_buffer)
pdb_lines = pdb_buffer.getvalue().splitlines(keepends=True)
use_pdb_lines = use_pdb_lines = [line for line in pdb_lines if line.startswith(('CONECT', 'TER', 'HETATM'))]
raw_params_dict = silent_tools.generate_params_for_pdb(use_pdb_lines)
for name3, raw_params in raw_params_dict.items():
if name3 in written_params:
eprint(f'{name3}.params already written')
continue
with open(name3 + '.params', 'w') as f:
f.write(raw_params)
to_print.append(f'-extra_res_fa {name3}.params')
print(' '.join(to_print))