Ejemplo n.º 1
0
def test_opt_orca():
    """Test Orca input generation and run functions."""
    h2o = Molecule(PATH_MOLECULES / "h2o.xyz", 'xyz', charge=0, multiplicity=1)

    h2o_geometry = dftb(templates.geometry, h2o)

    s = Settings()
    # generic keyword "basis" must be present in the generic dictionary
    s.basis = "sto_dzp"
    # s.specific.adf.basis.core = "large"

    r = templates.singlepoint.overlay(s)
    h2o_singlepoint = orca(r, h2o_geometry.molecule)

    dipole = h2o_singlepoint.dipole

    final_result = run(dipole, n_processes=1)

    expected_dipole = [0.82409, 0.1933, -0.08316]
    diff = sqrt(sum((x - y)**2 for x, y in zip(final_result, expected_dipole)))
    logger.info(
        f"Expected dipole computed with Orca 3.0.3 is: {expected_dipole}")
    logger.info(f"Actual dipole is: {final_result}")

    assertion.lt(diff, 1e-2)
Ejemplo n.º 2
0
def test_methanol_opt_orca():
    """Run a methanol optimization and retrieve the optimized geom."""
    methanol = Molecule(PATH_MOLECULES / "methanol.xyz")

    s = Settings()
    s.specific.orca.main = "RKS B3LYP SVP Opt NumFreq TightSCF SmallPrint"
    s.specific.orca.scf = " print[p_mos] 1"

    opt = orca(s, methanol)

    # extract coordinates
    mol_opt = run(opt.molecule)
    coords = collapse([a.coords for a in mol_opt.atoms])
    logger.info(coords)
Ejemplo n.º 3
0
def test_hessian_transfer():
    """Test DFTB -> Orca hessian transfer."""
    h2o = molkit.from_smiles('O')
    h2o.properties.symmetry = 'C1'

    h2o_freq = dftb(templates.freq, h2o, job_name="freq").hessian

    s = Settings()
    s.inithess = h2o_freq

    h2o_opt = orca(templates.geometry.overlay(s), h2o, job_name="opt")

    energy = h2o_opt.energy
    dipole = h2o_opt.dipole

    wf = gather(energy, dipole)

    logger.info(run(wf))
Ejemplo n.º 4
0
def test_overlay_cp2k_singlepoint():
    """Test Settings merge methods.

    Check thatthe merging with the CP2K templates produces
    the same Settings that writing it by hand.
    """
    s = Settings()
    dft = s.specific.cp2k.force_eval.dft
    force = s.specific.cp2k.force_eval
    dft.scf.scf_guess = 'atomic'
    dft.scf.ot.minimizer = 'diis'
    dft.scf.ot.n_diis = 7
    dft.scf.ot.preconditioner = 'full_single_inverse'
    dft.scf.added_mos = 0
    dft.scf.eps_scf = 5e-06

    dft.mgrid.cutoff = 400
    dft.mgrid.ngrids = 4

    dft['print']['mo']['add_last'] = 'numeric'
    dft['print']['mo']['each']['qs_scf'] = 0
    dft['print']['mo']['eigenvalues'] = ''
    dft['print']['mo']['eigenvectors'] = ''
    dft['print']['mo']['filename'] = './mo.data'
    dft['print']['mo']['ndigits'] = 36
    dft['print']['mo']['occupation_numbers'] = ''

    dft.scf.max_scf = 200
    dft.scf.scf_guess = 'atomic'

    dft.qs.method = 'gpw'
    force.subsys.cell.periodic = 'xyz'

    g = s['specific']['cp2k']['global']
    g.print_level = 'low'
    g.project = "cp2k"
    g.run_type = "energy"

    r = templates.singlepoint.overlay(s)

    logger.info(f"created:\n{s.specific.cp2k.force_eval}")
    logger.info(f"expected:\n{r.specific.cp2k.force_eval}")

    assertion.eq(s.specific.cp2k, r.specific.cp2k)
