Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
def save_scr(outfile_path, rewrite_inscr=True):
    """Archive the scr file so it isn't overwritten in future resubs. 

    Parameters
    ----------
        outfile_path : str
            The name of an output file.
        rewrite_inscr : bool, optional
            Determines whether to copy this runs wfn and optimized geometry to the inscr directory. Default is True.

    Returns
    -------
        scrpaths : str
            Path to new scr directory.

        
    """
    root = os.path.split(outfile_path)[0]
    scr_path = os.path.join(root, 'scr')

    if os.path.isdir(scr_path):
        # extract the optimized geometry, if it exists
        optim = glob.glob(os.path.join(scr_path, 'optim.xyz'))
        if len(optim) > 0:
            tools.extract_optimized_geo(optim[0])

        if rewrite_inscr:
            # save the files necessary to resub the job to a folder called inscr
            save_paths = []
            save_paths.extend(glob.glob(os.path.join(scr_path, 'c0')))
            save_paths.extend(glob.glob(os.path.join(scr_path, 'ca0')))
            save_paths.extend(glob.glob(os.path.join(scr_path, 'cb0')))
            save_paths.extend(glob.glob(os.path.join(scr_path, 'optimized.xyz')))
            if os.path.isdir(os.path.join(root, 'inscr')):
                shutil.rmtree(os.path.join(root, 'inscr'))
            os.mkdir(os.path.join(root, 'inscr'))
            for path in save_paths:
                shutil.copy(path, os.path.join(root, 'inscr', os.path.split(path)[-1]))

        # archive the scr under a new name so that we can write a new one
        old_scrs = glob.glob(scr_path + '_*')
        old_scrs = [int(i[-1]) for i in old_scrs]

        if len(old_scrs) > 0:
            new_scr = str(max(old_scrs) + 1)
        else:
            new_scr = '0'
        # print("current_scr: ", scr_path)
        # print("backup_scr: ", scr_path + '_' + new_scr)
        shutil.move(scr_path, scr_path + '_' + new_scr)

        return os.path.join(os.path.split(outfile_path)[0], 'scr') + '_' + new_scr
Beispiel #4
0
def process_geometry_optimizations(this_run, basedir, outfile, output):
    energy, ss_act, ss_target, tot_time, thermo_grad_error, solvent_cont, tot_step = output.wordgrab(
        ['FINAL', 'S-SQUARED:', 'S-SQUARED:', 'processing', 'Maximum component of gradient is too large',
         'C-PCM contribution to final energy:', 'Optimization Cycle'],
        [2, 2, 4, 3, 0, 4, 3], last_line=True)
    check_conv(this_run, tot_time, energy, output)
    this_run.geo_opt = True
    scrpath = basedir + '/scr/'
    optimpath = scrpath + 'optim.xyz'
    this_run.scrpath = optimpath
    if this_run.converged:
        if os.path.getsize(optimpath) > 45:
            this_run.init_energy = float(output.wordgrab(['FINAL ENERGY'], 'whole_line')[0][0][2])
            try:
                extract_optimized_geo(optimpath)
                this_run.geopath = scrpath + 'optimized.xyz'
            except:
                this_run.geopath = optimpath
            if os.path.isfile(outfile):
                diople_vec, diople_moment = grab_dipole_moment(outfile)
                this_run.diople_vec = diople_vec
                this_run.diople_moment = diople_moment
            else:
                raise ValueError("Output file does not exist: ", outfile)
            read_molden_file(this_run)
            obtain_wavefunction_molden(this_run)
            this_run.init_mol = mol3D()
            this_run.init_mol.readfromtxt(get_initgeo(optimpath))
            this_run.mol = mol3D()
            this_run.mol.readfromtxt(get_lastgeo(optimpath))
            try:
                use_initmol = False if (this_run.iscsd or this_run.isMutation) else True
                this_run.check_oct_needs_init(debug=False, external=True, use_initmol=use_initmol)
            except:
                print("Warning: falied get geo_check!!!")
            ### Note that we should put get_ligsymmetry_graphdet to avoid building the graph for this_run.init_mol before the geocheck
            this_run.init_ligand_symmetry, this_run.init_mol_graph_det = get_ligsymmetry_graphdet(this_run.init_mol)
            this_run.ligand_symmetry, this_run.mol_graph_det = get_ligsymmetry_graphdet(this_run.mol)
            this_run.obtain_rsmd()
            this_run.obtain_ML_dists()
            this_run.get_check_flags()
            this_run.get_optimization_time_step(current_path=outfile)
            if this_run.geo_flag:
                this_run.status = 0
            else:
                this_run.status = 1
        else:
            print(("Warning: optim file %s is empty. Skipping this run." % optimpath))
            this_run.converged = False
    else:
        this_run.status = 7
    return this_run
