Exemple #1
0
    def get_frequencies(self, current_directory, gasphase=False):
        ''' Returns a list of vibrational frequcencies
        Vibrational frequency calculations are placed in a subdirectory
        named 'vib'
        Calculations from VASP or PHONONPY can be extracted
        If no vibrational frequencies is found an empty list is returned
        frequencies : list
        '''

        frequencies = []

        # Check if directory 'vib' exists and get frequencies
        if 'vib' in os.listdir(current_directory):
            print("   'vib' directory found")
            if os.path.isfile(
                    os.path.join(current_directory, 'vib', self.outcarfile)):
                viboutcar = OUTCAR(
                    os.path.join(current_directory, 'vib', self.outcarfile))
                frequencies = viboutcar.read_vibrational_frequencies(
                    gasphase=gasphase)
            elif os.path.isfile(
                    os.path.join(current_directory, 'vib', self.phononpyfile)):
                from vasp_outcar import PHONONPY
                viboutfile = PHONONPY(
                    os.path.join(current_directory, 'vib', self.phononpyfile))
                frequencies = viboutfile.read_vibrational_frequencies_phononpy(
                )
        return frequencies
Exemple #2
0
    def get_frequencies(self, current_directory, gasphase = False):
        ''' Returns a list of vibrational frequcencies
        Vibrational frequency calculations are placed in a subdirectory
        named 'vib'
        Calculations from VASP or PHONONPY can be extracted
        If no vibrational frequencies is found an empty list is returned
        frequencies : list
        '''

        frequencies = []

        # Check if directory 'vib' exists and get frequencies
        if 'vib' in os.listdir(current_directory):
            print("   'vib' directory found")
            if os.path.isfile(os.path.join(
                    current_directory, 'vib', self.outcarfile)):
                viboutcar = OUTCAR(os.path.join(
                    current_directory, 'vib', self.outcarfile))
                frequencies = viboutcar.read_vibrational_frequencies(
                    gasphase=gasphase)
            elif os.path.isfile(os.path.join(
                    current_directory, 'vib', self.phononpyfile)):
                from vasp_outcar import PHONONPY
                viboutfile = PHONONPY(
                    os.path.join(current_directory, 'vib', self.phononpyfile))
                frequencies = viboutfile.read_vibrational_frequencies_phononpy()
        return frequencies
