コード例 #1
0
 def test_freq_dielectric(self):
     filepath = os.path.join(test_dir, "OUTCAR.LOPTICS")
     outcar = Outcar(filepath)
     outcar.read_freq_dielectric()
     self.assertAlmostEqual(outcar.frequencies[0], 0)
     self.assertAlmostEqual(outcar.frequencies[-1], 39.826101)
     self.assertAlmostEqual(outcar.dielectric_tensor_function[0][0, 0], 8.96938800)
     self.assertAlmostEqual(outcar.dielectric_tensor_function[-1][0, 0], 7.36167000e-01 +1.53800000e-03j)
     self.assertEqual(len(outcar.frequencies), len(outcar.dielectric_tensor_function))
コード例 #2
0
ファイル: test_outputs.py プロジェクト: bocklund/pymatgen
 def test_freq_dielectric_vasp544(self):
     filepath = os.path.join(test_dir, "OUTCAR.LOPTICS.vasp544")
     outcar = Outcar(filepath)
     outcar.read_freq_dielectric()
     self.assertAlmostEqual(outcar.frequencies[0], 0)
     self.assertAlmostEqual(outcar.frequencies[-1], 39.63964)
     self.assertAlmostEqual(outcar.dielectric_tensor_function[0][0, 0], 12.769435+0j)
     self.assertAlmostEqual(outcar.dielectric_tensor_function[-1][0, 0], 0.828615+0.016594j)
     self.assertEqual(len(outcar.frequencies), len(outcar.dielectric_tensor_function))
     np.testing.assert_array_equal( outcar.dielectric_tensor_function[0], outcar.dielectric_tensor_function[0].transpose())
コード例 #3
0
 def test_freq_dielectric_vasp544(self):
     filepath = os.path.join(test_dir, "OUTCAR.LOPTICS.vasp544")
     outcar = Outcar(filepath)
     outcar.read_freq_dielectric()
     self.assertAlmostEqual(outcar.frequencies[0], 0)
     self.assertAlmostEqual(outcar.frequencies[-1], 39.63964)
     self.assertAlmostEqual(outcar.dielectric_tensor_function[0][0, 0], 12.769435+0j)
     self.assertAlmostEqual(outcar.dielectric_tensor_function[-1][0, 0], 0.828615+0.016594j)
     self.assertEqual(len(outcar.frequencies), len(outcar.dielectric_tensor_function))
     np.testing.assert_array_equal( outcar.dielectric_tensor_function[0], outcar.dielectric_tensor_function[0].transpose())
コード例 #4
0
ファイル: optics.py プロジェクト: zezhong-zhang/vsc-workflows
    def from_file(cls, filename, fmt=None):
        """
        Initialize a DielTensor instance from a file.

        Args:
            filename (str): Path to file from which the dielectric data will be
                loaded. Can (so far) either be a vasprun.xml, OUTCAR or json file.
            fmt (str): Format of the file that contains the dielectric function
                data. Is optional, as the method can also figure out the format
                based on the filename.

        Returns:
            DielTensor: Dielectric tensor object from the dielectric data.

        """
        # Vasprun format: dielectric data is length 3 tuple
        if fmt == "vasprun" or filename.endswith(".xml"):

            dielectric_data = Vasprun(filename,
                                      parse_potcar_file=False).dielectric

            energies = np.array(dielectric_data[0])
            dielectric_tensor = np.array([
                to_matrix(*real_data) + 1j * to_matrix(*imag_data)
                for real_data, imag_data in zip(dielectric_data[1],
                                                dielectric_data[2])
            ])
            return cls(energies, dielectric_tensor)

        # OUTCAR format: dielectric data is length 2 tuple
        elif fmt == "outcar" or fnmatch(filename, "*OUTCAR*"):
            outcar = Outcar(filename)
            outcar.read_freq_dielectric()
            return cls(outcar.frequencies, outcar.dielectric_tensor_function)

        # JSON format
        if fmt == "json" or filename.endswith(".json"):
            with zopen(filename, "r") as f:
                return cls.from_dict(json.loads(f.read()))

        else:
            raise IOError("Format of file not recognized. Note: Currently "
                          "only vasprun.xml and OUTCAR files are supported.")