Beispiel #5
0
def save_scr(outfile_path, rewrite_inscr=True):
    root = os.path.split(outfile_path)[0]
    # print("root: ", root)
    basepath = os.getcwd()
    # print("basepath: ", basepath)
    os.chdir(root)
    root = './'
    scr_path = os.path.join(root, 'scr')

    print("scr_path: ", scr_path)
    if os.path.isdir(scr_path):
        # extract the optimized geometry, if it exists
        optim = glob.glob(os.path.join(scr_path, 'optim.xyz'))
        if len(optim) > 0:
            tools.extract_optimized_geo(optim[0])

        if rewrite_inscr:
            # save the files necessary to resub the job to a folder called inscr
            save_paths = []
            save_paths.extend(glob.glob(os.path.join(scr_path, 'c0')))
            save_paths.extend(glob.glob(os.path.join(scr_path, 'ca0')))
            save_paths.extend(glob.glob(os.path.join(scr_path, 'cb0')))
            save_paths.extend(
                glob.glob(os.path.join(scr_path, 'optimized.xyz')))
            if os.path.isdir(os.path.join(root, 'inscr')):
                shutil.rmtree(os.path.join(root, 'inscr'))
            os.mkdir(os.path.join(root, 'inscr'))
            for path in save_paths:
                shutil.copy(
                    path, os.path.join(root, 'inscr',
                                       os.path.split(path)[-1]))

        # archive the scr under a new name so that we can write a new one
        old_scrs = glob.glob(scr_path + '_*')
        old_scrs = [int(i[-1]) for i in old_scrs]
        print("old_scrs: ", old_scrs)
        if len(old_scrs) > 0:
            new_scr = str(max(old_scrs) + 1)
        else:
            new_scr = '0'
        # print("current_scr: ", scr_path)
        # print("backup_scr: ", scr_path + '_' + new_scr)
        shutil.move(scr_path, scr_path + '_' + new_scr)
        os.chdir(basepath)

        return os.path.join(os.path.split(outfile_path)[0],
                            'scr') + '_' + new_scr
    else:
        os.chdir(basepath)
Beispiel #6
0
def apply_geo_check(job_outfile_path, geometry):
    if geometry:  # The geometry variable is set to False if no geo check is requested for this job

        optim_path = os.path.join(
            os.path.split(job_outfile_path)[0], 'scr', 'optim.xyz')

        if os.path.isfile(optim_path):
            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)
        else:
            # If the optim.xyz doesn't exist, assume that it's a single point and should pass geo check
            return True

        if geometry.capitalize() in ['Oct', 'Octahedral']:
            geo_check_dict = mol.dict_oct_check_st
            IsOct, flag_list, oct_check = mol.IsOct(dict_check=geo_check_dict,
                                                    silent=True)
            if IsOct:
                return True
            else:
                return False

        elif geometry.capitalize() == 'Bidentate_oct':
            # Loosened geo check dict appropriate for bidentates
            geo_check_dict = {
                'num_coord_metal': 6,
                'rmsd_max': 3,
                'atom_dist_max': 0.45,
                'oct_angle_devi_max': 15,
                'max_del_sig_angle': 30,
                'dist_del_eq': 0.35,
                'dist_del_all': 1,
                'devi_linear_avrg': 20,
                'devi_linear_max': 28
            }
            outer_dict_flags = list(mol.dict_oct_check_st.keys())
            final_dict = dict()
            for key in outer_dict_flags:
                final_dict[key] = geo_check_dict

            IsOct, flag_list, oct_check = mol.IsOct(dict_check=final_dict,
                                                    silent=True)
            if IsOct:
                return True
            else:
                return False

        elif geometry.capitalize() == 'Tridentate_oct':
            # Extra loosened geo check dict appropriate for Tridentates
            geo_check_dict = {
                'num_coord_metal': 6,
                'rmsd_max': 3,
                'atom_dist_max': 0.45,
                'oct_angle_devi_max': 25,
                'max_del_sig_angle': 50,
                'dist_del_eq': 0.35,
                'dist_del_all': 1,
                'devi_linear_avrg': 20,
                'devi_linear_max': 28
            }
            outer_dict_flags = list(mol.dict_oct_check_st.keys())
            final_dict = dict()
            for key in outer_dict_flags:
                final_dict[key] = geo_check_dict

            IsOct, flag_list, oct_check = mol.IsOct(dict_check=final_dict,
                                                    silent=True)
            if IsOct:
                return True
            else:
                return False

        else:
            raise Exception('A check has not been implemented for geometry: ' +
                            geoemtry)
    else:
        # print('No geomery check requested for job: '+job_outfile_path)
        # print('Passing job without a geometry check')
        return True
Beispiel #7
0
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