本文整理汇总了Python中pymatgen.io.smartio.read_structure函数的典型用法代码示例。如果您正苦于以下问题:Python read_structure函数的具体用法?Python read_structure怎么用?Python read_structure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_structure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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')})
示例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)
示例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)
示例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))
示例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())
示例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.'
示例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)
示例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))
示例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
示例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)
示例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
示例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)
示例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)
示例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()
示例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)