Exemplo n.º 1
0
 def get_conv_res_test(spec_data, structure):
     """
     return test sets for the tests in test relative to the convergence results
     """
     tests_conv = {}
     tests_prep_conv = {}
     tests_prep = GWscDFTPrepVaspInputSet(structure, spec_data).tests
     tests_prep.update(GWDFTDiagVaspInputSet(structure, spec_data).tests)
     tests = GWG0W0VaspInputSet(structure, spec_data).tests
     conv_res = is_converged(spec_data, structure, return_values=True)
     for test in conv_res.keys():
         if test in tests_prep.keys():
             rel = tests_prep[test]['test_range'][1] - tests_prep[test][
                 'test_range'][0]
             value = conv_res[test]
             tests_prep_conv.update({test: tests_prep[test]})
             tests_prep_conv[test].update(
                 {'test_range': (value, value + rel)})
         elif test in tests.keys():
             rel = tests[test]['test_range'][1] - tests[test]['test_range'][
                 0]
             value = conv_res[test]
             tests_conv.update({test: tests[test]})
             tests_conv[test].update({'test_range': (value, value + rel)})
     return {'tests': tests_conv, 'tests_prep': tests_prep_conv}
Exemplo n.º 2
0
    def execute_flow(self, structure, spec_data):
        """
        execute spec prepare input/jobfiles or submit to fw for a given structure
        for abinit a flow is created using abinitio
        """

        if spec_data['converge'] and is_converged(self.hartree_parameters,
                                                  structure):
            option = is_converged(self.hartree_parameters,
                                  structure,
                                  return_values=True)
        else:
            option = None
        work_flow = SingleAbinitGWWork(structure, spec_data, option)
        flow = work_flow.create()
        print('flow')
        if flow is not None:
            flow.build_and_pickle_dump()
            work_flow.create_job_file()
Exemplo n.º 3
0
    def test_is_converged(self):
        """
        Testing the reading conv_res file for convergence
        """
        # no file case
        self.assertFalse(is_converged(hartree_parameters=True, structure=structure, return_values=False))

        rc = {'control': {u'ecuteps': True, u'ecut': True, u'nbands': True},
              'values': {u'ecuteps': 101.98825069084282, u'ecut': 1306.1464252800001, u'nscf_nbands': 30},
              'derivatives': {u'ecuteps': 0.00023073134391802955, u'ecut': -0.32831958027186586, u'nbands': -0.0013564443499111344}}

        with open('Si_mp-149.conv_res', 'w') as f:
            json.dump(obj=rc, fp=f)

        # file reading
        self.assertEqual(is_converged(hartree_parameters=True, structure=structure, return_values=True),
                         {u'nscf_nbands': 30, u'ecut': 48.0, u'ecuteps': 4.0})

        self.assertEqual(is_converged(hartree_parameters=False, structure=structure, return_values=True),
                         {u'ecut': 1306.1464252800001, u'ecuteps': 101.98825069084282, u'nscf_nbands': 30})
Exemplo n.º 4
0
 def set_status(self, structure):
     self._grid = 0
     self._all_done = False
     self._workdir = None
     self._converged = is_converged(False, structure)
     try:
         self._grid = read_grid_from_file(s_name(structure) +
                                          ".full_res")['grid']
         self._all_done = read_grid_from_file(
             s_name(structure) + ".full_res")['all_done']
         self._workdir = os.path.join(s_name(structure),
                                      'work_' + str(self.grid))
     except (IOError, OSError):
         pass
