#NEWLINE# def save_cluster_elements( elements , ids , out_pdb_name , data_handler , options , cluster_sizes = None ) : #NEWLINE# #INDENT# '\n    Saves a pdb file containing the most representative elements of the clustering.\n\n    @param elements: A list of the representative elements of the clustering we want to extract.\n\n    @params ids: A list with the cluster ids (1 to 1 mapping with \'elements\').\n\n    @param out_pdb_name: The complete path of the produced file.\n\n    @param data_handler: The trajectory handler for this run or an array with pdb file paths.\n\n    @param options: postprocessing options to generate the file. Currently a dic with any of these:\n        "keep_remarks" - Will add each model\'s remarks before the model header if present\n            Possible values are:\n            - "NONE": not to store remarks (Default)\n            - "STANDARD": stores remarks that follow pdb standard\n            - "NOT STANDARD": stores remarks not following the pdb standard\n            - "ALL": stores all remarks\n        "add_source_details" - Will add two remarks before the model tag: the path of the source file and \n            the original model number. \n            \n    @params cluster_sizes: specific for the representatives case. Each element of this array holds the\n    size of its cluster. \n        \n    ' #NEWLINE# keep_remarks = options . get_value ( 'keep_remarks' , default_value = 'NONE' ) #NEWLINE# add_source_details = options . get_value ( 'add_source_details' , default_value = False ) #NEWLINE# file_handler_out = open ( out_pdb_name , 'w' ) #NEWLINE# data = data_handler . get_data ( ) #NEWLINE# merged_structure = data . get_all_elements ( ) #NEWLINE# file_handler_out . write ( 'REMARK 000 File created using Prody and pyProCT\n' ) #NEWLINE# if ( ( not ( keep_remarks == 'NONE' ) ) and ( not add_source_details ) ) : #NEWLINE# #INDENT# prody . writePDBStream ( file_handler_out , merged_structure , csets = elements ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# all_remarks = filter_remarks ( data . get_all_remarks ( ) , subset = keep_remarks ) #NEWLINE# all_model_numbers = data . get_all_model_numbers ( ) #NEWLINE# current_model = 0 #NEWLINE# for ( i , element_id ) in enumerate ( elements ) : #NEWLINE# #INDENT# if keep_remarks : #NEWLINE# #INDENT# remarks = all_remarks [ element_id ] #NEWLINE# file_handler_out . write ( '' . join ( remarks ) ) #NEWLINE# #UNINDENT# if add_source_details : #NEWLINE# #INDENT# model_number = all_model_numbers [ element_id ] #NEWLINE# conf_source = data_handler . get_source_of_element ( element_id ) . get_path ( ) #NEWLINE# file_handler_out . write ( ( 'REMARK 000  source            : %s\n' % conf_source ) ) #NEWLINE# file_handler_out . write ( ( 'REMARK 000  original model nr : %d\n' % model_number ) ) #NEWLINE# file_handler_out . write ( ( 'REMARK 000  cluster id : %s\n' % ids [ i ] ) ) #NEWLINE# file_handler_out . write ( ( 'REMARK 000  cluster element : %d\n' % element_id ) ) #NEWLINE# if ( cluster_sizes is not None ) : #NEWLINE# #INDENT# file_handler_out . write ( ( 'REMARK 000  cluster population : %s\n' % cluster_sizes [ i ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# file_handler_out . write ( ( ( 'MODEL' + str ( current_model ) . rjust ( 9 ) ) + '\n' ) ) #NEWLINE# pdb_handler = cStringIO . StringIO ( ) #NEWLINE# prody . writePDBStream ( pdb_handler , merged_structure , csets = element_id ) #NEWLINE# lines = filter ( ( lambda line : ( ( line [ 0 : 6 ] != 'REMARK' ) and ( line [ 0 : 5 ] != 'MODEL' ) and ( line [ 0 : 6 ] != 'ENDMDL' ) ) ) , pdb_handler . getvalue ( ) . splitlines ( True ) ) #NEWLINE# pdb_handler . close ( ) #NEWLINE# file_handler_out . write ( '' . join ( lines ) ) #NEWLINE# file_handler_out . write ( 'ENDMDL\n' ) #NEWLINE# current_model += 1 #NEWLINE# #UNINDENT# #UNINDENT# file_handler_out . close ( )