本文整理汇总了Python中pymatgen.Structure.to方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.to方法的具体用法?Python Structure.to怎么用?Python Structure.to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.Structure
的用法示例。
在下文中一共展示了Structure.to方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: constrained_opt_run
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import to [as 别名]
def constrained_opt_run(cls, vasp_cmd, lattice_direction, initial_strain,
atom_relax=True, max_steps=20, algo="bfgs",
**vasp_job_kwargs):
"""
Returns a generator of jobs for a constrained optimization run. Typical
use case is when you want to approximate a biaxial strain situation,
e.g., you apply a defined strain to a and b directions of the lattice,
but allows the c-direction to relax.
Some guidelines on the use of this method:
i. It is recommended you do not use the Auto kpoint generation. The
grid generated via Auto may fluctuate with changes in lattice
param, resulting in numerical noise.
ii. Make sure your EDIFF/EDIFFG is properly set in your INCAR. The
optimization relies on these values to determine convergence.
Args:
vasp_cmd (str): Command to run vasp as a list of args. For example,
if you are using mpirun, it can be something like
["mpirun", "pvasp.5.2.11"]
lattice_direction (str): Which direction to relax. Valid values are
"a", "b" or "c".
initial_strain (float): An initial strain to be applied to the
lattice_direction. This can usually be estimated as the
negative of the strain applied in the other two directions.
E.g., if you apply a tensile strain of 0.05 to the a and b
directions, you can use -0.05 as a reasonable first guess for
initial strain.
atom_relax (bool): Whether to relax atomic positions.
max_steps (int): The maximum number of runs. Defaults to 20 (
highly unlikely that this limit is ever reached).
algo (str): Algorithm to use to find minimum. Default is "bfgs",
which is fast, but can be sensitive to numerical noise
in energy calculations. The alternative is "bisection",
which is more robust but can be a bit slow. The code does fall
back on the bisection when bfgs gives a non-sensical result,
e.g., negative lattice params.
\*\*vasp_job_kwargs: Passthrough kwargs to VaspJob. See
:class:`custodian.vasp.jobs.VaspJob`.
Returns:
Generator of jobs. At the end of the run, an "EOS.txt" is written
which provides a quick look at the E vs lattice parameter.
"""
nsw = 99 if atom_relax else 0
incar = Incar.from_file("INCAR")
# Set the energy convergence criteria as the EDIFFG (if present) or
# 10 x EDIFF (which itself defaults to 1e-4 if not present).
if incar.get("EDIFFG") and incar.get("EDIFFG") > 0:
etol = incar["EDIFFG"]
else:
etol = incar.get("EDIFF", 1e-4) * 10
if lattice_direction == "a":
lattice_index = 0
elif lattice_direction == "b":
lattice_index = 1
else:
lattice_index = 2
energies = {}
for i in range(max_steps):
if i == 0:
settings = [
{"dict": "INCAR",
"action": {"_set": {"ISIF": 2, "NSW": nsw}}}]
structure = Poscar.from_file("POSCAR").structure
x = structure.lattice.abc[lattice_index]
backup = True
else:
backup = False
v = Vasprun("vasprun.xml")
structure = v.final_structure
energy = v.final_energy
lattice = structure.lattice
x = lattice.abc[lattice_index]
energies[x] = energy
if i == 1:
x *= (1 + initial_strain)
else:
# Sort the lattice parameter by energies.
min_x = min(energies.keys(), key=lambda e: energies[e])
sorted_x = sorted(energies.keys())
ind = sorted_x.index(min_x)
if ind == 0:
other = ind + 1
elif ind == len(sorted_x) - 1:
other = ind - 1
else:
other = ind + 1 \
if energies[sorted_x[ind + 1]] \
< energies[sorted_x[ind - 1]] \
else ind - 1
if abs(energies[min_x]
#.........这里部分代码省略.........
示例2: cry2cif
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import to [as 别名]
def cry2cif(filename, to="cif", center=False, sortx=False, sortz=False,
b_dum=50, c_dum=50, istruct=-1):
"""
Read a CRYSTAL output file and return the structure in a cif or POSCAR format.
Args:
filename (str): crystal output filename
to (str): 'cif' or 'vasp', format of the output file (default is cif)
center (bool): if True, the slab or nanotube is translated to the center of
the box (default is False)
sortx (bool): Nanotube : if True, atoms are sorted along x axes (default is False).
sortz (bool): slab : if True, atoms are sorted along z axes (default is False).
b_dum (float): dummy lattice paramters b in angstrom for nanotubes (default 50 A)
c_dum (float): dummy lattice paramters c in angstrom for nanotubes and slabs (default 50 A)
istruct (int): structure to be extracted
"""
cryout = CrystalOutfile(filename)
print("title : ", cryout.title)
if cryout.group:
print("group : ", cryout.group)
# print("Number of structure read: ", len(cryout.structures))
if istruct == -1:
print("structure : Final structure")
structure = cryout.final_structure
else:
print("structure : Structure %d" % istruct)
structure = cryout.get_structure(istruct)
print("# atom : ", structure.num_sites)
print("composition: ", structure.composition)
print("Cell parameters:")
print("a : %10.4f" % structure.lattice.a)
print("b : %10.4f" % structure.lattice.b)
print("c : %10.4f" % structure.lattice.c)
print("alpha : %10.4f" % structure.lattice.alpha)
print("beta : %10.4f" % structure.lattice.beta)
print("gamma : %10.4f" % structure.lattice.gamma)
# ----------------------------------------------------------
# New b and c axes
# ----------------------------------------------------------
if cryout.slab:
frac_coords = structure.frac_coords
frac_coords[:, 2] *= structure.lattice.c / c_dum
matrix = structure.lattice.matrix
matrix[2, 2] = c_dum
structure = Structure(Lattice(matrix), structure.species, frac_coords)
if cryout.nanotube:
frac_coords = structure.frac_coords
frac_coords[:, 1] *= structure.lattice.c / c_dum
frac_coords[:, 2] *= structure.lattice.b / b_dum
matrix = structure.lattice.matrix
matrix[1, 1] = b_dum
matrix[2, 2] = c_dum
structure = Structure(Lattice(matrix), structure.species, frac_coords)
# ----------------------------------------------------------
# move slab or nanotube to the center of the box
# ----------------------------------------------------------
if center:
if cryout.slab:
coords = structure.frac_coords.copy()
coords[:, 2] += .5
structure = Structure(structure.lattice, structure.species, coords)
elif cryout.nanotube:
coords = structure.frac_coords
coords += .5
structure = Structure(structure.lattice, structure.species, coords)
# ----------------------------------------------------------
# sort atom along x or z axis for slab
# ----------------------------------------------------------
if sortz:
isort = 2
elif sortx:
isort = 0
axes = {2: "z", 0: "x"}
if sortz or sortx:
print("\nSort atoms along %s" % axes[isort])
data = zip(structure.species, structure.coords)
data = sorted(data, key=lambda d: d[-1][isort], reverse=True)
species = [d[0] for d in data]
coords = [d[1] for d in data]
structure = Structure(structure.lattice, species, coords)
# ----------------------------------------------------------
# export in the given format
# ----------------------------------------------------------
basename, _ = os.path.splitext(filename)
if to.lower() == "cif":
ext = ".cif"
elif to.lower() == "vasp":
to = "POSCAR"
ext = ".vasp"
else:
#.........这里部分代码省略.........