Minor fixes

This commit is contained in:
Atsushi Togo 2014-12-27 17:30:00 +09:00
parent 48992c1640
commit f180cf9484
4 changed files with 77 additions and 22 deletions

View File

@ -492,7 +492,7 @@ class Phonopy:
def write_yaml_mesh(self): def write_yaml_mesh(self):
self._mesh.write_yaml() self._mesh.write_yaml()
def plot_band_structure_and_dos(self, symbols=None): def plot_band_structure_and_dos(self, pdos_indices=None, symbols=None):
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec import matplotlib.gridspec as gridspec
if symbols: if symbols:
@ -506,10 +506,18 @@ class Phonopy:
ax2 = plt.subplot(gs[0, 1], sharey=ax1) ax2 = plt.subplot(gs[0, 1], sharey=ax1)
plt.subplots_adjust(wspace=0.03) plt.subplots_adjust(wspace=0.03)
plt.setp(ax2.get_yticklabels(), visible=False) plt.setp(ax2.get_yticklabels(), visible=False)
if pdos_indices is None:
self._total_dos.plot(plt, self._total_dos.plot(plt,
ylabel="", ylabel="",
draw_grid=False, draw_grid=False,
flip_xy=True) flip_xy=True)
else:
self._pdos.plot(plt,
indices=pdos_indices,
ylabel="",
draw_grid=False,
flip_xy=True)
return plt return plt

View File

