Example #1
0
def create_cp2k_settings(mol: Molecule) -> Settings:
    """Create CP2K general settings."""
    # Set path for basis set
    path_basis = pkg_resources.resource_filename("nanoqm",
                                                 "basis/BASIS_MOLOPT")
    path_potential = pkg_resources.resource_filename("nanoqm",
                                                     "basis/GTH_POTENTIALS")

    # Settings specifics
    s = Settings()
    s.basis = "DZVP-MOLOPT-SR-GTH"
    s.potential = "GTH-PBE"
    s.cell_parameters = 25
    s.specific.cp2k.force_eval.subsys.cell.periodic = 'none'
    s.specific.cp2k.force_eval.dft.basis_set_file_name = path_basis
    s.specific.cp2k.force_eval.dft.potential_file_name = path_potential

    # functional
    s.specific.cp2k.force_eval.dft.xc["xc_functional pbe"] = {}

    # Generate kinds for the atom types
    elements = [x.symbol for x in mol.atoms]
    kinds = generate_kinds(elements, s.basis, s.potential)

    # Update the setting with the kinds
    s.specific = s.specific + kinds

    return s
Example #2
0
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')
Example #3
0
def test_cp2k_cell_parameters():
    """Test the translation from settings to CP2K specific cell parameters keywords."""
    ETHYLENE = Molecule(PATH_MOLECULES / "ethylene.xyz")

    # List of parameters
    s = Settings()
    abc = [5.958, 7.596, 15.610]
    s.cell_parameters = abc

    # apply transformations
    CP2K.handle_special_keywords(s, "cell_parameters", abc, ETHYLENE)

    # compare with the reference
    ref = Settings()
    ref.specific.cp2k.force_eval.subsys.cell.ABC = " [angstrom] 5.958 7.596 15.61"
    assertion.eq(s.specific, ref.specific)

    # cubic cell
    s = Settings()
    abc = 10
    s.cell_parameters = abc

    # apply transformations
    CP2K.handle_special_keywords(s, "cell_parameters", abc, ETHYLENE)

    # compare with the reference
    ref = Settings()
    ref.specific.cp2k.force_eval.subsys.cell.ABC = " [angstrom] 10.0 10.0 10.0"
    assertion.eq(s.specific, ref.specific)

    # Matrix
    s = Settings()
    abc = [[16.12, 0.078, -0.70], [-0.22, 4.39, 1.41], [-0.22, 1.73, 9.75]]

    s.cell_parameters = abc

    # apply transformations
    CP2K.handle_special_keywords(s, "cell_parameters", abc, ETHYLENE)

    # compare with the reference
    ref = Settings()
    ref.specific.cp2k.force_eval.subsys.cell.A = '{:} {:} {:}'.format(*abc[0])
    ref.specific.cp2k.force_eval.subsys.cell.B = '{:} {:} {:}'.format(*abc[1])
    ref.specific.cp2k.force_eval.subsys.cell.C = '{:} {:} {:}'.format(*abc[2])
    assertion.eq(s.specific, ref.specific)
