Пример #1
0
def test_orca_mock(mocker: MockFixture):
    """Mock a call to orca."""
    methanol = Molecule(PATH_MOLECULES / "methanol.xyz")

    s = Settings()
    s.specific.orca.main = "RKS B3LYP SVP Opt NumFreq TightSCF SmallPrint"
    # print the orbitals
    s.specific.orca.scf = " print[p_mos] 1"
    job = orca(s, methanol)

    run_mocked = mocker.patch("qmflows.run")
    jobname = "ORCAjob"
    dill_path = WORKDIR / jobname / "ORCAjob.dill"
    plams_dir = WORKDIR / jobname
    run_mocked.return_value = ORCA_Result(s,
                                          methanol,
                                          jobname,
                                          dill_path=dill_path,
                                          plams_dir=plams_dir)
    rs = run_mocked(job)

    assertion.isfinite(rs.energy)
    assertion.isfinite(rs.runtime)
    assertion.isfinite(np.sum(rs.dipole))
    # steps until convergence
    assertion.eq(rs.optcycles, 8)

    # Check that hessian is symmetric
    hess = rs.hessian
    assertion.isclose(np.sum(hess - hess.T), 0.0)

    # frequencies
    frequencies = rs.frequencies
    assertion.len_eq(frequencies, 18)

    # Normal modes
    normal_modes = rs.normal_modes
    assertion.shape_eq(normal_modes, (18, 18))

    # Orbitals
    orbs = rs.orbitals
    assert np.isfinite(np.sum(orbs.eigenvalues))  # eigenvalues

    # Molecule
    mol = rs.molecule
    assertion.isinstance(mol, Molecule)
    assertion.len_eq(mol, 6)  # there are 6 atoms
Пример #2
0
def example_H2O2_TS():
    """
    This example 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
    """

    # 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

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

    return ts_dihe, n_optcycles
Пример #3
0
# DFTB optimization
dftb_jobs = {
    n: dftb(templates.geometry, mol, job_name='dftb_{}'.format(n))
    for n, mol in molecules.items()
}

# Check preoptimized molecules
opt_mols = {n: skip_dftb(job, molecules[n]) for n, job in dftb_jobs.items()}

# DFT optimization with Orca
s = templates.geometry
s.functional = 'BP86'
s.basis = 'def2TZVP'
dft_jobs = {
    n: orca(s, mol, job_name='orca_{}'.format(n))
    for n, mol in opt_mols.items()
}

# TD-DFT ADF with COSMO
s = templates.singlepoint
s.functional = 'camy-b3lyp'
s.basis = 'TZ2P'
s.specific.adf.Solvation.solvent = 'name=Dichloromethane emp=0.0 neql=2.028'

td_dft_jobs = {
    n: adf(s, job.molecule, job_name='td_dft_{}'.format(n))
    for n, job in dft_jobs.items()
}

energies = [gather(n, j.energy) for n, j in td_dft_jobs.items()]
Пример #4
0
# coordinates for the new atoms
temp.atoms[47].move_to((0.0, 0.0, 0.0))
temp.atoms[48].move_to((0.0, 0.0, 0.0))
# Replace dummy atoms by new groups, generate coordinates only for new atoms
job_list = []
for mod, smirks in list_of_modifications.items():
    print(mod)
    temp2, freeze = molkit.apply_reaction_smarts(temp, smirks, complete=True)
    # generate job
    s = Settings()
    s.freeze = freeze
    s.specific.dftb.dftb.resourcesdir = 'QUASINANO2015'
    partial_geometry = dftb(templates.geometry.overlay(s),
                            temp2,
                            job_name="partial_opt_" + mod)
    freq_dftb = dftb(templates.freq.overlay(s),
                     partial_geometry.molecule,
                     job_name="freq_" + mod)
    s = Settings()
    s.specific.orca.main = "B97-D"
    s.specific.orca.basis.basis = "_6_31G"
    s.specific.orca.basis.pol = "_d"
    s.inithess = freq_dftb.hessian
    ts = orca(templates.ts.overlay(s),
              freq_dftb.molecule,
              job_name="ts_" + mod)
    freq = orca(templates.freq.overlay(s), ts.molecule, job_name="freq" + mod)
    job_list.append(freq)

results = run(gather(*job_list), folder="Chris_results", n_processes=1)