示例#1
0
def phonons(model, bulk, supercell, dx, mesh=None, points=None, n_points=50):

    import model

    unitcell = PhonopyAtoms(symbols=bulk.get_chemical_symbols(),
                            cell=bulk.get_cell(),
                            scaled_positions=bulk.get_scaled_positions())
    phonon = Phonopy(unitcell, supercell)
    phonon.generate_displacements(distance=dx)

    sets_of_forces = []

    for s in phonon.get_supercells_with_displacements():
        at = Atoms(cell=s.get_cell(),
                   symbols=s.get_chemical_symbols(),
                   scaled_positions=s.get_scaled_positions(),
                   pbc=3 * [True])
        at.set_calculator(model.calculator)
        sets_of_forces.append(at.get_forces())

    phonon.set_forces(sets_of_forces=sets_of_forces)
    phonon.produce_force_constants()

    properties = {}

    if mesh is not None:
        phonon.set_mesh(mesh, is_gamma_center=True)
        qpoints, weights, frequencies, eigvecs = phonon.get_mesh()

        properties["frequencies"] = frequencies.tolist()
        properties["weights"] = weights.tolist()

    if points is not None:
        bands = []
        for i in range(len(points) - 1):
            band = []
            for r in np.linspace(0, 1, n_points):
                band.append(points[i] + (points[i + 1] - points[i]) * r)
            bands.append(band)

        phonon.set_band_structure(bands,
                                  is_eigenvectors=True,
                                  is_band_connection=False)
        band_q_points, band_distances, band_frequencies, band_eigvecs = phonon.get_band_structure(
        )

        band_distance_max = np.max(band_distances)
        band_distances = [(_b / band_distance_max).tolist()
                          for _b in band_distances]

        band_frequencies = [_b.tolist() for _b in band_frequencies]

        properties["band_q_points"] = band_q_points
        properties["band_distances"] = band_distances
        properties["band_frequencies"] = band_frequencies
        properties["band_eigvecs"] = band_eigvecs

    properties["phonopy"] = phonon

    return properties
示例#2
0
def obtain_phonon_dispersion_spectra(structure, bands_ranges, NAC=False, band_resolution=30):

    print("Calculating phonon dispersion spectra...")
    bulk = PhonopyAtoms(
        symbols=structure.get_atomic_types(),
        scaled_positions=structure.get_scaled_positions(),
        cell=structure.get_cell().T,
    )

    phonon = Phonopy(
        bulk,
        structure.get_super_cell_phonon(),
        primitive_matrix=structure.get_primitive_matrix(),
        is_auto_displacements=False,
    )

    if NAC:
        print("Phonopy warning: Using Non Analitical Corrections")
        print("BORN file is needed to do this")
        get_is_symmetry = True  # sfrom phonopy:   settings.get_is_symmetry()
        primitive = phonon.get_primitive()
        nac_params = parse_BORN(primitive, get_is_symmetry)
        phonon.set_nac_params(nac_params=nac_params)

    phonon.set_displacement_dataset(copy.deepcopy(structure.get_force_set()))
    phonon.produce_force_constants()

    bands = []
    for q_start, q_end in bands_ranges:
        band = []
        for i in range(band_resolution + 1):
            band.append(np.array(q_start) + (np.array(q_end) - np.array(q_start)) / band_resolution * i)
        bands.append(band)
    phonon.set_band_structure(bands)

    return phonon.get_band_structure()
示例#3
0
#            [0, 2.43533967, 0],
#            [0, 0, 2.43533967]]
# factors = 14.400
# nac_params = {'born': born,
#               'factor': factors,
#               'dielectric': epsilon}
phonon.set_nac_params(nac_params)

# BAND = 0.0 0.0 0.0  0.5 0.0 0.0  0.5 0.5 0.0  0.0 0.0 0.0  0.5 0.5 0.5
bands = []
append_band(bands, [0.0, 0.0, 0.0], [0.5, 0.0, 0.0])
append_band(bands, [0.5, 0.0, 0.0], [0.5, 0.5, 0.0])
append_band(bands, [0.5, 0.5, 0.0], [0.0, 0.0, 0.0])
append_band(bands, [0.0, 0.0, 0.0], [0.5, 0.5, 0.5])
phonon.set_band_structure(bands)
q_points, distances, frequencies, eigvecs = phonon.get_band_structure()
for q, d, freq in zip(q_points, distances, frequencies):
    print q, d, freq
