Exemplo n.º 1
0
def test_otf_par(software, per_atom_par, n_cpus):
    """
    Test that an otf run can survive going for more steps
    :return:
    """
    example = 1
    outdir = f'test_outputs_{software}'
    if os.path.isdir(outdir):
        shutil.rmtree(outdir)

    if (not os.environ.get(cmd[software], False)):
        pytest.skip(f'{cmd[software]} not found in environment:'
                    f' Please install the code '
                    f' and set the {cmd[software]} env. '
                    'variable to point to the executable.')
    if (software is 'cp2k'):
        if (not "popt" in os.environ.get(cmd[software])):
            pytest.skip(f'cp2k is serial version'
                        f' skipping the parallel test')

    dft_input = f'{software}.in'
    dft_output = f'{software}.out'
    shutil.copy(f'./test_files/{software}_input_{example}.in', dft_input)

    dt = 0.0001
    number_of_steps = 5
    dft_loc = os.environ.get(cmd[software])
    std_tolerance_factor = -0.1

    casename = name_list[example]

    gp = get_gp(par=True, n_cpus=n_cpus, per_atom_par=per_atom_par)

    otf = OTF(dft_input,
              dt,
              number_of_steps,
              gp,
              dft_loc,
              std_tolerance_factor,
              init_atoms=[0],
              calculate_energy=True,
              max_atoms_added=1,
              par=True,
              n_cpus=n_cpus,
              freeze_hyps=1,
              skip=1,
              mpi="mpi",
              force_source=software,
              dft_output=dft_output,
              output_name=f'{casename}_otf_{software}',
              store_dft_output=([dft_output, dft_input], '.'))

    otf.run()

    if not os.path.isdir(outdir):
        os.mkdir(outdir)
    for f in os.listdir("./"):
        if f'{casename}_otf_{software}' in f:
            shutil.move(f, outdir)
    cleanup(software, f'{casename}_otf_{software}')
Exemplo n.º 2
0
def test_otf(software, example):
    """
    Test that an otf run can survive going for more steps
    :return:
    """

    print('running test_otf.py')
    print('current working directory:')
    print(os.getcwd())

    outdir = f'test_outputs_{software}'
    if os.path.isdir(outdir):
        shutil.rmtree(outdir)

    if (not os.environ.get(cmd[software], False)):
        pytest.skip(f'{cmd[software]} not found in environment:'
                    f' Please install the code '
                    f' and set the {cmd[software]} env. '
                    'variable to point to the executable.')

    dft_input = f'{software}.in'
    dft_output = f'{software}.out'
    shutil.copy(f'./test_files/{software}_input_{example}.in', dft_input)

    dt = 0.0001
    number_of_steps = 5
    dft_loc = os.environ.get(cmd[software])
    std_tolerance_factor = -0.1

    casename = name_list[example]

    gp = get_gp()

    otf = OTF(dt=dt,
              number_of_steps=number_of_steps,
              gp=gp,
              write_model=3,
              std_tolerance_factor=std_tolerance_factor,
              init_atoms=[0],
              calculate_energy=True,
              max_atoms_added=1,
              freeze_hyps=1,
              skip=1,
              force_source=software,
              dft_input=dft_input,
              dft_loc=dft_loc,
              dft_output=dft_output,
              output_name=f'{casename}_otf_{software}',
              store_dft_output=([dft_output, dft_input], '.'))

    otf.run()

    if not os.path.isdir(outdir):
        os.mkdir(outdir)
    for f in os.listdir("./"):
        if f'{casename}_otf_{software}' in f:
            shutil.move(f, outdir)
    cleanup(software, f'{casename}_otf_{software}')
