示例#1
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)
def test_baker_ts_dimer(name, geom, charge, mult, ref_energy):
    print(f"@Got geom '{name}'")
    # Load initial dimers
    N_init_dict = make_N_init_dict()

    calc_kwargs = {
        "charge": charge,
        "mult": mult,
        "pal": 2,
        "base_name": Path(name).stem,
    }

    def calc_getter():
        return PySCF(basis="321g", **calc_kwargs)

    # def calc_getter():
    # return Gaussian16(route="HF/3-21G", **calc_kwargs)
    geom.set_calculator(calc_getter())

    dimer_kwargs = {
        "max_step": 0.25,
        # 1e-2 Angstroem in bohr
        "dR_base": 0.0189,
        "rot_opt": "lbfgs",
        # "trans_opt": "mb",
        "trans_opt": "lbfgs",
        # "trans_memory": 10, # bad idea
        "angle_tol": 5,
        "f_thresh": 1e-3,
        "max_cycles": 50,
        "f_tran_mod": True,
        # "rot_type": "direct",
        "multiple_translations": True,
    }
    dimer_kwargs["N_init"] = N_init_dict[name]
    geoms = (geom, )
    results = dimer_method(geoms, calc_getter, **dimer_kwargs)

    same_energy = geom.energy == pytest.approx(ref_energy)
    print(f"@Same energy: {str(same_energy): >5}, {name}, "
          f"{results.force_evals} force evaluations")
    if not same_energy:
        do_final_hessian(geom)

    # This way pytest prints the actual values... instead of just the boolean
    assert geom.energy == pytest.approx(ref_energy)
示例#3
0
def test_ts_hessian_opt(tsopt_cls, ref_cycle):
    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",
        "max_line_search": True,
        "min_line_search": True,
    }
    opt = tsopt_cls(geom, **opt_kwargs)
    opt.run()
    do_final_hessian(geom, write_imag_modes=True)

    assert opt.is_converged
    # 11 without linesearch
    assert opt.cur_cycle == ref_cycle
    assert geom.energy == pytest.approx(-92.2460426792319)
示例#4
0
def test_oniom3():
    run_dict = {
        "xyz": "lib:oniom3alkyl.pdb",
        "coord_type": "redund",
        "calc": {
            "type": "oniom",
            "calcs": {
                "real": {
                    "type": "pyscf",
                    "basis": "sto3g",
                    "pal": 2,
                },
                "mid": {
                    "type": "pyscf",
                    "basis": "321g",
                    "pal": 2,
                },
                "high": {
                    "type": "pyscf",
                    # "basis": "sto3g",
                    "basis": "431g",
                    "pal": 2,
                },
            },
            "models": {
                "high": {
                    "inds": list(range(7, 16)),
                    "calc": "high",
                },
                "mid": {
                    "inds": list(range(4, 19)),
                    "calc": "mid",
                },
            }
        },
        "opt": {
            "thresh": "gau_tight",
        },
    }
    res = run_from_dict(run_dict)
    print()

    opt = res.opt
    assert opt.is_converged
    assert opt.cur_cycle == 7

    geom = res.opt_geom
    res = do_final_hessian(geom, save_hessian=False)
    nus = res.nus
    assert nus[-1] == pytest.approx(3747.5594141, abs=1e-2)
    assert nus[-5] == pytest.approx(3563.8997581, abs=1e-2)
示例#5
0
def test_do_final_hessian(data_dir):
    fn = data_dir / "final_geometry.xyz"
    geom = geom_from_xyz_file(fn, coord_type="redund")
    calc = ORCA("")

    grad = np.load(data_dir / "grad.npy")
    hess = np.load(data_dir / "hess.npy")
    geom.hessian = hess
    geom.gradient = grad

    res = do_final_hessian(geom, save_hessian=False)

    neg_eigvals = res.neg_eigvals
    assert len(neg_eigvals) == 1
    np.testing.assert_allclose(neg_eigvals[0], -0.00224392407)
示例#6
0
def test_acetaldehyde_opt():
    """
        From https://doi.org/10.1016/S0166-1280(98)00475-8
    """
    geom = geom_loader("lib:acetaldehyd_oniom.xyz", coord_type="redund")

    real = set(range(len(geom.atoms)))
    high = [4, 5, 6]

    calcs = {
        "real": {
            "type": "g16",
            "route": "hf sto-3g"
        },
        "high": {
            "type": "g16",
            "route": "b3lyp d95v"
        }
    }

    for key, calc in calcs.items():
        calc["pal"] = 2
        calc["mult"] = 1
        calc["charge"] = 0

    models = {
        "high": {
            "inds": high,
            "calc": "high",
        },
    }

    oniom = ONIOM(calcs, models, geom, layers=None)
    geom.set_calculator(oniom)

    opt = RFOptimizer(geom, thresh="gau_tight")
    opt.run()
    assert geom.energy == pytest.approx(-153.07526171)

    hess_result = do_final_hessian(geom, save_hessian=False)
    nus = hess_result.nus
    print("wavenumbers / cm⁻¹:", nus)

    assert nus[-1] == pytest.approx(3759.5872)
    assert nus[-3] == pytest.approx(3560.9944)
示例#7
0
    def postprocess(self):
        super().postprocess()

        if self.do_hess:
            print()
            do_final_hessian(self.geometry)
示例#8
0
calc = Gaussian16("PM6", pal=4)
# from pysisyphus.calculators.XTB import XTB
# calc = XTB(pal=4)
geom.set_calculator(calc)

# opt = ANCOptimizer(geom, dump=True)
opt_kwargs = {
    "dump": True,
    "hessian_init": "calc",
    "freeze_modes": 200,
    "max_cycles": 20,
    "prefix": "frozen_"
}
opt = NCOptimizer(geom, **opt_kwargs)
opt.run()
do_final_hessian(geom)

# from pysisyphus.Geometry import Geometry
# from pysisyphus.tsoptimizers.RSIRFOptimizer import RSIRFOptimizer
# geom = Geometry(geom.atoms, geom.coords, coord_type="redund", define_prims=((20, 19),))
# geom.set_calculator(calc)
# tsopt = RSIRFOptimizer(geom, hessian_recalc=5, trust_max=0.3)
# tsopt.run()
# do_final_hessian(geom)

# from pysisyphus.irc.EulerPC import EulerPC
# geom = Geometry(geom.atoms, geom.cart_coords)
# geom.set_calculator(calc)
# irc = EulerPC(geom)
# irc.run()