コード例 #1
0
ファイル: test_sets.py プロジェクト: mhsiron/pymatgen
    def test_postfeffset(self):
        self.mp_xanes.write_input(os.path.join(".", "xanes_3"))
        feff_dict_input = FEFFDictSet.from_directory(os.path.join(".", "xanes_3"))
        self.assertTrue(
            feff_dict_input.tags
            == Tags.from_file(os.path.join(".", "xanes_3/feff.inp"))
        )
        self.assertTrue(
            str(feff_dict_input.header())
            == str(Header.from_file(os.path.join(".", "xanes_3/HEADER")))
        )
        feff_dict_input.write_input("xanes_3_regen")
        origin_tags = Tags.from_file(os.path.join(".", "xanes_3/PARAMETERS"))
        output_tags = Tags.from_file(os.path.join(".", "xanes_3_regen/PARAMETERS"))
        origin_mole = Atoms.cluster_from_file(os.path.join(".", "xanes_3/feff.inp"))
        output_mole = Atoms.cluster_from_file(
            os.path.join(".", "xanes_3_regen/feff.inp")
        )
        original_mole_dist = np.array(origin_mole.distance_matrix[0, :]).astype(
            np.float64
        )
        output_mole_dist = np.array(output_mole.distance_matrix[0, :]).astype(
            np.float64
        )
        original_mole_shell = [x.species_string for x in origin_mole]
        output_mole_shell = [x.species_string for x in output_mole]

        self.assertTrue(np.allclose(original_mole_dist, output_mole_dist))
        self.assertTrue(origin_tags == output_tags)
        self.assertTrue(original_mole_shell == output_mole_shell)

        shutil.rmtree(os.path.join(".", "xanes_3"))
        shutil.rmtree(os.path.join(".", "xanes_3_regen"))

        reci_mp_xanes = MPXANESSet(
            self.absorbing_atom, self.structure, user_tag_settings={"RECIPROCAL": ""}
        )
        reci_mp_xanes.write_input("xanes_reci")
        feff_reci_input = FEFFDictSet.from_directory(os.path.join(".", "xanes_reci"))
        self.assertTrue("RECIPROCAL" in feff_reci_input.tags)

        feff_reci_input.write_input("Dup_reci")
        self.assertTrue(os.path.exists(os.path.join(".", "Dup_reci", "HEADER")))
        self.assertTrue(os.path.exists(os.path.join(".", "Dup_reci", "feff.inp")))
        self.assertTrue(os.path.exists(os.path.join(".", "Dup_reci", "PARAMETERS")))
        self.assertFalse(os.path.exists(os.path.join(".", "Dup_reci", "ATOMS")))
        self.assertFalse(os.path.exists(os.path.join(".", "Dup_reci", "POTENTIALS")))

        tags_original = Tags.from_file(os.path.join(".", "xanes_reci/feff.inp"))
        tags_output = Tags.from_file(os.path.join(".", "Dup_reci/feff.inp"))
        self.assertTrue(tags_original == tags_output)

        stru_orig = Structure.from_file(os.path.join(".", "xanes_reci/Co2O2.cif"))
        stru_reci = Structure.from_file(os.path.join(".", "Dup_reci/Co2O2.cif"))
        self.assertTrue(stru_orig.__eq__(stru_reci))

        shutil.rmtree(os.path.join(".", "Dup_reci"))
        shutil.rmtree(os.path.join(".", "xanes_reci"))
コード例 #2
0
ファイル: test_sets.py プロジェクト: adozier/pymatgen
 def test_user_tag_settings(self):
     tags_dict_ans = self.mp_xanes.tags.as_dict()
     tags_dict_ans["COREHOLE"] = "RPA"
     tags_dict_ans["EDGE"] = "L1"
     user_tag_settings = {"COREHOLE": "RPA", "EDGE": "L1"}
     mp_xanes_2 = MPXANESSet(self.absorbing_atom, self.structure,
                             user_tag_settings=user_tag_settings)
     self.assertEqual(mp_xanes_2.tags.as_dict(), tags_dict_ans)
     print(mp_xanes_2.as_dict().keys())
コード例 #3
0
 def test_user_tag_settings(self):
     tags_dict_ans = self.mp_xanes.tags.as_dict()
     tags_dict_ans["COREHOLE"] = "RPA"
     tags_dict_ans["EDGE"] = "L1"
     user_tag_settings = {"COREHOLE": "RPA", "EDGE": "L1"}
     mp_xanes_2 = MPXANESSet(self.absorbing_atom,
                             self.structure,
                             user_tag_settings=user_tag_settings)
     self.assertEqual(mp_xanes_2.tags.as_dict(), tags_dict_ans)
     print(mp_xanes_2.as_dict().keys())
コード例 #4
0
def main():
    """
    Main method.
    """
    parser = argparse.ArgumentParser(description='''
    Example script to generate FEFF input files from a cif file
    Author: Alan Dozier
    Version: 1.0
    Last updated: August, 2012''')

    parser.add_argument('cif_file',
                        metavar='cif_file',
                        type=str,
                        nargs=1,
                        help='cif_file to use')
    parser.add_argument('central_atom',
                        metavar='central_atom',
                        type=str,
                        nargs=1,
                        help='symbol of absorbing atom')
    parser.add_argument('calc_type',
                        metavar='calc_type',
                        type=str,
                        nargs=1,
                        help='type of calc, currently XANES or EXAFS')

    args = parser.parse_args()
    cif_file = args.cif_file[0]
    central_atom = args.central_atom[0]
    calc_type = args.calc_type[0]

    r = CifParser(cif_file)
    structure = r.get_structures()[0]
    x = MPXANESSet("MaterialsProject")

    source = os.path.basename(cif_file)
    comment = 'From cif file'

    header = MPXANESSet.get_header(x, structure, source, comment)
    print("\n\nHEADER\n")
    print(header)

    tags = MPXANESSet.get_feff_tags(x, calc_type)
    print("\n\nPARAMETERS\n")
    print(tags)

    POT = MPXANESSet.get_feff_pot(x, structure, central_atom)
    print("\n\nPOTENTIALS\n")
    print(POT)

    ATOMS = MPXANESSet.get_feff_atoms(x, structure, central_atom)
    print("\n\nATOMS\n")
    print(ATOMS)