phonon.plot_band_structure().show()

# Mesh sampling 20x20x20
phonon.set_mesh([20, 20, 20])
phonon.set_thermal_properties(t_step=10,
                              t_max=1000,
                              t_min=0)

# DOS
phonon.set_total_DOS(sigma=0.1)
for omega, dos in np.array(phonon.get_total_DOS()).T:
    print "%15.7f%15.7f" % (omega, dos)
phonon.plot_total_DOS().show()
示例#4
0
#            [0, 2.43533967, 0],
#            [0, 0, 2.43533967]]
# factors = 14.400
# nac_params = {'born': born,
#               'factor': factors,
#               'dielectric': epsilon}
phonon.set_nac_params(nac_params)

# BAND = 0.0 0.0 0.0  0.5 0.0 0.0  0.5 0.5 0.0  0.0 0.0 0.0  0.5 0.5 0.5
bands = []
append_band(bands, [0.0, 0.0, 0.0], [0.5, 0.0, 0.0])
append_band(bands, [0.5, 0.0, 0.0], [0.5, 0.5, 0.0])
append_band(bands, [0.5, 0.5, 0.0], [0.0, 0.0, 0.0])
append_band(bands, [0.0, 0.0, 0.0], [0.5, 0.5, 0.5])
phonon.set_band_structure(bands)
q_points, distances, frequencies, eigvecs = phonon.get_band_structure()
for q, d, freq in zip(q_points, distances, frequencies):
    print q, d, freq
phonon.plot_band_structure().show()

# Mesh sampling 20x20x20
phonon.set_mesh([20, 20, 20])
phonon.set_thermal_properties(t_step=10, t_max=1000, t_min=0)

# DOS
phonon.set_total_DOS(sigma=0.1)
for omega, dos in np.array(phonon.get_total_DOS()).T:
    print "%15.7f%15.7f" % (omega, dos)
phonon.plot_total_DOS().show()

# Thermal properties
示例#5
0
def phonopy_calculation_inline(**kwargs):
    from phonopy.structure.atoms import Atoms as PhonopyAtoms
    from phonopy import Phonopy

    structure = kwargs.pop('structure')
    phonopy_input = kwargs.pop('phonopy_input').get_dict()
    force_constants = kwargs.pop('force_constants').get_array(
        'force_constants')
    bands = get_path_using_seekpath(structure)

    # Generate phonopy phonon object
    bulk = PhonopyAtoms(symbols=[site.kind_name for site in structure.sites],
                        positions=[site.position for site in structure.sites],
                        cell=structure.cell)

    phonon = Phonopy(bulk,
                     phonopy_input['supercell'],
                     primitive_matrix=phonopy_input['primitive'],
                     symprec=phonopy_input['symmetry_precision'])

    phonon.set_force_constants(force_constants)

    try:
        print('trying born')
        nac_data = kwargs.pop('nac_data')
        born = nac_data.get_array('born_charges')
        epsilon = nac_data.get_array('epsilon')

        phonon.set_nac_params(get_born_parameters(phonon, born, epsilon))
        print('born succeed')
    except:
        pass

    # Normalization factor primitive to unit cell
    norm_primitive_to_unitcell = phonon.unitcell.get_number_of_atoms(
    ) / phonon.primitive.get_number_of_atoms()

    phonon.set_band_structure(bands['ranges'])

    phonon.set_mesh(phonopy_input['mesh'],
                    is_eigenvectors=True,
                    is_mesh_symmetry=False)
    phonon.set_total_DOS(tetrahedron_method=True)
    phonon.set_partial_DOS(tetrahedron_method=True)

    # get band structure
    band_structure_phonopy = phonon.get_band_structure()
    q_points = np.array(band_structure_phonopy[0])
    q_path = np.array(band_structure_phonopy[1])
    frequencies = np.array(band_structure_phonopy[2])
    band_labels = np.array(bands['labels'])

    # stores band structure
    band_structure = ArrayData()
    band_structure.set_array('q_points', q_points)
    band_structure.set_array('q_path', q_path)
    band_structure.set_array('frequencies', frequencies)
    band_structure.set_array('labels', band_labels)

    # get DOS (normalized to unit cell)
    total_dos = phonon.get_total_DOS() * norm_primitive_to_unitcell
    partial_dos = phonon.get_partial_DOS() * norm_primitive_to_unitcell

    # Stores DOS data in DB as a workflow result
    dos = ArrayData()
    dos.set_array('frequency', total_dos[0])
    dos.set_array('total_dos', total_dos[1] * norm_primitive_to_unitcell)
    dos.set_array('partial_dos', partial_dos[1] * norm_primitive_to_unitcell)
    dos.set_array('partial_symbols', np.array(phonon.primitive.symbols))

    # THERMAL PROPERTIES (per primtive cell)
    phonon.set_thermal_properties()
    t, free_energy, entropy, cv = phonon.get_thermal_properties()

    # Stores thermal properties (per mol) data in DB as a workflow result
    thermal_properties = ArrayData()
    thermal_properties.set_array('temperature', t)
    thermal_properties.set_array('free_energy',
                                 free_energy * norm_primitive_to_unitcell)
    thermal_properties.set_array('entropy',
                                 entropy * norm_primitive_to_unitcell)
    thermal_properties.set_array('cv', cv * norm_primitive_to_unitcell)

    return {
        'thermal_properties': thermal_properties,
        'dos': dos,
        'band_structure': band_structure
    }
