Beispiel #1
0
    def pre_run(files_in, set_dirs):
        # Create run list
        run_list = []

        # Get environment settings
        s = pwscf_settings.load()
        cache = None
        if ('pwscf_cache' in s):
            cache = s['pwscf_cache']
        pwscf_scratch = None
        if ('pwscf_scratch' in s):
            pwscf_scratch = s['pwscf_scratch']
        pwscf_pp = None
        if ('pwscf_cache' in s):
            pwscf_pp = s['pwscf_pp']

        for file_path in files_in:
            file_name = pwscf_exec.file_name_only(file_path)
            path = pwscf_exec.file_path_only(file_path)

            pw_in = pwscf_input()
            pw_in.load(file_path)
            pw_in.set_dirs(pwscf_scratch, pwscf_pp)
            pw_in.save()

            sig = pw_in.signature()
            cache_file = None

            use_cache = False
            if (cache is not None):
                cache_file_in = cache + "/" + sig + ".in"
                cache_file_out = cache + "/" + sig + ".out"

                use_cache = True
                if (not os.path.exists(cache_file_in)):
                    use_cache = False
                if (not os.path.exists(cache_file_out)):
                    use_cache = False

            cmd = 'mpirun -n ' + s['proc_count'] + ' ' + s[
                'pwscf_bin'] + ' -i ' + file_path + ' > ' + path + '/' + file_name + '.out'

            run_list.append({
                'file_name': file_name,
                'path': path,
                'file_path_in': file_path,
                'file_path_out': path + '/' + file_name + '.out',
                'hash': sig,
                'use_cache': use_cache,
                'cache_in': cache_file_in,
                'cache_out': cache_file_out,
                'cmd': cmd,
                'cache_used': False,
            })

        # return
        return run_list
Beispiel #2
0
  def run_pwscf_list(run_list, log, allow_cache, run=True):
    # Get environment settings
    s = pwscf_settings.load()    
    cache = None
    if('pwscf_cache' in s):
      cache = s['pwscf_cache']
      
    list_out = []
    for i in range(len(run_list)):
      run_file = run_list[i]
    
      # Use cache?
      use_cache = run_file['use_cache']
    
      # Recheck for cache      
      if(cache is not None):
        if(os.path.exists(run_file['cache_in']) and os.path.exists(run_file['cache_out'])):
          use_cache = True        
      
      if(use_cache and allow_cache):
        run_list[i]['cache_used'] = True
        copyfile(run_file['cache_out'], run_file['file_path_out'])
        list_out.append({"file": run_file['file_path_out'], "status": "complete",})
        if(log is not None):
          log.add("##START PWSCF##")
          log.add("PWscf Run")
          log.add(run_file['cmd'])
          log.add("Cache used")
          log.add("##END PWSCF##")
          log.add("")
      else:  
      
        # Run
        if(run):
          os.system(run_file['cmd'])
          pwo = pwscf_output(run_file['file_path_out'])
          if(pwo.get_job_done()):
            copyfile(run_file['file_path_in'], run_file['cache_in'])
            copyfile(run_file['file_path_out'], run_file['cache_out'])
            list_out.append({"file": run_file['file_path_out'], "status": "complete",})
          else:
            list_out.append({"file": run_file['file_path_out'], "status": "failed",})          
        
          if(log is not None):
            log.add("##START PWSCF##")
            log.add("PWscf Run")
            log.add(run_file['cmd'])
            if(pwo.get_job_done()):
              log.add("Run successful")
            log.add("##END PWSCF##")
            log.add("")

    return log, list_out, run_list
Beispiel #3
0
    def pre_run(files_in, set_dirs):
        # Create run list
        run_list = []

        # Get environment settings
        s = pwscf_settings.load()
        cache = None
        if ('pwscf_cache' in s):
            cache = s['pwscf_cache']
        pwscf_scratch = None
        if ('pwscf_scratch' in s):
            pwscf_scratch = s['pwscf_scratch']
        pwscf_pp = None
        if ('pwscf_cache' in s):
            pwscf_pp = s['pwscf_pp']

        for file_path in files_in:
            file_name = pwscf_exec.file_name_only(file_path)
            path = pwscf_exec.file_path_only(file_path)

            pw_in = pwscf_input()
            pw_in.load(file_path)
            pw_in.set_dirs(pwscf_scratch, pwscf_pp)
            pw_in.save()

            sig = pw_in.signature()
            cache_file = None

            use_cache = False
            if (cache is not None):
                cache_file_in = cache + "/" + sig + ".in"
                cache_file_out = cache + "/" + sig + ".out"

                use_cache = True
                if (not os.path.exists(cache_file_in)):
                    use_cache = False
                if (not os.path.exists(cache_file_out)):
                    use_cache = False

            script = False
            bin = False
            if (s['pwscf_script'] != '' and os.path.isfile(s['pwscf_script'])):
                script = True
            if (s['pwscf_bin'] != '' and os.path.isfile(s['pwscf_bin'])):
                bin = True

            if (script):
                print("Using PW Script")
                print(s['pwscf_script'])
                cmd = s['pwscf_script'] + ' ' + str(
                    s['proc_count']
                ) + ' ' + file_path + ' ' + path + '/' + file_name + '.out'
            elif (bin):
                print("Using PW Bin")
                print(s['pwscf_bin'])
                cmd = 'mpirun -n ' + s['proc_count'] + ' ' + s[
                    'pwscf_bin'] + ' -i ' + file_path + ' > ' + path + '/' + file_name + '.out'
            else:
                print(
                    "================================================================="
                )
                print("Error: exiting")
                print("Please specify either:")
                print(
                    "PWSCF_SCRIPT      e.g. export PWSCF_SCRIPT=/opt/qe/bin/pw.sh"
                )
                print(
                    "PWSCF_BIN         e.g. export PWSCF_SCRIPT=/opt/qe/bin/pw.x"
                )
                print(
                    "================================================================="
                )
                exit()
            #  cmd = 'mpirun -n ' + s['proc_count'] + ' ' + s['pwscf_bin'] + ' -i ' + file_path + ' > ' + path + '/' + file_name + '.out'
            #else:
            #  cmd = s['pwscf_script'] + ' ' + s['proc_count'] + ' ' + file_path + ' ' + path + '/' + file_name + '.out'

            run_list.append({
                'file_name': file_name,
                'path': path,
                'file_path_in': file_path,
                'file_path_out': path + '/' + file_name + '.out',
                'hash': sig,
                'use_cache': use_cache,
                'cache_in': cache_file_in,
                'cache_out': cache_file_out,
                'cmd': cmd,
                'cache_used': False,
            })

        # return
        return run_list