Beispiel #1
0
def converge(base_path, structures_list, calculation_set_input_dictionary_template, change_set):

	Path.make(base_path)

	for structure_count, structure in enumerate(structures_list):
		structure_path = Path.join(base_path, 'structure_'+str(structure_count))

		Path.make(structure_path)

		change_key = change_set[0]
		change_values_list = change_set[1]
		num_relaxations = len(change_values_list)


		for run_set_count, change_set_value in enumerate(change_values_list):
			relaxation_set_path = Path.join(structure_path, 'relaxation_set_'+str(run_set_count))

			inputs = copy.deepcopy(calculation_set_input_dictionary_template)
			inputs[change_key] = change_set_value

			vasp_relaxation = VaspRelaxation(path=relaxation_set_path, initial_structure=structure, input_dictionary=inputs)

			vasp_relaxation.update()

			if vasp_relaxation.complete:
				print change_key, change_set_value, vasp_relaxation.get_final_energy(per_atom=True), vasp_relaxation.total_time
def npar_converger(base_path, structure, npar_list, base_kpoints_scheme,
                   base_kpoints_subdivisions_list, base_ediff, base_encut,
                   node_count):
    """Takes in a structure, set of npars, and base params and runs set in base_path"""
    encut_convergence_set_path = Path.clean(base_path)
    Path.make(encut_convergence_set_path)

    for npar in npar_list:
        run_path = Path.join(encut_convergence_set_path, str(npar))

        input_dictionary = {
            'external_relaxation_count': 0,
            'kpoint_schemes_list': [base_kpoints_scheme],
            'kpoint_subdivisions_lists': [base_kpoints_subdivisions_list],
            'submission_script_modification_keys_list': ['100'],
            'submission_node_count_list': [node_count],
            'ediff': [base_ediff],
            'encut': [base_encut],
            'npar': [npar]
        }

        vasp_relaxation = VaspRelaxation(run_path,
                                         structure,
                                         input_dictionary,
                                         verbose=False)

        if vasp_relaxation.update():
            print "npar:", npar, "node_count:", node_count, round(
                vasp_relaxation.get_final_energy(True),
                5), round(vasp_relaxation.total_time, 2)
        else:
            pass
Beispiel #3
0
    def __init__(self,
                 path,
                 initial_structure=None,
                 relaxation_input_dictionary=None,
                 extra_dos_inputs=None):
        """
		Input dicitonary should look something like:
		{
			'external_relaxation_count': 4,
			'kpoint_schemes_list': ['Gamma'],
			'kpoint_subdivisions_lists': [[1, 1, 1], [1, 1, 2], [2, 2, 4]],
			'submission_script_modification_keys_list': ['100', 'standard', 'standard_gamma'], #optional - will default to whatever queue adapter gives
			'submission_node_count_list': [1, 2],
			'ediff': [0.001, 0.00001, 0.0000001],
			'encut': [200, 400, 600, 800],
			'isif' : [5, 2, 3],
			'calculation_type': 'gga' #must be gga in this case
			#any other incar parameters with value as a list
		}

		extra_dos_inputs is optional and should look like:
		{
			HFSCREEN = 0.2 # sets the type of hybid - can give params for pbe0 here too
			NEDOS = 4001
			'kpoint_schemes_list': ['Gamma'],
			'kpoint_subdivisions_lists': [[2, 2, 4]], #for enhanced kpoints - can be up to three for each stage of the dos
			any other incar params for just dos part
		}

		If no relaxation_input_dictionary is provided, this class will attempt to load a saved pickled instance.
		"""

        self.path = Path.expand(path)
        self.relaxation_path = self.get_extended_path('relaxation')
        self.dos_path = self.get_extended_path('dos')
        self.extra_dos_inputs = extra_dos_inputs
        self.dos_runs_list = []

        if 'calculation_type' not in relaxation_input_dictionary or relaxation_input_dictionary[
                'calculation_type'] != 'gga':
            raise Exception(
                "Calculation type must be gga for hybrid calculations")

        if not relaxation_input_dictionary:
            self.load()
        else:

            Path.make(self.path)

            relaxation_input_dictionary['static_lwave'] = True
            self.relaxation = VaspRelaxation(
                path=self.relaxation_path,
                initial_structure=initial_structure,
                input_dictionary=relaxation_input_dictionary)
            self.save()
Beispiel #4
0
    def initialize_relaxation_list(self):

        self.vasp_relaxations_list = []

        eigen_structure = EigenStructure(
            reference_structure=self.reference_structure, hessian=self.hessian)

        for i, eigen_chromosome in enumerate(self.eigen_chromosomes_list):

            if (self.max_minima != None) and (i >= self.max_minima):
                break

            if (i % (len(self.eigen_chromosomes_list) / 10) == 0):
                mx = self.max_minima if self.max_minima else len(
                    self.eigen_chromosomes_list)
                print str(i) + "/" + str(mx)

            eigen_structure.set_eigen_chromosome(eigen_chromosome)

            initial_structure = eigen_structure.get_distorted_structure()

            self.vasp_relaxations_list.append(
                VaspRelaxation(
                    path=self.get_extended_path(
                        "rank_" + str(i) + "_" +
                        "_".join(str(x) for x in eigen_chromosome)),
                    initial_structure=initial_structure,
                    input_dictionary=self.vasp_relaxation_inputs_dictionary))

        print
Beispiel #5
0
    def directory_to_individual_conversion_method(self, path):
        """
		This method controls how to convert a directory containing vasp runs into an individual. The default, as implemented by this parent class, will be to return an
		individual whose calculation set is a vasp relaxation instance.
		"""

        return Individual(calculation_set=VaspRelaxation(
            path=path,
            input_dictionary=copy.deepcopy(
                self.calculation_set_input_dictionary)))
Beispiel #6
0
	def update(self):

		for misfit_strain in self.misfit_strains_list:

			misfit_path = self.get_extended_path(str(misfit_strain).replace('-', 'n'))

			for i in range(10000):
				relax_path = Path.join(misfit_path, 'structure_' + str(i))

				if not Path.exists(relax_path):
					break

				
				relaxation = VaspRelaxation(path=relax_path)

				relaxation.update()

				print "Updating Epitaxial Relax run at " + relax_path + "  Status is " + relaxation.get_status_string()

				if self.calculate_polarizations and relaxation.complete:
					self.update_polarization_run(relaxation)
Beispiel #7
0
	def complete(self):
		for misfit_strain in self.misfit_strains_list:
			misfit_path = self.get_extended_path(str(misfit_strain).replace('-', 'n'))

			for i in range(10000):
				relax_path = Path.join(misfit_path, 'structure_' + str(i))

				if not Path.exists(relax_path):
					return True
				else:
					relaxation = VaspRelaxation(path=relax_path)

					if not relaxation.complete:
						return False
Beispiel #8
0
    def create_new_individual(self, individual_path,
                              population_of_last_generation,
                              generation_number):
        """
		This method will create (and return) a new individual whose initial structure was created by randomly chosen means (heredity, random, mutate, ...etc.)
		"""

        initial_structure = self.get_structure(population_of_last_generation,
                                               generation_number)

        relaxation = VaspRelaxation(path=individual_path,
                                    initial_structure=initial_structure,
                                    input_dictionary=copy.deepcopy(
                                        self.calculation_set_input_dictionary))

        return Individual(
            calculation_set=relaxation,
            structure_creation_id_string=self.structure_creation_id_string,
            parent_structures_list=self.parent_structures_list,
            parent_paths_list=self.parent_paths_list)
Beispiel #9
0
	def initialize_vasp_relaxations(self):
		"""
		"""

		for misfit_strain in self.misfit_strains_list:
			lattice_constant = self.reference_lattice_constant*(1.0+misfit_strain)

			misfit_path = self.get_extended_path(str(misfit_strain).replace('-', 'n'))

			Path.make(misfit_path)

			for i, initial_structure in enumerate(self.initial_structures_list):

				#if self.structure_is_duplicate(initial_structure, misfit_path): #####################FIX THIS AND PUT BACK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
				#	print "Duplicate structure found - skipping"
				#	continue

				structure = copy.deepcopy(initial_structure)

				if abs(structure.lattice[0][1]) > 0.0 or abs(structure.lattice[0][2]) > 0.0 or abs(structure.lattice[1][0]) > 0.0 or abs(structure.lattice[1][2]) > 0.0:
					raise Exception("Current lattice is incompatible with (100) epitaxy: ", str(structure.lattice))

				structure.lattice[0][0] = lattice_constant*self.supercell_dimensions_list[0]
				structure.lattice[1][1] = lattice_constant*self.supercell_dimensions_list[1]

				#break symmetry
				structure.randomly_displace_sites(max_displacement_magnitude=0.01)


				relax_path = Path.join(misfit_path, 'structure_' + str(i))

				if not Path.exists(relax_path):
					print "Initializing epitaxial relaxation at " + relax_path

				relaxation = VaspRelaxation(path=relax_path, initial_structure=structure, input_dictionary=self.vasp_relaxation_inputs_dictionary)

				initial_structure.to_poscar_file_path(Path.join(relax_path, 'original_initial_structure'))
