本文整理汇总了Python中pymatgen.io.vasp.inputs.Poscar.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Poscar.from_file方法的具体用法?Python Poscar.from_file怎么用?Python Poscar.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.io.vasp.inputs.Poscar
的用法示例。
在下文中一共展示了Poscar.from_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar 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 Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def setUp(self):
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.Li2O'),
check_for_POTCAR=False)
s1 = p.structure
p = Poscar.from_file(os.path.join(test_dir, 'CONTCAR.Li2O'),
check_for_POTCAR=False)
s2 = p.structure
self.analyzer = RelaxationAnalyzer(s1, s2)
示例3: test_write
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def test_write(self):
filepath = os.path.join(test_dir, "POSCAR")
poscar = Poscar.from_file(filepath)
tempfname = "POSCAR.testing"
poscar.write_file(tempfname)
p = Poscar.from_file(tempfname)
self.assertArrayAlmostEqual(poscar.structure.lattice.abc, p.structure.lattice.abc, 5)
os.remove(tempfname)
示例4: test_write
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def test_write(self):
filepath = self.TEST_FILES_DIR / 'POSCAR'
poscar = Poscar.from_file(filepath)
tempfname = Path("POSCAR.testing")
poscar.write_file(tempfname)
p = Poscar.from_file(tempfname)
self.assertArrayAlmostEqual(poscar.structure.lattice.abc,
p.structure.lattice.abc, 5)
tempfname.unlink()
示例5: test_write_MD_poscar
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def test_write_MD_poscar(self):
# Parsing from an MD type run with velocities and predictor corrector data
# And writing a new POSCAR from the new structure
p = Poscar.from_file(os.path.join(test_dir, "CONTCAR.MD"), check_for_POTCAR=False)
tempfname = "POSCAR.testing"
p.write_file(tempfname)
p3 = Poscar.from_file(tempfname)
self.assertArrayAlmostEqual(p.structure.lattice.abc, p3.structure.lattice.abc, 5)
self.assertArrayAlmostEqual(p.velocities, p3.velocities, 5)
self.assertArrayAlmostEqual(p.predictor_corrector, p3.predictor_corrector, 5)
self.assertEqual(p.predictor_corrector_preamble, p3.predictor_corrector_preamble)
os.remove(tempfname)
示例6: setUp
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def setUp(self):
file_path = os.path.join(test_dir, 'POSCAR')
poscar = Poscar.from_file(file_path)
self.struct = poscar.structure
self.mvl_npt_set = MVLNPTMDSet(self.struct, start_temp=0,
end_temp=300, nsteps=1000)
warnings.simplefilter("ignore")
示例7: test_apply_transformation
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def test_apply_transformation(self):
enum_trans = EnumerateStructureTransformation(refine_structure=True)
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
check_for_POTCAR=False)
struct = p.structure
expected_ans = [1, 3, 1]
for i, frac in enumerate([0.25, 0.5, 0.75]):
trans = SubstitutionTransformation({'Fe': {'Fe': frac}})
s = trans.apply_transformation(struct)
oxitrans = OxidationStateDecorationTransformation(
{'Li': 1, 'Fe': 2, 'P': 5, 'O': -2})
s = oxitrans.apply_transformation(s)
alls = enum_trans.apply_transformation(s, 100)
self.assertEqual(len(alls), expected_ans[i])
self.assertIsInstance(trans.apply_transformation(s), Structure)
for s in alls:
self.assertIn("energy", s)
#make sure it works for non-oxidation state decorated structure
trans = SubstitutionTransformation({'Fe': {'Fe': 0.5}})
s = trans.apply_transformation(struct)
alls = enum_trans.apply_transformation(s, 100)
self.assertEqual(len(alls), 3)
self.assertIsInstance(trans.apply_transformation(s), Structure)
for s in alls:
self.assertNotIn("energy", s)
示例8: test_static_constructors
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def test_static_constructors(self):
kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0])
self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
self.assertEqual(kpoints.kpts, [[3, 3, 3]])
kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
self.assertEqual(kpoints.style, Kpoints.supported_modes.Monkhorst)
self.assertEqual(kpoints.kpts, [[2, 2, 2]])
kpoints = Kpoints.automatic(100)
self.assertEqual(kpoints.style, Kpoints.supported_modes.Automatic)
self.assertEqual(kpoints.kpts, [[100]])
filepath = os.path.join(test_dir, "POSCAR")
poscar = Poscar.from_file(filepath)
kpoints = Kpoints.automatic_density(poscar.structure, 500)
self.assertEqual(kpoints.kpts, [[2, 4, 4]])
self.assertEqual(kpoints.style, Kpoints.supported_modes.Monkhorst)
kpoints = Kpoints.automatic_density(poscar.structure, 500, True)
self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000)
self.assertEqual(kpoints.kpts, [[6, 11, 13]])
self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
s = poscar.structure
s.make_supercell(3)
kpoints = Kpoints.automatic_density(s, 500)
self.assertEqual(kpoints.kpts, [[1, 1, 1]])
self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
示例9: set_sd_flags
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def set_sd_flags(poscar_input=None, n_layers=2, top=True, bottom=True,
poscar_output='POSCAR2'):
"""
set the relaxation flags for top and bottom layers of interface.
The upper and lower bounds of the z coordinate are determined
based on the slab.
Args:
poscar_input: input poscar file name
n_layers: number of layers to be relaxed
top: whether n_layers from top are be relaxed
bottom: whether n_layers from bottom are be relaxed
poscar_output: output poscar file name
Returns:
None
writes the modified poscar file
"""
poscar1 = Poscar.from_file(poscar_input)
sd_flags = np.zeros_like(poscar1.structure.frac_coords)
z_coords = poscar1.structure.frac_coords[:, 2]
z_lower_bound, z_upper_bound = None, None
if bottom:
z_lower_bound = np.unique(z_coords)[n_layers - 1]
sd_flags[np.where(z_coords <= z_lower_bound)] = np.ones((1, 3))
if top:
z_upper_bound = np.unique(z_coords)[-n_layers]
sd_flags[np.where(z_coords >= z_upper_bound)] = np.ones((1, 3))
poscar2 = Poscar(poscar1.structure, selective_dynamics=sd_flags.tolist())
poscar2.write_file(filename=poscar_output)
示例10: test_apply_transformation
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def test_apply_transformation(self):
trans = MagOrderingTransformation({"Fe": 5})
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
check_for_POTCAR=False)
s = p.structure
alls = trans.apply_transformation(s, 10)
self.assertEqual(len(alls), 3)
f = SpacegroupAnalyzer(alls[0]["structure"], 0.1)
self.assertEqual(f.get_space_group_number(), 31)
model = IsingModel(5, 5)
trans = MagOrderingTransformation({"Fe": 5},
energy_model=model)
alls2 = trans.apply_transformation(s, 10)
# Ising model with +J penalizes similar neighbor magmom.
self.assertNotEqual(alls[0]["structure"], alls2[0]["structure"])
self.assertEqual(alls[0]["structure"], alls2[2]["structure"])
s = self.get_structure('Li2O')
# Li2O doesn't have magnetism of course, but this is to test the
# enumeration.
trans = MagOrderingTransformation({"Li+": 1}, max_cell_size=3)
alls = trans.apply_transformation(s, 100)
# TODO: check this is correct, unclear what len(alls) should be
self.assertEqual(len(alls), 12)
trans = MagOrderingTransformation({"Ni": 5})
alls = trans.apply_transformation(self.NiO.get_primitive_structure(),
return_ranked_list=10)
self.assertEqual(self.NiO_AFM_111.lattice, alls[0]["structure"].lattice)
self.assertEqual(self.NiO_AFM_001.lattice, alls[1]["structure"].lattice)
示例11: test_from_md_run
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def test_from_md_run(self):
#Parsing from an MD type run with velocities
p = Poscar.from_file(os.path.join(test_dir, "CONTCAR.MD"),
check_for_POTCAR=False)
self.assertAlmostEqual(np.sum(np.array(p.velocities)), 0.0065417961324)
self.assertEqual(p.predictor_corrector[0][0], 1)
self.assertEqual(p.predictor_corrector[1][0], 2)
示例12: read_poscar
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def read_poscar(i_path, l_get_sorted_symbols=False):
poscar = Poscar.from_file("{}".format(i_path))
struct = poscar.structure
if l_get_sorted_symbols:
return struct, poscar.site_symbols
else:
return struct
示例13: run_task
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def run_task(self, fw_spec):
chgcar_start = False
# read the VaspInput from the previous run
poscar = Poscar.from_file(zpath('POSCAR'))
incar = Incar.from_file(zpath('INCAR'))
# figure out what GGA+U values to use and override them
# LDAU values to use
mpvis = MPVaspInputSet()
ggau_incar = mpvis.get_incar(poscar.structure).as_dict()
incar_updates = {k: ggau_incar[k] for k in ggau_incar.keys() if 'LDAU' in k}
for k in ggau_incar:
# update any parameters not set explicitly in previous INCAR
if k not in incar and k in ggau_incar:
incar_updates[k] = ggau_incar[k]
incar.update(incar_updates) # override the +U keys
# start from the CHGCAR of previous run
if os.path.exists('CHGCAR'):
incar['ICHARG'] = 1
chgcar_start = True
# write back the new INCAR to the current directory
incar.write_file('INCAR')
return FWAction(stored_data={'chgcar_start': chgcar_start})
示例14: test_ferrimagnetic
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def test_ferrimagnetic(self):
trans = MagOrderingTransformation({"Fe": 5}, 0.75, max_cell_size=1)
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
check_for_POTCAR=False)
s = p.structure
alls = trans.apply_transformation(s, 10)
self.assertEqual(len(alls), 2)
示例15: setUp
# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_file [as 别名]
def setUp(self):
if "VASP_PSP_DIR" not in os.environ:
os.environ["VASP_PSP_DIR"] = test_dir
filepath = os.path.join(test_dir, 'POSCAR')
poscar = Poscar.from_file(filepath)
self.struct = poscar.structure
self.mitparamset = MITVaspInputSet()
self.mitparamset_unsorted = MITVaspInputSet(sort_structure=False)
self.mithseparamset = MITHSEVaspInputSet()
self.paramset = MPVaspInputSet()
self.userparamset = MPVaspInputSet(
user_incar_settings={'MAGMOM': {"Fe": 10, "S": -5, "Mn3+": 100}}
)
self.mitggaparam = MITGGAVaspInputSet()
self.mpstaticparamset = MPStaticVaspInputSet()
self.mpnscfparamsetu = MPNonSCFVaspInputSet(
{"NBANDS": 50}, mode="Uniform")
self.mpnscfparamsetl = MPNonSCFVaspInputSet(
{"NBANDS": 60}, mode="Line")
self.mphseparamset = MPHSEVaspInputSet()
self.mpbshseparamsetl = MPBSHSEVaspInputSet(mode="Line")
self.mpbshseparamsetu = MPBSHSEVaspInputSet(
mode="Uniform", added_kpoints=[[0.5, 0.5, 0.0]])
self.mpdielparamset = MPStaticDielectricDFPTVaspInputSet()