Esempio n. 1
0
def run_onedmin(spc_name, spc_dct, thy_dct, etrans_keyword_dct, run_prefix,
                save_prefix):
    """ Run the task
    """

    bath_name = etrans_keyword_dct['bath']

    tgt_dct, bath_dct = spc_dct[spc_name], spc_dct[bath_name]
    tgt_info = filesys.inf.get_spc_info(tgt_dct)
    bath_info = filesys.inf.get_spc_info(bath_dct)
    lj_info = filesys.inf.combine_spc_info(tgt_info, bath_info)

    # Build the modified thy objs
    inp_thy_info = filesys.inf.get_es_info(etrans_keyword_dct['inplvl'],
                                           thy_dct)
    run_thy_info = filesys.inf.get_es_info(etrans_keyword_dct['runlvl'],
                                           thy_dct)
    tgt_mod_thy_info = filesys.inf.modify_orb_restrict(tgt_info, inp_thy_info)
    bath_mod_thy_info = filesys.inf.modify_orb_restrict(
        bath_info, inp_thy_info)
    lj_mod_thy_info = filesys.inf.modify_orb_restrict(lj_info, run_thy_info)

    # Build the target conformer filesystem objects
    _, tgt_cnf_save_fs = filesys.build_fs(run_prefix,
                                          save_prefix,
                                          'CONFORMER',
                                          spc_locs=tgt_info,
                                          thy_locs=tgt_mod_thy_info[1:])

    tgt_loc_info = filesys.mincnf.min_energy_conformer_locators(
        tgt_cnf_save_fs, tgt_mod_thy_info)
    _, tgt_cnf_save_path = tgt_loc_info

    # Build the bath conformer filesystem objects
    _, bath_cnf_save_fs = filesys.build_fs(run_prefix,
                                           save_prefix,
                                           'CONFORMER',
                                           spc_locs=bath_info,
                                           thy_locs=bath_mod_thy_info[1:])

    # Build the target energy transfer filesystem objects
    etrans_save_fs = autofile.fs.energy_transfer(tgt_cnf_save_path)
    etrans_locs = bath_info + lj_mod_thy_info[1:4]

    # Calculate and save the Lennard-Jones parameters, if needed
    nsamp_needed = _nsamp_needed(etrans_save_fs, etrans_locs,
                                 etrans_keyword_dct)
    if nsamp_needed > 0:
        _runlj(nsamp_needed, lj_info, tgt_dct, lj_mod_thy_info,
               tgt_mod_thy_info, bath_mod_thy_info, tgt_cnf_save_fs,
               bath_cnf_save_fs, etrans_save_fs, etrans_locs,
               etrans_keyword_dct, run_prefix)
    else:
        epath = etrans_save_fs[-1].file.lennard_jones_epsilon.path(etrans_locs)
        spath = etrans_save_fs[-1].file.lennard_jones_sigma.path(etrans_locs)
        ioprinter.info_message(
            '- Lennard-Jones epsilon found at path {}'.format(epath))
        ioprinter.info_message(
            '- Lennard-Jones sigma found at path {}'.format(spath))
Esempio n. 2
0
def rpath_fs(ts_dct, tsname, mod_ini_thy_info, es_keyword_dct, run_prefix,
             save_prefix):
    """ reaction path filesystem
    """

    # Set up coordinate name
    rxn_coord = es_keyword_dct.get('rxncoord')

    # Get the zma and ts locs
    zma_locs = (ts_dct['zma_idx'], )
    ts_locs = (int(tsname.split('_')[-1]), )

    # Build filesys object down to TS FS
    ts_fs = build_fs(run_prefix,
                     save_prefix,
                     'TRANSITION STATE',
                     thy_locs=mod_ini_thy_info[1:],
                     **root_locs(ts_dct, saddle=True))
    ini_ts_run_fs, ini_ts_save_fs = ts_fs

    # generate fs
    if rxn_coord == 'irc':
        # Try and locate a minimum-energy conformer
        cnf_fs = build_fs(run_prefix,
                          save_prefix,
                          'CONFORMER',
                          thy_locs=mod_ini_thy_info[1:],
                          **root_locs(ts_dct, saddle=True, name=tsname))
        ini_cnf_run_fs, ini_cnf_save_fs = cnf_fs

        ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info)
        ini_min_locs, ini_pfx_save_path = ini_loc_info

        if any(ini_min_locs):
            # Run IRC from saddle point minimum-energy conformer
            ini_pfx_run_path = ini_cnf_run_fs[-1].path(ini_min_locs)
            ini_pfx_save_path = ini_cnf_save_fs[-1].path(ini_min_locs)
            scn_alg = 'irc-sadpt'
        else:
            # Run IRC from series of points {Rmax, Rmax-1, ...}
            ini_pfx_run_path = ini_ts_run_fs[-1].path(ts_locs)
            ini_pfx_save_path = ini_ts_save_fs[-1].path(ts_locs)
            scn_alg = 'irc-rmax'
    else:
        # Run a scan along the requested reaction coordinates
        # Have an auto option that just selects the coordinate?
        ini_pfx_run_path = ini_ts_run_fs[-1].path(ts_locs)
        ini_pfx_save_path = ini_ts_save_fs[-1].path(ts_locs)
        scn_alg = 'drp'

    # Set up the scan filesystem objects using the predefined prefix
    scn_fs = build_fs(ini_pfx_run_path,
                      ini_pfx_save_path,
                      'SCAN',
                      zma_locs=zma_locs)

    return scn_alg, scn_fs, cnf_fs, ini_min_locs
Esempio n. 3
0
def geom_init(spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix,
              save_prefix):
    """ Execute the task for a species used to seed the
        filesystem with a reliable initial conformer.

        :param spc_dct:
        :type spc_dct:
        :param spc_name: name of species
        :type spc_name: str
        :param thy_dct:
        :type thy_dct:
        :param es_keyword_dct: keyword-val pairs for electronic structure task
        :type es_keyword_dct: dict[str:str]
        :param run_prefix: root-path to the run-filesystem
        :type run_prefix: str
        :param save_prefix: root-path to the save-filesystem
        :type save_prefix: str
    """

    spc_dct_i = spc_dct[spc_name]
    spc_info = sinfo.from_dct(spc_dct_i)

    # Get the theory info
    method_dct = thy_dct.get(es_keyword_dct['runlvl'])
    ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
    thy_info = tinfo.from_dct(method_dct)
    ini_thy_info = tinfo.from_dct(ini_method_dct)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, spc_info)

    # Set the filesystem objects
    _, ini_cnf_save_fs = build_fs(run_prefix,
                                  save_prefix,
                                  'CONFORMER',
                                  spc_locs=spc_info,
                                  thy_locs=mod_ini_thy_info[1:])
    cnf_run_fs, cnf_save_fs = build_fs(run_prefix,
                                       save_prefix,
                                       'CONFORMER',
                                       spc_locs=spc_info,
                                       thy_locs=mod_thy_info[1:])

    # Get a reference geometry if one not found
    success = conformer.initial_conformer(spc_dct_i, spc_info, ini_method_dct,
                                          method_dct, ini_cnf_save_fs,
                                          cnf_run_fs, cnf_save_fs,
                                          es_keyword_dct)

    return success
Esempio n. 4
0
def geom_init(spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix,
              save_prefix):
    """ Find the initial geometry
    """

    spc_dct_i = spc_dct[spc_name]
    spc_info = sinfo.from_dct(spc_dct_i)

    # Get the theory info
    method_dct = thy_dct.get(es_keyword_dct['runlvl'])
    ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
    thy_info = tinfo.from_dct(method_dct)
    ini_thy_info = tinfo.from_dct(ini_method_dct)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, spc_info)

    # Set the filesystem objects
    _, ini_cnf_save_fs = build_fs(run_prefix,
                                  save_prefix,
                                  'CONFORMER',
                                  spc_locs=spc_info,
                                  thy_locs=mod_ini_thy_info[1:])
    cnf_run_fs, cnf_save_fs = build_fs(run_prefix,
                                       save_prefix,
                                       'CONFORMER',
                                       spc_locs=spc_info,
                                       thy_locs=mod_thy_info[1:])

    # _, ini_cnf_save_fs = build_fs(
    #     run_prefix, save_prefix, 'CONFORMER',
    #     spc_locs=spc_info, thy_locs=mod_ini_thy_info[1:])
    # cnf_run_fs, cnf_save_fs = build_fs(
    #     run_prefix, save_prefix, 'CONFORMER',
    #     spc_locs=spc_info, thy_locs=mod_thy_info[1:])

    _, instab_save_fs = build_fs(run_prefix,
                                 save_prefix,
                                 'INSTAB',
                                 spc_locs=spc_info,
                                 thy_locs=mod_thy_info[1:])

    # Get a reference geometry if one not found
    success = conformer.initial_conformer(spc_dct_i, spc_info, ini_method_dct,
                                          method_dct, ini_cnf_save_fs,
                                          cnf_run_fs, cnf_save_fs,
                                          instab_save_fs, es_keyword_dct)

    return success
Esempio n. 5
0
def create_ts_spc(ref, spc_dct, mult, run_prefix, save_prefix, rxnclass):
    """ add a ts species to the species dictionary
    """
    spec = {}
    spec['reacs'] = list(ref[0])
    spec['prods'] = list(ref[1])
    spec['charge'] = 0
    spec['inchi'] = ''
    spec['class'] = rxnclass
    spec['mult'] = mult
    rxn_ichs = [[], []]
    ioprinter.info_message('spec in build spc', spec)
    for rct_ich in spec['reacs']:
        if rct_ich:
            rxn_ichs[0].append(automol.inchi.add_stereo(rct_ich))
    for prd_ich in spec['prods']:
        if prd_ich:
            rxn_ichs[1].append(automol.inchi.add_stereo(prd_ich))
    rct_muls = []
    prd_muls = []
    rct_chgs = []
    prd_chgs = []
    for rct in spec['reacs']:
        found = False
        for name in spc_dct:
            if 'inchi' in spc_dct[name]:
                if spc_dct[name]['inchi'] == rct:
                    rct_muls.append(spc_dct[name]['mult'])
                    rct_chgs.append(spc_dct[name]['charge'])
                    found = True
                    break
        if not found:
            new_spc = create_spec(rct)
            rct_muls.append(new_spc['mult'])
            rct_chgs.append(new_spc['charge'])
    for rct in spec['prods']:
        found = False
        for name in spc_dct:
            if 'inchi' in spc_dct[name]:
                if spc_dct[name]['inchi'] == rct:
                    prd_muls.append(spc_dct[name]['mult'])
                    prd_chgs.append(spc_dct[name]['charge'])
                    found = True
                    break
        if not found:
            new_spc = create_spec(rct)
            prd_muls.append(new_spc['mult'])
            prd_chgs.append(new_spc['charge'])
    rxn_muls = [rct_muls, prd_muls]
    rxn_chgs = [rct_chgs, prd_chgs]

    rxn_info = rinfo.sort((rxn_ichs, rxn_chgs, rxn_muls, mult))
    spec['rxn_info'] = rxn_info
    spec['ts_locs'] = (0, )
    rxn_run_fs, rxn_save_fs = build_fs(run_prefix, save_prefix, 'REACTION')
    rxn_run_path = rxn_run_fs[-1].path(rxn_info)
    rxn_save_path = rxn_save_fs[-1].path(rxn_info)
    spec['rxn_fs'] = [rxn_run_fs, rxn_save_fs, rxn_run_path, rxn_save_path]

    return spec
Esempio n. 6
0
def conformer_list_from_models(spc_name, thy_dct, print_keyword_dct,
                               save_prefix, run_prefix, spc_dct_i,
                               spc_mod_dct_i):
    """ Create a list of conformers based on the species name
        and model.dat info
    """
    # conformer range
    cnf_range = _set_conf_range(print_keyword_dct)
    hbond_cutoffs = spc_dct_i['hbond_cutoffs']

    # thy_info build
    thy_info = spc_mod_dct_i['vib']['geolvl'][1][1]
    spc_info = sinfo.from_dct(spc_dct_i)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    sort_info_lst = _set_sort_info_lst(print_keyword_dct['sort'], thy_dct,
                                       spc_info)

    zrxn = spc_dct_i.get('zrxn', None)
    _root = filesys.root_locs(spc_dct_i,
                              name=spc_name,
                              saddle=(zrxn is not None))
    _, cnf_save_fs = filesys.build_fs(run_prefix,
                                      save_prefix,
                                      'CONFORMER',
                                      thy_locs=mod_thy_info[1:],
                                      **_root)
    rng_cnf_locs_lst, rng_cnf_locs_path = filesys.mincnf.conformer_locators(
        cnf_save_fs,
        mod_thy_info,
        cnf_range=cnf_range,
        sort_info_lst=sort_info_lst,
        hbond_cutoffs=hbond_cutoffs,
        print_enes=True)

    return cnf_save_fs, rng_cnf_locs_lst, rng_cnf_locs_path, mod_thy_info
Esempio n. 7
0
def set_model_filesys(spc_dct_i, level,
                      run_prefix, save_prefix, saddle, name=None, rings='all'):
    """ Gets filesystem objects for reading many calculations
    """

    # Set the spc_info
    if saddle:
        rxn_info = spc_dct_i['rxn_info']
        spc_info = rinfo.ts_info(rxn_info)
    else:
        spc_info = sinfo.from_dct(spc_dct_i)

    print('level', level)
    levelp = tinfo.modify_orb_label(level, spc_info)

    _root = root_locs(spc_dct_i, saddle=saddle, name=name)
    cnf_run_fs, cnf_save_fs = build_fs(
        run_prefix, save_prefix, 'CONFORMER',
        thy_locs=levelp[1:],
        **_root)

    if rings == 'min':
        min_rngs_locs, min_rngs_path = mincnf.min_energy_conformer_locators(
            cnf_save_fs, levelp)
        cnf_run_fs[-1].create(min_rngs_locs)
    else:
        min_rngs_locs, min_rngs_path = mincnf.conformer_locators(
             cnf_save_fs, levelp, cnf_range='r100')
        for min_locs in min_rngs_locs:
            cnf_run_fs[-1].create(min_locs)

    print('model filesys', min_rngs_locs, min_rngs_path)
    # Create run fs if that directory has been deleted to run the jobs

    return [cnf_save_fs, min_rngs_path, min_rngs_locs, '', cnf_run_fs]
