コード例 #1
0
ファイル: vasp_xml.py プロジェクト: rosswhitfield/ase
def main():
    if sys.version_info < (2, 7):
        raise NotAvailable('read_xml requires Python version 2.7 or greater')

    assert installed()

    # simple test calculation of CO molecule
    d = 1.14
    co = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)],
               pbc=True)
    co.center(vacuum=5.)

    calc = Vasp(xc='PBE',
                prec='Low',
                algo='Fast',
                ismear=0,
                sigma=1.,
                istart=0,
                lwave=False,
                lcharg=False)

    co.set_calculator(calc)
    energy = co.get_potential_energy()
    forces = co.get_forces()

    # check that parsing of vasprun.xml file works
    conf = read('vasprun.xml')
    assert conf.calc.parameters['kpoints_generation']
    assert conf.calc.parameters['sigma'] == 1.0
    assert conf.calc.parameters['ialgo'] == 68
    assert energy - conf.get_potential_energy() == 0.0
    assert array_almost_equal(conf.get_forces(), forces, tol=1e-4)

    # Cleanup
    calc.clean()
コード例 #2
0
def test_vasp_co():
    """
    Run some VASP tests to ensure that the VASP calculator works. This
    is conditional on the existence of the VASP_COMMAND or VASP_SCRIPT
    environment variables

    """

    from ase.test.vasp import installed

    assert installed()

    from ase import Atoms
    from ase.io import write
    from ase.calculators.vasp import Vasp
    import numpy as np

    def array_almost_equal(a1, a2, tol=np.finfo(type(1.0)).eps):
        """Replacement for old numpy.testing.utils.array_almost_equal."""
        return (np.abs(a1 - a2) < tol).all()

    d = 1.14
    co = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)], pbc=True)
    co.center(vacuum=5.)

    calc = Vasp(xc='PBE',
                prec='Low',
                algo='Fast',
                ismear=0,
                sigma=1.,
                istart=0,
                lwave=False,
                lcharg=False)

    co.calc = calc
    en = co.get_potential_energy()
    write('vasp_co.traj', co)
    assert abs(en + 14.918933) < 5e-3

    # Secondly, check that restart from the previously created VASP output works

    calc2 = Vasp(restart=True)
    co2 = calc2.get_atoms()

    # Need tolerance of 1e-14 because VASP itself changes coordinates
    # slightly between reading POSCAR and writing CONTCAR even if no ionic
    # steps are made.
    assert array_almost_equal(co.positions, co2.positions, 1e-14)

    assert en - co2.get_potential_energy() == 0.
    assert array_almost_equal(calc.get_stress(co), calc2.get_stress(co2))
    assert array_almost_equal(calc.get_forces(co), calc2.get_forces(co2))
    assert array_almost_equal(calc.get_eigenvalues(), calc2.get_eigenvalues())
    assert calc.get_number_of_bands() == calc2.get_number_of_bands()
    assert calc.get_xc_functional() == calc2.get_xc_functional()

    # Cleanup
    calc.clean()
コード例 #3
0
ファイル: vasp_xml.py プロジェクト: btodac/ase
def main():
    if sys.version_info < (2, 7):
        raise NotAvailable('read_xml requires Python version 2.7 or greater')

    assert installed()

    # simple test calculation of CO molecule
    d = 1.14
    co = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)],
               pbc=True)
    co.center(vacuum=5.)

    calc = Vasp(xc='LDA',
                prec='Low',
                algo='Fast',
                ismear=0,
                sigma=1.,
                nbands=12,
                istart=0,
                nelm=3,
                lwave=False,
                lcharg=False,
                ldipol=True)

    co.set_calculator(calc)
    energy = co.get_potential_energy()
    forces = co.get_forces()
    dipole_moment = co.get_dipole_moment()

    # check that parsing of vasprun.xml file works
    conf = read('vasprun.xml')
    assert conf.calc.parameters['kpoints_generation']
    assert conf.calc.parameters['sigma'] == 1.0
    assert conf.calc.parameters['ialgo'] == 68
    assert energy - conf.get_potential_energy() == 0.0

    # Check some arrays
    assert np.allclose(conf.get_forces(), forces)
    assert np.allclose(conf.get_dipole_moment(), dipole_moment, atol=1e-6)

    # Check k-point-dependent properties
    assert len(conf.calc.get_eigenvalues(spin=0)) >= 12
    assert conf.calc.get_occupation_numbers()[2] == 2
    assert conf.calc.get_eigenvalues(spin=1) is None
    kpt = conf.calc.get_kpt(0)
    assert kpt.weight == 1.

    # Perform a spin-polarised calculation
    co.calc.set(ispin=2, ibrion=-1)
    co.get_potential_energy()
    conf = read('vasprun.xml')
    assert len(conf.calc.get_eigenvalues(spin=1)) >= 12
    assert conf.calc.get_occupation_numbers(spin=1)[0] == 1.

    # Cleanup
    calc.clean()
コード例 #4
0
ファイル: parcalc.py プロジェクト: digideskio/Elastic
 def clean(self):
     with work_dir(self.working_dir) :
         Vasp.clean(self)
コード例 #5
0
ファイル: parcalc.py プロジェクト: wenlibin02/Elastic
 def clean(self):
     with work_dir(self.working_dir):
         Vasp.clean(self)
コード例 #6
0
ファイル: vasp_co.py プロジェクト: JConwayAWT/PGSS14CC
            algo = 'Fast',
            ismear= 0,
            sigma = 1.,
            istart = 0,
            lwave = False,
            lcharg = False)

