Пример #1
0
import cubetools as ct
import sys

samp = ct.read_cube(open(sys.argv[1],'r'))
ct.freq_cutoff(samp,freq_cutoff=0.6)
ct.gaussian_averager(samp,sigma=6,nbr_dist=10,repeat=1)
ct.write_cube(samp,open("smoothed/"+sys.argv[1],"w"))
Пример #2
0
import cubetools
import copy 

s1=cubetools.read_cube("qwalk_000.spin.dens.cube")
s2=cubetools.read_cube("../../../../undoped/PBE0/CHK/plots/qwalk_000.spin.dens.cube")

c1=cubetools.read_cube("qwalk_000.chg.dens.cube")
c2=cubetools.read_cube("../../../../undoped/PBE0/CHK/plots/qwalk_000.chg.dens.cube")

s1['data']-=s2['data'] #make 'up' the spin density
cubetools.write_cube(s1,"qwalk_000.spin_diff.dens.cube")
c1['data']-=c2['data'] #make 'up' the charge density
cubetools.write_cube(c1,"qwalk_000.chg_diff.dens.cube")

Пример #3
0
nup=66
ndown=66
'''
up=cubetools.read_cube("qwalk_000.plot_u.dens.cube")
down=cubetools.read_cube("qwalk_000.plot_d.dens.cube")
up=cubetools.normalize_abs(up)
down=cubetools.normalize_abs(down)
up['data']*=nup
down['data']*=ndown
up['data']-=down['data'] #make 'up' the spin density
cubetools.write_cube(up,"qwalk_000.spin.dens.cube")
up['data']+=2*down['data'] #make 'up' the charge density
cubetools.write_cube(up,"qwalk_000.chg.dens.cube")
'''

up=cubetools.read_cube("qwalk_000.plot_u.dens.cube")
down=cubetools.read_cube("qwalk_000.plot_d.dens.cube")
up_ct=cubetools.read_cube("qwalk_000.plot_u_ct.dens.cube")
down_ct=cubetools.read_cube("qwalk_000.plot_d_ct.dens.cube")
up=cubetools.normalize_abs(up)
down=cubetools.normalize_abs(down)
up_ct=cubetools.normalize_abs(up_ct)
down_ct=cubetools.normalize_abs(down_ct)
up['data']*=nup
down['data']*=ndown
up_ct['data']*=nup
down_ct['data']*=ndown

#Individual CT determinants
c_u_ct=copy.deepcopy(up_ct)
s_u_ct=copy.deepcopy(up_ct)
Пример #4
0
import cubetools
nup = 67
ndown = 66
import copy