Exemplo n.º 3
0
def test_otf_par(software, per_atom_par, n_cpus):
    """
    Test that an otf run can survive going for more steps
    :return:
    """

    example = 1
    outdir = f"test_outputs_{software}"
    if os.path.isdir(outdir):
        shutil.rmtree(outdir)

    print("running test_otf.py")
    print("current working directory:")
    print(os.getcwd())

    if not os.environ.get(cmd[software], False):
        pytest.skip(f"{cmd[software]} not found in environment:"
                    " Please install the code "
                    f" and set the {cmd[software]} env. "
                    "variable to point to the executable.")
    if software == "cp2k":
        if not "popt" in os.environ.get(cmd[software]):
            pytest.skip(f"cp2k is serial version skipping the parallel test")

    dft_input = f"{software}.in"
    dft_output = f"{software}.out"
    shutil.copy(f"./test_files/{software}_input_{example}.in", dft_input)

    dft_loc = os.environ.get(cmd[software])
    std_tolerance_factor = -0.1

    casename = name_list[example]

    gp = get_gp(par=True, n_cpus=n_cpus, per_atom_par=per_atom_par)

    otf = OTF(
        dt=dt,
        number_of_steps=number_of_steps,
        gp=gp,
        write_model=3,
        std_tolerance_factor=std_tolerance_factor,
        init_atoms=[0],
        calculate_energy=True,
        max_atoms_added=1,
        n_cpus=n_cpus,
        freeze_hyps=1,
        skip=1,
        mpi="mpi",
        force_source=software,
        dft_input=dft_input,
        dft_loc=dft_loc,
        dft_output=dft_output,
        output_name=f"{casename}_otf_{software}",
        store_dft_output=([dft_output, dft_input], "."),
    )

    otf.run()
    pytest.my_otf = otf
Exemplo n.º 4
0
def test_otf_al():
    """
    Test that an otf run can survive going for more steps
    :return:
    """
    os.system('cp ./test_files/qe_input_2.in ./pwscf.in')

    # make gp model
    kernel = en.three_body
    kernel_grad = en.three_body_grad
    hyps = np.array([0.1, 1, 0.01])
    hyp_labels = ['Signal Std', 'Length Scale', 'Noise Std']
    cutoffs = np.array([3.9, 3.9])
    energy_force_kernel = en.three_body_force_en

    gp = \
        GaussianProcess(kernel=kernel,
                        kernel_grad=kernel_grad,
                        hyps=hyps,
                        cutoffs=cutoffs,
                        hyp_labels=hyp_labels,
                        energy_force_kernel=energy_force_kernel,
                        maxiter=50)

    # set up DFT calculator
    qe_input = './pwscf.in'  # quantum espresso input file
    dft_loc = os.environ.get('PWSCF_COMMAND')

    # set up OTF parameters
    dt = 0.001  # timestep (ps)
    number_of_steps = 100  # number of steps
    std_tolerance_factor = 1
    max_atoms_added = 2
    freeze_hyps = 3

    otf = OTF(qe_input,
              dt,
              number_of_steps,
              gp,
              dft_loc,
              std_tolerance_factor,
              init_atoms=[0],
              calculate_energy=True,
              output_name='al_otf_qe',
              freeze_hyps=freeze_hyps,
              skip=5,
              max_atoms_added=max_atoms_added)

    # run OTF MD
    otf.run()

    os.system('mkdir test_outputs')
    os.system('mv al_otf_qe* test_outputs')

    cleanup_espresso_run()
Exemplo n.º 5
0
def test_otf_al():
    """
    Test that an otf run can survive going for more steps
    :return:
    """
    call('cp ./test_files/cp2k_input_2.in ./cp2k.in'.split())

    cp2k_input = './cp2k.in'
    dt = 0.001
    number_of_steps = 5
    cutoffs = np.array([3.9, 3.9])
    dft_loc = os.environ.get('CP2K_COMMAND')
    std_tolerance_factor = 1
    max_atoms_added = 2
    freeze_hyps = 3

    # make gp model
    kernel = en.three_body
    kernel_grad = en.three_body_grad
    hyps = np.array([0.1, 1, 0.01])
    hyp_labels = ['Signal Std', 'Length Scale', 'Noise Std']
    energy_force_kernel = en.three_body_force_en

    gp = \
        GaussianProcess(kernel=kernel,
                        kernel_grad=kernel_grad,
                        hyps=hyps,
                        cutoffs=cutoffs,
                        hyp_labels=hyp_labels,
                        energy_force_kernel=energy_force_kernel,
                        maxiter=50)

    otf = OTF(cp2k_input,
              dt,
              number_of_steps,
              gp,
              dft_loc,
              std_tolerance_factor,
              init_atoms=[0],
              calculate_energy=True,
              output_name='al_otf_cp2k',
              freeze_hyps=freeze_hyps,
              skip=5,
              force_source="cp2k",
              max_atoms_added=max_atoms_added)

    otf.run()
    call('mkdir test_outputs'.split())
    call('mv al_otf_cp2k*.* test_outputs'.split())

    cleanup("al_otf_cp2k")
