示例#1
0
def set_model_filesys(thy_save_fs, spc_info, level, saddle=False):
    """ Gets filesystem objects for torsional calculations
    """
    # Set the level for the model
    levelp = level[0:3]
    levelp.append(fsorb.orbital_restriction(spc_info, level))

    # Get the save fileystem path
    save_path = thy_save_fs.leaf.path(levelp[1:4])
    if saddle:
        save_fs = autofile.fs.ts(save_path)
        save_fs.trunk.create()
        save_path = save_fs.trunk.path()

    # Get the fs object and the locs
    cnf_save_fs = autofile.fs.conformer(save_path)
    min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)

    # Get the save path for the conformers
    if min_cnf_locs:
        cnf_save_path = cnf_save_fs.leaf.path(min_cnf_locs)
    else:
        cnf_save_path = ''

    return cnf_save_fs, cnf_save_path, min_cnf_locs, save_path
示例#2
0
def assess_pf_convergence(save_prefix, temps=(300., 500., 750., 1000., 1500.)):
    """ Determine how much the partition function has converged
    """
    # Get the energy of the mininimum-energy conformer
    cnf_save_fs = autofile.fs.conformer(save_prefix)
    min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)
    if min_cnf_locs:
        ene_ref = cnf_save_fs.leaf.file.energy.read(min_cnf_locs)

    # Calculate sigma values at various temperatures for the PF
    tau_save_fs = autofile.fs.tau(save_prefix)
    for temp in temps:
        sumq = 0.
        sum2 = 0.
        idx = 0
        print('integral convergence for T = ', temp)
        for locs in tau_save_fs.leaf.existing():
            idx += 1
            ene = tau_save_fs.leaf.file.energy.read(locs)
            ene = (ene - ene_ref) * phycon.EH2KCAL
            tmp = numpy.exp(-ene*349.7/(0.695*temp))
            sumq = sumq + tmp
            sum2 = sum2 + tmp**2
            sigma = numpy.sqrt(
                (abs(sum2/float(idx)-(sumq/float(idx))**2))/float(idx))
            print(sumq/float(idx), sigma, 100.*sigma*float(idx)/sumq, idx)
示例#3
0
def geometry_analysis(tsk,
                      thy_level,
                      ini_filesys,
                      spc,
                      overwrite,
                      saddle=False,
                      selection='min'):
    """ run the specified electronic structure task
    for a set of geometries
    """
    params = {}
    spc_info = finf.get_spc_info(spc)

    print('Task:', tsk)
    if 'conf' in tsk:
        run_dir = ini_filesys[2]
        save_dir = ini_filesys[3]
    elif 'tau' in tsk:
        run_dir = ini_filesys[4]
        save_dir = ini_filesys[5]
    elif 'hr' in tsk:
        run_dir = ini_filesys[6]
        save_dir = ini_filesys[7]
        if saddle:
            params['frm_bnd_key'] = spc['frm_bnd_key']
            params['brk_bnd_key'] = spc['brk_bnd_key']
            print('key test in ts_geom anal:', params['frm_bnd_key'],
                  params['brk_bnd_key'])
    else:
        return
    if isinstance(selection, str):
        if selection == 'all':
            locs_lst = save_dir.leaf.existing()
        elif selection == 'min':
            locs_lst = [fsmin.min_energy_conformer_locators(save_dir)]
    else:
        locs_lst = selection

    sp_script_str, _, kwargs, _ = runpar.run_qchem_par(*thy_level[0:2])
    params['spc_info'] = spc_info
    params['thy_level'] = thy_level
    params['script_str'] = sp_script_str
    params['overwrite'] = overwrite

    # cycle over the locations
    if tsk in ES_TSKS:
        task_call = eval(ES_TSKS[tsk])
        for locs in locs_lst:
            if locs:
                params['geo_run_fs'] = run_dir
                params['geo_save_fs'] = save_dir
                params['locs'] = locs
                task_call(params, kwargs)
            else:
                print('No initial geometry available for {} on {}'.format(
                    spc_info[0], '/'.join(thy_level[1:3])))
示例#4
0
def get_high_level_energy(spc_info,
                          thy_low_level,
                          thy_high_level,
                          save_prefix,
                          saddle=False):
    """ get high level energy at low level optimized geometry
    """
    if saddle:
        spc_save_path = save_prefix
    else:
        spc_save_fs = autofile.fs.species(save_prefix)
        spc_save_fs.leaf.create(spc_info)
        spc_save_path = spc_save_fs.leaf.path(spc_info)

    orb_restr = fsorb.orbital_restriction(spc_info, thy_low_level)
    thy_low_level = thy_low_level[1:3]
    thy_low_level.append(orb_restr)

    ll_save_fs = autofile.fs.theory(spc_save_path)
    ll_save_path = ll_save_fs.leaf.path(thy_low_level)

    if saddle:
        ll_save_fs = autofile.fs.ts(ll_save_path)
        ll_save_fs.trunk.create()
        ll_save_path = ll_save_fs.trunk.path()

    cnf_save_fs = autofile.fs.conformer(ll_save_path)
    min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)
    if not min_cnf_locs:
        print('ERROR: No minimum conformer geometry for ',
              'this species {}'.format(spc_info[0]))
        return 0.0
    cnf_save_path = cnf_save_fs.leaf.path(min_cnf_locs)

    orb_restr = fsorb.orbital_restriction(spc_info, thy_high_level)
    thy_high_level = thy_high_level[1:3]
    thy_high_level.append(orb_restr)

    sp_save_fs = autofile.fs.single_point(cnf_save_path)
    sp_save_fs.leaf.create(thy_high_level)

    if os.path.exists(sp_save_fs.leaf.path(thy_high_level)):
        min_ene = sp_save_fs.leaf.file.energy.read(thy_high_level)
    else:
        print('No energy at path')
        min_ene = None

    return min_ene
