def zip_simulation(project_id: str) -> Optional[str]: project_zip_path = server.get_project_file(project_id, ProjectFile.SIMULATION_ZIP) if server.simulation_files_exist(project_id): (pdb_file_path, xtc_file_path) = server.get_simulation_file_paths(project_id) with ZipFile(project_zip_path, 'w') as archive: archive.write(pdb_file_path, 'trajectory.pdb') archive.write(xtc_file_path, 'trajectory.xtc') return project_zip_path return None
def execute_sim(job_id: str, project_id: str, user_id: str, should_regenerate: bool, fresh_execution=True, execution_time=None): job = Job(id=job_id, process_name=execute_sim.request.id, start_time=timezone.now(), finish_time=None, terminated=False) job.save(update_fields=[ 'process_name', 'start_time', 'finish_time', 'terminated' ]) # Clean the previous execution files if should_regenerate or fresh_execution: server.clean_project(project_id) project_folder_path = server.get_project_folder_path(project_id) stdout_file_path = server.get_project_file(project_id, ProjectFile.STDOUT) if should_regenerate: print("Regenerating topology for project: " + project_id) generate_initial_configuration(project_id, stdout_file_path) print("Received new execution for project: " + project_id) stdout_log_file = open(file=stdout_file_path, mode='w') process = subprocess.Popen(['oxDNA', 'input.txt'], cwd=project_folder_path, stdout=stdout_log_file) try: process.wait(timeout=execution_time) except TimeoutExpired as ex: process.terminate() print("Simulation wall time of " + str(execution_time) + "s reached for project: " + project_id) stdout_log_file.close() print("Simulation completed, generating pdb file for project: " + project_id) if not project_util.generate_sim_files(project_id): print('Unable to convert simulation to visualizer output.') execute_output_analysis(project_id, user_id) job = Job(id=job_id, finish_time=timezone.now(), process_name=None) job.save(update_fields=['process_name', 'finish_time'])
def parse_input_file(project_id: str) -> Union[str, Dict]: input_file_path = server.get_project_file(project_id, ProjectFile.INPUT) if not os.path.isfile(input_file_path): return messages.MISSING_PROJECT_FILES input_file = open(file=input_file_path, mode='r') input_dictionary = {} for line in input_file.readlines(): if line[len(line) - 1] == '\n': line = line[:-1] key_and_value = line.split(' = ') input_dictionary[key_and_value[0]] = key_and_value[1] return input_dictionary
def zip_project(project_id: str) -> Optional[str]: project_folder_path = server.get_project_folder_path(project_id) project_zip_path = server.get_project_file(project_id, ProjectFile.PROJECT_ZIP) if server.project_folder_exists(project_id): if os.path.exists(project_zip_path): os.remove(project_zip_path) with ZipFile(project_zip_path, 'w') as archive: for (dir_path, dir_names, file_names) in os.walk(project_folder_path): file_names_len = len(file_names) for i in range(0, file_names_len): if '.zip' in file_names[i]: continue archive.write(os.path.join(dir_path, file_names[i]), file_names[i]) return project_zip_path return None
def generate_sim_files(project_id: str) -> bool: # Firstly, convert the 'trajectory.dat' file to 'trajectory.pdb' if not convert_dat_to_pdb(project_id): return False # If the 'server-sims' directory doesn't exist, make it here os.makedirs(server.get_simulation_folder_path(), exist_ok=True) # Get the file paths for the output simulation PDB and XTC files (pdb_file_path, xtc_file_path) = server.get_simulation_file_paths(project_id) # The original 'trajectory.pdb' that will be converted to simulation files original_pdb_path = server.get_project_file(project_id, ProjectFile.TRAJECTORY_PDB) try: os.remove(pdb_file_path) os.remove(xtc_file_path) except OSError: pass convert_pdb_to_xtc(input_file_path=original_pdb_path, output_file_path=xtc_file_path) convert_pdb_to_single_frame(input_file_path=original_pdb_path, output_file_path=pdb_file_path) return True
def is_executable(project_id: str, regenerate: bool) -> bool: input_file = server.get_project_file(project_id, ProjectFile.INPUT) if not os.path.isfile(input_file): return False project_settings = get_project_settings(project_id) generation_method = project_settings.generation.method if generation_method == 'generate-sa' or generation_method == 'generate-folded': if regenerate: sequence_file = server.get_project_file(project_id, ProjectFile.SEQUENCE) if os.path.isfile(sequence_file): return True else: return False else: generated_top = server.get_project_file(project_id, ProjectFile.GENERATED_TOP) generated_dat = server.get_project_file(project_id, ProjectFile.GENERATED_DAT) if os.path.isfile(generated_dat) and os.path.isfile(generated_top): return True else: return False elif generation_method == 'cadnano-interface': if regenerate: cadnano_project_file = server.get_project_file(project_id, ProjectFile.CADNANO) if os.path.isfile(cadnano_project_file): return True else: return False else: generated_top = server.get_project_file(project_id, ProjectFile.GENERATED_TOP) generated_dat = server.get_project_file(project_id, ProjectFile.GENERATED_DAT) if os.path.isfile(generated_dat) and os.path.isfile(generated_top): return True else: return False else: return False
def save_project_settings(project_id: str, project_settings: ProjectSettings): project_settings_file_path = server.get_project_file(project_id, ProjectFile.SETTINGS) file_util.write_string_to_file(jsonpickle.encode(project_settings), project_settings_file_path)
def get_project_settings(project_id: str) -> ProjectSettings: project_settings_file_path = server.get_project_file(project_id, ProjectFile.SETTINGS) return jsonpickle.decode(file_util.get_file_contents_as_string(project_settings_file_path))