def initialize_run_list(self):
		"""sets self.vasp_run_list based on directories present"""

		self.vasp_run_list = []

		for i in range(self.external_relaxation_count):
			run_path = self.get_extended_path(VaspRelaxation.external_relax_basename_string + str(i+1))
			if Path.exists(run_path):
				self.vasp_run_list.append(VaspRun(run_path))
			else:
				return

		static_path = self.get_extended_path(VaspRelaxation.static_basename_string)
		if Path.exists(static_path):
			self.vasp_run_list.append(VaspRun(static_path))
	def create_next_run(self):
		run_path = self.get_next_run_path()


		structure = self.get_next_structure()
		kpoints = Kpoints(scheme_string=self.kpoint_schemes[self.run_count], subdivisions_list=self.kpoint_subdivisions_lists[self.run_count])
		incar = self.get_next_incar()

		submission_script_file = None
		if self.submission_script_modification_keys_list:
			submission_script_file = QueueAdapter.modify_submission_script(QueueAdapter.get_submission_file(), self.submission_script_modification_keys_list[self.run_count])

		input_set = VaspInputSet(structure, kpoints, incar, submission_script_file=submission_script_file, calculation_type=self.calculation_type)

		#Override node count in submission script over the auto generated count based on atom count
		if self.submission_node_count_list:
			input_set.set_node_count(self.submission_node_count_list[self.run_count])
			input_set.set_npar_from_number_of_cores()

		#override npar if inputted
		for key in self.incar_modifier_lists_dictionary.keys():
			if key.upper() == 'NPAR':
				input_set.incar['npar'] = self.incar_modifier_lists_dictionary['npar'][self.run_count]

		vasp_run = VaspRun(run_path, input_set=input_set, wavecar_path=self.get_wavecar_path())

		#self.run_count += 1 #increment at end - this tracks how many runs have been created up to now
		self.vasp_run_list.append(vasp_run)
    def create_new_vasp_run(self, path, structure):
        """
		Creates a static force calculation at path using structure as the initial structure and self.vasp_run_inputs as the run inputs.
		"""

        run_inputs = copy.deepcopy(self.vasp_run_inputs)

        if 'submission_node_count' in run_inputs:
            node_count = run_inputs.pop('submission_node_count')
        else:
            node_count = None

        kpoints = Kpoints(
            scheme_string=run_inputs.pop('kpoint_scheme'),
            subdivisions_list=run_inputs.pop('kpoint_subdivisions_list'))
        incar = IncarMaker.get_static_incar(run_inputs)

        input_set = VaspInputSet(structure,
                                 kpoints,
                                 incar,
                                 auto_change_lreal=('lreal' not in run_inputs),
                                 auto_change_npar=('npar' not in run_inputs))

        if node_count != None:
            input_set.set_node_count(node_count)

            if 'npar' not in run_inputs:
                input_set.set_npar_from_number_of_cores()

        vasp_run = VaspRun(path=path,
                           input_set=input_set,
                           wavecar_path=self.wavecar_path)
Exemple #4
0
def encut_converger(base_path, structure, encut_list, base_kpoints_scheme, base_kpoints_subdivisions_list, base_ediff):
    """Takes in a structure, set of encuts, and base params and runs set in base_path""" 
    encut_convergence_set_path = Path.clean(base_path)
    Path.make(encut_convergence_set_path)
    
    for encut in encut_list:
        run_path = Path.join(encut_convergence_set_path, str(encut))
        
        kpoints = Kpoints(scheme_string=base_kpoints_scheme, subdivisions_list=base_kpoints_subdivisions_list)
        incar = IncarMaker.get_static_incar({'ediff':base_ediff, 'encut':encut})
        input_set = VaspInputSet(structure, kpoints, incar)
        
        vasp_run = VaspRun(run_path, input_set=input_set, verbose=False)
        
        if vasp_run.update():
            print encut, round(vasp_run.outcar.energy_per_atom, 5), round(vasp_run.outcar.get_calculation_time_in_core_hours(), 2)
        else:
            pass
Exemple #5
0
    def initialize_vasp_lepsilon_calculation(self):
        """
		Sets up a run for the calculation of dielectric and born effective charge tensors. This is necessary if the Non-Analytical correction is used (for polar materials).
		"""

        kpoints = Kpoints(
            scheme_string=self.vasp_run_inputs['kpoint_scheme'],
            subdivisions_list=[
                self.vasp_run_inputs['kpoint_subdivisions_list'][i] *
                self.phonopy_inputs['supercell_dimensions'][i]
                for i in range(3)
            ])
        incar = IncarMaker.get_lepsilon_incar()
        incar['encut'] = self.vasp_run_inputs['encut']

        input_set = VaspInputSet(self.initial_structure,
                                 kpoints,
                                 incar,
                                 auto_change_npar=False)

        self.lepsilon_calculation = VaspRun(
            path=self.get_lepsion_calculation_path(), input_set=input_set)