示例#5
0
def reagent_energies(save_prefix, rgt_ichs, rgt_chgs, rgt_muls, thy_level):
    """ reagent energies """
    enes = []
    for rgt_ich, rgt_chg, rgt_mul in zip(rgt_ichs, rgt_chgs, rgt_muls):
        spc_save_fs = autofile.fs.species(save_prefix)
        rgt_info = [rgt_ich, rgt_chg, rgt_mul]
        spc_save_path = spc_save_fs.leaf.path(rgt_info)

        orb_restr = fsorb.orbital_restriction(rgt_info, thy_level)
        thy_lvl = thy_level[0:3]
        thy_lvl.append(orb_restr)
        thy_save_fs = autofile.fs.theory(spc_save_path)
        thy_save_path = thy_save_fs.leaf.path(thy_lvl[1:4])
        cnf_save_fs = autofile.fs.conformer(thy_save_path)
        min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)
        ene = cnf_save_fs.leaf.file.energy.read(min_cnf_locs)
        enes.append(ene)
    return enes
示例#6
0
def check_filesys_for_ts(ts_dct, ts_zma, cnf_save_fs, overwrite, typ,
                         dist_info, dist_name, bkp_ts_class_data):
    """ Check if TS is in filesystem and matches original guess
    """
    min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)
    if min_cnf_locs and not overwrite:
        cnf_path = cnf_save_fs.trunk.path()
        print('Found TS at {}'.format(cnf_path))
        zma = cnf_save_fs.leaf.file.zmatrix.read(min_cnf_locs)
        chk_bkp = check_ts_zma(zma, ts_zma, ts_dct)

        # Check if TS is in filesystem and matches original guess
        is_bkp = False
        if chk_bkp and bkp_ts_class_data:
            [bkp_typ, bkp_ts_zma, _, _, bkp_tors_names, _] = bkp_ts_class_data
            is_bkp = check_ts_zma(zma, bkp_ts_zma, ts_dct)

        # Set information in ts_dct as needed
        if not chk_bkp:
            print("TS is type {}".format(typ))
        elif is_bkp:
            print('updating reaction class to {}'.format(bkp_typ))
            ts_dct['class'] = bkp_typ
            ts_dct['original_zma'] = bkp_ts_zma
            ts_dct['tors_names'] = bkp_tors_names
            print("TS is backup type {}".format(bkp_typ))
        else:
            print("TS may not be original type or backup type")
            print("Some part of the z-matrices have changed")

        print('class test:', ts_dct['class'])
        vals = automol.zmatrix.values(zma)
        final_dist = vals[dist_name]
        dist_info[1] = final_dist
        print('dist_info is being set at end of backup checking', dist_info[1],
              final_dist)
        # Add an angle check which is added to spc dct for TS
        angle = lts.check_angle(ts_dct['original_zma'], ts_dct['dist_info'],
                                ts_dct['class'])
        ts_dct['dist_info'][1] = final_dist
        ts_dct['dist_info'].append(angle)

    return ts_dct
示例#7
0
def get_geos(
        spcs, spc_dct, ini_thy_info, save_prefix, run_prefix, kickoff_size,
        kickoff_backward, projrot_script_str):
    """get geos for reactants and products using the initial level of theory
    """
    spc_geos = []
    cnf_save_fs_lst = []
    for spc in spcs:
        spc_info = [spc_dct[spc]['ich'],
                    spc_dct[spc]['chg'],
                    spc_dct[spc]['mul']]
        orb_restr = fsorb.orbital_restriction(spc_info, ini_thy_info)
        ini_thy_level = ini_thy_info[0:3]
        ini_thy_level.append(orb_restr)
        spc_save_fs = autofile.fs.species(save_prefix)
        spc_save_fs.leaf.create(spc_info)
        spc_save_path = spc_save_fs.leaf.path(spc_info)
        spc_run_fs = autofile.fs.species(run_prefix)
        spc_run_fs.leaf.create(spc_info)
        spc_run_path = spc_run_fs.leaf.path(spc_info)
        ini_thy_save_fs = autofile.fs.theory(spc_save_path)
        ini_thy_save_path = ini_thy_save_fs.leaf.path(ini_thy_level[1:4])
        ini_thy_run_fs = autofile.fs.theory(spc_run_path)
        ini_thy_run_path = ini_thy_run_fs.leaf.path(ini_thy_level[1:4])
        cnf_save_fs = autofile.fs.conformer(ini_thy_save_path)
        cnf_save_fs_lst.append(cnf_save_fs)
        cnf_run_fs = autofile.fs.conformer(ini_thy_run_path)
        min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)
        if min_cnf_locs:
            geo = cnf_save_fs.leaf.file.geometry.read(min_cnf_locs)
        else:
            run_fs = autofile.fs.run(ini_thy_run_path)
            run_fs.trunk.create()
            tmp_ini_fs = [None, ini_thy_save_fs]
            tmp_fs = [spc_save_fs, spc_run_fs, ini_thy_save_fs, ini_thy_run_fs,
                      cnf_save_fs, cnf_run_fs, run_fs]
            geo = geom.reference_geometry(
                spc_dct[spc], ini_thy_level, ini_thy_level, tmp_fs, tmp_ini_fs,
                kickoff_size, kickoff_backward, projrot_script_str,
                overwrite=False)
        spc_geos.append(geo)
    return spc_geos, cnf_save_fs_lst