#up=cubetools.read_cube("qwalk_000.plot_u.dens.cube")
#down=cubetools.read_cube("qwalk_000.plot_d.dens.cube")
#down=cubetools.read_cube("qwalk_000.plot_d_ex.dens.cube")
up = cubetools.read_cube("qwalk_110.plot_u.dens.cube")
down = cubetools.read_cube("qwalk_110.plot_d.dens.cube")
#down=cubetools.read_cube("qwalk_100.plot_d_ex.dens.cube")
up = cubetools.normalize_abs(up)
down = cubetools.normalize_abs(down)
up['data'] *= nup
down['data'] *= ndown
up['data'] -= down['data']  #make 'up' the spin density
cubetools.write_cube(up, "qwalk_110.spin.dens.cube")
up['data'] += 2 * down['data']  #make 'up' the charge density
cubetools.write_cube(up, "qwalk_110.chg.dens.cube")
Пример #5
0
def read_dir(froot,gosling='./gosling',read_cubes=False):
  """ Reads a CRYSTAL + QWalk directory's data into a dictionary.
  
  Current dictionary keys:
    fmixing, kdens, excited_energy_err, ordering, total_energy_err, 
    excited_energy, ts, tole, total_energy, se_height, tolinteg, 
    supercell, mixing, kpoint, spinlock, dft_energy, a, c, broyden, 
    dft_moments, 1rdm, access_root, average, covariance
  """

  ############################################################################
  # This first section should be edited to reflect naming conventions!
  dftfile   = froot+'.d12'
  dftoutf   = froot+'.d12.out'
  # Start by taking only the real k-points, since I'm sure these are on solid
  # ground, and have enough sample points. TODO generalize
  realk1 = np.array([1,3,8,10,27,29,34,36]) - 1
  realk2 = np.array([1,4,17,20,93,96,109,112]) - 1
  oldrealk = np.array(['k0','k1','k2','k3','k4','k5','k6','k7'])
  ############################################################################

  bres = {} # Data that is common to all k-points.
  ress = {} # Dict of all k-point data in directory.

  bres['access_root'] = os.getcwd() + '/' + froot

  print("Working on",froot+"..." )
  try:
    with open(froot+'_metadata.json','r') as metaf:
      metad = json.load(metaf)
    try:
      if metad['magnetic ordering'] != None:
        bres['ordering'] = metad['magnetic ordering']
    except KeyError: pass
    try:
      if metad['pressure'] != None:
        bres['pressure'] = metad['pressure']
    except KeyError: pass
    try:
      if metad['pressure'] != None:
        bres['pressure'] = metad['pressure']
    except KeyError: pass
  except IOError:
    print("  Didn't find any metadata")
  
  print("  DFT params and results..." )
  try:
    dftdat = cio.read_cryinp(open(dftfile,'r'))
    bres['a'] = dftdat['latparms'][0]
    bres['c'] = dftdat['latparms'][1]
    bres['se_height'] = dftdat['apos'][dftdat['atypes'].index(234)][-1]
    for key in ['mixing','broyden','fmixing','tolinteg',
                'kdens','spinlock','supercell','tole','basis']:
      bres[key] = dftdat[key]
    dftdat = cio.read_cryout(open(dftoutf,'r'))
    bres['dft_energy'] = dftdat['dft_energy']
    bres['dft_moments'] = dftdat['dft_moments']
  except IOError:
    print("There's no dft in this directory!")
    return {}

  # Determine k-point set and naming convention.
  if os.path.isfile(froot+'_'+str(oldrealk[0])+'.sys'):
    realk=oldrealk
    print("Using old-style kpoint notation.")
  elif os.path.isfile(froot+'_'+str(realk2[-1])+'.sys'):
    realk=realk2
    print("Using 6x6x6 kpoint notation.")
  else:
    realk=realk1
    print("Using 4x4x4 kpoint notation.")

  for rk in realk:
    kroot = froot + '_' + str(rk)

    print("  now DMC:",kroot+"..." )
    try:
      sysdat = qio.read_qfile(open(kroot+'.sys','r'))
      dmcinp = qio.read_qfile(open(kroot+'.dmc','r'))
      ress[rk] = bres.copy()
      ress[rk]['kpoint'] = sysdat['system']['kpoint']
      ress[rk]['ts'] = dmcinp['method']['timestep']
    except IOError:
      print("  (cannot find QMC input, skipping)")
      continue
    
    print("  energies..." )
    try:
      inpf = open(kroot+'.dmc.log','r')
      egydat = qio.read_qenergy(inpf,gosling)
      ress[rk]['dmc_energy']     =  egydat['egy']
      ress[rk]['dmc_energy_err'] =  egydat['err']
    except IOError:
      print("  (cannot find ground state energy log file)")

    try:
      inpf = open(kroot+'.ogp.log','r')
      ogpdat = qio.read_qenergy(inpf,gosling)
      ress[rk]['dmc_excited_energy']     =  ogpdat['egy']
      ress[rk]['dmc_excited_energy_err'] =  ogpdat['err']
    except IOError:
      print("  (cannot find excited state energy log file)")

    if read_cubes:
      print("  densities..." )
      try:
        inpf = open(kroot+'.dmc.up.cube','r')
        upcube = ct.read_cube(inpf)
        inpf = open(kroot+'.dmc.dn.cube','r')
        dncube = ct.read_cube(inpf)
        ress[rk]['updens'] = upcube
        ress[rk]['dndens'] = dncube
      except IOError:
        print("  (cannot find electron density)")
      except ValueError:
        print("  (electron density is corrupted)")

    print("  fluctuations..." )
    try:
      inpf = open(kroot+'.ppr.o','r')
      fludat, fluerr = qio.read_number_dens(inpf)
      if fludat is None:
        print("  (Error in number fluctuation output, skipping)")
      else:
        avg, var, cov, avge, vare, cove = qio.moments(fludat,fluerr)
        ress[rk]['average']    = avg
        ress[rk]['covariance'] = cov
    except IOError:
      print("  (cannot find number fluctuation)")

    print("  1-RDM..." )
    try:
      inpf = open(kroot+'.ordm.o')
      odmdat = qio.read_dm(inpf)
      if odmdat is None:
        print("  (Error in 1-RDM output, skipping)")
      else:
        ress[rk]['1rdm'] = odmdat
    except IOError:
      print("  (cannot find 1-RDM)")

    print("  done." )

  if ress == {}:
    ress['dft-only'] = bres
  return ress