示例#6
0
文件: Al2O3.py 项目: arbegla/phonopy
q_start = np.array([0, 0, 0])
q_end = np.array([1./3, 1./3, 1./2])
band = []
for i in range(51):
    band.append(q_start + ( q_end - q_start ) / 50 * i)
bands.append(band)

#*********************
# Matplotlib required
#*********************
print "\nPhonon dispersion:"
phonon.set_band_structure(bands,
                          is_eigenvectors=True)
phonon.plot_band_structure(["X", "$\Gamma$", "L"]).show()

bands = phonon.get_band_structure()
distances = bands[1]
frequencies = bands[2]
qpoints = bands[0]

for (qs_at_segments,
     dists_at_segments,
     freqs_at_segments) in zip(qpoints, distances, frequencies):

    for q, d, f in zip(qs_at_segments,
                       dists_at_segments,
                       freqs_at_segments):
        print "# %f %f %f" % tuple(q)
        print d, ("%f " * len(f)) % tuple(f)

# If you just want to plot along q-points of all band segments, the
示例#7
0
    phonon.set_forces(forces)
    phonon.produce_force_constants()

    mesh = [nqx, nqy, nqz]
    phonon.set_mesh(mesh, is_eigenvectors=True)
    qpoints, weights, frequencies, eigvecs = phonon.get_mesh()

    #SHOW DOS STRUCTURE
    phonon.set_total_DOS(freq_min=0.0, freq_max=12.0, tetrahedron_method=False)
    phonon.get_total_DOS()
    phonon.write_total_DOS()
    phonon.plot_total_DOS().show()

    #BAND STRUCTURE
    phonon.set_band_structure(paths, is_eigenvectors=False, is_band_connection=True)
    phonon.get_band_structure()
    ph_plot = phonon.plot_band_structure(labels=["G", "N", "P"])
    ph_plot.show()
    #WRITE ANIMATION MODE
    phonon.write_animation()
    #TEMPERATURE
    phonon.set_thermal_properties(t_step=10, t_max=1000, t_min=0)
    temp_plot = open('temp_plot.dat', 'w')
    for t, free_energy, entropy, cv in np.array(phonon.get_thermal_properties()).T:
        print >> temp_plot, ("%12.3f " + "%15.7f" * 3) % ( t, free_energy, entropy, cv )
    phonon.plot_thermal_properties().show()
    #Finally write parametrs of calculation i.e. supercell size for force_constant
    #and qpoint mesh

    with open('subgb.json','w') as f:
        gb_dict = {}