示例#8
0
def write_tau_data_str(name, save_prefix, gradient=False, hessian=False):
    """ Write out data fle for partition function evaluation
    """
    cnf_save_fs = autofile.fs.conformer(save_prefix)
    min_cnf_locs = fmin.min_energy_conformer_locators(cnf_save_fs)
    if min_cnf_locs:
        ene_ref = cnf_save_fs.leaf.file.energy.read(min_cnf_locs)

    tau_save_fs = autofile.fs.tau(save_prefix)
    evr = name + '\n'
    # cycle through saved tau geometries
    idx = 0
    for locs in tau_save_fs.leaf.existing():
        geo = tau_save_fs.leaf.file.geometry.read(locs)
        ene = tau_save_fs.leaf.file.energy.read(locs)
        ene = (ene - ene_ref) * phycon.EH2KCAL
        ene_str = autofile.file.write.energy(ene)
        geo_str = autofile.file.write.geometry(geo)

        idx += 1
        idx_str = str(idx)

        evr += 'Sampling point' + idx_str + '\n'
        evr += 'Energy' + '\n'
        evr += ene_str + '\n'
        evr += 'Geometry' + '\n'
        evr += geo_str + '\n'
        if gradient:
            grad = tau_save_fs.leaf.file.gradient.read(locs)
            grad_str = autofile.file.write.gradient(grad)
            evr += 'Gradient' + '\n'
            evr += grad_str
        if hessian:
            hess = tau_save_fs.leaf.file.hessian.read(locs)
            hess_str = autofile.file.write.hessian(hess)
            evr += 'Hessian' + '\n'
            evr += hess_str + '\n'

    return evr
示例#9
0
def check_save(save_fs, tsk, obj):
    """ check if information exists in a save directory for
        conformers, tau, scan
    """
    print('save fs leaf exist')
    print(save_fs.leaf.existing())
    print(save_fs.leaf.existing()[0])
    print([save_fs.leaf.existing()[0]])
    assert obj in ('conf', 'tau', 'scan')
    avail = True
    if obj == 'conf':
        save_locs = fsmin.min_energy_conformer_locators(save_fs)
    # Doesn't work well for tau since there are multipole tau we wish to comp
    elif obj == 'tau':
        save_locs = save_fs.leaf.existing()[0]
    else:
        save_locs = [save_fs.leaf.existing()[0]]
    if not save_locs:
        printmsg.ini_info_noavail_msg(tsk)
        avail = False
    elif not save_fs.leaf.file.geometry.exists(save_locs):
        printmsg.ini_info_noavail_msg(tsk)
        avail = False
    return avail
