Example #1
0
  def write(self, name=None, **kwargs):
    self.setting.update(kwargs)
    univ.cornerCube(self)
    inp, molecule = \
      super(GaussianBasisInput, self).write(name, **self.setting)

    # mode setup
    if self.setting['mode'] == 'single_point':
      operation = 'energy'
    elif self.setting['mode'] == 'geopt':
      operation = 'optimize'

    # Theory setupt
    dft = {
      'pbe': 'xpbe96 cpbe96',
      'pbe0': 'pbe0',
      'blyp': 'becke88 lyp',
      'b3lyp': 'b3lyp',
      'bp91': 'becke88 perdew91',
      'bp86': 'becke88 perdew86',
      'pw91': 'xperdew91 perdew91',
    }
    scf = {
      'rhf', 'rohf', 'uhf',
    }
    tce = {
      'mp2', 'mp3', 'mp4', 
      'ccsd', 'ccsdt', 'lccsd',
      'cisd', 'cisdt',
    }
    if self.setting['theory'] in dft:
      module = 'dft'
      xc = dft[self.setting['theory']]
    elif self.setting['theory'] in scf:
      module = 'scf'
    elif self.setting['theory'] in tce:
      module = 'tce'
    else:
      qtk.exit("theory %s is not implemented" % self.setting['theory'])

    mul_dict = {1: 'singlet', 2: 'doublet', 3: 'triplet'}

    # print file
    inp.write('title %s\n' % name)
    inp.write('start %s\n' % name)
    inp.write('echo\n')
    if self.setting['fix_molecule']\
    and self.setting['fix_molecule']:
      fix_mol = 'nocenter'
    else:
      fix_mol = ''
    inp.write('\ngeometry units angstrom %s\n' % fix_mol)
    if fix_mol:
      inp.write('symmetry group c1\n')
    if 'nuclear_charges' in self.setting:
      new_Z = self.setting['nuclear_charges']
    else:
      new_Z = []
    z_itr = 0
    for i in range(molecule.N):
      n_charge = ''
      e_str = molecule.type_list[i]
      if new_Z and z_itr < len(new_Z):
        if new_Z[z_itr][0] == i:
          Zn = molecule.Z[i]
          n_charge = 'charge %.3f' % float(new_Z[z_itr][1] + Zn)
          e_str = molecule.type_list[i] + '.' + new_Z[z_itr][2]
          molecule.string[i] = e_str
          z_itr = z_itr + 1
      inp.write(' %-8s % 8.4f % 8.4f % 8.4f %s\n' % \
                (e_str,
                 molecule.R[i, 0],
                 molecule.R[i, 1],
                 molecule.R[i, 2],
                 n_charge
               ))
    inp.write('end\n\n')
    inp.write('basis cartesian\n')
    if self.setting['basis_set'] != 'gen':
      eStr = []
      for e in range(len(molecule.Z)):
        if molecule.string[e]:
          eString = molecule.string[e]
        else:
          eString = molecule.type_list[e]
        if eString not in set(eStr):
          eStr.append(eString)
          inp.write(' %-8s library %2s %s\n' % (\
            eString,
            molecule.type_list[e],
            self.setting['basis_set'].upper()),
          )
    inp.write('end\n\n')

    if module == 'dft':
      inp.write('dft\n')
      inp.write(' xc %s\n' % xc)
      if molecule.multiplicity > 1:
        inp.write(' odft\n')
        inp.write(' mult %d\n' % molecule.multiplicity)
      if self.setting['wf_convergence'] != 1e-06:
        inp.write(' convergence energy %e\n' % \
                  self.setting['wf_convergence'])
      if 'scf_step' in self.setting:
        inp.write(' maxiter %d\n' % self.setting['scf_step'])
      if 'vdw' in self.setting:
        if self.setting['vdw'] == 'd3':
          inp.write(' disp vdw 3\n')
        elif self.setting['vdw'] == 'd2':
          inp.write(' disp vdw 2\n')
      inp.write('end\n\n')

    elif module == 'scf':
      inp.write('scf\n')
      if molecule.multiplicity <= 3:
        inp.write(' %s\n' % mul_dict[molecule.multiplicity])
        inp.write(' %s\n' % self.setting['theory'])
      else:
        qtk.exit('multiplicity > 3 is not yet implemented')
      inp.write('end\n\n')

    if module == 'tce':
      _mult = False
      if molecule.multiplicity > 1:
        _mult = True
        inp.write('scf\n')
        inp.write(' %s\n' % mul_dict[molecule.multiplicity])
        inp.write(' rohf\n')
        inp.write('end\n\n')
      inp.write('tce\n')
      if _mult: inp.write(' scf\n')
      inp.write(' %s\n' % self.setting['theory'])
      inp.write('end\n\n')

    if molecule.charge != 0:
      inp.write('charge % 5.2f\n' % molecule.charge)

    inp.write('\ntask %s %s\n' % (module, operation))

    if self.setting['save_density']:
      total_wf = int(sum(self.molecule.Z) / 2)
      valence_wf = self.molecule.getValenceElectrons() / 2 
      wf_list = reversed([total_wf - i for i in range(valence_wf)])
      cubeout = 'qmout'
      if name: cubeout = name
      inp.write('\ndplot\n')
      inp.write(' output %s_density.cube\n' % cubeout)
      inp.write(' vectors %s.movecs\n' % name)
      inp.write(' LimitXYZ\n')
      for i in range(3):
        for j in range(2):
          inp.write(' % 8.4f' % self.molecule.grid[i][j])
        inp.write('  %d\n' % self.molecule.grid[i][2])
      inp.write(' gaussian\n')
      inp.write(' spin total\n')
      inp.write(' orbitals; %d\n' % valence_wf)
      for i in wf_list:
        inp.write(' %d' % i)
      inp.write('\nend\n')
      inp.write('task dplot\n\n')

    if self.setting['save_wf']:
      for occ in self.setting['save_wf']:
        if not self.molecule.grid:
          self.setGrid()
        cubeout = 'qmout'
        if name: cubeout = name
        inp.write('\ndplot\n')
        inp.write(' output %s_wf%02d.cube\n' % (cubeout, occ))
        inp.write(' vectors %s.movecs\n' % cubeout)
        inp.write(' LimitXYZ\n')
        for i in range(3):
          for j in range(2):
            inp.write(' % 8.4f' % self.molecule.grid[i][j])
          inp.write('  %d\n' % self.molecule.grid[i][2])
        inp.write(' gaussian\n')
        inp.write(' spin total\n')
        inp.write(' orbitals view\n')
        inp.write('  1; %d\n' % occ)
        inp.write('end\n')
        inp.write('task dplot\n\n')

    inp.close()
    return inp
