Exemplo n.º 1
0
def turbo_comp():
    calc_kwargs = {
        "xc": "pbe",
        "method": "tddft",
        "basis": "def2-SVP",
        "pal": 4,
        "nstates": 2,
        "root": 1,
        "track": True,
    }
    pyscf_ = PySCF(**calc_kwargs)
    geom = geom_from_xyz_file("cytosin.xyz")
    geom.set_calculator(pyscf_)
    f = geom.forces.reshape(-1, 3)
    print("pyscf")
    print(f.reshape(-1, 3))

    ref_geom = geom.copy()
    turbo_kwargs = {
        "control_path": "/scratch/turbontos/control_pbe_clean",
        "track": True,
        "ovlp_type": "wf",
        "ovlp_with": "first",
        "pal": 4,
    }
    turbo = Turbomole(**turbo_kwargs)
    ref_geom.set_calculator(turbo)
    f_ref = ref_geom.forces
    print("Turbo")
    print(f_ref.reshape(-1, 3))
Exemplo n.º 2
0
def test_backtransform_hessian():
    geom = geom_loader("lib:azetidine_hf_321g_opt.xyz", coord_type="redund")

    H_fn = "H"
    cH_fn = "cH"
    f_fn = "f"
    cf_fn = "cf"

    calc = PySCF(basis="321g", pal=2)
    geom.set_calculator(calc)
    f = geom.forces
    np.savetxt(f_fn, f)
    cf = geom.cart_forces
    np.savetxt(cf_fn, cf)
    H = geom.hessian
    np.savetxt(H_fn, H)
    cH = geom.cart_hessian
    np.savetxt(cH_fn, cH)

    f_ref = np.loadtxt(f_fn)
    cf_ref = np.loadtxt(cf_fn)
    H_ref = np.loadtxt(H_fn)
    cH_ref = np.loadtxt(cH_fn)

    # norm = np.linalg.norm(cf_ref)
    # print(f"norm(cart. forces)={norm:.6f}")

    int_ = geom.internal
    int_gradient_ref = -f_ref
    H = int_.transform_hessian(cH_ref, int_gradient_ref)
    np.testing.assert_allclose(H, H_ref)

    cH = int_.backtransform_hessian(H, int_gradient_ref)
    np.testing.assert_allclose(cH, cH_ref, atol=1.5e-7)
Exemplo n.º 3
0
def test_baker_tsopt(name, geom, charge, mult, ref_energy):
    calc_kwargs = {
        "charge": charge,
        "mult": mult,
        "pal": 1,
    }

    print(f"@Running {name}")
    # geom.set_calculator(Gaussian16(route="HF/3-21G", **calc_kwargs))
    geom.set_calculator(PySCF(basis="321g", **calc_kwargs))
    if geom.coord_type != "cart":
        geom = augment_bonds(geom)

    opt_kwargs = {
        "thresh": "baker",
        "max_cycles": 50,
        "trust_radius": 0.3,
        "trust_max": 0.3,
    }
    # opt = RSPRFOptimizer(geom, **opt_kwargs)
    opt = RSIRFOptimizer(geom, **opt_kwargs)
    # opt = TRIM(geom, **opt_kwargs)
    opt.run()

    print(f"\t@Converged: {opt.is_converged}, {opt.cur_cycle+1} cycles")

    # Without symmetry restriction this lower lying TS will be obtained.
    if name.startswith("22_"):
        ref_energy = -242.25695787
    assert geom.energy == pytest.approx(ref_energy)
    print("\t@Energies match!")

    return opt.cur_cycle + 1
def test_augment_coordinates_silyl(augment, ref_cycle):
    geom = geom_from_library("baker_ts/18_silyene_insertion.xyz",
                             coord_type="redund")

    opt_kwargs = {
        "thresh": "baker",
        "max_cycles": 100,
        "dump": True,
        "trust_radius": 0.3,
        "trust_max": 0.3,
        "augment_bonds": augment,
    }
    calc_kwargs = {
        "charge": 0,
        "mult": 1,
        "pal": 4,
    }
    calc = PySCF(basis="321g", **calc_kwargs)

    geom.set_calculator(calc)

    opt = RSIRFOptimizer(geom, **opt_kwargs)
    opt.run()

    assert opt.is_converged
    assert opt.cur_cycle == ref_cycle

    ref_en = -367.20778
    assert opt.geometry.energy == pytest.approx(ref_en)