Esempio n. 8
0
def _read_from_filesys(rxn_info, ini_thy_info, zma_locs, save_prefix):
    """ Check if reaction exists in the filesystem and has been identified
    """

    zrxn, zma = None, None

    sort_rxn_info = rinfo.sort(rxn_info, scheme='autofile')
    ts_info = rinfo.ts_info(rxn_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, ts_info)

    rxn_fs = autofile.fs.reaction(save_prefix)
    if rxn_fs[-1].exists(sort_rxn_info):
        _, cnf_save_fs = build_fs(
            save_prefix,
            save_prefix,
            'CONFORMER',
            rxn_locs=sort_rxn_info,
            thy_locs=mod_ini_thy_info[1:],
            # this needs to be fixed for any case with more than one TS
            ts_locs=(0, ))

        _, ini_min_cnf_path = filesys.mincnf.min_energy_conformer_locators(
            cnf_save_fs, mod_ini_thy_info)
        if ini_min_cnf_path:
            zma_fs = autofile.fs.zmatrix(ini_min_cnf_path)
            if zma_fs[-1].file.reaction.exists(zma_locs):
                zrxn = zma_fs[-1].file.reaction.read(zma_locs)
                zma = zma_fs[-1].file.zmatrix.read(zma_locs)

        ts_locs = (0, )
        if zrxn is None:
            _, zma_fs = build_fs('',
                                 save_prefix,
                                 'ZMATRIX',
                                 rxn_locs=sort_rxn_info,
                                 ts_locs=ts_locs,
                                 thy_locs=mod_ini_thy_info[1:])

            if zma_fs[-1].file.reaction.exists(zma_locs):
                zrxn = zma_fs[-1].file.reaction.read(zma_locs)
                zma = zma_fs[-1].file.zmatrix.read(zma_locs)

    return zrxn, zma
Esempio n. 9
0
def conformer_list_from_models(print_keyword_dct, save_prefix, run_prefix,
                               spc_dct_i, spc_mod_dct_i):
    """ Create a list of conformers based on the species name
        and model.dat info
    """
    # conformer range
    cnf_range = _set_conf_range(print_keyword_dct)

    # thy_info build
    thy_info = spc_mod_dct_i['geo'][1]
    spc_info = sinfo.from_dct(spc_dct_i)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)

    _root = filesys.root_locs(spc_dct_i, saddle=False)
    _, cnf_save_fs = filesys.build_fs(run_prefix,
                                      save_prefix,
                                      'CONFORMER',
                                      thy_locs=mod_thy_info[1:],
                                      **_root)
    rng_cnf_locs_lst, rng_cnf_locs_path = filesys.mincnf.conformer_locators(
        cnf_save_fs, mod_thy_info, cnf_range=cnf_range)
    return cnf_save_fs, rng_cnf_locs_lst, rng_cnf_locs_path
Esempio n. 10
0
def instability_transformation(spc_dct, spc_name, thy_info, save_prefix,
                               zma_locs=(0,)):
    """ see if a species and unstable and handle task management
    """

    spc_info = sinfo.from_dct(spc_dct[spc_name])
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    _, zma_save_fs = build_fs(
        '', save_prefix, 'ZMATRIX',
        spc_locs=spc_info,
        thy_locs=mod_thy_info[1:],
        instab_locs=())

    # Check if the instability files exist
    if zma_save_fs[-1].file.reaction.exists(zma_locs):
        zrxn = zma_save_fs[-1].file.reaction.read(zma_locs)
        zma = zma_save_fs[-1].file.zmatrix.read(zma_locs)
        _instab = (zrxn, zma)
        path = zma_save_fs[-1].file.zmatrix.path(zma_locs)
    else:
        _instab = None
        path = None

    return _instab, path
Esempio n. 11
0
def run_tsk(tsk, spc_dct, spc_name, thy_dct, proc_keyword_dct, pes_mod_dct_i,
            spc_mod_dct_i, run_prefix, save_prefix):
    """ run a proc tess task
    for generating a list of conformer or tau sampling geometries
    """

    # Print the head of the task
    ioprinter.output_task_header(tsk)
    ioprinter.obj('line_dash')
    ioprinter.output_keyword_list(proc_keyword_dct, thy_dct)

    # Setup csv data dictionary for specific task
    csv_data = util.set_csv_data(tsk)
    chn_basis_ene_dct = {}
    spc_array = []

    # print species
    ioprinter.obj('line_dash')
    ioprinter.info_message("Species: ", spc_name)

    # Heat of formation basis molecules and coefficients
    # is not conformer specific
    if 'coeffs' in tsk:
        thy_info = spc_mod_dct_i['geo'][1]
        filelabel = 'coeffs'
        filelabel += '_{}'.format(pes_mod_dct_i['thermfit']['ref_scheme'])
        filelabel += '.csv'
        label = spc_name
        basis_dct, _ = basis.prepare_refs(
            pes_mod_dct_i['thermfit']['ref_scheme'], spc_dct, (spc_name, ))
        # Get the basis info for the spc of interest
        spc_basis, coeff_basis = basis_dct[spc_name]
        coeff_array = []
        for spc_i in spc_basis:
            if spc_i not in spc_array:
                spc_array.append(spc_i)
        for spc_i in spc_array:
            if spc_i in spc_basis:
                coeff_array.append(coeff_basis[spc_basis.index(spc_i)])
            else:
                coeff_array.append(0)
        csv_data[label] = [*coeff_array]

    else:
        # unpack spc and level info
        spc_dct_i = spc_dct[spc_name]
        if proc_keyword_dct['geolvl']:
            thy_info = tinfo.from_dct(thy_dct.get(proc_keyword_dct['geolvl']))
        else:
            thy_info = spc_mod_dct_i['geo'][1]

            # Loop over conformers
        if proc_keyword_dct['geolvl']:
            _, rng_cnf_locs_lst, rng_cnf_locs_path = util.conformer_list(
                proc_keyword_dct, save_prefix, run_prefix, spc_dct_i, thy_dct)
            spc_mod_dct_i, pf_models = None, None
        else:
            ret = util.conformer_list_from_models(proc_keyword_dct,
                                                  save_prefix, run_prefix,
                                                  spc_dct_i, thy_dct,
                                                  spc_mod_dct_i, pf_models)
            _, rng_cnf_locs_lst, rng_cnf_locs_path = ret
        for locs, locs_path in zip(rng_cnf_locs_lst, rng_cnf_locs_path):

            label = spc_name + '_' + '_'.join(locs)
            _, cnf_fs = filesys.build_fs(run_prefix, save_prefix, 'CONFORMER')
            if 'freq' in tsk:

                filelabel = 'freq'
                if spc_mod_dct_i:
                    filelabel += '_m{}'.format(spc_mod_dct_i['harm'][0])
                else:
                    filelabel += '_{}'.format(proc_keyword_dct['geolvl'])
                filelabel += '.csv'

                if pf_models:
                    pf_filesystems = filesys.models.pf_filesys(spc_dct_i,
                                                               spc_mod_dct_i,
                                                               run_prefix,
                                                               save_prefix,
                                                               saddle=False)
                    ret = vib.full_vib_analysis(spc_dct_i,
                                                pf_filesystems,
                                                spc_mod_dct_i,
                                                run_prefix,
                                                zrxn=None)
                    freqs, _, tors_zpe, sfactor, torsfreqs, all_freqs = ret
                    csv_data['tfreq'][label] = torsfreqs
                    csv_data['allfreq'][label] = all_freqs
                    csv_data['scalefactor'][label] = [sfactor]
                else:
                    es_model = util.freq_es_levels(proc_keyword_dct)
                    spc_mod_dct_i = parser.model.pf_level_info(
                        es_model, thy_dct)
                    try:
                        freqs, _, zpe = vib.read_locs_harmonic_freqs(
                            cnf_fs, locs, run_prefix, zrxn=None)
                    except:
                        freqs = []
                        zpe = 0

                tors_zpe = 0.0
                spc_data = []
                zpe = tors_zpe + (sum(freqs) / 2.0) * phycon.WAVEN2EH
                if freqs and proc_keyword_dct['scale'] is not None:
                    freqs, zpe = vib.scale_frequencies(freqs,
                                                       tors_zpe,
                                                       spc_mod_dct_i,
                                                       scale_method='3c')
                spc_data = [locs_path, zpe, *freqs]
                csv_data['freq'][label] = spc_data
            elif 'geo' in tsk:

                filelabel = 'geo'
                if spc_mod_dct_i:
                    filelabel += '_{}'.format(spc_mod_dct_i['harm'])
                else:
                    filelabel += '_{}'.format(proc_keyword_dct['geolvl'])
                filelabel += '.txt'

                if cnf_fs[-1].file.geometry.exists(locs):
                    geo = cnf_fs[-1].file.geometry.read(locs)
                    energy = cnf_fs[-1].file.energy.read(locs)
                    comment = 'energy: {0:>15.10f}'.format(energy)
                    xyz_str = automol.geom.xyz_string(geo, comment=comment)
                else:
                    xyz_str = '\t -- Missing --'
                spc_data = '\n\nSPC: {}\tConf: {}\tPath: {}\n'.format(
                    spc_name, locs, locs_path) + xyz_str

                csv_data[label] = spc_data

            elif 'zma' in tsk:

                filelabel = 'zmat'
                if spc_mod_dct_i:
                    filelabel += '_{}'.format(spc_mod_dct_i['harm'])
                else:
                    filelabel += '_{}'.format(proc_keyword_dct['geolvl'])
                filelabel += '.txt'

                geo = cnf_fs[-1].file.geometry.read(locs)
                zma = automol.geom.zmatrix(geo)
                energy = cnf_fs[-1].file.energy.read(locs)
                comment = 'energy: {0:>15.10f}\n'.format(energy)
                zma_str = automol.zmat.string(zma)
                spc_data = '\n\nSPC: {}\tConf: {}\tPath: {}\n'.format(
                    spc_name, locs, locs_path) + comment + zma_str
                csv_data[label] = spc_data

            elif 'ene' in tsk:

                filelabel = 'ene'
                if spc_mod_dct_i:
                    filelabel += '_{}'.format(spc_mod_dct_i['harm'])
                    filelabel += '_{}'.format(spc_mod_dct_i['ene'])
                else:
                    filelabel += '_{}'.format(proc_keyword_dct['geolvl'])
                    filelabel += '_{}'.format(proc_keyword_dct['proplvl'])
                filelabel += '.csv'

                energy = None
                if spc_mod_dct_i:
                    pf_filesystems = filesys.models.pf_filesys(spc_dct_i,
                                                               spc_mod_dct_i,
                                                               run_prefix,
                                                               save_prefix,
                                                               saddle=False)
                    energy = ene.electronic_energy(spc_dct_i,
                                                   pf_filesystems,
                                                   spc_mod_dct_i,
                                                   conf=(locs, locs_path,
                                                         cnf_fs))
                else:
                    spc_info = sinfo.from_dct(spc_dct_i)
                    thy_info = tinfo.from_dct(
                        thy_dct.get(proc_keyword_dct['proplvl']))
                    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
                    sp_save_fs = autofile.fs.single_point(locs_path)
                    sp_save_fs[-1].create(mod_thy_info[1:4])
                    # Read the energy
                    sp_path = sp_save_fs[-1].path(mod_thy_info[1:4])
                    if os.path.exists(sp_path):
                        if sp_save_fs[-1].file.energy.exists(
                                mod_thy_info[1:4]):
                            ioprinter.reading('Energy', sp_path)
                            energy = sp_save_fs[-1].file.energy.read(
                                mod_thy_info[1:4])
                csv_data[label] = [locs_path, energy]

            elif 'enthalpy' in tsk:
                filelabel = 'enthalpy'
                if spc_mod_dct_i:
                    filelabel += '_{}'.format(spc_mod_dct_i['harm'])
                    filelabel += '_{}'.format(spc_mod_dct_i['ene'])
                else:
                    filelabel += '_{}'.format(proc_keyword_dct['geolvl'])
                    filelabel += '_{}'.format(proc_keyword_dct['proplvl'])
                filelabel = '.csv'

                energy = None
                pf_filesystems = filesys.models.pf_filesys(spc_dct_i,
                                                           spc_mod_dct_i,
                                                           run_prefix,
                                                           save_prefix,
                                                           saddle=False)
                ene_abs = ene.read_energy(spc_dct_i,
                                          pf_filesystems,
                                          spc_mod_dct_i,
                                          run_prefix,
                                          conf=(locs, locs_path, cnf_fs),
                                          read_ene=True,
                                          read_zpe=True,
                                          saddle=False)
                hf0k, _, chn_basis_ene_dct, hbasis = basis.enthalpy_calculation(
                    spc_dct,
                    spc_name,
                    ene_abs,
                    chn_basis_ene_dct,
                    pes_mod_dct_i,
                    spc_mod_dct_i,
                    run_prefix,
                    save_prefix,
                    pforktp='pf',
                    zrxn=None)
                spc_basis, coeff_basis = hbasis[spc_name]
                coeff_array = []
                for spc_i in spc_basis:
                    if spc_i not in spc_array:
                        spc_array.append(spc_i)
                for spc_i in spc_array:
                    if spc_i in spc_basis:
                        coeff_array.append(coeff_basis[spc_basis.index(spc_i)])
                    else:
                        coeff_array.append(0)
                csv_data[label] = [locs_path, ene_abs, hf0k, *coeff_array]

    util.write_csv_data(tsk, csv_data, filelabel, spc_array)
