本文整理汇总了Python中pylada.vasp.Vasp.istart方法的典型用法代码示例。如果您正苦于以下问题:Python Vasp.istart方法的具体用法?Python Vasp.istart怎么用?Python Vasp.istart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylada.vasp.Vasp
的用法示例。
在下文中一共展示了Vasp.istart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_istart
# 需要导入模块: from pylada.vasp import Vasp [as 别名]
# 或者: from pylada.vasp.Vasp import istart [as 别名]
def test_istart():
from time import sleep
from collections import namedtuple
from pickle import loads, dumps
from os import remove, makedirs
from os.path import join, exists
from shutil import rmtree
from tempfile import mkdtemp
from pylada.vasp.files import WAVECAR
from pylada.vasp import Vasp
from pylada.misc import Changedir
Extract = namedtuple("Extract", ['directory', 'success'])
a = Vasp()
o = a._input['istart']
d = {'IStart': o.__class__}
directory = mkdtemp()
if directory in ['/tmp/test', '/tmp/test/']:
if exists(directory): rmtree(directory)
makedirs(directory)
try:
assert a.istart == 'auto'
assert o.output_map(vasp=a, outdir=directory)['istart'] == '0'
assert eval(repr(o), d).value == 'auto'
assert loads(dumps(o)).value == 'auto'
restartdir = join(directory, 'restart')
with Changedir(restartdir) as pwd: pass
with open(join(restartdir, WAVECAR), 'w') as file: file.write('hello')
# do not copy if not successful
a.restart = Extract(restartdir, False)
assert o.output_map(vasp=a, outdir=directory)['istart'] == '0'
assert not exists(join(directory, 'WAVECAR'))
# do not copy if file is empty
a.restart = Extract(restartdir, True)
with open(join(restartdir, WAVECAR), 'w') as file: pass
assert o.output_map(vasp=a, outdir=directory)['istart'] == '0'
assert not exists(join(directory, 'WAVECAR'))
# now should copy
assert a.istart == 'auto'
with open(join(restartdir, WAVECAR), 'w') as file: file.write('hello')
assert o.output_map(vasp=a, outdir=directory)['istart'] == '1'
assert exists(join(directory, 'WAVECAR'))
# check it copies only latest file.
with open(join(restartdir, WAVECAR), 'w') as file:
file.write('hello')
file.flush()
with open(join(restartdir, WAVECAR), 'r') as file: pass
sleep(1.5)
with open(join(directory, WAVECAR), 'w') as file: file.write('hello world')
with open(join(directory, WAVECAR), 'r') as file: pass
assert o.output_map(vasp=a, outdir=directory)['istart'] == '1'
assert exists(join(directory, 'WAVECAR'))
with open(join(directory, WAVECAR), 'r') as file:
assert file.read().rstrip().lstrip() == 'hello world'
sleep(0.2)
with open(join(restartdir, WAVECAR), 'w') as file: file.write('hello')
assert o.output_map(vasp=a, outdir=directory)['istart'] == '1'
assert exists(join(directory, 'WAVECAR'))
with open(join(directory, WAVECAR), 'r') as file:
assert file.read().rstrip().lstrip() == 'hello'
# check if scratch is required
remove(join(directory, WAVECAR))
a.istart = 'scratch'
assert a.istart == 'scratch'
assert o.output_map(vasp=a, outdir=directory)['istart'] == '0'
assert eval(repr(o), d).value == 'scratch'
assert loads(dumps(o)).value == 'scratch'
finally:
if directory not in ['/tmp/test', '/tmp/test/'] and exists(directory):
rmtree(directory)
示例2: test_istart
# 需要导入模块: from pylada.vasp import Vasp [as 别名]
# 或者: from pylada.vasp.Vasp import istart [as 别名]
def test_istart():
from time import sleep
from collections import namedtuple
from pickle import loads, dumps
from os import remove, makedirs
from os.path import join, exists
from shutil import rmtree
from tempfile import mkdtemp
from pylada.vasp.files import WAVECAR
from pylada.vasp import Vasp
from pylada.misc import Changedir
Extract = namedtuple("Extract", ["directory", "success"])
a = Vasp()
o = a._input["istart"]
d = {"IStart": o.__class__}
directory = mkdtemp()
if directory in ["/tmp/test", "/tmp/test/"]:
if exists(directory):
rmtree(directory)
makedirs(directory)
try:
assert a.istart == "auto"
assert o.output_map(vasp=a, outdir=directory)["istart"] == "0"
assert eval(repr(o), d).value == "auto"
assert loads(dumps(o)).value == "auto"
restartdir = join(directory, "restart")
with Changedir(restartdir) as pwd:
pass
with open(join(restartdir, WAVECAR), "w") as file:
file.write("hello")
# do not copy if not successful
a.restart = Extract(restartdir, False)
assert o.output_map(vasp=a, outdir=directory)["istart"] == "0"
assert not exists(join(directory, "WAVECAR"))
# do not copy if file is empty
a.restart = Extract(restartdir, True)
with open(join(restartdir, WAVECAR), "w") as file:
pass
assert o.output_map(vasp=a, outdir=directory)["istart"] == "0"
assert not exists(join(directory, "WAVECAR"))
# now should copy
assert a.istart == "auto"
with open(join(restartdir, WAVECAR), "w") as file:
file.write("hello")
assert o.output_map(vasp=a, outdir=directory)["istart"] == "1"
assert exists(join(directory, "WAVECAR"))
# check it copies only latest file.
with open(join(restartdir, WAVECAR), "w") as file:
file.write("hello")
file.flush()
with open(join(restartdir, WAVECAR), "r") as file:
pass
sleep(1.5)
with open(join(directory, WAVECAR), "w") as file:
file.write("hello world")
with open(join(directory, WAVECAR), "r") as file:
pass
assert o.output_map(vasp=a, outdir=directory)["istart"] == "1"
assert exists(join(directory, "WAVECAR"))
with open(join(directory, WAVECAR), "r") as file:
assert file.read().rstrip().lstrip() == "hello world"
sleep(0.2)
with open(join(restartdir, WAVECAR), "w") as file:
file.write("hello")
assert o.output_map(vasp=a, outdir=directory)["istart"] == "1"
assert exists(join(directory, "WAVECAR"))
with open(join(directory, WAVECAR), "r") as file:
assert file.read().rstrip().lstrip() == "hello"
# check if scratch is required
remove(join(directory, WAVECAR))
a.istart = "scratch"
assert a.istart == "scratch"
assert o.output_map(vasp=a, outdir=directory)["istart"] == "0"
assert eval(repr(o), d).value == "scratch"
assert loads(dumps(o)).value == "scratch"
finally:
if directory not in ["/tmp/test", "/tmp/test/"] and exists(directory):
rmtree(directory)