Пример #1
0
def test_incar():
  from shutil import rmtree
  from tempfile import mkdtemp
  from os.path import join, dirname
  from quantities import eV
  from pylada.vasp import Vasp, read_incar
  from pylada.crystal import Structure
  structure = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.43, name='has a name')\
                       .add_atom(0,0,0, "Si")\
                       .add_atom(0.25,0.25,0.25, "Si")

  vasp = Vasp()
  vasp.kpoints    = "Automatic generation\n0\nMonkhorst\n2 2 2\n0 0 0"
  vasp.precision  = "accurate"
  vasp.ediff      = 1e-5
  vasp.encut      = 1
  vasp.ismear     = "metal"
  vasp.sigma      = 0.06
  vasp.relaxation = "volume"
  vasp.add_specie = "Si", join(dirname(__file__), 'pseudos', 'Si')

  directory = mkdtemp()
  try: 
    vasp.write_incar(path=join(directory, 'INCAR'), structure=structure)
    other = read_incar(join(directory, 'INCAR'))
    assert abs(other.ediff - 1e-5)  < 1e-8
    assert abs(other.encut - 245.345) < 1e-8
    assert abs(other.sigma - 0.06 * eV) < 1e-8
    assert other.ibrion     == 2
    assert other.icharg     == 'atomic'
    assert other.isif       == 7
    assert other.ismear     == 'metal'
    assert other.istart     == 'scratch'
    assert other.lcharg     == False
    assert other.nsw        == 50
    assert other.relaxation == 'volume'
    assert other.system     == 'has a name'
    with open(join(directory, 'INCAR'), 'a') as file:
      file.write('\nSOMETHing = 0.5\n')
    other = read_incar(join(directory, 'INCAR'))
    assert abs(other.ediff - 1e-5)  < 1e-8
    assert abs(other.encut - 245.345) < 1e-8
    assert abs(other.sigma - 0.06 * eV) < 1e-8
    assert other.ibrion     == 2
    assert other.icharg     == 'atomic'
    assert other.isif       == 7
    assert other.ismear     == 'metal'
    assert other.istart     == 'scratch'
    assert other.lcharg     == False
    assert other.nsw        == 50
    assert other.relaxation == 'volume'
    assert other.system     == 'has a name'
    assert 'something' in other._input
    assert isinstance(other.something, float)
    assert abs(other.something - 0.5) < 1e-8
  finally: 
    rmtree(directory)
    pass
Пример #2
0
def test(path):
  from shutil import rmtree
  from tempfile import mkdtemp
  from os.path import join
  from quantities import eV
  from pylada.vasp import Vasp, read_incar
  from pylada.crystal import Structure
  structure = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.43, name='has a name')\
                       .add_atom(0,0,0, "Si")\
                       .add_atom(0.25,0.25,0.25, "Si")

  vasp = Vasp()
  vasp.kpoints    = "Automatic generation\n0\nMonkhorst\n2 2 2\n0 0 0"
  vasp.precision  = "accurate"
  vasp.ediff      = 1e-5
  vasp.encut      = 1
  vasp.ismear     = "metal"
  vasp.sigma      = 0.06
  vasp.relaxation = "volume"
  vasp.add_specie = "Si", "{0}/pseudos/Si".format(path)

  directory = mkdtemp()
  try: 
    vasp.write_incar(path=join(directory, 'INCAR'), structure=structure)
    other = read_incar(join(directory, 'INCAR'))
    assert abs(other.ediff - 1e-5)  < 1e-8
    assert abs(other.encut - 245.345) < 1e-8
    assert abs(other.sigma - 0.06 * eV) < 1e-8
    assert other.ibrion     == 2
    assert other.icharg     == 'atomic'
    assert other.isif       == 7
    assert other.ismear     == 'metal'
    assert other.istart     == 'scratch'
    assert other.lcharg     == False
    assert other.nsw        == 50
    assert other.relaxation == 'volume'
    assert other.system     == 'has a name'
    with open(join(directory, 'INCAR'), 'a') as file:
      file.write('\nSOMETHing = 0.5\n')
    other = read_incar(join(directory, 'INCAR'))
    assert abs(other.ediff - 1e-5)  < 1e-8
    assert abs(other.encut - 245.345) < 1e-8
    assert abs(other.sigma - 0.06 * eV) < 1e-8
    assert other.ibrion     == 2
    assert other.icharg     == 'atomic'
    assert other.isif       == 7
    assert other.ismear     == 'metal'
    assert other.istart     == 'scratch'
    assert other.lcharg     == False
    assert other.nsw        == 50
    assert other.relaxation == 'volume'
    assert other.system     == 'has a name'
    assert 'something' in other._input
    assert isinstance(other.something, float)
    assert abs(other.something - 0.5) < 1e-8
  finally: 
    rmtree(directory)
    pass
