def main(file_xyz, cell, restart, basis, basis_folder): """Define which systems need to be calculated.""" system = Molecule(file_xyz) # Set path for basis set basisCP2K = join(basis_folder, "BASIS_MOLOPT") potCP2K = join(basis_folder, "GTH_POTENTIALS") # Settings specifics s = templates.geometry s.basis = basis s.potential = "GTH-PBE" s.cell_parameters = cell s.specific.cp2k.force_eval.dft.basis_set_file_name = basisCP2K s.specific.cp2k.force_eval.dft.potential_file_name = potCP2K s.specific.cp2k.force_eval.dft.uks = '' s.specific.cp2k.force_eval.dft.charge = '-1' s.specific.cp2k.force_eval.dft.multiplicity = '2' s.specific.cp2k.force_eval.dft.wfn_restart_file_name = f'{restart}' # ======================= # Compute OPT files with CP2k # ======================= result = run(cp2k(s, system)) # ====================== # Output the results # ====================== print(result.energy)
def prepare_job_cp2k(settings: Settings, dict_input: Dict[str, Any], guess_job: PromisedObject) -> CP2K: """Generate a :class:`qmflows.packages.cp2k_packages.CP2K` job. Parameters ---------- settings Input for CP2K dict_input Input for the current molecular geometry guess_job Previous job to read the guess wave function Returns ------- :class:`qmflows.packages.cp2k_package.CP2K` job to run """ job_settings = prepare_cp2k_settings(settings, dict_input, guess_job) # remove keywords not use on the next translation phase for x in ('basis', 'potential'): if x in job_settings: del job_settings[x] return cp2k(job_settings, string_to_plams_Molecule(dict_input["geometry"]), work_dir=dict_input['point_dir'])
def main(file_xyz, cell, restart, basis, basis_folder): # Define which systems need to be calculated system = Molecule(file_xyz) # Set path for basis set basisCP2K = join(basis_folder, "BASIS_MOLOPT") potCP2K = join(basis_folder, "GTH_POTENTIALS") # Settings specifics s = templates.geometry s.basis = basis s.potential = "GTH-PBE" s.cell_parameters = cell s.specific.cp2k.force_eval.dft.basis_set_file_name = basisCP2K s.specific.cp2k.force_eval.dft.potential_file_name = potCP2K # s.specific.cp2k.force_eval.dft.uks = '' # s.specific.cp2k.force_eval.dft.charge = '1' # s.specific.cp2k.force_eval.dft.multiplicity = '2' s.specific.cp2k.force_eval.dft.wfn_restart_file_name = '{}'.format(restart) # ======================= # Compute OPT files with CP2k # ======================= result = run(cp2k(s, system)) # ====================== # Output the results # ====================== print(result.energy)
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_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_cp2k_opt(tmp_path: PathLike): """Run a simple molecular optimization.""" s = fill_cp2k_defaults(templates.geometry) # Do a single step s.specific.cp2k.motion.geo_opt.max_iter = 1 s.specific.cp2k.force_eval.dft.scf.eps_scf = 1e-1 water = Molecule(PATH_MOLECULES / "h2o.xyz", 'xyz', charge=0, multiplicity=1) job = cp2k(s, water) mol = run(job, folder=tmp_path) assertion.isinstance(mol.molecule, Molecule)
def test_c2pk_opt_mock(mocker: MockFixture): """Mock a call to CP2K.""" # geometry optimization input s = fill_cp2k_defaults(templates.geometry) jobname = "cp2k_opt" run_mocked = mock_runner(mocker, jobname) job = cp2k(s, ETHYLENE, job_name=jobname) rs = run_mocked(job) # check the optimized geometry mol = rs.geometry assertion.len_eq(mol, 6) atom = mol[1] assertion.len_eq(atom.coords, 3) assertion.eq(atom.symbol, 'C')
def compute_geo_opt(mol: Molecule, name: str, workdir: str, path_results: str) -> Molecule: """Perform the geometry optimization of **mol**.""" # Get cp2k settings s = create_cp2k_settings(mol) # Update the setting with the geometry optimization template sett_geo_opt = templates.geometry.overlay(s) # Create the cp2k job opt_job = cp2k(sett_geo_opt, mol, job_name="cp2k_opt") # Run the cp2k job optimized_geometry = run(opt_job.geometry, path=workdir, folder=name) store_optimized_molecule(optimized_geometry, name, path_results) logger.info(f"{name} has been optimized with CP2K") return optimized_geometry
def run_plams(path_input): """ Call Plams to run a CP2K job """ # create settings dict_input = process_input(path_input, "derivative_couplings") sett = dict_input['cp2k_general_settings']['cp2k_settings_guess'] # adjust the cell parameters file_cell_parameters = dict_input['cp2k_general_settings'].get("file_cell_parameters") if file_cell_parameters is not None: array_cell_parameters = read_cell_parameters_as_array(file_cell_parameters)[1] sett.cell_parameters = array_cell_parameters[0, 2:11].reshape(3, 3).tolist() # Run the job job = cp2k(sett, plams.Molecule("test/test_files/C.xyz")) print("sett: ", sett) return run(job.energy)
def run_plams(path_input: PathLike) -> float: """Call Plams to run a CP2K job.""" # create settings dict_input = process_input(path_input, "derivative_couplings") sett = dict_input['cp2k_general_settings']['cp2k_settings_guess'] # adjust the cell parameters file_cell_parameters = dict_input['cp2k_general_settings'].get( "file_cell_parameters") if file_cell_parameters is not None: array_cell_parameters = read_cell_parameters_as_array( file_cell_parameters)[1] sett.cell_parameters = array_cell_parameters[0, 2:11].reshape(3, 3).tolist() # Run the job job = cp2k(sett, plams.Molecule(PATH_TEST / "C.xyz")) return run(job.energy)
def compute_ldos(mol: Molecule, coord: NestedDict, name: str, workdir: str, path_results: str) -> None: """Compute the DOS projected on subsets of atoms given through lists. These lists are divided by atom type and coordination number. """ # Get cp2k settings s = create_cp2k_settings(mol) # Get the cp2k ldos setting containing the lists ldos = create_ldos_lists(coord) # Join settings and update with the single point template s.specific = s.specific + ldos sett_ldos = templates.singlepoint.overlay(s) # Create the cp2k job dos_job = cp2k(sett_ldos, mol, job_name="cp2k_ldos") # Run the cp2k job run(dos_job, path=workdir, folder=name) store_coordination(coord, name, path_results) logger.info(f"{name} LDOS has been printed with CP2K")
def main(file_xyz, cell, restart, basis, basis_folder): """ Define which systems need to be calculated """ system = Molecule(file_xyz) # Set path for basis set basisCP2K = join(basis_folder, "BASIS_MOLOPT") potCP2K = join(basis_folder, "GTH_POTENTIALS") # Settings specifics s = templates.singlepoint del s.specific.cp2k.force_eval.dft.print.mo s.basis = basis s.potential = "GTH-PBE" s.cell_parameters = cell s.specific.cp2k.force_eval.dft.basis_set_file_name = basisCP2K s.specific.cp2k.force_eval.dft.potential_file_name = potCP2K s.specific.cp2k.force_eval.dft.print.pdos.nlumo = '1000' s.specific.cp2k.force_eval.dft.wfn_restart_file_name = '{}'.format(restart) s.specific.cp2k.force_eval.dft.scf.ot.minimizer = 'DIIS' s.specific.cp2k.force_eval.dft.scf.ot.n_diis = 7 s.specific.cp2k.force_eval.dft.scf.ot.preconditioner = 'FULL_SINGLE_INVERSE' s.specific.cp2k['global']['run_type'] = 'energy' # ======================= # Compute OPT files with CP2k # ======================= result = run(cp2k(s, system)) # ====================== # Output the results # ====================== print(result.energy)