def test_vasp_charge():
    """
    Run VASP tests to ensure that determining number of electrons from
    user-supplied charge works correctly. This is conditional on the existence
    of the VASP_COMMAND or VASP_SCRIPT environment variables.

    """

    from ase.build import bulk
    from ase.calculators.vasp import Vasp
    from ase.test import must_raise
    from ase.test.vasp import installed

    assert installed()

    system = bulk('Al', 'fcc', a=4.5, cubic=True)

    # Dummy calculation to let VASP determine default number of electrons
    calc = Vasp(xc='LDA', nsw=-1, ibrion=-1, nelm=1, lwave=False, lcharg=False)
    calc.calculate(system)
    default_nelect_from_vasp = calc.get_number_of_electrons()
    assert default_nelect_from_vasp == 12

    # Make sure that no nelect was written into INCAR yet (as it wasn't necessary)
    calc = Vasp()
    calc.read_incar()
    assert calc.float_params['nelect'] is None

    # Compare VASP's output nelect from before minus charge to default nelect
    # determined by us minus charge
    charge = -2
    calc = Vasp(xc='LDA', nsw=-1, ibrion=-1, nelm=1, lwave=False, lcharg=False,
                charge=charge)
    calc.initialize(system)
    calc.write_input(system)
    calc.read_incar()
    assert calc.float_params['nelect'] == default_nelect_from_vasp - charge

    # Test that conflicts between explicitly given nelect and charge are detected
    with must_raise(ValueError):
        calc = Vasp(xc='LDA', nsw=-1, ibrion=-1, nelm=1, lwave=False, lcharg=False,
                    nelect=default_nelect_from_vasp-charge+1,
                    charge=charge)
        calc.calculate(system)

    # Test that nothing is written if charge is 0 and nelect not given
    calc = Vasp(xc='LDA', nsw=-1, ibrion=-1, nelm=1, lwave=False, lcharg=False,
                charge=0)
    calc.initialize(system)
    calc.write_input(system)
    calc.read_incar()
    assert calc.float_params['nelect'] is None

    # Test that explicitly given nelect still works as expected
    calc = Vasp(xc='LDA', nsw=-1, ibrion=-1, nelm=1, lwave=False, lcharg=False,
                nelect=15)
    calc.calculate(system)
    assert calc.get_number_of_electrons() == 15
Beispiel #2
0
print "Band Calc"
bands = zns.get_potential_energy()

# Get the band energies across the Brillouin zone
e_kn = np.array([calc_band.get_eigenvalues(k) for k in range(len(kpts))])
# Get Fermi energy
ef = calc_band.get_fermi_level()
nbands = calc_band.get_number_of_bands()

# Plotting time
e_kn -= ef
emin = e_kn.min() - 1.0
emax = e_kn[:, nbands-1].max() + 1.0

# Plot the energy Vs k-point for each band
nelect = calc_band.get_number_of_electrons()
for n in range(nbands):
# Choose colour based on valence or conduction
    for n in range(nbands):
	if n < nelect/2:
	    plt.plot(x, e_kn[len(ibzkpts):len(kpts), n],color='#800000')
	else:
	    plt.plot(x, e_kn[len(ibzkpts):len(kpts), n],color='#228B22')

# Shade in valence and conduction bands
plt.fill_between(x,emin,e_kn[len(ibzkpts):len(kpts), nelect/2 - 1],color='#800000',alpha=0.6)
plt.fill_between(x,e_kn[len(ibzkpts):len(kpts), nelect/2],emax,color='#228B22',alpha=0.6)

# Set thick lines at each k-point
for p in X:
    plt.plot([p, p], [emin, emax], 'k-')