Esempio n. 12
0
def tau_data(spc_dct_i, spc_mod_dct_i, run_prefix, save_prefix, saddle=False):
    """ Read the filesystem to get information for TAU
    """

    # Set up model and basic thy objects
    spc_info = sinfo.from_dct(spc_dct_i)
    thy_info = spc_mod_dct_i['vib']['geolvl'][1][1]
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)

    vib_model = spc_mod_dct_i['vib']['mod']

    # Set up reference conformer filesys
    pf_filesystems = filesys.models.pf_filesys(spc_dct_i, spc_mod_dct_i,
                                               run_prefix, save_prefix, saddle)
    [harm_save_fs, _, harm_min_locs, _, _] = pf_filesystems['harm']

    # Obtain all values from initial reference conformer
    rotors = tors.build_rotors(spc_dct_i,
                               pf_filesystems,
                               spc_mod_dct_i,
                               read_potentials=False)
    vib_info = vib.full_vib_analysis(spc_dct_i,
                                     pf_filesystems,
                                     spc_mod_dct_i,
                                     run_prefix,
                                     zrxn=None)
    freqs, _, zpe, _, tors_strs, _, harm_freqs, _ = vib_info
    harm_zpve = 0.5 * sum(harm_freqs) * phycon.WAVEN2EH

    ioprinter.info_message('Determining the symmetry factor...', newline=1)
    sym_factor = symm.symmetry_factor(
        pf_filesystems,
        spc_mod_dct_i,
        spc_dct_i,
        rotors,
    )

    zpe_chnlvl = zpe * phycon.EH2KCAL
    ref_ene = harm_zpve * phycon.EH2KCAL

    ref_geom = [harm_save_fs[-1].file.geometry.read(harm_min_locs)]
    ref_grad = [harm_save_fs[-1].file.gradient.read(harm_min_locs)]
    ref_hessian = [harm_save_fs[-1].file.hessian.read(harm_min_locs)]

    min_cnf_ene = filesys.read.energy(harm_save_fs, harm_min_locs,
                                      mod_thy_info)

    # Set up the TAU filesystem objects, get locs, and read info
    _, tau_save_fs = filesys.build_fs(run_prefix,
                                      save_prefix,
                                      'TAU',
                                      spc_locs=spc_info,
                                      thy_locs=mod_thy_info[1:])

    db_style = 'jsondb'
    vib_model = spc_mod_dct_i['vib']['mod']
    if vib_model == 'tau':
        if db_style == 'directory':
            tau_locs = [
                locs for locs in tau_save_fs[-1].existing()
                if tau_save_fs[-1].file.hessian.exists(locs)
            ]
        elif db_style == 'jsondb':
            tau_locs = [
                locs for locs in tau_save_fs[-1].json_existing()
                if tau_save_fs[-1].json.hessian.exists(locs)
            ]
    else:
        if db_style == 'directory':
            tau_locs = tau_save_fs[-1].existing()
        elif db_style == 'jsondb':
            tau_locs = tau_save_fs[-1].json_existing()

    ioprinter.info_message(
        'Reading data for the Monte Carlo samples from db.json'
        f'at path {tau_save_fs[0].path()}')
    samp_geoms, samp_enes, samp_grads, samp_hessians = [], [], [], []
    tot_locs = len(tau_locs)
    for idx, locs in enumerate(tau_locs):

        if db_style == 'directory':
            geo = tau_save_fs[-1].file.geometry.read(locs)
        elif db_style == 'jsondb':
            geo = tau_save_fs[-1].json.geometry.read(locs)

        # geo_str = autofile.data_types.swrite.geometry(geo)
        samp_geoms.append(geo)

        if db_style == 'directory':
            tau_ene = tau_save_fs[-1].file.energy.read(locs)
        elif db_style == 'jsondb':
            tau_ene = tau_save_fs[-1].json.energy.read(locs)
        rel_ene = (tau_ene - min_cnf_ene) * phycon.EH2KCAL
        # ene_str = autofile.data_types.swrite.energy(rel_ene)
        samp_enes.append(rel_ene)

        if vib_model == 'tau':
            if db_style == 'directory':
                grad = tau_save_fs[-1].file.gradient.read(locs)
            elif db_style == 'jsondb':
                grad = tau_save_fs[-1].json.gradient.read(locs)
            # grad_str = autofile.data_types.swrite.gradient(grad)
            samp_grads.append(grad)

            if db_style == 'directory':
                hess = tau_save_fs[-1].file.hessian.read(locs)
            elif db_style == 'jsondb':
                hess = tau_save_fs[-1].json.hessian.read(locs)
            # hess_str = autofile.data_types.swrite.hessian(hess)
            samp_hessians.append(hess)

        # Print progress message (every 150 geoms read)
        if idx % 149 == 0:
            print(f'Read {idx+1}/{tot_locs} samples...')

    # Determine the successful conformer ratio
    inf_obj = tau_save_fs[0].file.info.read()
    excluded_volume_factor = len(samp_geoms) / inf_obj.nsamp
    print('excluded volume factor test:', excluded_volume_factor,
          len(samp_geoms), inf_obj.nsamp)

    # Create info dictionary
    keys = [
        'geom', 'sym_factor', 'elec_levels', 'freqs', 'flux_mode_str',
        'samp_geoms', 'samp_enes', 'samp_grads', 'samp_hessians', 'ref_geom',
        'ref_grad', 'ref_hessian', 'zpe_chnlvl', 'ref_ene',
        'excluded_volume_factor'
    ]
    vals = [
        ref_geom[0], sym_factor, spc_dct_i['elec_levels'], freqs, tors_strs[2],
        samp_geoms, samp_enes, samp_grads, samp_hessians, ref_geom, ref_grad,
        ref_hessian, zpe_chnlvl, ref_ene, excluded_volume_factor
    ]
    inf_dct = dict(zip(keys, vals))

    return inf_dct
Esempio n. 13
0
def onedmin(spc_name, spc_dct, thy_dct, etrans_keyword_dct, run_prefix,
            save_prefix):
    """ Run the task
    """

    bath_name = etrans_keyword_dct['bath']

    tgt_dct, bath_dct = spc_dct[spc_name], spc_dct[bath_name]
    tgt_info = filesys.inf.get_spc_info(tgt_dct)
    bath_info = filesys.inf.get_spc_info(bath_dct)
    lj_info = filesys.inf.combine_spc_info(tgt_info, bath_info)

    # Build the modified thy objs
    inp_thy_info = filesys.inf.get_es_info(etrans_keyword_dct['inplvl'],
                                           thy_dct)
    run_thy_info = filesys.inf.get_es_info(etrans_keyword_dct['runlvl'],
                                           thy_dct)
    tgt_mod_thy_info = filesys.inf.modify_orb_restrict(tgt_info, inp_thy_info)
    bath_mod_thy_info = filesys.inf.modify_orb_restrict(
        bath_info, inp_thy_info)
    lj_mod_thy_info = filesys.inf.modify_orb_restrict(lj_info, run_thy_info)

    # Build the target conformer filesystem objects
    tgt_cnf_run_fs, tgt_cnf_save_fs = filesys.build_fs(
        run_prefix,
        save_prefix,
        'CONFORMER',
        spc_locs=tgt_info,
        thy_locs=tgt_mod_thy_info[1:])

    tgt_loc_info = filesys.mincnf.min_energy_conformer_locators(
        tgt_cnf_save_fs, tgt_mod_thy_info)
    tgt_min_cnf_locs, tgt_cnf_save_path = tgt_loc_info

    # Create run fs if that directory has been deleted to run the jobs
    tgt_cnf_run_fs[-1].create(tgt_min_cnf_locs)
    tgt_cnf_run_path = tgt_cnf_run_fs[-1].path(tgt_min_cnf_locs)

    # Get options from the dct or es options lst
    # tgt_cnf_run_fs[-1].create(tgt_min_cnf_locs)
    # tgt_cnf_run_path = filesys.build.cnf_paths_from_locs(
    #     tgt_cnf_run_fs, [tgt_min_cnf_locs])[0]

    # Build the target energy transfer filesystem objects
    etrans_run_fs = autofile.fs.energy_transfer(tgt_cnf_run_path)
    etrans_save_fs = autofile.fs.energy_transfer(tgt_cnf_save_path)
    etrans_locs = bath_info + lj_mod_thy_info[1:4]

    # Build the bath conformer filesystem objects
    # _, bath_thy_save_path = filesys.build.spc_thy_fs_from_root(
    #     save_prefix, bath_info, bath_mod_thy_info)
    # ioprinter.debug_message('bath path', bath_thy_save_path)
    # bath_cnf_save_fs = autofile.fs.conformer(bath_thy_save_path)

    # Calculate and save the Lennard-Jones parameters, if needed
    run_needed, nsamp_needed = _need_run(etrans_save_fs, etrans_locs,
                                         etrans_keyword_dct)
    if run_needed:
        _runlj(nsamp_needed, lj_info, lj_mod_thy_info, tgt_mod_thy_info,
               bath_mod_thy_info, tgt_cnf_save_fs, bath_cnf_save_fs,
               etrans_run_fs, etrans_locs, etrans_keyword_dct)
        _savelj(etrans_run_fs, etrans_save_fs, etrans_locs, etrans_keyword_dct)
    else:
        epath = etrans_save_fs[-1].file.lennard_jones_epsilon.path(etrans_locs)
        spath = etrans_save_fs[-1].file.lennard_jones_sigma.path(etrans_locs)
        ioprinter.info_message(
            '- Lennard-Jones epsilon found at path {}'.format(epath))
        ioprinter.info_message(
            '- Lennard-Jones sigma found at path {}'.format(spath))
