本文整理汇总了Python中pymatgen.io.vasp.inputs.Potcar.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Potcar.from_file方法的具体用法?Python Potcar.from_file怎么用?Python Potcar.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.io.vasp.inputs.Potcar
的用法示例。
在下文中一共展示了Potcar.from_file方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def setup(self):
"""
setup static jobs for all the calibrate objects
copies CONTCAR to POSCAR
sets NSW = 0
"""
for cal in self.cal_objs:
for i, jdir in enumerate(cal.old_job_dir_list):
job_dir = self.job_dir + os.sep \
+ jdir.replace(os.sep, '_').replace('.', '_') \
+ os.sep + 'STATIC'
logger.info('setting up job in {}'.format(job_dir))
cal.incar = Incar.from_file(jdir + os.sep + 'INCAR')
cal.incar['EDIFF'] = '1E-6'
cal.incar['NSW'] = 0
cal.potcar = Potcar.from_file(jdir + os.sep + 'POTCAR')
cal.kpoints = Kpoints.from_file(jdir + os.sep + 'KPOINTS')
contcar_file = jdir + os.sep + 'CONTCAR'
if os.path.isfile(contcar_file):
logger.info('setting poscar file from {}'
.format(contcar_file))
cal.poscar = Poscar.from_file(contcar_file)
cal.add_job(job_dir=job_dir)
else:
logger.critical("""CONTCAR doesnt exist.
Setting up job using input set in the old
calibration directory""")
cal.poscar = Poscar.from_file(jdir + os.sep + 'POSCAR')
cal.add_job(job_dir=job_dir)
示例2: setUp
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def setUp(self):
if "PMG_VASP_PSP_DIR" not in os.environ:
test_potcar_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..", "..", "..",
"test_files"))
os.environ["PMG_VASP_PSP_DIR"] = test_potcar_dir
filepath = os.path.join(test_dir, 'POTCAR')
self.potcar = Potcar.from_file(filepath)
示例3: setUp
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def setUp(self):
filepath = self.TEST_FILES_DIR / 'INCAR'
incar = Incar.from_file(filepath)
filepath = self.TEST_FILES_DIR / 'POSCAR'
poscar = Poscar.from_file(filepath,check_for_POTCAR=False)
if "PMG_VASP_PSP_DIR" not in os.environ:
os.environ["PMG_VASP_PSP_DIR"] = str(self.TEST_FILES_DIR)
filepath = self.TEST_FILES_DIR / 'POTCAR'
potcar = Potcar.from_file(filepath)
filepath = self.TEST_FILES_DIR / 'KPOINTS.auto'
kpoints = Kpoints.from_file(filepath)
self.vinput = VaspInput(incar, kpoints, poscar, potcar)
示例4: setUp
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def setUp(self):
filepath = os.path.join(test_dir, "INCAR")
incar = Incar.from_file(filepath)
filepath = os.path.join(test_dir, "POSCAR")
poscar = Poscar.from_file(filepath)
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")
potcar = Potcar.from_file(filepath)
filepath = os.path.join(test_dir, "KPOINTS.auto")
kpoints = Kpoints.from_file(filepath)
self.vinput = VaspInput(incar, kpoints, poscar, potcar)
示例5: bader_analysis_from_path
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def bader_analysis_from_path(path, suffix=''):
"""
Convenience method to run Bader analysis on a folder containing
typical VASP output files.
This method will:
1. Look for files CHGCAR, AECAR0, AECAR2, POTCAR or their gzipped
counterparts.
2. If AECCAR* files are present, constructs a temporary reference
file as AECCAR0 + AECCAR2
3. Runs Bader analysis twice: once for charge, and a second time
for the charge difference (magnetization density).
:param path: path to folder to search in
:param suffix: specific suffix to look for (e.g. '.relax1' for 'CHGCAR.relax1.gz'
:return: summary dict
"""
def _get_filepath(filename, warning, path=path, suffix=suffix):
paths = glob.glob(os.path.join(path, filename + suffix + '*'))
if not paths:
warnings.warn(warning)
return None
if len(paths) > 1:
# using reverse=True because, if multiple files are present,
# they likely have suffixes 'static', 'relax', 'relax2', etc.
# and this would give 'static' over 'relax2' over 'relax'
# however, better to use 'suffix' kwarg to avoid this!
paths.sort(reverse=True)
warnings.warn('Multiple files detected, using {}'.format(os.path.basename(path)))
path = paths[0]
return path
chgcar_path = _get_filepath('CHGCAR', 'Could not find CHGCAR!')
chgcar = Chgcar.from_file(chgcar_path)
aeccar0_path = _get_filepath('AECCAR0', 'Could not find AECCAR0, interpret Bader results with caution.')
aeccar0 = Chgcar.from_file(aeccar0_path) if aeccar0_path else None
aeccar2_path = _get_filepath('AECCAR2', 'Could not find AECCAR2, interpret Bader results with caution.')
aeccar2 = Chgcar.from_file(aeccar2_path) if aeccar2_path else None
potcar_path = _get_filepath('POTCAR', 'Could not find POTCAR, cannot calculate charge transfer.')
potcar = Potcar.from_file(potcar_path) if potcar_path else None
return bader_analysis_from_objects(chgcar, potcar, aeccar0, aeccar2)
示例6: __init__
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def __init__(self, chgcar_filename, potcar_filename=None):
"""
Initializes the Bader caller.
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.
"""
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
chgcarpath = os.path.abspath(chgcar_filename)
with ScratchDir(".") as temp_dir:
shutil.copy(chgcarpath, os.path.join(temp_dir, "CHGCAR"))
rs = subprocess.Popen(["bader", "CHGCAR"],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE, close_fds=True)
rs.communicate()
if rs.returncode != 0:
raise RuntimeError("bader exited with return code %d. "
"Pls check your bader installation."
% rs.returncode)
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
示例7: test_write
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.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)
示例8: setUp
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def setUp(self):
self.potcar = Potcar.from_file(test_dir+"/POTCAR")
self.zval_dict = {'Ba': 10.0, 'Ti': 10.0, 'O': 6.0}
self.ions = ions
self.structures = structures
示例9: assimilate
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.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
示例10: test_write
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def test_write(self):
tempfname = Path("POTCAR.testing")
self.potcar.write_file(tempfname)
p = Potcar.from_file(tempfname)
self.assertEqual(p.symbols, self.potcar.symbols)
tempfname.unlink()
示例11: __init__
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Potcar import from_file [as 别名]
def __init__(self, chgcar_filename, potcar_filename=None,
chgref_filename=None, parse_atomic_densities=False):
"""
Initializes the Bader caller.
Args:
chgcar_filename (str): The filename of the CHGCAR.
potcar_filename (str): 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.
chgref_filename (str): Optional. The filename of the reference
CHGCAR, which calculated by AECCAR0 + AECCAR2. (See
http://theory.cm.utexas.edu/henkelman/code/bader/ for details.)
parse_atomic_densities (bool): Optional. turns on atomic partition of the charge density
charge densities are atom centered
"""
if not BADEREXE:
raise RuntimeError(
"BaderAnalysis requires the executable bader to be in the path."
" Please download the library at http://theory.cm.utexas"
".edu/vasp/bader/ and compile the executable.")
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
chgcarpath = os.path.abspath(chgcar_filename)
chgrefpath = os.path.abspath(chgref_filename) if chgref_filename else None
self.reference_used = True if chgref_filename else False
self.parse_atomic_densities = parse_atomic_densities
with ScratchDir(".") as temp_dir:
with zopen(chgcarpath, 'rt') as f_in:
with open("CHGCAR", "wt") as f_out:
shutil.copyfileobj(f_in, f_out)
args = [BADEREXE, "CHGCAR"]
if chgref_filename:
with zopen(chgrefpath, 'rt') as f_in:
with open("CHGCAR_ref", "wt") as f_out:
shutil.copyfileobj(f_in, f_out)
args += ['-ref', 'CHGCAR_ref']
if parse_atomic_densities:
args += ['-p', 'all_atom']
rs = subprocess.Popen(args,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE, close_fds=True)
stdout, stderr = rs.communicate()
if rs.returncode != 0:
raise RuntimeError("bader exited with return code %d. "
"Please check your bader installation."
% rs.returncode)
try:
self.version = float(stdout.split()[5])
except:
self.version = -1 # Unknown
if self.version < 1.0:
warnings.warn('Your installed version of Bader is outdated, '
'calculation of vacuum charge may be incorrect.')
data = []
with open("ACF.dat") as f:
raw = f.readlines()
headers = ('x', 'y', 'z', 'charge', 'min_dist', 'atomic_vol')
raw.pop(0)
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, 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
if self.parse_atomic_densities:
# convert the charge denisty for each atom spit out by Bader into Chgcar objects for easy parsing
atom_chgcars = [Chgcar.from_file("BvAt{}.dat".format(str(i).zfill(4))) for i in
range(1, len(self.chgcar.structure) + 1)]
atomic_densities = []
# For each atom in the structure
for atom, loc, chg in zip(self.chgcar.structure,
self.chgcar.structure.frac_coords,
atom_chgcars):
# Find the index of the atom in the charge density atom
index = np.round(np.multiply(loc, chg.dim))
data = chg.data['total']
# Find the shift vector in the array
shift = (np.divide(chg.dim, 2) - index).astype(int)
# Shift the data so that the atomic charge density to the center for easier manipulation
shifted_data = np.roll(data, shift, axis=(0, 1, 2))
#.........这里部分代码省略.........
示例12: assimilate
# 需要导入模块: from pymatgen.io.vasp.inputs import Potcar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.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 = sorted(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:
# Since multiple files are ambiguous, we will always
# use the first one for POSCAR and the last one
# alphabetically for CONTCAR and OSZICAR.
if filename == "POSCAR":
files_to_parse[filename] = files[0]
else:
files_to_parse[filename] = files[-1]
warnings.warn(
"%d files found. %s is being parsed." %
(len(files), files_to_parse[filename]))
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