Exemple #6
0
def kpoints_converger(base_path, structure, kpoints_lists, base_kpoints_scheme, base_encut, base_ediff, incar_modification_dictionary=None):
    convergence_set_path = Path.clean(base_path)
    Path.make(convergence_set_path)

    for kpoints_list in kpoints_lists:
        run_path = Path.join(convergence_set_path, "_".join(str(kpoints) for kpoints in kpoints_list))

        kpoints = Kpoints(scheme_string=base_kpoints_scheme, subdivisions_list=kpoints_list)
        incar_mod = {'ediff':base_ediff, 'encut':base_encut}
        
        if incar_modification_dictionary:
            for key, value in incar_modification_dictionary.items():
                incar_mod[key] = value
                
        incar = IncarMaker.get_static_incar(incar_mod)
        
        input_set = VaspInputSet(structure, kpoints, incar)

        vasp_run = VaspRun(run_path, input_set=input_set, verbose=False)

        if vasp_run.update():
            print "_".join(str(kpoints) for kpoints in kpoints_list), round(vasp_run.outcar.energy_per_atom, 5), round(vasp_run.outcar.get_calculation_time_in_core_hours(), 2)
        else:
            vasp_run.view(['kpoints','_job_output.txt'])
	def create_new_vasp_run(self, path, structure):
		"""
		Creates a static force calculation at path using structure as the initial structure and self.vasp_run_inputs as the run inputs.
		"""

		kpoints = Kpoints(scheme_string=self.vasp_run_inputs['kpoint_scheme'], subdivisions_list=self.vasp_run_inputs['kpoint_subdivisions_list'])
		incar = IncarMaker.get_accurate_forces_incar()
		incar['encut'] = self.vasp_run_inputs['encut']

		if 'npar' in self.vasp_run_inputs:
			incar['npar'] = self.vasp_run_inputs['npar']
			auto_change_npar = False
		else:
			auto_change_npar = True

		input_set = VaspInputSet(structure, kpoints, incar, auto_change_lreal=False, auto_change_npar=auto_change_npar)

		vasp_run = VaspRun(path=path, input_set=input_set, wavecar_path=self.wavecar_path)
Exemple #8
0
    def get_current_dos_count(self):
        pre = 'hybrid_electronic_optimization_'

        current = 0
        while Path.exists(Path.join(self.dos_path, pre + str(current + 1))):
            current += 1

        if current == 0:
            return 0
        else:
            run_path = Path.join(self.dos_path, pre + str(current))

            current_dos_run = VaspRun(path=run_path)

            if current_dos_run.complete:
                return current + 1
            else:
                return current
    def get_energy_of_eigen_chromosome(self, path, eigen_chromosome):

        # print "chrom " + str(eigen_chromosome)

        structure = self.get_distorted_structure_from_eigen_chromosome(
            eigen_chromosome)

        run_inputs = copy.deepcopy(self.vasp_run_inputs_dictionary)

        if 'submission_node_count' in run_inputs:
            node_count = run_inputs.pop('submission_node_count')
        else:
            node_count = None

        kpoints = Kpoints(
            scheme_string=run_inputs.pop('kpoint_scheme'),
            subdivisions_list=run_inputs.pop('kpoint_subdivisions_list'))
        incar = IncarMaker.get_static_incar(run_inputs)

        input_set = VaspInputSet(structure,
                                 kpoints,
                                 incar,
                                 auto_change_lreal=('lreal' not in run_inputs),
                                 auto_change_npar=('npar' not in run_inputs))

        if node_count != None:
            input_set.set_node_count(node_count)

            if 'npar' not in run_inputs:
                input_set.set_npar_from_number_of_cores()

        vasp_run = VaspRun(
            path=path,
            input_set=input_set,
            wavecar_path=self.reference_completed_vasp_relaxation_run.
            get_wavecar_path())

        vasp_run.update()

        if vasp_run.complete:
            vasp_run.delete_wavecar_if_complete()
            return vasp_run.get_final_energy(per_atom=False)
        else:
            return None
Exemple #10
0

if not relaxation.complete:
	relaxation.update()