Ejemplo n.º 5
0
def example_generic_constraints():
    """Run different job with geometric constrains.

    This examples illustrates that, by using generic keywords, it is possible
    to call different packages interchangeably with the same Settings.
    """
    # build hydrogen fluoride molecule
    hydrogen_fluoride = molkit.from_smiles('F[H]')

    # loop over distances
    jobs = []
    for distance in [1.0, 1.1, 1.2]:
        s = Settings()
        s.constraint['dist 1 2'] = distance
        # loop over packages
        for package in [dftb, adf, orca]:
            job_name = package.pkg_name + '_' + str(distance)
            constraint_opt = package(templates.geometry.overlay(s),
                                     hydrogen_fluoride, job_name)
            jobs.append(constraint_opt)

    # run the jobs
    results = run(gather(*jobs))
    energies = [r.energy for r in results]
    names = [r.job_name for r in results]

    # put resulting energies into a dictionary
    table = {'dftb': {}, 'adf': {}, 'orca': {}}
    for r in results:
        package, distance = r.job_name.split('_')
        table[package][distance] = round(r.energy, 6)

    # print table
    hartree_to_kcalpermol = 627.094
    for package in ['dftb', 'adf', 'orca']:
        row = [package]
        for distance in ['1.0', '1.1', '1.2']:
            val = table[package][distance] - table[package]['1.0']
            row.append(round(val * hartree_to_kcalpermol, 2))
        logger.info('{:10s} {:10.2f} {:10.2f} {:10.2f}'.format(*row))

    return names, energies
Ejemplo n.º 6
0
def test_fail_scm(tmpdir):
    """Test that both ADF and DFTB returns ``None`` if a computation fails."""
    # Temporary mute all QMFlows_Warnings
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=QMFlows_Warning)

        mol = Molecule(PATH_MOLECULES / "ethylene.xyz")

        # Some dftb specific settings
        dftb_set = Settings()
        dftb_set.specific.dftb.dftb.scc

        # Calculate the DFTB hessian
        opt_dftb = dftb(templates.geometry.overlay(dftb_set),
                        mol,
                        job_name="failed_DFTB")
        fail_adf = adf(None, opt_dftb.molecule, job_name="fail_adf")
        result = run(fail_adf.molecule, path=tmpdir)
        logger.info(result)
        assertion.eq(result, None)
Ejemplo n.º 7
0
def test_overlay_adf_freq():
    """Test ovelay method.

    Check that the overlay function produces the
    same Settings that a user would write by hand.
    """
    s = Settings()
    s.specific.adf.xc.gga = "bp86"
    s.specific.adf.numericalquality = "good"
    s.specific.adf.scf.iterations = "99"
    s.specific.adf.scf.converge = "0.0000001"
    s.specific.adf.analyticalfreq

    r = templates.freq.overlay(s)

    s.specific.adf.basis.type = "DZP"
    s.specific.adf.basis.core = "None"

    logger.info(s.specific.adf)
    logger.info(r.specific.adf)
    assertion.eq(s.specific.adf, r.specific.adf)
Ejemplo n.º 8
0
def example_H2O2_TS():
    """Am example which generates an approximate TS for rotation in hydrogen peroxide using DFTB, and performs a full TS optimization in Orca.

    It illustrates using a hessian from one package, DFTB in this case,
    to initialize a TS optimization in another, *i.e.* Orca in this case
    """  # noqa: E501
    # Generate hydrogen peroxide molecule
    h2o2 = molkit.from_smarts('[H]OO[H]')

    # Define dihedral angle
    dihe = Dihedral(1, 2, 3, 4)

    # Constrained geometry optimization with DFTB
    # The dihedral is set to 0.0 to obtain an approximate TS
    s1 = Settings()
    s1.constraint.update(dihe.get_settings(0.0))
    dftb_opt = dftb(templates.geometry.overlay(s1), h2o2)

    # Calculate the DFTB hessian
    dftb_freq = dftb(templates.freq, dftb_opt.molecule)

    # Transition state calculation using the DFTB hessian as starting point
    s2 = Settings()
    s2.inithess = dftb_freq.hessian
    orca_ts = orca(templates.ts.overlay(s2), dftb_opt.molecule)

    # Execute the workflow
    result = run(orca_ts)

    # Analyse the result
    ts_dihe = round(dihe.get_current_value(result.molecule))
    n_optcycles = result.optcycles

    logger.info(f'Dihedral angle (degrees): {ts_dihe:.0f}')
    logger.info(f'Number of optimization cycles: {n_optcycles:d}')

    return ts_dihe, n_optcycles
Ejemplo n.º 9
0
def test_orca_mol_trj():
    """Test the result of reading a `job.trj` file."""
    mol = parse_molecule_traj(PATH_TRJ)
    logger.info(mol)

    assertion.isinstance(mol, plams.Molecule)