Example #2
0
    def write(self, name=None, **kwargs):
        self.setting.update(kwargs)
        if 'geopt' in self.setting and self.setting['geopt']:
            self.setting['mode'] = 'geopt'
        univ.cornerCube(self)
        inp, molecule = \
          super(GaussianBasisInput, self).write(name, **self.setting)

        # mode setup
        if self.setting['mode'] == 'single_point':
            operation = 'energy'
        elif self.setting['mode'] == 'geopt':
            operation = 'optimize'

        # Theory setupt
        dft = {
            'pbe': 'xpbe96 cpbe96',
            'pbe0': 'pbe0',
            'blyp': 'becke88 lyp',
            'b3lyp': 'b3lyp',
            'bp91': 'becke88 perdew91',
            'bp86': 'becke88 perdew86',
            'pw91': 'xperdew91 perdew91',
        }
        scf = {
            'rhf',
            'rohf',
            'uhf',
        }
        tce = {
            'mp2',
            'mp3',
            'mp4',
            'ccsd',
            'ccsdt',
            'lccsd',
            'cisd',
            'cisdt',
        }
        if self.setting['theory'] in dft:
            module = 'dft'
            xc = dft[self.setting['theory']]
        elif self.setting['theory'] in scf:
            module = 'scf'
        elif self.setting['theory'] in tce:
            module = 'tce'
        else:
            qtk.exit("theory %s is not implemented" % self.setting['theory'])

        mul_dict = {1: 'singlet', 2: 'doublet', 3: 'triplet'}

        # print file
        inp.write('title %s\n' % name)
        inp.write('start %s\n' % name)
        inp.write('echo\n')
        if self.setting['fix_molecule']\
        and self.setting['fix_molecule']:
            fix_mol = 'nocenter'
        else:
            fix_mol = ''
        inp.write('\ngeometry units angstrom %s\n' % fix_mol)
        if fix_mol:
            inp.write('symmetry group c1\n')
        if 'nuclear_charges' in self.setting:
            new_Z = self.setting['nuclear_charges']
        else:
            new_Z = []
        z_itr = 0
        for i in range(molecule.N):
            n_charge = ''
            e_str = molecule.type_list[i]
            if new_Z and z_itr < len(new_Z):
                if new_Z[z_itr][0] == i:
                    Zn = molecule.Z[i]
                    n_charge = 'charge %.3f' % float(new_Z[z_itr][1] + Zn)
                    e_str = molecule.type_list[i] + '.' + new_Z[z_itr][2]
                    molecule.string[i] = e_str
                    z_itr = z_itr + 1
            inp.write(' %-8s % 8.4f % 8.4f % 8.4f %s\n' % \
                      (e_str,
                       molecule.R[i, 0],
                       molecule.R[i, 1],
                       molecule.R[i, 2],
                       n_charge
                     ))
        inp.write('end\n\n')
        inp.write('basis cartesian\n')
        if self.setting['basis_set'] != 'gen':
            eStr = []
            for e in range(len(molecule.Z)):
                if molecule.string[e]:
                    eString = molecule.string[e]
                else:
                    eString = molecule.type_list[e]
                if eString not in set(eStr):
                    eStr.append(eString)
                    inp.write(' %-8s library %2s %s\n' % (\
                      eString,
                      molecule.type_list[e],
                      self.setting['basis_set'].upper()),
                    )
        inp.write('end\n\n')

        if module == 'dft':
            inp.write('dft\n')
            inp.write(' xc %s\n' % xc)
            if molecule.multiplicity > 1:
                inp.write(' odft\n')
                inp.write(' mult %d\n' % molecule.multiplicity)
            if self.setting['wf_convergence'] != 1e-06:
                inp.write(' convergence energy %e\n' % \
                          self.setting['wf_convergence'])
            if 'scf_step' in self.setting:
                inp.write(' maxiter %d\n' % self.setting['scf_step'])
            if 'vdw' in self.setting:
                if self.setting['vdw'] == 'd3':
                    inp.write(' disp vdw 3\n')
                elif self.setting['vdw'] == 'd2':
                    inp.write(' disp vdw 2\n')
            inp.write('end\n\n')

        elif module == 'scf':
            inp.write('scf\n')
            if molecule.multiplicity <= 3:
                inp.write(' %s\n' % mul_dict[molecule.multiplicity])
                inp.write(' %s\n' % self.setting['theory'])
            else:
                qtk.exit('multiplicity > 3 is not yet implemented')
            inp.write('end\n\n')

        if module == 'tce':
            _mult = False
            if molecule.multiplicity > 1:
                _mult = True
                inp.write('scf\n')
                inp.write(' %s\n' % mul_dict[molecule.multiplicity])
                inp.write(' rohf\n')
                inp.write('end\n\n')
            inp.write('tce\n')
            if _mult: inp.write(' scf\n')
            inp.write(' %s\n' % self.setting['theory'])
            inp.write('end\n\n')

        if molecule.charge != 0:
            inp.write('charge % 5.2f\n' % molecule.charge)

        inp.write('\ntask %s %s\n' % (module, operation))

        if self.setting['save_density']:
            total_wf = int(sum(self.molecule.Z) / 2)
            valence_wf = self.molecule.getValenceElectrons() / 2
            wf_list = reversed([total_wf - i for i in range(valence_wf)])
            cubeout = 'qmout'
            if name: cubeout = name
            inp.write('\ndplot\n')
            inp.write(' output %s_density.cube\n' % cubeout)
            inp.write(' vectors %s.movecs\n' % name)
            inp.write(' LimitXYZ\n')
            for i in range(3):
                for j in range(2):
                    inp.write(' % 8.4f' % self.molecule.grid[i][j])
                inp.write('  %d\n' % self.molecule.grid[i][2])
            inp.write(' gaussian\n')
            inp.write(' spin total\n')
            inp.write(' orbitals; %d\n' % valence_wf)
            for i in wf_list:
                inp.write(' %d' % i)
            inp.write('\nend\n')
            inp.write('task dplot\n\n')

        if self.setting['save_wf']:
            for occ in self.setting['save_wf']:
                if not self.molecule.grid:
                    self.setGrid()
                cubeout = 'qmout'
                if name: cubeout = name
                inp.write('\ndplot\n')
                inp.write(' output %s_wf%02d.cube\n' % (cubeout, occ))
                inp.write(' vectors %s.movecs\n' % cubeout)
                inp.write(' LimitXYZ\n')
                for i in range(3):
                    for j in range(2):
                        inp.write(' % 8.4f' % self.molecule.grid[i][j])
                    inp.write('  %d\n' % self.molecule.grid[i][2])
                inp.write(' gaussian\n')
                inp.write(' spin total\n')
                inp.write(' orbitals view\n')
                inp.write('  1; %d\n' % occ)
                inp.write('end\n')
                inp.write('task dplot\n\n')

        inp.close()
        return inp
