本文整理汇总了Python中pymatgen.io.cifio.CifParser类的典型用法代码示例。如果您正苦于以下问题:Python CifParser类的具体用法?Python CifParser怎么用?Python CifParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CifParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_init
def test_init(self):
fitter = StructureFitter(self.b, self.a)
self.assertTrue(fitter.mapping_op != None, "No fit found!")
#Now to try with rotated structure
op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False, np.array([0, 0, 1]))
editor = StructureEditor(self.a)
editor.apply_operation(op)
fitter = StructureFitter(self.b, editor.modified_structure)
self.assertTrue(fitter.mapping_op != None, "No fit found!")
#test with a supercell
mod = SupercellMaker(self.a, scaling_matrix=[[2, 0, 0], [0, 1, 0], [0, 0, 1]])
a_super = mod.modified_structure
fitter = StructureFitter(self.b, a_super)
self.assertTrue(fitter.mapping_op != None, "No fit found!")
# Test with a structure with a translated point
editor = StructureEditor(self.a)
site = self.a[0]
editor.delete_site(0)
trans = np.random.randint(0, 1000, 3)
editor.insert_site(0, site.species_and_occu, site.frac_coords + trans, False, False)
fitter = StructureFitter(self.b, editor.modified_structure)
self.assertTrue(fitter.mapping_op != None, "No fit found for translation {}!".format(trans))
parser = CifParser(os.path.join(test_dir, "FePO4a.cif"))
a = parser.get_structures()[0]
parser = CifParser(os.path.join(test_dir, "FePO4b.cif"))
b = parser.get_structures()[0]
fitter = StructureFitter(b, a)
self.assertTrue(fitter.mapping_op != None, "No fit found!")
开发者ID:chenweis,项目名称:pymatgen,代码行数:34,代码来源:test_structure_fitter.py
示例2: read_structure
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!")
开发者ID:jesuansito,项目名称:pymatgen,代码行数:30,代码来源:smartio.py
示例3: read_structure
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!")
开发者ID:brendaneng1,项目名称:pymatgen,代码行数:34,代码来源:smartio.py
示例4: test_apply_transformation
def test_apply_transformation(self):
t = PrimitiveCellTransformation()
coords = list()
coords.append([0, 0, 0])
coords.append([0.375, 0.375, 0.375])
coords.append([.5, .5, .5])
coords.append([0.875, 0.875, 0.875])
coords.append([0.125, 0.125, 0.125])
coords.append([0.25, 0.25, 0.25])
coords.append([0.625, 0.625, 0.625])
coords.append([0.75, 0.75, 0.75])
lattice = Lattice([[3.8401979337, 0.00, 0.00],
[1.9200989668, 3.3257101909, 0.00],
[0.00, -2.2171384943, 3.1355090603]])
struct = Structure(lattice, ["Li+", "Li+", "Li+", "Li+",
"O2-", "O2-", "O2-", "O2-"],
coords)
s = t.apply_transformation(struct)
self.assertEqual(len(s), 4)
parser = CifParser(os.path.join(test_dir, "TiO2_super.cif"))
s = parser.get_structures()[0]
prim = t.apply_transformation(s)
self.assertEqual(prim.formula, "Ti4 O8")
开发者ID:isayev,项目名称:pymatgen,代码行数:25,代码来源:test_standard_transformations.py
示例5: test_get_valence
def test_get_valence(self):
parser = CifParser(os.path.join(test_dir, "LiMn2O4.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 3, 3, 4, 4, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
parser = CifParser(os.path.join(test_dir, "LiFePO4.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
parser = CifParser(os.path.join(test_dir, "Li3V2(PO4)3.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
parser = CifParser(os.path.join(test_dir, "Li4Fe3Mn1(PO4)4.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
parser = CifParser(os.path.join(test_dir, "NaFePO4.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
开发者ID:isayev,项目名称:pymatgen,代码行数:26,代码来源:test_bond_valence.py
示例6: test_init
def test_init(self):
if not enumlib_present:
raise SkipTest("enumlib not present. Skipping...")
test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
'test_files')
parser = CifParser(os.path.join(test_dir, "LiFePO4.cif"))
struct = parser.get_structures(False)[0]
subtrans = SubstitutionTransformation({'Li': {'Li': 0.5}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2)
adaptor.run()
structures = adaptor.structures
self.assertEqual(len(structures), 86)
for s in structures:
self.assertAlmostEqual(s.composition
.get_atomic_fraction(Element("Li")),
0.5 / 6.5)
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2,
refine_structure=True)
adaptor.run()
structures = adaptor.structures
self.assertEqual(len(structures), 52)
subtrans = SubstitutionTransformation({'Li': {'Li': 0.25}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 1,
refine_structure=True)
adaptor.run()
structures = adaptor.structures
self.assertEqual(len(structures), 1)
for s in structures:
self.assertAlmostEqual(s.composition
.get_atomic_fraction(Element("Li")),
0.25 / 6.25)
#Make sure it works for completely disordered structures.
struct = Structure([[10, 0, 0], [0, 10, 0], [0, 0, 10]], [{'Fe':0.5}],
[[0, 0, 0]])
adaptor = EnumlibAdaptor(struct, 1, 2)
adaptor.run()
self.assertEqual(len(adaptor.structures), 3)
#Make sure it works properly when symmetry is broken by ordered sites.
parser = CifParser(os.path.join(test_dir, "LiFePO4.cif"))
struct = parser.get_structures(False)[0]
subtrans = SubstitutionTransformation({'Li': {'Li': 0.25}})
s = subtrans.apply_transformation(struct)
#REmove some ordered sites to break symmetry.
removetrans = RemoveSitesTransformation([4, 7])
s = removetrans.apply_transformation(s)
adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
self.assertEqual(len(structures), 4)
struct = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Si": 0.5}] * 2, [[0, 0, 0], [0.5, 0.5, 0.5]])
adaptor = EnumlibAdaptor(struct, 1, 3, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
self.assertEqual(len(structures), 10)
开发者ID:jesuansito,项目名称:pymatgen,代码行数:59,代码来源:test_enumlib_caller.py
示例7: setUp
def setUp(self):
"""
Setup Fe3O4 structure for testing multiple oxidation states
"""
cif_ob = CifParser(os.path.join(test_dir, "Fe3O4.cif"))
self._struct = cif_ob.get_structures()[0]
self._valrad_evaluator = ValenceIonicRadiusEvaluator(self._struct)
self._length = len(self._struct.sites)
开发者ID:brendaneng1,项目名称:pymatgen,代码行数:8,代码来源:test_point_defects.py
示例8: test_CifParser
def test_CifParser(self):
parser = CifParser(os.path.join(test_dir, 'LiFePO4.cif'))
for s in parser.get_structures(True):
self.assertEqual(s.formula, "Li4 Fe4 P4 O16", "Incorrectly parsed cif.")
#test for disordered structures
parser = CifParser(os.path.join(test_dir, 'Li10GeP2S12.cif'))
for s in parser.get_structures(True):
self.assertEqual(s.formula, "Li20.2 Ge2.06 P3.94 S24", "Incorrectly parsed cif.")
开发者ID:chenweis,项目名称:pymatgen,代码行数:9,代码来源:test_cifio.py
示例9: test_anonymized_fitting
def test_anonymized_fitting(self):
parser = CifParser(os.path.join(test_dir, "LiFePO4.cif"))
a = parser.get_structures()[0]
parser = CifParser(os.path.join(test_dir, "NaFePO4.cif"))
b = parser.get_structures()[0]
fitter = StructureFitter(b, a)
self.assertTrue(fitter.mapping_op == None, "No fit should be found when NaFePO4 and LiFePo4 are fitted in non-anonymized mode!")
fitter = StructureFitter(b, a, anonymized=True)
self.assertTrue(fitter.mapping_op != None, "Fit should be found when NaFePO4 and LiFePo4 are fitted in anonymized mode!")
self.assertEqual({el1.symbol:el2.symbol for el1, el2 in fitter.el_mapping.items()}, {"O":"O", "Fe":"Fe", "Na":"Li", "P":"P"})
开发者ID:chenweis,项目名称:pymatgen,代码行数:10,代码来源:test_structure_fitter.py
示例10: test_get_refined_structure
def test_get_refined_structure(self):
for a in self.sg.get_refined_structure().lattice.angles:
self.assertEqual(a, 90)
refined = self.disordered_sg.get_refined_structure()
for a in refined.lattice.angles:
self.assertEqual(a, 90)
self.assertEqual(refined.lattice.a, refined.lattice.b)
parser = CifParser(os.path.join(test_dir, 'Li2O.cif'))
s = parser.get_structures()[0]
sg = SymmetryFinder(s, 0.001)
self.assertEqual(sg.get_refined_structure().num_sites, 4 * s.num_sites)
开发者ID:bcbwilla,项目名称:pymatgen,代码行数:11,代码来源:test_finder.py
示例11: ConvertCifFileToPoscarFile
def ConvertCifFileToPoscarFile(cifFilename,poscarFilename):
parser = CifParser(cifFilename)
structure = parser.get_structures()[0]
structure_name = cif_file.split('.')[0]
poscar_obj = Poscar(structure=structure,comment=structure_name)
poscar_string = poscar_obj.to_string()
poscar_filename = '{}/{}.poscar'.format(poscar_directory_name,structure_name)
with open(poscar_filename,'w') as f:
f.write(poscar_string)
开发者ID:eragasa,项目名称:zircon,代码行数:11,代码来源:tsk1_createPoscarFilefromCif.py
示例12: test_filter
def test_filter(self):
filename = os.path.join(test_dir, "Li10GeP2S12.cif")
p = CifParser(filename)
s = p.get_structures()[0]
sf = SpecieProximityFilter({"Li": 1})
self.assertTrue(sf.test(s))
sf = SpecieProximityFilter({"Li": 2})
self.assertFalse(sf.test(s))
sf = SpecieProximityFilter({"P": 1})
self.assertTrue(sf.test(s))
sf = SpecieProximityFilter({"P": 5})
self.assertFalse(sf.test(s))
开发者ID:qimin,项目名称:pymatgen,代码行数:12,代码来源:test_filters.py
示例13: 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
示例14: setUp
def setUp(self):
filepath1 = os.path.join(test_dir, 'Li2O.cif')
p = CifParser(filepath1).get_structures(False)[0]
bv = BVAnalyzer()
valences = bv.get_valences(p)
el = [site.species_string for site in p.sites]
val_dict = dict(zip(el, valences))
self._radii = {}
for k,v in val_dict.items():
k1 = re.sub('[1-9,+,\-]', '', k)
self._radii[k] = Specie(k1, v).ionic_radius
p.remove(0)
self._vac_struct = p
开发者ID:akashneo,项目名称:pymatgen,代码行数:13,代码来源:test_zeoio.py
示例15: test_contains_peroxide
def test_contains_peroxide(self):
for filename in ['LiFePO4', 'NaFePO4', 'Li3V2(PO4)3', 'Li2O']:
filepath = os.path.join(test_dir, "{}.cif".format(filename))
parser = CifParser(filepath)
s = parser.get_structures()[0]
self.assertFalse(contains_peroxide(s))
for filename in ['Li2O2', "K2O2"]:
filepath = os.path.join(test_dir, "{}.cif".format(filename))
parser = CifParser(filepath)
s = parser.get_structures()[0]
self.assertTrue(contains_peroxide(s))
开发者ID:jesuansito,项目名称:pymatgen,代码行数:13,代码来源:test_structure_analyzer.py
示例16: setUp
def setUp(self):
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
self.structure = p.struct
self.sg = SymmetryFinder(self.structure, 0.001)
parser = CifParser(os.path.join(test_dir, 'Li10GeP2S12.cif'))
self.disordered_structure = parser.get_structures()[0]
self.disordered_sg = SymmetryFinder(self.disordered_structure, 0.001)
s = p.struct
editor = StructureEditor(p.struct)
site = s[0]
editor.delete_site(0)
editor.append_site(site.species_and_occu, site.frac_coords)
self.sg3 = SymmetryFinder(editor.modified_structure, 0.001)
开发者ID:chenweis,项目名称:pymatgen,代码行数:13,代码来源:test_spglib_adaptor.py
示例17: test_get_primitive
def test_get_primitive(self):
"""
F m -3 m Li2O testing of converting to primitive cell
"""
self.assertIsNone(self.sg.find_primitive())
parser = CifParser(os.path.join(test_dir, 'Li2O.cif'))
structure = parser.get_structures(False)[0]
s = SymmetryFinder(structure)
primitive_structure = s.find_primitive()
self.assertEqual(primitive_structure.formula, "Li2 O1")
# This isn't what is expected. All the angles should be 60
self.assertAlmostEqual(primitive_structure.lattice.alpha, 120)
self.assertAlmostEqual(primitive_structure.lattice.beta, 60)
self.assertAlmostEqual(primitive_structure.lattice.gamma, 120)
self.assertAlmostEqual(primitive_structure.lattice.volume, structure.lattice.volume / 4.0)
开发者ID:chenweis,项目名称:pymatgen,代码行数:15,代码来源:test_spglib_adaptor.py
示例18: from_cif_file
def from_cif_file(cif_file, source='', comment=''):
"""
Static method to create Header object from cif_file
Args:
cif_file: cif_file path and name
source: User supplied identifier, i.e. for Materials Project this
would be the material ID number
comment: User comment that goes in header
Returns:
Header Object
"""
r = CifParser(cif_file)
structure = r.get_structures()[0]
return Header(structure, source, comment)
开发者ID:zacharygibbs,项目名称:pymatgen,代码行数:16,代码来源:feffio.py
示例19: cif2geom
def cif2geom(ciffile):
parser=CifParser(ciffile)
struct=parser.get_structures()[0]
primstruct=struct.get_primitive_structure()
lat=primstruct.as_dict()['lattice']
sites=primstruct.as_dict()['sites']
geomlines=["CRYSTAL","0 0 0","1","%g %g %g %g %g %g"%\
(lat['a'],lat['b'],lat['c'],lat['alpha'],lat['beta'],lat['gamma'])]
geomlines+=["%i"%len(sites)]
for v in sites:
nm=v['species'][0]['element']
nm=str(Element(nm).Z+200)
geomlines+=[nm+" %g %g %g"%(v['abc'][0],v['abc'][1],v['abc'][2])]
return geomlines,primstruct
开发者ID:raybrad,项目名称:mainline,代码行数:16,代码来源:cif2crystal.py
示例20: setUp
def setUp(self):
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
self.structure = p.structure
self.sg = SymmetryFinder(self.structure, 0.001)
parser = CifParser(os.path.join(test_dir, 'Li10GeP2S12.cif'))
self.disordered_structure = parser.get_structures()[0]
self.disordered_sg = SymmetryFinder(self.disordered_structure, 0.001)
s = p.structure.copy()
site = s[0]
del s[0]
s.append(site.species_and_occu, site.frac_coords)
self.sg3 = SymmetryFinder(s, 0.001)
parser = CifParser(os.path.join(test_dir, 'Graphite.cif'))
graphite = parser.get_structures()[0]
graphite.add_site_property("magmom", [0.1] * len(graphite))
self.sg4 = SymmetryFinder(graphite, 0.001)
开发者ID:bcbwilla,项目名称:pymatgen,代码行数:16,代码来源:test_finder.py
注:本文中的pymatgen.io.cifio.CifParser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论