7
7
8
8
9
9
def parse_array (array ):
10
+ # Bin #0 corresponds with d>20A
11
+ # Bins #1 ~ #36 correspond with 2A<d<20A in increments of 0.5A
10
12
contacts = np .sum (array [:, :, 1 :13 ], axis = - 1 )
11
13
L = contacts .shape [0 ]
12
14
BINS = [np .sum (array [:, :, x :x + 4 ], axis = - 1 ) for x in range (1 , 37 , 4 )]
@@ -18,23 +20,25 @@ def parse_array(array):
18
20
for i in range (L ) for j in range (i + 5 , L )]
19
21
20
22
21
- def NpzParser (input , input_format ):
23
+ def NpzParser (input , input_format = None ):
22
24
output = []
23
25
content_type , content_string = input .split (',' )
24
- decoded = base64 .b64decode (content_string )
25
- archive = np .load (io .BytesIO (decoded ), allow_pickle = True )
26
- array = archive ['dist' ]
27
- # Bin #0 corresponds with d>20A
28
- # Bins #1 ~ #36 correspond with 2A<d<20A in increments of 0.5A
29
- tmp_output = parse_array (array )
26
+ try :
27
+ decoded = base64 .b64decode (content_string )
28
+ archive = np .load (io .BytesIO (decoded ), allow_pickle = True )
29
+ array = archive ['dist' ]
30
+ tmp_output = parse_array (array )
31
+ except (OSError , KeyError , IndexError ) as e :
32
+ raise InvalidFormat ('Unable to parse distance NPZ file' )
33
+
30
34
31
35
for contact in tmp_output :
32
36
# contact = [res_1, res_2, raw_score, distance_bin, distance_score]
33
37
contact [:2 ] = sorted (contact [:2 ], reverse = True )
34
38
output .append ((tuple (contact [:2 ]), * contact [2 :]))
35
39
36
40
if not output :
37
- raise InvalidFormat ('Unable to parse contacts ' )
41
+ raise InvalidFormat ('Unable to parse NPZ file ' )
38
42
else :
39
43
unique_contacts = unique_by_key (output , key = itemgetter (0 ))
40
44
output = [(* contact [0 ], * contact [1 :]) for contact in unique_contacts ]
0 commit comments