else:
	
	relaxed_structure = relaxation.final_structure


	force_calculation_path = Path.join(base_path, 'dfpt_force_calculation')

	kpoints = Kpoints(scheme_string=kpoint_scheme, subdivisions_list=kpoint_subdivisions_list)
	incar = IncarMaker.get_dfpt_hessian_incar(dfpt_incar_settings)
	input_set = VaspInputSet(relaxed_structure, kpoints, incar, auto_change_lreal=False, auto_change_npar=False)

	dfpt_force_run = VaspRun(path=force_calculation_path, input_set=input_set)

	if not dfpt_force_run.complete:
		dfpt_force_run.update()


	else:

		hessian = Hessian(dfpt_force_run.outcar)
		#hessian.print_eigen_components()
		hessian.print_eigenvalues()




		guessed_minima_data_path = Path.join(base_path, 'guessed_chromosomes')
def term_acceptance_function(expansion_term):

	variables = expansion_term.get_active_variables()

	if not expansion_term.is_pure_type('strain')

	#remove all terms with in-plane strain variables in them - these are fixed to 0 for (100) epitaxy
	for variable in variables:
		if variable.type_string == 'strain' and variable.index in [0, 1, 5]:
			return False

	#assume no forces or stresses on the cell
	if expansion_term.order == 1: 
		return False

	#only expand to second order w.r.t. strain
	if expansion_term.is_pure_type('strain') and expansion_term.order > 2:
		return False

	#for perovskite structure under arbitrary homogeneous strain, displacement terms are centrosymmetric
	if expansion_term.is_centrosymmetric():
		return False

	#only go to fourth order in single variable dsiplacement terms - don't do fourth order cross terms
	if expansion_term.order == 4 and not expansion_term.has_single_variable():
		return False

	return True


taylor_expansion = TaylorExpansion(variables_list=variables, term_acceptance_function=term_acceptance_function)

print
print "Number of terms:", len(taylor_expansion)


print '\n\t\t',
print taylor_expansion
print '\n'*3




base_path = "./"


perturbation_magnitudes_dictionary = {'strain': 0.01, 'displacement': 0.2}


a = 3.79
Nx = 1
Ny = 1
Nz = 1

vasp_run_inputs_dictionary = {
	'kpoint_scheme': 'Monkhorst',
	'kpoint_subdivisions_list': [8, 8, 8],
	'encut': 900,
	'addgrid': True
}

relaxation_input_dictionary= {
    'external_relaxation_count': 3,
    'isif': [6],
    'kpoint_schemes_list': [vasp_run_inputs_dictionary['kpoint_scheme']],
    'kpoint_subdivisions_lists': [vasp_run_inputs_dictionary['kpoint_subdivisions_list']],
    'ediff': [0.00001, 1e-7, 1e-9],
    'encut': [vasp_run_inputs_dictionary['encut']],
    'submission_script_modification_keys_list': ['100'],
    'lwave': [True]
}


initial_structure=Perovskite(supercell_dimensions=[Nx, Ny, Nz], lattice=[[a*Nx, 0.0, 0.0], [0.0, a*Ny, 0.0], [0.0, 0.0, a*Nz*1.02]], species_list=['Sr', 'Ti', 'O'])


relaxation = VaspRelaxation(path=Path.join(base_path, 'relaxation'), initial_structure=initial_structure, input_dictionary=relaxation_input_dictionary)


if not relaxation.complete:
	relaxation.update()
else:
	
	relaxed_structure = relaxation.final_structure

	force_calculation_path = Path.join(base_path, 'dfpt_force_calculation')

	kpoints = Kpoints(scheme_string=vasp_run_inputs_dictionary['kpoint_scheme'], subdivisions_list=vasp_run_inputs_dictionary['kpoint_subdivisions_list'])
	incar = IncarMaker.get_dfpt_hessian_incar({'encut': vasp_run_inputs_dictionary['encut']})

	input_set = VaspInputSet(relaxed_structure, kpoints, incar, auto_change_lreal=False, auto_change_npar=False)

	dfpt_force_run = VaspRun(path=force_calculation_path, input_set=input_set)

	if not dfpt_force_run.complete:
		dfpt_force_run.update()
	else:

		hessian = Hessian(dfpt_force_run.outcar)

		eigen_structure = EigenStructure(reference_structure=relaxed_structure, hessian=hessian)
		eigen_structure.print_eigen_components()



		de_path = Path.join(base_path, 'term_coefficient_calculations')
		derivative_evaluator = DerivativeEvaluator(path=de_path, reference_structure=relaxed_structure, hessian=hessian, taylor_expansion=taylor_expansion, 
			reference_completed_vasp_relaxation_run=relaxation, vasp_run_inputs_dictionary=vasp_run_inputs_dictionary, perturbation_magnitudes_dictionary=perturbation_magnitudes_dictionary)

		derivative_evaluator.update()

		print derivative_evaluator.taylor_expansion
 def vasp_run_list(self):
     return [
         VaspRun(path=run_path) for run_path in self.get_run_paths_list()
     ]