Exemplo n.º 5
0
    def test_SiC_conv(self):
        """
        Testing a full convergence calculation cycle on SiC using precomupted data.
        """

        # the current version uses refence data from a run using the production version on zenobe
        # once all checks out the run should be done using the input generated using this version to replace the
        # reference

        wdir = tempfile.mkdtemp()
        os.chdir(wdir)

        temp_ABINIT_PS_EXT = os.environ.get('ABINIT_PS_EXT', None)
        temp_ABINIT_PS = os.environ.get('ABINIT_PS', None)

        os.environ['ABINIT_PS_EXT'] = '.psp8'
        os.environ['ABINIT_PS'] = wdir

        reference_dir = os.path.join(__reference_dir__, 'SiC_test_case')
        if not os.path.isdir(reference_dir): raise RuntimeError('py.test needs to be started in the HTGW root, '
                                                                '%s does not exist' % __reference_dir__)

        # copy input
        print(wdir)
        self.assertTrue(os.path.isdir(reference_dir))
        src_files = os.listdir(reference_dir)
        for file_name in src_files:
            full_file_name = os.path.join(reference_dir, file_name)
            if os.path.isfile(full_file_name):
                shutil.copy(full_file_name, wdir)
        self.assertEqual(len(os.listdir(wdir)), 6)

        print(os.listdir(wdir))
        structure = Structure.from_file('SiC.cif')
        structure.item = 'SiC.cif'

        print(' ==== generate flow ===  ')
        gwsetup(update=False)
        self.assertTrue(os.path.isdir(os.path.join(wdir, 'SiC_SiC.cif')))
        print(os.listdir(os.path.join(wdir)))
        print(os.listdir(os.path.join(wdir, 'SiC_SiC.cif')))
        self.assertTrue(os.path.isfile(os.path.join(wdir, 'SiC_SiC.cif', '__AbinitFlow__.pickle')))
        self.assertEqual(len(os.listdir(os.path.join(wdir, 'SiC_SiC.cif', 'w0'))), 48)

        print(' ==== copy reference results from first calculation ===  ')
        shutil.rmtree(os.path.join(wdir, 'SiC_SiC.cif'))
        shutil.copytree(os.path.join(reference_dir, 'ref_res', 'SiC_SiC.cif'), os.path.join(wdir, 'SiC_SiC.cif'))
        self.assertTrue(os.path.isdir(os.path.join(wdir, 'SiC_SiC.cif')))
        self.assertEqual(len(os.listdir(os.path.join(wdir, 'SiC_SiC.cif', 'w0'))), 68)

        print(' ==== process output ===  ')
        gwoutput()
        print(os.listdir('.'))
        self.assertTrue(os.path.isfile('plot-fits'))
        self.assertTrue(os.path.isfile('plots'))
        self.assertEqual(is_converged(hartree_parameters=True, structure=structure, return_values=True),
                         {u'ecut': 44.0, u'ecuteps': 4.0, u'gap': 6.816130591466406, u'nbands': 60})
        self.assertTrue(os.path.isfile('SiC_SiC.cif.full_res'))

        print(' ==== generate next flow ===  ')
        print('      version with bandstructure and dos  ')
        gwsetup(update=False)
        self.assertTrue(os.path.isdir('SiC_SiC.cif.conv'))
        print(os.listdir(os.path.join(wdir, 'SiC_SiC.cif.conv', 'w0')))
        self.assertEqual(len(os.listdir(os.path.join(wdir, 'SiC_SiC.cif.conv', 'w0'))), 15)

        print(' ==== copy reference from second flow ===  ')
        time.sleep(1)  # the .conv directory should be older than the first one
        shutil.rmtree(os.path.join(wdir, 'SiC_SiC.cif.conv'))
        shutil.copytree(os.path.join(reference_dir, 'ref_res', 'SiC_SiC.cif.conv'),
                        os.path.join(wdir, 'SiC_SiC.cif.conv'))
        self.assertTrue(os.path.isdir(os.path.join(wdir, 'SiC_SiC.cif.conv')))
        self.assertEqual(len(os.listdir(os.path.join(wdir, 'SiC_SiC.cif.conv', 'w0'))), 13)

        print(' ==== process output ===  ')
        backup = sys.stdout
        sys.stdout = StringIO()  # capture output
        gwoutput()
        out = sys.stdout.getvalue()  # release output
        sys.stdout.close()  # close the stream
        sys.stdout = backup  # restore original stdout

        print('=== *** ====\n'+out+'=== *** ====\n')
        gap = 0
        for l in out.split('\n'):
            if 'values' in l:
                gap = float(l.split(' ')[6])
        self.assertEqual(gap, 7.114950664158926)

        print(os.listdir('.'))
        print('processed')
        self.assertTrue(os.path.isfile('SiC_SiC.cif.full_res'))
        full_res = read_grid_from_file(s_name(structure)+'.full_res')
        self.assertEqual(full_res, {u'all_done': True, u'grid': 0})
        self.assertTrue(os.path.isdir(os.path.join(wdir, 'SiC_SiC.cif.res')))
        self.assertEqual(len(os.listdir(os.path.join(wdir, 'SiC_SiC.cif.res'))), 5)
        print(os.listdir(os.path.join(wdir, 'SiC_SiC.cif.res')))

        msrf = MySigResFile(os.path.join(wdir, 'SiC_SiC.cif.res', 'out_SIGRES.nc'))
        self.assertEqual(msrf.h**o, 6.6843830378711786)
        self.assertEqual(msrf.lumo, 8.0650328308487982)
        self.assertEqual(msrf.homo_gw, 6.2325949743130034)
        self.assertEqual(msrf.lumo_gw, 8.2504215095164763)
        self.assertEqual(msrf.fundamental_gap('ks'), msrf.lumo - msrf.h**o)
        self.assertEqual(msrf.fundamental_gap('gw'), msrf.lumo_gw - msrf.homo_gw)
        self.assertAlmostEqual(msrf.fundamental_gap('gamma'), gap, places=3)

        # since we now have a mysigresfile object we test the functionality

        msrf.get_scissor()
        # return self.qplist_spin[0].build_scissors(domains=[[-200, mid], [mid, 200]], k=1, plot=False)

        res = msrf.get_scissor_residues()
        self.assertEqual(res, [0.05322754684319431, 0.34320373172956475])
        # return sc.residues

        #msrf.plot_scissor(title='')

        #msrf.plot_qpe(title='')

        # to be continued

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
Exemplo n.º 6
0
    def execute_flow(self, structure, spec_data):
        """
        execute spec prepare input/jobfiles or submit to fw for a given structure
        for vasp the different jobs are created into a flow
        todo this should actually create and execute a VaspGWWorkFlow(GWWorkflow)
        """
        # general part for the base class
        grid = 0
        all_done = False
        converged = is_converged(False, structure)
        try:
            grid = read_grid_from_file(s_name(structure) + ".full_res")['grid']
            all_done = read_grid_from_file(s_name(structure) +
                                           ".full_res")['all_done']
        except (IOError, OSError):
            pass

        if all_done:
            print('| all is done for this material')
            return

        # specific part

        if spec_data['mode'] == 'fw':
            fw_work_flow = VaspGWFWWorkFlow()
        else:
            fw_work_flow = []
        if spec_data['test'] or spec_data['converge']:
            if spec_data['test']:
                tests_prep = GWscDFTPrepVaspInputSet(structure,
                                                     spec_data).tests
                tests_prep.update(
                    GWDFTDiagVaspInputSet(structure, spec_data).tests)
            elif spec_data['converge'] and converged:
                tests_prep = self.get_conv_res_test(spec_data,
                                                    structure)['tests_prep']
            else:
                tests_prep = GWscDFTPrepVaspInputSet(structure,
                                                     spec_data).convs
                tests_prep.update(
                    GWDFTDiagVaspInputSet(structure, spec_data).convs)
                if grid > 0:
                    tests_prep = expand(tests=tests_prep, level=grid)
                print(tests_prep)
            for test_prep in tests_prep:
                print('setting up test for: ' + test_prep)
                for value_prep in tests_prep[test_prep]['test_range']:
                    print("**" + str(value_prep) + "**")
                    option = {'test_prep': test_prep, 'value_prep': value_prep}
                    self.create_job(spec_data, structure, 'prep', fw_work_flow,
                                    converged, option)
                    for job in spec_data['jobs'][1:]:
                        if job == 'G0W0':
                            if spec_data['test']:
                                tests = GWG0W0VaspInputSet(
                                    structure, spec_data).tests
                            elif spec_data['converge'] and converged:
                                tests = self.get_conv_res_test(
                                    spec_data, structure)['tests']
                            else:
                                tests = GWG0W0VaspInputSet(
                                    structure, spec_data).convs
                                if grid > 0:
                                    tests = expand(tests=tests, level=grid)
                                print(tests)
                        if job in ['GW0', 'scGW0']:
                            input_set = GWG0W0VaspInputSet(
                                structure, spec_data)
                            input_set.gw0_on()
                            if spec_data['test']:
                                tests = input_set.tests
                            else:
                                tests = input_set.tests
                        for test in tests:
                            print('    setting up test for: ' + test)
                            for value in tests[test]['test_range']:
                                print("    **" + str(value) + "**")
                                option.update({'test': test, 'value': value})
                                self.create_job(spec_data, structure, job,
                                                fw_work_flow, converged,
                                                option)