Пример #6
0
def reader(fi): return ct.read_cube(open(fi,'r'),qwalk_patch=True)
with mp.Pool(8) as pool:
Пример #7
0
import cubetools

f1 = cubetools.read_cube('test_mom.plot.orb7.cube')
f2 = cubetools.read_cube('test_mom.plot.orb10.cube')
f1 = cubetools.normalize_abs(f1)
f2 = cubetools.normalize_abs(f2)

f1['data'] -= f2['data']
cubetools.write_cube(f1, 'test_mom.plot.orbDiff.cube')

f1['data'] += 2 * f2['data']
cubetools.write_cube(f1, 'test_mom.plot.orbSum.cube')
Пример #8
0
def reader(fi):
    return ct.read_cube(open(fi, 'r'), qwalk_patch=True)
Пример #9
0
import cubetools

nup = 14
ndown = 11
import copy

up = cubetools.read_cube("Cuvtz_r1.963925_c0_s3_B3LYP.plot_u.dens.cube")
down = cubetools.read_cube("Cuvtz_r1.963925_c0_s3_B3LYP.plot_d.dens.cube")
up = cubetools.normalize_abs(up)
down = cubetools.normalize_abs(down)
up['data'] *= nup
down['data'] *= ndown
up['data'] -= down['data']  #make 'up' the spin density
cubetools.write_cube(up, "spin3.dens.cube")
up['data'] += 2 * down['data']  #make 'up' the charge density
cubetools.write_cube(up, "chg3.dens.cube")
Пример #10
0
import cubetools
import copy 

'''
s1=cubetools.read_cube("qwalk_000.spin.dens.cube")
s2=cubetools.read_cube("../../../../undoped/pbe0/col/plots/qwalk_000.spin.dens.cube")

c1=cubetools.read_cube("qwalk_000.chg.dens.cube")
c2=cubetools.read_cube("../../../../undoped/pbe0/col/plots/qwalk_000.chg.dens.cube")

s1['data']-=s2['data'] #make 'up' the spin density
cubetools.write_cube(s1,"qwalk_000.spin_diff.dens.cube")
c1['data']-=c2['data'] #make 'up' the charge density
cubetools.write_cube(c1,"qwalk_000.chg_diff.dens.cube")
'''
s1=cubetools.read_cube("qwalk_000.spin.dens.cube")
s2=cubetools.read_cube("../../CHK_ns/plots/qwalk_000.spin.dens.cube")

c1=cubetools.read_cube("qwalk_000.chg.dens.cube")
c2=cubetools.read_cube("../../CHK_ns/plots/qwalk_000.chg.dens.cube")