示例#10
0
def find_ts(spc_dct,
            ts_dct,
            ts_zma,
            ini_thy_info,
            thy_info,
            run_prefix,
            save_prefix,
            overwrite,
            rad_rad_ts='vtst'):
    """ find the ts geometry
    """

    # Set various TS information using the dictionary
    typ = ts_dct['class']
    dist_info = ts_dct['dist_info']
    grid = ts_dct['grid']
    bkp_ts_class_data = ts_dct['bkp_data']
    rad_rad = ('radical radical' in typ)
    low_spin = ('low spin' in typ)
    print('prepping ts scan for:', typ)

    [_, _, rxn_run_path, rxn_save_path] = ts_dct['rxn_fs']
    ts_info = (ts_dct['ich'], ts_dct['chg'], ts_dct['mul'])

    _, opt_script_str, _, opt_kwargs = runpar.run_qchem_par(*thy_info[0:2])

    orb_restr = fsorb.orbital_restriction(ts_info, thy_info)
    ref_level = thy_info[0:3]
    ref_level.append(orb_restr)

    thy_run_fs = autofile.fs.theory(rxn_run_path)
    thy_run_fs.leaf.create(ref_level[1:4])
    thy_run_path = thy_run_fs.leaf.path(ref_level[1:4])

    thy_save_fs = autofile.fs.theory(rxn_save_path)
    thy_save_fs.leaf.create(ref_level[1:4])
    thy_save_path = thy_save_fs.leaf.path(ref_level[1:4])

    scn_run_fs = autofile.fs.scan(thy_run_path)
    scn_save_fs = autofile.fs.scan(thy_save_path)

    ts_run_fs = autofile.fs.ts(thy_run_path)
    ts_run_fs.trunk.create()
    ts_run_path = ts_run_fs.trunk.path()
    run_fs = autofile.fs.run(ts_run_path)

    ts_save_fs = autofile.fs.ts(thy_save_path)
    ts_save_fs.trunk.create()
    ts_save_path = ts_save_fs.trunk.path()

    cnf_run_fs = autofile.fs.conformer(ts_run_path)
    cnf_save_fs = autofile.fs.conformer(ts_save_path)
    cnf_save_fs.trunk.create()

    # Unpack the dist info
    dist_name, _, update_guess, brk_name = dist_info

    # Get TS from filesys or get it from some procedure
    min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)
    if min_cnf_locs and not overwrite:
        check_filesys_for_ts(ts_dct, ts_zma, cnf_save_fs, overwrite, typ,
                             dist_info, dist_name, bkp_ts_class_data)
    else:
        filesys = [
            None, None, ts_run_fs, ts_save_fs, cnf_run_fs, cnf_save_fs, None,
            None, scn_run_fs, scn_save_fs, run_fs
        ]
        print('running ts scan:')
        if rad_rad and low_spin and 'elimination' not in ts_dct['class']:
            print('Running Scan for Barrierless TS:')
            find_barrierless_transition_state(
                ts_info, ts_zma, ts_dct, spc_dct, grid, dist_name,
                rxn_run_path, rxn_save_path, rad_rad_ts, ini_thy_info,
                thy_info, run_prefix, save_prefix, scn_run_fs, scn_save_fs,
                opt_script_str, overwrite, update_guess, **opt_kwargs)
            # Have code analyze the path and switch to a sadpt finder if needed
        else:
            print('Running Scan for Fixed TS:')
            max_zma = run_sadpt_scan(typ, grid, dist_name, brk_name, ts_zma,
                                     ts_info, ref_level, scn_run_fs,
                                     scn_save_fs, opt_script_str, overwrite,
                                     update_guess, **opt_kwargs)
            geo, zma, final_dist = find_sadpt_transition_state(
                opt_script_str, run_fs, max_zma, ts_info, ref_level, overwrite,
                ts_save_path, ts_save_fs, dist_name, dist_info, filesys,
                **opt_kwargs)

    return geo, zma, final_dist
示例#11
0
def set_fs(spc_dct, spc, thy_info,
           run_prefix, save_prefix,
           setfs_chk=True, ini_fs=False):
    """ set up filesystem """

    # Build the species filesys objs
    [spc_info,
     spc_run_fs, spc_save_fs,
     spc_run_path, spc_save_path] = set_spc_fs(
         spc_dct, spc, run_prefix, save_prefix)

    # Initialize the filesystems
    thy_run_fs = None
    thy_run_path = None
    thy_save_fs = None
    thy_save_path = None
    cnf_run_fs = None
    cnf_save_fs = None
    tau_run_fs = None
    tau_save_fs = None
    thy_level = thy_info
    scn_run_fs = None
    scn_save_fs = None

    # Build the theory filesys obj
    thy_level = thy_info
    orb_restr = fsorb.orbital_restriction(
        spc_info, thy_info)
    thy_level = thy_info[0:3]
    thy_level.append(orb_restr)
    thy_run_fs = autofile.fs.theory(spc_run_path)
    thy_save_fs = autofile.fs.theory(spc_save_path)

    if setfs_chk:
        if 'ts_' in spc:
            thy_run_fs.leaf.create(thy_level[1:4])
            thy_run_path = thy_run_fs.leaf.path(thy_level[1:4])
            thy_save_fs.leaf.create(thy_level[1:4])
            thy_save_path = thy_save_fs.leaf.path(thy_level[1:4])

            thy_run_fs = autofile.fs.ts(thy_run_path)
            thy_run_fs.trunk.create()
            thy_run_path = thy_run_fs.trunk.path()

            thy_save_fs = autofile.fs.ts(thy_save_path)
            thy_save_fs.trunk.create()
            thy_save_path = thy_save_fs.trunk.path()

        else:
            thy_run_fs.leaf.create(thy_level[1:4])
            thy_run_path = thy_run_fs.leaf.path(thy_level[1:4])
            thy_save_fs.leaf.create(thy_level[1:4])
            thy_save_path = thy_save_fs.leaf.path(thy_level[1:4])

        cnf_run_fs = autofile.fs.conformer(thy_run_path)
        cnf_save_fs = autofile.fs.conformer(thy_save_path)
        tau_run_fs = autofile.fs.tau(thy_run_path)
        tau_save_fs = autofile.fs.tau(thy_save_path)
        min_cnf_locs = fsmin.min_energy_conformer_locators(
            cnf_save_fs)
        if min_cnf_locs:
            min_cnf_run_path = cnf_run_fs.leaf.path(min_cnf_locs)
            min_cnf_save_path = cnf_save_fs.leaf.path(min_cnf_locs)
            scn_run_fs = autofile.fs.conformer(min_cnf_run_path)
            scn_save_fs = autofile.fs.conformer(min_cnf_save_path)

    # filesys = [spc_run_fs, spc_save_fs, thy_run_fs, thy_save_fs,
    #            cnf_run_fs, cnf_save_fs, tau_run_fs, tau_save_fs,
    #            scn_run_fs, scn_save_fs]

    # Add run fs if needed
    if not ini_fs:
        filesys = [spc_run_fs, spc_save_fs, 
                   thy_run_fs, thy_save_fs,
                   cnf_run_fs, cnf_save_fs,
                   tau_run_fs, tau_save_fs,
                   scn_run_fs, scn_save_fs]
        run_fs = autofile.fs.run(thy_run_path)
        run_fs.trunk.create()
        filesys.append(run_fs)
    else:
        filesys = [thy_run_fs, thy_save_fs,
                   cnf_run_fs, cnf_save_fs,
                   tau_run_fs, tau_save_fs,
                   scn_run_fs, scn_save_fs]

    return filesys, thy_level