Exemple #3
0
    def get_variables(self,
                      current_directory,
                      gasphase=False,
                      surface=False,
                      solid=False,
                      adsorbate=False,
                      ts=False,
                      species=None,
                      config=None,
                      system=None):
        '''Get the variables surface_name, composition, species_name, state,
        site_name, total_energy, frequencies, cell, positions, info
        from the VASP calculations
        '''

        system_name = self.rootdir.split('/')[-1]

        print('\nChecking --- ' + str(current_directory))

        # Check if outcarfile and contcarfile ie in the current_directory
        if (os.path.isfile(os.path.join(current_directory, self.outcarfile))
                and os.path.isfile(
                    os.path.join(current_directory, self.contcarfile))):
            outcar = OUTCAR(os.path.join(current_directory, self.outcarfile))
            contcar = CONTCAR(os.path.join(current_directory,
                                           self.contcarfile))

            # Checks if the OUTCAR file has completed -- will be
            # substituted with outcar.check_convergence
            finished = outcar.outcar_check()
            if finished is False:
                if surface:
                    print("   ERROR --- OUTCAR is not complete --- Exiting")
                    sys.exit()
                else:
                    print("    Warning --- OUTCAR file is not complete "
                          "--- This element is skipped")
                    variables = []
                return variables

        # if no contcar or outcar is in current_directory move to next
        else:
            print("    Warning --- No OUTCAR and/or CONTCAR file found "
                  "--- This element is skipped")
            variables = []
            return variables

        # Check if calculation has converged
        convergence = outcar.check_convergence()
        if convergence:
            print('    OUTCAR file - converged')
        #else:
        #print('WARNING --- Check convergency')

        # get chemical composition
        composition = contcar.read_composition(ordered=True)
        # get the total energy of the system
        total_energy = outcar.read_energy()

        # get the atomic super cell
        cell = contcar.read_cell()
        # get the atomic position of all elements
        positions = contcar.read_atoms_and_positions()
        # info is set as the given directory
        info = current_directory

        if gasphase:
            # check if atom/molecule is in defined molecules!!!! Add this

            # Set surface, site, species names and bulk_structure for
            # gasphase species
            surface_name = 'gasphase'
            species_name = contcar.read_composition(ordered=True, name=True)
            site_name = 'None'
            state = 'gasphase'

        if surface:
            # Set surface, site, species names and bulk_structure for
            # gasphase species
            surface_name = system_name
            site_name = 'None'
            species_name = contcar.read_composition(ordered=True)
            state = 'surface'

        if solid:
            # Set surface, site, species names and bulk_structure for
            # gasphase species
            surface_name = system_name
            site_name = 'None'
            species_name = contcar.read_composition(ordered=True)
            state = 'solid'

        if adsorbate:
            surface_name = system_name
            site_name = config
            surface_atoms = self.get_system_atoms(system=system)
            species_name = contcar.read_composition(adsorbed=True,
                                                    surface=surface_atoms,
                                                    name=True)
            state = species

        if ts:
            surface_name = system_name
            site_name = config
            surface_atoms = self.get_system_atoms(system=system)
            species_name = contcar.read_composition(adsorbed=True,
                                                    surface=surface_atoms,
                                                    name=True)

            state = species

            image = []
            for i in range(0, 40):
                if i < 10:
                    image.append(str(0) + str(i))
                else:
                    image.append(str(i))

            if 'dim' in current_directory.split('/'):
                print('    Dimer method - used')
            elif current_directory.split('/')[-1] in image:
                print('    (CI)-NEB method - used - image ' +
                      str(current_directory.split('/')[-1]) +
                      ' set as transition state '
                      '--- Check that this is the correct transition state')
            else:
                print('    Method for finding transition state not given')

        frequencies = self.get_frequencies(current_directory,
                                           gasphase=gasphase)

        # Check the number of imaginary frequencies
        j = 0
        for f in frequencies:
            if isinstance(f, complex):
                j = j + 1

        if j > 0 and ts is False:
            print("    WARNING --- " + str(j) + " imaginary frequencies found")

        elif j > 1 and ts is True:
            print("    WARNING --- " + str(j) +
                  " imaginary frequencies found - is this a true "
                  "transition state?")

        # make list containing information about surface species, species,
        # state, site, energy,
        # frequencies, cell, positions and info
        variables = [
            surface_name, composition, species_name, state, site_name,
            total_energy, frequencies, cell, positions, info
        ]

        print('    ' + str(variables[0:6]))

        return variables
Exemple #4
0
    def get_tslist(self, system=None):
        """
        Returns the calculated data regarding the transition states.
        Transition states data calculated using (CI-)NEB or dimer method can
        extracted
        Some updated are needed.
        """

        print("\n************ TRANSITION STATES ****************")

        # get the surface atom species and numbers
        #surface_atoms = self.get_surface_atoms()

        transition_state_dir, transition_states = self.tsdir_check(
            system=system)
        transition_state_list = []

        for transition_state in transition_states:
            # Get list of transition state configurations for ts
            config_dir = os.path.join(transition_state_dir, transition_state)
            configs = os.listdir(config_dir)

            for config in configs:
                ts_directory = os.path.join(config_dir, config)
                if os.path.isdir(ts_directory):
                    names = []

                    for i in os.listdir(ts_directory):
                        if os.path.isdir(ts_directory + '/' + i):
                            names.append(i)

                    # Check if dimer method is used
                    # If dim is present, results from dimer method will be used
                    if 'dim' in names:
                        if os.path.isfile(
                                os.path.join(ts_directory, 'dim',
                                             self.outcarfile)):
                            ts_dir = os.path.join(ts_directory, 'dim')
                        else:
                            print(
                                '    WARNING --- No OUTCAR/CONTCAR file found')
                            break

                    # Check if CI-NEB method is used
                    elif len(names) > 1:
                        # make a list with image number and energies
                        # the image with the highest energy is treated as the
                        # transition stat
                        # this can be changede
                        image_list = []
                        energy_list = []

                        for image in names:
                            if (image.startswith('0') or image.startswith('1')
                                    or image.startswith('2')):
                                # Make script for OUTCAR is .gz file

                                if os.path.isfile(
                                        os.path.join(ts_directory, image,
                                                     self.outcarfile)):
                                    outcar = OUTCAR(
                                        os.path.join(ts_directory, image,
                                                     self.outcarfile))
                                else:
                                    print('    WARNING --- No OUTCAR/CONTCAR '
                                          'file found')
                                    break

                                tot_energy = outcar.read_energy()
                                energy_list.append(tot_energy)
                                image_list.append(image)

                        # Find transition state energy and image number
                        index = energy_list.index(max(energy_list))

                        # Transition state image
                        ts_dir = os.path.join(ts_directory, image_list[index])
                    # The transisition state calculation is directly under
                    # the config_dir
                    elif os.path.isfile(
                            os.path.join(ts_directory, self.outcarfile)):
                        ts_dir = ts_directory

                    # No transition state is found
                    else:
                        print('    Warning --- no transition state files '
                              'found for ' + str(ts_directory))
                        break

                # get the variable for the adsorbed species
                variables = self.get_variables(ts_dir,
                                               ts=True,
                                               species=transition_state,
                                               config=config,
                                               system=system)

                variables_text = '\t'.join([str(w) for w in variables])
                transition_state_list.append(variables_text)

        return transition_state_list