def run_misfit_strain(path, misfit_strain, input_dictionary,
                      initial_relaxation_input_dictionary, dfpt_incar_settings,
                      derivative_evaluation_vasp_run_inputs_dictionary,
                      minima_relaxation_input_dictionary,
                      epitaxial_relaxation_input_dictionary):

    Path.make(path)
    guessed_minima_data_path = Path.join(path, 'guessed_chromosomes')

    species_list = input_dictionary['species_list']
    reference_lattice_constant = input_dictionary['reference_lattice_constant']
    Nx = input_dictionary['supercell_dimensions_list'][0]
    Ny = input_dictionary['supercell_dimensions_list'][1]
    Nz = input_dictionary['supercell_dimensions_list'][2]
    displacement_finite_differences_step_size = input_dictionary[
        'displacement_finite_differences_step_size']
    perturbation_magnitudes_dictionary = input_dictionary[
        'perturbation_magnitudes_dictionary']

    a = reference_lattice_constant * (1.0 + misfit_strain)

    initial_structure = Perovskite(
        supercell_dimensions=[Nx, Ny, Nz],
        lattice=[[a * Nx, 0.0, 0.0], [0.0, a * Ny, 0.0],
                 [
                     0.0, 0.0, reference_lattice_constant * Nz *
                     (1.0 + 0.3 * (1.0 - (a / reference_lattice_constant)))
                 ]],
        species_list=species_list)
    relaxation = VaspRelaxation(
        path=Path.join(path, 'relaxation'),
        initial_structure=initial_structure,
        input_dictionary=initial_relaxation_input_dictionary)

    if not relaxation.complete:
        relaxation.update()
        return False

    relaxed_structure = relaxation.final_structure

    relaxed_structure_path = Path.join(path, 'output_relaxed_structure')
    relaxed_structure.to_poscar_file_path(relaxed_structure_path)

    force_calculation_path = Path.join(path, 'dfpt_force_calculation')

    kpoints = Kpoints(scheme_string=kpoint_scheme,
                      subdivisions_list=kpoint_subdivisions_list)
    incar = IncarMaker.get_dfpt_hessian_incar(dfpt_incar_settings)
    input_set = VaspInputSet(relaxed_structure,
                             kpoints,
                             incar,
                             auto_change_lreal=False,
                             auto_change_npar=False)
    input_set.incar['lepsilon'] = True

    dfpt_force_run = VaspRun(path=force_calculation_path, input_set=input_set)

    if not dfpt_force_run.complete:
        dfpt_force_run.update()
        return False

    hessian = Hessian(dfpt_force_run.outcar)

    if input_dictionary['write_hessian_data']:
        hessian.print_eigenvalues_to_file(
            Path.join(path, 'output_eigen_values'))
        hessian.print_eigen_components_to_file(
            Path.join(path, 'output_eigen_components'))
        hessian.print_mode_effective_charge_vectors_to_file(
            Path.join(path, 'output_mode_effective_charge_vectors'),
            relaxed_structure)

        eigen_structure = EigenStructure(reference_structure=relaxed_structure,
                                         hessian=hessian)

        mode_structures_path = Path.join(path, 'mode_rendered_structures')
        Path.make(mode_structures_path)

        mode_charge_file = File(
            Path.join(path, 'output_mode_effective_charge_vectors'))

        sorted_eigen_pairs = hessian.get_sorted_hessian_eigen_pairs_list()
        for i, structure in enumerate(
                eigen_structure.get_mode_distorted_structures_list(
                    amplitude=0.6)):
            if i > 30:
                break
            structure.to_poscar_file_path(
                Path.join(
                    mode_structures_path, 'u' + str(i + 1) + '_' +
                    str(round(sorted_eigen_pairs[i].eigenvalue, 2)) + '.vasp'))

            structure.lattice = Lattice([[8.0, 0.0, 0.0], [0.0, 8.0, 0.0],
                                         [0.0, 0.0, 8.0]])

            mode_charge_file[i] += '    ' + structure.get_spacegroup_string(
                symprec=0.2) + '  ' + structure.get_spacegroup_string(
                    symprec=0.1) + '  ' + structure.get_spacegroup_string(
                        symprec=0.001)

        mode_charge_file.write_to_path()
    #sys.exit()

    ################################################### random structure searcher
    if True:
        rand_path = Path.join(path, 'random_trials')
        Path.make(rand_path)

        num_guesses = 1
        num_modes = 12
        max_amplitude = 0.6

        if misfit_strain == 0.02:
            eigen_structure = EigenStructure(
                reference_structure=relaxed_structure, hessian=hessian)

            for i in range(num_guesses):
                trial_path = Path.join(rand_path, str(i))

                if not Path.exists(trial_path):
                    initial_structure_trial = eigen_structure.get_random_structure(
                        mode_count_cutoff=num_modes,
                        max_amplitude=max_amplitude)
                    trial_relaxation = VaspRelaxation(
                        path=trial_path,
                        initial_structure=initial_structure_trial,
                        input_dictionary=minima_relaxation_input_dictionary)
                else:
                    trial_relaxation = VaspRelaxation(path=trial_path)

                print "Updating random trial relaxation at " + trial_relaxation.path + "  Status is " + trial_relaxation.get_status_string(
                )
                trial_relaxation.update()

                if trial_relaxation.complete:
                    print "Trial " + str(i)
                    print trial_relaxation.get_data_dictionary()

        return None
    ###################################################

    if not Path.exists(guessed_minima_data_path):
        variable_specialty_points_dictionary = input_dictionary[
            'variable_specialty_points_dictionary_set'][
                misfit_strain] if input_dictionary.has_key(
                    misfit_strain) else {}

        derivative_evaluation_path = Path.join(
            path, 'expansion_coefficient_calculations')
        derivative_evaluator = DerivativeEvaluator(
            path=derivative_evaluation_path,
            reference_structure=relaxed_structure,
            hessian=hessian,
            reference_completed_vasp_relaxation_run=relaxation,
            vasp_run_inputs_dictionary=
            derivative_evaluation_vasp_run_inputs_dictionary,
            perturbation_magnitudes_dictionary=
            perturbation_magnitudes_dictionary,
            displacement_finite_differences_step_size=
            displacement_finite_differences_step_size,
            status_file_path=Path.join(path, 'output_derivative_plot_data'),
            variable_specialty_points_dictionary=
            variable_specialty_points_dictionary,
            max_displacement_variables=input_dictionary[
                'max_displacement_variables'])

        derivative_evaluator.update()

    else:
        minima_path = Path.join(path, 'minima_relaxations')

        minima_relaxer = MinimaRelaxer(
            path=minima_path,
            reference_structure=relaxed_structure,
            reference_completed_vasp_relaxation_run=relaxation,
            hessian=hessian,
            vasp_relaxation_inputs_dictionary=
            minima_relaxation_input_dictionary,
            eigen_chromosome_energy_pairs_file_path=guessed_minima_data_path,
            log_base_path=path,
            max_minima=input_dictionary['max_minima'])

        minima_relaxer.update()
        minima_relaxer.print_status_to_file(
            Path.join(path, 'output_minima_relaxations_status'))

        if minima_relaxer.complete:
            print "Minima relaxer complete: sorting the relaxations to find the lowest energy structure."
            #minima_relaxer.print_selected_uniques_to_file(file_path=Path.join(path, 'output_selected_unique_minima_relaxations'))
            sorted_uniques = minima_relaxer.get_sorted_unique_relaxation_data_list(
            )

            return sorted_uniques