Esempio n. 14
0
def hr_tsk(job, spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix,
           save_prefix):
    """ Prepares and executes all electronic structure tasks that
        generate information for points along hindered-rotor coordinate
        scans which are launched from some conformer in the save filesystem.

        For species and transition state conformers.

        This includes scanning procedures to generate geometries
        (relaxed) or energies (rigid) points along
        conformer structures, as well as __ calculations using some
        saved conformer as input.

        :param job:
        :type job:
        :param spc_dct:
        :type spc_dct:
        :param spc_name:
        :type spc_name:
        :param thy_dct:
        :type thy_dct:
        :param es_keyword_dct: keyword-val pairs for electronic structure task
        :type es_keyword_dct: dict[str:str]
        :param run_prefix: root-path to the run-filesystem
        :type run_prefix: str
        :param save_prefix: root-path to the save-filesystem
        :type save_prefix: str
    """

    spc_dct_i = spc_dct[spc_name]
    saddle = bool('ts_' in spc_name)
    # Set the spc_info
    if not saddle:
        spc_info = sinfo.from_dct(spc_dct_i)
    else:
        spc_info = rinfo.ts_info(spc_dct_i['rxn_info'])

    # Get options from the dct or es options lst
    overwrite = es_keyword_dct['overwrite']
    retryfail = es_keyword_dct['retryfail']
    tors_model = es_keyword_dct['tors_model']
    # nprocs = es_keyword_dct['nprocs']
    nprocs = 1
    # Modify the theory
    method_dct = thy_dct.get(es_keyword_dct['runlvl'])
    ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
    thy_info = tinfo.from_dct(method_dct)
    ini_thy_info = tinfo.from_dct(ini_method_dct)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, spc_info)

    # Set the filesystem objects
    _root = root_locs(spc_dct_i, saddle=saddle, name=spc_name)
    _, ini_cnf_save_fs = build_fs(run_prefix,
                                  save_prefix,
                                  'CONFORMER',
                                  thy_locs=mod_ini_thy_info[1:],
                                  **_root)
    cnf_run_fs, cnf_save_fs = build_fs(run_prefix,
                                       save_prefix,
                                       'CONFORMER',
                                       thy_locs=mod_thy_info[1:],
                                       **_root)

    cnf_range = es_keyword_dct['cnf_range']
    hbond_cutoffs = spc_dct_i['hbond_cutoffs']

    user_conf_ids = spc_dct_i.get('conf_id')
    if user_conf_ids is None:
        cnf_sort_info_lst = _sort_info_lst(es_keyword_dct['sort'], thy_dct,
                                           spc_info)
        ini_min_locs_lst, ini_path_lst = filesys.mincnf.conformer_locators(
            ini_cnf_save_fs,
            mod_ini_thy_info,
            cnf_range=cnf_range,
            sort_info_lst=cnf_sort_info_lst,
            hbond_cutoffs=hbond_cutoffs,
            print_enes=True,
            nprocs=nprocs)
    else:
        ini_min_locs_lst = (user_conf_ids, )
        ini_path_lst = (ini_cnf_save_fs[-1].path(user_conf_ids), )

    all_run_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
        cnf_save_fs, mod_thy_info, cnf_range='all', nprocs=nprocs)
    ini_to_run_locs_dct = filesys.mincnf.fs_confs_dict(cnf_save_fs,
                                                       all_run_cnf_locs_lst,
                                                       ini_cnf_save_fs,
                                                       ini_min_locs_lst)

    for ini_min_locs, ini_cnf_save_path in zip(ini_min_locs_lst, ini_path_lst):

        # Read zma, geo, and torsions
        ini_zma_save_fs = autofile.fs.zmatrix(ini_cnf_save_path)
        geo = ini_cnf_save_fs[-1].file.geometry.read(ini_min_locs)
        zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))
        if ini_zma_save_fs[-1].file.torsions.exists([0]):
            tors_dct = ini_zma_save_fs[-1].file.torsions.read([0])
            torsions = automol.rotor.from_data(
                zma,
                tors_dct,
            )
        else:
            torsions = ()

        zrxn = spc_dct_i.get('zrxn', None)
        # Run the task if any torsions exist
        if any(torsions):
            # Find equivalent conformer in the run filesys, if it doesn't exist
            # run a single conformer to generate it
            min_locs = ini_to_run_locs_dct[tuple(ini_min_locs)]
            if min_locs is None:
                script_str, kwargs = qchem_params(method_dct,
                                                  elstruct.Job.OPTIMIZATION)
                rid = conformer.rng_loc_for_geo(geo, cnf_save_fs)
                if rid is None:
                    new_rid = autofile.schema.generate_new_ring_id()
                    new_cid = autofile.schema.generate_new_conformer_id()
                    conformer.single_conformer(zma,
                                               spc_info,
                                               mod_thy_info,
                                               cnf_run_fs,
                                               cnf_save_fs,
                                               script_str,
                                               overwrite,
                                               retryfail=retryfail,
                                               zrxn=zrxn,
                                               use_locs=(new_rid, new_cid),
                                               **kwargs)
                    min_locs = (new_rid, new_cid)
                else:
                    new_cid = autofile.schema.generate_new_conformer_id()
                    conformer.single_conformer(zma,
                                               spc_info,
                                               mod_thy_info,
                                               cnf_run_fs,
                                               cnf_save_fs,
                                               script_str,
                                               overwrite,
                                               retryfail=retryfail,
                                               zrxn=zrxn,
                                               use_locs=(rid, new_cid),
                                               **kwargs)
                    min_locs = (rid, new_cid)
                    save_locs = cnf_save_fs[-1].existing()
                    if min_locs not in save_locs:
                        locinf = filesys.mincnf.this_conformer_was_run_in_run(
                            zma, cnf_run_fs)
                        _, sym_locs_lst = locinf
                        for sym_locs in sym_locs_lst:
                            if sym_locs in save_locs:
                                min_locs = sym_locs
            cnf_save_path = cnf_save_fs[-1].path(min_locs)
            ioprinter.info_message(
                f'Same conformer saved at {ini_cnf_save_path} '
                f'and {cnf_save_path}')

            # Create run fs if that directory has been deleted to run the jobs
            # ini_cnf_run_fs[-1].create(ini_min_locs)
            # ini_cnf_run_path = ini_cnf_run_fs[-1].path(ini_min_locs)
            cnf_run_fs[-1].create(min_locs)
            cnf_run_path = cnf_run_fs[-1].path(min_locs)

            # Get the runlvl zma and torsion info
            zma_save_fs = autofile.fs.zmatrix(cnf_save_path)
            geo = cnf_save_fs[-1].file.geometry.read(min_locs)
            zma = zma_save_fs[-1].file.zmatrix.read((0, ))
            if zma_save_fs[-1].file.torsions.exists([0]):
                tors_dct = zma_save_fs[-1].file.torsions.read([0])
                torsions = automol.rotor.from_data(
                    zma,
                    tors_dct,
                )
            else:
                torsions = ()

            if 'fa' in tors_model:
                scn = 'CSCAN'
            elif 'f' in tors_model:
                if len(torsions) > 1:
                    scn = 'CSCAN'
                else:
                    scn = 'SCAN'
            else:
                scn = 'SCAN'
            # ini_scn_run_fs, ini_scn_save_fs = build_fs(
            #     ini_cnf_run_path, ini_cnf_save_path, scn,
            #     zma_locs=(0,))
            scn_run_fs, scn_save_fs = build_fs(cnf_run_path,
                                               cnf_save_path,
                                               scn,
                                               zma_locs=(0, ))

            if job == 'scan':

                increment = spc_dct_i.get('hind_inc', 30.0 * phycon.DEG2RAD)
                hr.hindered_rotor_scans(zma,
                                        spc_info,
                                        mod_thy_info,
                                        scn_run_fs,
                                        scn_save_fs,
                                        torsions,
                                        tors_model,
                                        method_dct,
                                        overwrite,
                                        zrxn=zrxn,
                                        saddle=saddle,
                                        increment=increment,
                                        retryfail=retryfail)

            elif job == 'reopt':

                script_str, kwargs = qchem_params(method_dct,
                                                  elstruct.Job.OPTIMIZATION)

                # pull stuff from dcts
                ethresh = es_keyword_dct['hrthresh']
                increment = spc_dct_i.get('hind_inc', 30.0 * phycon.DEG2RAD)

                zrxn = spc_dct_i.get('zrxn', None)

                run_tors_names = automol.rotor.names(torsions)
                run_tors_grids = automol.rotor.grids(torsions,
                                                     increment=increment)

                # Set constraints
                const_names = automol.zmat.set_constraint_names(
                    zma, run_tors_names, tors_model)

                # Read and print the potential
                sp_fs = autofile.fs.single_point(cnf_save_path)
                ref_ene = sp_fs[-1].file.energy.read(mod_thy_info[1:4])
                tors_pots, tors_zmas, tors_paths = {}, {}, {}
                for tors_names, tors_grids in zip(run_tors_names,
                                                  run_tors_grids):
                    constraint_dct = automol.zmat.constraint_dct(
                        zma, const_names, tors_names)
                    pot, _, _, _, zmas, paths = filesys.read.potential(
                        tors_names,
                        tors_grids,
                        cnf_save_path,
                        mod_thy_info,
                        ref_ene,
                        constraint_dct,
                        read_zma=True)
                    tors_pots[tors_names] = pot
                    tors_zmas[tors_names] = zmas
                    tors_paths[tors_names] = paths

                # Check for new minimum conformer
                new_min_zma = hr.check_hr_pot(tors_pots,
                                              tors_zmas,
                                              tors_paths,
                                              emax=ethresh)

                if new_min_zma is not None:
                    ioprinter.info_message(
                        'Finding new low energy conformer...', newline=1)
                    new_min_geo = automol.zmat.geometry(new_min_zma)
                    rid = conformer.rng_loc_for_geo(new_min_geo, cnf_save_fs)
                    if rid is None:
                        new_locs = None
                    else:
                        cid = autofile.schema.generate_new_conformer_id()
                        new_locs = (rid, cid)
                    conformer.single_conformer(new_min_zma,
                                               spc_info,
                                               mod_thy_info,
                                               cnf_run_fs,
                                               cnf_save_fs,
                                               script_str,
                                               overwrite,
                                               retryfail=retryfail,
                                               zrxn=zrxn,
                                               use_locs=new_locs,
                                               **kwargs)

            elif job in ('energy', 'grad', 'hess', 'vpt2'):

                # Script (add energy script call)
                script_str, kwargs = qchem_params(method_dct)

                run_tors_names = automol.rotor.names(torsions, flat=True)
                for tors_names in run_tors_names:

                    # Set the constraint dct and filesys for the scan
                    const_names = automol.zmat.set_constraint_names(
                        zma, run_tors_names, tors_model)
                    constraint_dct = automol.zmat.constraint_dct(
                        zma, const_names, tors_names)

                    # get the scn_locs, maybe get a function?
                    _, scn_locs = scan.scan_locs(scn_save_fs,
                                                 tors_names,
                                                 constraint_dct=constraint_dct)
                    for locs in scn_locs:
                        geo = scn_save_fs[-1].file.geometry.read(locs)
                        zma = scn_save_fs[-1].file.zmatrix.read(locs)
                        scn_run_fs[-1].create(locs)
                        ES_TSKS[job](zma,
                                     geo,
                                     spc_info,
                                     mod_thy_info,
                                     scn_run_fs,
                                     scn_save_fs,
                                     locs,
                                     run_prefix,
                                     script_str,
                                     overwrite,
                                     zrxn=zrxn,
                                     retryfail=retryfail,
                                     **kwargs)
                        ioprinter.obj('vspace')
        else:
            ioprinter.info_message('No torsional modes in the species')
Esempio n. 15
0
def _set_thy_inf_dcts(tsname,
                      ts_dct,
                      thy_dct,
                      es_keyword_dct,
                      run_prefix,
                      save_prefix,
                      zma_locs=(0, )):
    """ set the theory
    """

    rxn_info = ts_dct['rxn_info']
    ts_info = rinfo.ts_info(rxn_info)
    rct_info = rinfo.rgt_info(rxn_info, 'reacs')
    rxn_info = rinfo.sort(rxn_info)

    ts_locs = (int(tsname.split('_')[-1]), )

    high_mult = rinfo.ts_mult(rxn_info, rxn_mul='high')

    # Set the hs info
    hs_info = (ts_info[0], ts_info[1], high_mult)

    # Initialize the theory objects
    ini_thy_info, mod_ini_thy_info = None, None
    thy_info, mod_thy_info = None, None
    vscnlvl_thy_info, mod_vscnlvl_thy_info = None, None
    vsp1lvl_thy_info, mod_vsp1lvl_thy_info = None, None
    vsp2lvl_thy_info, mod_vsp2lvl_thy_info = None, None
    hs_vscnlvl_thy_info = None
    hs_vsp1lvl_thy_info = None
    hs_vsp2lvl_thy_info = None
    hs_thy_info = None

    # Initialize the necessary run filesystem
    runlvl_ts_run_fs = None
    runlvl_scn_run_fs = None
    runlvl_cscn_run_fs = None
    vscnlvl_ts_run_fs = None
    vscnlvl_scn_run_fs = None
    vscnlvl_cscn_run_fs = None
    vrctst_run_fs = None

    # Initialize the necessary save filesystem
    ini_zma_save_fs = None
    runlvl_ts_save_fs = None
    runlvl_scn_save_fs = None  # above cnf filesys, for search scans
    runlvl_cscn_save_fs = None  # above cnf filesys, for search scans
    runlvl_cnf_save_fs = None
    vscnlvl_thy_save_fs = None
    vscnlvl_ts_save_fs = None
    vscnlvl_scn_save_fs = None
    vscnlvl_cscn_save_fs = None
    vrctst_save_fs = None
    runlvl_ts_zma_fs = None

    if es_keyword_dct.get('inplvl', None) is not None:

        ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
        ini_thy_info = tinfo.from_dct(ini_method_dct)
        mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, ts_info)

        ini_cnf_run_fs, ini_cnf_save_fs = build_fs(
            run_prefix,
            save_prefix,
            'CONFORMER',
            rxn_locs=rxn_info,
            ts_locs=ts_locs,
            thy_locs=mod_ini_thy_info[1:])

        ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info)
        ini_min_cnf_locs, ini_path = ini_loc_info

        if ini_path:
            ini_zma_save_fs = autofile.fs.zmatrix(
                ini_cnf_save_fs[-1].path(ini_min_cnf_locs))

    if es_keyword_dct.get('runlvl', None) is not None:

        method_dct = thy_dct.get(es_keyword_dct['runlvl'])
        thy_info = tinfo.from_dct(method_dct)
        mod_thy_info = tinfo.modify_orb_label(thy_info, ts_info)
        hs_thy_info = tinfo.modify_orb_label(thy_info, hs_info)

        runlvl_cnf_run_fs, runlvl_cnf_save_fs = build_fs(
            run_prefix,
            save_prefix,
            'CONFORMER',
            rxn_locs=rxn_info,
            ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:])

        _, runlvl_ts_zma_save_fs = build_fs(run_prefix,
                                            save_prefix,
                                            'ZMATRIX',
                                            rxn_locs=rxn_info,
                                            ts_locs=ts_locs,
                                            thy_locs=mod_thy_info[1:])

        runlvl_loc_info = filesys.mincnf.min_energy_conformer_locators(
            runlvl_cnf_save_fs, mod_thy_info)
        runlvl_min_cnf_locs, _ = runlvl_loc_info
        runlvl_cnf_save_fs = (runlvl_cnf_save_fs, runlvl_min_cnf_locs)

        runlvl_scn_run_fs, runlvl_scn_save_fs = build_fs(
            run_prefix,
            save_prefix,
            'SCAN',
            rxn_locs=rxn_info,
            ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:],
            zma_locs=(0, ))

        runlvl_cscn_run_fs, runlvl_cscn_save_fs = build_fs(
            run_prefix,
            save_prefix,
            'CSCAN',
            rxn_locs=rxn_info,
            ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:],
            zma_locs=(0, ))

    if es_keyword_dct.get('var_scnlvl', None) is not None:

        method_dct = thy_dct.get(es_keyword_dct['var_scnlvl'])
        vscnlvl_thy_info = tinfo.from_dct(method_dct)
        mod_vscnlvl_thy_info = tinfo.modify_orb_label(vscnlvl_thy_info,
                                                      ts_info)
        hs_vscnlvl_thy_info = tinfo.modify_orb_label(vscnlvl_thy_info, hs_info)

        vscnlvl_scn_run_fs, vscnlvl_scn_save_fs = build_fs(
            run_prefix,
            save_prefix,
            'SCAN',
            rxn_locs=rxn_info,
            ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:],
            zma_locs=(0, ))

        vscnlvl_cscn_run_fs, vscnlvl_cscn_save_fs = build_fs(
            run_prefix,
            save_prefix,
            'CSCAN',
            rxn_locs=rxn_info,
            ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:],
            zma_locs=(0, ))

        vrctst_run_fs, vrctst_save_fs = build_fs(run_prefix,
                                                 save_prefix,
                                                 'VRCTST',
                                                 rxn_locs=rxn_info,
                                                 ts_locs=ts_locs,
                                                 thy_locs=mod_thy_info[1:])

        if es_keyword_dct.get('var_splvl1', None) is not None:

            method_dct = thy_dct.get(es_keyword_dct['var_scnlvl1'])
            vsplvl1_thy_info = tinfo.from_dct(method_dct)
            mod_vsplvl1_thy_info = tinfo.modify_orb_label(
                vsplvl1_thy_info, ts_info)
            hs_vsplvl1_thy_info = tinfo.modify_orb_label(
                vsplvl1_thy_info, hs_info)

        if es_keyword_dct.get('var_splvl2', None) is not None:

            method_dct = thy_dct.get(es_keyword_dct['var_scnlvl2'])
            vsplvl2_thy_info = tinfo.from_dct(method_dct)
            mod_vsplvl2_thy_info = tinfo.modify_orb_label(
                vsplvl2_thy_info, ts_info)
            hs_vsplvl2_thy_info = tinfo.modify_orb_label(
                vsplvl2_thy_info, hs_info)

    # Get the conformer filesys for the reactants
    _rcts_cnf_fs = rcts_cnf_fs(rct_info, thy_dct, es_keyword_dct, run_prefix,
                               save_prefix)

    thy_inf_dct = {
        'inplvl': ini_thy_info,
        'runlvl': thy_info,
        'var_scnlvl': vscnlvl_thy_info,
        'var_splvl1': vsp1lvl_thy_info,
        'var_splvl2': vsp2lvl_thy_info,
        'mod_inplvl': mod_ini_thy_info,
        'mod_runlvl': mod_thy_info,
        'mod_var_scnlvl': mod_vscnlvl_thy_info,
        'mod_var_splvl1': mod_vsp1lvl_thy_info,
        'mod_var_splvl2': mod_vsp2lvl_thy_info,
        'hs_var_scnlvl': hs_vscnlvl_thy_info,
        'hs_var_splvl1': hs_vsp1lvl_thy_info,
        'hs_var_splvl2': hs_vsp2lvl_thy_info,
        'hs_runlvl': hs_thy_info
    }

    runfs_dct = {
        'runlvl_scn_fs': runlvl_scn_run_fs,
        'runlvl_cscn_fs': runlvl_cscn_run_fs,
        'runlvl_cnf_fs': runlvl_cnf_run_fs,
        'vscnlvl_ts_fs': vscnlvl_ts_run_fs,
        'vscnlvl_scn_fs': vscnlvl_scn_run_fs,
        'vscnlvl_cscn_fs': vscnlvl_cscn_run_fs,
        'vrctst_fs': vrctst_run_fs,
    }

    savefs_dct = {
        'inilvl_zma_fs': ini_zma_save_fs,
        'runlvl_scn_fs': runlvl_scn_save_fs,
        'runlvl_cscn_fs': runlvl_cscn_save_fs,
        'runlvl_cnf_fs': runlvl_cnf_save_fs,
        'vscnlvl_scn_fs': vscnlvl_scn_save_fs,
        'vscnlvl_cscn_fs': vscnlvl_cscn_save_fs,
        'vrctst_fs': vrctst_save_fs,
        'rcts_cnf_fs': _rcts_cnf_fs,
        'runlvl_ts_zma_fs': runlvl_ts_zma_save_fs
    }

    return thy_inf_dct, runfs_dct, savefs_dct
