Esempio n. 1
0
 def read_conf_file(self, filename):
     if not os.path.exists(filename):
         warning("file %s does not exist, but it will continue anyway!" %filename)
     else:
         c = open(filename, 'r')
         confs = self._conf
         is_continue = False
         for line in c:
             new_line=line.split("#")[0]
             if new_line.strip() == '':
                 is_continue = False
                 continue   
             
             if new_line.find('=') != -1:
                 left, right = [x.strip().lower() for x in new_line.split('=')]
                 if left.find("filename")!=-1 or left=="atom_type":
                     right=new_line.split("=")[1].strip()
                 confs[left] = right
                 
             if is_continue:
                 confs[left] += new_line.strip()
                 confs[left] = confs[left].replace('\\', ' ')
                 is_continue = False 
                 
             if new_line.find('\\') != -1:
                 is_continue = True
Esempio n. 2
0
    def plot_freq(self,is_plot=True, is_save=False):
        dirt=self.dirt
        try:
            import matplotlib.pyplot as plt
            freq=self.kappa_omega["frequency"]
            kappa=self.kappa_omega["kappa"]
            kappa_cum = self.kappa_omega['kappa_cum']
            plt.figure(figsize=(16,12))
            if dirt is not None:
                plt.plot(freq, kappa[:,dirt[0],dirt[1]],linewidth=3)
            else:
                plt.plot(freq,np.einsum("ijj",kappa), linewidth=3)
            plt.xlabel("Frequency(THz)",fontsize=18)
            plt.ylabel("Kappa(W/(m K THz))",fontsize=18)
            plt.title("thermal conductivity with frequency", fontsize=24)
            plt.figure(figsize=(16,12))
            if dirt is not None:
                plt.plot(freq, kappa_cum[:,dirt[0],dirt[1]],linewidth=3)
            else:
                plt.plot(freq,np.einsum("ijj",kappa_cum),linewidth=3)
            plt.xlabel("Frequency(THz)",fontsize=18)
            plt.ylabel("Kappa(W/(m K))",fontsize=18)

            if is_save:
                plt.savefig("kappa.pdf")
            if is_plot:
                plt.show()
        except ImportError:
            warning("lib matplotlib is not implemented, continuing anyway...")
Esempio n. 3
0
    def plot_time(self,is_plot=True, is_save=False):
        try:
            import matplotlib.pyplot as plt
            time_series = np.arange(self.corr_length) * self.time_step
            if self.dirt is not None:
                correlation = self.correlation[:,self.dirt[0], self.dirt[1]]
            else:
                correlation = np.einsum("ijj",self.correlation) / 3.0
            plt.figure(figsize=(8,6))
            eflux = self.eflux[0]
            plt.plot(np.arange(len(self.eflux[0])) * self.time_step, eflux)
            plt.figure(figsize=(8,6))
            plt.plot(time_series[:], correlation / correlation[0])
            # plt.plot(time_series[:], np.cumsum(correlation / correlation[0])/np.arange(1,len(correlation)+1))
            plt.xlabel("Time(ps)",fontsize=18)
            plt.ylabel("Autocorrelation (normalized)",fontsize=18)
            plt.title("Autocorrelation fuction with simulation time", fontsize=24)
            if is_save:
                plt.savefig("ACF.pdf")
            plt.figure(figsize=(8,6))
            kappa_cum = np.cumsum(correlation * self.time_step) * self.conversion_factor
            plt.plot(time_series,kappa_cum)
            plt.xlabel("Time(ps)",fontsize=18)
            plt.ylabel("Thermal conductivity (W/m-K)",fontsize=18)
            plt.title("Thermal conductivity with time", fontsize=24)

            if is_save:
                plt.savefig("KAPPA.pdf")
            if is_plot:
                plt.show()
        except ImportError:
            warning("lib matplotlib is not implemented, continuing anyway...")
Esempio n. 4
0
    def read_conf_file(self, filename):
        if not os.path.exists(filename):
            warning("file %s does not exist, but it will continue anyway!" %
                    filename)
        else:
            c = open(filename, 'r')
            confs = self._conf
            is_continue = False
            for line in c:
                new_line = line.split("#")[0]
                if new_line.strip() == '':
                    is_continue = False
                    continue

                if new_line.find('=') != -1:
                    left, right = [
                        x.strip().lower() for x in new_line.split('=')
                    ]
                    if left.find("filename") != -1 or left == "atom_type":
                        right = new_line.split("=")[1].strip()
                    confs[left] = right

                if is_continue:
                    confs[left] += new_line.strip()
                    confs[left] = confs[left].replace('\\', ' ')
                    is_continue = False

                if new_line.find('\\') != -1:
                    is_continue = True
