def test_custom_units(self): matplotlib_bands(self.bands, pyplot.gca(), energy_units=2 * Ry, energy_units_name="Hartree") assert pyplot.gca().get_yaxis().get_label().get_text().endswith( "(Hartree)")
def test_plot_weights_size(self): rlc = matplotlib_bands(self.bands, pyplot.gca(), weights_size=self.weights) a = rlc.get_linewidth() b = self.weights assert a[0] == 0.5 * (b[0, 0] + b[1, 0]) assert a[-1] == 0.5 * (b[-2, -1] + b[-1, -1])
def test_plot_weights_color(self): rlc = matplotlib_bands(self.bands, pyplot.gca(), weights_color=self.weights) a = rlc.get_array() b = self.weights assert a[0] == 0.5 * (b[0, 0] + b[1, 0]) assert a[-1] == 0.5 * (b[-2, -1] + b[-1, -1])
def _test_plot(self, units): rlc = matplotlib_bands(self.bands, pyplot.gca(), units = units) axes = pyplot.gcf().axes assert len(axes) == 1 axes = axes[0] lc = axes.findobj(LineCollection) assert len(lc) == 1 lc = lc[0] assert lc == rlc segments = lc.get_segments() assert len(segments) == (30*3-3)*3 testing.assert_equal(axes.get_ylim(), numpy.array((0,3))*eV/getattr(numericalunits, units)) assert axes.get_yaxis().get_label().get_text().endswith("("+units+")")
def _test_plot(self, units): rlc = matplotlib_bands(self.bands, pyplot.gca(), energy_units=units) axes = pyplot.gcf().axes assert len(axes) == 1 axes = axes[0] lc = axes.findobj(LineCollection) assert len(lc) == 1 lc = lc[0] assert lc == rlc segments = lc.get_segments() assert len(segments) == (30 * 3 - 3) * 3 testing.assert_allclose( axes.get_ylim(), numpy.array((-0.15, 3.15)) * eV / getattr(numericalunits, units)) assert axes.get_yaxis().get_label().get_text().endswith("(" + units + ")")
def test_huge_bands(self): matplotlib_bands(self.huge_bands, pyplot.gca()) axes = pyplot.gca() y = axes.get_ylim() assert y[0] > -2 and y[0] < -1 assert y[1] > 3 and y[1] < 4
def test_plot_weights_error(self): with self.assertRaises(TypeError): matplotlib_bands(self.bands, pyplot.gca(), weights=self.weights[..., numpy.newaxis])
def test_plot_weights_error(self): with self.assertRaises(TypeError): matplotlib_bands(self.bands, pyplot.gca(), weights = self.weights[...,numpy.newaxis])
from dfttools.simple import parse from dfttools import presentation import numpy from matplotlib import pyplot with open("plot.py.data",'r') as f: # Retrieve the last band structure from the file bands = parse(f, "band-structure")[-1] # Convert to a grid grid = bands.as_grid() # Interpolate kp_path = numpy.linspace(0,1)[:,numpy.newaxis] * ((1./3,2./3,0),) bands = grid.interpolate_to_cell(kp_path) # Plot presentation.matplotlib_bands(bands, pyplot.gca()) pyplot.show()
basis, kp, numpy.zeros((100,2), dtype = numpy.float64), ) # Calculate graphene band k = bands.cartesian()*numpy.pi/3.**.5*2 e = (1+4*numpy.cos(k[...,1])**2 + 4*numpy.cos(k[...,1])*numpy.cos(k[...,0]*3.**.5))**.5*eV # Set the band values bands.values[...,0] = -e bands.values[...,1] = e # Assign some weights weights = bands.values.copy() weights -= weights.min() weights /= weights.max() # Prepare axes ax_left = pyplot.subplot2grid((1,3), (0, 0), colspan=2) ax_right = pyplot.subplot2grid((1,3), (0, 2)) # Plot bands p = presentation.matplotlib_bands(bands,ax_left,weights = weights) presentation.matplotlib_bands_density(bands, ax_right, 100, orientation = 'portrait') presentation.matplotlib_bands_density(bands, ax_right, 100, orientation = 'portrait', weights = weights, use_fill = True, color = "#AAAAFF") ax_right.set_ylabel('') pyplot.colorbar(p) pyplot.show()
from dfttools.simple import parse from dfttools import presentation from matplotlib import pyplot with open("plot.py.data",'r') as f: # Read bands data bands = parse(f, "band-structure") # Prepare axes ax_left = pyplot.subplot2grid((1,3), (0, 0), colspan=2) ax_right = pyplot.subplot2grid((1,3), (0, 2)) # Plot bands presentation.matplotlib_bands(bands,ax_left) presentation.matplotlib_bands_density(bands, ax_right, 100, orientation = 'portrait') ax_right.set_ylabel('') pyplot.show()
def test_plot_weights_color(self): rlc = matplotlib_bands(self.bands, pyplot.gca(), weights_color = self.weights) a = rlc.get_array() b = self.weights assert a[0] == 0.5*(b[0,0]+b[1,0]) assert a[-1] == 0.5*(b[-2,-1]+b[-1,-1])
def test_unknown_units(self): matplotlib_bands(self.bands, pyplot.gca(), units = 2*Ry) assert pyplot.gca().get_yaxis().get_label().get_text() == 'Energy'
def test_custom_units(self): matplotlib_bands(self.bands, pyplot.gca(), units = 2*Ry, units_name = "Hartree") assert pyplot.gca().get_yaxis().get_label().get_text().endswith("(Hartree)")
def test_huge_bands(self): matplotlib_bands(self.huge_bands, pyplot.gca()) axes = pyplot.gca() y = axes.get_ylim() assert y[0]>-2 and y[0]<-1 assert y[1]>3 and y[1]<4
from dfttools.parsers.openmx import bands from dfttools import presentation from matplotlib import pyplot with open("plot.py.data",'r') as f: # Read bands data b = bands(f.read()).bands() # Plot bands presentation.matplotlib_bands(b,pyplot.gca()) pyplot.show()
# Set the band values bands.values[..., 0] = -e bands.values[..., 1] = e # Assign some weights weights = bands.values.copy() weights -= weights.min() weights /= weights.max() # Prepare axes ax_left = pyplot.subplot2grid((1, 3), (0, 0), colspan=2) ax_right = pyplot.subplot2grid((1, 3), (0, 2)) # Plot bands p = presentation.matplotlib_bands(bands, ax_left, weights=weights) presentation.matplotlib_bands_density(bands, ax_right, 100, orientation='portrait') presentation.matplotlib_bands_density(bands, ax_right, 100, orientation='portrait', weights=weights, use_fill=True, color="#AAAAFF") ax_right.set_ylabel('') pyplot.colorbar(p) pyplot.show()
def test_unknown_units(self): matplotlib_bands(self.bands, pyplot.gca(), energy_units=2 * Ry) assert pyplot.gca().get_yaxis().get_label().get_text() == 'Energy'
from dfttools.simple import parse from dfttools import presentation from matplotlib import pyplot with open("plot.py.data",'r') as f: # Read bands data bands = parse(f, "band-structure")[0] # Prepare axes ax_left = pyplot.subplot2grid((1,3), (0, 0), colspan=2) ax_right = pyplot.subplot2grid((1,3), (0, 2)) # Plot bands presentation.matplotlib_bands(bands,ax_left) presentation.matplotlib_bands_density(bands, ax_right, 100, orientation = 'portrait') ax_right.set_ylabel('') pyplot.show()
def test_plot_weights_size(self): rlc = matplotlib_bands(self.bands, pyplot.gca(), weights_size = self.weights) a = rlc.get_linewidth() b = self.weights assert a[0] == 0.5*(b[0,0]+b[1,0]) assert a[-1] == 0.5*(b[-2,-1]+b[-1,-1])