s1['data']-=s2['data'] #make 'up' the spin density
cubetools.write_cube(s1,"qwalk_000.spin_diff2.dens.cube")
c1['data']-=c2['data'] #make 'up' the charge density
cubetools.write_cube(c1,"qwalk_000.chg_diff2.dens.cube")
Пример #11
0
def read_dir(froot,gosling='./gosling',read_cubes=False):
  """ Reads a CRYSTAL + QWalk directory's data into a dictionary.
  
  Current dictionary keys:
    fmixing, kdens, excited_energy_err, ordering, total_energy_err, 
    excited_energy, ts, tole, total_energy, se_height, tolinteg, 
    supercell, mixing, kpoint, spinlock, dft_energy, a, c, broyden, 
    dft_moments, 1rdm, access_root, average, covariance
  """

  ############################################################################
  # This first section should be edited to reflect naming conventions!
  dftfile   = froot+'.d12'
  dftoutf   = froot+'.d12.out'
  # Start by taking only the real k-points, since I'm sure these are on solid
  # ground, and have enough sample points. TODO generalize
  realk1 = np.array([1,3,8,10,27,29,34,36]) - 1
  realk2 = np.array([1,4,17,20,93,96,109,112]) - 1
  oldrealk = np.array(['k0','k1','k2','k3','k4','k5','k6','k7'])
  ############################################################################

  bres = {} # Data that is common to all k-points.
  ress = {} # Dict of all k-point data in directory.

  bres['access_root'] = os.getcwd() + '/' + froot

  print("Working on",froot+"..." )
  try:
    with open(froot+'_metadata.json','r') as metaf:
      metad = json.load(metaf)
    try:
      if metad['magnetic ordering'] != None:
        bres['ordering'] = metad['magnetic ordering']
    except KeyError: pass
    try:
      if metad['pressure'] != None:
        bres['pressure'] = metad['pressure']
    except KeyError: pass
    try:
      if metad['pressure'] != None:
        bres['pressure'] = metad['pressure']
    except KeyError: pass
  except IOError:
    print("  Didn't find any metadata")
  
  print("  DFT params and results..." )
  try:
    dftdat = cio.read_cryinp(open(dftfile,'r'))
    bres['a'] = dftdat['latparms'][0]
    bres['c'] = dftdat['latparms'][1]
    bres['se_height'] = dftdat['apos'][dftdat['atypes'].index(234)][-1]
    for key in ['mixing','broyden','fmixing','tolinteg',
                'kdens','spinlock','supercell','tole','basis']:
      bres[key] = dftdat[key]
    dftdat = cio.read_cryout(open(dftoutf,'r'))
    bres['dft_energy'] = dftdat['dft_energy']
    bres['dft_moments'] = dftdat['dft_moments']
  except IOError:
    print("There's no dft in this directory!")
    return {}

  # Determine k-point set and naming convention.
  if os.path.isfile(froot+'_'+str(oldrealk[0])+'.sys'):
    realk=oldrealk
    print("Using old-style kpoint notation.")
  elif os.path.isfile(froot+'_'+str(realk2[-1])+'.sys'):
    realk=realk2
    print("Using 6x6x6 kpoint notation.")
  else:
    realk=realk1
    print("Using 4x4x4 kpoint notation.")

  for rk in realk:
    kroot = froot + '_' + str(rk)

    print("  now DMC:",kroot+"..." )
    try:
      sysdat = qio.read_qfile(open(kroot+'.sys','r'))
      dmcinp = qio.read_qfile(open(kroot+'.dmc','r'))
      ress[rk] = bres.copy()
      ress[rk]['kpoint'] = sysdat['system']['kpoint']
      ress[rk]['ts'] = dmcinp['method']['timestep']
    except IOError:
      print("  (cannot find QMC input, skipping)")
      continue
    
    print("  energies..." )
    try:
      inpf = open(kroot+'.dmc.log','r')
      egydat = qio.read_qenergy(inpf,gosling)
      ress[rk]['dmc_energy']     =  egydat['egy']
      ress[rk]['dmc_energy_err'] =  egydat['err']
    except IOError:
      print("  (cannot find ground state energy log file)")

    try:
      inpf = open(kroot+'.ogp.log','r')
      ogpdat = qio.read_qenergy(inpf,gosling)
      ress[rk]['dmc_excited_energy']     =  ogpdat['egy']
      ress[rk]['dmc_excited_energy_err'] =  ogpdat['err']
    except IOError:
      print("  (cannot find excited state energy log file)")

    if read_cubes:
      print("  densities..." )
      try:
        inpf = open(kroot+'.dmc.up.cube','r')
        upcube = ct.read_cube(inpf)
        inpf = open(kroot+'.dmc.dn.cube','r')
        dncube = ct.read_cube(inpf)
        ress[rk]['updens'] = upcube
        ress[rk]['dndens'] = dncube
      except IOError:
        print("  (cannot find electron density)")
      except ValueError:
        print("  (electron density is corrupted)")

    print("  fluctuations..." )
    try:
      inpf = open(kroot+'.ppr.o','r')
      fludat, fluerr = qio.read_number_dens(inpf)
      if fludat is None:
        print("  (Error in number fluctuation output, skipping)")
      else:
        avg, var, cov, avge, vare, cove = qio.moments(fludat,fluerr)
        ress[rk]['average']    = avg
        ress[rk]['covariance'] = cov
    except IOError:
      print("  (cannot find number fluctuation)")

    print("  1-RDM..." )
    try:
      inpf = open(kroot+'.ordm.o')
      odmdat = qio.read_dm(inpf)
      if odmdat is None:
        print("  (Error in 1-RDM output, skipping)")
      else:
        ress[rk]['1rdm'] = odmdat
    except IOError:
      print("  (cannot find 1-RDM)")

    print("  done." )

  if ress == {}:
    ress['dft-only'] = bres
  return ress