def main_nci(args): """Build NCI model and dump VMD script and cube files for visualizing NCI with VMD.""" # load molecule mol = Molecule.from_file(args.fname) # make cubic grid if args.cube.endswith('.cube'): # load cube file cube = UniformGrid.from_cube(args.cube) elif len(args.cube.split(',')) == 2: # make a cubic grid spacing, extension = [float(item) for item in args.cube.split(',')] cube = UniformGrid.from_molecule(mol, spacing=spacing, extension=extension, rotate=True) else: raise ValueError('Argument cube={0} is not recognized!'.format( args.cube)) # build NCI model nci = NCI.from_molecule(mol, grid=cube) # dump files/scripts for visualizing NCI nci.generate_scripts(args.output, isosurf=args.isosurface, denscut=args.denscut) # plot reduced density gradient vs. signed density if args.plot: nci.generate_plot(args.output, color=args.color)
def main_esp(args): """Generate VMD script and cube files for visualizing ESP on electron density iso-surface.""" # load molecule mol = Molecule.from_file(args.fname) # make cubic grid if args.cube.endswith('.cube'): # load cube file cube = UniformGrid.from_cube(args.cube) elif len(args.cube.split(',')) == 2: # make a cubic grid spacing, extension = [float(item) for item in args.cube.split(',')] cube = UniformGrid.from_molecule(mol, spacing=spacing, extension=extension, rotate=True) else: raise ValueError('Argument cube={0} is not recognized!'.format(args.cube)) # dump cube files & script for visualization espname = args.output + '_esp.cube' rhoname = args.output + '_rho.cube' vmdname = args.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 main_mot(args): """Build MOTBasedTool model and dump VMD script and cube files for visualizing MO.""" # load molecule mol = Molecule.from_file(args.fname) # make cubic grid if args.cube.endswith('.cube'): # load cube file cube = UniformGrid.from_cube(args.cube) elif len(args.cube.split(',')) == 2: # make a cubic grid spacing, extension = [float(item) for item in args.cube.split(',')] cube = UniformGrid.from_molecule(mol, spacing=spacing, extension=extension, rotate=True) else: raise ValueError('Argument cube={0} is not recognized!'.format(args.cube)) if args.index is not None: index = [int(item) for item in args.index.split(',')] if len(index) == 1: index = index[0] else: index = None # build MOT model mot = MOTBasedTool.from_molecule(mol) # print logging message logging.info('') logging.info('Initialized : {0}'.format(mot)) logging.info('# of basis : {0}'.format(mot.nbasis)) logging.info('# of a & b electrons : {0}'.format(mot.nelectrons)) logging.info('') logging.info('Index of a & b LUMO : {0}'.format(mot.lumo_index)) logging.info('Energy of a & b LUMO : {0}'.format(mot.lumo_energy)) logging.info('') logging.info('Index of a & b H**O : {0}'.format(mot.homo_index)) logging.info('Energy of a & b H**O : {0}'.format(mot.homo_energy)) logging.info('') # dump file/script for visualizing MOT mot.generate_scripts(args.output, spin=args.spin, index=index, grid=cube, isosurf=args.isosurface)
def main_lol(args): """Build LOL model and dump VMD script and cube files for visualizing LOL.""" # load molecule mol = Molecule.from_file(args.fname) # make cubic grid if args.cube.endswith('.cube'): # load cube file cube = UniformGrid.from_cube(args.cube) elif len(args.cube.split(',')) == 2: # make a cubic grid spacing, extension = [float(item) for item in args.cube.split(',')] cube = UniformGrid.from_molecule(mol, spacing=spacing, extension=extension, rotate=True) else: raise ValueError('Argument cube={0} is not recognized!'.format(args.cube)) # build LOL model lol = LOL.from_molecule(mol, grid=cube, trans=args.trans, trans_k=args.trans_k, trans_a=args.trans_a, denscut=args.denscut) # dump file/script for visualizing LOL lol.generate_scripts(args.output, isosurf=args.isosurface)
def main_conceptual_local(args): """Build LocalConceptualDFT class and dump a cube file of local descriptor.""" # load the first molecule mol = Molecule.from_file(args.file_wfn[0]) # make cubic grid if args.cube.endswith('.cube'): # load cube file cube = UniformGrid.from_cube(args.cube) elif len(args.cube.split(',')) == 2: # make a cubic grid spacing, threshold = [float(item) for item in args.cube.split(',')] cube = UniformGrid.from_molecule(mol, spacing, threshold) else: raise ValueError('Argument cube={0} is not recognized!'.format( args.cube)) # build global tool model = LocalConceptualDFT.from_file(args.file_wfn, args.model, cube.points) # check whether local property exists if not hasattr(model, args.prop): raise ValueError('The {0} local conceptual DFT class does not contain ' '{1} attribute.'.format(args.model, args.prop)) if callable(getattr(model, args.prop)): raise ValueError( 'The {0} argument is a method, please provide an attribute of ' '{1} local conceptual DFT.'.format(args.prop, args.model)) # name of files cubefile = '{0}.cube'.format(args.output_name) vmdfile = '{0}.vmd'.format(args.output_name) # dump cube file of local property cube.generate_cube(cubefile, getattr(model, args.prop)) # generate VMD scripts for visualizing iso-surface with VMD print_vmd_script_isosurface(vmdfile, cubefile, isosurf=args.isosurface)
r""" =================================================== EX1: ESP from wave-function file & user-defied cube =================================================== Compute ESP and visualize it on electron density iso-surface for SCl2. """ from chemtools import UniformGrid, Molecule, print_vmd_script_isosurface # 1. Build Molecule fname = 'scl2' mol = Molecule.from_file(fname + '.fchk') cub = UniformGrid.from_molecule(mol, spacing=1.0, extension=5.0) # 2. Generate cube files: fname_esp.cube & fname_rho.cube espname = fname + '_esp.cube' rhoname = fname + '_rho.cube' cub.generate_cube(rhoname, mol.compute_density(cub.points)) cub.generate_cube(espname, mol.compute_esp(cub.points)) # 3. Generate vmd script: fname.vmd # To visualize the iso-surface, use command: $ vmd -e fname.vmd print_vmd_script_isosurface(fname + '.vmd', rhoname,
r""" ============================================ EX3: LOL from Molecule and user-defined cube ============================================ Compute LOL and visualize it for formamide, using the inverse hyperbolic transformation. """ from chemtools import LOL, UniformGrid, Molecule # 1. Build Molecule, UnifromGrid and LOL model mol = Molecule.from_file('formamide_q+0.fchk') cub = UniformGrid.from_molecule(mol, spacing=0.1, extension=2.0) lol = LOL.from_molecule(mol, grid=cub, trans='inverse_hyperbolic', trans_k=1, trans_a=1) # 2. Generate cube file(s) and script for visualizing LOL # Files generated are chonh2-lol.cube & chonh2.vmd # To visualize the iso-surface, use command: $ vmd -e chonh2.vmd lol.generate_scripts('chonh2', isosurf=0.55) # DISCARD BELOW: # the code below is for displaying the LOL image on the website, you should remove it # when running the script on your machine. from tools.rug import plot_existing_image plot_existing_image('lol055_chonh2_hyperbolic.jpg')
r""" ============================================ EX3: NCI from Molecule and user-defined cube ============================================ Compute NCI and visualize it for formic acid dimer. """ from chemtools import NCI, UniformGrid, Molecule # 1. Build UniformGrid and NCI model mol = Molecule.from_file('formic_acid_dimer.fchk') cub = UniformGrid.from_molecule(mol, spacing=0.1, extension=0.5) nci = NCI.from_molecule(mol, grid=cub) # 2. Generate plot, cube file(s) and script for visualizing NCI # Files generated are formic_acid_dimer-dens.cube, formic_acid_dimer-grad.cube, # & formic_acid_dimer.vmd # To visualize the iso-surface, use command: $ vmd -e formic_acid_dimer.vmd # nci.generate_plot('formic_acid_dimer', denslim=(-0.15, 0.15)) nci.generate_scripts('formic_acid_dimer') # DISCARD BELOW: # the code below is for displaying the NCI image on the website, you should remove it # when running the script on your machine. from tools.rug import plot_existing_image plot_existing_image('nci_formic_acid_dimer.jpg')
Compute ELF and visualize spherically averaged ELF for Kr atom using 'rational' & 'hyperbolic' transformations. """ import numpy as np import matplotlib.pyplot as plt from chemtools import Molecule, ELF from horton import AtomicGrid # 1. Build Molecule, AtomicGrid and ELF model mol = Molecule.from_file('atom_kr.fchk') grid = AtomicGrid(mol.numbers[0], mol.pseudo_numbers[0], mol.coordinates[0], agspec='exp:0.005:10.0:200:194', random_rotate=False) elf_r = ELF.from_molecule(mol, grid=grid, trans='rational', trans_k=2, trans_a=1) elf_h = ELF.from_molecule(mol, grid=grid, trans='hyperbolic', trans_k=1, trans_a=1) # 2. Compute spherically-averaged density ($4.0 \pi r^2 \rho$) & ELF elf_r = grid.get_spherical_average(elf_r.value) elf_h = grid.get_spherical_average(elf_h.value) dens = grid.get_spherical_average(mol.compute_density(points=grid.points)) dens *= (4.0 * np.pi * grid.rgrid.radii**2) # 3. Plot ElF and (scaled) radially weighted density versus radius
def main_mot(args): """Build MOTBasedTool model and dump VMD script and cube files for visualizing MO.""" # load molecule mol = Molecule.from_file(args.fname) hia, hib = np.array(mol.homo_index) - 1 lia, lib = np.array(mol.lumo_index) - 1 ea, eb = mol.orbital_energy print('') print('File: {0}'.format(args.fname)) # print('Charge : % 5f' % np.sum(mol.numbers) - np.sum(ne)) # print('Multiplicity: % 5d' % np.max(ne) - np.min(ne) + 1) print('') print('Atomic number and coordinates:') for index, num in enumerate(mol.numbers): coord = mol.coordinates[index, :] print('% 2i %10.6f %10.6f %10.6f' % (num, coord[0], coord[1], coord[2])) print('') print('Information on alpha & beta electrons:') print('# electrons : % 3.3f % 3.3f' % mol.nelectrons) print('H**O index : % 3d % 5d' % mol.homo_index) print('') print('LUMO+2 index : %10.6f %10.6f' % (ea[lia + 2], eb[lib + 2])) print('LUMO+1 energy: %10.6f %10.6f' % (ea[lia + 1], eb[lib + 1])) print('LUMO energy: %10.6f %10.6f' % mol.lumo_energy) print('H**O energy: %10.6f %10.6f' % mol.homo_energy) print('H**O-1 energy: %10.6f %10.6f' % (ea[hia - 1], eb[hib - 1])) print('H**O-2 energy: %10.6f %10.6f' % (ea[hia - 2], eb[hib - 2])) print('') if args.info: return # make cubic grid if args.cube.endswith('.cube'): # load cube file cube = UniformGrid.from_cube(args.cube) elif len(args.cube.split(',')) == 2: # make a cubic grid spacing, extension = [float(item) for item in args.cube.split(',')] cube = UniformGrid.from_molecule(mol, spacing=spacing, extension=extension, rotate=True) else: raise ValueError('Argument cube={0} is not recognized!'.format( args.cube)) if args.index is not None: index = [int(item) for item in args.index.split(',')] if len(index) == 1: index = index[0] else: index = None # build MOT model mot = MOTBasedTool.from_molecule(mol) # print logging message # logging.info('') # logging.info('Initialized : {0}'.format(mot)) # logging.info('# of basis : {0}'.format(mot.nbasis)) # logging.info('# of a & b electrons : {0}'.format(mot.nelectrons)) # logging.info('') # logging.info('Index of a & b LUMO : {0}'.format(mot.lumo_index)) # logging.info('Energy of a & b LUMO : {0}'.format(mot.lumo_energy)) # logging.info('') # logging.info('Index of a & b H**O : {0}'.format(mot.homo_index)) # logging.info('Energy of a & b H**O : {0}'.format(mot.homo_energy)) # logging.info('') # dump file/script for visualizing MOT if args.output is None: args.output = args.fname.rsplit('.')[0] mot.generate_scripts(args.output, spin=args.spin, index=index, grid=cube, isosurf=args.isosurface)
r""" ================================= EX1: Topology of Electron Density ================================= Compute critical points and visualize it for cyclobutadiene. """ from chemtools import Molecule, UniformGrid, TopologicalTool # 1. Build Topology model mol = Molecule.from_file('c4h4.fchk') cub = UniformGrid.from_molecule(mol, spacing=0.1, extension=0.1, rotate=False) top = TopologicalTool.from_molecule(mol, points=cub.points) # 2. Generate vmd script: fname.vmd # To visualize the iso-surface, use command: $ vmd -e fname.vmd top.generate_scripts('c4h4.vmd') # DISCARD BELOW: # the code below is for displaying the ELF image on the website, you should remove it # when running the script on your machine. from tools.rug import plot_existing_image plot_existing_image('top_c4h4.jpg')