-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathper_aa.py
68 lines (51 loc) · 2.05 KB
/
per_aa.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
import collections as col
import glob
import os
import sys
import pandas as pd
import pyrosetta as pr
import pyrosetta.rosetta.core.scoring as scoring
import pyrosetta.teaching as pt
if len(sys.argv) < 2:
print('Usage: python per_aa.py pdb_dir')
sys.exit(1)
filedir = sys.argv[1]
output_csv = filedir + '/per_aa.csv'
print(f'Writing {filedir:} to {output_csv:}')
pr.init("-mute basic.random basic.io core.chemical core.scoring core.pack "
"core.init core.import_pose",
silent=True)
ref15 = pt.get_fa_scorefxn()
scorefxn = scoring.get_score_function()
sf = pr.ScoreFunction()
results = col.defaultdict(list)
for filepath in glob.glob(filedir + '*.pdb'):
print(f'Doing {filepath:}')
pose = pr.pose_from_pdb(filepath)
# scorefxn.show(pose)
scorefxn.score(pose)
# Copying from
# main/source/src/protocols/flexpep_docking/FlexPepDockingPoseMetrics.cc
recseq = pose.chain_sequence(1)
pepseq = pose.chain_sequence(2)
pepscore = 0
pepscore_noref = 0
filename_len = len(os.path.basename(filepath))
file_column_name = 'file'
results[f'{file_column_name:<{filename_len}}'].append(os.path.basename(filepath))
for idx, i in enumerate(range(len(recseq) + 1, len(recseq) + 1 + len(pepseq))):
ienergy = pose.energies().residue_total_energy(i)
ifa_ref = pose.energies().residue_total_energies(i)[scoring.ref]
pepscore += ienergy
pepscore_noref += ienergy - ifa_ref
results[f'{pepseq[idx] + str(idx):>6}'].append(ienergy-ifa_ref)
# print(f'{pepseq[idx] + str(idx):}: {ienergy-ifa_ref:6.3f}')
# scorefxn_no_cst = scoring.deep_copy(scorefxn)
# scorefxn_no_cst.set_weight(scoring.coordinate_constraint, 0.0);
# scorefxn_no_cst.set_weight(scoring.atom_pair_constraint, 0.0);
# scorefxn_no_cst.set_weight(scoring.angle_constraint, 0.0);
# scorefxn_no_cst.set_weight(scoring.dihedral_constraint, 0.0);
# import pdb; pdb.set_trace()
#test.energies().show(1)
results = pd.DataFrame(results)
results.to_csv(output_csv, index=False, float_format='%6.3f')