本文整理汇总了Python中pymatgen.io.smartio.read_structure函数的典型用法代码示例。如果您正苦于以下问题:Python read_structure函数的具体用法?Python read_structure怎么用?Python read_structure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_structure函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_electronegativity
def test_electronegativity(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5)
s1 = read_structure(os.path.join(test_dir, "Na2Fe2PAsO4S4.cif"))
s2 = read_structure(os.path.join(test_dir, "Na2Fe2PNO4Se4.cif"))
self.assertAlmostEqual(sm.fit_with_electronegativity(s1, s2),
{Composition('S'): Composition('Se'), Composition('As'): Composition('N')})
开发者ID:akashneo,项目名称:pymatgen,代码行数:7,代码来源:test_structure_matcher.py
示例2: test_get_xrd_data
def test_get_xrd_data(self):
a = 4.209
latt = Lattice.cubic(a)
structure = Structure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
c = XRDCalculator()
data = c.get_xrd_data(structure, two_theta_range=(0, 90))
#Check the first two peaks
self.assertAlmostEqual(data[0][0], 21.107738329639844)
self.assertAlmostEqual(data[0][1], 36.483184003748946)
self.assertEqual(data[0][2], {(1, 0, 0): 6})
self.assertAlmostEqual(data[0][3], 4.2089999999999996)
self.assertAlmostEqual(data[1][0], 30.024695921112777)
self.assertAlmostEqual(data[1][1], 100)
self.assertEqual(data[1][2], {(1, 1, 0): 12})
self.assertAlmostEqual(data[1][3], 2.976212442014178)
s = read_structure(os.path.join(test_dir, "LiFePO4.cif"))
data = c.get_xrd_data(s, two_theta_range=(0, 90))
self.assertAlmostEqual(data[1][0], 17.03504233621785)
self.assertAlmostEqual(data[1][1], 50.400928948337075)
s = read_structure(os.path.join(test_dir, "Li10GeP2S12.cif"))
data = c.get_xrd_data(s, two_theta_range=(0, 90))
self.assertAlmostEqual(data[1][0], 14.058274883353876)
self.assertAlmostEqual(data[1][1], 4.4111123641667671)
# Test a hexagonal structure.
s = read_structure(os.path.join(test_dir, "Graphite.cif"),
primitive=False)
data = c.get_xrd_data(s, two_theta_range=(0, 90))
self.assertAlmostEqual(data[0][0], 7.929279053132362)
self.assertAlmostEqual(data[0][1], 100)
self.assertAlmostEqual(len(list(data[0][2].keys())[0]), 4)
#Add test case with different lengths of coefficients.
#Also test d_hkl.
coords = [[0.25, 0.25, 0.173], [0.75, 0.75, 0.827], [0.75, 0.25, 0],
[0.25, 0.75, 0], [0.25, 0.25, 0.676], [0.75, 0.75, 0.324]]
sp = ["Si", "Si", "Ru", "Ru", "Pr", "Pr"]
s = Structure(Lattice.tetragonal(4.192, 6.88), sp, coords)
data = c.get_xrd_data(s)
self.assertAlmostEqual(data[0][0], 12.86727341476735)
self.assertAlmostEqual(data[0][1], 31.448239816769796)
self.assertAlmostEqual(data[0][3], 6.88)
self.assertEqual(len(data), 42)
data = c.get_xrd_data(s, two_theta_range=[0, 60])
self.assertEqual(len(data), 18)
#Test with and without Debye-Waller factor
tungsten = Structure(Lattice.cubic(3.1653), ["W"] * 2,
[[0, 0, 0], [0.5, 0.5, 0.5]])
data = c.get_xrd_data(tungsten, scaled=False)
self.assertAlmostEqual(data[0][0], 40.294828554672264)
self.assertAlmostEqual(data[0][1], 2414237.5633093244)
self.assertAlmostEqual(data[0][3], 2.2382050944897789)
c = XRDCalculator(debye_waller_factors={"W": 0.1526})
data = c.get_xrd_data(tungsten, scaled=False)
self.assertAlmostEqual(data[0][0], 40.294828554672264)
self.assertAlmostEqual(data[0][1], 2377745.2296686019)
self.assertAlmostEqual(data[0][3], 2.2382050944897789)
开发者ID:NadezhdaBzhilyanskaya,项目名称:pymatgen,代码行数:60,代码来源:test_xrd.py
示例3: test_fit
def test_fit(self):
"""
Take two known matched structures
1) Ensure match
2) Ensure match after translation and rotations
3) Ensure no-match after large site translation
4) Ensure match after site shuffling
"""
sm = StructureMatcher()
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
# Test rotational/translational invariance
op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False,
np.array([0.4, 0.7, 0.9]))
self.struct_list[1].apply_operation(op)
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
#Test failure under large atomic translation
self.struct_list[1].translate_sites([0], [.4, .4, .2],
frac_coords=True)
self.assertFalse(sm.fit(self.struct_list[0], self.struct_list[1]))
self.struct_list[1].translate_sites([0], [-.4, -.4, -.2],
frac_coords=True)
# random.shuffle(editor._sites)
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
#Test FrameworkComporator
sm2 = StructureMatcher(comparator=FrameworkComparator())
lfp = read_structure(os.path.join(test_dir, "LiFePO4.cif"))
nfp = read_structure(os.path.join(test_dir, "NaFePO4.cif"))
self.assertTrue(sm2.fit(lfp, nfp))
self.assertFalse(sm.fit(lfp, nfp))
#Test anonymous fit.
self.assertEqual(sm.fit_anonymous(lfp, nfp),
{Composition("Li"): Composition("Na")})
self.assertAlmostEqual(sm.get_minimax_rms_anonymous(lfp, nfp)[0],
0.096084154118549828)
#Test partial occupancies.
s1 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
s2 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Fe": 0.25}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.75}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
self.assertFalse(sm.fit(s1, s2))
self.assertFalse(sm.fit(s2, s1))
s2 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Fe": 0.25}, {"Fe": 0.25}, {"Fe": 0.25},
{"Fe": 0.25}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
self.assertEqual(sm.fit_anonymous(s1, s2),
{Composition("Fe0.5"): Composition("Fe0.25")})
self.assertAlmostEqual(sm.get_minimax_rms_anonymous(s1, s2)[0], 0)
开发者ID:leicheng,项目名称:pymatgen,代码行数:60,代码来源:test_structure_matcher.py
示例4: test_supercell_fit
def test_supercell_fit(self):
sm = StructureMatcher(attempt_supercell=False)
s1 = read_structure(os.path.join(test_dir, "Al3F9.cif"))
s2 = read_structure(os.path.join(test_dir, "Al3F9_distorted.cif"))
self.assertFalse(sm.fit(s1, s2))
sm = StructureMatcher(attempt_supercell=True)
self.assertTrue(sm.fit(s1, s2))
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:10,代码来源:test_structure_matcher.py
示例5: test_read_structure
def test_read_structure(self):
test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
'test_files')
for fname in ("Li2O.cif", "Li2O2.cif", "vasprun.xml",
"vasprun_Si_bands.xml", "Si.cssr"):
filename = os.path.join(test_dir, fname)
struct = read_structure(filename)
self.assertIsInstance(struct, Structure)
prim = read_structure(filename, primitive=True)
self.assertLessEqual(len(prim), len(struct))
sorted_s = read_structure(filename, sort=True)
self.assertEqual(sorted_s, sorted_s.get_sorted_structure())
开发者ID:bcbwilla,项目名称:pymatgen,代码行数:12,代码来源:test_smartio.py
示例6: scaleCell
def scaleCell(path,volume):
poscar = os.path.join(path,'POSCAR')
refcar = os.path.join(path,'REFCAR')
potcar = Potcar()
assert os.path.isfile(poscar)
struct = read_structure(poscar)
struct.scale_lattice(volume)
species = [ pot.element for pot in potcar.from_file('POTCAR') ]
reprule = { old:new for old,new in zip(struct.composition.elements,species) }
struct.replace_species(reprule)
p = Poscar(struct)
with open(poscar) as f:
poscomment = f.readline().strip()
p.comment = poscomment
p.write_file(poscar,vasp4_compatible=True)
if os.path.isfile(refcar):
tmp = os.path.join(path,'POSCARtmp')
# copy Poscar to temporary file and refcar to poscar
copyfile(poscar,tmp)
copyfile(refcar,poscar)
struct = read_structure(poscar)
struct.scale_lattice(volume)
species = [ pot.element for pot in potcar.from_file('POTCAR') ]
reprule = { old:new for old,new in zip(struct.composition.elements,species) }
struct.replace_species(reprule)
r = Poscar(struct)
with open(poscar) as f:
poscomment = f.readline().strip()
r.comment = poscomment
r.write_file(poscar,vasp4_compatible=True)
with open(refcar) as f:
poscomment = f.readline().strip()
r.comment = poscomment
r.write_file(refcar,vasp4_compatible=True)
# replace poscar with its original
move(tmp,poscar)
else:
print 'No REFCAR found.'
开发者ID:smwahl,项目名称:pymatgen_scripts,代码行数:52,代码来源:scaleCell.py
示例7: test_electronegativity
def test_electronegativity(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5)
s1 = read_structure(os.path.join(test_dir, "Na2Fe2PAsO4S4.cif"))
s2 = read_structure(os.path.join(test_dir, "Na2Fe2PNO4Se4.cif"))
self.assertEqual(sm.get_best_electronegativity_anonymous_mapping(s1, s2),
{Element('S'): Element('Se'),
Element('As'): Element('N'),
Element('Fe'): Element('Fe'),
Element('Na'): Element('Na'),
Element('P'): Element('P'),
Element('O'): Element('O'),})
self.assertEqual(len(sm.get_all_anonymous_mappings(s1, s2)), 2)
开发者ID:bcbwilla,项目名称:pymatgen,代码行数:13,代码来源:test_structure_matcher.py
示例8: asabistructure
def asabistructure(obj):
"""
Convert obj into an AbiStructure object. Accepts:
- AbiStructure instance
- Subinstances of pymatgen.
- File paths
"""
if isinstance(obj, AbiStructure):
return obj
if isinstance(obj, Structure):
# Promote
return AbiStructure(obj)
if isinstance(obj, str):
# Handle file paths.
if os.path.isfile(obj):
if obj.endswith(".nc"):
from .netcdf import structure_from_etsf_file
structure = structure_from_etsf_file(obj)
print(structure._sites)
else:
from pymatgen.io.smartio import read_structure
structure = read_structure(obj)
# Promote
return AbiStructure(structure)
raise ValueError("Don't know how to convert object %s to an AbiStructure structure" % str(obj))
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:31,代码来源:abiobjects.py
示例9: from_file
def from_file(cls, filepath):
"""
Return a new Structure instance from a NetCDF file
Args:
filename:
netcdf file with crystallographic data in the ETSF-IO format.
or any other file format supported by `pymatgen.io.smartio`.
"""
if filepath.endswith(".nc"):
file, closeit = as_etsfreader(filepath)
new = file.read_structure()
# Change the class of new.
new.__class__ = cls
new.set_spacegroup(SpaceGroup.from_file(file))
if closeit:
file.close()
else:
# TODO: Spacegroup is missing here.
from pymatgen.io.smartio import read_structure
new = read_structure(filepath)
# Change the class of new.
new.__class__ = cls
return new
开发者ID:srirampr,项目名称:abipy,代码行数:28,代码来源:structure.py
示例10: test_apply_transformation
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 = SymmetryFinder(alls[0]["structure"], 0.1)
self.assertEqual(f.get_spacegroup_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"])
from pymatgen.io.smartio import read_structure
s = read_structure(os.path.join(test_dir, 'Li2O.cif'))
#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)
self.assertEqual(len(alls), 10)
开发者ID:artemcpp,项目名称:pymatgen,代码行数:25,代码来源:test_advanced_transformations.py
示例11: test_read_structure
def test_read_structure(self):
for fname in ("Li2O.cif", "Li2O2.cif", "vasprun.xml",
"vasprun_Si_bands.xml", "Si.cssr"):
filename = os.path.join(test_dir, fname)
struct = read_structure(filename)
self.assertIsInstance(struct, Structure)
print struct
开发者ID:jesuansito,项目名称:pymatgen,代码行数:7,代码来源:test_smartio.py
示例12: generate_diffraction_plot
def generate_diffraction_plot(args):
s = read_structure(args.filenames[0])
c = XRDCalculator()
if args.outfile:
c.get_xrd_plot(s).savefig(args.outfile[0])
else:
c.show_xrd_plot(s)
开发者ID:NadezhdaBzhilyanskaya,项目名称:pymatgen,代码行数:7,代码来源:matgenie.py
示例13: test_read_structure
def test_read_structure(self):
test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
'test_files')
for fname in ("Li2O.cif", "Li2O2.cif", "vasprun.xml",
"vasprun_Si_bands.xml", "Si.cssr"):
filename = os.path.join(test_dir, fname)
struct = read_structure(filename)
self.assertIsInstance(struct, Structure)
开发者ID:akashneo,项目名称:pymatgen,代码行数:8,代码来源:test_smartio.py
示例14: parse_view
def parse_view(args):
from pymatgen.vis.structure_vtk import StructureVis
excluded_bonding_elements = args.exclude_bonding[0].split(",") \
if args.exclude_bonding else []
s = read_structure(args.filename[0])
vis = StructureVis(excluded_bonding_elements=excluded_bonding_elements)
vis.set_structure(s)
vis.show()
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:8,代码来源:matgenie.py
示例15: test_get_energy
def test_get_energy(self):
m = IsingModel(5, 6)
from pymatgen.core.periodic_table import Specie
s = read_structure(os.path.join(test_dir, "LiFePO4.cif"))
s.replace_species({"Fe": Specie("Fe", 2, {"spin": 4})})
self.assertEqual(m.get_energy(s), 172.81260515787977)
s.replace(4, Specie("Fe", 2, {"spin": -4}))
s.replace(5, Specie("Fe", 2, {"spin": -4}))
self.assertAlmostEqual(m.get_energy(s), 51.97424405382921)
开发者ID:jmflorez,项目名称:pymatgen,代码行数:9,代码来源:test_energy_models.py
示例16: test_read_structure
def test_read_structure(self):
test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
'test_files')
for fname in ("Li2O.cif", "vasprun.xml",
"vasprun_Si_bands.xml", "Si.cssr"):
filename = os.path.join(test_dir, fname)
struct = read_structure(filename)
self.assertIsInstance(struct, Structure)
prim = read_structure(filename, primitive=True)
self.assertLessEqual(len(prim), len(struct))
sorted_s = read_structure(filename, sort=True)
self.assertEqual(sorted_s, sorted_s.get_sorted_structure())
m = StructureMatcher()
for ext in [".cif", ".json", ".cssr"]:
fn = "smartio_structure_test" + ext
write_structure(struct, fn)
back = read_structure(fn)
self.assertTrue(m.fit(back, struct))
os.remove(fn)
开发者ID:ATNDiaye,项目名称:pymatgen,代码行数:20,代码来源:test_smartio.py
示例17: convert_fmt
def convert_fmt(args):
iformat = args.input_format[0]
oformat = args.output_format[0]
filename = args.input_filename[0]
out_filename = args.output_filename[0]
try:
if iformat == "smart":
structure = read_structure(filename)
if iformat == "POSCAR":
p = Poscar.from_file(filename)
structure = p.structure
elif iformat == "CIF":
r = CifParser(filename)
structure = r.get_structures()[0]
elif iformat == "CSSR":
structure = Cssr.from_file(filename).structure
if oformat == "smart":
write_structure(structure, out_filename)
elif oformat == "POSCAR":
p = Poscar(structure)
p.write_file(out_filename)
elif oformat == "CIF":
w = CifWriter(structure)
w.write_file(out_filename)
elif oformat == "CSSR":
c = Cssr(structure)
c.write_file(out_filename)
elif oformat == "VASP":
input_set = MPVaspInputSet()
ts = TransformedStructure(
structure,
[],
history=[
{"source": "file", "datetime": str(datetime.datetime.now()), "original_file": open(filename).read()}
],
)
ts.write_vasp_input(input_set, output_dir=out_filename)
elif oformat == "MITVASP":
input_set = MITVaspInputSet()
ts = TransformedStructure(
structure,
[],
history=[
{"source": "file", "datetime": str(datetime.datetime.now()), "original_file": open(filename).read()}
],
)
ts.write_vasp_input(input_set, output_dir=out_filename)
except Exception as ex:
print "Error converting file. Are they in the right format?"
print str(ex)
开发者ID:sikisis,项目名称:pymatgen,代码行数:53,代码来源:matgenie.py
示例18: test_mix
def test_mix(self):
structures = []
for fname in ["POSCAR.Li2O", "Li2O.cif", "Li2O2.cif", "LiFePO4.cif", "POSCAR.LiFePO4"]:
structures.append(read_structure(os.path.join(test_dir, fname)))
sm = StructureMatcher(comparator=ElementComparator())
groups = sm.group_structures(structures)
for g in groups:
formula = g[0].composition.reduced_formula
if formula in ["Li2O", "LiFePO4"]:
self.assertEqual(len(g), 2)
else:
self.assertEqual(len(g), 1)
开发者ID:qimin,项目名称:pymatgen,代码行数:12,代码来源:test_structure_matcher.py
示例19: test_zero_spin_case
def test_zero_spin_case(self):
#ensure that zero spin case maintains sites and formula
from pymatgen.io.smartio import read_structure
s = read_structure(os.path.join(test_dir, 'Li2O.cif'))
trans = MagOrderingTransformation({"Li+": 0.0}, 0.5)
alls = trans.apply_transformation(s)
#compositions will not be equal due to spin assignment
#structure representations will be the same
self.assertEqual(str(s), str(alls))
#Ensure s does not have a spin property
self.assertFalse('spin' in s.sites[0].specie._properties)
#ensure sites are assigned a spin property in alls
self.assertTrue('spin' in alls.sites[0].specie._properties)
开发者ID:NadezhdaBzhilyanskaya,项目名称:pymatgen,代码行数:13,代码来源:test_advanced_transformations.py
示例20: setup
def setup(self):
"""
Performs initial setup for VaspJob, including overriding any settings
and backing up.
"""
files = os.listdir(".")
num_structures = 0
if not set(files).issuperset(VASP_INPUT_FILES):
for f in files:
try:
struct = read_structure(f)
num_structures += 1
except:
pass
if num_structures != 1:
raise RuntimeError("{} structures found. Unable to continue."
.format(num_structures))
else:
self.default_vis.write_input(struct, ".")
if self.backup:
for f in VASP_INPUT_FILES:
shutil.copy(f, "{}.orig".format(f))
if self.auto_npar:
try:
incar = Incar.from_file("INCAR")
#Only optimized NPAR for non-HF and non-RPA calculations.
if not (incar.get("LHFCALC") or incar.get("LRPA") or
incar.get("LEPSILON")):
if incar.get("IBRION") in [5, 6, 7, 8]:
# NPAR should not be set for Hessian matrix
# calculations, whether in DFPT or otherwise.
del incar["NPAR"]
else:
import multiprocessing
# try sge environment variable first
# (since multiprocessing counts cores on the current machine only)
ncores = os.environ.get('NSLOTS') or multiprocessing.cpu_count()
ncores = int(ncores)
for npar in range(int(round(math.sqrt(ncores))),
ncores):
if ncores % npar == 0:
incar["NPAR"] = npar
break
incar.write_file("INCAR")
except:
pass
if self.settings_override is not None:
VaspModder().apply_actions(self.settings_override)
开发者ID:cnk118,项目名称:custodian,代码行数:51,代码来源:jobs.py
注:本文中的pymatgen.io.smartio.read_structure函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论