示例#12
0
def conformer_sampling(spc_info,
                       thy_level,
                       thy_save_fs,
                       cnf_run_fs,
                       cnf_save_fs,
                       script_str,
                       overwrite,
                       saddle=False,
                       nsamp_par=(False, 3, 3, 1, 50, 50),
                       tors_names='',
                       dist_info=(),
                       two_stage=False,
                       rxn_class='',
                       **kwargs):
    """ Find the minimum energy conformer by optimizing from nsamp random
    initial torsional states
    """

    ich = spc_info[0]
    coo_names = []
    if not saddle:
        geo = thy_save_fs.leaf.file.geometry.read(thy_level[1:4])
        tors_names = automol.geom.zmatrix_torsion_coordinate_names(geo)
        zma = automol.geom.zmatrix(geo)
    else:
        geo = thy_save_fs.trunk.file.geometry.read()
        zma = thy_save_fs.trunk.file.zmatrix.read()
        coo_names.append(tors_names)

    tors_ranges = tuple((0, 2 * numpy.pi) for tors in tors_names)
    tors_range_dct = dict(zip(tors_names, tors_ranges))
    if not saddle:
        gra = automol.inchi.graph(ich)
        ntaudof = len(
            automol.graph.rotational_bond_keys(gra, with_h_rotors=False))
        nsamp = util.nsamp_init(nsamp_par, ntaudof)
    else:
        ntaudof = len(tors_names)
        nsamp = util.nsamp_init(nsamp_par, ntaudof)

    save_conformers(cnf_run_fs=cnf_run_fs,
                    cnf_save_fs=cnf_save_fs,
                    saddle=saddle,
                    dist_info=dist_info,
                    rxn_class=rxn_class)

    run_conformers(
        zma=zma,
        spc_info=spc_info,
        thy_level=thy_level,
        nsamp=nsamp,
        tors_range_dct=tors_range_dct,
        cnf_run_fs=cnf_run_fs,
        cnf_save_fs=cnf_save_fs,
        script_str=script_str,
        overwrite=overwrite,
        saddle=saddle,
        two_stage=two_stage,
        **kwargs,
    )
    save_conformers(cnf_run_fs=cnf_run_fs,
                    cnf_save_fs=cnf_save_fs,
                    saddle=saddle,
                    dist_info=dist_info,
                    rxn_class=rxn_class)

    # save information about the minimum energy conformer in top directory
    min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)
    if min_cnf_locs:
        geo = cnf_save_fs.leaf.file.geometry.read(min_cnf_locs)
        zma = cnf_save_fs.leaf.file.zmatrix.read(min_cnf_locs)
        if not saddle:
            assert automol.zmatrix.almost_equal(zma, automol.geom.zmatrix(geo))
            thy_save_fs.leaf.file.geometry.write(geo, thy_level[1:4])
            thy_save_fs.leaf.file.zmatrix.write(zma, thy_level[1:4])

        else:
            thy_save_fs.trunk.file.geometry.write(geo)
            thy_save_fs.trunk.file.zmatrix.write(zma)