Exemple #14
0
class VaspPhonon(VaspRunSet):
    """
	Represents a phonon run in vasp built on the phonopy finite differences framework. 
	This class takes as input an initial structure and parameters for the static force calculations
	as well as phonopy parameters.

	Upon finishing, the force constants file and (potentially) the BORN file are written out. These two files can be used to initialize
	a phonopy instance for analysis of eigenvalues/vectors, dispersion relations, and so forth.

	The file structure is:

	path
	 |
	 ----------------force_calculations--------------lepsilon_calculation-----------FORCE_CONSTANTS-------------BORN
	 					   |                                |
	 		0----1----2---3----4----5---...              INCAR---POSCAR---...
	 		|
	 	INCAR----POSCAR----...
	"""
    def __init__(self, path, initial_structure, phonopy_inputs_dictionary,
                 vasp_run_inputs_dictionary):
        """
		path holds the main path of the calculation sets

		initial_structure should be some small Structure instance for which one wishes to calculate phonons

		phonopy_inputs should be a dictionary that looks like:

		phonopy_inputs_dictionary = {
			'supercell_dimensions': [2, 2, 2],
			'symprec': 0.001,
			'displacement_distance': 0.01,
			'nac': True
			...
		}

		vasp_run_inputs_dictionary should be a dictionary that looks like:

		vasp_run_inputs_dictionary = {
			'kpoint_scheme': 'Monkhorst',
			'kpoint_subdivisions_list': [4, 4, 4], #***This is the kpoints of the supercell, not the primitive cell!!!***
			'encut': 800
		}
		"""

        self.path = path
        self.initial_structure = initial_structure
        self.phonopy_inputs = phonopy_inputs_dictionary
        self.vasp_run_inputs = vasp_run_inputs_dictionary
        self.forces_run_set = None  #holds set of force calculations on distorted structures
        self.lepsilon_calculation = None  #calculates dielectric tensor and born effective charge if nac is needed

        Path.make(path)

        self.initialize_forces_run_set()

        if self.has_nac():
            self.initialize_vasp_lepsilon_calculation()

        self.update()

    def initialize_forces_run_set(self):
        """
		Creates the set of force calculation vasp runs on the phonopy generated list of distorted structures.
		"""

        self.forces_run_set = VaspForcesRunSet(
            path=self.get_forces_run_set_path(),
            structures_list=self.get_distorted_structures_list(),
            vasp_run_inputs_dictionary=self.vasp_run_inputs,
            wavecar_path=None)

    def get_distorted_structures_list(self):
        """
		Returns list of Structure instances containing the distorted structures determined as necessary to calculate the forces of by phonopy.
		"""

        #########make sure we're using proper initial structure if there was reoptimization#####################################################################################

        return phonopy_utility.get_distorted_structures_list(
            initial_structure=self.initial_structure,
            phonopy_inputs=self.phonopy_inputs)

    def initialize_vasp_lepsilon_calculation(self):
        """
		Sets up a run for the calculation of dielectric and born effective charge tensors. This is necessary if the Non-Analytical correction is used (for polar materials).
		"""

        kpoints = Kpoints(
            scheme_string=self.vasp_run_inputs['kpoint_scheme'],
            subdivisions_list=[
                self.vasp_run_inputs['kpoint_subdivisions_list'][i] *
                self.phonopy_inputs['supercell_dimensions'][i]
                for i in range(3)
            ])
        incar = IncarMaker.get_lepsilon_incar()
        incar['encut'] = self.vasp_run_inputs['encut']

        input_set = VaspInputSet(self.initial_structure,
                                 kpoints,
                                 incar,
                                 auto_change_npar=False)

        self.lepsilon_calculation = VaspRun(
            path=self.get_lepsion_calculation_path(), input_set=input_set)

    def update(self):
        """
		Runs update on all force calculations (and potentially the lepsilon calculation) until they are all complete. 
		Once they are all complete, the force constants are generated and written to file, completing the phonon calculation.
		"""

        if not self.complete:
            self.forces_run_set.update()

            if self.has_nac():
                self.lepsilon_calculation.update()

        else:
            #write the final results to file so that they can be used to initialize a phonopy instance
            self.write_initial_structure()
            self.write_force_constants()

            if self.has_nac():
                self.write_born_file()

    @property
    def complete(self):
        if not self.forces_run_set.complete:
            return False

        if self.has_nac() and not self.lepsilon_calculation.complete:
            return False

        return True

    def has_nac(self):
        return self.phonopy_inputs.has_key(
            'nac') and self.phonopy_inputs['nac']

    def get_initial_structure_path(self):
        return self.get_extended_path('initial_structure')

    def get_force_constants_path(self):
        return self.get_extended_path('FORCE_CONSTANTS')

    def get_born_path(self):
        return self.get_extended_path('BORN')

    def get_lepsion_calculation_path(self):
        return self.get_extended_path('lepsilon_calculation')

    def get_forces_run_set_path(self):
        return self.get_extended_path('force_calculations')

    def write_initial_structure(self):
        """
		Writes the initial structure used to generate displacements to a poscar file.
		"""

        #######make sure this is reoptimized structure
        self.initial_structure.to_poscar_file_path(
            self.get_initial_structure_path())

    def write_force_constants(self):
        """
		Writes the calculated force constants to file.
		"""

        phonopy_utility.write_force_constants_to_file_path(
            initial_structure=self.initial_structure,
            phonopy_inputs=self.phonopy_inputs,
            vasp_xml_file_paths_list=self.forces_run_set.
            get_xml_file_paths_list(),
            file_path=self.get_force_constants_path())

    def write_born_file(self):
        """
		Writes born file necessary for NAC to file.
		"""

        if self.has_nac():
            dielectric_tensor = self.lepsilon_calculation.outcar.get_dielectric_tensor(
            )
            born_effective_charge_tensor = self.lepsilon_calculation.outcar.get_born_effective_charge_tensor(
            )

            phonopy_utility.write_born_file(
                initial_structure=self.initial_structure,
                phonopy_inputs=self.phonopy_inputs,
                dielectric_tensor=dielectric_tensor,
                born_effective_charge_tensor=born_effective_charge_tensor,
                file_path=self.get_born_path())
