Пример #1
0
def main():
    """
    main gw output processing
    """
    if os.path.isfile('plots'):
        os.remove('plots')
    if os.path.isfile('plot-fits'):
        os.remove('plot-fits')
    spec = get_spec('GW')
    spec.read_from_file('spec.in')
    print('Found setup for ', spec.get_code())
    counters = spec.loop_structures('o')
    return counters
Пример #2
0
 def test_store_empty(self):
     """
     Testing loop_structures store mode s empty case
     """
     wdir = tempfile.mkdtemp()
     print('wdir', wdir)
     os.chdir(wdir)
     shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
     spec_in = get_spec('GW')
     self.assertIsInstance(spec_in, GWSpecs)
     spec_in.data['source'] = 'cif'
     return_value = spec_in.loop_structures('s')
     self.assertEqual(return_value[0], 0)
     self.assertEqual(return_value[1], 1)
     self.assertEqual(return_value[2], {u'Si_si.cif': 'no data found to insert in db'})
Пример #3
0
 def test_output_empty(self):
     """
     Testing loop_structures output parsing mode o empty case
     """
     wdir = tempfile.mkdtemp()
     print('wdir', wdir)
     os.chdir(wdir)
     shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
     spec_in = get_spec('GW')
     self.assertIsInstance(spec_in, GWSpecs)
     spec_in.data['source'] = 'cif'
     spec_in.data['converge'] = True
     return_value = spec_in.loop_structures('o')
     self.assertEqual(return_value[0], 0)
     self.assertEqual(return_value[1], 1)
     self.assertEqual(return_value[2], {u'Si_si.cif': u'calculation stage could not be determined for convergence calculation'})