Esempio n. 16
0
def conformer_tsk(job,
                  spc_dct,
                  spc_name,
                  thy_dct,
                  es_keyword_dct,
                  run_prefix,
                  save_prefix,
                  print_debug=False):
    """ Prepares and executes all electronic structure tasks that
        generate information for species and transition state conformers.
        This includes sampling and optimization procedures to generate
        conformer structures, as well as __ calculations using some
        saved conformer as input.

        :param job(subtask): calculatiion(s) to perform for conformer
        :type job: str
        :param spc_dct:
        :type spc_dct:
        :param spc_name: name of species
        :type spc_name: str
        :param thy_dct:
        :type thy_dct:
        :param es_keyword_dct: keyword-values for electronic structure task
        :type es_keyword_dct: dict[str:str]
        :param run_prefix: root-path to the run-filesystem
        :type run_prefix: str
        :param save_prefix: root-path to the save-filesystem
        :type save_prefix: str
    """

    saddle = bool('ts_' in spc_name)

    spc_dct_i = spc_dct[spc_name]

    # Set the spc_info
    if not saddle:
        spc_info = sinfo.from_dct(spc_dct_i)
    else:
        spc_info = rinfo.ts_info(spc_dct_i['rxn_info'])
    zrxn = spc_dct_i.get('zrxn', None)

    overwrite = es_keyword_dct['overwrite']
    retryfail = es_keyword_dct['retryfail']
    nprocs = 1
    # Modify the theory
    method_dct = thy_dct.get(es_keyword_dct['runlvl'])
    ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
    thy_info = tinfo.from_dct(method_dct)
    ini_thy_info = tinfo.from_dct(ini_method_dct)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, spc_info)

    # New filesystem objects
    _root = root_locs(spc_dct_i, saddle=saddle, name=spc_name)
    ini_cnf_run_fs, ini_cnf_save_fs = build_fs(run_prefix,
                                               save_prefix,
                                               'CONFORMER',
                                               thy_locs=mod_ini_thy_info[1:],
                                               **_root)
    cnf_run_fs, cnf_save_fs = build_fs(run_prefix,
                                       save_prefix,
                                       'CONFORMER',
                                       thy_locs=mod_thy_info[1:],
                                       **_root)

    if job == 'samp':

        # Build the ini zma filesys
        user_conf_ids = spc_dct_i.get('conf_id')
        if user_conf_ids is None:
            ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
                ini_cnf_save_fs, mod_ini_thy_info)
            ini_locs, ini_min_cnf_path = ini_loc_info
        else:
            print(f'Using user specified conformer IDs: {user_conf_ids}')
            ini_locs = user_conf_ids

        if any(ini_locs):
            ini_zma_save_fs = autofile.fs.zmatrix(ini_min_cnf_path)

            # Set up the run scripts
            script_str, kwargs = qchem_params(method_dct,
                                              elstruct.Job.OPTIMIZATION)

            # Set variables if it is a saddle
            two_stage = saddle
            mc_nsamp = spc_dct_i['mc_nsamp']
            resave = es_keyword_dct['resave']

            # Read the geometry and zma from the ini file system
            geo = ini_cnf_save_fs[-1].file.geometry.read(ini_locs)
            zma = ini_zma_save_fs[-1].file.zmatrix.read([0])

            # Read the torsions from the ini file sys
            if ini_zma_save_fs[-1].file.torsions.exists([0]):
                tors_dct = ini_zma_save_fs[-1].file.torsions.read([0])
                rotors = automol.rotor.from_data(zma, tors_dct)
                tors_names = automol.rotor.names(rotors, flat=True)
            else:
                tors_names = ()

            geo_path = ini_cnf_save_fs[-1].path(ini_locs)
            ioprinter.initial_geom_path('Sampling started', geo_path)

            # Check runsystem for equal ring CONF make conf_fs
            # Else make new ring conf directory
            rid = conformer.rng_loc_for_geo(geo, cnf_save_fs)

            if rid is None:
                conformer.single_conformer(zma,
                                           spc_info,
                                           mod_thy_info,
                                           cnf_run_fs,
                                           cnf_save_fs,
                                           script_str,
                                           overwrite,
                                           retryfail=retryfail,
                                           zrxn=zrxn,
                                           **kwargs)

                rid = conformer.rng_loc_for_geo(geo, cnf_save_fs)

            # Run the sampling
            conformer.conformer_sampling(zma,
                                         spc_info,
                                         mod_thy_info,
                                         cnf_run_fs,
                                         cnf_save_fs,
                                         rid,
                                         script_str,
                                         overwrite,
                                         nsamp_par=mc_nsamp,
                                         tors_names=tors_names,
                                         zrxn=zrxn,
                                         two_stage=two_stage,
                                         retryfail=retryfail,
                                         resave=resave,
                                         repulsion_thresh=40.0,
                                         print_debug=print_debug,
                                         **kwargs)
        else:
            ioprinter.info_message('Missing conformers. Skipping task...')

    elif job == 'pucker':

        # Build the ini zma filesys
        ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info)
        ini_min_locs, ini_min_cnf_path = ini_loc_info
        ini_zma_save_fs = autofile.fs.zmatrix(ini_min_cnf_path)

        # Set up the run scripts
        script_str, kwargs = qchem_params(method_dct,
                                          elstruct.Job.OPTIMIZATION)

        # Set variables if it is a saddle
        two_stage = saddle
        mc_nsamp = spc_dct_i['mc_nsamp']

        # Read the geometry and zma from the ini file system
        geo = ini_cnf_save_fs[-1].file.geometry.read(ini_min_locs)
        zma = ini_zma_save_fs[-1].file.zmatrix.read([0])

        # Read the torsions from the ini file sys
        if ini_zma_save_fs[-1].file.ring_torsions.exists([0]):
            ring_tors_dct = ini_zma_save_fs[-1].file.ring_torsions.read([0])
        else:
            ring_tors_dct = {}

        geo_path = ini_cnf_save_fs[-1].path(ini_min_locs)
        ioprinter.initial_geom_path('Sampling started', geo_path)

        # Run the sampling
        conformer.ring_conformer_sampling(zma,
                                          spc_info,
                                          mod_thy_info,
                                          cnf_run_fs,
                                          cnf_save_fs,
                                          script_str,
                                          overwrite,
                                          nsamp_par=mc_nsamp,
                                          ring_tors_dct=ring_tors_dct,
                                          zrxn=zrxn,
                                          two_stage=two_stage,
                                          retryfail=retryfail,
                                          **kwargs)

    elif job == 'opt':

        cnf_range = es_keyword_dct['cnf_range']
        hbond_cutoffs = spc_dct_i['hbond_cutoffs']
        cnf_sort_info_lst = _sort_info_lst(es_keyword_dct['sort'], thy_dct,
                                           spc_info)

        # Set up the run scripts
        script_str, kwargs = qchem_params(method_dct,
                                          elstruct.Job.OPTIMIZATION)

        rng_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
            cnf_save_fs, mod_thy_info, cnf_range='all', nprocs=nprocs)

        ini_rng_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
            ini_cnf_save_fs,
            mod_ini_thy_info,
            cnf_range=cnf_range,
            sort_info_lst=cnf_sort_info_lst,
            hbond_cutoffs=hbond_cutoffs,
            print_enes=True,
            nprocs=nprocs)

        # Truncate the list of the ini confs
        uni_rng_locs_lst, uni_cnf_locs_lst = conformer.unique_fs_ring_confs(
            cnf_save_fs, rng_cnf_locs_lst, ini_cnf_save_fs,
            ini_rng_cnf_locs_lst)
        # ioprinter.debug_message(
        #    'uni lst that has no similar ring', uni_rng_locs_lst)
        # ioprinter.debug_message(
        #    'uni lst that has similar ring', uni_cnf_locs_lst)

        for locs in uni_rng_locs_lst:
            rid, cid = locs
            # Obtain the zma from ini loc
            ini_cnf_save_path = ini_cnf_save_fs[-1].path(locs)
            ini_zma_save_fs = autofile.fs.zmatrix(ini_cnf_save_path)
            zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))

            # Make the ring filesystem
            conformer.single_conformer(zma,
                                       spc_info,
                                       mod_thy_info,
                                       cnf_run_fs,
                                       cnf_save_fs,
                                       script_str,
                                       overwrite,
                                       retryfail=retryfail,
                                       zrxn=zrxn,
                                       use_locs=locs,
                                       **kwargs)

        for locs in uni_cnf_locs_lst:
            ini_locs, rid = locs
            # Obtain the zma from ini loc
            ini_cnf_save_path = ini_cnf_save_fs[-1].path(ini_locs)
            ini_zma_save_fs = autofile.fs.zmatrix(ini_cnf_save_path)
            zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))
            # obtain conformer filesys associated with ring at the runlevel
            cid = autofile.schema.generate_new_conformer_id()
            conformer.single_conformer(zma,
                                       spc_info,
                                       mod_thy_info,
                                       cnf_run_fs,
                                       cnf_save_fs,
                                       script_str,
                                       overwrite,
                                       retryfail=retryfail,
                                       zrxn=zrxn,
                                       use_locs=(rid, cid),
                                       **kwargs)

        # print all geometres within cnfrange
        rng_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
            cnf_save_fs,
            mod_thy_info,
            cnf_range=cnf_range,
            sort_info_lst=cnf_sort_info_lst,
            hbond_cutoffs=hbond_cutoffs,
            nprocs=nprocs)
        for locs in rng_cnf_locs_lst:
            geo = cnf_save_fs[-1].file.geometry.read(locs)
            ioprinter.geometry(geo)

    elif job in ('energy', 'grad', 'hess', 'vpt2', 'prop'):

        cnf_range = es_keyword_dct['cnf_range']
        hbond_cutoffs = spc_dct_i['hbond_cutoffs']
        cnf_sort_info_lst = _sort_info_lst(es_keyword_dct['sort'], thy_dct,
                                           spc_info)

        user_conf_ids = spc_dct_i.get('conf_id')
        if user_conf_ids is None:
            ini_rng_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
                ini_cnf_save_fs,
                mod_ini_thy_info,
                cnf_range=cnf_range,
                sort_info_lst=cnf_sort_info_lst,
                hbond_cutoffs=hbond_cutoffs,
                print_enes=True,
                nprocs=nprocs)
        else:
            print(f'Using user specified conformer IDs: {user_conf_ids}')
            ini_rng_cnf_locs_lst = (user_conf_ids, )

        # Check if locs exist, kill if it doesn't
        if not ini_rng_cnf_locs_lst:
            ioprinter.error_message('No min-energy conformer found for level:')

        else:

            # Set up the run scripts
            script_str, kwargs = qchem_params(method_dct)

            # Grab frequencies for the reference, print ref freqs
            if job == 'hess':
                if ini_cnf_save_fs[-1].file.harmonic_frequencies.exists(
                        ini_rng_cnf_locs_lst[0]):
                    frq = ini_cnf_save_fs[-1].file.harmonic_frequencies.read(
                        ini_rng_cnf_locs_lst[0])
                    ref_val = frq
                else:
                    ref_val = None
                if ref_val is not None and zrxn is not None:
                    ref_path = cnf_save_fs[-1].path(ini_rng_cnf_locs_lst[0])
                    print('Found reference frequencies for saddle-point '
                          f'checks for conformer at\n {ref_path}')
                    ioprinter.frequencies(ref_val)
            else:
                ref_val = None

            # Run the job over all the conformers requested by the user
            print('Going over all requested conformers for task...\n')
            for ini_locs in ini_rng_cnf_locs_lst:
                ini_cnf_run_fs[-1].create(ini_locs)
                geo_save_path = ini_cnf_save_fs[-1].path(ini_locs)
                ini_zma_save_fs = autofile.fs.zmatrix(geo_save_path)
                print('Running task for geometry at ', geo_save_path)
                geo = ini_cnf_save_fs[-1].file.geometry.read(ini_locs)
                zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))
                ES_TSKS[job](zma,
                             geo,
                             spc_info,
                             mod_thy_info,
                             ini_cnf_run_fs,
                             ini_cnf_save_fs,
                             ini_locs,
                             run_prefix,
                             script_str,
                             overwrite,
                             zrxn=zrxn,
                             retryfail=retryfail,
                             method_dct=method_dct,
                             ref_val=ref_val,
                             **kwargs)
                print('\n === FINISHED CONF ===\n')
