def test_c2pk_cell_opt() -> None: """Test CP2K cell optimization calculations with the :class:`CP2K_MM` class.""" mol = Molecule(PATH / 'cspbbr3_3d.xyz') s = Settings() s.specific.cp2k += cell_opt.specific.cp2k_mm.copy() s.specific.cp2k.motion.cell_opt.max_iter = 10 s.specific.cp2k.motion.print['forces low'].filename = '' s.gmax = [22, 22, 22] s.cell_parameters = [25.452, 35.995, 24.452] s.charge = { 'param': 'charge', 'Cs': 0.2, 'Pb': 0.4, 'Br': -0.2, } s.lennard_jones = { 'param': ('sigma', 'epsilon'), 'unit': ('nm', 'kjmol'), 'Cs Cs': (0.585, 1), 'Cs Pb': (0.510, 1), 'Br Se': (0.385, 1), 'Pb Pb': (0.598, 1), 'Br Pb': (0.290, 1), 'Br Br': (0.426, 1), } job = cp2k_mm(settings=s, mol=mol, job_name='cp2k_mm_cell_opt') result = run(job, path=PATH) assertion.eq(result.status, 'successful')
def test_c2pk_npt_mock(mocker: MockFixture) -> None: """Mock a call to CP2K.""" s = Settings() job = cp2k_mm(s, None) run_mocked = mock_runner(mocker, settings=s, jobname="cp2k_mm_npt") result = run_mocked(job) ref_pressure = np.load(PATH / 'pressure.npy') np.testing.assert_allclose(result.pressure, ref_pressure)
def test_c2pk_md_mock(mocker: MockFixture) -> None: """Mock a call to CP2K.""" s = SETTINGS.copy() s.specific.cp2k += md.specific.cp2k_mm job = cp2k_mm(s, MOL) run_mocked = mock_runner(mocker, settings=s, jobname="cp2k_mm_md") result = run_mocked(job) assertion.eq(result.status, 'successful') assertion.isfile(result.results['cp2k-1_1000.restart'])
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)
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)
def test_md() -> None: """Test CP2K molecular dynamics calculations with the :class:`CP2K_MM` class.""" mol = Molecule( PATH_MOLECULES / 'Cd68Cl26Se55__26_acetate.freq.xyz') # Optimized coordinates s = SETTINGS.copy() s.specific.cp2k += md.specific.cp2k_mm s.specific.cp2k.motion.md.steps = 1000 job = cp2k_mm(settings=s, mol=mol, job_name='cp2k_mm_md') result = run(job, path=PATH) assertion.eq(result.status, 'successful') plams_results = result.results assertion.isfile(plams_results['cp2k-1_1000.restart'])
def test_c2pk_cell_opt_mock(mocker: MockFixture) -> None: """Mock a call to CP2K.""" mol = Molecule(PATH / 'cspbbr3_3d.xyz') s = Settings() s.specific.cp2k += cell_opt.specific.cp2k_mm.copy() s.specific.cp2k.motion.cell_opt.max_iter = 10 s.specific.cp2k.motion.print['forces low'].filename = '' s.gmax = [22, 22, 22] s.cell_parameters = [25.452, 35.995, 24.452] s.charge = { 'param': 'charge', 'Cs': 0.2, 'Pb': 0.4, 'Br': -0.2, } s.lennard_jones = { 'param': ('sigma', 'epsilon'), 'unit': ('nm', 'kjmol'), 'Cs Cs': (0.585, 1), 'Cs Pb': (0.510, 1), 'Br Se': (0.385, 1), 'Pb Pb': (0.598, 1), 'Br Pb': (0.290, 1), 'Br Br': (0.426, 1), } job = cp2k_mm(s, mol) run_mocked = mock_runner(mocker, settings=s, jobname="cp2k_mm_cell_opt") result = run_mocked(job) assertion.eq(result.status, 'successful') ref_volume = np.load(PATH / 'volume.npy') ref_coordinates = np.load(PATH / 'coordinates.npy') ref_forces = np.load(PATH / 'forces.npy') ref_lattice = np.load(PATH / 'lattice.npy') np.testing.assert_allclose(result.volume, ref_volume) np.testing.assert_allclose(result.coordinates, ref_coordinates) np.testing.assert_allclose(result.forces, ref_forces) np.testing.assert_allclose(result.lattice, ref_lattice)
def _multi_ligand_job(mol: Molecule, psf: PSFContainer, settings: QmSettings, workdir: str, db_file: str, **kwargs: Any) -> CP2KMM_Result: """Helper function for :func:`multi_ligand_job`.""" # Run MATCH on all unique ligands lig_dict = _lig_from_psf(mol, psf) ff: str = kwargs.pop('forcefield', 'top_all36_cgenff_new') rtf_list, prm = _run_match(lig_dict.values(), forcefield=ff) # Update the .psf file with all MATCH results initial_charge = psf.charge.sum() for id_range, rtf_file in zip(lig_dict.keys(), rtf_list): overlay_rtf_file(psf, rtf_file, id_range) # Update the charge _constrain_charge(psf, settings, initial_charge) # Fill in all missing core/ligand lennard-jones parameters with those from UFF # TODO: Connect this with the newly improved Auto-FOX 0.8 parameter guessing schemes prm_to_df(settings) if settings.get('lennard_jones') is not None: _fill_uff(psf, settings['lennard_jones']) elif settings.get('lennard-jones') is not None: _fill_uff(psf, settings['lennard-jones']) # Write the new .prm and .psf files and update the CP2K settings prm_name = join(workdir, 'mol.prm') psf_name = join(workdir, 'mol.psf') prm.write(prm_name) psf.write(psf_name) settings.prm = prm_name settings.psf = psf_name # Run the actual CP2K job with SET_CONFIG_STDOUT: job = cp2k_mm(mol=mol, settings=settings, **kwargs) return run_parallel(job, db_file=db_file, n_threads=1, always_cache=True, registry=registry, echo_log=False)
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)
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)
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)
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)