Exemple #5
0
    def get_variables(self, current_directory, gasphase=False, surface=False,
                      solid=False, adsorbate=False, ts=False, species=None,
                      config=None, system=None):
        '''Get the variables surface_name, composition, species_name, state,
        site_name, total_energy, frequencies, cell, positions, info
        from the VASP calculations
        '''

        system_name = self.rootdir.split('/')[-1]

        print('\nChecking --- ' + str(current_directory))



        # Check if outcarfile and contcarfile ie in the current_directory
        if (os.path.isfile(os.path.join(
                current_directory, self.outcarfile)) and
            os.path.isfile(os.path.join(
                current_directory, self.contcarfile))):
            outcar = OUTCAR(os.path.join(current_directory, self.outcarfile))
            contcar = CONTCAR(os.path.join(current_directory, self.contcarfile))

            # Checks if the OUTCAR file has completed -- will be
            # substituted with outcar.check_convergence
            finished = outcar.outcar_check()
            if finished is False:
                if surface:
                    print("   ERROR --- OUTCAR is not complete --- Exiting")
                    sys.exit()
                else:
                    print("    Warning --- OUTCAR file is not complete "
                          "--- This element is skipped")
                    variables = []
                return variables

        # if no contcar or outcar is in current_directory move to next
        else:
            print("    Warning --- No OUTCAR and/or CONTCAR file found "
                  "--- This element is skipped")
            variables = []
            return variables


        # Check if calculation has converged
        convergence = outcar.check_convergence()
        if convergence:
            print('    OUTCAR file - converged')
        #else:
            #print('WARNING --- Check convergency')


        # get chemical composition
        composition = contcar.read_composition(ordered=True)
        # get the total energy of the system
        total_energy = outcar.read_energy()

        # get the atomic super cell
        cell = contcar.read_cell()
        # get the atomic position of all elements
        positions = contcar.read_atoms_and_positions()
        # info is set as the given directory
        info = current_directory

        if gasphase:
            # check if atom/molecule is in defined molecules!!!! Add this

            # Set surface, site, species names and bulk_structure for
            # gasphase species
            surface_name = 'gasphase'
            species_name = contcar.read_composition(ordered=True, name=True)
            site_name = 'None'
            state = 'gasphase'

        if surface:
            # Set surface, site, species names and bulk_structure for
            # gasphase species
            surface_name = system_name
            site_name = 'None'
            species_name = contcar.read_composition(ordered=True)
            state = 'surface'

        if solid:
            # Set surface, site, species names and bulk_structure for
            # gasphase species
            surface_name = system_name
            site_name = 'None'
            species_name = contcar.read_composition(ordered=True)
            state = 'solid'

        if adsorbate:
            surface_name = system_name
            site_name = config
            surface_atoms = self.get_system_atoms(system=system)
            species_name = contcar.read_composition(
                adsorbed=True, surface=surface_atoms, name=True)
            state = species

        if ts:
            surface_name = system_name
            site_name = config
            surface_atoms = self.get_system_atoms(system=system)
            species_name = contcar.read_composition(
                adsorbed=True, surface=surface_atoms, name=True)

            state = species


            image = []
            for i in range(0,40):
                if i < 10:
                    image.append(str(0)+str(i))
                else:
                    image.append(str(i))

            if 'dim' in current_directory.split('/'):
                print('    Dimer method - used')
            elif current_directory.split('/')[-1] in image:
                print('    (CI)-NEB method - used - image ' +
                      str(current_directory.split('/')[-1]) +
                      ' set as transition state '
                      '--- Check that this is the correct transition state')
            else:
                print('    Method for finding transition state not given')


        frequencies = self.get_frequencies(
            current_directory, gasphase = gasphase)

        # Check the number of imaginary frequencies
        j = 0
        for f in frequencies:
            if isinstance(f, complex):
                j = j + 1

        if j > 0 and ts is False:
            print("    WARNING --- " + str(j) + " imaginary frequencies found")

        elif j > 1 and ts is True:
            print("    WARNING --- " + str(j) +
                  " imaginary frequencies found - is this a true "
                  "transition state?")

        # make list containing information about surface species, species,
        # state, site, energy,
        # frequencies, cell, positions and info
        variables = [surface_name, composition, species_name, state, site_name,
                         total_energy, frequencies,
                         cell, positions, info]

        print('    ' + str(variables[0:6]))

        return variables
