-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrunfirst.py
111 lines (74 loc) · 3.76 KB
/
runfirst.py
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
'''
runfirst.py - functions to run FIRST simulations, analyzing rigidity in proteins
'''
import os
'''
firstsim - main function for running FIRST analysis on a protein
Inputs:
- string exec_folder: folder where the python scripts are located (full path)
- struct args: structure containing all arguments already parsed
- string cleanpdb: full path to PDB file after cleaning (by extension, also includes path to where all outputs are)
Outputs:
- string hydropdb: full path to PDB file after addition of hydrogens
'''
def firstsim(exec_folder,args,cleanpdb):
print ("---------------------------------------------------------------")
print ("firstsim:")
print ("----------------------------------------------------------------")
# print "./reduce.3.23.130521 -DB reduce_het_dict.txt -build "+cleanpdb+" > "+cleanpdb[:-9]+"hydro.pdb"
# first we isolate the name of the protein, which is in the clean PDB path somewhere!
print ("---------------------------------------------------------------")
print ("firstsim: find name of protein")
print ("----------------------------------------------------------------")
prot=cleanpdb[:-10].rsplit("/",1)[1]
# print "prot is "+prot
# now, we need to run reduce to add hydrogens to protein residues - this generates a PDB file with hydrogens
print ("---------------------------------------------------------------")
print ("firstsim: calling reduce.3.23.130521")
print ("----------------------------------------------------------------")
os.system(exec_folder+"/reduce.3.23.130521 -DB "+exec_folder+"/reduce_het_dict.txt -build "+cleanpdb+" > "+cleanpdb[:-9]+"hydro.pdb")
# we also isolate the folder where outputs are being saved
folder=cleanpdb.rsplit("/",1)[0]
# now, we call an external function to renumber the atoms taking the hydrogens into account
renum_atoms(cleanpdb[:-9]+"hydro.pdb",folder)
# finally we run FIRST with the PDB after hydrogen addition!
print ("---------------------------------------------------------------")
print ("firstsim: running FIRST with new PDB file after hydrogens added")
print ("----------------------------------------------------------------")
os.system(exec_folder+"/FIRST-190916-SAW/src/FIRST "+cleanpdb[:-9]+"hydro.pdb -non -dil 1 -E -0 -covout -hbout -phout -srout")
# finally, return the hydro-added PDB path
return cleanpdb[:-9]+"hydro.pdb"
# print folder,prot
'''
renum_atoms: renumber the atoms in a PDB file to make sure they're in order and without gaps
Inputs:
string filename: path to origin PDB file
string folder: path to output folder
'''
def renum_atoms(filename,folder):
# open the input file and a temp file at the output folder
inputfile=open(filename,'r')
tempfile=open(folder+"/tmp.pdb",'w')
# let's learn how to count!
counter=1
# test=format(1, '05d')
# print test
print ("---------------------------------------------------------------")
print ("renum_atoms:")
print ("----------------------------------------------------------------")
# looping over every line in the input file
for line in inputfile:
# if line is an atom...
if (line[0:6].strip()=='ATOM' or line[0:6].strip()=='HETATM'):
# we chop up the line, cutting out the current atom number and putting the value of counter as atom number
line=line[:6]+format(counter, '05d')+line[11:]
# write it to temp file and increase counter
tempfile.write(line)
counter=counter+1
# now we can close them both
inputfile.close()
tempfile.close()
# finally, we replace the original file with the temporary one
os.system("rm "+filename)
os.system("mv "+folder+"/tmp.pdb "+filename)