Пример #3
0
def getincar(incar):
	from pylada.vasp import read_incar
	vasp = read_incar(incar)
	@tools.layer
	def new(job):
		@tools.cellcall(job.params["call"])
		def func(job):
			job.params['vasp'] = vasp
		job.params["call"] = func
		yield job
	return new
Пример #4
0
def test_read_from_incar_with_unknowns_params(tmpdir, vasp, structure):
    from pylada.vasp import read_incar
    vasp.write_incar(path=str(tmpdir.join('INCAR')), structure=structure)
    with open(str(tmpdir.join('INCAR')), 'a') as file:
        file.write('\nSOMETHing = 0.5\n')

    other = read_incar(str(tmpdir.join('INCAR')))
    check_vasp(other)
    assert 'something' in other._input
    assert isinstance(other.something, float)
    assert abs(other.something - 0.5) < 1e-8
Пример #5
0
def test_read_from_incar_with_unknowns_params(tmpdir, vasp, structure):
    from pylada.vasp import read_incar

    vasp.write_incar(path=str(tmpdir.join("INCAR")), structure=structure)
    with open(str(tmpdir.join("INCAR")), "a") as file:
        file.write("\nSOMETHing = 0.5\n")

    other = read_incar(str(tmpdir.join("INCAR")))
    check_vasp(other)
    assert "something" in other._input
    assert isinstance(other.something, float)
    assert abs(other.something - 0.5) < 1e-8
Пример #6
0
def compute(outdir, common, **kwargs):
    from pylada.vasp import read_incar
    from pylada.crystal import read
    import os
    structure = read.poscar(kwargs["poscar"])
    vasp = read_incar(kwargs["incar"])

    for pot in kwargs["potcar"]:
        vasp.add_specie = pot.split("_")[0], os.path.join(
            os.environ["PAW"], pot)
    if "writechg" in kwargs.keys():
        vasp.lcharg = kwargs["writechg"]
    else:
        vasp.lcharg = True
    if "writewave" in kwargs.keys():
        vasp.lwave = kwargs["writewave"]
    else:
        vasp.lwave = True
    if "writeoptics" in kwargs.keys():
        vasp.loptics = kwargs["writeoptics"]
    else:
        vasp.loptics = False
    if "optcell" in kwargs.keys():
        if kwargs["optcell"] is not None:
            writeoptcell(outdir, kwargs["optcell"])
    if "chgcar" in kwargs.keys():
        copyorlinkfile(outdir, "CHGCAR", kwargs["chgcar"], "cp")
    if "wavecar" in kwargs.keys():
        copyorlinkfile(outdir, "WAVECAR", kwargs["wavecar"], "cp")
    if "dfile" in kwargs.keys():
        if not os.path.exists(os.path.join(outdir, "DFILE")):
            with open(os.path.join(outdir, "DFILE"), "w") as f:
                f.write(kwargs["dfile"])
    if "kpointscell" in kwargs.keys():
        import numpy as np
        kpoint = "Automatic generation\n0\nMonkhorst\n%d %d %d\n0 0 0"
        diag = np.diag(structure.cell)
        tmp = np.array(kwargs["kpointscell"]) // diag
        tmp[tmp == 0] = 1
        vasp.kpoints = kpoint % (tuple(tmp))
    else:
        if hasattr(vasp, "kspacing"):
            vasp.write_kpoints = nowritekpoints
        else:
            with open(kwargs["kpoints"], "r") as rfile:
                vasp.kpoints = rfile.read()
    try:
        result = vasp(structure, outdir=outdir, comm=common)
    except Exception as e:
        print("path:" + outdir)
        raise e
    return result