Example #3
0
    def write(self, name=None, **kwargs):
        self.setting.update(kwargs)
        univ.cornerCube(self)
        inp, molecule = \
          super(GaussianBasisInput, self).write(name, **self.setting)

        theory_dict = {
            'pbe': 'pbepbe',
            'pbe0': 'pbe1pbe',
        }

        if self.setting['theory'] in theory_dict:
            theory = theory_dict[self.setting['theory']]
        else:
            theory = self.setting['theory']
        if 'cc' in theory:
            try:
                ind = self.setting['gaussian_setting'].index('force')
                del self.setting['gaussian_setting'][ind]
            except:
                pass

        if 'openshell' in self.setting:
            if self.setting['openshell'] == 'restricted':
                theory = 'ro' + theory
            elif self.setting['openshell'] == 'unrestricted':
                theory = 'u' + theory
        if 'geopt' in self.setting and self.setting['geopt']:
            self.setting['gaussian_setting'].append('opt')
            if 'force' in self.setting['gaussian_setting']:
                ind = self.setting['gaussian_setting'].index('force')
                del self.setting['gaussian_setting'][ind]
        if 'print_polarizability' in self.setting\
        and self.setting['print_polarizability']:
            self.setting['gaussian_setting'].append('polar')
            if 'force' in self.setting['gaussian_setting']:
                ind = self.setting['gaussian_setting'].index('force')
                del self.setting['gaussian_setting'][ind]
        basis = self.setting['basis_set']
        if type(basis) is str:
            if 'def2' in basis.lower():
                basis = basis.replace('-', '')
        if 'charge_multiplicity' not in self.setting:
            charge, multiplicity = \
              self.molecule.charge, self.molecule.multiplicity
        else:
            charge, multiplicity = \
              self.setting['charge_multiplicity']
            if (charge + sum(self.molecule.Z) + 1) % 2 != multiplicity % 2:
                qtk.exit("charge: %3.1f and multiplicity %d is " \
                         % (float(charge), multiplicity) +
                         "not competible with number of electron %d\n"
                         % sum(self.molecule.Z))

        gaussian_setting = self.setting['gaussian_setting']

        chk_flag = False
        save_list = [
            'save_density',
            'ks_states',
            'save_wf',
            'save_restart',
        ]
        for s in save_list:
            if s in self.setting and self.setting[s]:
                chk_flag = True

        if 'threads' in self.setting:
            inp.write('%%nproc=%d\n' % self.setting['threads'])
        else:
            inp.write('%nproc=\n')
        if chk_flag:
            if name:
                inp.write('%%chk=%s.chk\n' % name)
            else:
                inp.write('%chk=tmp.chk\n')

            density_dict = {'ccsd', 'mp2', 'mp3', 'ccd', 'cid', 'cisd'}

            if 'save_density' in self.setting\
            and self.setting['save_density']:
                if theory.lower() in density_dict\
                and 'Density=Current' not in self.setting['gaussian_setting']:
                    self.setting['gaussian_setting'].append('Density=Current')

        if 'nuclear_charges' in self.setting:
            gaussian_setting.append('Charge')
        if 'vdw' in self.setting:
            if self.setting['vdw'] == 'd3':
                gaussian_setting.append('EmpiricalDispersion=GD3')
            elif self.setting['vdw'] == 'd2':
                gaussian_setting.append('EmpiricalDispersion=GD2')
        if 'print_energy' in self.setting and self.setting['print_energy']:
            gaussian_setting.append('ExtraLinks=L608')
        if 'mode' in self.setting and self.setting['mode'] == 'geopt':
            gaussian_setting.append('Opt')
        if type(basis) is str:
            inp.write("# %s/%s" % (theory, basis))
        else:
            inp.write("# %s/gen" % theory)
        for s in list(set(gaussian_setting)):
            inp.write(" %s" % s)
        inp.write("\n\n%s\n\n" % self.molecule.name)
        inp.write("%d   %d\n" % (charge, multiplicity))

        for i in range(molecule.N):
            inp.write('%-2s % 8.4f % 8.4f % 8.4f\n' % \
                      (molecule.type_list[i],
                       molecule.R[i, 0],
                       molecule.R[i, 1],
                       molecule.R[i, 2]))

        if 'nuclear_charges' in self.setting:
            new_Z = self.setting['nuclear_charges']
        else:
            new_Z = []
        if new_Z:
            inp.write('\n')
            for chg_list in new_Z:
                for i in range(molecule.N):
                    if chg_list[0] == i:
                        Ri = molecule.R[i]
                        charge = chg_list[1]
                        inp.write('% 8.4f % 8.4f % 8.4f  % .3f\n' %\
                                  (Ri[0], Ri[1], Ri[2], charge))

        if type(basis) is dict:
            inp.write('\n')
            l_dict = {0: 'S', 1: 'P', 2: 'D', 3: 'F', 4: 'G'}
            for atom in set(molecule.type_list):
                if atom not in basis:
                    qtk.exit("basis function for atom %s is missing" % atom)
                inp.write("%-2s   0\n" % atom)
                for b in basis[atom]:
                    inp.write("%s  %2d   1.00\n" % (l_dict[b[0]], len(b) - 1))
                    for ec in b[1:]:
                        inp.write("  %16.8f  %16.8f\n" % (ec[0], ec[1]))
                inp.write('****\n')
        inp.write('\n\n')
        inp.close()

        return inp
