Beispiel #1
0
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)
Beispiel #2
0
def test_singlepoint() -> None:
    """Test CP2K singlepoint calculations with the :class:`CP2K_MM` class."""
    s = SETTINGS.copy()
    s.specific.cp2k += singlepoint.specific.cp2k_mm

    job = cp2k_mm(settings=s, mol=MOL, job_name='cp2k_mm_sp')
    result = run(job, path=PATH)
    assertion.eq(result.status, 'successful')

    # Compare energies
    ref = -15.4431781758
    assertion.isclose(result.energy, ref, rel_tol=10**-4)
Beispiel #3
0
def test_cp2k_singlepoint_mock(mocker: MockFixture) -> None:
    """Mock a call to CP2K."""
    s = SETTINGS.copy()
    s.specific.cp2k += geometry.specific.cp2k_mm

    job = cp2k_mm(s, MOL)
    run_mocked = mock_runner(mocker, settings=s, jobname="cp2k_mm_sp")

    result = run_mocked(job)
    assertion.eq(result.status, 'successful')

    # Compare energies
    ref = -15.4431781758
    assertion.isclose(result.energy, ref, rel_tol=10**-4)
Beispiel #4
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
Beispiel #5
0
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))
Beispiel #6
0
def test_c2pk_freq_mock(mocker: MockFixture) -> None:
    """Mock a call to CP2K."""
    s = SETTINGS.copy()
    s.specific.cp2k += freq.specific.cp2k_mm

    job = cp2k_mm(s, MOL)
    run_mocked = mock_runner(mocker, settings=s, jobname="cp2k_mm_freq")

    result = run_mocked(job)
    assertion.eq(result.status, 'successful')

    freqs = result.frequencies
    freqs_ref = np.load(PATH / 'Cd68Cl26Se55__26_acetate.freq.npy')
    np.testing.assert_allclose(freqs, freqs_ref, rtol=0, atol=5.0)

    G = result.free_energy
    H = result.enthalpy
    H_ref = -8642.371633064053
    assertion.isnan(G)
    assertion.isclose(H, H_ref, rel_tol=0.1)
Beispiel #7
0
def test_freq() -> None:
    """Test CP2K frequency calculations with the :class:`CP2K_MM` class."""
    mol = Molecule(
        PATH_MOLECULES /
        'Cd68Cl26Se55__26_acetate.freq.xyz')  # Optimized coordinates
    s = SETTINGS.copy()
    s.specific.cp2k += freq.specific.cp2k_mm

    job = cp2k_mm(settings=s, mol=mol, job_name='cp2k_mm_freq')
    result = run(job, path=PATH)
    assertion.eq(result.status, 'successful')

    freqs = result.frequencies
    freqs_ref = np.load(PATH / 'Cd68Cl26Se55__26_acetate.freq.npy')
    np.testing.assert_allclose(freqs, freqs_ref, rtol=0, atol=5.0)

    G = result.free_energy
    H = result.enthalpy
    H_ref = -8642.371633064053
    assertion.isnan(G)
    assertion.isclose(H, H_ref, rel_tol=0.1)
Beispiel #8
0
def test_geometry() -> None:
    """Test CP2K geometry optimization calculations with the :class:`CP2K_MM` class."""
    s = SETTINGS.copy()
    s.specific.cp2k += geometry.specific.cp2k_mm

    job = cp2k_mm(settings=s, mol=MOL, job_name='cp2k_mm_opt')
    result = run(job, path=PATH)
    assertion.eq(result.status, 'successful')

    # Compare energies
    ref = -16.865587192150834
    assertion.isclose(result.energy, ref, rel_tol=10**-4)

    # Compare geometries
    xyz_ref = np.load(PATH_MOLECULES / 'Cd68Cl26Se55__26_acetate.npy')
    _xyz = np.array(result.geometry)
    _xyz -= _xyz.mean(axis=0)[None, ...]
    xyz = overlap_coords(_xyz, xyz_ref)

    r_mean = np.linalg.norm(xyz - xyz_ref, axis=1).mean()
    assertion.le(r_mean, 0.1)
Beispiel #9
0
def _validate(atom: str, value: float, param: pd.Series) -> None:
    """Validate the moves of :func:`test_constraint_blocks`."""
    ident = f"{atom}={value}"
    assertion.isclose(param[atom],
                      value,
                      abs_tol=0.001,
                      message=f'{atom} ({ident})')
    for min_, max_, (key, v) in zip(PRM_MIN, PRM_MAX, param.items()):
        assertion.le(min_, v, message=f'{key} ({ident})')
        assertion.ge(max_, v, message=f'{key} ({ident})')

    assertion.isclose((param * COUNT).sum(),
                      0,
                      abs_tol=0.001,
                      message=f"net charge ({ident})")
    for key in EXCLUDE:
        assertion.eq(param[key], PARAM[key], message=f'{key} ({ident})')

    idx1 = ATOM_COEFS[0].index
    idx2 = ATOM_COEFS[1].index
    v1 = (param[idx1] * ATOM_COEFS[0]).sum()
    v2 = (param[idx2] * ATOM_COEFS[1]).sum()
    assertion.isclose(v1,
                      v2,
                      abs_tol=0.001,
                      message=f"{idx1} and {idx2} ({ident})")
Beispiel #10
0
def test_c2pk_opt_mock(mocker: MockFixture) -> None:
    """Mock a call to CP2K."""
    s = SETTINGS.copy()
    s.specific.cp2k += singlepoint.specific.cp2k_mm

    job = cp2k_mm(s, MOL)
    run_mocked = mock_runner(mocker, settings=s, jobname="cp2k_mm_opt")

    result = run_mocked(job)
    assertion.eq(result.status, 'successful')

    # Compare energies
    ref = -16.865587192150834
    energy = result.energy
    assertion.isclose(energy, ref, rel_tol=10**-4)

    # Compare geometries
    xyz_ref = np.load(PATH_MOLECULES / 'Cd68Cl26Se55__26_acetate.npy')
    _xyz = np.array(result.geometry)
    _xyz -= _xyz.mean(axis=0)[None, ...]
    xyz = overlap_coords(_xyz, xyz_ref)

    r_mean = np.linalg.norm(xyz - xyz_ref, axis=1).mean()
    assertion.le(r_mean, 0.1)