Exemple #6
0
    def get_tslist(self, system=None):
        """
        Returns the calculated data regarding the transition states.
        Transition states data calculated using (CI-)NEB or dimer method can
        extracted
        Some updated are needed.
        """

        print("\n************ TRANSITION STATES ****************")

        # get the surface atom species and numbers
        #surface_atoms = self.get_surface_atoms()

        transition_state_dir, transition_states = self.tsdir_check(
            system=system)
        transition_state_list = []

        for transition_state in transition_states:
            # Get list of transition state configurations for ts
            config_dir = os.path.join(transition_state_dir, transition_state)
            configs = os.listdir(config_dir)

            for config in configs:
                ts_directory = os.path.join(config_dir, config)
                if os.path.isdir(ts_directory):
                    names = []

                    for i in os.listdir(ts_directory):
                        if os.path.isdir(ts_directory + '/' + i):
                            names.append(i)


                    # Check if dimer method is used
                    # If dim is present, results from dimer method will be used
                    if 'dim' in names:
                        if os.path.isfile(os.path.join(
                                ts_directory, 'dim', self.outcarfile)):
                            ts_dir = os.path.join(ts_directory, 'dim')
                        else:
                            print(
                                '    WARNING --- No OUTCAR/CONTCAR file found')
                            break

                    # Check if CI-NEB method is used
                    elif len(names) > 1:
                        # make a list with image number and energies
                        # the image with the highest energy is treated as the
                        # transition stat
                        # this can be changede
                        image_list = []
                        energy_list = []

                        for image in names:
                            if (image.startswith('0') or
                                image.startswith('1') or
                                image.startswith('2')):
                                # Make script for OUTCAR is .gz file

                                if os.path.isfile(os.path.join(
                                        ts_directory, image, self.outcarfile)):
                                    outcar = OUTCAR(os.path.join(
                                        ts_directory, image, self.outcarfile))
                                else:
                                    print('    WARNING --- No OUTCAR/CONTCAR '
                                          'file found')
                                    break

                                tot_energy = outcar.read_energy()
                                energy_list.append(tot_energy)
                                image_list.append(image)

                        # Find transition state energy and image number
                        index = energy_list.index(max(energy_list))

                        # Transition state image
                        ts_dir = os.path.join(ts_directory, image_list[index])
                    # The transisition state calculation is directly under
                    # the config_dir
                    elif os.path.isfile(
                            os.path.join(ts_directory, self.outcarfile)):
                        ts_dir = ts_directory

                    # No transition state is found
                    else:
                        print('    Warning --- no transition state files '
                              'found for ' + str(ts_directory))
                        break

                # get the variable for the adsorbed species
                variables = self.get_variables(
                    ts_dir, ts=True, species=transition_state, config=config,
                    system=system)

                variables_text = '\t'.join([str(w) for w in variables])
                transition_state_list.append(variables_text)

        return transition_state_list