Exemplo n.º 1
0
def get_data_from_node_id(node_id):
    n = load_node(node_id.value)
    if 'structure' in n.inputs:
        cell = phonopy_atoms_from_structure(n.inputs.structure)
        structure = phonopy_atoms_to_structure(cell)
    else:
        raise RuntimeError("Crystal structure could not be found.")

    if 'born_charges' in n.outputs and 'dielectrics' in n.outputs:
        born = DataFactory('array')()
        born.set_array('born_charges',
                       n.outputs.born_charges.get_array('born_charges'))
        born.label = 'born_charges'
        epsilon = DataFactory('array')()
        epsilon.set_array('epsilon',
                          n.outputs.dielectrics.get_array('epsilon'))
        epsilon.label = 'epsilon'
        return {
            'born_charges': born,
            'dielectrics': epsilon,
            'structure': structure
        }
    elif 'forces' in n.outputs:
        forces = DataFactory('array')()
        forces.set_array('final', n.outputs.forces.get_array('final'))
        forces.label = 'forces'
        return {'forces': forces, 'structure': structure}
    else:
        raise RuntimeError("Forces or NAC params were not found.")
Exemplo n.º 2
0
def get_phonon_setting_info(phonon_settings,
                            structure,
                            symmetry_tolerance,
                            displacement_dataset=None):
    return_vals = {}

    ph_settings = {}
    ph_settings.update(phonon_settings.get_dict())
    dim = ph_settings['supercell_matrix']
    if len(np.ravel(dim)) == 3:
        smat = np.diag(dim)
    else:
        smat = np.array(dim)
    if not np.issubdtype(smat.dtype, np.integer):
        raise TypeError("supercell_matrix is not integer matrix.")
    else:
        ph_settings['supercell_matrix'] = smat.tolist()

    if 'mesh' not in ph_settings:
        ph_settings['mesh'] = 100.0
    if 'distance' not in ph_settings:
        ph_settings['distance'] = 0.01
    tolerance = symmetry_tolerance.value
    ph_settings['symmetry_tolerance'] = tolerance

    ph = get_phonopy_instance(structure, ph_settings, {})
    ph_settings['primitive_matrix'] = ph.primitive_matrix
    ph_settings['symmetry'] = {
        'number': ph.symmetry.dataset['number'],
        'international': ph.symmetry.dataset['international']
    }

    if displacement_dataset is None:
        ph.generate_displacements(distance=ph_settings['distance'])
    else:
        ph.dataset = displacement_dataset.get_dict()
    ph_settings['displacement_dataset'] = ph.dataset
    settings = DataFactory('dict')(dict=ph_settings)
    settings.label = 'phonon_setting_info'
    return_vals['phonon_setting_info'] = settings

    # Supercells and primitive cell
    for i, scell in enumerate(ph.supercells_with_displacements):
        structure = phonopy_atoms_to_structure(scell)
        label = "supercell_%03d" % (i + 1)
        structure.label = "%s %s" % (structure.get_formula(
            mode='hill_compact'), label)
        return_vals[label] = structure

    supercell_structure = phonopy_atoms_to_structure(ph.supercell)
    supercell_structure.label = "%s %s" % (supercell_structure.get_formula(
        mode='hill_compact'), 'supercell')
    return_vals['supercell'] = supercell_structure

    primitive_structure = phonopy_atoms_to_structure(ph.primitive)
    primitive_structure.label = "%s %s" % (primitive_structure.get_formula(
        mode='hill_compact'), 'primitive cell')
    return_vals['primitive'] = primitive_structure

    return return_vals
Exemplo n.º 3
0
def get_thermal_properties(thermal_properties):
    tprops = DataFactory('array.xy')()
    tprops.set_x(thermal_properties['temperatures'], 'Temperature', 'K')
    tprops.set_y([
        thermal_properties['free_energy'], thermal_properties['entropy'],
        thermal_properties['heat_capacity']
    ], ['Helmholtz free energy', 'Entropy', 'Cv'],
                 ['kJ/mol', 'J/K/mol', 'J/K/mol'])
    tprops.label = 'Thermal properties'
    return tprops
Exemplo n.º 4
0
def get_projected_dos(projected_dos):
    pdos = DataFactory('array.xy')()
    pdos_list = [pd for pd in projected_dos['projected_dos']]
    pdos.set_x(projected_dos['frequency_points'], 'Frequency', 'THz')
    pdos.set_y(pdos_list, [
        'Projected DOS',
    ] * len(pdos_list), [
        '1/THz',
    ] * len(pdos_list))
    pdos.label = 'Projected DOS'
    return pdos