Esempio n. 5
0
 def check_settting(self):
     if self.num_steps<self.sample_length:
         error("number of total time steps %d is lower than sampling length %d!" 
             % (self.num_steps, self.sample_length))
     if self.corr_length >= self.sample_length:
         error("correlation length %d is larger than sampling length %d!"
             %(self.corr_length, self.sample_length))
     elif self.sample_length-self.corr_length<5:
         warning("correlation of the last few time steps may be incorrect!")
Esempio n. 6
0
 def save_fe_to_hdf5(self, filename="md_fe.hdf5"):
     "save the force, energy, coordinate and velocity into a hdf5 file"
     try:
         import h5py
         write_md_to_hdf5(filename=filename,
                          force=self.atom_forces,
                          energy=self.atom_energies,
                          stress=self.atom_stresses)
     except ImportError:
         warning("h5py not implemented, velocities not saved")
Esempio n. 7
0
 def save_fe_to_hdf5(self, filename="md_fe.hdf5"):
     "save the force, energy, coordinate and velocity into a hdf5 file"
     try:
         import h5py
         write_md_to_hdf5(filename=filename,
                          force=self.atom_forces,
                          energy=self.atom_energies,
                          stress=self.atom_stresses)
     except ImportError:
         warning("h5py not implemented, velocities not saved")
Esempio n. 8
0
 def save_cv_to_hdf5(self, filename="md_cv.hdf5"):
     "Save the coordinate and velocity information into a hdf5 file"
     try:
         import h5py
         write_md_to_hdf5(filename=filename,
                          coordinate=self.atom_coordinates,
                          velocity=self.atom_velocities,
                          type=self.atom_types,
                          time_step=self.time_step)
         print "Coordinates and velocity information has been written to %s" % filename
     except ImportError:
         warning("h5py not implemented, velocities not saved")
Esempio n. 9
0
 def save_cv_to_hdf5(self, filename="md_cv.hdf5"):
     "Save the coordinate and velocity information into a hdf5 file"
     try:
         import h5py
         write_md_to_hdf5(filename=filename,
                          coordinate=self.atom_coordinates,
                          velocity=self.atom_velocities,
                          type=self.atom_types,
                          time_step=self.time_step)
         print "Coordinates and velocity information has been written to %s" %filename
     except ImportError:
         warning("h5py not implemented, velocities not saved")
Esempio n. 10
0
 def parameter_coupling(self):
     if self.input_filename is not None and not self._conf.has_key("file_format"):
         if self.input_filename.split(".")[-1]=="xyz":
             if self.file_format != "x":
                 warning("xyz file format detected, format converted forcibly!")
                 self.file_format="x"  
         elif self.input_filename.split(".")[-1]=="hdf5":
             if self.file_format != "h":
                 warning("hdf5 file format detected, format converted forcibly!")
                 self.file_format="h"
         elif self.input_filename == "XDATCAR":
             if self.file_format != "v":
                 warning("vasp file format detected, format converted forcibly!")
                 self.file_format="v"
     if self.file_format is not None:
         if self.file_format=="v":
             if self.input_filename is None:
                 print "XDATCAR as input file name used by default for the file format of vasp"
                 self.input_filename="XDATCAR"
         if self.file_format=="h":
             if self.input_filename is None:
                 print "md_velocities.hdf5 as input file name used by default for the file format of hdf5"
                 self.input_filename="md_velocities.hdf5"
             elif self.input_filename.split(".")[-1] != "hdf5":
                 warning("'filename.hdf5' should be used for hdf5 file type, 'md_velocities.hdf5' is used!")
                 self.input_filename="md_velocities.hdf5"
Esempio n. 11
0
 def parameter_coupling(self):
     if self.input_filename is not None and not self._conf.has_key(
             "file_format"):
         if self.input_filename.split(".")[-1] == "xyz":
             if self.file_format != "x":
                 warning(
                     "xyz file format detected, format converted forcibly!")
                 self.file_format = "x"
         elif self.input_filename.split(".")[-1] == "hdf5":
             if self.file_format != "h":
                 warning(
                     "hdf5 file format detected, format converted forcibly!"
                 )
                 self.file_format = "h"
         elif self.input_filename == "XDATCAR":
             if self.file_format != "v":
                 warning(
                     "vasp file format detected, format converted forcibly!"
                 )
                 self.file_format = "v"
     if self.file_format is not None:
         if self.file_format == "v":
             if self.input_filename is None:
                 print "XDATCAR as input file name used by default for the file format of vasp"
                 self.input_filename = "XDATCAR"
         if self.file_format == "h":
             if self.input_filename is None:
                 print "md_velocities.hdf5 as input file name used by default for the file format of hdf5"
                 self.input_filename = "md_velocities.hdf5"
             elif self.input_filename.split(".")[-1] != "hdf5":
                 warning(
                     "'filename.hdf5' should be used for hdf5 file type, 'md_velocities.hdf5' is used!"
                 )
                 self.input_filename = "md_velocities.hdf5"