Esempio n. 17
0
def thy_dcts(tsname, ts_dct, thy_dct, es_keyword_dct,
             run_prefix, save_prefix):
    """ set the theory
    """

    # Get transition state info
    ts_zma = ts_dct['zma']
    aspace = ts_dct['active']

    # Set reaction info
    rxn_info = ts_dct['rxn_info']
    ts_info = rinfo.ts_info(rxn_info)
    rct_info = rinfo.rgt_info(rxn_info, 'reacs')
    rxn_info_sort = rinfo.sort(rxn_info)

    # Set the high-sping ts info
    high_mult = rinfo.ts_mult(rxn_info, rxn_mul='high')
    hs_info = (ts_info[0], ts_info[1], high_mult)

    # Set the filesystem locs
    ts_locs = (int(tsname.split('_')[-1]),)
    zma_locs = (ts_dct.get('zma_idx', 0),)

    # Initialize the theory objects
    ini_thy_info, mod_ini_thy_info = None, None
    thy_info, mod_thy_info = None, None
    vscnlvl_thy_info, mod_vscnlvl_thy_info = None, None
    vsp1lvl_thy_info, mod_vsp1lvl_thy_info = None, None
    vsp2lvl_thy_info, mod_vsp2lvl_thy_info = None, None
    hs_vscnlvl_thy_info = None
    hs_vsp1lvl_thy_info = None
    hs_vsp2lvl_thy_info = None
    hs_thy_info = None

    # Method dicts
    ini_method_dct = None
    run_method_dct = None
    vscn_method_dct = None
    vsp1_method_dct = None
    vsp2_method_dct = None

    # Multireference Params
    inplvl_mref_params = {}
    runlvl_mref_params = {}
    vscn_mref_params = {}
    vsp1_mref_params = {}
    vsp2_mref_params = {}

    # Initialize the necessary run filesystem
    runlvl_scn_run_fs = None
    runlvl_cscn_run_fs = None
    vscnlvl_ts_run_fs = None
    vscnlvl_scn_run_fs = None
    vscnlvl_cscn_run_fs = None
    vrctst_run_fs = None

    # Initialize the necessary save filesystem
    inplvl_cnf_save_fs = None
    runlvl_scn_save_fs = None   # above cnf filesys, for search scans
    runlvl_cscn_save_fs = None   # above cnf filesys, for search scans
    runlvl_cnf_save_fs = None
    vscnlvl_scn_save_fs = None
    vscnlvl_cscn_save_fs = None
    vrctst_save_fs = None

    if es_keyword_dct.get('inplvl', None) is not None:

        ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
        ini_thy_info = tinfo.from_dct(ini_method_dct)
        mod_ini_thy_info = tinfo.modify_orb_label(
            ini_thy_info, ts_info)

        # Conformer Layer for saddle point structures
        _, inplvl_cnf_save_fs = build_fs(
            run_prefix, save_prefix, 'CONFORMER',
            rxn_locs=rxn_info_sort, ts_locs=ts_locs,
            thy_locs=mod_ini_thy_info[1:])

        inplvl_loc_info = filesys.mincnf.min_energy_conformer_locators(
            inplvl_cnf_save_fs, mod_thy_info)
        inplvl_min_cnf_locs, _ = inplvl_loc_info
        inplvl_cnf_save_tuple = (inplvl_cnf_save_fs, inplvl_min_cnf_locs)

        if elstruct.par.Method.is_multiref(ini_thy_info[1]):
            inplvl_mref_params = multireference_calculation_parameters(
                ts_zma, ts_info, hs_info,
                aspace, mod_ini_thy_info, rxn_info=rxn_info)

    if es_keyword_dct.get('runlvl', None) is not None:

        run_method_dct = thy_dct.get(es_keyword_dct['runlvl'])
        thy_info = tinfo.from_dct(run_method_dct)
        mod_thy_info = tinfo.modify_orb_label(
            thy_info, ts_info)
        hs_thy_info = tinfo.modify_orb_label(
            thy_info, hs_info)

        # Conformer Layer for saddle point structures
        runlvl_cnf_run_fs, runlvl_cnf_save_fs = build_fs(
            run_prefix, save_prefix, 'CONFORMER',
            rxn_locs=rxn_info_sort, ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:])

        runlvl_loc_info = filesys.mincnf.min_energy_conformer_locators(
            runlvl_cnf_save_fs, mod_thy_info)
        runlvl_min_cnf_locs, _ = runlvl_loc_info
        runlvl_cnf_save_tuple = (runlvl_cnf_save_fs, runlvl_min_cnf_locs)

        # TS/IDX/Z Layer used for coordinate scans (perhaps for guesses)
        _, runlvl_z_save_fs = build_fs(
            run_prefix, save_prefix, 'ZMATRIX',
            rxn_locs=rxn_info_sort, ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:])

        runlvl_scn_run_fs, runlvl_scn_save_fs = build_fs(
            run_prefix, save_prefix, 'SCAN',
            rxn_locs=rxn_info_sort, ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:], zma_locs=zma_locs)

        runlvl_cscn_run_fs, runlvl_cscn_save_fs = build_fs(
            run_prefix, save_prefix, 'CSCAN',
            rxn_locs=rxn_info_sort, ts_locs=ts_locs,
            thy_locs=mod_thy_info[1:], zma_locs=zma_locs)

        if elstruct.par.Method.is_multiref(thy_info[1]):
            runlvl_mref_params = multireference_calculation_parameters(
                ts_zma, ts_info, hs_info,
                aspace, mod_thy_info, rxn_info=rxn_info)

    if es_keyword_dct.get('var_scnlvl', None) is not None:

        vscn_method_dct = thy_dct.get(es_keyword_dct['var_scnlvl'])
        vscnlvl_thy_info = tinfo.from_dct(vscn_method_dct)
        mod_vscnlvl_thy_info = tinfo.modify_orb_label(
            vscnlvl_thy_info, ts_info)
        hs_vscnlvl_thy_info = tinfo.modify_orb_label(
            vscnlvl_thy_info, hs_info)

        vscnlvl_scn_run_fs, vscnlvl_scn_save_fs = build_fs(
            run_prefix, save_prefix, 'SCAN',
            rxn_locs=rxn_info_sort, ts_locs=ts_locs,
            thy_locs=mod_vscnlvl_thy_info[1:], zma_locs=zma_locs)

        vscnlvl_cscn_run_fs, vscnlvl_cscn_save_fs = build_fs(
            run_prefix, save_prefix, 'CSCAN',
            rxn_locs=rxn_info_sort, ts_locs=ts_locs,
            thy_locs=mod_vscnlvl_thy_info[1:], zma_locs=zma_locs)

        vrctst_run_fs, vrctst_save_fs = build_fs(
            run_prefix, save_prefix, 'VRCTST',
            rxn_locs=rxn_info_sort, ts_locs=ts_locs,
            thy_locs=mod_vscnlvl_thy_info[1:])

        if elstruct.par.Method.is_multiref(vscnlvl_thy_info[1]):
            vscn_mref_params = multireference_calculation_parameters(
                ts_zma, ts_info, hs_info,
                aspace, mod_vscnlvl_thy_info, rxn_info=rxn_info)

    if es_keyword_dct.get('var_splvl1', None) is not None:

        vsp1_method_dct = thy_dct.get(es_keyword_dct['var_splvl1'])
        vsp1lvl_thy_info = tinfo.from_dct(vsp1_method_dct)
        mod_vsp1lvl_thy_info = tinfo.modify_orb_label(
            vsp1lvl_thy_info, ts_info)
        hs_vsp1lvl_thy_info = tinfo.modify_orb_label(
            vsp1lvl_thy_info, hs_info)

        if elstruct.par.Method.is_multiref(vsp1lvl_thy_info[1]):
            vsp1_mref_params = multireference_calculation_parameters(
                ts_zma, ts_info, hs_info,
                aspace, mod_vsp1lvl_thy_info, rxn_info=rxn_info)

    if es_keyword_dct.get('var_splvl2', None) is not None:

        vsp2_method_dct = thy_dct.get(es_keyword_dct['var_splvl2'])
        vsp2lvl_thy_info = tinfo.from_dct(vsp2_method_dct)
        mod_vsp2lvl_thy_info = tinfo.modify_orb_label(
            vsp2lvl_thy_info, ts_info)
        hs_vsp2lvl_thy_info = tinfo.modify_orb_label(
            vsp2lvl_thy_info, hs_info)

        if elstruct.par.Method.is_multiref(vsp2lvl_thy_info[1]):
            vsp2_mref_params = multireference_calculation_parameters(
                ts_zma, ts_info, hs_info,
                aspace, mod_vsp2lvl_thy_info, rxn_info=rxn_info)

    # Get the conformer filesys for the reactants
    _rcts_cnf_fs = rcts_cnf_fs(rct_info, ini_thy_info, run_prefix, save_prefix)
    if _rcts_cnf_fs is None:
        _rcts_cnf_fs = rcts_cnf_fs(rct_info, thy_info, run_prefix, save_prefix)

    thy_inf_dct = {
        'inplvl': ini_thy_info,
        'runlvl': thy_info,
        'var_scnlvl': vscnlvl_thy_info,
        'var_splvl1': vsp1lvl_thy_info,
        'var_splvl2': vsp2lvl_thy_info,
        'mod_inplvl': mod_ini_thy_info,
        'mod_runlvl': mod_thy_info,
        'mod_var_scnlvl': mod_vscnlvl_thy_info,
        'mod_var_splvl1': mod_vsp1lvl_thy_info,
        'mod_var_splvl2': mod_vsp2lvl_thy_info,
        'hs_var_scnlvl': hs_vscnlvl_thy_info,
        'hs_var_splvl1': hs_vsp1lvl_thy_info,
        'hs_var_splvl2': hs_vsp2lvl_thy_info,
        'hs_runlvl': hs_thy_info,
        'rct_info': rct_info
    }

    thy_method_dct = {
        'inplvl': ini_method_dct,
        'runlvl': run_method_dct,
        'var_scnlvl': vscn_method_dct,
        'var_splvl1': vsp1_method_dct,
        'var_splvl2': vsp2_method_dct,
    }

    mref_params_dct = {
        'inplvl': inplvl_mref_params,
        'runlvl': runlvl_mref_params,
        'var_scnlvl': vscn_mref_params,
        'var_splvl1': vsp1_mref_params,
        'var_splvl2': vsp2_mref_params,
    }

    runfs_dct = {
        'runlvl_scn': runlvl_scn_run_fs,
        'runlvl_cscn': runlvl_cscn_run_fs,
        'runlvl_cnf': runlvl_cnf_run_fs,
        'vscnlvl_ts': vscnlvl_ts_run_fs,
        'vscnlvl_scn': vscnlvl_scn_run_fs,
        'vscnlvl_cscn': vscnlvl_cscn_run_fs,
        'vrctst': vrctst_run_fs,
        'prefix': run_prefix
    }

    savefs_dct = {
        'runlvl_scn': runlvl_scn_save_fs,
        'runlvl_cscn': runlvl_cscn_save_fs,
        'runlvl_ts_zma': runlvl_z_save_fs,
        'inplvl_cnf_tuple': inplvl_cnf_save_tuple,
        'runlvl_cnf_tuple': runlvl_cnf_save_tuple,
        'vscnlvl_scn': vscnlvl_scn_save_fs,
        'vscnlvl_cscn': vscnlvl_cscn_save_fs,
        'vrctst': vrctst_save_fs,
        'rcts_cnf': _rcts_cnf_fs,
        'prefix': save_prefix
    }

    return (thy_inf_dct, thy_method_dct,
            mref_params_dct,
            runfs_dct, savefs_dct)
Esempio n. 18
0
def rpath_tsk(job, spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix,
              save_prefix):
    """ run a scan over the specified torsional coordinates
    """

    # Get dct for specific species task is run for
    spc_dct_i = spc_dct[spc_name]

    # Set up coordinate name
    rxn_coord = es_keyword_dct.get('rxn_coord')
    if rxn_coord == 'auto':
        coord_name = ['Rn']  # grab from zrxn object
    else:
        # coord_name =
        coord_name = ['IRC']

    # Set the spc_info
    spc_info = sinfo.from_dct(spc_dct_i)

    # Modify the theory
    method_dct = thy_dct.get(es_keyword_dct['runlvl'])
    ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
    thy_info = tinfo.from_dct(method_dct)
    ini_thy_info = tinfo.from_dct(ini_method_dct)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, spc_info)

    # Get options from the dct or es options lst
    overwrite = es_keyword_dct['overwrite']
    # retryfail = es_keyword_dct['retryfail']

    # Set up the script
    script_str, kwargs = qchem_params(method_dct, elstruct.Job.OPTIMIZATION)

    # Set the filesystem objects
    rxn_info = spc_dct_i['rxn_info']
    fs_rxn_info = rinfo.sort(rxn_info)

    # New filesystem objects
    if coord_name == 'irc':
        _root = root_locs(spc_dct_i, saddle=True)
        # ini_cnf_run_fs, ini_cnf_save_fs = build_fs(
        #     run_prefix, save_prefix, 'CONFORMER',
        #     thy_locs=mod_ini_thy_info[1:],
        #     **_root)
        # cnf_run_fs, cnf_save_fs = build_fs(
        #     run_prefix, save_prefix, 'CONFORMER',
        #     thy_locs=mod_thy_info[1:],
        #     **_root)
        ini_cnf_run_fs, ini_cnf_save_fs = build_fs(
            run_prefix,
            save_prefix,
            'CONFORMER',
            thy_locs=mod_ini_thy_info[1:],
            **_root)
        cnf_run_fs, cnf_save_fs = build_fs(run_prefix,
                                           save_prefix,
                                           'CONFORMER',
                                           thy_locs=mod_thy_info[1:],
                                           **_root)
        ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info)
        ini_min_locs, ini_pfx_save_path = ini_loc_info
        # ini_min_rng_locs, ini_min_cnf_locs = ini_min_cnf_locs
        # ini_min_rng_path, ini_min_cnf_path = ini_min_cnf_path
        ini_cnf_run_fs[-1].create(ini_min_locs)
        ini_pfx_run_path = ini_cnf_run_fs[-1].path(ini_min_locs)

    else:
        ts_info = (ts_num, )
        ini_ts_run_fs, ini_ts_save_fs = build_fs(run_prefix,
                                                 save_prefix,
                                                 'TS',
                                                 thy_locs=mod_ini_thy_info[1:],
                                                 **_root)
        ini_pfx_run_path = ini_ts_run_fs.path(ts_info)
        ini_pfx_save_path = ini_ts_save_fs.path(ts_info)

    # Get options from the dct or es options lst
    overwrite = es_keyword_dct['overwrite']

    ini_scn_run_fs, ini_scn_save_fs = build_fs(ini_pfx_run_path,
                                               ini_pfx_save_path,
                                               'SCAN',
                                               zma_locs=(0, ))

    ini_zma_save_fs = autofile.fs.zmatrix(ini_cnf_save_path)
    geo = ini_cnf_save_fs[-1].file.geometry.read(ini_min_locs)
    zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))

    # Run job
    if job == 'scan':

        if rcoord == 'auto':
            pass
        elif rcoord == 'irc':
            rpath.irc_scan(geo, spc_info, coord_name, mod_ini_thy_info,
                           ini_method_dct, ini_scn_save_fs, ini_cnf_run_path,
                           overwrite)

    elif job in ('energy', 'grad', 'hess'):

        # Script
        script_str, kwargs = qchem_params(method_dct)

        # Need to put in something with the IRC idxs
        for locs in ini_scn_save_fs[-1].existing():
            geo_run_path = ini_scn_run_fs[-1].path(locs)
            geo_save_path = ini_scn_save_fs[-1].path(locs)
            geo = ini_scn_save_fs[-1].file.geometry.read(locs)
            zma = None
            ini_scn_run_fs[-1].create(locs)
            ES_TSKS[job](zma, geo, spc_info, mod_thy_info, ini_scn_save_fs,
                         geo_run_path, geo_save_path, locs, script_str,
                         overwrite, **kwargs)
            ioprinter.obj('vspace')

    elif job == 'infene':
        pass
