本文整理汇总了Python中pymatgen.io.vaspio.Poscar.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Poscar.from_file方法的具体用法?Python Poscar.from_file怎么用?Python Poscar.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.io.vaspio.Poscar
的用法示例。
在下文中一共展示了Poscar.from_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _vasp_poscar_setup
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def _vasp_poscar_setup(self):
"""Set up the POSCAR file for a single VASP run.
"""
name = self.keywords['name']
pospath = os.path.join(name, "POSCAR")
if os.path.isfile(pospath):
my_poscar = Poscar.from_file(pospath)
#parent should have given a structure
else: #this is an originating run; mast should give it a structure
if self.keywords['structure'] is not None:
my_poscar = Poscar(self.keywords['structure'])
else:
pf = os.path.join(os.path.dirname(name),'POSCAR_%s'%os.path.basename(name))
if os.path.isfile(pf):
my_poscar = Poscar.from_file(pf)
workdir=os.path.dirname(name)
sdir=os.path.join(workdir,"structure_index_files")
if os.path.exists(sdir):
mystr=my_poscar.structure
manname="manifest___"
myatomindex=AtomIndex(structure_index_directory=sdir)
newstr=myatomindex.graft_new_coordinates_from_manifest(mystr, manname, "")
self.logger.info("Getting original coordinates from manifest.")
new_pos=Poscar(newstr)
my_poscar=new_pos
self.logger.info("No POSCAR found from a parent; base structure used for %s" % self.keywords['name'])
if 'mast_coordinates' in self.keywords['program_keys'].keys():
sxtend = StructureExtensions(struc_work1=my_poscar.structure, name=self.keywords['name'])
coordstrucs=self.get_coordinates_only_structure_from_input()
newstruc = sxtend.graft_coordinates_onto_structure(coordstrucs[0])
my_poscar.structure=newstruc.copy()
dirutil.lock_directory(name)
my_poscar.write_file(pospath)
dirutil.unlock_directory(name)
return my_poscar
示例2: checkrelax_single
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def checkrelax_single(path, src_ini="posfinal", src_fin="posfinal3"):
dirc = path
initial = Poscar.from_file(os.path.join(dirc, src_ini)).structure.as_dict()["lattice"]
final = Poscar.from_file(os.path.join(dirc, src_fin)).structure.as_dict()["lattice"]
length_a = final[u"a"] / initial[u"a"]
length_b = final[u"b"] / initial[u"b"]
length_c = final[u"c"] / initial[u"c"]
delta_length = ((length_b / length_a - 1) ** 2 + (length_c / length_a - 1) ** 2) ** 0.5
# print(delta_length)
angle_a = final["alpha"] / initial["alpha"] - 1
angle_b = final["beta"] / initial["beta"] - 1
angle_c = final["gamma"] / initial["gamma"] - 1
delta_angle = (angle_a ** 2 + angle_b ** 2 + angle_c ** 2) ** 0.5
# print(delta_angle)
return delta_length, delta_angle
示例3: supercell
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def supercell(poscar,scale,outFile=None,replace=False):
'''Reads in a structure in VASP POSCAR format and returns one with a supercell
of that structure
Args:
-------------------------------------
poscar: location of POSCAR file to find supercell of
scale: iterable of integer scaling factors with length 3.
kwargs:
-------------------------------------
outFile: location for new poscar file with
modifies:
-------------------------------------
outFile: if replace=True
poscar: if replace=False
'''
assert os.path.isfile(poscar)
assert replace==True or not outFile is None
p = Poscar.from_file(poscar,False)
# with open(poscar) as f:
# poscomment = f.readline().strip()
#
# p.comment = poscomment
p.structure.make_supercell(scale)
if replace==True:
p.write_file(poscar,vasp4_compatible=True)
else:
p.write_file(outFile,vasp4_compatible=True)
示例4: read_structure
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def read_structure(filename):
"""
Reads a structure based on file extension. For example, anything ending in
a "cif" is assumed to be a Crystallographic Information Format file.
Args:
filename:
A filename to read from.
Returns:
A Structure object.
"""
lower_filename = os.path.basename(filename).lower()
if re.search("\.cif", lower_filename):
parser = CifParser(filename)
return parser.get_structures(True)[0]
elif lower_filename.startswith("poscar") \
or lower_filename.startswith("contcar"):
return Poscar.from_file(filename, False).structure
elif lower_filename.startswith("chgcar") \
or lower_filename.startswith("locpot"):
return Chgcar.from_file(filename).structure
elif re.search("vasprun", lower_filename) \
and re.search("xml", lower_filename):
return Vasprun(filename).final_structure
elif re.search("\.cssr", lower_filename):
cssr = Cssr.from_file(filename)
return cssr.structure
raise ValueError("Unrecognized file extension!")
示例5: five
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def five(src="POSCAR"):
"""
ver5 に変換
"""
srcpos = Poscar.from_file(src)
dst = "POSCAR_five"
srcpos.write_file(dst)
示例6: test_init_from_structure
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def test_init_from_structure(self):
filepath = os.path.join(test_dir, "POSCAR")
poscar = Poscar.from_file(filepath)
struct = poscar.struct
xyz = XYZ(struct)
ans = """24
Fe4 P4 O16
Fe 2.277347 4.550379 2.260125
Fe 2.928536 1.516793 4.639870
Fe 7.483231 4.550379 0.119620
Fe 8.134420 1.516793 2.499364
P 0.985089 1.516793 1.990624
P 4.220794 4.550379 4.370369
P 6.190973 1.516793 0.389120
P 9.426677 4.550379 2.768865
O 0.451582 4.550379 3.365614
O 1.006219 1.516793 3.528306
O 1.725331 0.279529 1.358282
O 1.725331 2.754057 1.358282
O 3.480552 3.313115 3.738027
O 3.480552 5.787643 3.738027
O 4.199665 4.550379 1.148562
O 4.754301 1.516793 0.985870
O 5.657466 4.550379 3.773620
O 6.212102 1.516793 3.610928
O 6.931215 0.279529 1.021463
O 6.931215 2.754057 1.021463
O 8.686436 3.313115 3.401208
O 8.686436 5.787643 3.401208
O 9.405548 4.550379 1.231183
O 9.960184 1.516793 1.393875"""
self.assertEqual(str(xyz), ans)
示例7: set_structure_from_inputs
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def set_structure_from_inputs(self, input_options):
"""Make a pymatgen structure and update the
structure key.
Args:
input_options <InputOptions>
"""
strposfile = input_options.get_item('structure','posfile')
if strposfile is None:
iopscoords=input_options.get_item('structure','coordinates')
iopslatt=input_options.get_item('structure','lattice')
iopsatoms=input_options.get_item('structure','atom_list')
iopsctype=input_options.get_item('structure','coord_type')
structure = MAST2Structure(lattice=iopslatt,
coordinates=iopscoords, atom_list=iopsatoms,
coord_type=iopsctype)
elif ('poscar' in strposfile.lower()):
from pymatgen.io.vaspio import Poscar
structure = Poscar.from_file(strposfile).structure
elif ('cif' in strposfile.lower()):
from pymatgen.io.cifio import CifParser
structure = CifParser(strposfile).get_structures()[0]
else:
error = 'Cannot build structure from file %s' % strposfile
raise MASTError(self.__class__.__name__, error)
input_options.update_item('structure','structure',structure)
if input_options.get_item('structure','use_structure_index') in ['True','true','T','t']:
self.do_structure_indexing(input_options)
return
示例8: read_structure
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def read_structure(filename):
"""
Reads a structure based on file extension. For example, anything ending in
a "cif" is assumed to be a Crystallographic Information Format file.
Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT,
vasprun.xml, CSSR and pymatgen's JSON serialized structures.
Args:
filename (str): A filename to read from.
Returns:
A Structure object.
"""
fname = os.path.basename(filename)
if fnmatch(fname.lower(), "*.cif*"):
parser = CifParser(filename)
return parser.get_structures(True)[0]
elif fnmatch(fname, "POSCAR*") or fnmatch(fname, "CONTCAR*"):
return Poscar.from_file(filename, False).structure
elif fnmatch(fname, "CHGCAR*") or fnmatch(fname, "LOCPOT*"):
return Chgcar.from_file(filename).structure
elif fnmatch(fname, "vasprun*.xml*"):
return Vasprun(filename).final_structure
elif fnmatch(fname.lower(), "*.cssr*"):
cssr = Cssr.from_file(filename)
return cssr.structure
elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"):
with zopen(filename) as f:
s = json.load(f, cls=PMGJSONDecoder)
if type(s) != Structure:
raise IOError("File does not contain a valid serialized "
"structure")
return s
raise ValueError("Unrecognized file extension!")
示例9: get_structure_from_file
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def get_structure_from_file(self, myfilepath=""):
"""Get the structure from a specified file path.
For VASP, this is a POSCAR-type file.
Args:
myfilepath <str>: File path for structure.
"""
return Poscar.from_file(myfilepath).structure
示例10: print_spg
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def print_spg(src="POSCAR"):
srcpos = Poscar.from_file(src)
finder = SpacegroupAnalyzer(srcpos.structure, symprec=5e-2, angle_tolerance=8)
spg = finder.get_spacegroup_symbol()
spg_num = finder.get_spacegroup_number()
print(spg)
print(spg_num)
示例11: setUp
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def setUp(self):
filepath = os.path.join(test_dir, 'POSCAR')
poscar = Poscar.from_file(filepath)
self.struct = poscar.struct
self.mitparamset = MITVaspInputSet()
self.mithseparamset = MITHSEVaspInputSet()
self.paramset = MaterialsProjectVaspInputSet()
示例12: get_elements
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def get_elements(src):
"""
組成比を得るための method
"""
srcpos = Poscar.from_file(src)
elements = [x.symbol for x in srcpos.structure.species]
elem_counter = Counter(elements)
return elem_counter
示例13: get_primitive
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def get_primitive(fname):
poscar = Poscar.from_file(fname)
finder = SymmetryFinder(poscar.structure)
spg_num = finder.get_spacegroup_number()
primitive = finder.get_primitive_standard_structure()
return spg_num, primitive
示例14: test_get_atoms
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def test_get_atoms(self):
if not aio.ase_loaded:
raise SkipTest("ASE not present. Skipping...")
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
structure = p.struct
atoms = aio.AseAtomsAdaptor.get_atoms(structure)
ase_composition = Composition.from_formula(atoms.get_name())
self.assertEqual(ase_composition, structure.composition)
示例15: test_to_from_dict
# 需要导入模块: from pymatgen.io.vaspio import Poscar [as 别名]
# 或者: from pymatgen.io.vaspio.Poscar import from_file [as 别名]
def test_to_from_dict(self):
json_str = json.dumps(PartialRemoveSpecieTransformation("Li+", 0.5, PartialRemoveSpecieTransformation.ALGO_BEST_FIRST).to_dict)
t = transformation_from_json(json_str)
module_dir = os.path.dirname(os.path.abspath(__file__))
p = Poscar.from_file(os.path.join(module_dir, 'POSCAR.LiFePO4'))
t1 = OxidationStateDecorationTransformation({"Li":1, "Fe":2, "P":5, "O":-2})
s = t1.apply_transformation(p.struct)
self.assertEqual(len(t.apply_transformation(s)), 26)