Пример #1
0
# orbkit options
ok.options.filename = 'h2o.molden'  # input file name
ok.options.itype = 'molden'  # input file type
ok.options.outputname = 'h2o_MO'  # output file (base) name
ok.options.otype = 'h5'  # output file type
ok.options.numproc = 1  # number of processes for multiprocessing
ok.options.slice_length = 4e4  # number of points per process
ok.options.calc_mo = 'MO_List.tab'  # list of molecular orbitals to be used

# first run: do not calculate derivatives
ok.options.drv = None  # do not calculate derivative
ok.options.no_output = True  # we will create our own output

# run orbkit
mo_list, mo = ok.run_orbkit()

# create output: molecular orbital data
ok.output.HDF5_creator(\
    mo_list,ok.options.outputname,ok.main.qc.geo_info,ok.main.qc.geo_spec,
    data_id='MO',               # name of data set
    append=None,                # create new file [default]
    data_only=False,            # include grid, structure, and MO data [default]
    is_mo_output=True,
    mo_spec=mo['mo_spec'])

# second run: calculate derivatives
ok.options.drv = ['x', 'y', 'z']  # calculate derivatives along x, y and z
ok.options.no_output = True  # we will create our own output

# run orbkit
Пример #2
0
# Perform a standard orbkit computation
mult.construct_qc() # Construct the qc_info class for every structure
r = 0                    # Index to be calculated
outputname = 'nacl_r%d' % r # Specifies the name of the output file

display('Running orbkit for the structure %d' % r)
import orbkit

# Initialize orbkit with default parameters and options
orbkit.init(reset_display=False)

# Set some options
orbkit.options.adjust_grid= [5, 0.1]                # adjust the grid to the geometry
orbkit.options.outputname = outputname              # output file (base) name
orbkit.options.otype      = 'h5'                    # output file type [default]
orbkit.options.numproc    = 4                       # number of processes

# Run orbkit with qc as input
data = orbkit.run_orbkit(mult.QC[r])

t.append(time())

# Print information about the timing
string = '\n%s\nRequired time:\n\t' % (80*'-')
for i,j in enumerate(run_id):
  if t[i+1]-t[i] > 1e-1:
    string += tForm(j,t[i+1]-t[i],extra='')[1:] + '\t'

display(string)
Пример #3
0
                if pattern in line:
                    num = 1
        f.close()
        filename2 = "RPA_S" + ".molden"
        with open(filename2, "w") as f:
            f.writelines(lines)
        f.close()

        qc = read.main_read(filename2, all_mo=True)
        orbkit.init()
        orbkit.options.quiet = True
        orbkit.options.no_log = True
        orbkit.options.calc_mo = [1]
        orbkit.options.filename = filename2
        orbkit.options.adjust_grid = [5, 0.5]
        data = orbkit.run_orbkit()
        xl = numpy.amin(orbkit.grid.x)
        yl = numpy.amin(orbkit.grid.y)
        zl = numpy.amin(orbkit.grid.z)
        xh = numpy.amax(orbkit.grid.x)
        yh = numpy.amax(orbkit.grid.y)
        zh = numpy.amax(orbkit.grid.z)
        eig = [sub['energy'] for sub in qc.mo_spec]
        fdim = len(qc.mo_spec) / 2
        fdim = int(fdim)
        i = numpy.argsort(eig)
        j = i[::-1]
        orbkit.init()
        orbkit.options.quiet = True
        orbkit.options.no_log = True
        orbkit.grid.is_initialized = True
Пример #4
0
orbkit.grid.sph2cart_vector(r, theta, phi)

# orbkit options
orbkit.options.filename = 'h2o.molden'  # input file name
orbkit.options.itype = 'molden'  # input file type
orbkit.options.numproc = 1  # number of processes for multiprocessing
orbkit.options.slice_length = 4e4  # number of points per process
orbkit.options.calc_mo = 'MO_List.tab'  # list of molecular orbitals to be used

# first run: do not calculate derivatives
orbkit.options.drv = ['None', 'x', 'y', 'z'
                      ]  # calculate mos and their derivatives along x, y and z
