-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlookup.py
82 lines (58 loc) · 4.09 KB
/
lookup.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
# ! /usr/bin/env python
# lookup - companion code to cylindr for returning...
# Dr. R. J. Mandle - University of Leeds, 2022
import numpy as np
from numpy import savetxt
import argparse
def initialize():
parser = argparse.ArgumentParser(description='Reads the .npz output from\
cylindr.py (-i) and Returns timestep and residue numbers for pairs of molecules\
that satisfy the user supplied length (-L) and radius (-R) ranges')
parser.add_argument('-i', '--input_name', default='', type=str, help='the output .npz file generated by cylindr to use as an input')
parser.add_argument('-L', '--L_range', default = '', type=str, help='cylinder length window lower and upper limits, in angstroms. seperate values with a comma')
parser.add_argument('-R', '--R_range', default = '', type=str, help='cylinder radius window lower and upper limits, in angstroms. seperate values with a comma')
parser.add_argument('-o', '--output_name', default = 'default_out', type=str, help='supply a custom output name, if you want.')
return parser
args = initialize().parse_args()
L_range = np.array((args.L_range).split(','),dtype=float)
R_range = np.array((args.R_range).split(','),dtype=float)
# print out what range of -L and -R we'll use, and why (if <2 or >2 values given!)
if np.size(L_range) ==2: # if the user supplies exactly 2 values of L
print('Using user value of ' + str(L_range[0]) + ' as lower length limit and '\
+ str(L_range[1]) + ' as upper length limit \n')
if np.size(L_range) >2: # if the user supplies > 2 values of L
print('Expected two values for cylinder length range (-L) but more than 2 given')
print('Please run lookup.py multiple times for multiple windows \n')
L_range = [L_range[0], L_range[1]]
print('Using user value of ' + str(L_range[0]) + ' as lower length limit and '\
+ str(L_range[1]) + ' as upper length limit \n')
if np.size(L_range)<2: # if the user supplies < 2 values of L
print('Expected two values for cylinder length range (-L) but only one given \n')
L_range = [L_range, L_range + 1]
print('Using user value of ' + str(L_range[0]) + ' as lower length limit and '\
+ str(L_range[1]) + ' as upper length limit \n')
if np.size(R_range) ==2: # if the user supplies exactly 2 values of R
print('Using user value of ' + str(R_range[0]) + ' as lower radius limit and '\
+ str(R_range[1]) + ' as upper radius limit \n')
if np.size(R_range) >2: # if the user supplies > 2 values of R
print('Expected two values for cylinder radius range (-R) but more than 2 given')
print('Please run lookup.py multiple times for multiple windows \n')
R_range = [R_range[0], R_range[1]]
print('Using user value of ' + str(R_range[0]) + ' as lower radius limit and '\
+ str(R_range[1]) + ' as upper radius limit \n')
if np.size(R_range)<2: # if the user supplies < 2 values of R
print('Expected two values for cylinder radius range (-R) but only one given')
R_range = [R_range, R_range + 1]
print('Using user value of ' + str(R_range[0]) + ' as lower radius limit and '\
+ str(R_range[1]) + ' as upper radius limit \n')
if args.output_name == 'default_out': # if default name; encodes user parameters
Output_Name = (str(args.input_name) + '_L' + str(L_range[0]) + '-'\
+ str(L_range[1]) + '_R' + str(R_range[0]) + '-' + str(R_range[1]))
if args.output_name != 'default_out': # use the user supplied name for output
Output_Name = args.output_name
print('Will save output as: ' + Output_Name + '.csv')
Data = np.load(args.input_name + ".npz") # load data from cylindr.py
# Simple lookup engine - find pairs within supplied cutoff distances
Contacts = np.array(np.where((Data['Dist_L'] > L_range[0]) & (Data['Dist_L'] < L_range[1]) & (Data['Dist_R'] > R_range[0]) & (Data['Dist_R'] < R_range[1])))
Contacts = [Contacts[0, :], Contacts[1, :] + 1, Contacts[2, :] + 1] # +1 to residue indexes, as python indexes from zero
np.savetxt(Output_Name + ".csv", np.transpose(Contacts), delimiter=",")