co.set_calculator(calc)
en = co.get_potential_energy()
assert abs(en + 14.918933) < 1e-4

# Secondly, check that restart from the previously created VASP output works

calc2 = Vasp(restart=True)
co2 = calc2.get_atoms()

# Need tolerance of 1e-14 because VASP itself changes coordinates
# slightly between reading POSCAR and writing CONTCAR even if no ionic
# steps are made.
assert array_almost_equal(co.positions, co2.positions, 1e-14)

assert en - co2.get_potential_energy() == 0.
assert array_almost_equal(calc.get_stress(co), calc2.get_stress(co2))
assert array_almost_equal(calc.get_forces(co), calc2.get_forces(co2))
assert array_almost_equal(calc.get_eigenvalues(), calc2.get_eigenvalues())
assert calc.get_number_of_bands() == calc2.get_number_of_bands()
assert calc.get_xc_functional() == calc2.get_xc_functional()

# Cleanup
calc.clean()
コード例 #7
0
Al = bulk('Al', 'fcc', a=4.5, cubic=True)


def check_kpoints_line(n, contents):
    """Assert the contents of a line"""
    with open('KPOINTS', 'r') as f:
        lines = f.readlines()
        assert lines[n] == contents

# Default to (1 1 1)

calc = Vasp(gamma=True)
calc.write_kpoints()
check_kpoints_line(2, 'Gamma\n')
check_kpoints_line(3, '1 1 1 \n')
calc.clean()

# 3-tuple prints mesh
calc = Vasp(gamma=False, kpts=(4, 4, 4))
calc.write_kpoints()
check_kpoints_line(2, 'Monkhorst-Pack\n')
check_kpoints_line(3, '4 4 4 \n')
calc.clean()

# Auto mode
calc = Vasp(kpts=20)
calc.write_kpoints()
check_kpoints_line(1, '0\n')
check_kpoints_line(2, 'Auto\n')
check_kpoints_line(3, '20 \n')
calc.clean()
コード例 #8
0
def test_vasp_kpoints():
    """

    Check the many ways of specifying KPOINTS

    """

    import os
    import filecmp

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

    assert installed()

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

    def check_kpoints_line(n, contents):
        """Assert the contents of a line"""
        with open('KPOINTS', 'r') as f:
            lines = f.readlines()
            assert lines[n] == contents

    # Default to (1 1 1)

    calc = Vasp(gamma=True)
    calc.write_kpoints()
    check_kpoints_line(2, 'Gamma\n')
    check_kpoints_line(3, '1 1 1 \n')
    calc.clean()

    # 3-tuple prints mesh
    calc = Vasp(gamma=False, kpts=(4, 4, 4))
    calc.write_kpoints()
    check_kpoints_line(2, 'Monkhorst-Pack\n')
    check_kpoints_line(3, '4 4 4 \n')
    calc.clean()

    # Auto mode
    calc = Vasp(kpts=20)
    calc.write_kpoints()
    check_kpoints_line(1, '0\n')
    check_kpoints_line(2, 'Auto\n')
    check_kpoints_line(3, '20 \n')
    calc.clean()

    # 1-element list ok, Gamma ok
    calc = Vasp(kpts=[20], gamma=True)
    calc.write_kpoints()
    check_kpoints_line(1, '0\n')
    check_kpoints_line(2, 'Auto\n')
    check_kpoints_line(3, '20 \n')
    calc.clean()

    # KSPACING suppresses KPOINTS file
    calc = Vasp(kspacing=0.23)
    calc.initialize(Al)
    calc.write_kpoints()
    calc.write_incar(Al)
    assert not os.path.isfile('KPOINTS')
    with open('INCAR', 'r') as f:
        assert ' KSPACING = 0.230000\n' in f.readlines()
    calc.clean()

    # Negative KSPACING raises an error
    calc = Vasp(kspacing=-0.5)

    try:
        calc.write_kpoints()
    except ValueError:
        pass
    else:
        raise AssertionError("Negative KSPACING did not raise ValueError")
    calc.clean()

    # Explicit weighted points with nested lists, Cartesian if not specified
    calc = Vasp(
        kpts=[[0.1, 0.2, 0.3, 2], [0.0, 0.0, 0.0, 1], [0.0, 0.5, 0.5, 2]])
    calc.write_kpoints()

    with open('KPOINTS.ref', 'w') as f:
        f.write("""KPOINTS created by Atomic Simulation Environment
    3 
    Cartesian
    0.100000 0.200000 0.300000 2.000000 
    0.000000 0.000000 0.000000 1.000000 
    0.000000 0.500000 0.500000 2.000000 
    """)

    assert filecmp.cmp('KPOINTS', 'KPOINTS.ref')
    os.remove('KPOINTS.ref')

    # Explicit points as list of tuples, automatic weighting = 1.
    calc = Vasp(kpts=[(0.1, 0.2, 0.3), (0.0, 0.0, 0.0), (0.0, 0.5, 0.5)],
                reciprocal=True)
    calc.write_kpoints()

    with open('KPOINTS.ref', 'w') as f:
        f.write("""KPOINTS created by Atomic Simulation Environment
    3 
    Reciprocal
    0.100000 0.200000 0.300000 1.0 
    0.000000 0.000000 0.000000 1.0 
    0.000000 0.500000 0.500000 1.0 
    """)

    assert filecmp.cmp('KPOINTS', 'KPOINTS.ref')
    os.remove('KPOINTS.ref')