示例#8
0
文件: test.py 项目: tdengg/pylastic
 def __init__(self, numbatom=125, supercell=5):
     
     #species = 'WRe_0.25_conv'
     species = 'WRe_0.00'
     #species = 'Re'
     ###read force constants from vasprun.xml###
     vasprun = etree.iterparse('vasprun.xml', tag='varray')
     #fc = vasp.get_force_constants_vasprun_xml(vasprun,1) #pass xml input and species atomic weight.
     ###########################################
     
     ########### read positionsl ###############
     primitive = vasp.get_atoms_from_poscar(open('POSCAR-p'),'W')
     superc =  vasp.get_atoms_from_poscar(open('POSCAR'),'W')
     ###########################################
     numbatom =  superc.get_number_of_atoms()
     #print primitive.get_cell()
     #print primitive.get_scaled_positions()
     #print superc.get_scaled_positions()
     
     print numbatom, species, os.getcwd()
     if species=='W':
     #Tungsten
         fc = vasp.get_force_constants_vasprun_xml(vasprun,1,0,64)
         s = 4.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
         
     elif species=='W_conv_2x2x2':
     #Tungsten
         fc = vasp.get_force_constants_vasprun_xml(vasprun,1,2)
         s = 2.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W','W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     
     elif species=='W_conv':
     #Tungsten
         fc = vasp.get_force_constants_vasprun_xml(vasprun,1,2)
         s = 4.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W','W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     
     elif species=='WRe_0.25_conv':
     #Tungsten
         fc = vasp.get_force_constants_vasprun_xml(vasprun,8,2,64)
         s = 4.
         a = superc.get_cell()[0][0]*2.
         print a, primitive.get_scaled_positions()
         bulk = PhonopyAtoms(symbols=['W','W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         #print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     
     elif species == 'WRe_B2': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,1,1)
         s = 5.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W','Re'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     elif species == 'WRe_0.00': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,1,0,numbatom)
         s = supercell
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [200, 200, 200]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     elif species == 'WRe_0.03': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,2,0)
         s = 2.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     elif species == 'WRe_0.06': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,3,0)
         s = 2.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     
     elif species == 'WRe_0.09': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,4,0)
         s = 2.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     elif species == 'WRe_0.12': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,5,0)
         s = 2.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     
     elif species == 'WRe_0.18': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,6,0)
         s = 2.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)
     elif species == 'WRe_0.25': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,7,0)
         s = 2.
         a = primitive.get_cell()[0][0]*2.
         print a, primitive.get_scaled_positions()
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         #phonon.set_partial_DOS()
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)    
     
     elif species == 'WRe_0.50': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,8,0)
         s = 2.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['W'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         #print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         #print frequencies
         phonon.set_total_DOS()
         #phonon.set_partial_DOS()
         phonon.set_thermal_properties(t_step=10,
                                       t_max=3700,
                                       t_min=0)    
         
         
     elif species == 'Au': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,1,0)
         #Gold
         s = 5.
         a = superc.get_cell()[0][0]
         bulk = PhonopyAtoms(symbols=['Au'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[0.5, 0.5, 0.0],[0.0, 0.5, 0.5],[0.5, 0.0, 0.5]],
                          distance=0.01, factor=15.633302)
         
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         phonon.set_partial_DOS()
         phonon.set_thermal_properties(t_step=10,
                                       t_max=1300,
                                       t_min=0)
     
     elif species == 'Mo': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,10,0)
         s = 5.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['Mo'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=2500,
                                       t_min=0)
     
     
     elif species == 'Re': 
         fc = vasp.get_force_constants_vasprun_xml(vasprun,9,0)
         s = 5.
         a = superc.get_cell()[0][0]*2.
         print a
         bulk = PhonopyAtoms(symbols=['Re'] * 1,
                             scaled_positions= primitive.get_scaled_positions())
         bulk.set_cell(np.diag((a, a, a)))
         phonon = Phonopy(bulk,
                          [[s,0.,0.],[0.,s,0.],[0.,0.,s]],
                          primitive_matrix=[[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5],[0.5, 0.5, -0.5]],
                          distance=0.01, factor=15.633302)
         print fc
         phonon.set_force_constants(fc[0])
         phonon.set_dynamical_matrix()
         #print phonon.get_dynamical_matrix_at_q([0,0,0])
         mesh = [100, 100, 100]
         phonon.set_mesh(mesh)
         qpoints, weights, frequencies, eigvecs = phonon.get_mesh()
         print frequencies
         phonon.set_total_DOS()
         
         phonon.set_thermal_properties(t_step=10,
                                       t_max=2500,
                                       t_min=0)
     
     
     f = open('F_TV','w')
     for t, free_energy, entropy, cv in np.array(phonon.get_thermal_properties()).T:
         #print t, cv
         #print ("%12.3f " + "%15.7f" * 3) % ( t, free_energy, entropy, cv )
         f.write(("%12.3f " + "%15.7f" + "\n") % ( t, free_energy))
     f.close()
     
     fc = open('thermal_properties','w')
     for t, free_energy, entropy, cv in np.array(phonon.get_thermal_properties()).T:
         fc.write(("%12.3f " + "%15.7f" *3 + "\n") % ( t, free_energy, entropy, cv ))
     fc.close()
     
     #phonon.plot_thermal_properties().show()
     
     #phonon.plot_total_DOS().show()
     phonon.write_total_DOS()
     #phonon.write_partial_DOS()
     phonon.write_yaml_thermal_properties()
     
     bands = []
     
     #### PRIMITIVE
     
     q_start  = np.array([0.0, 0.0, 0.0])
     #q_start  = np.array([0.5, 0.5, 0.0])
     q_end    = np.array([-0.5, 0.5, 0.5])
     #q_end    = np.array([0., 0., 0.])
     band = []
     for i in range(101):
         band.append(q_start + (q_end - q_start) / 100 * i)
     bands.append(band)
     
     band = []
     
     
     q_start  = np.array([-0.5, 0.5, 0.5])
     #q_start  = np.array([0., 0., 0.])
     q_end    = np.array([0.25, 0.25, 0.25])
     #q_end    = np.array([1., 0., 0.])
     
     for i in range(101):
         #band.append([-0.5+3*1/400*i, 0.5-1/400*i, 0.5-1/400*i])
         band.append(q_start + (q_end - q_start) / 100 * i)
     bands.append(band)
     #print band
     q_start  = np.array([0.25, 0.25, 0.25])
     q_end    = np.array([0., 0., 0.])
     band = []
     for i in range(101):
         band.append(q_start + (q_end - q_start) / 100 * i)
     bands.append(band)
     
     q_start  = np.array([0., 0., 0.])
     q_end    = np.array([0.0, 0., 0.5])
     band = []
     for i in range(101):
         band.append(q_start + (q_end - q_start) / 100 * i)
     bands.append(band)
     
     #q_start  = np.array([0.0, 0.0, 0.0])
     #q_end    = np.array([0.5, 0.5, 0.5])
     #band = []
     #for i in range(101):
     #    band.append(q_start + (q_end - q_start) / 100 * i)
     #bands.append(band)
     
     """
     ###### CONVENTIONAL CELL ######
     q_start  = np.array([0.0, 0.0, 0.0])
     q_end    = np.array([-0.5, 0.5, 0.5])
     band = []
     for i in range(101):
         band.append(q_start + (q_end - q_start) / 100 * i)
     bands.append(band)
     
     
     q_start  = np.array([-0.5, 0.5, 0.5])
     q_end    = np.array([1./4., 1./4., 1./4.])
     band = []
     for i in range(101):
         band.append(q_start + (q_end - q_start) / 100 * i)
     bands.append(band)
     q_start  = np.array([1./4., 1./4., 1./4.])
     q_end    = np.array([0.0, 0.0, 0.0])
     band = []
     for i in range(101):
         band.append(q_start + (q_end - q_start) / 100 * i)
     bands.append(band)
     q_start  = np.array([0.0, 0.0, 0.0])
     q_end    = np.array([0.5, 0.0, 0.0])
     band = []
     for i in range(101):
         band.append(q_start + (q_end - q_start) / 100 * i)
     bands.append(band)
     """
     phonon.set_band_structure(bands)
     #phonon.plot_band_structure().show()
     
     q_points, distances, frequencies, eigvecs = phonon.get_band_structure()
     disp = {'q':q_points, 'distances':distances, 'frequencies':frequencies, 'eigvecs':eigvecs}
     f = open('ph_dispersion.pkl','w')
     pickle.dump(disp, f)
     f.close()
