Example #1
0
    def writeInp(name=None, **setting):

      inp, molecule = \
        PlanewaveInput.write(self, name, **setting)

      molecule.sort()

      type_index = molecule.index
      type_list = molecule.type_list
      pp_files = []

      self.content['system']['nat'] = molecule.N
      self.content['system']['ntyp'] = len(type_index) - 1
      if setting['full_kmesh']:
        self.content['system']['nosym'] = True
        self.content['system']['noinv'] = True
  
      if 'restart' in setting and setting['restart']:
        self.content['control']['restart_mode'] = 'restart'

      if 'save_density' in setting and setting['save_density']:
        self.content['control']['wf_collect'] = True

      if 'save_wf' in setting and setting['save_wf']:
        self.content['control']['wf_collect'] = True
      if 'print_force' not in setting or not setting['print_force']:
        self.content['control']['tprnfor'] = True
   

      if not setting['periodic']:
        self.content['system']['assume_isolated'] = 'mt'

      if 'exx' in setting and setting['exx'] == 'anisotropic':
        self.content['system']['exxdiv_treatment'] = 'vcut_ws'
        self.content['system']['ecutvcut'] = 0.7
        self.content['system']['x_gamma_extrapolation'] = False

      if molecule.charge != 0:
        self.content['system']['tot_charge'] = molecule.charge
      if molecule.multiplicity != 1:
        self.content['system']['nspin'] = 2
        diff = molecule.multiplicity - 1
        self.content['system']['tot_magnetization'] = diff

      if 'theory' in setting:
        if self.setting['theory'] in dft_dict:
          self.content['system']['input_dft'] = \
            dft_dict[self.setting['theory']]
        else:
          self.content['system']['input_dft'] = self.setting['theory']

      if 'scf_step' in setting:
        self.content['electrons']['electron_maxstep'] =\
          setting['scf_step']

      if 'ks_states' in setting and setting['ks_states']:
        vs = int(round(self.molecule.getValenceElectrons() / 2.0))
        self.content['system']['nbnd'] = setting['ks_states'] + vs
        if 'd_shell' in setting:
          for a in molecule.type_list:
            if a in setting['d_shell'] and qtk.n2ve(a) < 10:
              self.content['system']['nbnd'] += 5

      if 'symmetry' in setting:
        if setting['symmetry'] == 'fcc':
          self.content['system']['ibrav'] = 2
          setting['fractional_coordinate'] = True
          dm = ['A', 'B', 'C', 'cosBC', 'cosAC', 'cosAB']
          for i in range(6):
            self.content['system'][dm[i]] = float(self
              .molecule.celldm[i])

      for section_key in self.content.iterkeys():
        section = '&' + section_key + '\n'
        inp.write(section)
        for key, value in self.content[section_key].iteritems():
          if type(value) is str:
            entry = " %s = '%s',\n" % (key, value)
          elif type(value) is int:
            entry = ' %s = %d,\n' % (key, value)
          elif type(value) is float:
            entry = ' %s = %14.8E,\n' % (key, value)
          elif type(value) is bool:
            if value:
              entry = ' %s = .true.,\n' % key
            else:
              entry = ' %s = .false.,\n' % key
          inp.write(entry)
        inp.write('/\n')

      inp.write("ATOMIC_SPECIES\n")
      for a in range(len(type_index)-1):
        type_n = type_index[a+1] - type_index[a]
        PPStr = PPString(self, molecule, 
          type_index[a], type_n, inp)
        stem, ext = os.path.splitext(PPStr)
        if ext != '.UPF':
          PPStr = PPStr + '.UPF'
        mass = qtk.n2m(type_list[type_index[a]])
        inp.write(' %-3s % 6.3f %s\n' % \
          (type_list[type_index[a]], mass, PPStr))
        pp_files.append(PPStr)
      inp.write("\n")

      inp.write("ATOMIC_POSITIONS ")
      if self.content['system']['ibrav'] == 0:
        if not setting['fractional_coordinate']:
          inp.write("angstrom\n")
          R = molecule.R
        else:
          inp.write("crystal\n")
          R = molecule.R_scale
      else:
        inp.write("\n")
        R = molecule.R_scale
      for a in range(len(type_list)):
        inp.write(' %-3s' % type_list[a])
        for i in range(3):
          inp.write(' % 12.8f' % R[a, i])
        inp.write("\n")
      inp.write("\n")

      if 'kmesh' in setting and setting['kmesh']:
        inp.write("K_POINTS automatic\n")
        for k in setting['kmesh']:
          inp.write(" %d" % k)
        for s in range(3):
          inp.write(" 0")
        inp.write('\n\n')

      if 'save_restart' in setting and setting['save_restart']:
        inp.write("ALCHEMY reference\n\n")

      if 'restart' in setting and setting['restart']:
        if 'scf_step' in setting and setting['scf_step'] == 1:
          inp.write("ALCHEMY prediction\n\n")

      if self.content['system']['ibrav'] == 0:
        inp.write("CELL_PARAMETERS angstrom\n")
        if 'lattice' not in self.setting:
          self.celldm2lattice()
        lattice_vec = self.setting['lattice']
        for vec in lattice_vec:
          for component in vec:
            inp.write(' % 11.6f' % component)
          inp.write('\n')
  
      for pp in pp_files:
        pp_file = os.path.join(qtk.setting.espresso_pp, pp)
        if pp not in inp.dependent_files:
          inp.dependent_files.append(pp_file)

      if 'no_cleanup' in setting and setting['no_cleanup']:
        inp.close(no_cleanup=True)
      else:
        inp.close()

      return inp
