def generate_scripts(self, fname, isosurf=0.8): """Generate VMD scripts & cube file to visualize ELF iso-surface. Parameters ---------- fname : str File name used for the generated files. The VMD script and cube file will be named fname.vmd and fname-elf.cube, respectively. isosurf : float, optional Value of ELF iso-surface used in VMD script. """ if not isinstance(self._grid, UniformGrid): raise ValueError('Only possible if argument grid is a cubic grid.') if self._denstool.density.shape[0] != self._grid.points.shape[0]: raise ValueError( 'Number of grid points should match number of dens values!') # dump ELF cube file & generate vmd script vmdname = fname + '.vmd' cubname = fname + '-elf.cube' self._grid.generate_cube(cubname, self.value) print_vmd_script_isosurface(vmdname, cubname, isosurf=isosurf, representation='Line')
def main_esp(args): """Generate VMD script and cube files for visualizing ESP on electron density iso-surface.""" # load molecule & cubic grid mol, cube = load_molecule_and_grid(args.fname, args.cube) # dump files for visualization output = args.output if output is None: output = args.fname.split(".")[0] espname = output + "_esp.cube" rhoname = output + "_dens.cube" vmdname = output + ".vmd" cube.generate_cube(rhoname, mol.compute_density(cube.points)) cube.generate_cube(espname, mol.compute_esp(cube.points)) print_vmd_script_isosurface(vmdname, rhoname, colorfile=espname, isosurf=args.isosurface, scalemin=args.scalemin, scalemax=args.scalemax)
def generate_scripts(self, fname, spin='a', index=None, isosurf=0.05, grid=None): """Generate VMD script(s) and cube file(s) to visualize MO iso-surface of given orbitals. Parameters ---------- fname : str A string representing the path to a fname of generated files. The VMD script and cube file will be named fname_mo{index}.vmd and fname_mo{index}.cube, respectively. spin : str, optional The type of occupied spin orbitals. Choose either 'a' or 'b'. index : int, optional Integer representing the index of spin orbital to visualize. Spin orbitals are each indexed from 1 to :attr:`nbasis`. If None, files for visualizing all orbitals are generated. isosurf : float, optional Value of MO iso-surface used in VMD script. grid : UniformGrid, optional Instance of UniformGrid used for computation and generating cube file(s). If None, a cubic grid is constructed from molecule with spacing=0.2 & extension=5.0. """ if spin not in ['a', 'b']: raise ValueError('Argument spin can only be "a" or "b".') if index is not None and not isinstance(index, int): raise ValueError('Argument index is either None or an integer for visualization. ' 'Given index={0}'.format(index)) if grid is None: grid = UniformGrid.from_molecule(self._molecule, spacing=0.2, extension=5.0, rotate=True) elif not isinstance(grid, UniformGrid): raise ValueError('Argument grid should be a UniformGrid to generate cube files.') if index is None: spin_index = {'a': 0, 'b': 1} index = range(1, self._molecule.mo.homo_index[spin_index[spin]] + 1) else: index = [index] for mo_index in index: vmdname = fname + '_mo{0}.vmd'.format(mo_index) cubname = fname + '_mo{0}.cube'.format(mo_index) mo_value = self.compute_orbital_expression(grid.points, spin=spin, index=mo_index) grid.generate_cube(cubname, mo_value) print_vmd_script_isosurface(vmdname, cubname, isosurf=isosurf, negative=True, material='BlownGlass')
def generate_scripts(self, fname, isosurf=0.5): """Generate VMD scripts & cube file to visualize LOL iso-surface. Parameters ---------- fname : str A string representing the path to a fname of generated files. The VMD script and cube file will be named fname.vmd and fname-lol.cube, respectively. isosurf : float Value of LOL iso-surface used in VMD script. """ if not isinstance(self._grid, UniformGrid): raise ValueError("Only possible if argument grid is a cubic grid.") # dump LOL cube files fname_vmd = fname + '.vmd' fname_lol = fname + '-lol.cube' self._grid.generate_cube(fname_lol, self.value) # write VMD script for visualization print_vmd_script_isosurface(fname_vmd, fname_lol, isosurf=isosurf, representation='Line')
def test_print_vmd_script_isosurface(): with tmpdir( 'chemtools.utils.test.test_base.test_vmd_script_isosurface') as dn: fname = '%s/%s' % (dn, 'test.vmd') vmd.print_vmd_script_isosurface(fname, 'iso.cube') with open(fname, 'r') as content_file: assert content_file.read() == \ (header + '# load new molecule\n' 'mol new iso.cube type cube first 0 last -1 step 1 filebonds 1 autobonds 1 ' 'waitfor all\n' '#\n' '# representation of the atoms\n' 'mol representation CPK 1.000000 0.300000 118.000000 131.000000\n' 'mol delrep 0 top\n' 'mol color Element\n' 'mol selection {{all}}\n' 'mol material Opaque\n' 'mol addrep top\n' '#\n' '# add representation of the surface\n' 'mol representation Isosurface 0.50000 0 0 0 1 1\n' 'mol color ColorID 0\n' 'mol selection {all}\n' 'mol material Opaque\n' 'mol addrep top\n' 'mol selupdate 1 top 0\n' 'mol colupdate 1 top 0\n' 'mol scaleminmax top 1 -0.050000 0.050000\n' 'mol smoothrep top 1 0\n' 'mol drawframes top 1 {now}\n' 'color scale method RGB\n' 'color Display Background silver\n' '#\n') vmd.print_vmd_script_isosurface(fname, 'iso.cube', colorfile='col.cube', isosurf=0.6, material='Transparent', scalemin=-0.06, scalemax=0.08) with open(fname, 'r') as content_file: assert content_file.read() == \ (header + '# load new molecule\n' 'mol new col.cube type cube first 0 last -1 step 1 filebonds 1 autobonds 1 ' 'waitfor all\n' 'mol addfile iso.cube type cube first 0 last -1 step 1 filebonds 1 autobonds 1 ' 'waitfor all\n' '#\n' '# representation of the atoms\n' 'mol representation CPK 1.000000 0.300000 118.000000 131.000000\n' 'mol delrep 0 top\n' 'mol color Element\n' 'mol selection {{all}}\n' 'mol material Opaque\n' 'mol addrep top\n' '#\n' '# add representation of the surface\n' 'mol representation Isosurface 0.60000 1 0 0 1 1\n' 'mol color Volume 0\n' 'mol selection {all}\n' 'mol material Transparent\n' 'mol addrep top\n' 'mol selupdate 1 top 0\n' 'mol colupdate 1 top 0\n' 'mol scaleminmax top 1 -0.060000 0.080000\n' 'mol smoothrep top 1 0\n' 'mol drawframes top 1 {now}\n' 'color scale method RGB\n' 'color Display Background silver\n' '#\n') vmd.print_vmd_script_isosurface(fname, 'iso.cube', colorscheme=[0, 1], negative=True) with open(fname, 'r') as content_file: assert content_file.read() == \ (header + '# load new molecule\n' 'mol new iso.cube type cube first 0 last -1 step 1 filebonds 1 autobonds 1 ' 'waitfor all\n' '#\n' '# representation of the atoms\n' 'mol representation CPK 1.000000 0.300000 118.000000 131.000000\n' 'mol delrep 0 top\n' 'mol color Element\n' 'mol selection {{all}}\n' 'mol material Opaque\n' 'mol addrep top\n' '#\n' '# add representation of the surface\n' 'mol representation Isosurface 0.50000 0 0 0 1 1\n' 'mol color ColorID 0\n' 'mol selection {all}\n' 'mol material Opaque\n' 'mol addrep top\n' 'mol selupdate 1 top 0\n' 'mol colupdate 1 top 0\n' 'mol scaleminmax top 1 -0.050000 0.050000\n' 'mol smoothrep top 1 0\n' 'mol drawframes top 1 {now}\n' 'color scale method RGB\n' 'color Display Background silver\n' '#\n' '# add representation of the surface\n' 'mol representation Isosurface -0.50000 0 0 0 1 1\n' 'mol color ColorID 1\n' 'mol selection {all}\n' 'mol material Opaque\n' 'mol addrep top\n' 'mol selupdate 1 top 0\n' 'mol colupdate 1 top 0\n' 'mol scaleminmax top 1 -0.050000 0.050000\n' 'mol smoothrep top 1 0\n' 'mol drawframes top 1 {now}\n' 'color scale method RGB\n' 'color Display Background silver\n' '#\n')