Exemplo n.º 1
0
    def test_run_second_order_phonons(self):
        N2_ref = """\
2   angstroem
free
N   3.571946174   3.571946174   3.620526682
N   3.571946174   3.571946174   4.71401439"""
        ref_pos = Posinp.from_string(N2_ref)
        gs = Job(posinp=ref_pos, name='N2', run_dir='tests/phonons_N2')
        phonons = Phonons(gs, order=2)
        raman = RamanSpectrum(phonons)
        assert not phonons.is_completed
        assert not raman.is_completed
        raman.run(nmpi=2, nomp=2)
        assert phonons.is_completed
        assert raman.is_completed
        # Test the only physically relevant phonon energy
        np.testing.assert_almost_equal(
            max(raman.energies), 2386.9463343478246, decimal=6)
        # Test the only physically relevant intensity
        np.testing.assert_almost_equal(
            max(raman.intensities), 22.564457304830206)
        # Test the only physically relevant depolarization ratio
        i = np.argmax(raman.energies)
        np.testing.assert_almost_equal(
            raman.depolarization_ratios[i], 0.09412173797731693)
        # Test that running the workflow again warns a UserWarning
        with pytest.warns(UserWarning):
            phonons.run()
        with pytest.warns(UserWarning):
            raman.run()
def single_phonon_calculation(
    nmpi=1,
    nomp=1,
    preparation=True,
    savefile=True,
    pseudos=False,
    verbose=False,
    optimization=True,
):
    if preparation:
        base_inp, ref_pos, jobname = utils.prepare_calculations()

    if optimization:
        base_job = Job(
            posinp=ref_pos,
            inputparams=base_inp,
            name=jobname,
            run_dir="geopt/",
            pseudos=pseudos,
        )
        geopt = Geopt(base_job, forcemax=2e-5, ncount_cluster_x=50)
        geopt.run(nmpi=nmpi, nomp=nomp, restart_if_incomplete=True)
        relaxed_pos = geopt.final_posinp
    else:
        relaxed_pos = ref_pos

    if "output" in base_inp:
        del base_inp["output"]

    ground_state = Job(
        name=jobname,
        posinp=relaxed_pos,
        inputparams=base_inp,
        run_dir="phonons/",
        ref_data_dir=(geopt.queue[0].data_dir if optimization else None),
        pseudos=pseudos,
    )
    phonons = Phonons(ground_state)
    phonons.run(nmpi=nmpi, nomp=nomp, restart_if_incomplete=True)

    if verbose:
        for i in range(len(phonons.energies)):
            print(f"Mode {i} :")
            print("Energy : ", phonons.energies[i])
            print("Mode : ", phonons.normal_modes[:, i], "\n")

    if savefile:
        save("phonons/ph_energies.npy", phonons.energies)
        save("phonons/ph_normal_modes.npy", phonons.normal_modes)
Exemplo n.º 3
0
    def test_run_first_order(self):
        N2_ref = """\
2   angstroem
free
N   3.571946174   3.571946174   3.620526682
N   3.571946174   3.571946174   4.71401439"""
        ref_pos = Posinp.from_string(N2_ref)
        gs = Job(posinp=ref_pos, name='N2', run_dir='tests/phonons_N2')
        ph = Phonons(gs, order=1)
        assert not ph.is_completed
        ph.run(nmpi=2, nomp=2)
        assert ph.is_completed
        # Test the only physically relevant phonon energy
        np.testing.assert_almost_equal(
            max(ph.energies), 2386.9850607523636, decimal=6)
Exemplo n.º 4
0
 def test_run(self):
     atoms = [Atom('N', [3.571946174, 3.571946174, 3.620526682]),
              Atom('N', [3.571946174, 3.571946174, 4.71401439])]
     pos = Posinp(atoms, units="angstroem", boundary_conditions="free")
     gs = Job(posinp=pos, name='N2', run_dir='tests/phonons_N2')
     ph = Phonons(gs)
     ir = InfraredSpectrum(ph)
     assert not ir.is_completed
     ir.run()
     assert ir.is_completed
     # Test the only physically relevant infrared intensity
     i = np.argmax(ir.energies)
     np.testing.assert_almost_equal(ir.intensities[i], 1.100446469749e-06)
     # Test that running the workflow again warns a UserWarning
     with pytest.warns(UserWarning):
         ir.run()