Exemplo n.º 5
0
def test_pyscf():
    # pyscf_ = PySCF(basis="3-21g", pal=4)
    pyscf_ = PySCF(basis="3-21g", pal=4)
    # pyscf_ = PySCF(basis="3-21g", method="mp2", pal=4)
    # geom = geom_from_library("birkholz/vitamin_c.xyz")
    # geom = geom_from_library("hcn.xyz")
    geom = geom_from_library("hcn_iso_ts.xyz")
    geom.set_calculator(pyscf_)
    f = geom.forces.reshape(-1, 3)
    print("PySCF")
    print(f)

    H = geom.hessian
    print("PySCF hessian")
    print(H.reshape(-1, 9))

    ref_geom = geom.copy()
    from pysisyphus.calculators.Gaussian16 import Gaussian16
    g16 = Gaussian16("hf/3-21G", pal=4)
    # g16 = Gaussian16("mp2/3-21G", pal=4)
    ref_geom.set_calculator(g16)
    f_ref = ref_geom.forces.reshape(-1, 3)
    print("Gaussian16")
    print(f_ref)

    # np.testing.assert_allclose(f, f_ref, rtol=5e-3)

    H_ref = ref_geom.hessian
    print("G16 Hess")
    print(H_ref)
Exemplo n.º 6
0
def test_bias_rotation():
    # geom = geom_from_library("claisen_forward.xyz")
    # bonds = ((10, 11, 1), (12, 13, -1))
    # calc_kwargs = {
    # "xc": "pbe",
    # # "basis": "def2svp",
    # # "auxbasis": "weigend",
    # "basis": "321g",
    # "pal": 4,
    # }
    # calc = PySCF(**calc_kwargs)

    geom = geom_from_library("baker_ts/01_hcn.xyz")
    bonds = ((1, 2, -1), (2, 0, 1))
    calc = PySCF("321g", pal=2)

    dimer_kwargs = {
        "rotation_method": "fourier",
        "calculator": calc,
        "bonds": bonds,
        # "rotation_thresh": 2e-4,
        "bias_rotation": True,
    }
    dimer = Dimer(**dimer_kwargs)
    geom.set_calculator(dimer)

    f = geom.forces
    print(f)
Exemplo n.º 7
0
def test_dimer_hcn(bonds, ref_cycle):
    geom = geom_from_library("baker_ts/01_hcn.xyz")
    ref_energy = -92.24604
    N_raw = " 0.5858  0.      0.0543 " \
             "-0.7697 -0.      0.061 " \
             "0.2027  0.     -0.1295".split()
    if bonds is not None:
        N_raw = None

    calc = PySCF("321g", pal=2)

    dimer_kwargs = {
        "rotation_method": "fourier",
        "calculator": calc,
        "N_raw": N_raw,
        "bonds": bonds,
    }
    dimer = Dimer(**dimer_kwargs)
    geom.set_calculator(dimer)

    opt_kwargs = {
        "precon": True,
        "max_step_element": 0.25,
        "max_cycles": 15,
    }
    opt = PreconLBFGS(geom, **opt_kwargs)
    opt.run()

    assert opt.is_converged
    assert opt.cur_cycle == ref_cycle
    assert geom.energy == pytest.approx(ref_energy)