Example #4
0
def prepare_cp2k_settings(geometry, work_dir):
    """
    Fills in the parameters for running a single job in CP2K.

    :param geometry: Molecular geometry stored as String
    :type geometry: plams.Molecule
    :param files: Tuple containing the IO files to run the calculations
    :type files: nameTuple
    :parameter settings: Dictionary contaning the data to
    fill in the template
    :type  settings: ~qmflows.Settings
    :parameter work_dir: Name of the Working folder
    :type      work_dir: String
    :param wfn_restart_job: Path to *.wfn cp2k file use as restart file.
    :type wfn_restart_job: String
    :param cp2k_config:  Parameters required by cp2k.
    :type cp2k_config: Dict
   :returns: ~qmflows.Settings
    """
    # Input/Output Files
    file_MO = join(work_dir, 'mo_coeffs.out')

    # create Settings for the Cp2K Jobs
    cp2k_args = Settings()
    cp2k_args.basis = "DZVP-MOLOPT-SR-GTH"
    cp2k_args.potential = "GTH-PBE"
    cp2k_args.cell_parameters = [12.74] * 3
    dft = cp2k_args.specific.cp2k.force_eval.dft
    dft.scf.added_mos = 20
    dft.scf.eps_scf = 1e-3
    dft["print"]["mo"]["mo_index_range"] = "7 46"
    dft.scf.diagonalization.jacobi_threshold = 1e-5

    # Atom basis
    cp2k_args.specific.cp2k.force_eval.subsys.kind["C"]["BASIS_SET"] = "DZVP-MOLOPT-SR-GTH-q4"
    cp2k_args.specific.cp2k.force_eval.subsys.kind["C"]["POTENTIAL"] = "GTH-PBE-q4"
    cp2k_args.specific.cp2k.force_eval.subsys.kind["H"]["BASIS_SET"] = "DZVP-MOLOPT-SR-GTH-q1"
    cp2k_args.specific.cp2k.force_eval.subsys.kind["H"]["POTENTIAL"] = "GTH-PBE-q1"

    # Functional
    # cp2k_args.specific.cp2k.force_eval.dft.xc["xc_functional"]["pbe"]["scale_x"] = 0.75
    # cp2k_args.specific.cp2k.force_eval.dft.xc["xc_functional"]["pbe"]["scale_c"] = 1.0

    # copy the basis and potential to a tmp file
    for f in ['BASIS_MOLOPT', 'GTH_POTENTIALS', 'BASIS_ADMM_MOLOPT']:
        shutil.copy(join('test/test_files', f), work_dir)
    # Cp2k configuration files

    force = cp2k_args.specific.cp2k.force_eval
    force.dft.basis_set_file_name = join(work_dir, 'BASIS_MOLOPT')
    force.dft.Basis_set_file_name = join(work_dir, 'BASIS_ADMM_MOLOPT')
    force.dft.potential_file_name = join(work_dir, 'GTH_POTENTIALS')
    force.dft['print']['mo']['filename'] = file_MO
    cp2k_args.specific.cp2k['global']['project'] = 'ethylene'

    return templates.singlepoint.overlay(cp2k_args)
def cp2k_input(
        range_orbitals, cell_parameters, cell_angles, added_mos,
        basis="DZVP-MOLOPT-SR-GTH", potential="GTH-PBE"):
    """
    # create ``Settings`` for the Cp2K Jobs.
    """
    # Main Cp2k Jobs
    cp2k_args = Settings()
    cp2k_args.basis = fun_format(basis)
    cp2k_args.potential = fun_format(potential)
    cp2k_args.cell_parameters = cell_parameters
    cp2k_args.cell_angles = cell_angles
    main_dft = cp2k_args.specific.cp2k.force_eval.dft
    main_dft.scf.added_mos = added_mos
    main_dft.scf.max_scf = 40
    main_dft.scf.eps_scf = 5e-4
    main_dft['print']['mo']['mo_index_range'] = '"{} {}"'.format(*range_orbitals)
    cp2k_args.specific.cp2k.force_eval.subsys.cell.periodic = fun_format('None')

    # Setting to calculate the wave function used as guess
    cp2k_OT = Settings()
    cp2k_OT.basis = fun_format(basis)
    cp2k_OT.potential = fun_format(potential)
    cp2k_OT.cell_parameters = cell_parameters
    cp2k_OT.cell_angles = cell_angles
    ot_dft = cp2k_OT.specific.cp2k.force_eval.dft
    ot_dft.scf.scf_guess = fun_format('atomic')
    ot_dft.scf.ot.minimizer = fun_format('DIIS')
    ot_dft.scf.ot.n_diis = 7
    ot_dft.scf.ot.preconditioner = fun_format('FULL_SINGLE_INVERSE')
    ot_dft.scf.added_mos = 0
    ot_dft.scf.eps_scf = 1e-06
    ot_dft.scf.scf_guess = fun_format('restart')
    cp2k_OT.specific.cp2k.force_eval.subsys.cell.periodic = fun_format('None')

    return cp2k_args, cp2k_OT
Example #6
0
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)