Beispiel #3
0
Should be removed along with the net_charge parameter itself at some point.
"""

from ase.build import bulk
from ase.calculators.vasp import Vasp
from ase.test import must_raise, must_warn
from ase.test.vasp import installed

assert installed()

system = bulk('Al', 'fcc', a=4.5, cubic=True)

# Dummy calculation to let VASP determine default number of electrons
calc = Vasp(xc='LDA', nsw=-1, ibrion=-1, nelm=1, lwave=False, lcharg=False)
calc.calculate(system)
default_nelect_from_vasp = calc.get_number_of_electrons()
assert default_nelect_from_vasp == 12

# Compare VASP's output nelect from before + net charge to default nelect
# determined by us + net charge
with must_warn(FutureWarning):
    net_charge = -2
    calc = Vasp(xc='LDA',
                nsw=-1,
                ibrion=-1,
                nelm=1,
                lwave=False,
                lcharg=False,
                net_charge=net_charge)
    calc.initialize(system)
    calc.write_input(system)
Beispiel #4
0
print "Band Calc"
bands = zns.get_potential_energy()

# Get the band energies across the Brillouin zone
e_kn = np.array([calc_band.get_eigenvalues(k) for k in range(len(kpts))])
# Get Fermi energy
ef = calc_band.get_fermi_level()
nbands = calc_band.get_number_of_bands()

# Plotting time
e_kn -= ef
emin = e_kn.min() - 1.0
emax = e_kn[:, nbands - 1].max() + 1.0

# Plot the energy Vs k-point for each band
nelect = calc_band.get_number_of_electrons()
for n in range(nbands):
    # Choose colour based on valence or conduction
    for n in range(nbands):
        if n < nelect / 2:
            plt.plot(x, e_kn[len(ibzkpts):len(kpts), n], color='#800000')
        else:
            plt.plot(x, e_kn[len(ibzkpts):len(kpts), n], color='#228B22')

# Shade in valence and conduction bands
plt.fill_between(x,
                 emin,
                 e_kn[len(ibzkpts):len(kpts), nelect / 2 - 1],
                 color='#800000',
                 alpha=0.6)
plt.fill_between(x,
Beispiel #5
0
def test_vasp_net_charge():
    """
    Run VASP tests to ensure that determining number of electrons from
    user-supplied net charge (via the deprecated net_charge parameter) works
    correctly. This is conditional on the existence of the VASP_COMMAND or
    VASP_SCRIPT environment variables.

    This is mainly a slightly reduced duplicate of the vasp_charge test, but with
    flipped signs and with checks that ensure FutureWarning is emitted.

    Should be removed along with the net_charge parameter itself at some point.
    """

    from ase.build import bulk
    from ase.calculators.vasp import Vasp
    from ase.test import must_raise, must_warn
    from ase.test.vasp import installed

    assert installed()

    system = bulk('Al', 'fcc', a=4.5, cubic=True)

    # Dummy calculation to let VASP determine default number of electrons
    calc = Vasp(xc='LDA', nsw=-1, ibrion=-1, nelm=1, lwave=False, lcharg=False)
    calc.calculate(system)
    default_nelect_from_vasp = calc.get_number_of_electrons()
    assert default_nelect_from_vasp == 12

    # Compare VASP's output nelect from before + net charge to default nelect
    # determined by us + net charge
    with must_warn(FutureWarning):
        net_charge = -2
        calc = Vasp(xc='LDA',
                    nsw=-1,
                    ibrion=-1,
                    nelm=1,
                    lwave=False,
                    lcharg=False,
                    net_charge=net_charge)
        calc.initialize(system)
        calc.write_input(system)
        calc.read_incar()
    assert calc.float_params['nelect'] == default_nelect_from_vasp + net_charge

    # Test that conflicts between explicitly given nelect and net charge are
    # detected
    with must_raise(ValueError):
        with must_warn(FutureWarning):
            calc = Vasp(xc='LDA',
                        nsw=-1,
                        ibrion=-1,
                        nelm=1,
                        lwave=False,
                        lcharg=False,
                        nelect=default_nelect_from_vasp + net_charge + 1,
                        net_charge=net_charge)
            calc.calculate(system)

    # Test that conflicts between charge and net_charge are detected
    with must_raise(ValueError):
        with must_warn(FutureWarning):
            calc = Vasp(xc='LDA',
                        nsw=-1,
                        ibrion=-1,
                        nelm=1,
                        lwave=False,
                        lcharg=False,
                        charge=-net_charge - 1,
                        net_charge=net_charge)
            calc.calculate(system)

    # Test that nothing is written if net charge is 0 and nelect not given
    with must_warn(FutureWarning):
        calc = Vasp(xc='LDA',
                    nsw=-1,
                    ibrion=-1,
                    nelm=1,
                    lwave=False,
                    lcharg=False,
                    net_charge=0)
        calc.initialize(system)
        calc.write_input(system)
        calc.read_incar()
    assert calc.float_params['nelect'] is None