def test_cp2k_singlepoint_mock(mocker: MockFixture): """Mock a call to CP2K.""" # single point calculation s = fill_cp2k_defaults(templates.singlepoint) # print orbitals s.specific.cp2k.force_eval.dft.print.mo.filename = ( PATH / "orbitals.out").as_posix() s.specific.cp2k.force_eval.dft.print.mo.mo_index_range = "7 46" s.specific.cp2k.force_eval.dft.scf.added_mos = 20 # Construct a result objects job = cp2k(s, ETHYLENE) jobname = "cp2k_job" run_mocked = mock_runner(mocker, jobname) rs = run_mocked(job) # electronic energy assertion.isfinite(rs.energy) # Molecular orbitals orbs = rs.orbitals assertion.assert_(np.isfinite, orbs.eigenvectors, post_process=np.all) # eigenvalues assertion.shape_eq(orbs.eigenvectors, (46, 40))
def test_adf_parser(): """Test the adf output readers.""" energy = kfreader(path_t21, section="Energy", prop="Bond Energy") charge = kfreader(path_t21, section="Properties", prop="AtomCharge Mulliken") assertion.isclose(np.sum(charge), 0.0, abs_tol=1e-8) assertion.isfinite(energy)
def test_dftb_opt_mock(mocker: MockFixture): """Mock a geometry optimization using DFTB.""" jobname = "dftb_geometry" job = dftb(templates.geometry, WATER, job_name=jobname) run_mocked = mock_runner(mocker, jobname) rs = run_mocked(job) # check the properties assertion.isfinite(rs.energy) assertion.len_eq(rs.dipole, 3) assertion.isinstance(rs.molecule, Molecule)
def test_adf_mock(mocker: MockFixture): """Mock the ADF output.""" mol = Molecule(PATH_MOLECULES / "acetonitrile.xyz") job = adf(templates.geometry, mol) run_mocked = mocker.patch("qmflows.run") jobname = "ADFjob" dill_path = WORKDIR / jobname / "ADFjob.dill" plams_dir = WORKDIR / jobname run_mocked.return_value = ADF_Result(templates.geometry, mol, jobname, dill_path=dill_path, work_dir=plams_dir, plams_dir=plams_dir) rs = run_mocked(job) assertion.isfinite(rs.energy) assertion.isfinite(rs.h**o) assertion.isfinite(rs.lumo) # Array of runtime for each optimization assertion.isfinite(rs.runtime[-1]) # 3-dimensional vector assertion.len_eq(rs.dipole, 3) # number of steps until convergence assertion.eq(rs.optcycles, 8) # Test molecule # Molecule mol = rs.molecule assertion.isinstance(mol, Molecule) assertion.len_eq(mol, 6) # there are 6 atoms
def test_c2pk_freq_mock(mocker: MockFixture): """Mock a call to CP2K.""" # Frequency calculation s = fill_cp2k_defaults(templates.singlepoint) s.specific.cp2k.vibrational_analysis.thermochemistry = ".TRUE." s.specific.cp2k["global"]["run_type"] = "VIBRATIONAL_ANALYSIS" jobname = "cp2k_freq" run_mocked = mock_runner(mocker, jobname) job = cp2k(s, ETHYLENE, job_name=jobname) rs = run_mocked(job) # check properties assertion.isfinite(rs.enthalpy) assertion.isfinite(rs.free_energy)
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
def test_dftb_freq_mock(mocker: MockFixture): """Mock a geometry optimization using DFTB.""" jobname = "dftb_freq" job = dftb(templates.geometry, WATER, job_name=jobname) run_mocked = mock_runner(mocker, jobname) rs = run_mocked(job) # Check that hessian is symmetric hess_list = rs.hessian dim = int(np.sqrt(len(hess_list))) hess = np.array(hess_list).reshape(dim, dim) assertion.isclose(np.sum(hess - hess.T), 0.0) # enthalpy and Gibbs free energy assertion.isfinite(rs.enthalpy) assertion.isfinite(rs.free_energy) # frequencies assertion.isfinite(np.sum(rs.frequencies))
def test_isfinite() -> None: """Test :meth:`AssertionManager.isfinite`.""" assertion.isfinite(0) assertion.isfinite(0.0) assertion.isfinite(98) assertion.isfinite(nan, invert=True) assertion.isfinite(inf, invert=True) assertion.isfinite(-inf, invert=True) assertion.isfinite(1, 1, 1, exception=TypeError) assertion.isfinite('bob', exception=TypeError)
def test_line_extraction(): """Test the line extraction function for ADF.""" h**o = extract_line_value(path_output, pattern="H**O", pos=4) assertion.isfinite(h**o)
def test_adf_awk(): """Test the awk parser for ADF.""" script = r"/Total Used/ {print $9}" filename = path_output.as_posix() results = np.array(awk_file(filename, script=script)) assertion.isfinite(np.sum(results))
def test_orca_awk(): """Test the Awk reader for orca.""" script = r"/Sum of individual times/ {runtime = $6} END {print runtime}" filename = PATH_OUTPUT.as_posix() result = awk_file(filename, script=script) assertion.isfinite(result)