Example #2
0
    def writeInp(name=None, **setting):
      setting['no_update'] = True
      inp, molecule = PlanewaveInput.write(self, name, **setting)

      if 'ks_states' in setting and 'ks_states':
        setting['mode'] = 'ks_states'

      if 'big_memory' not in setting:
        if qtk.setting.memory > 16:
          setting['big_memory'] = True

#      if molecule.scale:
#        molecule.R = molecule.R_scale
#        setting['scale'] = molecule.scale
  
      inp.write('&INFO\n')
      inp.write(' ' + setting['info'] + '\n')
      inp.write('&END\n\n')
  
      inp.write('&CPMD\n MIRROR\n')
      if 'save_restart' not in setting\
      or not setting['save_restart']:
        inp.write(' BENCHMARK\n')
        inp.write('  1 0 0 0 0 0 0 0 0 0\n')
      if 'init_random' in setting\
      and setting['init_random']:
        inp.write(' INITIALIZE WAVEFUNCTION RANDOM\n')
      if setting['mode'].lower() == 'single_point':
        inp.write(' OPTIMIZE WAVEFUNCTION\n')
      elif setting['mode'].lower() == 'geopt':
        inp.write(' OPTIMIZE GEOMETRY\n')
      elif setting['mode'].lower() == 'ks_states':
        if not setting['restart']:
          setting['restart'] = True
        inp.write(' KOHN-SHAM ENERGIES\n  %d\n'\
          % setting['ks_states'])
        #inp.write(' LANCZOS PARAMETER N=5\n')
        #inp.write('  1000  16  20  1.D-9\n')
        #inp.write('  0.05          1.D-11\n')
        #inp.write('  0.01          1.D-13\n')
        #inp.write('  0.0025        1.D-16\n')
        #inp.write('  0.001         1.D-18\n')
      elif setting['mode'].lower() == 'md':
        inp.write(' MOLECULAR DYNAMICS BO\n')
      if re.match(setting['mode'], 'md'):
        inp.write(' TRAJECTORY SAMPLE XYZ\n  %d\n'\
          % setting['sample_period'])
        inp.write(' TEMPERATURE\n')
        inp.write('  %.1f\n' % setting['T'])
        if setting['thermostat'].lower() == 'nose-hoover':
          inp.write(' NOSE IONS\n  %.1f %.1f\n' % \
            (setting['T'], setting['T_tolerance']))
      if 'geometry_convergence' in setting:
        inp.write(' CONVERGENCE GEOMETRY\n  %.2E\n' %\
          setting['geometry_convergence'])
      if 'md_step' in setting:
        inp.write(' MAXSTEP\n  %d\n' % setting['md_step'])
      if 'wf_convergence' in setting:
        inp.write(' CONVERGENCE ORBITAL\n  %.2E\n' %\
          setting['wf_convergence'])
      if 'scf_step' in setting:
        inp.write(' MAXITER\n  %d\n' % setting['scf_step'])
      if 'restart' in setting and setting['restart']:
        inp.write(' RESTART WAVEFUNCTION\n')
      if 'fix_molecule' in setting\
       and setting['fix_molecule']:
        inp.write(' CENTER MOLECULE OFF\n')
      if ('save_density' in setting and setting['save_density'])\
      or ('save_wf' in setting and setting['save_wf']):
        inp.write(' RHOOUT')
        if setting['save_wf']:
          inp.write(' BANDS\n  %d\n ' % len(setting['save_wf']))
          for i in setting['save_wf']:
            inp.write(' %d' % i)
        inp.write('\n')

      if molecule.multiplicity != 1:
        inp.write(' LOCAL SPIN DENSITY\n') 
      if 'big_memory' in setting and setting['big_memory']:
        inp.write(' MEMORY BIG\n')
      inp.write('&END\n\n')
  
      inp.write('&DFT\n FUNCTIONAL %s\n&END\n\n' % \
        setting['theory'].upper())
  
      inp.write('&SYSTEM\n')
      if setting['periodic']:
        inp.write(' CELL VECTORS\n')
        lattice_vec = self.setting['lattice']
        for vec in lattice_vec:
          inp.write(' ')
          for component in vec:
            inp.write(' % 11.6f' % component)
          inp.write('\n')
      else:
        inp.write(' SYMMETRY\n')
        inp.write('  ISOLATED\n')
        if setting['isolation'] == 'mt':
          inp.write(' POISSON SOLVER TUCKERMAN\n')
        inp.write(' CELL ABSOLUTE\n ')
        for d in setting['celldm']:
          inp.write(' %6.3f'% float(d))
        inp.write('\n')
      if setting['unit'].lower() == 'angstrom':
        inp.write(' ANGSTROM\n')
      inp.write(' CUTOFF\n  %.1f\n' % setting['cutoff'])
      if 'kmesh' in setting and setting['kmesh']:
        inp.write(' KPOINTS MONKHORST-PACK\n  %d %d %d\n' %\
          (setting['kmesh'][0],
           setting['kmesh'][1],
           setting['kmesh'][2]))
      if 'mesh' in setting:
        inp.write(' MESH\n  %d %d %d\n' %\
          (setting['mesh'][0],
           setting['mesh'][1],
           setting['mesh'][2]))
      if molecule.charge != 0:
        inp.write(' CHARGE\n  %d\n' % molecule.charge)
      if molecule.multiplicity != 1:
        inp.write(' MULTIPLICITY\n  %d\n' % molecule.multiplicity)
      inp.write('&END\n\n')
  
      inp.write('&ATOMS\n')
      molecule.sort()
      type_index = molecule.index
      type_list = molecule.type_list
      # loop through sorted atom type indices
      for atom_type in xrange(0,len(type_index)-1):
        # number of each atom type
        type_n = type_index[atom_type+1] - type_index[atom_type]
        PPString(self, molecule, type_index[atom_type], type_n, inp)
        for I in\
        xrange(type_index[atom_type],type_index[atom_type+1]):
          inp.write('  ')
          for i in range(3):
            inp.write(' % 8.4f' % molecule.R[I,i])
          inp.write('\n')
      inp.write('&END\n')

      for pp in self.pp_files:
        pp_file = os.path.join(qtk.setting.cpmd_pp, pp)
        inp.dependent_files.append(pp_file)
  
      if 'no_cleanup' in setting and setting['no_cleanup']:
        inp.close(no_cleanup=True)
      else:
        inp.close()

      return inp