Exemplo n.º 8
0
def test_afir():
    """Example (R1) from
        https://aip.scitation.org/doi/pdf/10.1063/1.3457903?class=pdf

    See Fig. 2 and Fig. 4
    """

    geom = geom_loader("lib:ohch3f_anion_cs.xyz")
    # OH group is a fragment
    fragment_indices = [
        (5, 6),
    ]
    calc = PySCF(basis="6-31g*", xc="b3lyp", pal=2, charge=-1)
    gamma = 100
    afir = AFIR(calc, fragment_indices, gamma)
    geom.set_calculator(afir)

    opt = RFOptimizer(geom, dump=True, trust_max=.3)
    opt.run()

    assert opt.is_converged
    assert opt.cur_cycle == 47

    # Broken C-Cl bond
    c3d = geom.coords3d
    assert np.linalg.norm(c3d[0] - c3d[4]) == pytest.approx(4.805665, abs=1e-4)
    # Formed O-C bond
    assert np.linalg.norm(c3d[0] - c3d[5]) == pytest.approx(2.674330, abs=1e-4)
Exemplo n.º 9
0
 def calc_getter(calc_number):
     calc_kwargs = {
         "charge": +1,
         "mult": 1,
         "pal": 2,
         "basis": "321g",
         "calc_number": calc_number,
     }
     calc = PySCF(**calc_kwargs)
     return calc
Exemplo n.º 10
0
def test_water_hf_precon_opt(opt_cls, precon, ref_cycles):
    geom = geom_from_library("h2o_shaken.xyz")
    calc = PySCF(basis="sto3g")
    geom.set_calculator(calc)

    opt = opt_cls(geom, thresh="gau_tight", precon=precon)
    opt.run()

    assert opt.is_converged
    assert opt.cur_cycle == ref_cycles
    assert geom.energy == pytest.approx(-74.96590119)
Exemplo n.º 11
0
def test_allene_opt():
    geom = geom_loader("lib:08_allene.xyz", coord_type="redund")

    calc = PySCF(basis="321g", pal=1)
    geom.set_calculator(calc)
    opt = RFOptimizer(geom, thresh="gau_tight")
    opt.run()

    assert opt.is_converged
    # assert opt.cur_cycle == 7
    assert geom.energy == pytest.approx(-115.21991342)
Exemplo n.º 12
0
def test_hcn_iso_gs2(step_length):
    geom = geom_loader("lib:hcn_iso_hf_sto3g_ts_opt.xyz")
    calc = PySCF(basis="sto3g")
    geom.set_calculator(calc)
    irc_kwargs = {
        "step_length": step_length,
    }
    irc = GonzalezSchlegel(geom, **irc_kwargs)
    irc.run()

    assert irc.forward_is_converged
    assert irc.backward_is_converged
Exemplo n.º 13
0
def test_numhess(xyz_fn, coord_type, ref_rms):
    geom = geom_loader(xyz_fn, coord_type=coord_type)

    # Interestingly enough the test will fail with keep_chk == True ...
    # as the RMS value will be much higher
    calc = PySCF(basis="321g", pal=2, keep_chk=False)
    geom.set_calculator(calc)

    H = geom.hessian
    nH = numhess(geom)

    assert compare_hessians(H, nH, ref_rms)
Exemplo n.º 14
0
def test_mulliken_charges():
    geom = geom_from_library("oniom_ee_model_system.xyz", coord_type="redund")

    calc_kwargs = {
        "basis": "sto3g",
    }
    calc = PySCF(**calc_kwargs)
    geom.set_calculator(calc)

    energy = geom.energy
    assert energy == pytest.approx(-5.789815189924002E+02)

    charges = calc.parse_charges()
    chrg_ref = """
        -4.84551410E-02  9.03447614E-02  8.75522347E-02 -4.66142813E-01  2.09615873E-01
      2.03308060E-01  3.18063759E-01 -3.52693455E-01  2.59066455E-01 -2.90419166E-01
     -4.29794447E-01  2.21955145E-01  1.77292603E-01 -3.98003060E-01  2.17833663E-01
      2.08840824E-01 -4.30825317E-01  1.78166353E-01  2.25524078E-01 -4.10146906E-01
      2.03058796E-01  2.25857702E-01"""
    ref_charges = np.array(chrg_ref.strip().split(), dtype=float)

    np.testing.assert_allclose(charges, ref_charges, atol=1e-5)