def run_misfit_strain(path, misfit_strain, input_dictionary,
                      initial_relaxation_input_dictionary, dfpt_incar_settings,
                      derivative_evaluation_vasp_run_inputs_dictionary,
                      minima_relaxation_input_dictionary,
                      epitaxial_relaxation_input_dictionary):

    Path.make(path)

    species_list = input_dictionary['species_list']
    reference_lattice_constant = input_dictionary['reference_lattice_constant']
    Nx = input_dictionary['supercell_dimensions_list'][0]
    Ny = input_dictionary['supercell_dimensions_list'][1]
    Nz = input_dictionary['supercell_dimensions_list'][2]
    displacement_finite_differrences_step_size = input_dictionary[
        'displacement_finite_differrences_step_size']
    perturbation_magnitudes_dictionary = input_dictionary[
        'perturbation_magnitudes_dictionary']

    a = reference_lattice_constant * (1.0 + misfit_strain)

    initial_structure = Perovskite(
        supercell_dimensions=[Nx, Ny, Nz],
        lattice=[[a * Nx, 0.0, 0.0], [0.0, a * Ny, 0.0],
                 [
                     0.0, 0.0, reference_lattice_constant * Nz *
                     (1.0 + 0.3 * (1.0 - (a / reference_lattice_constant)))
                 ]],
        species_list=species_list)
    relaxation = VaspRelaxation(
        path=Path.join(path, 'relaxation'),
        initial_structure=initial_structure,
        input_dictionary=initial_relaxation_input_dictionary)

    if not relaxation.complete:
        relaxation.update()
        return False

    relaxed_structure = relaxation.final_structure

    relaxed_structure_path = Path.join(path, 'output_relaxed_structure')
    relaxed_structure.to_poscar_file_path(relaxed_structure_path)

    force_calculation_path = Path.join(path, 'dfpt_force_calculation')

    kpoints = Kpoints(scheme_string=kpoint_scheme,
                      subdivisions_list=kpoint_subdivisions_list)
    incar = IncarMaker.get_dfpt_hessian_incar(dfpt_incar_settings)
    input_set = VaspInputSet(relaxed_structure,
                             kpoints,
                             incar,
                             auto_change_lreal=False,
                             auto_change_npar=False)

    dfpt_force_run = VaspRun(path=force_calculation_path, input_set=input_set)

    if not dfpt_force_run.complete:
        dfpt_force_run.update()
        return False

    hessian = Hessian(dfpt_force_run.outcar)
    hessian.print_eigenvalues_to_file(Path.join(path, 'output_eigen_values'))
    hessian.print_eigen_components_to_file(
        Path.join(path, 'output_eigen_components'))

    variable_specialty_points_dictionary = input_dictionary[
        'variable_specialty_points_dictionary_set'][
            misfit_strain] if input_dictionary.has_key(misfit_strain) else {}

    derivative_evaluation_path = Path.join(
        path, 'expansion_coefficient_calculations')
    derivative_evaluator = DerivativeEvaluator(
        path=derivative_evaluation_path,
        reference_structure=relaxed_structure,
        hessian=hessian,
        reference_completed_vasp_relaxation_run=relaxation,
        vasp_run_inputs_dictionary=
        derivative_evaluation_vasp_run_inputs_dictionary,
        perturbation_magnitudes_dictionary=perturbation_magnitudes_dictionary,
        displacement_finite_differrences_step_size=
        displacement_finite_differrences_step_size,
        status_file_path=Path.join(path, 'output_derivative_plot_data'),
        variable_specialty_points_dictionary=
        variable_specialty_points_dictionary)
    derivative_evaluator.update()

    guessed_minima_data_path = Path.join(path, 'guessed_chromosomes')
    minima_path = Path.join(path, 'minima_relaxations')

    if Path.exists(guessed_minima_data_path):
        minima_relaxer = MinimaRelaxer(
            path=minima_path,
            reference_structure=relaxed_structure,
            reference_completed_vasp_relaxation_run=relaxation,
            hessian=hessian,
            vasp_relaxation_inputs_dictionary=
            minima_relaxation_input_dictionary,
            eigen_chromosome_energy_pairs_file_path=guessed_minima_data_path)

        minima_relaxer.update()
        minima_relaxer.print_status_to_file(
            Path.join(path, 'output_minima_relaxations_status'))

        if minima_relaxer.complete:
            minima_relaxer.print_selected_uniques_to_file(file_path=Path.join(
                path, 'output_selected_unique_minima_relaxations'))
            sorted_uniques = minima_relaxer.get_sorted_unique_relaxation_data_list(
            )

            return sorted_uniques