Esempio n. 12
0
 def _save2hdf5(self, filename="md_fecv.hdf5"):
     "save the force, energy, coordinate and velocity into a hdf5 file"
     try:
         import h5py
     except ImportError:
         warning("h5py not implemented, velocities not saved")
         return
     o=h5py.File(filename,"w")
     if self.volume is not None:
         o.create_dataset("volume", data=self.volume)
     o.create_dataset("velocities", data=self.atom_velocities)
     o.create_dataset("coordinates", data=self.atom_coordinates)
     o.create_dataset("forces", data=self.atom_forces)
     o.create_dataset("energies",data=self.atom_energies)
     o.create_dataset("atom_types",data=self.atom_types)
     o.create_dataset("step_indices",data=self.step_indices)
     o.close()
Esempio n. 13
0
 def parameter_coupling(self):
     parameters = self._parameters
     if parameters.has_key("coord_filename") and parameters.has_key(
             "file_format"):
         coord_filename = parameters['coord_filename']
         file_format = parameters['file_format']
         if coord_filename is not None:
             if coord_filename.split(".")[-1] == "xyz":
                 if file_format != "x":
                     warning(
                         "xyz file format detected, format converted forcibly!"
                     )
                     self.set_parameter('file_format', "x")
             elif coord_filename.split(".")[-1] == "hdf5":
                 if file_format != "h":
                     warning(
                         "hdf5 file format detected, format converted forcibly!"
                     )
                     self.set_parameter('file_format', 'h')
             elif coord_filename == "XDATCAR":
                 if file_format != "v":
                     warning(
                         "vasp file format detected, format converted forcibly!"
                     )
                     self.set_parameter('file_format', "v")
Esempio n. 14
0
 def plot(self, is_plot=False, is_save=False):
     try:
         import matplotlib.pyplot as plt
         freq = self.dos["frequency"]
         dos = np.swapaxes(np.atleast_3d(self.dos["dos"]), 0, 1)
         for d in np.arange(dos.shape[-1]):  # dimension
             plt.figure(num=d, figsize=(16, 12))
             for s in np.arange(self.num_species):
                 plt.plot(freq,
                          dos[:, s, d],
                          linewidth=3,
                          label="specie %s" % str(self.species[s]))
             plt.xlabel("Frequency(THz)", fontsize=18)
             plt.ylabel("DOS(Arbitary unit)", fontsize=18)
             plt.title("phonon density of states", fontsize=24)
             plt.legend(fontsize=14)
             if is_save:
                 plt.savefig("dos_%d.pdf" % d)
             if is_plot:
                 plt.show()
     except ImportError:
         warning("lib matplotlib is not implemented, continuing anyway...")
Esempio n. 15
0
 def parameter_coupling(self):
     parameters = self._parameters
     if parameters.has_key("coord_filename") and parameters.has_key("file_format"):
         coord_filename = parameters['coord_filename']
         file_format = parameters['file_format']
         if coord_filename is not None:
             if coord_filename.split(".")[-1]=="xyz":
                 if file_format != "x":
                     warning("xyz file format detected, format converted forcibly!")
                     self.set_parameter('file_format', "x")
             elif coord_filename.split(".")[-1]=="hdf5":
                 if file_format != "h":
                     warning("hdf5 file format detected, format converted forcibly!")
                     self.set_parameter('file_format', 'h')
             elif coord_filename == "XDATCAR":
                 if file_format != "v":
                     warning("vasp file format detected, format converted forcibly!")
                     self.set_parameter('file_format', "v")
Esempio n. 16
0
    def __init__(self, options,option_list, args,config_file=None):
        Settings.__init__(self,options, option_list, args, config_file)
        if len(args) >= 3:
            self.md_input_filename = args[2]
            self.fe_input_filename=args[1]
        elif len(args) >= 2:
            warning("The general information file is set default as md.out")
            self.md_input_filename = "md.out"
            self.fe_input_filename = args[1]
        else:
            warning("The force_and_energy file is set default as heat_flux.out")
            warning("The general information file is set default as md.out")
            self.fe_input_filename= None
            self.md_input_filename = None
        self.temperature = 300
        self.is_convert_input = False
        self.volume = None
        self.is_difference = False
        self.hf_filename = None

        if options is not None:
            self._read_options()
        self._set_settings()
Esempio n. 17
0
    def __init__(self, options, option_list, args, config_file=None):
        Settings.__init__(self, options, option_list, args, config_file)
        if len(args) >= 3:
            self.md_input_filename = args[2]
            self.fe_input_filename = args[1]
        elif len(args) >= 2:
            warning("The general information file is set default as md.out")
            self.md_input_filename = "md.out"
            self.fe_input_filename = args[1]
        else:
            warning(
                "The force_and_energy file is set default as heat_flux.out")
            warning("The general information file is set default as md.out")
            self.fe_input_filename = None
            self.md_input_filename = None
        self.temperature = 300
        self.is_convert_input = False
        self.volume = None
        self.is_difference = False
        self.hf_filename = None

        if options is not None:
            self._read_options()
        self._set_settings()