Exemplo n.º 15
0
def test_geometry_get_restart_info():
    geom = geom_from_library("benzene.xyz")
    calc = PySCF(method="scf", basis="def2svp")

    geom.set_calculator(calc)
    restart = geom.get_restart_info()

    atoms = restart["atoms"]
    coords = restart["cart_coords"]

    assert atoms == geom.atoms
    assert len(coords) == len(geom.atoms * 3)
    assert "calc_info" in restart
Exemplo n.º 16
0
def test_hcn_irc(irc_cls, irc_kwargs, fw_cycle, bw_cycle):
    geom = geom_loader("lib:hcn_iso_hf_sto3g_ts_opt.xyz")

    calc = PySCF(basis="sto3g", )
    geom.set_calculator(calc)

    irc = irc_cls(geom, **irc_kwargs, rms_grad_thresh=1e-4)
    irc.run()

    # approx. +- 0.5 kJ/mol
    assert irc.forward_energies[0] == pytest.approx(
        -91.67520894777218)  #, abs=2.2e-4)
    assert irc.backward_energies[-1] == pytest.approx(-91.64442379051056)
Exemplo n.º 17
0
def test_baker_tsopt(name, results_bag):
    charge, mult, ref_energy = get_baker_ts_data()[name]
    geom = geom_loader(
        f"lib:baker_ts/{name}",
        coord_type="redund",
        coord_kwargs={
            "rebuild": True,
        },
    )
    # geom.jmol()
    calc_kwargs = {
        "charge": charge,
        "mult": mult,
        "pal": 1,
    }

    print(f"@Running {name}")
    geom.set_calculator(PySCF(basis="321g", **calc_kwargs))
    # geom.set_calculator(ORCA(keywords="HF 3-21G", **calc_kwargs))
    if geom.coord_type != "cart":
        geom = augment_bonds(geom)

    opt_kwargs = {
        "thresh": "baker",
        "max_cycles": 50,
        "trust_radius": 0.1,
        "trust_max": 0.3,
        "min_line_search": True,
        "max_line_search": True,
    }
    opt = RSPRFOptimizer(geom, **opt_kwargs)
    # opt = RSIRFOptimizer(geom, **opt_kwargs)
    # opt = TRIM(geom, **opt_kwargs)
    opt.run()

    # Without symmetry restriction this lower lying TS will be obtained.
    # if name.startswith("22_"):
        # ref_energy = -242.25695787

    results_bag.cycles = opt.cur_cycle + 1
    results_bag.is_converged = opt.is_converged
    results_bag.energy = geom.energy
    results_bag.ref_energy = ref_energy

    print(f"\t@Converged: {opt.is_converged}, {opt.cur_cycle+1} cycles")

    assert geom.energy == pytest.approx(ref_energy)
    print("\t@Energies match!")

    return opt.cur_cycle + 1
Exemplo n.º 18
0
def test_diels_alder_ts(define_prims, ref_cycle, proj):
    """
        https://onlinelibrary.wiley.com/doi/epdf/10.1002/jcc.21494
    """

    coord_kwargs = None
    augment = True

    if define_prims:
        coord_kwargs = {
            "define_prims": define_prims,
        }
        augment = False

    geom = geom_loader(
        "lib:baker_ts/09_parentdieslalder.xyz",
        coord_type="redund",
        coord_kwargs=coord_kwargs,
    )

    calc_kwargs = {
        "charge": 0,
        "mult": 1,
        "pal": 4,
    }
    # geom.set_calculator(Gaussian16(route="HF/3-21G", **calc_kwargs))
    geom.set_calculator(PySCF(basis="321g", **calc_kwargs))
    if augment:
        geom = augment_bonds(geom, proj=proj)

    opt_kwargs = {
        "thresh": "baker",
        "max_cycles": 50,
        "trust_radius": 0.3,
        "trust_max": 0.3,
        "hessian_recalc": 5,
        "dump": True,
        "overachieve_factor": 2,
    }
    opt = RSIRFOptimizer(geom, **opt_kwargs)
    opt.run()

    print(f"\t@Converged: {opt.is_converged}, {opt.cur_cycle+1} cycles")

    ref_energy = -231.60320857
    assert geom.energy == pytest.approx(ref_energy)
    print("\t@Energies match!")
    assert opt.is_converged
    assert opt.cur_cycle == ref_cycle