orbkit.options.no_output = True  # we will create our own output

# run orbkit
mos = orbkit.run_orbkit()

# Write a npz file with all the ouput
orbkit.output.main_output(mos, outputname='h2o_MO', otype='npz')

# plot derivative
x = orbkit.grid.x
y = orbkit.grid.y
z = orbkit.grid.z

# test if mayavi exists and possibly plot
maya = False
try:
    from enthought.mayavi import mlab
    maya = True
except ImportError:
Пример #5
0
# initialize orbkit with default parameters and options
orbkit.init()

# set some options
orbkit.grid.N_            = [  201,   201,   101]   # grid points (regular grid)
orbkit.grid.max_          = [ 10.0,  10.0,   5.0]   # maximum grid value
orbkit.grid.min_          = [-10.0, -10.0,  -5.0]   # minimum grid value
orbkit.options.filename   = in_fid                  # input file name
orbkit.options.itype      = 'molden'                # input file type [default]
orbkit.options.outputname = out_fid                 # output file (base) name
orbkit.options.otype      = 'h5'                    # output file type [default]
orbkit.options.numproc    = 4                       # number of processes

# run orbkit
rho = orbkit.run_orbkit()

import numpy as np
print('We have %.3f electrons.' % (np.sum(rho)*orbkit.grid.d3r))

