def convertInputData(self): """Convert input data to command-adaptable format data.""" # {system: Data, restraint self.state.preparing for socket_name, c in self.inputs.items(): data = c['data'] if data.type in self.__command.type_format_table: formats = self.__command.type_format_table[data.type] dc = DataConverter(data, formats, user_command=False) dc.convert() datas = dc.get_datas() rev_formats = dict([ (format, key) for key, format in self.__command.input_formats.items() ]) for data in datas: if data.format in rev_formats: option = rev_formats[data.format] if option in self.__command.default_options: filename = self.__command.default_options[option] file_abspath = os.path.join(self.path, filename) data.dump(file_abspath) else: mes = "option: {0} was not found in default options." raise OptionNotFound(mes.format(option)) else: mes = "format: {0} was not found in input formats:" raise FormatNotFound(mes.format(key))
def __call__(self): start_time = time.time() try: zf = zipfile.ZipFile(self.input_file, 'r') zf.extractall(self.extract_dir) zf.close() # data conversion start converter = DataConverter(in_dir=self.extract_dir, out_dir=self.output_dir, zipfilename=os.path.basename( self.input_file), logger=self.logger) data = converter.run(output_format=self.output_format) # insert in database if settings were provided (IP and Port) if self.db_settings['enabled'] is True: dbconnection = MongoDBConnector(self.db_settings['ip'], self.db_settings['port'], self.db_settings['database']) dbconnection.insert_dataset(datapoints=data, datasetname='l' + self.logger + '_' + os.path.basename(self.input_file)) shutil.rmtree(self.extract_dir) shutil.move( self.input_file, self.processed_dir + '/' + os.path.basename(self.input_file)) except Exception as err: print(' error: executing conversion task of %s failed: %s' % (os.path.basename(self.input_file), err)) return end_time = time.time() print('converted %s to %s (%s sec)' % (os.path.basename(self.input_file), self.output_format, round((end_time - start_time), 2))) return
def main(): # d = DataConverter() # for k, f in d.convert_dict.items(): # print k, f import project p = project.Project() d = Data(p, type='System') p.append_data(d) print d.context pdb_path = '~/Dropbox/Office/Nagara/v02-src/examples/structures/1HEW.pdb' pdb_abspath = os.path.expanduser(pdb_path) d.set_local_file(filename=pdb_abspath, format='PDB') print d.context print d.get_file() from dataconverter import DataConverter dc = DataConverter( input_data_list=[d], output_format_list=['NagaraData'] ) system_data = dc.get_data_list()[0] print system_data.context system = system_data.ndo # for atom in system.atoms: # print atom dc2 = DataConverter( input_data_list=[system_data], output_format_list=['PDB'] ) pdb_data = dc2.get_data_list()[0] print 222222222, pdb_data.type print 33333333333, pdb_data.context