Example #3
0
        def writeInp(name=None, **setting):

            inp, molecule = \
              PlanewaveInput.write(self, name, **setting)

            molecule.sort()

            type_index = molecule.index
            type_list = molecule.type_list
            pp_files = []

            self.content['system']['nat'] = molecule.N
            self.content['system']['ntyp'] = len(type_index) - 1
            if setting['full_kmesh']:
                self.content['system']['nosym'] = True
                self.content['system']['noinv'] = True

            if 'restart' in setting and setting['restart']:
                self.content['control']['restart_mode'] = 'restart'

            if 'save_density' in setting and setting['save_density']:
                self.content['control']['wf_collect'] = True

            if 'save_wf' in setting and setting['save_wf']:
                self.content['control']['wf_collect'] = True
            if 'print_force' not in setting or not setting['print_force']:
                self.content['control']['tprnfor'] = True

            if not setting['periodic']:
                self.content['system']['assume_isolated'] = 'mt'

            if 'exx' in setting and setting['exx'] == 'anisotropic':
                self.content['system']['exxdiv_treatment'] = 'vcut_ws'
                self.content['system']['ecutvcut'] = 0.7
                self.content['system']['x_gamma_extrapolation'] = False

            if molecule.charge != 0:
                self.content['system']['tot_charge'] = molecule.charge
            if molecule.multiplicity != 1:
                self.content['system']['nspin'] = 2
                diff = molecule.multiplicity - 1
                self.content['system']['tot_magnetization'] = diff

            if 'theory' in setting:
                if self.setting['theory'] in dft_dict:
                    self.content['system']['input_dft'] = \
                      dft_dict[self.setting['theory']]
                else:
                    self.content['system']['input_dft'] = self.setting[
                        'theory']

            if 'scf_step' in setting:
                self.content['electrons']['electron_maxstep'] =\
                  setting['scf_step']

            if 'ks_states' in setting and setting['ks_states']:
                vs = int(round(self.molecule.getValenceElectrons() / 2.0))
                self.content['system']['nbnd'] = setting['ks_states'] + vs
                if 'd_shell' in setting:
                    for a in molecule.type_list:
                        if a in setting['d_shell'] and qtk.n2ve(a) < 10:
                            self.content['system']['nbnd'] += 5

            if 'symmetry' in setting:
                if setting['symmetry'] == 'fcc':
                    self.content['system']['ibrav'] = 2
                    setting['fractional_coordinate'] = True
                    dm = ['A', 'B', 'C', 'cosBC', 'cosAC', 'cosAB']
                    for i in range(6):
                        self.content['system'][dm[i]] = float(
                            self.molecule.celldm[i])

            for section_key in self.content.iterkeys():
                section = '&' + section_key + '\n'
                inp.write(section)
                for key, value in self.content[section_key].iteritems():
                    if type(value) is str:
                        entry = " %s = '%s',\n" % (key, value)
                    elif type(value) is int:
                        entry = ' %s = %d,\n' % (key, value)
                    elif type(value) is float:
                        entry = ' %s = %14.8E,\n' % (key, value)
                    elif type(value) is bool:
                        if value:
                            entry = ' %s = .true.,\n' % key
                        else:
                            entry = ' %s = .false.,\n' % key
                    inp.write(entry)
                inp.write('/\n')

            inp.write("ATOMIC_SPECIES\n")
            for a in range(len(type_index) - 1):
                type_n = type_index[a + 1] - type_index[a]
                PPStr = PPString(self, molecule, type_index[a], type_n, inp)
                stem, ext = os.path.splitext(PPStr)
                if ext != '.UPF':
                    PPStr = PPStr + '.UPF'
                mass = qtk.n2m(type_list[type_index[a]])
                inp.write(' %-3s % 6.3f %s\n' % \
                  (type_list[type_index[a]], mass, PPStr))
                pp_files.append(PPStr)
            inp.write("\n")

            inp.write("ATOMIC_POSITIONS ")
            if self.content['system']['ibrav'] == 0:
                if not setting['fractional_coordinate']:
                    inp.write("angstrom\n")
                    R = molecule.R
                else:
                    inp.write("crystal\n")
                    R = molecule.R_scale
            else:
                inp.write("\n")
                R = molecule.R_scale
            for a in range(len(type_list)):
                inp.write(' %-3s' % type_list[a])
                for i in range(3):
                    inp.write(' % 12.8f' % R[a, i])
                inp.write("\n")
            inp.write("\n")

            if 'kmesh' in setting and setting['kmesh']:
                inp.write("K_POINTS automatic\n")
                for k in setting['kmesh']:
                    inp.write(" %d" % k)
                for s in range(3):
                    inp.write(" 0")
                inp.write('\n\n')

            if 'save_restart' in setting and setting['save_restart']:
                inp.write("ALCHEMY reference\n\n")

            if 'restart' in setting and setting['restart']:
                if 'scf_step' in setting:
                    if setting['scf_step'] != 1:
                        qtk.warning('alchemy with optimization...')
                    inp.write("ALCHEMY prediction\n\n")

            if self.content['system']['ibrav'] == 0:
                inp.write("CELL_PARAMETERS angstrom\n")
                if 'lattice' not in self.setting:
                    self.celldm2lattice()
                lattice_vec = self.setting['lattice']
                for vec in lattice_vec:
                    for component in vec:
                        inp.write(' % 11.6f' % component)
                    inp.write('\n')

            for pp in pp_files:
                pp_file = os.path.join(qtk.setting.espresso_pp, pp)
                if pp not in inp.dependent_files:
                    inp.dependent_files.append(pp_file)

            if 'no_cleanup' in setting and setting['no_cleanup']:
                inp.close(no_cleanup=True)
            else:
                inp.close()

            return inp
