コード例 #1
0
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)
コード例 #2
0
ファイル: chemtools_esp.py プロジェクト: kimt33/chemtools-1
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)
コード例 #3
0
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)
コード例 #4
0
ファイル: chemtools_lol.py プロジェクト: tovrstra/chemtools
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)
コード例 #5
0
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)
コード例 #6
0
ファイル: ex001_esp_plot.py プロジェクト: kimt33/chemtools-1
===================================================
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,
                            colorfile=espname,
コード例 #7
0
ファイル: ex003_lol_plot.py プロジェクト: kimt33/chemtools-1
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')
コード例 #8
0
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)
コード例 #9
0
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')