Exemplo n.º 5
0
 def test_run(self):
     atoms = [Atom('N', [3.571946174, 3.571946174, 3.620526682]),
              Atom('N', [3.571946174, 3.571946174, 4.71401439])]
     pos = Posinp(atoms, units="angstroem", boundary_conditions="free")
     gs = Job(posinp=pos, name='N2', run_dir='tests/phonons_N2')
     ph = Phonons(gs)
     ir = InfraredSpectrum(ph)
     vpt = VibPolTensor(ir)
     assert not vpt.is_completed
     vpt.run()
     assert vpt.is_completed
     # Test the mean vibrational polarizability
     np.testing.assert_almost_equal(vpt.mean_polarizability,
                                    1.092296473682357e-08)
     # Changing the value of e_cut changes the value of the mean
     # vibrational polarizability
     vpt.e_cut = 0
     np.testing.assert_almost_equal(vpt.mean_polarizability,
                                    0.0007775548377767935)
     # Test that running the workflow again warns a UserWarning
     with pytest.warns(UserWarning):
         vpt.run()
Exemplo n.º 6
0
class TestRamanSpectrum:

    gs = Job(posinp=pos, name='N2', run_dir='tests/phonons_N2')
    ph = Phonons(gs)

    def test_run_first_order_phonons(self):
        N2_ref = """\
2   angstroem
free
N   3.571946174   3.571946174   3.620526682
N   3.571946174   3.571946174   4.71401439"""
        ref_pos = Posinp.from_string(N2_ref)
        gs = Job(posinp=ref_pos, name='N2', run_dir='tests/phonons_N2')
        phonons = Phonons(gs, order=1)
        raman = RamanSpectrum(phonons)
        assert not phonons.is_completed
        assert not raman.is_completed
        raman.run(nmpi=2, nomp=2)
        assert phonons.is_completed
        assert raman.is_completed
        # Test the only physically relevant phonon energy
        np.testing.assert_almost_equal(
            max(raman.energies), 2386.9850607466974, decimal=6)
        # Test the only physically relevant intensity
        np.testing.assert_almost_equal(
            max(raman.intensities), 22.561427637014187)
        # Test the only physically relevant depolarization ratio
        i = np.argmax(raman.energies)
        np.testing.assert_almost_equal(
            raman.depolarization_ratios[i], 0.09412532271275614)
        # Test that running the workflow again warns a UserWarning
        with pytest.warns(UserWarning):
            phonons.run()
        with pytest.warns(UserWarning):
            raman.run()

    def test_run_second_order_phonons(self):
        N2_ref = """\
2   angstroem
free
N   3.571946174   3.571946174   3.620526682
N   3.571946174   3.571946174   4.71401439"""
        ref_pos = Posinp.from_string(N2_ref)
        gs = Job(posinp=ref_pos, name='N2', run_dir='tests/phonons_N2')
        phonons = Phonons(gs, order=2)
        raman = RamanSpectrum(phonons)
        assert not phonons.is_completed
        assert not raman.is_completed
        raman.run(nmpi=2, nomp=2)
        assert phonons.is_completed
        assert raman.is_completed
        # Test the only physically relevant phonon energy
        np.testing.assert_almost_equal(
            max(raman.energies), 2386.9463343478246, decimal=6)
        # Test the only physically relevant intensity
        np.testing.assert_almost_equal(
            max(raman.intensities), 22.564457304830206)
        # Test the only physically relevant depolarization ratio
        i = np.argmax(raman.energies)
        np.testing.assert_almost_equal(
            raman.depolarization_ratios[i], 0.09412173797731693)
        # Test that running the workflow again warns a UserWarning
        with pytest.warns(UserWarning):
            phonons.run()
        with pytest.warns(UserWarning):
            raman.run()

    @pytest.mark.parametrize("to_evaluate", [
        "RamanSpectrum(self.ph, ef_amplitudes=1)",
        "RamanSpectrum(self.ph, ef_amplitudes=[3]*2)",
        "RamanSpectrum(self.ph, ef_amplitudes=[3]*4)",
    ])
    def test_init_raises_ValueError(self, to_evaluate):
        with pytest.raises(ValueError):
            eval(to_evaluate)
Exemplo n.º 7
0
 def test_init_raises_NotImplementedError(self):
     with pytest.raises(NotImplementedError):
         Phonons(self.gs, order=-1)