Exemplo n.º 19
0
def test_opt_load_save_hessian(this_dir):
    geom = geom_loader("lib:acetaldehyd.xyz", coord_type="redund")
    calc = PySCF(basis="321g", pal=2)
    geom.set_calculator(calc)

    opt_kwargs = {
        "hessian_recalc": 1,
        "hessian_init": this_dir / "inp_hess_calc_cyc_0.h5",
    }
    opt = RFOptimizer(geom, **opt_kwargs)
    opt.run()

    assert opt.is_converged
    assert opt.cur_cycle == 2
    assert geom.energy == pytest.approx(-152.05524620313963)
Exemplo n.º 20
0
def test_hcn_iso_lanczos(coord_type, guess):
    geom = geom_loader("lib:hcn_iso_hf_sto3g_ts_opt.xyz", coord_type=coord_type)
    calc = PySCF(pal=2, basis="sto3g")
    geom.set_calculator(calc)

    w_min, v_min = geom_lanczos(geom, guess=guess, logger=logger)

    # Reference values
    H = geom.hessian
    w, v = np.linalg.eigh(H)
    w_ref = w[0]
    v_ref = v[:,0]

    assert w_min == pytest.approx(w_ref, abs=1e-2)
    assert any([np.allclose(v, v_ref, atol=5e-2) for v in (v_min, -v_min)])
Exemplo n.º 21
0
def test_irc_load_save_hessian(this_dir):
    geom = geom_loader("lib:hcn_iso_hf_sto3g_ts_opt.xyz")
    calc = PySCF(basis="sto3g", pal=2)
    geom.set_calculator(calc)

    irc_kwargs = {
        "rms_grad_thresh": 1e-3,
        "hessian_init": this_dir / "inp_hess_init_irc.h5",
        "hessian_recalc": 2,
        "max_cycles": 5,
    }
    irc = EulerPC(geom, **irc_kwargs)
    irc.run()

    assert irc.forward_cycle == 5
    assert irc.backward_cycle == 5
Exemplo n.º 22
0
def test_guess_hessians(hessian_init, ref_cycle):
    geom = geom_loader("lib:h2o2_hf_321g_opt.xyz", coord_type="redund")
    geom.set_calculator(PySCF(basis="def2svp", pal=2))

    print("@\tguess_hessian:", hessian_init)
    opt_kwargs = {
        "hessian_init": hessian_init,
        "thresh": "gau_tight",
    }
    opt = RFOptimizer(geom, **opt_kwargs)
    opt.run()

    print("@\tcur_cycle:", opt.cur_cycle)

    assert opt.is_converged
    assert opt.cur_cycle == ref_cycle
    assert geom.energy == pytest.approx(-150.65298169)
Exemplo n.º 23
0
def test_downhill_irc_model_hessian(hessian_init, ref_cycle):
    geom = geom_loader("lib:hcn_downhill_model_hessian.xyz")

    calc = PySCF(basis="sto3g", pal=2)
    geom.set_calculator(calc)

    irc_kwargs = {
        "hessian_init": hessian_init,
        "rms_grad_thresh": 5e-3,
        "downhill": True,
    }

    irc = EulerPC(geom, **irc_kwargs)
    irc.run()

    assert irc.downhill_energies[-1] == pytest.approx(-91.67517096968325)
    assert irc.downhill_cycle == ref_cycle
def water():
    geom = geom_loader("lib:h2o.xyz")
    init_logging()
    calc_kwargs = {
        "xc": "pbe0",
        "method": "tddft",
        "basis": "sto3g",
        "nstates": 2,
        "root": 1,
        # OverlapCalculator specific
        "track": True,
        "cdds": "calc",
        "ovlp_type": "tden",
    }
    calc = PySCF(**calc_kwargs)
    geom.set_calculator(calc)
    return geom
