def prep_vertical_ip(path): # Given a path to the outfile of a finished run, this preps the files for a corresponding vertical IP run # Returns a list of the PATH(s) to the jobscript(s) to start the vertical IP calculations(s) home = os.getcwd() path = convert_to_absolute_path(path) results = manager_io.read_outfile(path) if not results['finished']: raise Exception('This calculation does not appear to be complete! Aborting...') infile_dict = manager_io.read_infile(path) if infile_dict['spinmult'] == 1: new_spin = [2] else: new_spin = [infile_dict['spinmult'] - 1, infile_dict['spinmult'] + 1] base = os.path.split(path)[0] if infile_dict['run_type'] == 'minimize': optimxyz = os.path.join(base, 'scr', 'optim.xyz') else: optimxyz = os.path.join(base, 'scr', 'xyz.xyz') extract_optimized_geo(optimxyz) ipname = results['name'] + '_vertIP' vertip_base_path = os.path.join(base, ipname) if os.path.isdir(vertip_base_path): return ['Directory for vertIP single point already exists'] os.mkdir(vertip_base_path) os.chdir(vertip_base_path) jobscripts = [] for calc in new_spin: if calc < 7: name = results['name'] + '_vertIP_' + str(calc) PATH = os.path.join(vertip_base_path, str(calc)) if os.path.isdir(PATH): jobscripts.append('File for vert IP spin ' + str(calc) + 'already exists') else: os.mkdir(PATH) os.chdir(PATH) shutil.copyfile(os.path.join(base, 'scr', 'optimized.xyz'), os.path.join(PATH, name + '.xyz')) local_infile_dict = copy.copy(infile_dict) local_infile_dict['charge'], local_infile_dict['guess'] = infile_dict['charge'] + 1, False local_infile_dict['run_type'], local_infile_dict['spinmult'] = 'energy', calc local_infile_dict['name'] = name local_infile_dict['levelshifta'], local_infile_dict['levelshiftb'] = 0.25, 0.25 local_infile_dict['machine'] = machine manager_io.write_input(local_infile_dict) manager_io.write_jobscript(name,machine=machine) jobscripts.append(os.path.join(PATH, name + '_jobscript')) os.chdir(home) return jobscripts
def resub_scf(outfile_path): """Resubmits a job that's having trouble converging the scf with different level shifts (1.0 and 0.1). Parameters ---------- outfile_path : str The name of an output file. Returns ------- Resub_flag : bool True if resubmitted. """ # Resubmits a job that's having trouble converging the scf with different level shifts (1.0 and 0.1) history = resub_history() history.read(outfile_path) resubbed_before = False if 'SCF convergence error, level shifts adjusted to aid convergence' in history.notes: resubbed_before = True history.status = os.path.split(outfile_path)[ -1] + ' has been submitted with levels shifted and is still encountering an scf error' history.save() if 'Needs clean resub' in history.notes: resubbed_before = True history.status = os.path.split(outfile_path)[ -1] + ' job recovery has failed - requesting resub_scf() after clean resubmission round' history.save() if not resubbed_before: save_run(outfile_path, rewrite_inscr=False) history = resub_history() history.read(outfile_path) history.resub_number += 1 history.status = 'Level shifts adjusted to assist convergence' history.needs_resub = True history.notes.append('SCF convergence error, level shifts adjusted to aid convergence') history.save() machine=tools.get_machine() root = outfile_path.rsplit('.', 1)[0] name = os.path.split(root)[-1] directory = os.path.split(outfile_path)[0] infile_dict = manager_io.read_infile(outfile_path) home = os.getcwd() if len(directory) > 0: # if the string is blank, then we're already in the correct directory os.chdir(directory) infile_dict['levelshifta'], infile_dict['levelshiftb'] = 1.0, 0.1 infile_dict['machine'] = machine manager_io.write_input(infile_dict) manager_io.write_jobscript(name, machine=machine) os.chdir(home) tools.qsub(root + '_jobscript') return True else: return False
def resub_thermo(outfile_path): # Similar to simple resub, but specific for addressing thermo gradient errors # Checks for the existance of an ultratight version of this run. If it exists, uses the most up to date version for the new thermo run save_run(outfile_path, rewrite_inscr=False) history = resub_history() history.read(outfile_path) history.resub_number += 1 history.status = 'Normal' history.notes.append( 'Resubmitting thermo, possibly with a better initial geo') history.needs_resub = False history.save() name = os.path.split(outfile_path)[-1] name = name.rsplit('.', 1)[0] directory = os.path.split(outfile_path)[0] parent_name = name.rsplit('_', 1)[0] parent_directory = os.path.split(os.path.split(outfile_path)[0])[0] ultratight_dir = os.path.join(parent_directory, parent_name + '_ultratight') infile_dict = manager_io.read_infile(outfile_path) if os.path.exists(ultratight_dir): if os.path.exists(os.path.join(ultratight_dir, 'scr', 'optim.xyz')): tools.extract_optimized_geo( os.path.join(ultratight_dir, 'scr', 'optim.xyz')) shutil.copy(os.path.join(ultratight_dir, 'scr', 'optimized.xyz'), outfile_path.rsplit('.', 1)[0] + '.xyz') else: raise Exception( 'Unable to identify the ultratight geometry for run: ' + outfile_path) if infile_dict['spinmult'] == 1 and os.path.exists( os.path.join(ultratight_dir, 'scr', 'c0')): shutil.copy(os.path.join(ultratight_dir, 'scr', 'c0'), os.path.join(directory, 'c0')) elif infile_dict['spinmult'] != 1 and os.path.exists( os.path.join(ultratight_dir, 'scr', 'ca0')) and os.path.exists( os.path.join(ultratight_dir, 'scr', 'cb0')): shutil.copy(os.path.join(ultratight_dir, 'scr', 'ca0'), os.path.join(directory, 'ca0')) shutil.copy(os.path.join(ultratight_dir, 'scr', 'cb0'), os.path.join(directory, 'cb0')) else: raise Exception( 'Unable to find wavefunction files for ultratight geometry for run: ' + outfile_path) else: raise Exception( 'An ultratight run does not exist for this thermo file. Consider calling simple_resub() or resub_tighter() instead of resub_thermo()' ) jobscript = outfile_path.rsplit('.', 1)[0] + '_jobscript' tools.qsub(jobscript) return True
def read_run(outfile_PATH): # Evaluates all aspects of a run using the outfile and derivative files results = manager_io.read_outfile(outfile_PATH, long_output=True) infile_dict = manager_io.read_infile(outfile_PATH) results['levela'], results['levelb'] = infile_dict['levelshifta'], infile_dict['levelshiftb'] results['method'], results['hfx'] = infile_dict['method'], infile_dict['hfx'] results['constraints'] = infile_dict['constraints'] mullpop_path = os.path.join(os.path.split(outfile_PATH)[0], 'scr', 'mullpop') if os.path.exists(mullpop_path): mullpops = manager_io.read_mullpop(outfile_PATH) metal_types = ['Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Mo', 'Tc', 'Ru', 'Rh'] metals = [i for i in mullpops if i.split()[0] in metal_types] if len(metals) > 1: results['metal_spin'] = np.nan elif len(metals) == 0: pass else: results['metal_spin'] = float(metals[0].split()[-1]) else: results['metal_spin'] = np.nan optim_path = os.path.join(os.path.split(outfile_PATH)[0], 'scr', 'optim.xyz') check_geo = False if os.path.isfile(optim_path): fil = open(optim_path, 'r') lines = fil.readlines() fil.close() if len(lines) > 0: check_geo = True # Only apply geo check if an optimized geometry exists if check_geo: tools.extract_optimized_geo(optim_path) optimized_path = os.path.join(os.path.split(optim_path)[0], 'optimized.xyz') mol = mol3D() mol.readfromxyz(optimized_path) IsOct, flag_list, oct_check = mol.IsOct(dict_check=mol.dict_oct_check_st, silent=True) if IsOct: IsOct = True else: IsOct = False results['Is_Oct'] = IsOct results['Flag_list'] = flag_list results['Oct_check_details'] = oct_check else: results['Is_Oct'] = None results['Flag_list'] = None results['Oct_check_details'] = None return results
def resub_spin(outfile_path): # resubmits a spin contaminated job with blyp to help convergence to a non-spin contaminated solution history = resub_history() history.read(outfile_path) resubbed_before = False if 'Spin contaminated, lowering HFX to aid convergence' in history.notes: resubbed_before = True history.status = os.path.split( outfile_path )[-1] + ' has been submitted with lower HFX and still converges to a spin contaminated solution' history.save() if 'Needs clean resub' in history.notes: resubbed_before = True history.status = os.path.split( outfile_path )[-1] + ' job recovery has failed - requesting resub_spin() after clean resubmission round' history.save() if 'HFXresampling' in outfile_path: resubbed_before = True history.status = os.path.split( outfile_path )[-1] + ' is spin contaminated, but submitting with lower HFX does not make sense for HFX resampling jobs' history.save() if not resubbed_before: save_run(outfile_path, rewrite_inscr=False) history = resub_history() history.read(outfile_path) history.resub_number += 1 history.status = 'HFX altered to assist convergence' history.needs_resub = True history.notes.append( 'Spin contaminated, lowering HFX to aid convergence') history.save() root = outfile_path.rsplit('.', 1)[0] name = os.path.split(root)[-1] directory = os.path.split(outfile_path)[0] infile_dict = manager_io.read_infile(outfile_path) home = os.getcwd() if len( directory ) > 0: # if the string is blank, then we're already in the correct directory os.chdir(directory) infile_dict['method'] = 'blyp' infile_dict['machine'] = machine manager_io.write_input(infile_dict) manager_io.write_jobscript(name, machine=machine) os.chdir(home) tools.qsub(root + '_jobscript') return True else: return False
def clean_resub(outfile_path): # Resubmits a job with default parameters, useful for undoing level shift or hfx alterations save_run(outfile_path) history = resub_history() history.read(outfile_path) history.resub_number += 1 history.status = 'Normal' history.notes.append('Needs clean resub') history.needs_resub = False history.save() root = outfile_path.rsplit('.', 1)[0] name = os.path.split(root)[-1] directory = os.path.split(outfile_path)[0] infile_dict = manager_io.read_infile(outfile_path) home = os.getcwd() if len( directory ) > 0: # if the string is blank, then we're already in the correct directory os.chdir(directory) if os.path.isfile('inscr/optimized.xyz'): coordinates = 'inscr/optimized.xyz' # Should trigger for optimization runs elif os.path.isfile(name + '.xyz'): coordinates = name + '.xyz' # Should trigger for single point runs else: raise ValueError( 'No coordinates idenfied for clean in resubmission in directory ' + os.getcwd()) configure_dict = manager_io.read_configure('in_place', outfile_path) infile_dict['coordinates'] = coordinates infile_dict['method'] = configure_dict['method'] infile_dict['levelshifta'], infile_dict['levelshiftb'] = configure_dict[ 'levela'], configure_dict['levelb'] infile_dict['dispersion'] = configure_dict['dispersion'] infile_dict['constraints'] = False infile_dict['machine'] = machine if infile_dict['spinmult'] == 1: infile_dict['guess'] = 'inscr/c0' manager_io.write_input(infile_dict) else: infile_dict['guess'] = 'inscr/ca0 inscr/cb0' manager_io.write_input(infile_dict) manager_io.write_jobscript(name, custom_line='# -fin inscr/', machine=machine) os.chdir(home) tools.qsub(root + '_jobscript') return True
def resub_oscillating_scf(outfile_path): # Resubmits a job that's having trouble converging the scf with different level shifts (1.0 and 0.1) history = resub_history() history.read(outfile_path) resubbed_before = False if 'SCF convergence error, precision and grid adjusted to aid convergence' in history.notes: resubbed_before = True history.status = os.path.split( outfile_path )[-1] + ' has been submitted with higher precision and grid and is still encountering an scf error' history.save() if 'Needs clean resub' in history.notes: resubbed_before = True history.status = os.path.split( outfile_path )[-1] + ' job recovery has failed - requesting resub_oscillating_scf() after clean resubmission round' history.save() if not resubbed_before: save_run(outfile_path, rewrite_inscr=False) history = resub_history() history.read(outfile_path) history.resub_number += 1 history.status = 'precision and grid adjusted to assist convergence' history.notes.append( 'SCF convergence error, precision and grid adjusted to aid convergence' ) history.save() root = outfile_path.rsplit('.', 1)[0] name = os.path.split(root)[-1] directory = os.path.split(outfile_path)[0] infile_dict = manager_io.read_infile(outfile_path) home = os.getcwd() if len( directory ) > 0: # if the string is blank, then we're already in the correct directory os.chdir(directory) infile_dict['precision'], infile_dict['dftgrid'], infile_dict[ 'dynamicgrid'] = "double", 5, "no" infile_dict['machine'] = machine manager_io.write_input(infile_dict) manager_io.write_jobscript(name, machine=machine) os.chdir(home) tools.qsub(root + '_jobscript') return True else: return False
def prep_thermo(path): # Given a path to the outfile of a finished run, this preps the files for a thermo calculation # Uses the wavefunction from the previous calculation as an initial guess # Returns a list of the PATH(s) to the jobscript(s) to start the solvent sp calculations(s) home = os.getcwd() path = convert_to_absolute_path(path) results = manager_io.read_outfile(path) infile_dict = manager_io.read_infile(path) base = os.path.split(path)[0] if infile_dict['run_type'] == 'minimize': optimxyz = os.path.join(base, 'scr', 'optim.xyz') else: optimxyz = os.path.join(base, 'scr', 'xyz.xyz') extract_optimized_geo(optimxyz) # Now, start generating the new directory name = results['name'] + '_thermo' PATH = os.path.join(base, name) if os.path.isdir(PATH): return ['Thermo Calculation Directory already exists'] os.mkdir(PATH) os.chdir(PATH) shutil.copyfile(os.path.join(base, 'scr', 'optimized.xyz'), os.path.join(PATH, name + '.xyz')) local_infile_dict = copy.copy(infile_dict) local_infile_dict['guess'] = True local_infile_dict['run_type'] = 'frequencies' local_infile_dict['name'] = name manager_io.write_input(local_infile_dict) if infile_dict['spinmult'] == 1: shutil.copyfile(os.path.join(base, 'scr', 'c0'), os.path.join(PATH, 'c0')) manager_io.write_jobscript(name, custom_line='# -fin c0') if infile_dict['spinmult'] != 1: shutil.copyfile(os.path.join(base, 'scr', 'ca0'), os.path.join(PATH, 'ca0')) shutil.copyfile(os.path.join(base, 'scr', 'cb0'), os.path.join(PATH, 'cb0')) manager_io.write_jobscript( name, custom_line=['# -fin ca0\n', '# -fin cb0\n']) os.chdir(home) return [os.path.join(PATH, name + '_jobscript')]
def resub_bad_geo(outfile_path, home_directory): """Resubmits a job that's converged to a bad geometry with additional contraints. Parameters ---------- outfile_path : str The name of an output file. home_directory : str Path to the base directory of the run. Returns ------- Resub_flag : bool True if resubmitted. """ # Resubmits a job that's converged to a bad geometry with additional contraints history = resub_history() history.read(outfile_path) resubbed_before = False if 'Bad geometry detected, adding constraints and trying again' in history.notes: resubbed_before = True history.status = os.path.split(outfile_path)[ -1] + " has been submitted with additional constraints and still isn't a good geometry" history.save() if 'Needs clean resub' in history.notes: resubbed_before = True history.status = os.path.split(outfile_path)[ -1] + ' job recovery has failed - requesting resub_bad_geo after clean resubmission round' history.save() if not resubbed_before: save_run(outfile_path, rewrite_inscr=True) history = resub_history() history.read(outfile_path) history.resub_number += 1 history.status = 'Constraints added to help convergence' history.needs_resub = True history.notes.append('Bad geometry detected, adding constraints and trying again') history.save() machine=tools.get_machine() root = outfile_path.rsplit('.', 1)[0] name = os.path.split(root)[-1] directory = os.path.split(outfile_path)[0] infile_dict = manager_io.read_infile(outfile_path) if infile_dict['constraints']: raise Exception( 'resub.py does not currently support the use of external atom constraints. These will be overwritten by clean_resub() during job recovery') goal_geo = manager_io.read_configure(home_directory, outfile_path)['geo_check'] if not goal_geo: raise Exception( 'Goal geometry not specified, job ' + outfile_path + ' should not have been labelled bad geo!') else: metal_index, bonded_atom_indices = moltools.get_metal_and_bonded_atoms(outfile_path, goal_geo) # convert indexes from zero-indexed to one-indexed metal_index += 1 bonded_atom_indices = [index + 1 for index in bonded_atom_indices] # Convert to TeraChem input syntax constraints = ['bond ' + str(metal_index) + '_' + str(index) + '\n' for index in bonded_atom_indices] home = os.getcwd() if len(directory) > 0: # if the string is blank, then we're already in the correct directory os.chdir(directory) infile_dict['constraints'] = constraints infile_dict['machine'] = machine manager_io.write_input(infile_dict) manager_io.write_jobscript(name, machine=machine) os.chdir(home) tools.qsub(root + '_jobscript') return True else: return False
def prep_ligand_breakown(outfile_path): # Given a path to the outfile of a finished run, this preps the files for rigid ligand dissociation energies of all ligands # Returns a list of the PATH(s) to the jobscript(s) to start the rigid ligand calculations home = os.getcwd() outfile_path = tools.convert_to_absolute_path(outfile_path) results = manager_io.read_outfile(outfile_path) if not results['finished']: raise Exception( 'This calculation does not appear to be complete! Aborting...') infile_dict = manager_io.read_infile(outfile_path) charge = int(infile_dict['charge']) spinmult = int(infile_dict['spinmult']) base = os.path.split(outfile_path)[0] name = os.path.split(outfile_path)[-1][:-4] breakdown_folder = os.path.join(base, name + '_dissociation') if os.path.isdir(breakdown_folder): return ['Ligand dissociation directory already exists'] optimxyz = os.path.join(base, 'scr', 'optim.xyz') tools.extract_optimized_geo(optimxyz) mol = mol3D() mol.readfromxyz(os.path.join(base, 'scr', 'optimized.xyz')) ligand_idxs, _, _ = ligand_breakdown(mol, silent=True) ligand_syms = [] for ii in ligand_idxs: ligand_syms.append([mol.getAtom(i).symbol() for i in ii]) ligand_names = name_ligands(ligand_syms) if not os.path.isdir(breakdown_folder): os.mkdir(breakdown_folder) os.chdir(breakdown_folder) jobscripts = [] for ligand in zip(ligand_names, ligand_idxs): # Assign charges to use during the breakdown for special cases...oxygen, hydroxide, peroxide, and acac # All other ligands are currently assigned charge 0 ligand_charges = {'O1': -2, 'H1O1': -1, 'H1O2': -1, 'C5H7O2': -1} if ligand[0] in list(ligand_charges.keys()): ligand_charge = ligand_charges[ligand[0]] else: ligand_charge = 0 metal_charge = charge - ligand_charge # Assign spin, which always remains with the metal except for when an O2 leaves if spinmult == 1: # If the whole complex is restricted, it's components must be restricted as well ligand_spin, metal_spin = 1, 1 else: ligand_spinmults = {'O2': 3} if ligand[0] in list(ligand_spinmults.keys()): ligand_spin = ligand_spinmults[ligand[0]] else: ligand_spin = 1 metal_spin = spinmult - ligand_spin + 1 # Derived from spinmult = (2S+1) where S=1/2 per electron # Create the necessary files for the metal complex single point local_name = name + '_rm_' + ligand[0] if os.path.isdir('rm_' + ligand[0]): pass else: os.mkdir('rm_' + ligand[0]) os.chdir('rm_' + ligand[0]) local_mol = mol3D() local_mol.copymol3D(mol) local_mol.deleteatoms(ligand[1]) local_mol.writexyz(local_name + '.xyz') local_infile_dict = copy.copy(infile_dict) local_infile_dict['name'] = local_name local_infile_dict['charge'], local_infile_dict[ 'spinmult'] = metal_charge, metal_spin local_infile_dict['run_type'] = 'energy' local_infile_dict['constraints'], local_infile_dict[ 'convergence_thresholds'] = False, False manager_io.write_input(local_infile_dict) manager_io.write_jobscript(local_name, time_limit='12:00:00', sleep=True) jobscripts.append(local_name + '.in') os.chdir('..') # Create the necessary files for the dissociated ligand single point local_name = name + '_kp_' + ligand[0] if os.path.isdir('kp_' + ligand[0]): pass else: os.mkdir('kp_' + ligand[0]) os.chdir('kp_' + ligand[0]) local_mol = mol3D() local_mol.copymol3D(mol) deletion_indices = list( set(range(local_mol.natoms)) - set(ligand[1])) local_mol.deleteatoms(deletion_indices) local_mol.writexyz(local_name + '.xyz') local_infile_dict = copy.copy(infile_dict) local_infile_dict['name'] = local_name local_infile_dict['charge'], local_infile_dict[ 'spinmult'] = ligand_charge, ligand_spin local_infile_dict['run_type'] = 'energy' local_infile_dict['constraints'], local_infile_dict[ 'convergence_thresholds'] = False, False manager_io.write_input(local_infile_dict) manager_io.write_jobscript(local_name, time_limit='12:00:00', sleep=True) jobscripts.append(local_name + '.in') os.chdir('..') os.chdir(home) return jobscripts
def prep_hfx_resample(path, hfx_values=[0, 5, 10, 15, 20, 25, 30]): # Given a path to the outfile of a finished run, this preps the files for hfx resampling # Uses the wavefunction from the gas phase calculation as an initial guess # Returns a list of the PATH(s) to the jobscript(s) to start the resampling calculations(s) home = os.getcwd() path = convert_to_absolute_path(path) base = os.path.split(path)[0] results = manager_io.read_outfile(path) if not results['finished']: raise Exception('This calculation does not appear to be complete! Aborting...') # Check the state of the calculation and ensure than hfx resampling is valid infile_dict = manager_io.read_infile(path) if infile_dict['method'] != 'b3lyp': raise Exception('HFX resampling may not behave well for methods other than b3lyp!') if not infile_dict['hfx']: infile_dict['hfx'] = 20 if infile_dict['hfx'] not in hfx_values: raise Exception('HFX resampling list does not contain the original hfx value!') # Now, start generating the base directory to hold all the hfx resampling values name = results['name'] + '_HFXresampling' hfx_path = os.path.join(base, name) if not os.path.isdir(hfx_path): os.mkdir(hfx_path) os.chdir(hfx_path) # Make the directory for the original calculation subname = name + '_' + str(infile_dict['hfx']) PATH = os.path.join(hfx_path, subname) if not os.path.isdir(PATH): os.mkdir(PATH) os.chdir(PATH) if not os.path.exists(os.path.join(PATH, subname + '.out')): shutil.copyfile(path, subname + '.out') shutil.copyfile(path.rsplit('.', 1)[0] + '_jobscript', subname + '_jobscript') shutil.copyfile(path.rsplit('.', 1)[0] + '.in', subname + '.in') shutil.copytree(os.path.join(os.path.split(path)[0], 'scr'), 'scr') if os.path.exists(path.rsplit('.', 1)[0] + '.xyz'): shutil.copyfile(path.rsplit('.', 1)[0] + '.xyz', subname + '.xyz') # Find the hfx resampling values that we're ready to generate hfx_values_to_generate = [] existing_resampled_values = glob.glob(os.path.join(hfx_path, name + '_*')) for existing in existing_resampled_values: hfx = int(existing.rsplit('_', 1)[1]) subname = name + '_' + str(hfx) outfile_path = os.path.join(existing, subname + '.out') if os.path.exists(outfile_path): if manager_io.read_outfile(outfile_path)['finished']: hfx_values_to_generate.append(hfx - 5) hfx_values_to_generate.append(hfx + 5) hfx_values_to_generate = list(set(hfx_values_to_generate)) hfx_values_to_generate = [i for i in hfx_values_to_generate if i in hfx_values] # Now generate the additional hfx resampling values jobscripts = [] for hfx in hfx_values_to_generate: subname = name + '_' + str(hfx) if os.path.exists(os.path.join(hfx_path, subname)): # skip over values that we've already done continue os.mkdir(os.path.join(hfx_path, subname)) os.chdir(os.path.join(hfx_path, subname)) higher_hfx = subname.rsplit('_', 1)[0] + '_' + str(int(subname.rsplit('_', 1)[1]) + 5) lower_hfx = subname.rsplit('_', 1)[0] + '_' + str(int(subname.rsplit('_', 1)[1]) - 5) if os.path.exists(os.path.join(hfx_path, higher_hfx)): source_dir = os.path.join(hfx_path, higher_hfx) else: source_dir = os.path.join(hfx_path, lower_hfx) if infile_dict['run_type'] == 'minimize': optimxyz = os.path.join(source_dir, 'scr', 'optim.xyz') else: optimxyz = os.path.join(source_dir, 'scr', 'xyz.xyz') extract_optimized_geo(optimxyz) shutil.copy(os.path.join(source_dir, 'scr', 'optimized.xyz'), subname + '.xyz') if infile_dict['spinmult'] == 1: shutil.copy(os.path.join(source_dir, 'scr', 'c0'), 'c0') manager_io.write_jobscript(subname, custom_line='# -fin c0', machine=machine) elif infile_dict['spinmult'] != 1: shutil.copyfile(os.path.join(source_dir, 'scr', 'ca0'), os.path.join('ca0')) shutil.copyfile(os.path.join(source_dir, 'scr', 'cb0'), os.path.join('cb0')) manager_io.write_jobscript(subname, custom_line=['# -fin ca0\n', '# -fin cb0\n'], machine=machine) local_infile_dict = copy.copy(infile_dict) local_infile_dict['guess'] = True local_infile_dict['hfx'] = hfx / 100. local_infile_dict['name'] = subname local_infile_dict['machine'] = machine manager_io.write_input(local_infile_dict) jobscripts.append(os.path.join(os.getcwd(), subname + '_jobscript')) os.chdir(home) return jobscripts
def prep_ultratight(path): # Given a path to the outfile of a finished run, this preps a run with tighter convergence criteria # Uses the wavefunction and geometry from the previous calculation as an initial guess # Returns a list of the PATH(s) to the jobscript(s) to start the solvent sp calculations(s) home = os.getcwd() path = convert_to_absolute_path(path) results = manager_io.read_outfile(path) if not results['finished']: raise Exception('This calculation does not appear to be complete! Aborting...') infile_dict = manager_io.read_infile(path) base = os.path.split(path)[0] if infile_dict['run_type'] == 'minimize': optimxyz = os.path.join(base, 'scr', 'optim.xyz') else: optimxyz = os.path.join(base, 'scr', 'xyz.xyz') extract_optimized_geo(optimxyz) # Now, start generating the new directory name = results['name'] + '_ultratight' PATH = os.path.join(base, name) if not os.path.isdir(PATH): # First time that ultratight has been run, create necessary files os.mkdir(PATH) os.chdir(PATH) if os.path.exists(name + '.in') or os.path.exists(name + '.out') or os.path.exists(name + '_jobscript'): raise Exception('This tightened convergence run appears to already exist. Aborting...') shutil.copyfile(os.path.join(base, 'scr', 'optimized.xyz'), os.path.join(PATH, name + '.xyz')) if infile_dict['spinmult'] == 1: shutil.copyfile(os.path.join(base, 'scr', 'c0'), os.path.join(PATH, 'c0')) manager_io.write_jobscript(name, custom_line='# -fin c0', machine=machine) elif infile_dict['spinmult'] != 1: shutil.copyfile(os.path.join(base, 'scr', 'ca0'), os.path.join(PATH, 'ca0')) shutil.copyfile(os.path.join(base, 'scr', 'cb0'), os.path.join(PATH, 'cb0')) manager_io.write_jobscript(name, custom_line=['# -fin ca0\n', '# -fin cb0\n'], machine=machine) criteria = ['2.25e-04', '1.5e-04', '0.9e-03', '0.6e-03', '0.5e-06', '1.5e-05'] local_infile_dict = copy.copy(infile_dict) local_infile_dict['guess'] = True local_infile_dict['convergence_thresholds'] = criteria local_infile_dict['name'] = name local_infile_dict['machine'] = machine manager_io.write_input(local_infile_dict) # Make an empty .out file to prevent the resubmission module from mistakenly submitting this job twice f = open(name + '.out', 'w') f.close() os.chdir(home) return [os.path.join(PATH, name + '_jobscript')] else: # This has been run before, further tighten the convergence criteria os.chdir(PATH) infile_dict = manager_io.read_infile(os.path.join(PATH, name + '.out')) criteria = [str(float(i) / 2.) for i in infile_dict['convergence_thresholds']] local_infile_dict = copy.copy(infile_dict) local_infile_dict['guess'] = True local_infile_dict['convergence_thresholds'] = criteria local_infile_dict['name'] = name local_infile_dict['machine'] = machine manager_io.write_input(local_infile_dict) extract_optimized_geo(os.path.join(PATH, 'scr', 'optim.xyz')) shutil.copy(os.path.join(PATH, 'scr', 'optimized.xyz'), os.path.join(PATH, name + '.xyz')) os.chdir(home) return [os.path.join(PATH, name + '_jobscript')]
def prep_functionals_sp(path, functionalsSP): home = os.getcwd() path = convert_to_absolute_path(path) results = manager_io.read_outfile(path) if not results['finished']: raise Exception('This calculation does not appear to be complete! Aborting...') infile_dict = manager_io.read_infile(path) base = os.path.split(path)[0] if infile_dict['run_type'] == 'minimize': optimxyz = os.path.join(base, 'scr', 'optim.xyz') else: optimxyz = os.path.join(base, 'scr', 'xyz.xyz') extract_optimized_geo(optimxyz) # Now, start generating the new directory funcname = results['name'] + '_functionalsSP' functional_base_path = os.path.join(base, funcname) if os.path.isdir(functional_base_path): # print('Directory for functional single point already exists') pass else: os.mkdir(functional_base_path) os.chdir(functional_base_path) jobscripts = [] for func in functionalsSP: PATH = os.path.join(functional_base_path, str(func)) if os.path.isdir(PATH): continue ensure_dir(PATH) name = results['name'] + "_functional_" + str(func) shutil.copyfile(os.path.join(base, 'scr', 'optimized.xyz'), os.path.join(PATH, name + '.xyz')) guess = False os.chdir(PATH) if infile_dict['spinmult'] == 1: if os.path.isfile(os.path.join(base, 'scr', 'c0')): shutil.copyfile(os.path.join(base, 'scr', 'c0'), os.path.join(PATH, 'c0')) manager_io.write_jobscript(name, custom_line='# -fin c0', machine=machine) guess = True else: if os.path.isfile(os.path.join(base, 'scr', 'ca0')) and os.path.isfile(os.path.join(base, 'scr', 'cb0')): shutil.copyfile(os.path.join(base, 'scr', 'ca0'), os.path.join(PATH, 'ca0')) shutil.copyfile(os.path.join(base, 'scr', 'cb0'), os.path.join(PATH, 'cb0')) manager_io.write_jobscript(name, custom_line=['# -fin ca0\n', '# -fin cb0\n'], machine=machine) guess = True local_infile_dict = copy.copy(infile_dict) local_infile_dict['guess'] = guess local_infile_dict['run_type'] = 'energy' local_infile_dict['name'] = name local_infile_dict['levelshifta'], local_infile_dict['levelshiftb'] = 0.25, 0.25 local_infile_dict['method'] = func local_infile_dict['machine'] = machine manager_io.write_input(local_infile_dict) fil = open('configure', 'w') fil.write('method:' + func) fil.close() os.chdir(home) jobscripts.append(os.path.join(PATH, name + '_jobscript')) os.chdir(home) return jobscripts
def prep_solvent_sp(path, solvents=[78.9]): # Given a path to the outfile of a finished run, this preps the files for a single point solvent run # Uses the wavefunction from the gas phase calculation as an initial guess # Returns a list of the PATH(s) to the jobscript(s) to start the solvent sp calculations(s) home = os.getcwd() path = convert_to_absolute_path(path) results = manager_io.read_outfile(path) if not results['finished']: raise Exception('This calculation does not appear to be complete! Aborting...') infile_dict = manager_io.read_infile(path) base = os.path.split(path)[0] if infile_dict['run_type'] == 'minimize': optimxyz = os.path.join(base, 'scr', 'optim.xyz') else: optimxyz = os.path.join(base, 'scr', 'xyz.xyz') extract_optimized_geo(optimxyz) # Now, start generating the new directory solname = results['name'] + '_solvent' solvent_base_path = os.path.join(base, solname) # print(solvent_base_path) if os.path.isdir(solvent_base_path): # print('Directory for solvent single point already exists') pass else: os.mkdir(solvent_base_path) os.chdir(solvent_base_path) jobscripts = [] for sol_val in solvents: PATH = os.path.join(solvent_base_path, str(sol_val).replace('.', '_')) if os.path.isdir(PATH): continue ensure_dir(PATH) name = results['name'] + "_solvent_" + str(sol_val) shutil.copyfile(os.path.join(base, 'scr', 'optimized.xyz'), os.path.join(PATH, name + '.xyz')) guess = False os.chdir(PATH) if infile_dict['spinmult'] == 1: if os.path.isfile(os.path.join(base, 'scr', 'c0')): shutil.copyfile(os.path.join(base, 'scr', 'c0'), os.path.join(PATH, 'c0')) manager_io.write_jobscript(name, custom_line='# -fin c0', machine=machine) guess = True else: if os.path.isfile(os.path.join(base, 'scr', 'ca0')) and os.path.isfile(os.path.join(base, 'scr', 'cb0')): shutil.copyfile(os.path.join(base, 'scr', 'ca0'), os.path.join(PATH, 'ca0')) shutil.copyfile(os.path.join(base, 'scr', 'cb0'), os.path.join(PATH, 'cb0')) manager_io.write_jobscript(name, custom_line=['# -fin ca0\n', '# -fin cb0\n'], machine=machine) guess = True local_infile_dict = copy.copy(infile_dict) local_infile_dict['solvent'], local_infile_dict['guess'] = sol_val, guess local_infile_dict['run_type'] = 'energy' local_infile_dict['name'] = name local_infile_dict['levelshifta'], local_infile_dict['levelshiftb'] = 0.25, 0.25 local_infile_dict['machine'] = machine manager_io.write_input(local_infile_dict) os.chdir(home) jobscripts.append(os.path.join(PATH, name + '_jobscript')) os.chdir(home) return jobscripts