示例#13
0
def hindered_rotor_scans(spc_info,
                         thy_level,
                         cnf_run_fs,
                         cnf_save_fs,
                         script_str,
                         overwrite,
                         scan_increment=30.0,
                         saddle=False,
                         run_tors_names=(),
                         frm_bnd_key=(),
                         brk_bnd_key=(),
                         tors_model=('1dhr', False),
                         **opt_kwargs):
    """ Perform 1d scans over each of the torsional coordinates
    """

    # Unpack tors model
    ndim_tors, freeze_all_tors = tors_model

    # Run with the old code
    min_cnf_locs = fsmin.min_energy_conformer_locators(cnf_save_fs)
    if min_cnf_locs:
        min_cnf_run_path = cnf_run_fs.leaf.path(min_cnf_locs)
        min_cnf_save_path = cnf_save_fs.leaf.path(min_cnf_locs)
        scn_run_fs = autofile.fs.scan(min_cnf_run_path)
        scn_save_fs = autofile.fs.scan(min_cnf_save_path)
        geo = cnf_save_fs.leaf.file.geometry.read(min_cnf_locs)
        zma = cnf_save_fs.leaf.file.zmatrix.read(min_cnf_locs)

        run_tors_names, run_tors_grids = hr_prep(zma,
                                                 geo,
                                                 run_tors_names=(),
                                                 scan_increment=scan_increment,
                                                 ndim_tors=ndim_tors,
                                                 saddle=saddle,
                                                 frm_bnd_key=frm_bnd_key,
                                                 brk_bnd_key=brk_bnd_key)

        print('TEST: run_tors_names')
        print(run_tors_names)
        print(run_tors_grids)
        # import sys
        # sys.exit()

        print('TEST: in loop')
        # for tors_name, tors_grid in zip(tors_names, tors_grids):
        for tors_names, tors_grids in zip(run_tors_names, run_tors_grids):

            # Get the dictionary for the torsional modes
            print(tors_names)
            print(tors_grids)
            if not tors_names:
                continue
            grid_dct = dict(zip(tors_names, tors_grids))

            # Get a list of the other tors coords to freeze
            print('freeze variable', freeze_all_tors)
            if freeze_all_tors:
                alt_constraints = [
                    name for name_lst in run_tors_names for name in name_lst
                ]
            else:
                alt_constraints = ()
            print('alt_constraints')
            print(alt_constraints)

            # Perform the scans
            save_scan(
                scn_run_fs=scn_run_fs,
                scn_save_fs=scn_save_fs,
                coo_names=tors_names,
            )

            run_scan(
                zma=zma,
                spc_info=spc_info,
                thy_level=thy_level,
                grid_dct=grid_dct,
                scn_run_fs=scn_run_fs,
                scn_save_fs=scn_save_fs,
                script_str=script_str,
                overwrite=overwrite,
                saddle=saddle,
                alt_constraints=alt_constraints,
                **opt_kwargs,
            )

            save_scan(
                scn_run_fs=scn_run_fs,
                scn_save_fs=scn_save_fs,
                coo_names=tors_names,
            )