示例#9
0
class PhononFromModel(object):
    """
    This class uses frozen phonon method to calculate the phonon dispersion curves and thermodynamic
    properties of a structure.
    The steps are as follows:
        1. Displaced structures are obtained from pristine structure via phonopy.
        2. The forces of each displaced structures are calculated by model
        3. The forces are passed to phonopy object and the force constant are produced
        4. Phonon is calculated once the force constant matrix is available.

    Args:
        model (model object): a model object that has a method "calculate_forces" that takes in a list of
            structures and return a list of N*3 forces, where N are the number of atoms in each structures
        structure (pymatgen structure): a pristine pymatgen structure
        atom_disp (float): small displacements in Angstrom

    """

    def __init__(self, model=None, structure=None, atom_disp=0.015, **kwargs):
        self.model = model
        self.structure = structure
        self.atom_disp = atom_disp
        self.qpoints, self.vertices = get_qpoints_and_vertices(self.structure)
        is_plusminus = kwargs.get('is_plusminus', True)
        is_diagonal = kwargs.get('is_diagonal', True)
        is_trigonal = kwargs.get('is_diagonal', False)
        supercell_matrix = kwargs.get('is_diagonal', None)
        ph_structure = get_phonopy_structure(self.structure)
        if supercell_matrix is None:
            supercell_matrix = np.eye(3) * np.array((1, 1, 1))
        self.phonon = Phonopy(unitcell=ph_structure, supercell_matrix=supercell_matrix)
        self.phonon.generate_displacements(distance=self.atom_disp,
                                      is_plusminus=is_plusminus,
                                      is_diagonal=is_diagonal,
                                      is_trigonal=is_trigonal)

        disp_supercells = self.phonon.get_supercells_with_displacements()
        # Perfect supercell structure
        init_supercell = self.phonon.get_supercell()
        # Structure list to be returned
        self.structure_list = [get_pmg_structure(init_supercell)]

        for c in disp_supercells:
            if c is not None:
                self.structure_list.append(get_pmg_structure(c))

        forces = self.model.calculate_forces(self.structure_list)
        self.phonon.set_forces(forces[1:])
        self.phonon.produce_force_constants()
        logging.info("Force constant produced") 

    def get_thermo_properties(self, mesh=[8, 8, 8], t_step=10, t_max=3000, t_min=0):
        self.phonon.set_mesh(mesh=mesh)
        self.phonon.set_thermal_properties(t_step=t_step,
                                           t_max=t_max,
                                           t_min=t_min)
        plt = self.phonon.plot_thermal_properties()
        return plt

    def get_bs_plot(self, points_per_line=50, figsize=(6, 4), ylim=[-1, 5]):
        bands = []
        bands = append_bands(bands, self.qpoints, points_per_line)
        self.phonon.set_band_structure(bands)
        q_points, self.distances, self.frequencies, eigvecs = self.phonon.get_band_structure()

        special_points = self.phonon._band_structure._special_points
        distance = self.phonon._band_structure._distance

        plt.figure(figsize=figsize)
        for j, (d, f) in enumerate(zip(self.distances, self.frequencies)):
            for i, freqs in enumerate(f.T):
                if i == 0 and j == 0:
                    plt.plot(d, freqs, "b-", lw=1)
                else:
                    plt.plot(d, freqs, "b-", lw=1)
        for sp in special_points:
            plt.axvline(x=sp, linestyle=':', linewidth=1, color='k')
        plt.axhline(y=0, linestyle=':', linewidth=1, color='k')

        plt.xticks(special_points, ["$\mathrm{%s}$" % i for i in self.vertices])
        plt.xlabel("Wave vector")
        plt.ylabel("Frequency (THz)")
        plt.xlim(0, distance)
        plt.ylim(ylim)
        plt.yticks(list(range(ylim[0], ylim[-1]+1)))
        plt.tight_layout()
        return plt
