def get_sample(calculation_path):
    structure = Structure(file_path=Path.join(calculation_path, 'POSCAR'))
    structure.shift_sites_so_first_atom_is_at_origin()

    outcar = Outcar(file_path=Path.join(calculation_path, 'OUTCAR'))

    lattice_information = structure.get_magnitudes_and_angles()

    ideal_perovskite_structure = Perovskite(
        supercell_dimensions=[1, 1, 1],
        lattice=copy.deepcopy(structure.lattice),
        species_list=structure.get_species_list())

    displacement_vector = DisplacementVector.get_instance_from_displaced_structure_relative_to_reference_structure(
        reference_structure=ideal_perovskite_structure,
        displaced_structure=structure,
        coordinate_mode='Cartesian')

    energy = outcar.energy

    forces = outcar.final_forces_list

    stresses = outcar.final_stresses_list
    volume = structure.lattice.get_volume()  #in A^3

    for z in range(len(stresses)):
        stresses[z] /= volume

    row_of_data = lattice_information + displacement_vector.to_list() + [
        energy
    ] + forces + stresses

    output_string = ' '.join([str(x) for x in row_of_data])

    return row_of_data, output_string
예제 #2
0
    def __init__(self, vasp_calculation_input_dictionary):

        vasp_calculation_input_dictionary = copy.deepcopy(
            vasp_calculation_input_dictionary)

        vasp_calculation_input_dictionary = {
            k.lower(): v
            for k, v in vasp_calculation_input_dictionary.items()
        }  #enforce all keys lowercase

        path = Path.clean(vasp_calculation_input_dictionary.pop('path'))

        information_structure = None  #used for number of nodes and potcar
        if isinstance(vasp_calculation_input_dictionary['structure'],
                      Structure):
            initial_structure = vasp_calculation_input_dictionary.pop(
                'structure')
            information_structure = initial_structure
            contcar_path = None
        else:
            initial_structure = None
            contcar_path = vasp_calculation_input_dictionary.pop('structure')
            information_structure = Structure(contcar_path)

        wavecar_path = vasp_calculation_input_dictionary.pop(
            'wavecar_path'
        ) if 'wavecar_path' in vasp_calculation_input_dictionary else None
        chargecar_path = vasp_calculation_input_dictionary.pop(
            'chargecar_path'
        ) if 'chargecar_path' in vasp_calculation_input_dictionary else None
        incar_template = vasp_calculation_input_dictionary.pop(
            'incar_template'
        ) if 'incar_template' in vasp_calculation_input_dictionary else None
        kpoints_scheme = vasp_calculation_input_dictionary.pop(
            'kpoints_scheme'
        ) if 'kpoints_scheme' in vasp_calculation_input_dictionary else None
        kpoints_list = [
            int(x) for x in vasp_calculation_input_dictionary.pop(
                'kpoints_list').split(' ')
        ] if ('kpoints_list' in vasp_calculation_input_dictionary
              and vasp_calculation_input_dictionary['kpoints_list'] != None
              ) else None
        potcar_type = vasp_calculation_input_dictionary.pop(
            'potcar_type'
        ) if 'potcar_type' in vasp_calculation_input_dictionary else 'lda_paw'
        vasp_code_type = vasp_calculation_input_dictionary.pop(
            'vasp_code_type'
        ) if 'vasp_code_type' in vasp_calculation_input_dictionary else 'standard'
        node_count = vasp_calculation_input_dictionary.pop(
            'node_count'
        ) if 'node_count' in vasp_calculation_input_dictionary else None
        use_mp_hubbard_u = vasp_calculation_input_dictionary.pop(
            'use_mp_hubbard_u'
        ) if 'use_mp_hubbard_u' in vasp_calculation_input_dictionary else None

        for file_path in [wavecar_path, chargecar_path]:
            if file_path != None and not Path.exists(file_path):
                print "Warning: Path " + str(
                    file_path) + " specified does not exist. Not using."
                #raise Exception("Path " + str(file_path) + " specified does not exist.")

        if kpoints_scheme != None and kpoints_list != None:
            kpoints = Kpoints(scheme_string=kpoints_scheme,
                              subdivisions_list=kpoints_list)

            if 'kspacing' in vasp_calculation_input_dictionary:
                raise Exception(
                    "kpoints are being specified by more than one method.")
        elif 'kspacing' not in vasp_calculation_input_dictionary:
            raise Exception(
                "If kpoints aren't explicitly defined through a scheme and a list, the kspacing tag must be present in the incar."
            )
        else:
            kpoints = None

        potcar = Potcar(elements_list=information_structure.get_species_list(),
                        calculation_type=potcar_type)

        submission_script_file = QueueAdapter.get_submission_file()

        if os.environ['QUEUE_ADAPTER_HOST'] != 'Savio':
            if node_count == None:
                submission_script_file = QueueAdapter.modify_number_of_cores_from_num_atoms(
                    submission_script_file, information_structure.site_count)
            else:
                submission_script_file = QueueAdapter.set_number_of_nodes(
                    submission_script_file, node_count)

            submission_script_file = QueueAdapter.modify_submission_script(
                submission_script_file, modification_key=vasp_code_type)

        incar_modifiers = vasp_calculation_input_dictionary  #whatever is left should only be incar modifiers - we popped all other keys

        for key, value in incar_modifiers.items(
        ):  #make sure there are no None values - these should not be put in INCAR
            if value in [None, 'None']:
                del incar_modifiers[key]

        if 'encut' in incar_modifiers and (
                0.1 < incar_modifiers['encut']) and (
                    incar_modifiers['encut'] <
                    10.0):  #Should use this as a multiplier times enmax
            enmax = potcar.get_enmax()

            incar_modifiers['encut'] = int(incar_modifiers['encut'] * enmax)

        if incar_template == 'static':
            incar = IncarMaker.get_static_incar(
                custom_parameters_dictionary=incar_modifiers)
        elif incar_template == 'external_relaxation':
            incar = IncarMaker.get_external_relaxation_incar(
                custom_parameters_dictionary=incar_modifiers)
        elif incar_template != None:
            raise Exception("Incar template " + str(incar_template) +
                            " not valid")
        else:
            incar = Incar()
            incar.modify_from_dictionary(incar_modifiers)

        if 'lreal' not in incar:
            if information_structure.site_count > 20:
                incar['lreal'] = 'Auto'
            else:
                incar['lreal'] = False

        if 'npar' not in incar:
            if os.environ['QUEUE_ADAPTER_HOST'] == 'Savio':
                incar['npar'] = 4
            else:
                incar['npar'] = QueueAdapter.get_optimal_npar(
                    submission_script_file)
        elif incar['npar'] in ['Remove', 'remove']:
            del incar['npar']

        ###################TEMPORARILY HARDCODED FOR PEROVSKITES##########################################
        if use_mp_hubbard_u:
            u_species = initial_structure.get_species_list()[1]
            mp_hubbard_u_values = {
                'Co': 3.32,
                'Cr': 3.7,
                'Fe': 5.3,
                'Mn': 3.9,
                'Mo': 4.38,
                'Ni': 6.2,
                'V': 3.25,
                'W': 6.2
            }

            if u_species in mp_hubbard_u_values.keys():

                u_value = mp_hubbard_u_values[u_species]

                incar['LDAU'] = True
                incar['LDAUJ'] = '0 0 0'
                incar['LDAUL'] = '0 2 0'
                incar['LDAUPRINT'] = 1
                incar['LDAUTYPE'] = 2
                incar['LDAUU'] = '0 ' + str(u_value) + ' 0'
                incar['LMAXMIX'] = 4
                incar['LORBIT'] = 11

        super(VaspCalculationGenerator,
              self).__init__(path=path,
                             initial_structure=initial_structure,
                             incar=incar,
                             kpoints=kpoints,
                             potcar=potcar,
                             submission_script_file=submission_script_file,
                             contcar_path=contcar_path,
                             wavecar_path=wavecar_path,
                             chargecar_path=chargecar_path)