Example #4
0
  def write(self, name=None, **kwargs):
    self.setting.update(kwargs)
    univ.cornerCube(self)
    inp, molecule = \
      super(GaussianBasisInput, self).write(name, **self.setting)

    theory_dict = {
      'pbe': 'pbepbe',
      'pbe0': 'pbe1pbe',
    }

    if self.setting['theory'] in theory_dict:
      theory = theory_dict[self.setting['theory']]
    else:
      theory = self.setting['theory']
    if 'cc' in theory:
      try:
        ind = self.setting['gaussian_setting'].index('force')
        del self.setting['gaussian_setting'][ind]
      except:
        pass
      
    if 'openshell' in self.setting :
      if self.setting['openshell'] == 'restricted':
        theory = 'ro' + theory
      elif self.setting['openshell'] == 'unrestricted':
        theory = 'u' + theory
    if 'geopt' in self.setting and self.setting['geopt']:
      self.setting['gaussian_setting'].append('opt')
      if 'force' in self.setting['gaussian_setting']:
        ind = self.setting['gaussian_setting'].index('force')
        del self.setting['gaussian_setting'][ind]
    if 'print_polarizability' in self.setting\
    and self.setting['print_polarizability']:
      self.setting['gaussian_setting'].append('polar')
      if 'force' in self.setting['gaussian_setting']:
        ind = self.setting['gaussian_setting'].index('force')
        del self.setting['gaussian_setting'][ind]
    basis = self.setting['basis_set']
    if 'def2' in basis.lower():
      basis = basis.replace('-', '')
    if 'charge_multiplicity' not in self.setting:
      charge, multiplicity = \
        self.molecule.charge, self.molecule.multiplicity
    else:
      charge, multiplicity = \
        self.setting['charge_multiplicity']
      if (charge + sum(self.molecule.Z) + 1) % 2 != multiplicity % 2:
        qtk.exit("charge: %3.1f and multiplicity %d is " \
                 % (float(charge), multiplicity) + 
                 "not competible with number of electron %d\n"
                 % sum(self.molecule.Z))

    gaussian_setting = self.setting['gaussian_setting']

    chk_flag = False
    save_list = [
      'save_density',
      'ks_states',
      'save_wf',
      'save_restart',
    ]
    for s in save_list:
      if s in self.setting and self.setting[s]:
        chk_flag = True

    if 'threads' in self.setting:
      inp.write('%%nproc=%d\n' % self.setting['threads'])
    else:
      inp.write('%nproc=\n')
    if chk_flag:
      if name:
        inp.write('%%chk=%s.chk\n' % name)
      else:
        inp.write('%chk=tmp.chk\n')

      density_dict = {'ccsd', 'mp2', 'mp3', 'ccd', 'cid', 'cisd'}

      if 'save_density' in self.setting\
      and self.setting['save_density']:
        if theory.lower() in density_dict\
        and 'Density=Current' not in self.setting['gaussian_setting']:
          self.setting['gaussian_setting'].append('Density=Current')
       
    if 'nuclear_charges' in self.setting:
      gaussian_setting.append('Charge')
    if 'vdw' in self.setting:
      if self.setting['vdw'] == 'd3':
        gaussian_setting.append('EmpiricalDispersion=GD3')
      elif self.setting['vdw'] == 'd2':
        gaussian_setting.append('EmpiricalDispersion=GD2')
    if 'print_energy' in self.setting and self.setting['print_energy']:
      gaussian_setting.append('ExtraLinks=L608')
    if 'mode' in self.setting and self.setting['mode'] == 'geopt':
      gaussian_setting.append('Opt')
    inp.write("# %s/%s" % (theory, basis))
    for s in list(set(gaussian_setting)):
      inp.write(" %s" % s)
    inp.write("\n\n%s\n\n" % self.molecule.name)
    inp.write("%d   %d\n" % (charge, multiplicity))

    for i in range(molecule.N):
      inp.write('%-2s % 8.4f % 8.4f % 8.4f\n' % \
                (molecule.type_list[i],
                 molecule.R[i, 0],
                 molecule.R[i, 1],
                 molecule.R[i, 2]))

    if 'nuclear_charges' in self.setting:
      new_Z = self.setting['nuclear_charges']
    else:
      new_Z = []
    if new_Z:
      inp.write('\n')
      for chg_list in new_Z:
        for i in range(molecule.N):
          if chg_list[0] == i:
            Ri = molecule.R[i]
            charge = chg_list[1]
            inp.write('% 8.4f % 8.4f % 8.4f  % .3f\n' %\
                      (Ri[0], Ri[1], Ri[2], charge))
    inp.write('\n\n')
    inp.close()

    return inp