Beispiel #10
0
    else:
        start_range = 1

    component_complete = True

    energies = [stored_energy]

    for i in range(start_range, 3):
        relaxation_path = Path.join(component_path, str(i))

        eigen_structure[component_index + 6] = i * increment

        distorted_structure = eigen_structure.get_distorted_structure()

        relax = VaspRelaxation(path=relaxation_path,
                               initial_structure=distorted_structure,
                               input_dictionary=relax_input_dictionary)

        relax.update()

        if start_range == 1 and i == 1:
            print str(0.0), stored_energy

        if relax.complete:
            if i == 0:
                stored_energy = relax.get_final_energy()

            relaxed_structure = relax.final_structure

            print str(eigen_structure[component_index +
                                      6]), relax.get_final_energy()
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
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
for chromosome_index, chromosome in enumerate(random_chromosomes):
    eigen_structure = EigenStructure(reference_structure=reference_structure,
                                     hessian=hessian)

    relaxation_path = Path.join(base_path,
                                "chromosome_index_" + str(chromosome_index))

    Path.make(relaxation_path)

    eigen_structure.set_eigen_chromosome(chromosome)

    print "Chromosome index is " + str(
        chromosome_index) + "\n\t initial eigenstructure is " + str(
            eigen_structure)

    distorted_structure = eigen_structure.get_distorted_structure()

    relax = VaspRelaxation(path=relaxation_path,
                           initial_structure=distorted_structure,
                           input_dictionary=relax_input_dictionary)

    relax.update()

    if relax.complete:
        relaxed_structure = relax.final_structure
        relaxed_eigen_structure = EigenStructure(
            reference_structure=reference_structure,
            hessian=hessian,
            distorted_structure=relaxed_structure)
        print "\t   final eigenstructure is " + str(
            relaxed_eigen_structure) + " " + str(relax.get_final_energy())
de_path = Path.join(base_path, 'derivative_evaluator_test_1')

relaxation_path = Path.join(base_path, 'relaxation')

input_dictionary = {
    'external_relaxation_count':
    0,
    'kpoint_schemes_list': [vasp_run_inputs_dictionary['kpoints_scheme']],
    'kpoint_subdivisions_lists':
    [vasp_run_inputs_dictionary['kpoints_subdivisions_list']],
    'ediff': [0.0001],
    'encut': [vasp_run_inputs_dictionary['encut']]
}

relaxation_run = VaspRelaxation(path=relaxation_path,
                                initial_structure=reference_structure,
                                input_dictionary=input_dictionary)

derivative_evaluator = DerivativeEvaluator(
    path=de_path,
    reference_structure=reference_structure,
    hessian=hessian,
    taylor_expansion=taylor_expansion,
    reference_completed_vasp_relaxation_run=vasp_relaxation_run,
    vasp_run_inputs_dictionary=vasp_run_inputs_dictionary,
    perturbation_magnitudes_dictionary=perturbation_magnitudes_dictionary)

derivative_evaluator.update()

# a = 3.79
# Nx = 2
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
            path = './relaxation_type_potim_equals_' + str(potim).replace(
                '.', 'o') + '_trial_' + str(i)
            input_dictionary = {
                'external_relaxation_count': 4,
                'kpoint_schemes_list': ['Monkhorst'],
                'kpoint_subdivisions_lists': [[1, 1, 4]],
                'submission_script_modification_keys_list': ['100'],
                'submission_node_count_list': [2],
                'ediff': [0.001, 0.001, 0.0001, 0.0001],
                'encut': [500],
                'potim': [potim]
            }

            relaxes.append(
                VaspRelaxation(path,
                               structure,
                               input_dictionary,
                               verbose=False))

    for relax in relaxes:
        relax.update()
        print os.path.basename(relax.path)
        if not relax.complete:
            #relax.view(['_job_output.txt'])
            relax.quick_view()

    for relax in relaxes:
        print os.path.basename(relax.path)

        #print relax.get_final_energy(), relax.total_time
        data_dict = relax.get_data_dictionary()