Example #4
0
    def writeInp(name=None, **setting):
      setting['no_update'] = True
      inp, molecule = PlanewaveInput.write(self, name, **setting)

      if 'ks_states' in setting and 'ks_states':
        setting['mode'] = 'ks_states'

      if 'big_memory' not in setting:
        if qtk.setting.memory > 16:
          setting['big_memory'] = True

#      if molecule.scale:
#        molecule.R = molecule.R_scale
#        setting['scale'] = molecule.scale
  
      inp.write('&INFO\n')
      inp.write(' ' + setting['info'] + '\n')
      inp.write('&END\n\n')
  
      inp.write('&CPMD\n MIRROR\n')
      if 'save_restart' not in setting\
      or not setting['save_restart']:
        inp.write(' BENCHMARK\n')
        inp.write('  1 0 0 0 0 0 0 0 0 0\n')
      if 'init_random' in setting\
      and setting['init_random']:
        inp.write(' INITIALIZE WAVEFUNCTION RANDOM\n')
      if setting['mode'].lower() == 'single_point':
        inp.write(' OPTIMIZE WAVEFUNCTION\n')
      elif setting['mode'].lower() == 'geopt':
        inp.write(' OPTIMIZE GEOMETRY\n')
      elif setting['mode'].lower() == 'ks_states':
        if not setting['restart']:
          setting['restart'] = True
        inp.write(' KOHN-SHAM ENERGIES\n  %d\n'\
          % setting['ks_states'])
        #inp.write(' LANCZOS PARAMETER N=5\n')
        #inp.write('  1000  16  20  1.D-9\n')
        #inp.write('  0.05          1.D-11\n')
        #inp.write('  0.01          1.D-13\n')
        #inp.write('  0.0025        1.D-16\n')
        #inp.write('  0.001         1.D-18\n')
      elif setting['mode'].lower() == 'md':
        inp.write(' MOLECULAR DYNAMICS BO\n')
      if re.match(setting['mode'], 'md'):
        inp.write(' TRAJECTORY SAMPLE XYZ\n  %d\n'\
          % setting['sample_period'])
        inp.write(' TEMPERATURE\n')
        inp.write('  %.1f\n' % setting['T'])
        if setting['thermostat'].lower() == 'nose-hoover':
          inp.write(' NOSE IONS\n  %.1f %.1f\n' % \
            (setting['T'], setting['T_tolerance']))
      if 'geometry_convergence' in setting:
        inp.write(' CONVERGENCE GEOMETRY\n  %.2E\n' %\
          setting['geometry_convergence'])
      if 'md_step' in setting:
        inp.write(' MAXSTEP\n  %d\n' % setting['md_step'])
      if 'wf_convergence' in setting:
        inp.write(' CONVERGENCE ORBITAL\n  %.2E\n' %\
          setting['wf_convergence'])
      if 'scf_step' in setting:
        inp.write(' MAXITER\n  %d\n' % setting['scf_step'])
      if 'restart' in setting and setting['restart']:
        inp.write(' RESTART WAVEFUNCTION\n')
      if 'restart_wavefunction_file' in setting:
        if os.path.exists(setting['restart_wavefunction_file']):
          inp.dependent_files.append(
            [setting['restart_wavefunction_file'], 'RESTART']
          )
        else:
          qtk.warning('%s not found' % setting['restart_wavefunction_file'])
      if 'fix_molecule' in setting\
       and setting['fix_molecule']:
        inp.write(' CENTER MOLECULE OFF\n')
      if ('save_density' in setting and setting['save_density'])\
      or ('save_wf' in setting and setting['save_wf']):
        inp.write(' RHOOUT')
        if setting['save_wf']:
          inp.write(' BANDS\n  %d\n ' % len(setting['save_wf']))
          for i in setting['save_wf']:
            inp.write(' %d' % i)
        inp.write('\n')

      if molecule.multiplicity != 1:
        inp.write(' LOCAL SPIN DENSITY\n') 
      if 'big_memory' in setting and setting['big_memory']:
        inp.write(' MEMORY BIG\n')
      inp.write('&END\n\n')
  
      inp.write('&DFT\n FUNCTIONAL %s\n&END\n\n' % \
        setting['theory'].upper())
  
      inp.write('&SYSTEM\n')
      if setting['periodic']:
        inp.write(' CELL VECTORS\n')
        lattice_vec = self.setting['lattice']
        for vec in lattice_vec:
          inp.write(' ')
          for component in vec:
            inp.write(' % 11.6f' % component)
          inp.write('\n')
      else:
        inp.write(' SYMMETRY\n')
        inp.write('  ISOLATED\n')
        if setting['isolation'] == 'mt':
          inp.write(' POISSON SOLVER TUCKERMAN\n')
        inp.write(' CELL ABSOLUTE\n ')
        for d in setting['celldm']:
          inp.write(' %6.3f'% float(d))
        inp.write('\n')
      if setting['unit'].lower() == 'angstrom':
        inp.write(' ANGSTROM\n')
      inp.write(' CUTOFF\n  %.1f\n' % setting['cutoff'])
      if 'kmesh' in setting and setting['kmesh']:
        inp.write(' KPOINTS MONKHORST-PACK\n  %d %d %d\n' %\
          (setting['kmesh'][0],
           setting['kmesh'][1],
           setting['kmesh'][2]))
      if 'mesh' in setting:
        inp.write(' MESH\n  %d %d %d\n' %\
          (setting['mesh'][0],
           setting['mesh'][1],
           setting['mesh'][2]))
      if molecule.charge != 0:
        inp.write(' CHARGE\n  %d\n' % molecule.charge)
      if molecule.multiplicity != 1:
        inp.write(' MULTIPLICITY\n  %d\n' % molecule.multiplicity)
      inp.write('&END\n\n')
  
      inp.write('&ATOMS\n')
      molecule.sort()
      type_index = molecule.index
      type_list = molecule.type_list
      # loop through sorted atom type indices
      for atom_type in xrange(0,len(type_index)-1):
        # number of each atom type
        type_n = type_index[atom_type+1] - type_index[atom_type]
        PPString(self, molecule, type_index[atom_type], type_n, inp)
        for I in\
        xrange(type_index[atom_type],type_index[atom_type+1]):
          inp.write('  ')
          for i in range(3):
            inp.write(' % 8.4f' % molecule.R[I,i])
          inp.write('\n')
      inp.write('&END\n')

      for pp in self.pp_files:
        pp_file = os.path.join(qtk.setting.cpmd_pp, pp)
        inp.dependent_files.append(pp_file)
  
      if 'no_cleanup' in setting and setting['no_cleanup']:
        inp.close(no_cleanup=True)
      else:
        inp.close()

      return inp