Exemplo n.º 1
0
def MO(mol,
       C,
       orbital,
       outfile='orbital',
       nx=80,
       ny=80,
       nz=80,
       resolution=None,
       save=True):
    """Calculates electron density and write out in cube format.

    Args:
        mol : Mole
            Molecule to calculate the electron density for.
        outfile : str
            Name of Cube file to be written.
        dm : ndarray
            Density matrix of molecule.

    Kwargs:
        nx : int
            Number of grid point divisions in x direction.
            Note this is function of the molecule's size; a larger molecule
            will have a coarser representation than a smaller one for the
            same value. Conflicts to keyword resolution.
        ny : int
            Number of grid point divisions in y direction.
        nz : int
            Number of grid point divisions in z direction.
        resolution: float
            Resolution of the mesh grid in the cube box. If resolution is
            given in the input, the input nx/ny/nz have no effects.  The value
            of nx/ny/nz will be determined by the resolution and the cube box
            size.
    """

    cc = Cube(mol, nx, ny, nz, resolution)

    # Compute density on the .cube grid
    coords = cc.get_coords()
    ngrids = cc.get_ngrids()
    #blksize = min(8000, ngrids)
    blksize = ngrids
    rho = np.empty(ngrids)
    for ip0, ip1 in lib.prange(0, ngrids, blksize):
        ao = numint.eval_ao(mol, coords[ip0:ip1])
    MO = np.array([i @ C[:, orbital] for i in ao])
    MO = MO.reshape((nx, ny, nz))
    if save:
        cc.write(MO,
                 outfile,
                 comment='Orbital ' + str(orbital) +
                 ' in real space (e/Bohr^3)')
    x = (coords[:, 0].min(), coords[:, 0].max(), nx)
    y = (coords[:, 1].min(), coords[:, 1].max(), ny)
    z = (coords[:, 2].min(), coords[:, 2].max(), nz)
    return MO, np.array([y, x, z])
Exemplo n.º 2
0
def AO(mol,
       C,
       outfile='AO_dir/AOs',
       nx=80,
       ny=80,
       nz=80,
       resolution=None,
       save=True):
    counter = 1
    if not os.path.exists(outfile):
        os.makedirs(outfile)
    else:
        exists = True
        while exists:
            cache = outfile + '_' + str(counter)
            exists = os.path.exists(cache)
            counter += 1
        outfile = cache
        os.makedirs(cache)
    cc = Cube(mol, nx, ny, nz, resolution)
    # Compute density on the .cube grid
    coords = cc.get_coords()
    ngrids = cc.get_ngrids()
    #blksize = min(8000, ngrids)
    blksize = ngrids
    rho = np.empty(ngrids)
    for ip0, ip1 in lib.prange(0, ngrids, blksize):
        ao = numint.eval_ao(mol, coords[ip0:ip1])
    x = (coords[:, 0].min(), coords[:, 0].max(), nx)
    y = (coords[:, 1].min(), coords[:, 1].max(), ny)
    z = (coords[:, 2].min(), coords[:, 2].max(), nz)
    if save:
        np.savetxt(outfile + '/AOs', ao)
        np.savetxt(outfile + '/C', C)

        np.savetxt(outfile + '/coords', np.array([y, x, z]))
        f = open(outfile + '/geom_basis', 'w')
        f.write(str(mol.atom) + '_')
        f.write(str(mol.basis))
        f.close()
        #cc.write(np.array([]),outfile + '_geom',comment = 'Geometry')
    return ao, np.array([y, x, z])
Exemplo n.º 3
0
  def test_cube_c(self):
    """ Compute the density and store into a cube file  """

    # Initialize the class cube_c
    cc = Cube(mol, nx=20, ny=20, nz=20)
    
    # Compute density on the .cube grid
    coords = cc.get_coords()
    ngrids = cc.get_ngrids()
    blksize = min(8000, ngrids)
    rho = np.empty(ngrids)
    ao = None
    dm = mf.make_rdm1()
    for ip0, ip1 in gen_grid.prange(0, ngrids, blksize):
        ao = numint.eval_ao(mol, coords[ip0:ip1], out=ao)
        rho[ip0:ip1] = numint.eval_rho(mol, ao, dm)
    rho = rho.reshape(cc.nx,cc.ny,cc.nz)
    
    # Write out density to the .cube file
    cc.write(rho, "h2o_den_cube_c.cube", comment='Electron density in real space (e/Bohr^3)')