Пример #4
0
    def test_expand(self):
        """
        Testing helper function to extend the convergence grid
        """
        self.maxDiff = None
        spec = get_spec('GW')
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        print('wdir', wdir)

        os.chdir(wdir)
        shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
        shutil.copyfile(abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'shell_manager.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'simple_scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        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'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir

        tests = SingleAbinitGWWork(struc, spec).convs
        tests_out = {'nscf_nbands': {'test_range': (25,),
                                     'control': 'gap', 'method': 'set_bands', 'level': 'nscf'},
                     'ecut': {'test_range': (50, 48, 46, 44),
                              'control': 'e_ks_max', 'method': 'direct', 'level': 'scf'},
                     'ecuteps': {'test_range': (4, 6, 8, 10, 12),
                                 'control': 'gap', 'method': 'direct', 'level': 'sigma'}}
        self.assertEqual(expand(tests, 1), tests_out)
        spec.data['code'] = 'VASP'

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
Пример #5
0
def main(update=True):
    """
    main gw setup
    """
    spec_in = get_spec('GW')

    try:
        spec_in.read_from_file('spec.in')
    except (IOError, OSError):
        try:
            spec_in.read_from_file('$HOME/.abinit/abipy/spec.in')
        except (IOError, OSError):
            pass
        pass

    if update:
        # in testing mode there should not be interactive updating
        spec_in.update_interactive()

    spec_in.test()
    spec_in.write_to_file('spec.in')
    counters = spec_in.loop_structures('i')
    return counters
Пример #6
0
    def test_setup_single(self):
        """
        Testing the main functions called in the abiGWsetup script for a single shot calculation
        """

        spec_in = get_spec('GW')
        self.assertIsInstance(spec_in, GWSpecs)

        self.assert_equal(spec_in.test(), 0)
        self.assert_equal(len(spec_in.to_dict()), 10)
        self.assert_equal(spec_in.get_code(), 'ABINIT')

        spec_in.data['source'] = 'cif'

        self.assert_equal(spec_in.hash_str(), "code:ABINIT;source:cifjobs:['prep', 'G0W0'];mode:ceci;functional:PBE;kp_grid_dens:500prec:m;tol:0.0001;test:False;converge:False")

        wdir = tempfile.mkdtemp()
        print('wdir', wdir)

        os.chdir(wdir)

        shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
        shutil.copyfile(abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'shell_manager.yml'), os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'simple_scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        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'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir

        spec_in.data['source'] = 'cif'
        print('dirpath', abidata.dirpath)

        spec_in.write_to_file('spec.in')
        self.assertTrue(os.path.isfile(os.path.join(wdir, 'spec.in')))

        spec_in.loop_structures('i')

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS

        ls = os.listdir('.')
        print(ls)
        self.assertEqual(ls, [u'job_collection', u'manager.yml', u'scheduler.yml', u'si.cif', u'Si.pspnc',
                              u'Si_si.cif', u'spec.in'])

        ls2 = os.listdir('Si_si.cif/')
        print(ls2)
        self.assertEqual(ls2, [u'.nodeid', u'__AbinitFlow__.pickle', u'indata', u'outdata', u'tmpdata', u'w0'])

        ls3 = os.listdir('Si_si.cif/w0/')
        print(ls3)
        self.assertEqual(ls3, [u'indata', u'outdata', u't0', u't1', u't2', u't3', u'tmpdata'])

        with open('Si_si.cif/w0/t0/run.abi') as f:
            abi = f.readlines()
        for x in [' ecut 44\n', ' tolvrs 1e-08\n', ' kptopt 1\n', ' ngkpt 6 6 6\n', ' nshiftk 1\n', ' nband 26\n']:
            self.assertIn(x, abi)

        with open('Si_si.cif/w0/t1/run.abi') as f:
            abi = f.readlines()
        for x in [' ecut 44\n', ' tolwfr 1e-17\n', ' kptopt 1\n', ' iscf -2\n']:
            self.assertIn(x, abi)

        with open('Si_si.cif/w0/t2/run.abi') as f:
            abi = f.readlines()
        for x in [' kptopt 1\n', ' shiftk 0 0 0\n', ' ngkpt 6 6 6\n', ' nshiftk 1\n', ' iscf -2\n', ' nband 60\n',
                  ' nsppol 1\n', ' ecut 44\n', ' toldfe 1e-08\n',' gwmem 10\n', ' inclvkb 2\n', '\n', ' symsigma 1\n',
                  ' ecuteps 8\n']:
            self.assertIn(x, abi)

        with open('Si_si.cif/w0/t3/run.abi') as f:
            abi = f.readlines()
        for x in [' kptopt 1\n', ' shiftk 0 0 0\n', ' ngkpt 6 6 6\n', ' nshiftk 1\n', ' iscf -2\n', ' nband 60\n',
                  ' nsppol 1\n', ' ecut 44\n', ' toldfe 1e-08\n', ' gwmem 10\n', ' inclvkb 2\n', '\n', ' symsigma 1\n',
                  ' ecutsigx 44\n', ' ecuteps 8\n', ' gw_qprange 2\n', ' ppmodel 1\n', ' gwcalctyp 00\n']:
            self.assertIn(x, abi)
Пример #7
0
 def test_GWget_spec(self):
     """
     Testing the factory function get_specs()
     """
     spec = get_spec('GW')
     self.assertIsInstance(spec, GWSpecs)
Пример #8
0
    def test_SingleAbinitGWWork(self):
        """
        Testing the concrete SingleAbinitGWWork class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
        shutil.copyfile(abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'shell_nompi_manager.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'simple_scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        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'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir
        self.assertIsInstance(struc, AbiStructure)
        spec = get_spec('GW')
        spec.data['kp_grid_dens'] = 100
        spec.data['kp_in'] = -100
        with open(os.path.join(wdir, 'extra_abivars'), 'w') as f:
            f.write('{"ecut": 8, "ecutsigx": 8}')

        work = SingleAbinitGWWork(struc, spec)
        self.assertEqual(len(work.CONVS), 3)

        conv_strings = ['method', 'control', 'level']
        for test in work.CONVS:
            self.assertIsInstance(work.CONVS[test]['test_range'], tuple)
            for item in conv_strings:
                self.assertIsInstance(work.CONVS[test][item], str)
        self.assertEqual(work.work_dir, 'Si_test')
        self.assertEqual(len(work.pseudo_table), 1)
        self.assertEqual(work.bands_fac, 1)

        self.assertEqual(work.get_electrons(struc), 8)
        self.assertEqual(work.get_bands(struc), 6)
        self.assertGreater(work.get_bands(struc), work.get_electrons(struc) / 2, 'More electrons than bands, very bad.')

        flow = work.create()
        print(work.work_dir)
        print(flow.workdir)
        print(flow[0].workdir)
        self.assertIsInstance(flow, Flow)
        self.assertEqual(len(flow), 1)      # one work
        self.assertEqual(len(flow[0]), 4)   # with 4 tasks
        # self.assertEqual(flow.workdir, 'Si')

        self.assertEqual(flow.build_and_pickle_dump(), 0)
        # some more tests
        flow.rmtree()

        spec = get_spec('GW')
        spec.data['converge'] = True
        struc.item = 'converge'
        work = SingleAbinitGWWork(struc, spec)
        flow = work.create()
        self.assertEqual(len(flow[0]), 45)
        self.assertEqual(flow[0][0].__class__, ScfTask)
        self.assertEqual(flow[0][1].__class__, ScfTask)
        self.assertEqual(flow[0][2].__class__, ScfTask)
        self.assertEqual(flow[0][3].__class__, ScfTask)
        self.assertEqual(flow[0][4].__class__, NscfTask)
        self.assertEqual(flow[0][5].__class__, ScrTask)
        self.assertEqual(flow[0][6].__class__, SigmaTask)

        ecuts = [dict(task.input.as_dict()['abi_args'])['ecut'] for task in flow[0]]
        print('ecuts:', ecuts)
        # it is essential that the first four are diffent, this is for the convergence study of ecut, and that
        # after that is stays the same
        self.assertEqual(ecuts, [50, 48, 46, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
                                 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
                                 44])

        nbands = [dict(task.input.as_dict()['abi_args'])['nband'] for task in flow[0]]
        print('nbands:', nbands)
        # the firs 4 should be 'low' these are self consistent
        # the fifth should be the maximum of what follows
        # the 6th and on should always be pairs that are the same, they are combinations of scr and sigma tasks
        self.assertEqual(nbands, [26, 26, 26, 26, 120, 30, 30, 60, 60, 90, 90, 120, 120, 30, 30, 60, 60, 90, 90, 120,
                                  120, 30, 30, 60, 60, 90, 90, 120, 120, 30, 30, 60, 60, 90, 90, 120, 120, 30, 30, 60,
                                  60, 90, 90, 120, 120])

        ecuteps = [dict(task.input.as_dict()['abi_args']).get('ecuteps', None) for task in flow[0]]
        print('ecuteps:', ecuteps)
        self.assertEqual(ecuteps, [None, None, None, None, None, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8,
                                   8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12])

        inplens = [len(task.input.as_dict()['abi_args']) for task in flow[0]]
        print(inplens)
        self.assertEqual(inplens, [18, 18, 18, 18, 19, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31,
                                   29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29, 31, 29,
                                   31, 29, 31])

        ngkpts = [dict(task.input.as_dict()['abi_args'])['ngkpt'] for task in flow[0]]

        for ngkpt in ngkpts:
            self.assertEqual(ngkpt, [2, 2, 2])

        npffts = [dict(task.input.as_dict()['abi_args'])['npfft'] for task in flow[0]]

        self.assertTrue(all(x == 3 for x in npffts))

        self.assertEqual(flow.build_and_pickle_dump(), 0)

        # some more tests
        flow.rmtree()

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
Пример #9
0
def main():
    spec_in = get_spec('GW')
    spec_in.read_from_file('spec.in')
    counters = spec_in.loop_structures('s')
    return counters