Esempio n. 19
0
def hr_tsk(job, spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix,
           save_prefix):
    """ run a scan over the specified torsional coordinates
    """

    spc_dct_i = spc_dct[spc_name]
    saddle = bool('ts_' in spc_name)
    # Set the spc_info
    if not saddle:
        spc_info = sinfo.from_dct(spc_dct_i)
    else:
        spc_info = rinfo.ts_info(spc_dct_i['rxn_info'])

    # Modify the theory
    method_dct = thy_dct.get(es_keyword_dct['runlvl'])
    ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
    thy_info = tinfo.from_dct(method_dct)
    ini_thy_info = tinfo.from_dct(ini_method_dct)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, spc_info)

    # Set the filesystem objects
    _root = root_locs(spc_dct_i, saddle=saddle, name=spc_name)
    ini_cnf_run_fs, ini_cnf_save_fs = build_fs(run_prefix,
                                               save_prefix,
                                               'CONFORMER',
                                               thy_locs=mod_ini_thy_info[1:],
                                               **_root)
    cnf_run_fs, cnf_save_fs = build_fs(run_prefix,
                                       save_prefix,
                                       'CONFORMER',
                                       thy_locs=mod_thy_info[1:],
                                       **_root)
    instab_save_fs = ()

    ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
        ini_cnf_save_fs, mod_ini_thy_info)
    ini_min_locs, ini_cnf_save_path = ini_loc_info
    # ini_min_rng_locs, ini_min_cnf_locs = ini_min_cnf_locs
    # ini_min_rng_path, ini_min_cnf_path = ini_min_cnf_path

    # Create run fs if that directory has been deleted to run the jobs
    ini_cnf_run_fs[-1].create(ini_min_locs)
    ini_cnf_run_path = ini_cnf_run_fs[-1].path(ini_min_locs)

    # Get options from the dct or es options lst
    overwrite = es_keyword_dct['overwrite']
    retryfail = es_keyword_dct['retryfail']
    tors_model = es_keyword_dct['tors_model']

    # Read zma, geo, and torsions
    ini_zma_save_fs = autofile.fs.zmatrix(ini_cnf_save_path)
    geo = ini_cnf_save_fs[-1].file.geometry.read(ini_min_locs)
    zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))
    if ini_zma_save_fs[-1].file.torsions.exists([0]):
        tors_dct = ini_zma_save_fs[-1].file.torsions.read([0])
        torsions = automol.rotor.from_data(
            zma,
            tors_dct,
        )
    else:
        torsions = ()

    # Run the task if any torsions exist
    if any(torsions):

        scn = 'SCAN' if 'fa' not in tors_model else 'CSCAN'
        ini_scn_run_fs, ini_scn_save_fs = build_fs(ini_cnf_run_path,
                                                   ini_cnf_save_path,
                                                   scn,
                                                   zma_locs=(0, ))

        if job == 'scan':

            increment = spc_dct_i.get('hind_inc', 30.0 * phycon.DEG2RAD)
            hr.hindered_rotor_scans(zma,
                                    spc_info,
                                    mod_thy_info,
                                    instab_save_fs,
                                    ini_scn_run_fs,
                                    ini_scn_save_fs,
                                    torsions,
                                    tors_model,
                                    method_dct,
                                    overwrite,
                                    saddle=saddle,
                                    increment=increment,
                                    retryfail=retryfail)

        # elif job == 'reopt':

        #     # pull stuff from dcts
        #     two_stage = saddle
        #     rxn_class = spc_dct_i['class'] if saddle else ''
        #     mc_nsamp = spc_dct_i['mc_nsamp']
        #     ethresh = es_keyword_dct['hrthresh']

        #     # Read and print the potential
        #     sp_fs = autofile.fs.single_point(ini_cnf_save_path)
        #     ref_ene = sp_fs[-1].file.energy.read(mod_ini_thy_info[1:4])
        #     # ref_ene = ini_cnf_save_fs[-1].file.energy.read(ini_min_cnf_locs)
        #     tors_pots, tors_zmas, tors_paths = {}, {}, {}
        #     for tors_names, tors_grids in zip(run_tors_names, run_tors_grids):
        #         constraint_dct = automol.zmat.build_constraint_dct(
        #             zma, const_names, tors_names)
        #         pot, _, _, _, zmas, paths = filesys.read.potential(
        #             tors_names, tors_grids,
        #             ini_cnf_save_path,
        #             mod_ini_thy_info, ref_ene,
        #             constraint_dct,
        #             read_zma=True)
        #         tors_pots[tors_names] = pot
        #         tors_zmas[tors_names] = zmas
        #         tors_paths[tors_names] = paths

        #     # Check for new minimum conformer
        #     new_min_zma = __.check_hr_pot(
        #         tors_pots, tors_zmas, tors_paths, emax=ethresh)

        #     if new_min_zma is not None:
        #         ioprinter.info_message(
        #             'Finding new low energy conformer...', newline=1)
        #         conformer.single_conformer(
        #             zma, spc_info, mod_thy_info,
        #             ini_cnf_run_fs, ini_cnf_save_fs,
        #             script_str, overwrite,
        #             retryfail=retryfail, rxn=rxn, **kwargs)

        elif job in ('energy', 'grad', 'hess', 'vpt2'):

            # Script (add energy script call)
            script_str, kwargs = qchem_params(method_dct)

            run_tors_names = automol.rotor.names(torsions, flat=True)
            for tors_names in run_tors_names:

                # Set the constraint dct and filesys for the scan
                const_names = automol.zmat.set_constraint_names(
                    zma, run_tors_names, tors_model)
                constraint_dct = automol.zmat.build_constraint_dct(
                    zma, const_names, tors_names)

                # get the scn_locs, maybe get a function?
                scn_locs = ()
                for locs in scn_locs:
                    geo_run_path = ini_scn_run_fs[-1].path(locs)
                    geo_save_path = ini_scn_save_fs[-1].path(locs)
                    geo = ini_scn_save_fs[-1].file.geometry.read(locs)
                    zma = ini_scn_save_fs[-1].file.zmatrix.read(locs)
                    ini_scn_run_fs[-1].create(locs)
                    ES_TSKS[job](zma,
                                 geo,
                                 spc_info,
                                 mod_thy_info,
                                 ini_scn_save_fs,
                                 geo_run_path,
                                 geo_save_path,
                                 locs,
                                 script_str,
                                 overwrite,
                                 retryfail=retryfail,
                                 **kwargs)
                    ioprinter.obj('vspace')
    else:
        ioprinter.info_message('No torsional modes in the species')
Esempio n. 20
0
def tau_tsk(job, spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix,
            save_prefix):
    """ Energies, gradients, and hessians,
        for set of arbitrarily sampled torsional coordinates
        with all other coordinates optimized
    """
    spc_dct_i = spc_dct[spc_name]

    # Set the spc_info
    spc_info = sinfo.from_dct(spc_dct_i)

    # Get es options
    overwrite = es_keyword_dct['overwrite']
    retryfail = es_keyword_dct['retryfail']
    # scan_increment = spc_dct_i['hind_inc']
    nsamp_par = spc_dct_i['tau_nsamp']

    # Modify the theory
    method_dct = thy_dct.get(es_keyword_dct['runlvl'])
    ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
    thy_info = tinfo.from_dct(method_dct)
    ini_thy_info = tinfo.from_dct(ini_method_dct)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, spc_info)

    # Script
    script_str, kwargs = qchem_params(method_dct, elstruct.Job.OPTIMIZATION)

    # Set the filesystem objects for thy info
    _, ini_cnf_save_fs = build_fs(run_prefix,
                                  save_prefix,
                                  'CONFORMER',
                                  spc_locs=spc_info,
                                  thy_locs=mod_ini_thy_info[1:])
    ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
        ini_cnf_save_fs, mod_ini_thy_info)
    ini_min_cnf_locs, ini_min_cnf_path = ini_loc_info
    ini_min_rid, ini_min_cid = ini_min_cnf_locs

    ini_zma_save_fs = autofile.fs.zmatrix(ini_min_cnf_path)
    geo = ini_cnf_save_fs[-1].file.geometry.read(ini_min_cnf_locs)
    zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))
    ini_sp_save_fs = autofile.fs.single_point(ini_min_cnf_path)
    if ini_sp_save_fs[-1].file.energy.exists(mod_ini_thy_info[1:4]):
        ref_ene = ini_sp_save_fs[-1].file.energy.read(mod_ini_thy_info[1:4])
    else:
        ref_ene = ini_cnf_save_fs[-1].file.energy.read(ini_min_cnf_locs)

    # Get the tors names
    ini_zma_save_fs = autofile.fs.zmatrix(ini_min_cnf_path)
    if ini_zma_save_fs[-1].file.torsions.exists([0]):
        tors_dct = ini_zma_save_fs[-1].file.torsions.read([0])
        torsions = automol.rotor.from_data(zma, tors_dct)
    else:
        torsions = ()

    saddle = bool('ts_' in spc_name)

    # Run the task if any torsions exist
    if torsions and not saddle:

        # Set up tau filesystem objects
        tau_run_fs, tau_save_fs = build_fs(run_prefix,
                                           save_prefix,
                                           'TAU',
                                           spc_locs=spc_info,
                                           thy_locs=mod_thy_info[1:])
        # db_style = 'jsondb'
        db_style = 'directory'
        if db_style == 'jsondb':
            tau_save_fs[-1].root.create()
            tau_save_fs[-1].json_create()
            for locs in tau_save_fs[-1].existing():
                if tau_save_fs[-1].file.geometry.exists(locs):
                    geol = tau_save_fs[-1].file.geometry.read(locs)
                    tau_save_fs[-1].json.geometry.write(geol, locs)
                if tau_save_fs[-1].file.energy.exists(locs):
                    enel = tau_save_fs[-1].file.energy.read(locs)
                    tau_save_fs[-1].json.energy.write(enel, locs)
                if tau_save_fs[-1].file.geometry_info.exists(locs):
                    geo_infl = tau_save_fs[-1].file.geometry_info.read(locs)
                    tau_save_fs[-1].json.geometry_info.write(geo_infl, locs)
                if tau_save_fs[-1].file.geometry_input.exists(locs):
                    inp_strl = tau_save_fs[-1].file.geometry_input.read(locs)
                    tau_save_fs[-1].json.geometry_input.write(inp_strl, locs)
                if tau_save_fs[-1].file.gradient_input.exists(locs):
                    inp_strl = tau_save_fs[-1].file.gradient_input.read(locs)
                    tau_save_fs[-1].json.gradient_input.write(inp_strl, locs)
                if tau_save_fs[-1].file.hessian_input.exists(locs):
                    inp_strl = tau_save_fs[-1].file.hessian_input.read(locs)
                    tau_save_fs[-1].json.hessian_input.write(inp_strl, locs)
                if tau_save_fs[-1].file.gradient_info.exists(locs):
                    inf_objl = tau_save_fs[-1].file.gradient_info.read(locs)
                    tau_save_fs[-1].json.gradient_info.write(inf_objl, locs)
                if tau_save_fs[-1].file.hessian_info.exists(locs):
                    inf_objl = tau_save_fs[-1].file.hessian_info.read(locs)
                    tau_save_fs[-1].json.hessian_info.write(inf_objl, locs)
                if tau_save_fs[-1].file.gradient.exists(locs):
                    gradl = tau_save_fs[-1].file.gradient.read(locs)
                    tau_save_fs[-1].json.gradient.write(gradl, locs)
                if tau_save_fs[-1].file.hessian.exists(locs):
                    hessl = tau_save_fs[-1].file.hessian.read(locs)
                    tau_save_fs[-1].json.energy.hessian(hessl, locs)
                if tau_save_fs[-1].file.zmatrix.exists(locs):
                    zmatl = tau_save_fs[-1].file.zmatrix.read(locs)
                    tau_save_fs[-1].json.zmatrix.write(zmatl, locs)
                if tau_save_fs[-1].file.harmonic_frequencies.exists(locs):
                    hfreql = tau_save_fs[-1].file.harmonic_frequencies.read(
                        locs)
                    tau_save_fs[-1].json.harmonic_frequencies.write(
                        hfreql, locs)
                save_path = tau_save_fs[-1].path(locs)
                sp_save_fs = autofile.fs.single_point(save_path)
                sp_save_locs = sp_save_fs[-1].existing()
                save_path = tau_save_fs[-1].root.path()
                jsp_save_fs = autofile.fs.single_point(save_path,
                                                       json_layer=locs)
                for sp_locs in sp_save_locs:
                    if sp_save_fs[-1].file.energy.exists(sp_locs):
                        enel = sp_save_fs[-1].file.energy.read(sp_locs)
                        jsp_save_fs[-1].json.energy.write(enel, sp_locs)
                    if sp_save_fs[-1].file.input.exists(sp_locs):
                        inp_strl = sp_save_fs[-1].file.input.read(sp_locs)
                        jsp_save_fs[-1].json.input.write(inp_strl, sp_locs)
                    if sp_save_fs[-1].file.info.exists(sp_locs):
                        inf_objl = sp_save_fs[-1].file.info.read(sp_locs)
                        jsp_save_fs[-1].json.info.write(inf_objl, sp_locs)

        if job == 'samp':

            # Set up the script
            script_str, kwargs = qchem_params(method_dct,
                                              elstruct.Job.OPTIMIZATION)

            tors_names = automol.rotor.names(torsions, flat=True)
            # Run sampling
            tau.tau_sampling(zma,
                             ref_ene,
                             spc_info,
                             tors_names,
                             nsamp_par,
                             mod_ini_thy_info,
                             tau_run_fs,
                             tau_save_fs,
                             script_str,
                             overwrite,
                             saddle=saddle,
                             **kwargs)

        elif job in ('energy', 'grad'):

            # Set up the run scripts
            script_str, kwargs = qchem_params(method_dct)

            # Run the job over all the conformers requested by the user
            for locs in tau_save_fs[-1].existing():
                geo_run_path = tau_run_fs[-1].path(locs)
                if db_style == 'jsondb':
                    geo_save_path = tau_save_fs[-1].root.path()
                    geo = tau_save_fs[-1].json.geometry.read(locs)
                elif db_style == 'directory':
                    geo_save_path = tau_save_fs[-1].path(locs)
                    geo = tau_save_fs[-1].file.geometry.read(locs)
                tau_run_fs[-1].create(locs)
                zma = None
                ES_TSKS[job](zma,
                             geo,
                             spc_info,
                             mod_thy_info,
                             tau_save_fs,
                             geo_run_path,
                             geo_save_path,
                             locs,
                             script_str,
                             overwrite,
                             retryfail=retryfail,
                             **kwargs)
                ioprinter.obj('vspace')

        elif job == 'hess':

            # Add the hessian max
            hessmax = es_keyword_dct['hessmax']

            # Set up the run scripts
            script_str, kwargs = qchem_params(method_dct)

            # Run the job over all the conformers requested by the user
            hess_cnt = 0
            for locs in tau_save_fs.existing():
                ioprinter.info_message('HESS Number {}'.format(hess_cnt + 1),
                                       newline=1)
                geo_run_path = tau_run_fs[-1].path(locs)
                if db_style == 'directory':
                    geo_save_path = tau_save_fs[-1].path(locs)
                    if tau_save_fs[-1].file.hessian.exists(locs):
                        ioprinter.existing_path('Hessian', geo_save_path)
                        hess_cnt += 1
                        continue
                    geo = tau_save_fs[-1].file.geometry.read(locs)
                elif db_style == 'jsondb':
                    geo_save_path = tau_save_fs[-1].root.path()
                    if tau_save_fs[-1].json.hessian.exists(locs):
                        ioprinter.existing_path('Hessian', geo_save_path)
                        hess_cnt += 1
                        continue
                    geo = tau_save_fs[-1].json.geometry.read(locs)
                zma = None
                tau_run_fs[-1].create(locs)
                ES_TSKS[job](zma,
                             geo,
                             spc_info,
                             mod_thy_info,
                             tau_save_fs,
                             geo_run_path,
                             geo_save_path,
                             locs,
                             script_str,
                             overwrite,
                             retryfail=retryfail,
                             **kwargs)
                hess_cnt += 1
                if hess_cnt == hessmax:
                    break

    else:
        ioprinter.info_message('No torsional modes in the species')
Esempio n. 21
0
def conformer_tsk(job, spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix,
                  save_prefix):
    """ Launch tasks associated with conformers.
        Scan: Generate a set of conformer geometries and energies via
              random sampling over torsional coordinates
              following by optimization
        SP: Calculate ene, grad, ..
    """

    saddle = bool('ts_' in spc_name)

    spc_dct_i = spc_dct[spc_name]

    # Set the spc_info
    if not saddle:
        spc_info = sinfo.from_dct(spc_dct_i)
    else:
        spc_info = rinfo.ts_info(spc_dct_i['rxn_info'])
    zrxn = spc_dct_i.get('zrxn', None)

    overwrite = es_keyword_dct['overwrite']
    retryfail = es_keyword_dct['retryfail']

    # Modify the theory
    method_dct = thy_dct.get(es_keyword_dct['runlvl'])
    ini_method_dct = thy_dct.get(es_keyword_dct['inplvl'])
    thy_info = tinfo.from_dct(method_dct)
    ini_thy_info = tinfo.from_dct(ini_method_dct)
    mod_thy_info = tinfo.modify_orb_label(thy_info, spc_info)
    mod_ini_thy_info = tinfo.modify_orb_label(ini_thy_info, spc_info)

    # New filesystem objects
    _root = root_locs(spc_dct_i, saddle=saddle, name=spc_name)
    ini_cnf_run_fs, ini_cnf_save_fs = build_fs(run_prefix,
                                               save_prefix,
                                               'CONFORMER',
                                               thy_locs=mod_ini_thy_info[1:],
                                               **_root)
    cnf_run_fs, cnf_save_fs = build_fs(run_prefix,
                                       save_prefix,
                                       'CONFORMER',
                                       thy_locs=mod_thy_info[1:],
                                       **_root)

    if job == 'samp':

        # Build the ini zma filesys
        ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info)
        ini_locs, ini_min_cnf_path = ini_loc_info
        ini_min_rid, ini_min_cid = ini_locs

        ini_zma_save_fs = autofile.fs.zmatrix(ini_min_cnf_path)

        # Set up the run scripts
        script_str, kwargs = qchem_params(method_dct,
                                          elstruct.Job.OPTIMIZATION)

        # Set variables if it is a saddle
        two_stage = saddle
        mc_nsamp = spc_dct_i['mc_nsamp']
        resave = es_keyword_dct['resave']

        # Read the geometry and zma from the ini file system
        geo = ini_cnf_save_fs[-1].file.geometry.read(ini_locs)
        zma = ini_zma_save_fs[-1].file.zmatrix.read([0])

        # Read the torsions from the ini file sys
        if ini_zma_save_fs[-1].file.torsions.exists([0]):
            tors_dct = ini_zma_save_fs[-1].file.torsions.read([0])
            rotors = automol.rotor.from_data(zma, tors_dct)
            tors_names = automol.rotor.names(rotors, flat=True)
        else:
            tors_names = ()

        geo_path = ini_cnf_save_fs[-1].path(ini_locs)
        ioprinter.initial_geom_path('Sampling started', geo_path)

        # Check runsystem for equal ring CONF make conf_fs
        # Else make new ring conf directory
        rid = conformer.rng_loc_for_geo(geo, cnf_run_fs, cnf_save_fs)

        if rid is None:
            conformer.single_conformer(zma,
                                       spc_info,
                                       mod_thy_info,
                                       cnf_run_fs,
                                       cnf_save_fs,
                                       script_str,
                                       overwrite,
                                       retryfail=retryfail,
                                       zrxn=zrxn,
                                       **kwargs)

            rid = conformer.rng_loc_for_geo(geo, cnf_run_fs, cnf_save_fs)

        # Run the sampling
        conformer.conformer_sampling(zma,
                                     spc_info,
                                     mod_thy_info,
                                     cnf_run_fs,
                                     cnf_save_fs,
                                     rid,
                                     script_str,
                                     overwrite,
                                     nsamp_par=mc_nsamp,
                                     tors_names=tors_names,
                                     zrxn=zrxn,
                                     two_stage=two_stage,
                                     retryfail=retryfail,
                                     resave=resave,
                                     **kwargs)

    elif job == 'pucker':

        # Build the ini zma filesys
        ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info)
        ini_min_locs, ini_min_cnf_path = ini_loc_info
        ini_min_rid, ini_min_cid = ini_min_locs
        ini_zma_save_fs = autofile.fs.zmatrix(ini_min_cnf_path)

        # Set up the run scripts
        script_str, kwargs = qchem_params(method_dct,
                                          elstruct.Job.OPTIMIZATION)

        # Set variables if it is a saddle
        two_stage = saddle
        mc_nsamp = spc_dct_i['mc_nsamp']

        # Read the geometry and zma from the ini file system
        geo = ini_cnf_save_fs[-1].file.geometry.read(ini_min_locs)
        zma = ini_zma_save_fs[-1].file.zmatrix.read([0])

        # Read the torsions from the ini file sys
        if ini_zma_save_fs[-1].file.ring_torsions.exists([0]):
            ring_tors_dct = ini_zma_save_fs[-1].file.ring_torsions.read([0])
        else:
            ring_tors_dct = {}

        geo_path = ini_cnf_save_fs[-1].path(ini_min_locs)
        ioprinter.initial_geom_path('Sampling started', geo_path)

        # Run the sampling
        conformer.ring_conformer_sampling(zma,
                                          spc_info,
                                          mod_thy_info,
                                          cnf_run_fs,
                                          cnf_save_fs,
                                          script_str,
                                          overwrite,
                                          nsamp_par=mc_nsamp,
                                          ring_tors_dct=ring_tors_dct,
                                          zrxn=zrxn,
                                          two_stage=two_stage,
                                          retryfail=retryfail,
                                          **kwargs)

    elif job == 'opt':

        cnf_range = es_keyword_dct['cnf_range']
        ioprinter.debug_message('range', cnf_range)

        # Set up the run scripts
        script_str, kwargs = qchem_params(method_dct,
                                          elstruct.Job.OPTIMIZATION)

        ini_loc_info = filesys.mincnf.min_energy_conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info)
        ini_min_locs, ini_min_cnf_path = ini_loc_info
        ini_min_rid, ini_min_cid = ini_min_locs

        rng_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
            cnf_save_fs, mod_thy_info, cnf_range='all')

        ini_rng_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info, cnf_range=cnf_range)

        # Truncate the list of the ini confs
        uni_rng_locs_lst, uni_cnf_locs_lst = conformer.unique_fs_ring_confs(
            cnf_save_fs, rng_cnf_locs_lst, ini_cnf_save_fs,
            ini_rng_cnf_locs_lst)
        ioprinter.debug_message('uni lst that has no similar ring',
                                uni_rng_locs_lst)
        ioprinter.debug_message('uni lst that has similar ring',
                                uni_cnf_locs_lst)

        for locs in uni_rng_locs_lst:
            rid, cid = locs
            # Obtain the zma from ini loc
            ini_cnf_save_path = ini_cnf_save_fs[-1].path(locs)
            ini_zma_save_fs = autofile.fs.zmatrix(ini_cnf_save_path)
            zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))

            # Make the ring filesystem
            conformer.single_conformer(zma,
                                       spc_info,
                                       mod_thy_info,
                                       cnf_run_fs,
                                       cnf_save_fs,
                                       script_str,
                                       overwrite,
                                       retryfail=retryfail,
                                       zrxn=zrxn,
                                       use_locs=locs,
                                       **kwargs)

        for locs in uni_cnf_locs_lst:
            ini_locs, rid = locs
            ini_rid, ini_cid = ini_locs
            # Obtain the zma from ini loc
            ini_cnf_save_path = ini_cnf_save_fs[-1].path(ini_locs)
            ini_zma_save_fs = autofile.fs.zmatrix(ini_cnf_save_path)
            zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))
            # obtain conformer filesystem associated with the ring at the runlevel
            cid = autofile.schema.generate_new_conformer_id()
            conformer.single_conformer(zma,
                                       spc_info,
                                       mod_thy_info,
                                       cnf_run_fs,
                                       cnf_save_fs,
                                       script_str,
                                       overwrite,
                                       retryfail=retryfail,
                                       zrxn=zrxn,
                                       use_locs=(rid, cid),
                                       **kwargs)

        rng_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
            cnf_save_fs, mod_thy_info, cnf_range=cnf_range)
        for locs in rng_cnf_locs_lst:
            geo = cnf_save_fs[-1].file.geometry.read(locs)
            ioprinter.geometry(geo)

    elif job in ('energy', 'grad', 'hess', 'vpt2', 'prop'):

        cnf_range = es_keyword_dct['cnf_range']

        ini_rng_cnf_locs_lst, _ = filesys.mincnf.conformer_locators(
            ini_cnf_save_fs, mod_ini_thy_info, cnf_range=cnf_range)

        # Check if locs exist, kill if it doesn't
        if not ini_rng_cnf_locs_lst:
            ioprinter.error_message('No min-energy conformer found for level:')
            sys.exit()

        # Set up the run scripts
        script_str, kwargs = qchem_params(method_dct)

        # Run the job over all the conformers requested by the user
        for ini_locs in ini_rng_cnf_locs_lst:
            ini_rid, ini_cid = ini_locs
            ioprinter.running('task for conformer: ', ini_locs, newline=2)
            ini_cnf_run_fs[-1].create(ini_locs)
            geo_run_path = ini_cnf_run_fs[-1].path(ini_locs)
            geo_save_path = ini_cnf_save_fs[-1].path(ini_locs)
            ini_zma_save_fs = autofile.fs.zmatrix(geo_save_path)
            ioprinter.debug_message('reading geometry from ', geo_save_path)
            geo = ini_cnf_save_fs[-1].file.geometry.read(ini_locs)
            zma = ini_zma_save_fs[-1].file.zmatrix.read((0, ))
            ES_TSKS[job](zma,
                         geo,
                         spc_info,
                         mod_thy_info,
                         ini_cnf_save_fs,
                         geo_run_path,
                         geo_save_path,
                         ini_locs,
                         script_str,
                         overwrite,
                         retryfail=retryfail,
                         **kwargs)