Example #1
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(PymatgenTest.TEST_FILES_DIR, "HEADER")
     header = Header.from_file(file_name)
     d = header.as_dict()
     header2 = Header.from_dict(d)
     self.assertEqual(str(header), str(header2),
                      "Header failed to and from dict test")
Example #2
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(test_dir, 'HEADER')
     header = Header.from_file(file_name)
     d = header.as_dict()
     header2 = Header.from_dict(d)
     self.assertEqual(str(header), str(header2),
                      "Header failed to and from dict test")
Example #3
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(test_dir, 'HEADER')
     header = Header.from_file(file_name)
     d = header.as_dict()
     header2 = Header.from_dict(d)
     self.assertEqual(str(header), str(header2),
                      "Header failed to and from dict test")
Example #4
0
 def test_from_string(self):
     header = Header.from_string(header_string)
     self.assertEqual(
         header.struct.composition.reduced_formula,
         "CoO",
         "Failed to generate structure from HEADER string",
     )
Example #5
0
    def test_post_distdiff(self):
        feff_dict_input = FEFFDictSet.from_directory(
            os.path.join(PymatgenTest.TEST_FILES_DIR, "feff_dist_test"))
        self.assertTrue(feff_dict_input.tags == Tags.from_file(
            os.path.join(PymatgenTest.TEST_FILES_DIR,
                         "feff_dist_test/feff.inp")))
        self.assertTrue(
            str(feff_dict_input.header()) == str(
                Header.from_file(
                    os.path.join(PymatgenTest.TEST_FILES_DIR,
                                 "feff_dist_test/HEADER"))))
        feff_dict_input.write_input("feff_dist_regen")
        origin_tags = Tags.from_file(
            os.path.join(PymatgenTest.TEST_FILES_DIR,
                         "feff_dist_test/PARAMETERS"))
        output_tags = Tags.from_file(
            os.path.join(".", "feff_dist_regen/PARAMETERS"))
        origin_mole = Atoms.cluster_from_file(
            os.path.join(PymatgenTest.TEST_FILES_DIR,
                         "feff_dist_test/feff.inp"))
        output_mole = Atoms.cluster_from_file(
            os.path.join(".", "feff_dist_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(".", "feff_dist_regen"))
Example #6
0
 def test_get_string(self):
     cif_file = os.path.join(test_dir, 'CoO19128.cif')
     h = Header.from_cif_file(cif_file)
     head = str(h)
     self.assertEqual(head.splitlines()[3].split()[-1],
                      header_string.splitlines()[3].split()[-1],
                      "Failed to generate HEADER from structure")
Example #7
0
 def test_get_string(self):
     cif_file = os.path.join(test_dir, 'CoO19128.cif')
     h = Header.from_cif_file(cif_file)
     head = str(h)
     self.assertEqual(head.splitlines()[3].split()[-1],
                      header_string.splitlines()[3].split()[-1],
                      "Failed to generate HEADER from structure")
Example #8
0
 def test_get_string(self):
     header = Header.from_string(header_string)
     struc = header.struct
     central_atom = 'O'
     a = Atoms(struc, central_atom, radius=10.)
     atoms = str(a)
     self.assertEqual(atoms.splitlines()[3].split()[4], central_atom,
                      "failed to create ATOMS string")
Example #9
0
 def test_get_string(self):
     header = Header.from_string(header_string)
     struc = header.struct
     central_atom = 'O'
     a = Atoms(struc, central_atom, radius=10.)
     atoms = str(a)
     self.assertEqual(atoms.splitlines()[3].split()[4], central_atom,
                      "failed to create ATOMS string")
Example #10
0
    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"))
Example #11
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(test_dir, 'HEADER')
     header = Header.from_file(file_name)
     struct = header.struct
     pot = Potential(struct, 'O')
     d=pot.as_dict()
     pot2 = Potential.from_dict(d)
     self.assertEqual(str(pot), str(pot2),
                      "Potential to and from dict does not match")
Example #12
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(test_dir, 'HEADER')
     header = Header.from_file(file_name)
     struct = header.struct
     atoms = Atoms(struct, 'O', radius=10.)
     d = atoms.as_dict()
     atoms2 = Atoms.from_dict(d)
     self.assertEqual(str(atoms), str(atoms2),
                      "Atoms failed to and from dict test")
Example #13
0
 def test_get_string(self):
     cif_file = os.path.join(PymatgenTest.TEST_FILES_DIR, "CoO19128.cif")
     h = Header.from_cif_file(cif_file)
     head = str(h)
     self.assertEqual(
         head.splitlines()[3].split()[-1],
         header_string.splitlines()[3].split()[-1],
         "Failed to generate HEADER from structure",
     )
Example #14
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(PymatgenTest.TEST_FILES_DIR, "HEADER")
     header = Header.from_file(file_name)
     struct = header.struct
     pot = Potential(struct, "O")
     d = pot.as_dict()
     pot2 = Potential.from_dict(d)
     self.assertEqual(str(pot), str(pot2),
                      "Potential to and from dict does not match")
Example #15
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(PymatgenTest.TEST_FILES_DIR, "HEADER")
     header = Header.from_file(file_name)
     struct = header.struct
     atoms = Atoms(struct, "O", radius=10.0)
     d = atoms.as_dict()
     atoms2 = Atoms.from_dict(d)
     self.assertEqual(str(atoms), str(atoms2),
                      "Atoms failed to and from dict test")
Example #16
0
 def test_init(self):
     filepath = os.path.join(test_dir, 'HEADER')
     header = Header.header_string_from_file(filepath)
     h = header.splitlines()
     hs = header_string.splitlines()
     for i, line in enumerate(h):
         self.assertEqual(line, hs[i])
     self.assertEqual(header_string.splitlines(), header.splitlines(),
                      "Failed to read HEADER file")
Example #17
0
 def test_init(self):
     filepath = os.path.join(test_dir, 'HEADER')
     header = Header.header_string_from_file(filepath)
     h = header.splitlines()
     hs = header_string.splitlines()
     for i, line in enumerate(h):
         self.assertEqual(line, hs[i])
     self.assertEqual(header_string.splitlines(), header.splitlines(),
                      "Failed to read HEADER file")
Example #18
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(test_dir, 'HEADER')
     header = Header.from_file(file_name)
     struct = header.struct
     atoms = Atoms(struct, 'O', radius=10.)
     d = atoms.as_dict()
     atoms2 = Atoms.from_dict(d)
     self.assertEqual(str(atoms), str(atoms2),
                      "Atoms failed to and from dict test")
Example #19
0
 def test_as_dict_and_from_dict(self):
     file_name = os.path.join(test_dir, 'HEADER')
     header = Header.from_file(file_name)
     struct = header.struct
     pot = Potential(struct, 'O')
     d=pot.as_dict()
     pot2 = Potential.from_dict(d)
     self.assertEqual(str(pot), str(pot2),
                      "Potential to and from dict does not match")
Example #20
0
 def test_init(self):
     filepath = os.path.join(PymatgenTest.TEST_FILES_DIR, "HEADER")
     header = Header.header_string_from_file(filepath)
     h = header.splitlines()
     hs = header_string.splitlines()
     for i, line in enumerate(h):
         self.assertEqual(line, hs[i])
     self.assertEqual(
         header_string.splitlines(),
         header.splitlines(),
         "Failed to read HEADER file",
     )
Example #21
0
    def header(self, source='', comment=''):
        """
        Creates header string from structure object

        Args:
            source: Source identifier used to create structure, can be defined
                however user wants to organize structures, calculations, etc.
                example would be Materials Project material ID number.
            comment: comment to include in header

        Returns:
            Header
        """
        return Header(self.structure, source, comment)
Example #22
0
    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'))
Example #23
0
    def test_post_distdiff(self):
        feff_dict_input = FEFFDictSet.from_directory(os.path.join(test_dir, 'feff_dist_test'))
        self.assertTrue(feff_dict_input.tags == Tags.from_file(os.path.join(test_dir, 'feff_dist_test/feff.inp')))
        self.assertTrue(
            str(feff_dict_input.header()) == str(Header.from_file(os.path.join(test_dir, 'feff_dist_test/HEADER'))))
        feff_dict_input.write_input('feff_dist_regen')
        origin_tags = Tags.from_file(os.path.join(test_dir, 'feff_dist_test/PARAMETERS'))
        output_tags = Tags.from_file(os.path.join('.', 'feff_dist_regen/PARAMETERS'))
        origin_mole = Atoms.cluster_from_file(os.path.join(test_dir, 'feff_dist_test/feff.inp'))
        output_mole = Atoms.cluster_from_file(os.path.join('.', 'feff_dist_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('.', 'feff_dist_regen'))
Example #24
0
        coords=[
            [1 / 3, 2 / 3, 0.00000],
            [1 / 3, 2 / 3, 0.37780],
        ],
        coords_are_cartesian=False,
        tol=1e-9,
    )
    print(zno_structure)
    print(zno_structure.get_space_group_info())
    out_file_name = '/home/yugin/PycharmProjects/neurons/data/src/feff.inp.new2'
    file_name = '/home/yugin/PycharmProjects/neurons/data/src/feff.inp.old'
    atoms_obj = Atoms(zno_structure, 'O', 12)
    pprint(atoms_obj.struct.cart_coords)
    pprint(atoms_obj.get_lines())

    header_obj = Header(struct=zno_structure)
    pot_obj = Potential(zno_structure, 'O')


    tags_obj = Tags().from_file(filename=file_name)
    pprint(tags_obj.as_dict())

    pot_obj.pot_string_from_file(filename=file_name)
    pprint(pot_obj)
    atoms_obj.atoms_string_from_file(filename=file_name)
    pprint(atoms_obj.as_dict())

    header_obj.write_file(out_file_name)
    tags_obj.write_file(out_file_name)
    pot_obj.write_file(out_file_name)
    atoms_obj.write_file(out_file_name)
Example #25
0
 def init_header(self):
     self._header = Header(struct=self.structure, source=self.header_user_identifier, comment=self.header_comment)
Example #26
0
 def test_from_string(self):
     header = Header.from_string(header_string)
     self.assertEqual(header.struct.composition.reduced_formula, "CoO",
                      "Failed to generate structure from HEADER string")