def mvplot_trajectories(self, colormap="hot", sampling=1, figure=None, show=True, with_forces=True, **kwargs): # pragma: no cover """ Call mayavi_ to plot atomic trajectories and the variation of the unit cell. """ from abipy.display import mvtk figure, mlab = mvtk.get_fig_mlab(figure=figure) style = "labels" line_width = 100 mvtk.plot_structure(self.initial_structure, style=style, unit_cell_color=(1, 0, 0), figure=figure) mvtk.plot_structure(self.final_structure, style=style, unit_cell_color=(0, 0, 0), figure=figure) steps = np.arange(start=0, stop=self.num_steps, step=sampling) xcart_list = self.reader.read_value("xcart") * units.bohr_to_ang for iatom in range(self.reader.natom): x, y, z = xcart_list[::sampling, iatom, :].T #for i in zip(x, y, z): print(i) trajectory = mlab.plot3d(x, y, z, steps, colormap=colormap, tube_radius=None, line_width=line_width, figure=figure) mlab.colorbar(trajectory, title='Iteration', orientation='vertical') if with_forces: fcart_list = self.reader.read_cart_forces(unit="eV ang^-1") for iatom in range(self.reader.natom): x, y, z = xcart_list[::sampling, iatom, :].T u, v, w = fcart_list[::sampling, iatom, :].T q = mlab.quiver3d(x, y, z, u, v, w, figure=figure, colormap=colormap, line_width=line_width, scale_factor=10) #mlab.colorbar(q, title='Forces [eV/Ang]', orientation='vertical') if show: mlab.show() return figure
def test_mayavi_toolkit(self): """Test mayavi toolkit.""" if not self.has_mayavi(): raise self.SkipTest("This test requires mayavi!") figure, mlab = mvtk.get_fig_mlab(figure=None) si_structure = self.get_abistructure_from_abiref("si_nscf_GSR.nc") same_fig = mvtk.plot_wigner_seitz(si_structure.lattice, figure=figure) assert same_fig is figure figure = mvtk.plot_unit_cell(si_structure.lattice) assert mvtk.plot_lattice_vectors(si_structure.lattice, figure=figure) is figure assert mvtk.plot_structure(si_structure, frac_coords=False, to_unit_cell=False, style="points+labels", unit_cell_color=(0, 0, 0), color_scheme="VESTA", figure=None, show=False)
def mvanimate(self, delay=500): # pragma: no cover from abipy.display import mvtk figure, mlab = mvtk.get_fig_mlab(figure=None) style = "points" #mvtk.plot_structure(self.initial_structure, style=style, figure=figure) #mvtk.plot_structure(self.final_structure, style=style, figure=figure) xcart_list = self.reader.read_value("xcart") * units.bohr_to_ang #t = np.arange(self.num_steps) #line_width = 2 #for iatom in range(self.reader.natom): # x, y, z = xcart_list[:, iatom, :].T # trajectory = mlab.plot3d(x, y, z, t, colormap=colormap, tube_radius=None, line_width=line_width, figure=figure) #mlab.colorbar(trajectory, title='Iteration', orientation='vertical') #x, y, z = xcart_list[0, :, :].T #nodes = mlab.points3d(x, y, z) #nodes.glyph.scale_mode = 'scale_by_vector' #this sets the vectors to be a 3x5000 vector showing some random scalars #nodes.mlab_source.dataset.point_data.vectors = np.tile( np.random.random((5000,)), (3,1)) #nodes.mlab_source.dataset.point_data.scalars = np.random.random((5000,)) @mlab.show @mlab.animate(delay=delay, ui=True) def anim(): """Animate.""" for it, structure in enumerate(self.structures): #for it in range(self.num_steps): print('Updating scene for iteration:', it) #mlab.clf(figure=figure) mvtk.plot_structure(structure, style=style, figure=figure) #x, y, z = xcart_list[it, :, :].T #nodes.mlab_source.set(x=x, y=y, z=z) #figure.scene.render() mlab.draw(figure=figure) yield anim()