Example #1
0
def run_gradient(zma,
                 geo,
                 spc_info,
                 thy_info,
                 geo_run_fs,
                 geo_save_fs,
                 locs,
                 run_prefix,
                 script_str,
                 overwrite,
                 zrxn=None,
                 retryfail=True,
                 method_dct=None,
                 ref_val=None,
                 **kwargs):
    """ Determine the gradient for the geometry in the given location
    """

    # Set unneeded vals
    _, _, _, _ = zrxn, method_dct, ref_val, run_prefix

    geo_run_path = geo_run_fs[-1].path(locs)
    geo_save_path = geo_save_fs[-1].path(locs)

    # Set input geom
    if geo is not None:
        job_geo = geo
    else:
        job_geo = automol.zmat.geometry(zma)
    is_atom = automol.geom.is_atom(job_geo)

    if not is_atom:

        if _json_database(geo_save_path):
            exists = geo_save_fs[-1].json.gradient.exists(locs)
        else:
            exists = geo_save_fs[-1].file.gradient.exists(locs)
        if not exists:
            ioprinter.info_message(
                'No gradient found in save filesys. Running gradient...')
            _run = True
        elif overwrite:
            ioprinter.info_message(
                'User specified to overwrite gradient with new run...')
            _run = True
        else:
            _run = False

        if _run:

            run_fs = autofile.fs.run(geo_run_path)

            success, ret = es_runner.execute_job(
                job=elstruct.Job.GRADIENT,
                script_str=script_str,
                run_fs=run_fs,
                geo=job_geo,
                spc_info=spc_info,
                thy_info=thy_info,
                zrxn=zrxn,
                overwrite=overwrite,
                retryfail=retryfail,
                **kwargs,
            )

            if success:
                inf_obj, inp_str, out_str = ret

                if is_atom:
                    grad = ()
                else:
                    ioprinter.info_message(
                        " - Reading gradient from output...")
                    grad = elstruct.reader.gradient(inf_obj.prog, out_str)

                    ioprinter.info_message(" - Saving gradient...")
                    if _json_database(geo_save_path):
                        geo_save_fs[-1].json.gradient_info.write(inf_obj, locs)
                        geo_save_fs[-1].json.gradient_input.write(
                            inp_str, locs)
                        geo_save_fs[-1].json.gradient.write(grad, locs)
                    else:
                        geo_save_fs[-1].file.gradient_info.write(inf_obj, locs)
                        geo_save_fs[-1].file.gradient_input.write(
                            inp_str, locs)
                        geo_save_fs[-1].file.gradient.write(grad, locs)
                    ioprinter.save_geo(geo_save_path)

        else:
            ioprinter.existing_path('Gradient', geo_save_path)

    else:
        ioprinter.info_message('Species is an atom. Skipping gradient task.')
Example #2
0
def run_prop(zma,
             geo,
             spc_info,
             thy_info,
             geo_run_fs,
             geo_save_fs,
             locs,
             run_prefix,
             script_str,
             overwrite,
             zrxn=None,
             retryfail=True,
             method_dct=None,
             ref_val=None,
             **kwargs):
    """ Determine the properties in the given location
    """

    # Set unneeded vals
    _, _, _, _ = zrxn, method_dct, ref_val, run_prefix

    # Set input geom
    geo_run_path = geo_run_fs[-1].path(locs)
    geo_save_path = geo_save_fs[-1].path(locs)
    if geo is not None:
        job_geo = geo
    else:
        job_geo = automol.zmat.geometry(zma)

    if _json_database(geo_save_path):
        dmom_exists = geo_save_fs[-1].json.dipole_moment.exists(locs)
        polar_exists = geo_save_fs[-1].json.polarizability.exists(locs)
    else:
        dmom_exists = geo_save_fs[-1].file.dipole_moment.exists(locs)
        polar_exists = geo_save_fs[-1].file.polarizability.exists(locs)
    if not dmom_exists or not polar_exists:
        ioprinter.info_message(
            'Either no dipole moment or polarizability found in'
            'in save filesys. Running properties...')
        _run = True
    elif overwrite:
        ioprinter.info_message(
            'User specified to overwrite property with new run...')
        _run = True
    else:
        _run = False

    if _run:

        run_fs = autofile.fs.run(geo_run_path)

        success, ret = es_runner.execute_job(
            job=elstruct.Job.MOLPROP,
            script_str=script_str,
            run_fs=run_fs,
            geo=job_geo,
            spc_info=spc_info,
            thy_info=thy_info,
            zrxn=zrxn,
            overwrite=overwrite,
            retryfail=retryfail,
            **kwargs,
        )

        if success:
            inf_obj, _, out_str = ret

            ioprinter.info_message(" - Reading dipole moment from output...")
            dmom = elstruct.reader.dipole_moment(inf_obj.prog, out_str)
            ioprinter.info_message(" - Reading polarizability from output...")
            polar = elstruct.reader.polarizability(inf_obj.prog, out_str)

            ioprinter.debug_message('dip mom', dmom)
            ioprinter.debug_message('polar', polar)
            ioprinter.info_message(
                " - Saving dipole moment and polarizability...")
            if _json_database(geo_save_path):
                # geo_save_fs[-1].json.property_info.write(inf_obj, locs)
                # geo_save_fs[-1].json.property_input.write(
                #     inp_str, locs)
                geo_save_fs[-1].json.dipole_moment.write(dmom, locs)
                geo_save_fs[-1].json.polarizability.write(polar, locs)
            else:
                # geo_save_fs[-1].file.property_info.write(inf_obj, locs)
                # geo_save_fs[-1].file.property_input.write(
                #     inp_str, locs)
                geo_save_fs[-1].file.dipole_moment.write(dmom, locs)
                geo_save_fs[-1].file.polarizability.write(polar, locs)
            ioprinter.save_geo(geo_save_path)

    else:
        ioprinter.existing_path('Dipole moment and polarizability',
                                geo_save_path)
Example #3
0
def save_tau(tau_run_fs, tau_save_fs, mod_thy_info):
    """ save the tau dependent geometries that have been found so far
    """
    # db_style = 'jsondb'
    db_style = 'directory'
    if db_style == 'jsondb':
        saved_locs = tau_save_fs[-1].json_existing()
        saved_geos = tau_save_fs[-1].json.geometry.read_all(saved_locs)
    elif db_style == 'directory':
        saved_geos = [tau_save_fs[-1].file.geometry.read(locs)
                      for locs in tau_save_fs[-1].existing()]
    if not tau_run_fs[0].exists():
        ioprinter.info_message("No tau geometries to save. Skipping...")
    else:
        if db_style == 'jsondb':
            save_info = [[], [], [], [], []]
            sp_save_info = [[], [], [], [], []]
        for locs in tau_run_fs[-1].existing():
            run_path = tau_run_fs[-1].path(locs)
            run_fs = autofile.fs.run(run_path)
            save_path = tau_save_fs[-1].root.path()

            ioprinter.reading("tau run", run_path)

            success, ret = es_runner.read_job(
                job=elstruct.Job.OPTIMIZATION, run_fs=run_fs)
            if success:
                inf_obj, inp_str, out_str = ret
                prog = inf_obj.prog
                method = inf_obj.method
                ene = elstruct.reader.energy(prog, method, out_str)

                geo = elstruct.reader.opt_geometry(prog, out_str)
                if db_style == 'directory':
                    ioprinter.save_geo(save_path)
                    tau_save_fs[-1].create(locs)
                    tau_save_fs[-1].file.geometry_info.write(inf_obj, locs)
                    tau_save_fs[-1].file.geometry_input.write(inp_str, locs)
                    tau_save_fs[-1].file.energy.write(ene, locs)
                    tau_save_fs[-1].file.geometry.write(geo, locs)
                    # Saving the energy to a SP filesystem
                    save_path = tau_save_fs[-1].path(locs)
                    ioprinter.save_energy(save_path)
                    sp_save_fs = autofile.fs.single_point(save_path)
                    sp_save_fs[-1].create(mod_thy_info[1:4])
                    sp_save_fs[-1].file.input.write(inp_str, mod_thy_info[1:4])
                    sp_save_fs[-1].file.info.write(inf_obj, mod_thy_info[1:4])
                    sp_save_fs[-1].file.energy.write(ene, mod_thy_info[1:4])
                elif db_style == 'jsondb':
                    # tau_save_fs[-1].json.geometry_info.write(inf_obj, locs)
                    # tau_save_fs[-1].json.geometry_input.write(inp_str, locs)
                    # tau_save_fs[-1].json.energy.write(ene, locs)
                    # tau_save_fs[-1].json.geometry.write(geo, locs)
                    ioprinter.info_message(
                        " - Saving energy and geo of unique geometry...")
                    save_info[0].append(locs)
                    save_info[1].append(inf_obj)
                    save_info[2].append(inp_str)
                    save_info[3].append(ene)
                    save_info[4].append(geo)

                    sp_save_fs = autofile.fs.single_point(
                        save_path, json_layer=locs)
                    sp_save_info[0].append(sp_save_fs)
                    sp_save_info[1].append(mod_thy_info[1:4])
                    sp_save_info[2].append(inp_str)
                    sp_save_info[3].append(inf_obj)
                    sp_save_info[4].append(ene)
                    sp_save_fs[-1].json.input.write(inp_str, mod_thy_info[1:4])
                    sp_save_fs[-1].json.info.write(inf_obj, mod_thy_info[1:4])
                    sp_save_fs[-1].json.energy.write(ene, mod_thy_info[1:4])

                saved_geos.append(geo)

        if db_style == 'jsondb':
            tau_save_fs[-1].json_create()
            tau_save_fs[-1].json.geometry_info.write_all(
                save_info[1], save_info[0])
            tau_save_fs[-1].json.geometry_input.write_all(
                save_info[2], save_info[0])
            tau_save_fs[-1].json.energy.write_all(
                save_info[3], save_info[0])
            tau_save_fs[-1].json.geometry.write_all(
                save_info[4], save_info[0])

            for i, sp_save_fs_i in enumerate(sp_save_info[0]):
                sp_save_fs_i[-1].json.input.write(
                    sp_save_info[2][i], sp_save_info[1][i])
                sp_save_fs_i[-1].json.info.write(
                    sp_save_info[3][i], sp_save_info[1][i])
                sp_save_fs_i[-1].json.energy.write(
                    sp_save_info[4][i], sp_save_info[1][i])

        # update the tau trajectory file
        filesys.mincnf.traj_sort(tau_save_fs, mod_thy_info)