Пример #7
0
def vasp(name, incar):
	"""
		return a function to set a new vasp form incar
		@param inputlayer : a function created by front layer
		@param names : layer name
		@param incar : path of incar for loading
	"""
	from pylada.vasp import read_incar
	vasp = read_incar(incar)
	@tools.layer
	def new(job):
		@tools.cellcall(job.params["call"])
		def func(job):
			job.params["vasp"] = vasp
		t_job = job / name
		t_job.params["call"] = func
		return [t_job]
	return new
Пример #8
0
def test(path):
    from shutil import rmtree
    from tempfile import mkdtemp
    from os.path import join
    from quantities import eV
    from pylada.vasp import Vasp, read_incar
    from pylada.crystal import Structure

    structure = (
        Structure([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.43, name="has a name")
        .add_atom(0, 0, 0, "Si")
        .add_atom(0.25, 0.25, 0.25, "Si")
    )

    vasp = Vasp()
    vasp.kpoints = "Automatic generation\n0\nMonkhorst\n2 2 2\n0 0 0"
    vasp.precision = "accurate"
    vasp.ediff = 1e-5
    vasp.encut = 1
    vasp.ismear = "metal"
    vasp.sigma = 0.06
    vasp.relaxation = "volume"
    vasp.add_specie = "Si", "{0}/pseudos/Si".format(path)

    directory = mkdtemp()
    try:
        vasp.write_incar(path=join(directory, "INCAR"), structure=structure)
        other = read_incar(join(directory, "INCAR"))
        assert abs(other.ediff - 1e-5) < 1e-8
        assert abs(other.encut - 245.345) < 1e-8
        assert abs(other.sigma - 0.06 * eV) < 1e-8
        assert other.ibrion == 2
        assert other.icharg == "atomic"
        assert other.isif == 7
        assert other.ismear == "metal"
        assert other.istart == "scratch"
        assert other.lcharg == False
        assert other.nsw == 50
        assert other.relaxation == "volume"
        assert other.system == "has a name"
        with open(join(directory, "INCAR"), "a") as file:
            file.write("\nSOMETHing = 0.5\n")
        other = read_incar(join(directory, "INCAR"))
        assert abs(other.ediff - 1e-5) < 1e-8
        assert abs(other.encut - 245.345) < 1e-8
        assert abs(other.sigma - 0.06 * eV) < 1e-8
        assert other.ibrion == 2
        assert other.icharg == "atomic"
        assert other.isif == 7
        assert other.ismear == "metal"
        assert other.istart == "scratch"
        assert other.lcharg == False
        assert other.nsw == 50
        assert other.relaxation == "volume"
        assert other.system == "has a name"
        assert "something" in other._input
        assert isinstance(other.something, float)
        assert abs(other.something - 0.5) < 1e-8
    finally:
        rmtree(directory)
        pass
Пример #9
0
def test_read_from_incar(tmpdir, vasp, structure):
    from pylada.vasp import read_incar
    vasp.write_incar(path=str(tmpdir.join('INCAR')), structure=structure)
    other = read_incar(str(tmpdir.join('INCAR')))
    check_vasp(other)
Пример #10
0
def test_read_from_incar(tmpdir, vasp, structure):
    from pylada.vasp import read_incar

    vasp.write_incar(path=str(tmpdir.join("INCAR")), structure=structure)
    other = read_incar(str(tmpdir.join("INCAR")))
    check_vasp(other)