Exemple #16
0
    def update(self):
        if not self.relaxation.complete:
            self.relaxation.update()
        else:
            Path.make(self.dos_path)

            dos_runs_count = self.get_current_dos_count()

            incar_modifications = {}
            for key, value_list in self.relaxation.incar_modifier_lists_dictionary.items(
            ):
                incar_modifications[key] = value_list[1000]

            incar = IncarMaker.get_static_incar(incar_modifications)

            if 'submission_node_count' in self.extra_dos_inputs:
                node_count = self.extra_dos_inputs.pop('submission_node_count')
            else:
                node_count = None

            structure = self.relaxation.final_structure
            kpoint_schemes = ParameterList(
                self.extra_dos_inputs.pop('kpoint_schemes_list'))
            kpoint_subdivisions_lists = ParameterList(
                self.extra_dos_inputs.pop('kpoint_subdivisions_lists'))

            kpoints = Kpoints(
                scheme_string=kpoint_schemes[dos_runs_count],
                subdivisions_list=kpoint_subdivisions_lists[dos_runs_count])
            incar = IncarMaker.get_static_incar(incar_modifications)

            for key, value in self.extra_dos_inputs.items():
                incar[key] = value

            if node_count != None:
                input_set.set_node_count(node_count)

            incar['lhfcalc'] = True
            incar['hfscreen'] = 0.2
            incar['lorbit'] = 11

            chargecar_path = None

            if dos_runs_count == 0:
                run_path = Path.join(self.dos_path,
                                     'hybrid_electronic_optimization_1')
                Path.make(run_path)

                wavecar_path = Path.join(self.relaxation.path, 'static',
                                         'WAVECAR')

                incar['algo'] = 'All'
                incar['time'] = 0.4
                incar['precfock'] = 'Fast'
                incar['nkred'] = 2
                incar['ismear'] = 0
                incar['sigma'] = 0.02
                incar['lwave'] = True

            elif dos_runs_count == 1:
                run_path = Path.join(self.dos_path,
                                     'hybrid_electronic_optimization_2')
                Path.make(run_path)

                wavecar_path = Path.join(self.dos_path,
                                         'hybrid_electronic_optimization_1',
                                         'WAVECAR')

                incar['ialgo'] = 53
                incar['time'] = 0.4
                incar['precfock'] = 'Fast'
                incar['nkred'] = 2
                incar['ismear'] = -5
                incar['sigma'] = 0.02
                incar['lwave'] = True
                incar['lcharg'] = True

            elif dos_runs_count >= 2:
                run_path = Path.join(self.dos_path,
                                     'hybrid_electronic_optimization_3')
                Path.make(run_path)

                wavecar_path = Path.join(self.dos_path,
                                         'hybrid_electronic_optimization_2',
                                         'WAVECAR')
                chargecar_path = Path.join(self.dos_path,
                                           'hybrid_electronic_optimization_2',
                                           'CHARGECAR')

                incar['ialgo'] = 53
                incar['time'] = 0.4
                incar['precfock'] = 'Fast'
                incar['nkred'] = 2
                incar['ismear'] = -5
                incar['sigma'] = 0.02
                incar['lwave'] = True
                incar['lcharg'] = True
                incar['icharge'] = 11

            input_set = VaspInputSet(structure,
                                     kpoints,
                                     incar,
                                     calculation_type='gga')

            current_dos_run = VaspRun(path=run_path,
                                      input_set=input_set,
                                      wavecar_path=wavecar_path,
                                      chargecar_path=None)

            current_dos_run.update()