@ -100,9 +100,6 @@ def plot_partial_dos(pyplot,
ylabel=None, ylabel=None,
draw_grid=True, draw_grid=True,
flip_xy=False): flip_xy=False):
pyplot.grid(draw_grid)
pyplot.xlabel('Frequency')
pyplot.ylabel('Partial density of states')
plots = [] plots = []
num_atom = len(partial_dos) num_atom = len(partial_dos)
@ -119,11 +116,21 @@ def plot_partial_dos(pyplot,
print "Your specified atom number is out of range." print "Your specified atom number is out of range."
raise ValueError raise ValueError
pdos_sum += partial_dos[i] pdos_sum += partial_dos[i]
if flip_xy:
plots.append(pyplot.plot(pdos_sum, frequency_points))
else:
plots.append(pyplot.plot(frequency_points, pdos_sum)) plots.append(pyplot.plot(frequency_points, pdos_sum))
if legend is not None: if legend is not None:
pyplot.legend(legend) pyplot.legend(legend)
if xlabel:
pyplot.xlabel(xlabel)
if ylabel:
pyplot.ylabel(ylabel)
pyplot.grid(draw_grid)
class NormalDistribution: class NormalDistribution:
def __init__(self, sigma): def __init__(self, sigma):
self._sigma = sigma self._sigma = sigma
@ -366,12 +373,36 @@ class PartialDos(Dos):
""" """
return self._frequency_points, self._partial_dos return self._frequency_points, self._partial_dos
def plot(self, pyplot, indices=None, legend=None): def plot(self,
pyplot,
indices=None,
legend=None,
xlabel=None,
ylabel=None,
draw_grid=True,
flip_xy=False):
if flip_xy:
_xlabel = 'Partial density of states'
_ylabel = 'Frequency'
else:
_xlabel = 'Frequency'
_ylabel = 'Partial density of states'
if xlabel is not None:
_xlabel = xlabel
if ylabel is not None:
_ylabel = ylabel
plot_partial_dos(pyplot, plot_partial_dos(pyplot,
self._frequency_points, self._frequency_points,
self._partial_dos, self._partial_dos,
indices=indices, indices=indices,
legend=legend) legend=legend,
xlabel=_xlabel,
ylabel=_ylabel,
draw_grid=draw_grid,
flip_xy=flip_xy)
def write(self): def write(self):
if self._tetrahedron_mesh is None: if self._tetrahedron_mesh is None:

View File

@ -221,9 +221,9 @@ if not options.is_gnuplot:
plt.xlim(distances[0], distances[-1]) plt.xlim(distances[0], distances[-1])
if options.f_max is not None: if options.f_max is not None:
plt.ylim(ymax = options.f_max) plt.ylim(ymax=options.f_max)
if options.f_min is not None: if options.f_min is not None:
plt.ylim(ymin = options.f_min) plt.ylim(ymin=options.f_min)
plt.axhline(y=0, linestyle=':', linewidth=0.5, color='b') plt.axhline(y=0, linestyle=':', linewidth=0.5, color='b')
if len(filenames) == 1: if len(filenames) == 1:
xticks = segment_positions + [distances[-1]] xticks = segment_positions + [distances[-1]]
@ -251,6 +251,10 @@ if not options.is_gnuplot:
plt.setp(ax2.get_yticklabels(), visible=False) plt.setp(ax2.get_yticklabels(), visible=False)
plt.plot(dos, dos_frequencies) plt.plot(dos, dos_frequencies)
plt.xlabel('DOS') plt.xlabel('DOS')
if options.f_max is not None:
plt.ylim(ymax=options.f_max)
if options.f_min is not None:
plt.ylim(ymin=options.f_min)
if options.output_filename is not None: if options.output_filename is not None:
plt.rcParams['pdf.fonttype'] = 42 plt.rcParams['pdf.fonttype'] = 42

View File

@ -1012,13 +1012,12 @@ elif run_mode == 'band' or run_mode == 'mesh' or run_mode == 'band_mesh':
# Partial DOS # Partial DOS
elif (settings.get_is_eigenvectors() and elif (settings.get_is_eigenvectors() and
(options.is_graph_plot or settings.get_is_dos_mode()) and (options.is_graph_plot or settings.get_is_dos_mode())):
(not settings.get_is_thermal_properties())):
p_direction = settings.get_projection_direction() p_direction = settings.get_projection_direction()
if log_level > 0: if log_level > 0:
if p_direction is not None: if p_direction is not None:
print "Projection direction:", np.array(p_direction) print "Projection direction:", np.array(p_direction)
print "Calculating PDOS..." print "Calculating partial DOS..."
dos_range = settings.get_dos_range() dos_range = settings.get_dos_range()
phonon.set_partial_DOS( phonon.set_partial_DOS(
sigma=settings.get_sigma(), sigma=settings.get_sigma(),
@ -1032,7 +1031,10 @@ elif run_mode == 'band' or run_mode == 'mesh' or run_mode == 'band_mesh':
if options.is_graph_plot: if options.is_graph_plot:
pdos_indices = settings.get_pdos_indices() pdos_indices = settings.get_pdos_indices()
if pdos_indices is None: if pdos_indices is None:
pdos_indices = [range(primitive.get_number_of_atoms())] pdos_indices = [[x] for x in
range(primitive.get_number_of_atoms())]
if options.is_graph_plot and run_mode != 'band_mesh':
plot = phonon.plot_partial_DOS( plot = phonon.plot_partial_DOS(
pdos_indices=pdos_indices, pdos_indices=pdos_indices,
legend=([np.array(x) + 1 for x in pdos_indices])) legend=([np.array(x) + 1 for x in pdos_indices]))
@ -1069,7 +1071,17 @@ elif run_mode == 'band' or run_mode == 'mesh' or run_mode == 'band_mesh':
else: else:
plot.show() plot.show()
if options.is_graph_plot and run_mode == 'band_mesh': if (run_mode == 'band_mesh' and
options.is_graph_plot and
not settings.get_is_thermal_properties() and
not settings.get_is_thermal_displacements() and
not settings.get_is_thermal_displacement_matrices() and
not settings.get_is_thermal_distances()):
if settings.get_is_eigenvectors():
plot = phonon.plot_band_structure_and_dos(
pdos_indices=pdos_indices,
symbols=settings.get_band_labels())
else:
plot = phonon.plot_band_structure_and_dos( plot = phonon.plot_band_structure_and_dos(
symbols=settings.get_band_labels()) symbols=settings.get_band_labels())
if options.is_graph_save: if options.is_graph_save: