当前位置: 首页>>代码示例>>Python>>正文


Python cifio.CifParser类代码示例

本文整理汇总了Python中pymatgen.io.cifio.CifParser的典型用法代码示例。如果您正苦于以下问题:Python CifParser类的具体用法?Python CifParser怎么用?Python CifParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CifParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的pymatgen.io.cifio.CifParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。