示例#14
0
def infinite_separation_energy(spc_1_info,
                               spc_2_info,
                               ts_info,
                               high_mul,
                               ref_zma,
                               ini_thy_info,
                               thy_info,
                               multi_info,
                               run_prefix,
                               save_prefix,
                               scn_run_fs,
                               scn_save_fs,
                               locs,
                               overwrite=False,
                               num_act_elc=None,
                               num_act_orb=None):
    """ Obtain the infinite separation energy from the multireference energy
        at a given reference point, the high-spin low-spin splitting at that
        reference point, and the high level energy for the high spin state
        at the reference geometry and for the fragments
    """

    # Initialize infinite sep energy
    inf_sep_ene = -1.0e12

    # set up all the file systems for the TS
    # start with the geo and reference theory info
    geo_run_path = scn_run_fs.leaf.path(locs)
    geo_save_path = scn_save_fs.leaf.path(locs)
    geo = scn_save_fs.leaf.file.geometry.read(locs)
    sp_run_fs = autofile.fs.single_point(geo_run_path)
    sp_save_fs = autofile.fs.single_point(geo_save_path)

    # get the multi reference ene for low spin state for the ref point on scan

    # file system for low spin multireference calculation

    multi_info[0] = 'molpro2015'
    multi_info[1] = 'caspt2'
    # ultimately the above should be properly passed
    prog = multi_info[0]
    method = multi_info[1]

    # get the multi reference energy for high spin state for ref point on scan
    hs_info = (ts_info[0], ts_info[1], high_mul)
    orb_restr = fsorb.orbital_restriction(hs_info, multi_info)
    multi_lvl = multi_info[0:3]
    multi_lvl.append(orb_restr)

    hs_run_fs = autofile.fs.high_spin(geo_run_path)
    hs_save_fs = autofile.fs.high_spin(geo_save_path)
    hs_run_fs.leaf.create(multi_lvl[1:4])
    hs_save_fs.leaf.create(multi_lvl[1:4])

    hs_mr_run_path = hs_run_fs.leaf.path(multi_lvl[1:4])
    hs_mr_save_path = hs_save_fs.leaf.path(multi_lvl[1:4])
    run_mr_fs = autofile.fs.run(hs_mr_run_path)

    mr_script_str, _, mr_kwargs, _ = runpar.run_qchem_par(prog, method)

    if num_act_elc is None and num_act_orb is None:
        num_act_elc = high_mul
        num_act_orb = num_act_elc
    ts_formula = automol.geom.formula(automol.zmatrix.geometry(ref_zma))

    cas_opt, _ = ts.cas_options_2(hs_info, ts_formula, num_act_elc,
                                  num_act_orb, high_mul)
    guess_str = ts.multiref_wavefunction_guess(high_mul, ref_zma, hs_info,
                                               multi_lvl, [cas_opt])
    guess_lines = guess_str.splitlines()

    mr_kwargs['casscf_options'] = cas_opt
    mr_kwargs['mol_options'] = ['nosym']
    mr_kwargs['gen_lines'] = {1: guess_lines}

    ret = driver.read_job(
        job='energy',
        run_fs=run_mr_fs,
    )
    if ret:
        print(" - Reading high spin multi reference energy from output...")
        inf_obj, inp_str, out_str = ret
        ene = elstruct.reader.energy(inf_obj.prog, inf_obj.method, out_str)
        hs_save_fs.leaf.file.energy.write(ene, multi_lvl[1:4])
        hs_save_fs.leaf.file.input.write(inp_str, multi_lvl[1:4])
        hs_save_fs.leaf.file.info.write(inf_obj, multi_lvl[1:4])

    if not hs_save_fs.leaf.file.energy.exists(multi_lvl[1:4]) or overwrite:
        print(" - Running high spin multi reference energy ...")
        driver.run_job(
            job='energy',
            script_str=mr_script_str,
            run_fs=run_mr_fs,
            geom=geo,
            spc_info=hs_info,
            thy_level=multi_lvl,
            overwrite=overwrite,
            **mr_kwargs,
        )

        ret = driver.read_job(
            job='energy',
            run_fs=run_mr_fs,
        )

        if ret is not None:
            inf_obj, inp_str, out_str = ret

            print(" - Reading high spin multi reference energy from output...")
            hs_mr_ene = elstruct.reader.energy(inf_obj.prog, inf_obj.method,
                                               out_str)

            print(" - Saving high spin multi reference energy...")
            print(" - Save path: {}".format(hs_mr_save_path))
            hs_save_fs.leaf.file.energy.write(hs_mr_ene, multi_lvl[1:4])
            hs_save_fs.leaf.file.input.write(inp_str, multi_lvl[1:4])
            hs_save_fs.leaf.file.info.write(inf_obj, multi_lvl[1:4])
        else:
            print('ERROR: high spin multi reference energy job fails: ',
                  'Energy is needed to evaluate infinite separation energy')
            return inf_sep_ene

    else:
        hs_mr_ene = hs_save_fs.leaf.file.energy.read(multi_lvl[1:4])

    # file system for high spin single ireference calculation
    thy_info = ['molpro2015', 'ccsd(t)-f12', 'cc-pvdz-f12', 'RR']
    orb_restr = fsorb.orbital_restriction(hs_info, thy_info)
    thy_lvl = thy_info[0:3]
    thy_lvl.append(orb_restr)

    hs_run_fs.leaf.create(thy_lvl[1:4])
    hs_save_fs.leaf.create(thy_lvl[1:4])

    hs_sr_run_path = hs_run_fs.leaf.path(thy_lvl[1:4])
    hs_sr_save_path = hs_save_fs.leaf.path(thy_lvl[1:4])
    run_sr_fs = autofile.fs.run(hs_sr_run_path)

    sp_script_str, _, kwargs, _ = runpar.run_qchem_par(*thy_lvl[0:2])
    ret = driver.read_job(
        job='energy',
        run_fs=run_sr_fs,
    )
    if ret:
        print(" - Reading high spin single reference energy from output...")
        inf_obj, inp_str, out_str = ret
        ene = elstruct.reader.energy(inf_obj.prog, inf_obj.method, out_str)
        hs_save_fs.leaf.file.energy.write(ene, thy_lvl[1:4])
        hs_save_fs.leaf.file.input.write(inp_str, thy_lvl[1:4])
        hs_save_fs.leaf.file.info.write(inf_obj, thy_lvl[1:4])

    if not hs_save_fs.leaf.file.energy.exists(thy_lvl[1:4]) or overwrite:
        print(" - Running high spin single reference energy ...")

        errors, options_mat = runpar.set_molpro_options_mat(hs_info, geo)

        driver.run_job(
            job='energy',
            script_str=sp_script_str,
            run_fs=run_sr_fs,
            geom=geo,
            spc_info=hs_info,
            thy_level=thy_lvl,
            errors=errors,
            options_mat=options_mat,
            overwrite=overwrite,
            **kwargs,
        )

        ret = driver.read_job(
            job='energy',
            run_fs=run_sr_fs,
        )

        if ret is not None:
            inf_obj, inp_str, out_str = ret

            print(" - Reading high spin single ref energy from output...")
            hs_sr_ene = elstruct.reader.energy(inf_obj.prog, inf_obj.method,
                                               out_str)

            print(" - Saving high spin single reference energy...")
            print(" - Save path: {}".format(hs_sr_save_path))
            hs_save_fs.leaf.file.energy.write(hs_sr_ene, thy_lvl[1:4])
            hs_save_fs.leaf.file.input.write(inp_str, thy_lvl[1:4])
            hs_save_fs.leaf.file.info.write(inf_obj, thy_lvl[1:4])
        else:
            print('ERROR: High spin single reference energy job fails: ',
                  'Energy is needed to evaluate infinite separation energy')
            return inf_sep_ene

    else:
        hs_sr_ene = hs_save_fs.leaf.file.energy.read(thy_lvl[1:4])

    # get the single reference energy for each of the reactant configurations
    spc_ene = []
    spc_infos = [spc_1_info, spc_2_info]
    for spc_info in spc_infos:
        # set up the file systems for the reactants one by one
        spc_run_fs = autofile.fs.species(run_prefix)
        spc_run_fs.leaf.create(spc_info)
        spc_run_path = spc_run_fs.leaf.path(spc_info)
        spc_save_fs = autofile.fs.species(save_prefix)
        spc_save_fs.leaf.create(spc_info)
        spc_save_path = spc_save_fs.leaf.path(spc_info)

        orb_restr = fsorb.orbital_restriction(spc_info, ini_thy_info)
        ini_thy_lvl = ini_thy_info[0:3]
        ini_thy_lvl.append(orb_restr)

        orb_restr = fsorb.orbital_restriction(spc_info, thy_info)
        thy_lvl = thy_info[0:3]
        thy_lvl.append(orb_restr)

        ini_thy_run_fs = autofile.fs.theory(spc_run_path)
        ini_thy_run_fs.leaf.create(ini_thy_lvl[1:4])
        ini_thy_run_path = ini_thy_run_fs.leaf.path(ini_thy_lvl[1:4])
        ini_thy_save_fs = autofile.fs.theory(spc_save_path)
        ini_thy_save_fs.leaf.create(ini_thy_lvl[1:4])
        ini_thy_save_path = ini_thy_save_fs.leaf.path(ini_thy_lvl[1:4])
        ini_cnf_run_fs = autofile.fs.conformer(ini_thy_run_path)
        ini_cnf_save_fs = autofile.fs.conformer(ini_thy_save_path)
        min_cnf_locs = fsmin.min_energy_conformer_locators(ini_cnf_save_fs)
        min_cnf_run_path = ini_cnf_run_fs.leaf.path(min_cnf_locs)
        min_cnf_save_path = ini_cnf_save_fs.leaf.path(min_cnf_locs)

        thy_run_fs = autofile.fs.theory(spc_run_path)
        thy_run_fs.leaf.create(thy_lvl[1:4])
        thy_save_fs = autofile.fs.theory(spc_save_path)
        thy_save_fs.leaf.create(thy_lvl[1:4])

        geo = ini_cnf_save_fs.leaf.file.geometry.read(min_cnf_locs)

        sp_run_fs = autofile.fs.single_point(min_cnf_run_path)
        sp_run_fs.leaf.create(thy_lvl[1:4])
        sp_save_fs = autofile.fs.single_point(min_cnf_save_path)
        sp_save_fs.leaf.create(thy_lvl[1:4])

        sp_sr_run_path = sp_run_fs.leaf.path(thy_lvl[1:4])
        sp_sr_save_path = sp_save_fs.leaf.path(thy_lvl[1:4])
        print('sp_sr_run_path')
        print(sp_sr_run_path)
        run_sr_fs = autofile.fs.run(sp_sr_run_path)

        ret = driver.read_job(
            job='energy',
            run_fs=run_sr_fs,
        )
        if ret:
            print(" - Reading single reference energy for",
                  "{} from output...".format(spc_info[0]))
            inf_obj, inp_str, out_str = ret
            ene = elstruct.reader.energy(inf_obj.prog, inf_obj.method, out_str)
            sp_save_fs.leaf.file.energy.write(ene, thy_lvl[1:4])
            sp_save_fs.leaf.file.input.write(inp_str, thy_lvl[1:4])
            sp_save_fs.leaf.file.info.write(inf_obj, thy_lvl[1:4])

        if not sp_save_fs.leaf.file.energy.exists(thy_lvl[1:4]) or overwrite:
            print(" - Running single reference energy for",
                  "{} from output...".format(spc_info[0]))
            driver.run_job(
                job='energy',
                script_str=sp_script_str,
                run_fs=run_sr_fs,
                geom=geo,
                spc_info=spc_info,
                thy_level=thy_lvl,
                overwrite=overwrite,
                **kwargs,
            )

            ret = driver.read_job(
                job='energy',
                run_fs=run_sr_fs,
            )

            if ret is not None:
                inf_obj, inp_str, out_str = ret

                print(" - Reading single reference energy for ",
                      "{} from output...".format(spc_info[0]))
                sp_sr_ene = elstruct.reader.energy(inf_obj.prog,
                                                   inf_obj.method, out_str)

                print(" - Saving single reference energy for ",
                      "{} from output...".format(spc_info[0]))
                print(" - Save path: {}".format(sp_sr_save_path))
                sp_save_fs.leaf.file.energy.write(sp_sr_ene, thy_lvl[1:4])
                sp_save_fs.leaf.file.input.write(inp_str, thy_lvl[1:4])
                sp_save_fs.leaf.file.info.write(inf_obj, thy_lvl[1:4])

            else:
                print('ERROR: Single reference energy job fails',
                      'for {}: '.format(spc_info[0]),
                      'Energy needed to evaluate infinite separation energy')
                return inf_sep_ene

        else:
            sp_sr_ene = sp_save_fs.leaf.file.energy.read(thy_lvl[1:4])

        spc_ene.append(sp_sr_ene)

    inf_sep_ene = spc_ene[0] + spc_ene[1] - hs_sr_ene + hs_mr_ene

    return inf_sep_ene