Beispiel #17
0
	def get_data_dictionaries_list(self, get_polarization=False):
		"""
		Starts at most negative misfit runs and goes to larger misfits finding the minimum energy data set. To encourage continuity, if two or more relaxations are within a small energy threshold of each other, the 
		structure that is closest to the last chosen structure is chosen.

		The output of this function looks like [[-0.02, energy_1, [polarization_vector_1]], [-0.015, energy_2, [polarization_vector_2]], ...]
		"""

		output_data_dictionaries = []
		spg_symprecs = [0.1, 0.05, 0.04, 0.03, 0.02, 0.01, 0.001]

		for misfit_strain in self.misfit_strains_list:
			# print str(misfit_strain)
			data_dictionary = OrderedDict()
			data_dictionary['misfit_strain'] = misfit_strain

			misfit_path = self.get_extended_path(str(misfit_strain).replace('-', 'n'))

			minimum_energy = 10000000000
			minimum_energy_relaxation = None
			for i in range(10000):
				relax_path = Path.join(misfit_path, 'structure_' + str(i))

				if not Path.exists(relax_path):
					break

				relaxation = VaspRelaxation(path=relax_path)

				if not relaxation.complete:
					continue

				energy = relaxation.get_final_energy(per_atom=False)
				# print 'structure_' + str(i), energy
				
				if energy < minimum_energy:
					minimum_energy = energy
					minimum_energy_relaxation = relaxation

			# print 
			# print "minimum E " + str(minimum_energy)
			# print 
			
			if minimum_energy_relaxation == None:
				data_dictionary['structure'] = None
				data_dictionary['energy'] = None
				data_dictionary['polarization_vector'] = None

				for symprec in spg_symprecs:
					data_dictionary['spg_' + str(symprec)] = None

				data_dictionary['path'] = None
			else:				

				structure = copy.deepcopy(minimum_energy_relaxation.final_structure)

				if get_polarization:
					polarization_vector = self.update_polarization_run(minimum_energy_relaxation)
				else:
					polarization_vector = None

				data_dictionary['structure'] = structure
				data_dictionary['energy'] = minimum_energy
				data_dictionary['polarization_vector'] = polarization_vector

				for symprec in spg_symprecs:
					data_dictionary['spg_' + str(symprec)] = structure.get_spacegroup_string(symprec)

				data_dictionary['path'] = Path.join(minimum_energy_relaxation.path, 'static')

			output_data_dictionaries.append(data_dictionary)

		return output_data_dictionaries
                         supercell_dimensions_list=phonopy_inputs_dictionary[
                             'supercell_dimensions'])

    coordinate_path = Path.join(base_path,
                                "coordinate_index_" + str(coordinate_index))

    Path.make(coordinate_path)

    print "Coordinate index is " + str(
        coordinate_index) + ", Frequency squared is " + str(
            ps.normal_coordinates_list[coordinate_index].frequency**2)

    for i in range(4):
        relaxation_path = Path.join(coordinate_path, str(i))

        ps.normal_coordinates_list[coordinate_index].coefficient = i * 0.1

        dist_struct = ps.get_distorted_supercell_structure()

        relax = vasp_relaxation = VaspRelaxation(
            path=relaxation_path,
            initial_structure=dist_struct,
            input_dictionary=relax_input_dictionary)

        relax.update()

        if relax.complete:
            relaxed_structure = relax.final_structure

            print str(ps.normal_coordinates_list[coordinate_index].coefficient
                      ), relax.get_final_energy()
from fpctoolkit.io.file import File
from fpctoolkit.structure.site import Site
from fpctoolkit.structure.lattice import Lattice
from fpctoolkit.structure.structure import Structure
from fpctoolkit.structure.perovskite import Perovskite
from fpctoolkit.structure.site_collection import SiteCollection
from fpctoolkit.io.vasp.outcar import Outcar
from fpctoolkit.workflow.vasp_run import VaspRun
from fpctoolkit.io.vasp.vasp_input_set import VaspInputSet
from fpctoolkit.io.vasp.incar_maker import IncarMaker
from fpctoolkit.workflow.vasp_relaxation import VaspRelaxation

if __name__ == "__main__":

    path = './relaxation_BTO_2'
    initial_structure = Perovskite(supercell_dimensions=[1, 1, 1],
                                   lattice=[[4.1, 0.1, 0.0], [0.0, 4.0, 0.0],
                                            [0.0, 0.1, 3.9]],
                                   species_list=['Ba', 'Ti', 'O'])
    input_dictionary = {
        'external_relaxation_count': 2,
        'kpoint_schemes_list': ['Monkhorst'],
        'kpoint_subdivisions_lists': [[2, 2, 2], [4, 4, 4], [6, 6, 6]],
        'ediff': [0.001, 0.0001, 0.00001],
        'encut': [400, 600]
    }

    relax = VaspRelaxation(path, initial_structure, input_dictionary)
    relax.update()
    relax.view(['poscar', 'contcar'])
    'kpoint_subdivisions_lists': [[
        vasp_run_inputs_dictionary['kpoint_subdivisions_list'][i] *
        phonopy_inputs_dictionary['supercell_dimensions'][i] for i in range(3)
    ]],
    #'submission_script_modification_keys_list': ['100'],
    #'submission_node_count_list': [1],
    'potim': [0.05, 0.2, 0.4],
    'ediff': [0.000001, 0.00000001, 0.00000000001],
    'encut': [vasp_run_inputs_dictionary['encut']]
}

initial_structure = Perovskite(supercell_dimensions=[1, 1, 1],
                               lattice=[[4.0, 0.0, 0.0], [0.0, 4.0, 0.0],
                                        [0.0, 0.0, 4.0]],
                               species_list=['Ba', 'Ti', 'O'])

relax = VaspRelaxation(path=relaxation_path,
                       initial_structure=initial_structure,
                       input_dictionary=relax_input_dictionary)

relax.update()

if relax.complete:
    relaxed_structure = relax.final_structure

    vasp_phonon_calculation = VaspPhonon(
        path=phonon_path,
        initial_structure=relaxed_structure,
        phonopy_inputs_dictionary=phonopy_inputs_dictionary,
        vasp_run_inputs_dictionary=vasp_run_inputs_dictionary)
Beispiel #21
0
    'submission_node_count': 1,
    'potim': [0.1, 0.2, 0.4],
    'isif': [21, 71, 161],
    'ediff': [1e-4, 1e-5, 1e-6],
    'encut': [encut],
    'submission_script_modification_keys_list': ['100'],
    'lwave': [True],
    'lreal': [False],
    'addgrid': [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=species_list)


relaxation = VaspRelaxation(path=Path.join(base_path, 'relaxation'), initial_structure=initial_structure, input_dictionary=initial_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=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)
Beispiel #22
0
class VaspHybridDosRunSet(VaspRunSet):
    """
	Collection of runs that form a hybrid dos calculation

	The general workflow is:
	1. Relax (internally, externally, or skip and use expt structure) using PBE GGA - to skip set external_relaxation_count to zero
	2. Run normal GGA static calculation at normal kpoints with lwave on
	3. Run HSE06 calculation using this wavecar with lwave on using guassian smearing with prefock = fast and NKRED = 2 and algo = all time = 0.4
	4. Run HSE06 from the above wavecar with lwave and lcharge on using tetrahedral smearing with prefock = Normal and no NKRED set and IALGO = 53; TIME = 0.4
	5. Rerun HSE06 at desired higher kpoints with above chargecar, ICHARGE = 11, lorbit = 11, and all other same incar settings above

	"""
    def __init__(self,
                 path,
                 initial_structure=None,
                 relaxation_input_dictionary=None,
                 extra_dos_inputs=None):
        """
		Input dicitonary should look something like:
		{
			'external_relaxation_count': 4,
			'kpoint_schemes_list': ['Gamma'],
			'kpoint_subdivisions_lists': [[1, 1, 1], [1, 1, 2], [2, 2, 4]],
			'submission_script_modification_keys_list': ['100', 'standard', 'standard_gamma'], #optional - will default to whatever queue adapter gives
			'submission_node_count_list': [1, 2],
			'ediff': [0.001, 0.00001, 0.0000001],
			'encut': [200, 400, 600, 800],
			'isif' : [5, 2, 3],
			'calculation_type': 'gga' #must be gga in this case
			#any other incar parameters with value as a list
		}

		extra_dos_inputs is optional and should look like:
		{
			HFSCREEN = 0.2 # sets the type of hybid - can give params for pbe0 here too
			NEDOS = 4001
			'kpoint_schemes_list': ['Gamma'],
			'kpoint_subdivisions_lists': [[2, 2, 4]], #for enhanced kpoints - can be up to three for each stage of the dos
			any other incar params for just dos part
		}

		If no relaxation_input_dictionary is provided, this class will attempt to load a saved pickled instance.
		"""

        self.path = Path.expand(path)
        self.relaxation_path = self.get_extended_path('relaxation')
        self.dos_path = self.get_extended_path('dos')
        self.extra_dos_inputs = extra_dos_inputs
        self.dos_runs_list = []

        if 'calculation_type' not in relaxation_input_dictionary or relaxation_input_dictionary[
                'calculation_type'] != 'gga':
            raise Exception(
                "Calculation type must be gga for hybrid calculations")

        if not relaxation_input_dictionary:
            self.load()
        else:

            Path.make(self.path)

            relaxation_input_dictionary['static_lwave'] = True
            self.relaxation = VaspRelaxation(
                path=self.relaxation_path,
                initial_structure=initial_structure,
                input_dictionary=relaxation_input_dictionary)
            self.save()

    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 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()