示例#10
0
def get_properties_from_phonopy(**kwargs):
    """
    Calculate DOS and thermal properties using phonopy (locally)
    :param structure: StructureData Object
    :param ph_settings: Parametersdata object containing a dictionary with the data needed to run phonopy:
            supercells matrix, primitive matrix and q-points mesh.
    :param force_constants: (optional)ForceConstantsData object containing the 2nd order force constants
    :param force_sets: (optional) ForceSetsData object containing the phonopy force sets
    :param nac: (optional) ArrayData object from a single point calculation data containing dielectric tensor and Born charges
    :return: phonon band structure, force constants, thermal properties and DOS
    """

    structure = kwargs.pop('structure')
    ph_settings = kwargs.pop('ph_settings')
    bands = kwargs.pop('bands')

    from phonopy import Phonopy

    phonon = Phonopy(phonopy_bulk_from_structure(structure),
                     supercell_matrix=ph_settings.dict.supercell,
                     primitive_matrix=ph_settings.dict.primitive,
                     symprec=ph_settings.dict.symmetry_precision)

    if 'force_constants' in kwargs:
        force_constants = kwargs.pop('force_constants')
        phonon.set_force_constants(force_constants.get_data())

    else:
        force_sets = kwargs.pop('force_sets')
        phonon.set_displacement_dataset(force_sets.get_force_sets())
        phonon.produce_force_constants()
        force_constants = ForceConstantsData(data=phonon.get_force_constants())

    if 'nac_data' in kwargs:
        print('use born charges')
        nac_data = kwargs.pop('nac_data')
        primitive = phonon.get_primitive()
        nac_parameters = nac_data.get_born_parameters_phonopy(
            primitive_cell=primitive.get_cell())
        phonon.set_nac_params(nac_parameters)

    # Normalization factor primitive to unit cell
    normalization_factor = phonon.unitcell.get_number_of_atoms(
    ) / phonon.primitive.get_number_of_atoms()

    # DOS
    phonon.set_mesh(ph_settings.dict.mesh,
                    is_eigenvectors=True,
                    is_mesh_symmetry=False)
    phonon.set_total_DOS(tetrahedron_method=True)
    phonon.set_partial_DOS(tetrahedron_method=True)

    total_dos = phonon.get_total_DOS()
    partial_dos = phonon.get_partial_DOS()
    dos = PhononDosData(
        frequencies=total_dos[0],
        dos=total_dos[1] * normalization_factor,
        partial_dos=np.array(partial_dos[1]) * normalization_factor,
        atom_labels=np.array(phonon.primitive.get_chemical_symbols()))

    # THERMAL PROPERTIES (per primtive cell)
    phonon.set_thermal_properties()
    t, free_energy, entropy, cv = phonon.get_thermal_properties()

    # Stores thermal properties (per unit cell) data in DB as a workflow result
    thermal_properties = ArrayData()
    thermal_properties.set_array('temperature', t)
    thermal_properties.set_array('free_energy',
                                 free_energy * normalization_factor)
    thermal_properties.set_array('entropy', entropy * normalization_factor)
    thermal_properties.set_array('heat_capacity', cv * normalization_factor)

    # BAND STRUCTURE
    phonon.set_band_structure(bands.get_bands())
    band_structure = BandStructureData(bands=bands.get_bands(),
                                       labels=bands.get_labels(),
                                       unitcell=bands.get_unitcell())

    band_structure.set_band_structure_phonopy(phonon.get_band_structure())
    return {
        'thermal_properties': thermal_properties,
        'dos': dos,
        'band_structure': band_structure,
        'force_constants': force_constants
    }