#es_software = "gaussian" istep = 0 fstep = 1 #3000 njobs = 1 #600 for njob in range(njobs): job_init_step, job_final_step = step2_many_body.curr_and_final_step_job( istep, fstep, njobs, njob) nsteps_this_job = job_final_step - job_init_step + 1 print('\n1- We are before creating job ', njob, ' in directory:', os.getcwd()) # Here we create the jobs through auxiliary_functions.cp2k_distribute if es_software.lower() == "cp2k": CP2K_methods.cp2k_distribute(job_init_step, job_final_step, nsteps_this_job, trajectory_xyz_file, es_software_input_template, njob) elif es_software.lower() == "gaussian": Gaussian_methods.gaussian_distribute(job_init_step, job_final_step, nsteps_this_job, trajectory_xyz_file, es_software_input_template, njob) print('2- Finished distributing for job ', njob, '\nNow we are in directory', os.getcwd()) os.chdir("wd/job" + str(njob) + "/") print('3- Now we have changed directory to :', os.getcwd(), 'To submit job', njob) os.mkdir("cubefiles")
def run_step2_jobs(params): """ Prepares and runs job folders needed for running step2 Args: params (dict): The parameters dictionary used for containing the variables needed to make the submit.slm template Returns: None: but creates the wd (working diretory) that stores the job folders and the files needed to run each job, and runs those jobs. """ logger.debug("Entered into the function initialize_step2_jobs") critical_params = [] default_params = { "trajectory_xyz_filename": "md.xyz", "es_software": "cp2k", "es_software_input_template": "cp2k_input_template", "istep": 0, "fstep": 1, "njobs": 1, "waveplot_input_template": "waveplot_in.hsd" } comn.check_input(params, default_params, critical_params) logger.debug("Checked params in the function initialize_step2_jobs") # Consider using shutils module here instead of os.system() os.system("rm -r wd") os.mkdir('wd') os.system("rm -r res") os.mkdir('res') # Get the neededvariables from the params dictionary trajectory_xyz_filename = params["trajectory_xyz_filename"] es_software = params["es_software"] es_software_input_template = params["es_software_input_template"] init_md_step = params["istep"] final_md_step = params["fstep"] njobs = params["njobs"] if es_software == "dftb+": waveplot_input_template = params["waveplot_input_template"] # Initialize the jobs for njob in range(njobs): logger.debug(f"Within the loops over njobs, initializing job: {njob}") job_init_step, job_final_step = step2_many_body.curr_and_final_step_job( init_md_step, final_md_step, njobs, njob) nsteps_this_job = job_final_step - job_init_step + 1 logger.debug( f"The initial step for the job {njob} is: {job_init_step} with final step: {job_final_step}" ) logger.debug(f"nsteps_this_job is: {nsteps_this_job}") logger.debug(f"Creating job: {njob} in directory: {os.getcwd()}") if es_software.lower() == "cp2k": logger.debug("es_software.lower() == cp2k") CP2K_methods.cp2k_distribute(job_init_step, job_final_step, nsteps_this_job, trajectory_xyz_filename, es_software_input_template, njob) elif es_software.lower() == "gaussian": logger.debug("es_software.lower() == gaussian") Gaussian_methods.gaussian_distribute(job_init_step, job_final_step, nsteps_this_job, trajectory_xyz_filename, es_software_input_template, njob) elif es_software.lower() == "dftb+": logger.debug("es_software.lower() == dftb+") DFTB_methods.dftb_distribute(job_init_step, job_final_step, nsteps_this_job, trajectory_xyz_filename, es_software_input_template, waveplot_input_template, njob) logger.debug( f"Finished distributing for job: {njob}. We are currently in directory: {os.getcwd()}" ) os.chdir("wd/job" + str(njob) + "/") logger.debug(f"Changed directory to: {os.getcwd()}") logger.debug( "Assigning values to the variables job_init_step, nsteps_this_job, and njob in submit_template.slm" ) os.system("cp ../../submit_template.slm submit_" + str(njob) + ".slm") # Now, open the submit_template file in this job folder # Add the values to the params for this job f = open("submit_" + str(njob) + ".slm") submit_template_file = f.readlines() submit_template_file_size = len(submit_template_file) f.close() f = open("submit_" + str(njob) + ".slm", 'w') f.close() for i in range(submit_template_file_size): f = open("submit_" + str(njob) + ".slm", 'a') submit_template_file_line = submit_template_file[i].split() if not submit_template_file_line: continue elif submit_template_file_line[0] == "job_init_step=": f.write("declare -i job_init_step=%i" % (job_init_step)) f.write("\n") elif submit_template_file_line[0] == "nsteps_this_job=": f.write("declare -i nsteps_this_job=%i" % (nsteps_this_job)) f.write("\n") elif submit_template_file_line[0] == "njob=": f.write("declare -i njob=%i" % (njob)) f.write("\n") else: f.write(submit_template_file[i]) logger.debug(f"Updated submit_template.slm") os.system("sbatch submit_" + str(njob) + ".slm") #os.system("sh submit_"+str(njob)+".slm") logger.debug(f"Submitting the job in folder: {os.getcwd()}") # Change directory back to the top directory os.chdir("../../") logger.debug( f"Finished submitting job. We are now back in directory: {os.getcwd()}" )