本文整理汇总了Python中pymatgen.io.vasp.inputs.Potcar类的典型用法代码示例。如果您正苦于以下问题:Python Potcar类的具体用法?Python Potcar怎么用?Python Potcar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Potcar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_potcar
def set_potcar(self, mapping=None, functional='PBE'):
"""
set the potcar: symbol to potcar type mapping
"""
symbols = self.poscar.site_symbols
mapped_symbols = []
if mapping:
for sym in symbols:
mapped_symbols.append(mapping[sym])
elif self.mappings_override:
for sym in symbols:
if sym in self.mappings_override.keys():
mapped_symbols.append(self.mappings_override[sym])
else:
mapped_symbols.append(sym)
else:
mapped_symbols = symbols
if functional:
func=functional
else:
func=self.functional
self.potcar = Potcar(symbols=mapped_symbols,
functional=func)
pass
示例2: __init__
def __init__(self, name, incar, poscar, potcar, kpoints,
qadapter=None, **kwargs ):
"""
default INCAR from config_dict
"""
self.name = name
self.incar = Incar.from_dict(incar.as_dict())
self.poscar = Poscar.from_dict(poscar.as_dict())
self.potcar = Potcar.from_dict(potcar.as_dict())
self.kpoints = Kpoints.from_dict(kpoints.as_dict())
self.extra = kwargs
if qadapter is not None:
self.qadapter = qadapter.from_dict(qadapter.to_dict())
else:
self.qadapter = None
config_dict = {}
config_dict['INCAR'] = self.incar.as_dict()
config_dict['POSCAR'] = self.poscar.as_dict()
#caution the key and the value are not always the same
config_dict['POTCAR'] = self.potcar.as_dict()
#dict(zip(self.potcar.as_dict()['symbols'],
#self.potcar.as_dict()['symbols']))
config_dict['KPOINTS'] = self.kpoints.as_dict()
#self.user_incar_settings = self.incar.as_dict()
DictVaspInputSet.__init__(self, name, config_dict,
ediff_per_atom=False, **kwargs)
示例3: setup
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)
示例4: setUp
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)
示例5: from_dict
def from_dict(cls, d):
incar = Incar.from_dict(d["incar"])
poscar = Poscar.from_dict(d["poscar"])
potcar = Potcar.from_dict(d["potcar"])
kpoints = Kpoints.from_dict(d["kpoints"])
qadapter = None
if d["qadapter"] is not None:
qadapter = CommonAdapter.from_dict(d["qadapter"])
return MPINTVaspInputSet(d["name"], incar, poscar, potcar,
kpoints, qadapter, **d["kwargs"])
示例6: setUp
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)
示例7: from_dict
def from_dict(cls, d):
incar = Incar.from_dict(d["incar"])
poscar = Poscar.from_dict(d["poscar"])
potcar = Potcar.from_dict(d["potcar"])
kpoints = Kpoints.from_dict(d["kpoints"])
qadapter = None
if d["qadapter"] is not None:
qadapter = CommonAdapter.from_dict(d["qadapter"])
script_name = d["script_name"]
return MPINTVaspInputSet(d["name"], incar, poscar, potcar,
kpoints, qadapter,
script_name=script_name,
vis_logger=logging.getLogger(d["logger"]),
**d["kwargs"])
示例8: from_dict
def from_dict(cls, d):
incar = Incar.from_dict(d["incar"])
poscar = Poscar.from_dict(d["poscar"])
potcar = Potcar.from_dict(d["potcar"])
kpoints = Kpoints.from_dict(d["kpoints"])
cal = Calibrate(incar, poscar, potcar, kpoints,
system=d["system"], is_matrix = d["is_matrix"],
Grid_type = d["Grid_type"],
parent_job_dir=d["parent_job_dir"],
job_dir=d["job_dir"], qadapter=d.get("qadapter"),
job_cmd=d["job_cmd"], wait=d["wait"],
turn_knobs=d["turn_knobs"])
cal.job_dir_list = d["job_dir_list"]
cal.job_ids = d["job_ids"]
return cal
示例9: setUp
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)
示例10: __init__
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
示例11: bader_analysis_from_path
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)
示例12: __init__
def __init__(self, name, incar, poscar, kpoints, potcar=None,
qadapter=None, script_name='submit_script',
vis_logger=None, reuse_path=None, test=False,
**kwargs):
"""
default INCAR from config_dict
"""
self.name = name
self.test = test
self.incar_init = Incar.from_dict(incar.as_dict())
self.poscar_init = Poscar.from_dict(poscar.as_dict())
if not self.test:
self.potcar_init = Potcar.from_dict(potcar.as_dict())
if not isinstance(kpoints, str):
self.kpoints_init = Kpoints.from_dict(kpoints.as_dict())
else:
self.kpoints_init = kpoints
self.reuse_path = reuse_path # complete reuse paths
self.extra = kwargs
if qadapter is not None:
self.qadapter = qadapter.from_dict(qadapter.to_dict())
else:
self.qadapter = None
self.script_name = script_name
config_dict = {}
config_dict['INCAR'] = self.incar_init.as_dict()
config_dict['POSCAR'] = self.poscar_init.as_dict()
# caution the key and the value are not always the same
if not self.test:
config_dict['POTCAR'] = self.potcar_init.as_dict()
# dict(zip(self.potcar.as_dict()['symbols'],
# self.potcar.as_dict()['symbols']))
if not isinstance(kpoints, str):
config_dict['KPOINTS'] = self.kpoints_init.as_dict()
else:
# need to find a way to dictify this kpoints string more
# appropriately
config_dict['KPOINTS'] = {'kpts_hse':self.kpoints_init}
# self.user_incar_settings = self.incar.as_dict()
DictSet.__init__(self, poscar.structure, config_dict)
#**kwargs)
if vis_logger:
self.logger = vis_logger
else:
self.logger = logger
示例13: __init__
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))
#.........这里部分代码省略.........
示例14: test_write
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)
示例15: test_to_from_dict
def test_to_from_dict(self):
d = self.potcar.as_dict()
potcar = Potcar.from_dict(d)
self.assertEqual(potcar.symbols, ["Fe", "P", "O"])