コード例 #5
0
ファイル: test_sets.py プロジェクト: albalu/pymatgen
    def test_postfeffset(self):
        self.mp_xanes.write_input(os.path.join('.', 'xanes_3'))
        feff_dict_input = FEFFDictSet.from_directory(os.path.join('.', 'xanes_3'))
        self.assertTrue(feff_dict_input.tags == Tags.from_file(os.path.join('.', 'xanes_3/feff.inp')))
        self.assertTrue(str(feff_dict_input.header()) == str(Header.from_file(os.path.join('.', 'xanes_3/HEADER'))))
        feff_dict_input.write_input('xanes_3_regen')
        origin_tags = Tags.from_file(os.path.join('.', 'xanes_3/PARAMETERS'))
        output_tags = Tags.from_file(os.path.join('.', 'xanes_3_regen/PARAMETERS'))
        origin_mole = Atoms.cluster_from_file(os.path.join('.', 'xanes_3/feff.inp'))
        output_mole = Atoms.cluster_from_file(os.path.join('.', 'xanes_3_regen/feff.inp'))
        original_mole_dist = np.array(origin_mole.distance_matrix[0, :]).astype(np.float64)
        output_mole_dist = np.array(output_mole.distance_matrix[0, :]).astype(np.float64)
        original_mole_shell = [x.species_string for x in origin_mole]
        output_mole_shell = [x.species_string for x in output_mole]

        self.assertTrue(np.allclose(original_mole_dist, output_mole_dist))
        self.assertTrue(origin_tags == output_tags)
        self.assertTrue(original_mole_shell == output_mole_shell)

        shutil.rmtree(os.path.join('.', 'xanes_3'))
        shutil.rmtree(os.path.join('.', 'xanes_3_regen'))

        reci_mp_xanes = MPXANESSet(self.absorbing_atom, self.structure,
                                   user_tag_settings={"RECIPROCAL": ""})
        reci_mp_xanes.write_input('xanes_reci')
        feff_reci_input = FEFFDictSet.from_directory(os.path.join('.', 'xanes_reci'))
        self.assertTrue("RECIPROCAL" in feff_reci_input.tags)

        feff_reci_input.write_input('Dup_reci')
        self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'HEADER')))
        self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'feff.inp')))
        self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'PARAMETERS')))
        self.assertFalse(os.path.exists(os.path.join('.', 'Dup_reci', 'ATOMS')))
        self.assertFalse(os.path.exists(os.path.join('.', 'Dup_reci', 'POTENTIALS')))

        tags_original = Tags.from_file(os.path.join('.', 'xanes_reci/feff.inp'))
        tags_output = Tags.from_file(os.path.join('.', 'Dup_reci/feff.inp'))
        self.assertTrue(tags_original == tags_output)

        stru_orig = Structure.from_file(os.path.join('.', 'xanes_reci/Co2O2.cif'))
        stru_reci = Structure.from_file(os.path.join('.', 'Dup_reci/Co2O2.cif'))
        self.assertTrue(stru_orig.__eq__(stru_reci))

        shutil.rmtree(os.path.join('.', 'Dup_reci'))
        shutil.rmtree(os.path.join('.', 'xanes_reci'))
コード例 #6
0
ファイル: test_sets.py プロジェクト: kjappelbaum/pymatgen
    def setUpClass(cls):

        cls.header_string = """* This FEFF.inp file generated by pymatgen
TITLE comment: From cif file
TITLE Source:  CoO19128.cif
TITLE Structure Summary:  Co2 O2
TITLE Reduced formula:  CoO
TITLE space group: (P6_3mc), space number:  (186)
TITLE abc:  3.297078   3.297078   5.254213
TITLE angles: 90.000000  90.000000 120.000000
TITLE sites: 4
* 1 Co     0.333333     0.666667     0.503676
* 2 Co     0.666667     0.333333     0.003676
* 3 O     0.333333     0.666667     0.121324
* 4 O     0.666667     0.333333     0.621325"""
        cif_file = os.path.join(PymatgenTest.TEST_FILES_DIR, "CoO19128.cif")
        cls.structure = CifParser(cif_file).get_structures()[0]
        cls.absorbing_atom = "O"
        cls.mp_xanes = MPXANESSet(cls.absorbing_atom, cls.structure)
コード例 #7
0
ファイル: test_sets.py プロジェクト: kjappelbaum/pymatgen
 def test_to_and_from_dict(self):
     f1_dict = self.mp_xanes.as_dict()
     f2 = MPXANESSet.from_dict(f1_dict)
     self.assertEqual(f1_dict, f2.as_dict())
コード例 #8
0
ファイル: test_sets.py プロジェクト: albalu/pymatgen
 def test_to_and_from_dict(self):
     f1_dict = self.mp_xanes.as_dict()
     f2 = MPXANESSet.from_dict(f1_dict)
     self.assertEqual(f1_dict, f2.as_dict())