#---- Second scenario ----
'''
Calculate the density and its x- and z-derivative using some orbitals
defined in an external file (by symmetry notation), read the grid from a file,
and save the data to cube and hdf5 files.

Note that for the derivatives, there will be one cube file per MO per direction,
while there will only be one hdf5 file containing information of all MOs per 
direction.

Ommit the creation of the *.oklog file
Пример #6
0
    def calculate(self, filein, v, x):
        try:
            printed = [
                "Note: If the mean error of any of the computed integrals is large, consider increasing max. evaluations value\n"
            ]
            printed.append(
                "=============================================================\n"
            )
            printed.append(
                "Filename                      Overlap Integral           Mean Absolute Error \n"
            )
            numproc = 1  #: Specifies number of subprocesses.
            slice_length = 1e4
            infile = filein.split(",")

            filenames_RPA_singlet = sorted(infile)
            for filename in filenames_RPA_singlet:
                fullpath, just_filename = os.path.split(filename)
                orbkit.options.quiet = True
                orbkit.options.no_log = True
                pattern = "[GTO]"
                lines = []
                num = 0
                with open(filename, "r") as f:
                    lines1 = f.readlines()
                    for line in lines1:
                        if num == 0:
                            lines.append(line.lstrip())
                        elif num == 1:
                            lines.append(line)
                        if pattern in line:
                            num = 1
                f.close()
                filename2 = "RPA_S" + ".molden"
                with open(filename2, "w") as f:
                    f.writelines(lines)
                f.close()

                qc = read.main_read(filename2, all_mo=True)
                orbkit.init()
                orbkit.options.quiet = True
                orbkit.options.no_log = True
                orbkit.options.calc_mo = [1]
                orbkit.options.filename = filename2
                orbkit.options.adjust_grid = [5, 0.5]
                data = orbkit.run_orbkit()
                xl = numpy.amin(orbkit.grid.x)
                yl = numpy.amin(orbkit.grid.y)
                zl = numpy.amin(orbkit.grid.z)
                xh = numpy.amax(orbkit.grid.x)
                yh = numpy.amax(orbkit.grid.y)
                zh = numpy.amax(orbkit.grid.z)
                eig = [sub['energy'] for sub in qc.mo_spec]
                fdim = len(qc.mo_spec) / 2
                fdim = int(fdim)
                i = numpy.argsort(eig)
                j = i[::-1]
                orbkit.init()
                orbkit.options.quiet = True
                orbkit.options.no_log = True
                orbkit.grid.is_initialized = True

                def func(x_array, *args):
                    x_array = x_array.reshape((-1, 3))
                    orbkit.grid.x = numpy.array(x_array[:, 0], copy=True)
                    orbkit.grid.y = numpy.array(x_array[:, 1], copy=True)
                    orbkit.grid.z = numpy.array(x_array[:, 2], copy=True)

                    out = orbkit.rho_compute(qc,
                                             calc_mo=True,
                                             slice_length=slice_length,
                                             drv=None,
                                             laplacian=False,
                                             numproc=numproc)
                    out1 = out[i]
                    out2 = out[j]
                    out1 = numpy.abs(out1)
                    out2 = numpy.abs(out2)

                    out = out1[:fdim] * out2[:fdim]
                    return out.transpose()

                ndim = 3
                xmin = numpy.array([xl, yl, zl], dtype=float)
                xmax = numpy.array([xh, yh, zh], dtype=float)
                abserr = 1e-15
                relerr = 1e-5
                integral_mo, error_mo = cubature(func,
                                                 ndim,
                                                 fdim,
                                                 xmin,
                                                 xmax,
                                                 args=[],
                                                 adaptive='h',
                                                 abserr=abserr,
                                                 relerr=relerr,
                                                 norm=0,
                                                 maxEval=v,
                                                 vectorized=True)
                coeff = numpy.sort(eig)[:fdim]
                sum = numpy.sum(numpy.abs(coeff))
                norm_integral_mo = (numpy.abs(coeff) * integral_mo) / sum
                delta = numpy.sum(norm_integral_mo)
                mae = numpy.mean(numpy.abs(error_mo))
                printed.append(
                    str(just_filename) + "                    " +
                    str("%.5f" % delta) + "                           " +
                    str("%.5f" % mae) + "\n")

            printed.append("Job completed! \n")
            printed.append(
                "====================================================================\n"
            )

            print(printed)
            with open(os.path.join(fullpath, 'Overlap.txt'), 'w') as fw:
                fw.writelines(("%s\n" % k for k in printed))
            fw.close()

            return printed

        except:
            printed = ["\n Oops! Something went wrong! \n"]
            printed.append(
                "====================================================================\n"
            )
            return printed
# Perform a standard orbkit computation
QC = mult.construct_qc()  # Construct the qc_info class for every structure
r = 0  # Index to be calculated
out_fid = 'nacl_r%d' % r  # Specifies the name of the output file

display('Running orbkit for the structure %d' % r)
import orbkit as ok

# Initialize orbkit with default parameters and options
ok.init(reset_display=False)

# Set some options
ok.options.adjust_grid = [5, 0.1]  # adjust the grid to the geometry
ok.options.outputname = out_fid  # output file (base) name
ok.options.otype = 'h5'  # output file type [default]
ok.options.numproc = 4  # number of processes

# Run orbkit with qc as input
ok.run_orbkit(QC[r])

t.append(time())

# Print information about the timing
string = '\n%s\nRequired time:\n\t' % (80 * '-')
for i, j in enumerate(run_id):
    if t[i + 1] - t[i] > 1e-1:
        string += tForm(j, t[i + 1] - t[i], extra='')[1:] + '\t'

display(string)
Пример #8
0
# initialize orbkit with default parameters and options
ok.init()

# set some options
ok.grid.N_ = [201, 201, 101]  # grid points (regular grid)
ok.grid.max_ = [10.0, 10.0, 5.0]  # maximum grid value
ok.grid.min_ = [-10.0, -10.0, -5.0]  # minimum grid value
ok.options.filename = in_fid  # input file name
ok.options.itype = 'molden'  # input file type [default]
ok.options.outputname = out_fid  # output file (base) name
ok.options.otype = 'h5'  # output file type [default]
ok.options.numproc = 4  # number of processes

# run orbkit
rho = ok.run_orbkit()

import numpy as np
print('We have %.3f electrons.' % (np.sum(rho) * ok.grid.d3r))

#---- Second scenario ----
'''
Calculate the density and its x- and z-derivative using some orbitals
defined in an external file (by symmetry notation), read the grid from a file,
and save the data to cube and HDF5 files.

Note that for the derivatives, there will be one cube file per MO per direction,
while there will only be one HDF5 file containing information of all MOs per 
direction.

Ommit the creation of the *.oklog file