Exemplo n.º 6
0
def test_otf_Al_npool():
    """
    Test that an otf run can survive going for more steps
    :return:
    """
    os.system('cp ./test_files/qe_input_2.in ./pwscf.in')

    qe_input = './pwscf.in'
    dt = 0.0001
    number_of_steps = 4
    cutoffs = np.array([5])
    dft_loc = os.environ.get('PWSCF_COMMAND')
    std_tolerance_factor = -0.1

    # make gp model
    kernel = en.two_body
    kernel_grad = en.two_body_grad
    hyps = np.array([1, 1, 1])
    hyp_labels = ['Signal Std', 'Length Scale', 'Noise Std']
    energy_force_kernel = en.two_body_force_en

    gp = \
        GaussianProcess(kernel=kernel,
                        kernel_grad=kernel_grad,
                        hyps=hyps,
                        cutoffs=cutoffs,
                        hyp_labels=hyp_labels,
                        par=True,
                        energy_force_kernel=energy_force_kernel,
                        maxiter=50)

    otf = OTF(qe_input,
              dt,
              number_of_steps,
              gp,
              dft_loc,
              std_tolerance_factor,
              init_atoms=[0],
              calculate_energy=True,
              max_atoms_added=1,
              no_cpus=2,
              par=True,
              npool=2,
              mpi="mpi",
              output_name='h2_otf_qe_par')

    otf.run()
    os.system('mkdir test_outputs')
    os.system('mv h2_otf_qe_par* test_outputs')
    cleanup_espresso_run()
Exemplo n.º 7
0
def test_otf_h2_par():
    """
    Test that an otf run can survive going for more steps
    :return:
    """
    call('cp ./test_files/cp2k_input_1.in ./cp2k.in'.split())

    cp2k_input = './cp2k.in'
    dt = 0.0001
    number_of_steps = 5
    cutoffs = np.array([5])
    dft_loc = os.environ.get('CP2K_COMMAND')
    std_tolerance_factor = -0.1

    # make gp model
    kernel = en.two_body
    kernel_grad = en.two_body_grad
    hyps = np.array([1, 1, 1])
    hyp_labels = ['Signal Std', 'Length Scale', 'Noise Std']
    energy_force_kernel = en.two_body_force_en

    gp = \
        GaussianProcess(kernel=kernel,
                        kernel_grad=kernel_grad,
                        hyps=hyps,
                        cutoffs=cutoffs,
                        hyp_labels=hyp_labels,
                        energy_force_kernel=energy_force_kernel,
                        par=True,
                        maxiter=50)

    otf = OTF(cp2k_input,
              dt,
              number_of_steps,
              gp,
              dft_loc,
              std_tolerance_factor,
              init_atoms=[0],
              calculate_energy=True,
              max_atoms_added=1,
              dft_softwarename="cp2k",
              no_cpus=2,
              par=True,
              mpi="mpi",
              output_name='h2_otf_cp2k_par')

    otf.run()
    call('mkdir test_outputs'.split())
    call('mv h2_otf_cp2k_par* test_outputs'.split())
    cleanup()
