本文整理汇总了Python中pymatgen.io.vaspio.vasp_input.Potcar.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Potcar.from_file方法的具体用法?Python Potcar.from_file怎么用?Python Potcar.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.io.vaspio.vasp_input.Potcar
的用法示例。
在下文中一共展示了Potcar.from_file方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from pymatgen.io.vaspio.vasp_input import Potcar [as 别名]
# 或者: from pymatgen.io.vaspio.vasp_input.Potcar import from_file [as 别名]
def setUp(self):
if "VASP_PSP_DIR" not in os.environ:
test_potcar_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "test_files")
)
os.environ["VASP_PSP_DIR"] = test_potcar_dir
filepath = os.path.join(test_dir, "POTCAR")
self.potcar = Potcar.from_file(filepath)
示例2: __init__
# 需要导入模块: from pymatgen.io.vaspio.vasp_input import Potcar [as 别名]
# 或者: from pymatgen.io.vaspio.vasp_input.Potcar import from_file [as 别名]
def __init__(self, chgcar_filename, potcar_filename=None):
"""
Args:
chgcar_filename:
The filename of the CHGCAR.
potcar_filename:
Optional: the filename of the corresponding POTCAR file. Used
for calculating the charge transfer. If None, the
get_charge_transfer method will raise a ValueError.
"""
temp_dir = tempfile.mkdtemp()
self.chgcar = Chgcar.from_file(chgcar_filename)
self.potcar = Potcar.from_file(potcar_filename) \
if potcar_filename is not None else None
self.natoms = self.chgcar.poscar.natoms
try:
shutil.copy(chgcar_filename, os.path.join(temp_dir, "CHGCAR"))
current_dir = os.getcwd()
os.chdir(temp_dir)
rs = subprocess.Popen(["bader", "CHGCAR"],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE, close_fds=True)
rs.communicate()
data = []
with open("ACF.dat") as f:
raw = f.readlines()
headers = [s.lower() for s in raw.pop(0).split()]
raw.pop(0)
while True:
l = raw.pop(0).strip()
if l.startswith("-"):
break
vals = map(float, l.split()[1:])
data.append(dict(zip(headers[1:], vals)))
for l in raw:
toks = l.strip().split(":")
if toks[0] == "VACUUM CHARGE":
self.vacuum_charge = float(toks[1])
elif toks[0] == "VACUUM VOLUME":
self.vacuum_volume = float(toks[1])
elif toks[0] == "NUMBER OF ELECTRONS":
self.nelectrons = float(toks[1])
self.data = data
os.chdir(current_dir)
except Exception as ex:
print str(ex)
finally:
shutil.rmtree(temp_dir)
示例3: buildPOTCAR
# 需要导入模块: from pymatgen.io.vaspio.vasp_input import Potcar [as 别名]
# 或者: from pymatgen.io.vaspio.vasp_input.Potcar import from_file [as 别名]
def buildPOTCAR(atname, fpotcar="POTCAR"):
"""
Build POTCAR file according to atom for wich CL calculation is required. The POTCAR of
the atom is placed in first postion.
"""
from pymatgen.io.vaspio.vasp_input import Potcar
potcar = Potcar.from_file(fpotcar)
add = False
for pot in potcar:
if pot.symbol == atname:
newpot = pot
add = True
break
if not add:
print("Atom " + atname + " not found in POTCAR")
exit(1)
else:
potcar.insert(0, newpot)
potcar.write_file("POTCAR_CL")
示例4: assimilate
# 需要导入模块: from pymatgen.io.vaspio.vasp_input import Potcar [as 别名]
# 或者: from pymatgen.io.vaspio.vasp_input.Potcar import from_file [as 别名]
def assimilate(self, path):
files = os.listdir(path)
try:
files_to_parse = {}
if "relax1" in files and "relax2" in files:
for filename in ("INCAR", "POTCAR", "POSCAR"):
search_str = os.path.join(path, "relax1", filename + "*")
files_to_parse[filename] = glob.glob(search_str)[0]
for filename in ("CONTCAR", "OSZICAR"):
search_str = os.path.join(path, "relax2", filename + "*")
files_to_parse[filename] = glob.glob(search_str)[-1]
else:
files_to_parse["INCAR"] = glob.glob(os.path.join(path,
"INCAR*"))[0]
files_to_parse["POTCAR"] = glob.glob(
os.path.join(path, "POTCAR*"))[-1]
for filename in ("CONTCAR", "OSZICAR", "POSCAR"):
files = glob.glob(os.path.join(path, filename + "*"))
if len(files) == 1:
files_to_parse[filename] = files[0]
elif len(files) > 1:
"""
This is a bit confusing, since there maybe be
multiple steps. By default, assimilate will try to find
a file simply named filename, filename.bz2, or
filename.gz. Failing which it will try to get a relax2
from an aflow style run if possible. Or else, a
randomly chosen file is chosen.
"""
for fname in files:
if fnmatch.fnmatch(os.path.basename(fname),
"{}(\.gz|\.bz2)*"
.format(filename)):
files_to_parse[filename] = fname
break
if fname == "POSCAR" and \
re.search("relax1", fname):
files_to_parse[filename] = fname
break
if (fname in ("CONTCAR", "OSZICAR") and
re.search("relax2", fname)):
files_to_parse[filename] = fname
break
files_to_parse[filename] = fname
poscar = Poscar.from_file(files_to_parse["POSCAR"])
contcar = Poscar.from_file(files_to_parse["CONTCAR"])
param = {}
incar = Incar.from_file(files_to_parse["INCAR"])
if "LDAUU" in incar:
param["hubbards"] = dict(zip(poscar.site_symbols,
incar["LDAUU"]))
else:
param["hubbards"] = {}
param["is_hubbard"] = \
incar.get("LDAU", False) and sum(param["hubbards"].values()) > 0
param["run_type"] = "GGA+U" if param["is_hubbard"] else "GGA"
potcar = Potcar.from_file(files_to_parse["POTCAR"])
param["potcar_symbols"] = potcar.symbols
oszicar = Oszicar(files_to_parse["OSZICAR"])
energy = oszicar.final_energy
structure = contcar.structure
initial_vol = poscar.structure.volume
final_vol = contcar.structure.volume
delta_volume = (final_vol / initial_vol - 1)
data = {"filename": path, "delta_volume": delta_volume}
if self._inc_structure:
entry = ComputedStructureEntry(structure, energy,
parameters=param,
data=data)
else:
entry = ComputedEntry(structure.composition, energy,
parameters=param, data=data)
return entry
except Exception as ex:
logger.debug("error in {}: {}".format(path, ex))
return None
示例5: test_write
# 需要导入模块: from pymatgen.io.vaspio.vasp_input import Potcar [as 别名]
# 或者: from pymatgen.io.vaspio.vasp_input.Potcar import from_file [as 别名]
def test_write(self):
tempfname = "POTCAR.testing"
self.potcar.write_file(tempfname)
p = Potcar.from_file(tempfname)
self.assertEqual(p.symbols, self.potcar.symbols)
os.remove(tempfname)
示例6: assimilate
# 需要导入模块: from pymatgen.io.vaspio.vasp_input import Potcar [as 别名]
# 或者: from pymatgen.io.vaspio.vasp_input.Potcar import from_file [as 别名]
def assimilate(self, path):
files = os.listdir(path)
try:
files_to_parse = {}
if "relax1" in files and "relax2" in files:
for filename in ("INCAR", "POTCAR", "POSCAR"):
search_str = os.path.join(path, "relax1", filename + "*")
files_to_parse[filename] = glob.glob(search_str)[0]
for filename in ("CONTCAR", "OSZICAR"):
search_str = os.path.join(path, "relax2", filename + "*")
files_to_parse[filename] = glob.glob(search_str)[-1]
else:
for filename in (
"INCAR", "POTCAR", "CONTCAR", "OSZICAR", "POSCAR", "DYNMAT"
):
files = glob.glob(os.path.join(path, filename + "*"))
if len(files) < 1:
continue
if len(files) == 1 or filename == "INCAR" or \
filename == "POTCAR" or filename == "DYNMAT":
files_to_parse[filename] = files[-1]\
if filename == "POTCAR" else files[0]
elif len(files) > 1:
"""
This is a bit confusing, since there maybe be
multiple steps. By default, assimilate will try to find
a file simply named filename, filename.bz2, or
filename.gz. Failing which it will try to get a relax2
from a custodian double relaxation style run if
possible. Or else, a random file is chosen.
"""
for fname in files:
if fnmatch.fnmatch(os.path.basename(fname),
"{}(\.gz|\.bz2)*"
.format(filename)):
files_to_parse[filename] = fname
break
if fname == "POSCAR" and \
re.search("relax1", fname):
files_to_parse[filename] = fname
break
if (fname in ("CONTCAR", "OSZICAR") and
re.search("relax2", fname)):
files_to_parse[filename] = fname
break
files_to_parse[filename] = fname
poscar, contcar, incar, potcar, oszicar, dynmat = [None]*6
if 'POSCAR' in files_to_parse:
poscar = Poscar.from_file(files_to_parse["POSCAR"])
if 'CONTCAR' in files_to_parse:
contcar = Poscar.from_file(files_to_parse["CONTCAR"])
if 'INCAR' in files_to_parse:
incar = Incar.from_file(files_to_parse["INCAR"])
if 'POTCAR' in files_to_parse:
potcar = Potcar.from_file(files_to_parse["POTCAR"])
if 'OSZICAR' in files_to_parse:
oszicar = Oszicar(files_to_parse["OSZICAR"])
if 'DYNMAT' in files_to_parse:
dynmat = Dynmat(files_to_parse["DYNMAT"])
param = {"hubbards":{}}
if poscar is not None and incar is not None and "LDAUU" in incar:
param["hubbards"] = dict(zip(poscar.site_symbols,
incar["LDAUU"]))
param["is_hubbard"] = (
incar.get("LDAU", False) and sum(param["hubbards"].values()) > 0
) if incar is not None else False
param["run_type"] = None
if incar is not None:
param["run_type"] = "GGA+U" if param["is_hubbard"] else "GGA"
param["history"] = _get_transformation_history(path)
param["potcar_spec"] = potcar.spec if potcar is not None else None
energy = oszicar.final_energy if oszicar is not None else 1e10
structure = contcar.structure if contcar is not None\
else poscar.structure
initial_vol = poscar.structure.volume if poscar is not None else \
None
final_vol = contcar.structure.volume if contcar is not None else \
None
delta_volume = None
if initial_vol is not None and final_vol is not None:
delta_volume = (final_vol / initial_vol - 1)
data = {"filename": path, "delta_volume": delta_volume}
if dynmat is not None:
data['phonon_frequencies'] = dynmat.get_phonon_frequencies()
if self._inc_structure:
entry = ComputedStructureEntry(
structure, energy, parameters=param, data=data
)
else:
entry = ComputedEntry(
structure.composition, energy, parameters=param, data=data
)
return entry
except Exception as ex:
logger.debug("error in {}: {}".format(path, ex))
return None