Exemplo n.º 25
0
def test_ts_hessian_opt():
    geom = geom_loader("lib:baker_ts/01_hcn.xyz", coord_type="redund")
    geom.set_calculator(PySCF(basis="321g"))

    opt_kwargs = {
        "hessian_init": "fischer",
        "dump": True,
        "rx_coords": ((2, 1, 0), ),
        "thresh": "gau_tight",
    }
    opt = RSPRFOptimizer(geom, **opt_kwargs)
    opt.run()
    do_final_hessian(geom, write_imag_modes=True)

    assert opt.is_converged
    assert opt.cur_cycle == 11
    assert geom.energy == pytest.approx(-92.2460426792319)
Exemplo n.º 26
0
def test_baker_gs_opt(name, geom, ref_energy, results_bag):
    opt_kwargs = {
        "thresh": "baker",
    }
    print(f"@Running {name}")
    pal = min(os.cpu_count(), 4)
    geom.set_calculator(PySCF(basis="sto3g", pal=pal))
    opt = RFOptimizer(geom, **opt_kwargs)
    opt.run()

    results_bag.cycles = opt.cur_cycle + 1
    results_bag.is_converged = opt.is_converged
    results_bag.energy = geom.energy
    results_bag.ref_energy = ref_energy

    assert np.allclose(geom.energy, ref_energy)

    return opt.cur_cycle + 1, opt.is_converged
Exemplo n.º 27
0
def test_pyscf_tddft():
    calc_kwargs = {
        "xc": "b3lyp",
        "method": "tddft",
        "basis": "3-21g",
        "pal": 4,
        "nstates": 10,
        "root": 2,
        "track": True,
    }
    pyscf_ = PySCF(**calc_kwargs)
    geom = geom_from_library("hcn_iso_ts.xyz")
    geom.set_calculator(pyscf_)
    e = geom.energy
    print(e)
    f = geom.forces.reshape(-1, 3)
    print("PySCF")
    print(f)
Exemplo n.º 28
0
def test_diels_alder_neb(opt_cls):
    geoms = geom_from_library("diels_alder_interpolated.trj")
    for i, geom in enumerate(geoms):
        calc_kwargs = {
            "basis": "sto3g",
            "pal": 2,
            "calc_number": i,
        }
        calc = PySCF(**calc_kwargs)
        geom.set_calculator(calc)
    neb = NEB(geoms)

    opt_kwargs = {
        "dump": True,
        "align": True,
        "max_cycles": 15,
    }
    opt = opt_cls(neb, **opt_kwargs)
    opt.run()
Exemplo n.º 29
0
def test_modekill_pyscf(this_dir):
    fn = this_dir / "ethane_shaked.xyz"
    geom = geom_loader(fn)
    calc = PySCF(basis="sto3g", xc="bp86", pal=2)
    geom.set_calculator(calc)

    w, v = np.linalg.eigh(geom.eckart_projection(geom.mw_hessian))
    nus = eigval_to_wavenumber(w)
    assert nus[0] == pytest.approx(-266.11360383)

    modekill = ModeKill(geom, kill_inds=[
        0,
    ])
    modekill.run()
    assert modekill.converged

    w, v = np.linalg.eigh(geom.eckart_projection(geom.mw_hessian))
    nus = eigval_to_wavenumber(w)
    assert nus[0] == pytest.approx(-4.5086469e-05, abs=1e-4)
Exemplo n.º 30
0
def test_pyscf_cytosin_td_opt():
    calc_kwargs = {
        "xc": "pbe0",
        "method": "tddft",
        # "method": "dft",
        "basis": "def2SVP",
        # "auxbasis": "weigend",
        # "basis": "sto3g",
        "pal": 4,
        "nstates": 2,
        "root": 1,
        "track": True,
        "ovlp_with": "adapt",
        "ovlp_type": "tden",
    }
    pyscf_ = PySCF(**calc_kwargs)
    geom = geom_from_library("cytosin.xyz", coord_type="redund")
    geom.set_calculator(pyscf_)
    opt = RFOptimizer(geom)
    opt.run()