Exemplo n.º 8
0
def test_otf_h2():
    """
    :return:
    """
    os.system('cp ./test_files/test_POSCAR_2 POSCAR')

    vasp_input = './POSCAR'
    dt = 0.0001
    number_of_steps = 5
    cutoffs = np.array([5])
    dft_loc = 'cp ./test_files/test_vasprun_h2.xml vasprun.xml'
    std_tolerance_factor = -0.1

    # make gp model
    kernel = en.two_body
    kernel_grad = en.two_body_grad
    hyps = np.array([1, 1, 1])
    hyp_labels = ['Signal Std', 'Length Scale', 'Noise Std']
    energy_force_kernel = en.two_body_force_en

    gp = GaussianProcess(kernel=kernel,
                         kernel_grad=kernel_grad,
                         hyps=hyps,
                         cutoffs=cutoffs,
                         hyp_labels=hyp_labels,
                         energy_force_kernel=energy_force_kernel,
                         maxiter=50)

    otf = OTF(vasp_input,
              dt,
              number_of_steps,
              gp,
              dft_loc,
              std_tolerance_factor,
              init_atoms=[0],
              calculate_energy=True,
              max_atoms_added=1,
              no_cpus=1,
              dft_softwarename='vasp',
              output_name='h2_otf_vasp')

    otf.run()

    os.system('mv h2_otf_vasp* test_outputs')
Exemplo n.º 9
0
def test_otf_h2():
    """
    :return:
    """
    os.system("cp ./test_files/test_POSCAR_2 POSCAR")

    vasp_input = "./POSCAR"
    dt = 0.0001
    number_of_steps = 5
    cutoffs = {"twobody": 5}
    dft_loc = "cp ./test_files/test_vasprun_h2.xml vasprun.xml"
    std_tolerance_factor = -0.1

    # make gp model
    hyps = np.array([1, 1, 1])
    hyp_labels = ["Signal Std", "Length Scale", "Noise Std"]

    gp = GaussianProcess(
        kernel_name="2", hyps=hyps, cutoffs=cutoffs, hyp_labels=hyp_labels, maxiter=50
    )

    otf = OTF(
        dt=dt,
        number_of_steps=number_of_steps,
        gp=gp,
        calculate_energy=True,
        std_tolerance_factor=std_tolerance_factor,
        init_atoms=[0],
        output_name="h2_otf_vasp",
        max_atoms_added=1,
        force_source="vasp",
        dft_input=vasp_input,
        dft_loc=dft_loc,
        dft_output="vasprun.xml",
        n_cpus=1,
    )

    otf.run()

    os.system("mv h2_otf_vasp* test_outputs")
Exemplo n.º 10
0
def test_otf_h2():
    """
    :return:
    """
    os.system('cp ./test_files/test_POSCAR_2 POSCAR')

    vasp_input = './POSCAR'
    dt = 0.0001
    number_of_steps = 5
    cutoffs = {'twobody':5}
    dft_loc = 'cp ./test_files/test_vasprun_h2.xml vasprun.xml'
    std_tolerance_factor = -0.1

    # make gp model
    hyps = np.array([1, 1, 1])
    hyp_labels = ['Signal Std', 'Length Scale', 'Noise Std']

    gp = GaussianProcess(kernel_name='2',
                         hyps=hyps,
                         cutoffs=cutoffs,
                         hyp_labels=hyp_labels,
                         maxiter=50)

    otf = OTF(dt=dt, number_of_steps=number_of_steps,
              gp=gp, calculate_energy=True,
              std_tolerance_factor=std_tolerance_factor,
              init_atoms=[0],
              output_name='h2_otf_vasp',
              max_atoms_added=1,
              force_source='vasp',
              dft_input=vasp_input, dft_loc=dft_loc,
              dft_output="vasprun.xml",
              n_cpus=1)

    otf.run()

    os.system('mv h2_otf_vasp* test_outputs')
Exemplo n.º 11
0
def test_load_checkpoint(software):

    if not os.environ.get(cmd[software], False):
        pytest.skip(f"{cmd[software]} not found in environment:"
                    " Please install the code "
                    f" and set the {cmd[software]} env. "
                    "variable to point to the executable.")

    if software == "cp2k":
        pytest.skip()

    example = 1
    casename = name_list[example]
    log_name = f"{casename}_otf_{software}"
    new_otf = OTF.from_checkpoint(log_name + "_checkpt.json")
    print("loaded from checkpoint", log_name)
    assert new_otf.curr_step == number_of_steps
    new_otf.number_of_steps = new_otf.number_of_steps + 2
    new_otf.run()