本文整理汇总了Python中pylada.vasp.Vasp.icharg方法的典型用法代码示例。如果您正苦于以下问题:Python Vasp.icharg方法的具体用法?Python Vasp.icharg怎么用?Python Vasp.icharg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylada.vasp.Vasp
的用法示例。
在下文中一共展示了Vasp.icharg方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_icharg
# 需要导入模块: from pylada.vasp import Vasp [as 别名]
# 或者: from pylada.vasp.Vasp import icharg [as 别名]
def test_icharg():
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, CHGCAR
from pylada.vasp import Vasp
from pylada.misc import Changedir
from pylada.error import ValueError
Extract = namedtuple("Extract", ['directory', 'success'])
a = Vasp()
o = a._input['icharg']
d = {'ICharg': o.__class__}
directory = mkdtemp()
if directory in ['/tmp/test', '/tmp/test/']:
if exists(directory): rmtree(directory)
makedirs(directory)
try:
assert a.icharg == 'auto'
assert o.output_map(vasp=a, outdir=directory)['icharg'] == '2'
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, CHGCAR), 'w') as file: file.write('hello')
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)['icharg'] == '2'
assert not exists(join(directory, CHGCAR))
assert not exists(join(directory, WAVECAR))
# do not copy if empty
with open(join(restartdir, CHGCAR), 'w') as file: pass
with open(join(restartdir, WAVECAR), 'w') as file: pass
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)['icharg'] == '2'
assert not exists(join(directory, CHGCAR))
assert not exists(join(directory, WAVECAR))
# now copy only CHGCAR
with open(join(restartdir, CHGCAR), 'w') as file: file.write('hello')
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)['icharg'] == '1'
assert exists(join(directory, CHGCAR))
assert not exists(join(directory, WAVECAR))
remove(join(directory, CHGCAR))
# now copy only CHGCAR with scf
a.nonscf = True
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)['icharg'] == '11'
assert exists(join(directory, CHGCAR))
assert not exists(join(directory, WAVECAR))
remove(join(directory, CHGCAR))
# now copy both
a.nonscf = False
with open(join(restartdir, WAVECAR), 'w') as file: file.write('hello')
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)['icharg'] == '0'
assert exists(join(directory, CHGCAR))
assert exists(join(directory, WAVECAR))
# now copy both with scf
a.nonscf = True
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)['icharg'] == '10'
assert exists(join(directory, CHGCAR))
assert exists(join(directory, WAVECAR))
# now check that latest is copied
remove(join(restartdir, CHGCAR))
remove(join(directory, CHGCAR))
sleep(1.2)
with open(join(directory, WAVECAR), 'w') as file: file.write('hello world')
with open(join(directory, WAVECAR), 'r') as file: pass # Buffering issues..
a.nonscf = False
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)['icharg'] == '0'
assert exists(join(directory, WAVECAR))
with open(join(directory, WAVECAR), 'r') as file:
assert file.read().rstrip().lstrip() == 'hello world'
with open(join(directory, WAVECAR), 'r') as file:
assert file.read().rstrip().lstrip() != 'hello'
with open(join(restartdir, WAVECAR), 'w') as file: file.write('hello')
assert o.output_map(vasp=a, outdir=directory)['icharg'] == '0'
assert exists(join(directory, WAVECAR))
with open(join(directory, WAVECAR), 'r') as file:
assert file.read().rstrip().lstrip() == 'hello'
with open(join(directory, WAVECAR), 'r') as file:
assert file.read().rstrip().lstrip() != 'hello world'
#.........这里部分代码省略.........
示例2: test_icharg
# 需要导入模块: from pylada.vasp import Vasp [as 别名]
# 或者: from pylada.vasp.Vasp import icharg [as 别名]
def test_icharg():
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, CHGCAR
from pylada.vasp import Vasp
from pylada.misc import Changedir
from pylada.error import ValueError
Extract = namedtuple("Extract", ["directory", "success"])
a = Vasp()
o = a._input["icharg"]
d = {"ICharg": o.__class__}
directory = mkdtemp()
if directory in ["/tmp/test", "/tmp/test/"]:
if exists(directory):
rmtree(directory)
makedirs(directory)
try:
assert a.icharg == "auto"
assert o.output_map(vasp=a, outdir=directory)["icharg"] == "2"
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, CHGCAR), "w") as file:
file.write("hello")
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)["icharg"] == "2"
assert not exists(join(directory, CHGCAR))
assert not exists(join(directory, WAVECAR))
# do not copy if empty
with open(join(restartdir, CHGCAR), "w") as file:
pass
with open(join(restartdir, WAVECAR), "w") as file:
pass
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)["icharg"] == "2"
assert not exists(join(directory, CHGCAR))
assert not exists(join(directory, WAVECAR))
# now copy only CHGCAR
with open(join(restartdir, CHGCAR), "w") as file:
file.write("hello")
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)["icharg"] == "1"
assert exists(join(directory, CHGCAR))
assert not exists(join(directory, WAVECAR))
remove(join(directory, CHGCAR))
# now copy only CHGCAR with scf
a.nonscf = True
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)["icharg"] == "11"
assert exists(join(directory, CHGCAR))
assert not exists(join(directory, WAVECAR))
remove(join(directory, CHGCAR))
# now copy both
a.nonscf = False
with open(join(restartdir, WAVECAR), "w") as file:
file.write("hello")
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)["icharg"] == "0"
assert exists(join(directory, CHGCAR))
assert exists(join(directory, WAVECAR))
# now copy both with scf
a.nonscf = True
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)["icharg"] == "10"
assert exists(join(directory, CHGCAR))
assert exists(join(directory, WAVECAR))
# now check that latest is copied
remove(join(restartdir, CHGCAR))
remove(join(directory, CHGCAR))
sleep(1.2)
with open(join(directory, WAVECAR), "w") as file:
file.write("hello world")
with open(join(directory, WAVECAR), "r") as file:
pass # Buffering issues..
a.nonscf = False
a.restart = Extract(restartdir, True)
assert o.output_map(vasp=a, outdir=directory)["icharg"] == "0"
assert exists(join(directory, WAVECAR))
with open(join(directory, WAVECAR), "r") as file:
assert file.read().rstrip().lstrip() == "hello world"
with open(join(directory, WAVECAR), "r") as file:
#.........这里部分代码省略.........