-
Notifications
You must be signed in to change notification settings - Fork 0
/
dx_analysis.py
104 lines (86 loc) · 3.78 KB
/
dx_analysis.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
# ----------------------------------------
# USAGE:
# ----------------------------------------
# python3 dx_analysis.py config_file.config IO.py
# ----------------------------------------
# PREAMBLE:
# ----------------------------------------
import sys
import os
import importlib
import numpy as np
import MDAnalysis
# ----------------------------------------
# VARIABLE DECLARATION:
# ----------------------------------------
config_file = sys.argv[1]
IO_functions_file = sys.argv[2]
config_parser = importlib.import_module(IO_functions_file.split('.py')[0],package=None).dx_config_parser
summary = importlib.import_module(IO_functions_file.split('.py')[0],package=None).summary
# ----------------------------------------
# FUNCTIONS:
# ----------------------------------------
def main():
# ----------------------------------------
# FILE NAMING VARIABLES
# ----------------------------------------
summary_file_name = parameters['output_directory'] + 'summary.txt'
dx_file_name = parameters['output_directory'] + parameters['dx_output_file_name']
if parameters['other_cv']:
cv_file_name = parameters['output_directory'] + parameters['cv_file_name']
# ----------------------------------------
# LOAD IN THE STRUCTURES TO BE ANALYZED
# ----------------------------------------
positions = np.array([[0.,0.,0.]])
weights = np.array([0.])
if parameters['other_cv']:
cvs = np.array([0.])
for pdb, weight in parameters['pdb_list']:
u = MDAnalysis.Universe(pdb)
selection = u.select_atoms(parameters['selection'])
weights = np.append(weights,[weight for i in range(selection.n_atoms)])
positions = np.append(positions,selection.positions,axis=0)
if parameters['other_cv']:
cvs = np.append(cvs,calc_cv(selection))
# ----------------------------------------
# ANALYZE POSITION DATA AND CREATE DX FILES
# ----------------------------------------
if parameters['other_cv']:
half_max_counts = create_dx(positions,weights,float(parameters['dx_delta']),dx_file_name,cv_data=cvs,cv_file_name=cv_file_name)
else:
half_max_counts = create_dx(positions,weights,float(parameters['dx_delta']),dx_file_name)
# ----------------------------------------
# OUTPUTTING SUMMARY INFORMATION
# ----------------------------------------
if parameters['summary_boolean']:
summary(summary_file_name,sys.argv,parameters)
# ----------------------------------------
# CREATING PARAMETER DICTIONARY
# ----------------------------------------
parameters = {}
config_parser(config_file,parameters)
# ----------------------------------------
# LOADING IN NECESSARY FUNCTIONS FROM MODULE FILES
# ----------------------------------------
create_dx = importlib.import_module(parameters['visualization_functions_file'].split('.')[0],package=None).create_dx
if parameters['other_cv']:
if parameters['cv_type'].upper() == "B_FACTOR":
calc_cv = importlib.import_module(parameters['user_functions_file'].split('.')[0],package=None).bfactors
else:
print('User needs to read in an accepted "cv_type" or edit the main code (line 74) to accept their new function.')
sys.exit()
# ----------------------------------------
# PREP OUTPUT DIRECTORY STEP
# ----------------------------------------
if parameters['output_directory'][-1] != os.sep:
parameters['output_directory'] += os.sep
if os.path.exists(parameters['output_directory']):
print('The output directory, ', parameters['output_directory'], 'already exists. Please select a different directory name for output.')
sys.exit()
else:
os.mkdir(parameters['output_directory'])
# ----------------------------------------
# MAIN
# ----------------------------------------
if __name__ == '__main__':
main()