<s> """<STR_LIT>""" <EOL> import os <EOL> import numpy <EOL> from prody . measure . measure import calcCenter , calcDistance <EOL> class AtomicDistancesPostAction ( object ) : <EOL> KEYWORD = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def run ( self , clustering , postprocessing_parameters , data_handler , workspace_handler , matrix_handler , generatedFiles ) : <EOL> file_name = postprocessing_parameters . get_value ( "<STR_LIT:file>" , default_value = "<STR_LIT>" ) + "<STR_LIT>" <EOL> file_path = os . path . join ( workspace_handler [ "<STR_LIT>" ] , file_name ) <EOL> self . process_distances ( file_path , clustering , postprocessing_parameters , data_handler , workspace_handler , matrix_handler , generatedFiles ) <EOL> def process_distances ( self , file_path , clustering , postprocessing_parameters , data_handler , workspace_handler , matrix_handler , generatedFiles ) : <EOL> handler = open ( file_path , "<STR_LIT:w>" ) <EOL> distances = calculate_selection_distances ( postprocessing_parameters [ "<STR_LIT>" ] , data_handler ) <EOL> write_distances_file ( handler , distances , clustering , postprocessing_parameters [ "<STR_LIT>" ] ) <EOL> handler . close ( ) <EOL> generatedFiles . append ( { <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:path>" : os . path . abspath ( file_path ) , <EOL> "<STR_LIT:type>" : "<STR_LIT>" <EOL> } ) <EOL> def write_distances_file ( handler , distances , clustering , distance_descriptors ) : <EOL> for cluster in clustering . clusters : <EOL> handler . write ( "<STR_LIT>" ) <EOL> for distance_id in distances : <EOL> cluster_distances = distances [ distance_id ] [ cluster . all_elements ] <EOL> if "<STR_LIT>" in distance_descriptors [ distance_id ] : <EOL> cutoff = float ( distance_descriptors [ distance_id ] [ "<STR_LIT>" ] ) <EOL> print cluster_distances [ cluster_distances < cutoff ] <EOL> handler . write ( "<STR_LIT>" % ( cluster . id , <EOL> distance_id , <EOL> numpy . mean ( cluster_distances ) , <EOL> numpy . std ( cluster_distances ) , <EOL> len ( cluster_distances [ cluster_distances < cutoff ] ) ) ) <EOL> else : <EOL> handler . write ( "<STR_LIT>" % ( cluster . id , <EOL> distance_id , <EOL> numpy . mean ( distances [ distance_id ] [ cluster . all_elements ] ) , <EOL> numpy . std ( distances [ distance_id ] [ cluster . all_elements ] ) ) ) <EOL> handler . write ( "<STR_LIT>" ) <EOL> for cluster in clustering . clusters : <EOL> for distance_id in distances : <EOL> handler . write ( "<STR_LIT>" % ( cluster . id , distance_id ) ) <EOL> for element in cluster . all_elements : <EOL> handler . write ( "<STR_LIT>" % ( distances [ distance_id ] [ element ] ) ) <EOL> handler . write ( "<STR_LIT:\n>" ) <EOL> def calculate_selection_distances ( distance_selection_objects , data_handler ) : <EOL> """<STR_LIT>""" <EOL> distances = { } <EOL> ensemble = data_handler . get_data ( ) . get_all_elements ( ) <EOL> for distance_id in distance_selection_objects : <EOL> try : <EOL> from_selection = ensemble . select ( distance_selection_objects [ distance_id ] [ "<STR_LIT>" ] ) <EOL> to_selection = ensemble . select ( distance_selection_objects [ distance_id ] [ "<STR_LIT:to>" ] ) <EOL> except KeyError : <EOL> print '<STR_LIT>' % distance_id <EOL> break <EOL> if from_selection is None : <EOL> print '<STR_LIT>' % distance_id <EOL> break <EOL> if to_selection is None : <EOL> print '<STR_LIT>' % distance_id <EOL> break <EOL> distances [ distance_id ] = calcDistance ( calcCenter ( from_selection . getCoordsets ( ) ) , <EOL> calcCenter ( to_selection . getCoordsets ( ) ) ) <EOL> return distances </s>