Exemplo n.º 5
0
def get_force_constants(structure, phonon_settings, force_sets):
    params = {}
    phonon = get_phonopy_instance(structure, phonon_settings, params)
    phonon.dataset = phonon_settings['displacement_dataset']
    phonon.forces = force_sets.get_array('force_sets')
    phonon.produce_force_constants()
    force_constants = DataFactory('array')()
    force_constants.set_array('force_constants', phonon.force_constants)
    force_constants.set_array('p2s_map', phonon.primitive.p2s_map)
    force_constants.label = 'force_constants'

    return force_constants
Exemplo n.º 6
0
def get_force_sets(**forces_dict):
    forces = []
    energies = []
    for i in range(len(forces_dict)):
        label = "forces_%03d" % (i + 1)
        if label in forces_dict:
            forces.append(forces_dict[label].get_array('final'))
        label = "misc_%03d" % (i + 1)
        if label in forces_dict:
            energies.append(
                forces_dict[label]['total_energies']['energy_no_entropy'])

    assert len(forces) == sum(['forces' in k for k in forces_dict])

    force_sets = DataFactory('array')()
    force_sets.set_array('force_sets', np.array(forces))
    if energies:
        force_sets.set_array('energies', np.array(energies))
    force_sets.label = 'force_sets'
    return force_sets
Exemplo n.º 7
0
def get_bands(qpoints, frequencies, labels, path_connections, label=None):
    qpoints_list = list(qpoints[0])
    frequencies_list = list(frequencies[0])
    labels_list = [
        (0, labels[0]),
    ]
    label_index = 1

    for pc, qs, fs in zip(path_connections[:-1], qpoints[1:], frequencies[1:]):
        if labels[label_index] == 'GAMMA' and pc:
            labels_list.append((len(qpoints_list) - 1, labels[label_index]))
            if label_index < len(labels):
                labels_list.append((len(qpoints_list), labels[label_index]))
            label_index += 1
            qpoints_list += list(qs)
            frequencies_list += list(fs)
        elif pc:
            labels_list.append((len(qpoints_list) - 1, labels[label_index]))
            label_index += 1
            qpoints_list += list(qs[1:])
            frequencies_list += list(fs[1:])
        else:
            labels_list.append((len(qpoints_list) - 1, labels[label_index]))
            label_index += 1
            if label_index < len(labels):
                labels_list.append((len(qpoints_list), labels[label_index]))
                label_index += 1
            qpoints_list += list(qs)
            frequencies_list += list(fs)
    labels_list.append((len(qpoints_list) - 1, labels[-1]))

    bs = DataFactory('array.bands')()
    bs.set_kpoints(np.array(qpoints_list))
    bs.set_bands(np.array(frequencies_list), units='THz')
    bs.labels = labels_list
    if label is not None:
        bs.label = label

    return bs
Exemplo n.º 8
0
def get_nac_params(born_charges, epsilon, nac_structure, **params):
    """Obtain Born effective charges and dielectric constants in primitive cell

    When Born effective charges and dielectric constants are calculated within
    phonopy workchain, those values are calculated in the primitive cell.
    However using immigrant, the cell may not be primitive cell and can be
    unit cell. In this case, conversion of data is necessary. This conversion
    needs information of the structure where those values were calcualted and
    the target primitive cell structure.

    Two kargs parameters
    primitive : StructureData
    symmetry_tolerance : Float

    """
    from phonopy.structure.symmetry import symmetrize_borns_and_epsilon

    borns = born_charges.get_array('born_charges')
    eps = epsilon.get_array('epsilon')

    nac_cell = phonopy_atoms_from_structure(nac_structure)
    kargs = {}
    if 'symmetry_tolerance' in params:
        kargs['symprec'] = params['symmetry_tolerance'].value
    if 'primitive' in params:
        pcell = phonopy_atoms_from_structure(params['primitive'])
        kargs['primitive'] = pcell
    borns_, epsilon_ = symmetrize_borns_and_epsilon(borns, eps, nac_cell,
                                                    **kargs)

    nac_params = DataFactory('array')()
    nac_params.set_array('born_charges', borns_)
    nac_params.set_array('epsilon', epsilon_)
    nac_params.label = 'born_charges & epsilon'

    return nac_params
Exemplo n.º 9
0
def get_total_dos(total_dos):
    dos = DataFactory('array.xy')()
    dos.set_x(total_dos['frequency_points'], 'Frequency', 'THz')
    dos.set_y(total_dos['total_dos'], 'Total DOS', '1/THz')
    dos.label = 'Total DOS'
    return dos