Exemple #1
0
    def test_SingleAbinitGWWork(self):
        """
        Testing the concrete SingelAbinitGWWork class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        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_nompi.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_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('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], unicode)
        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.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
Exemple #2
0
    def test_SingleAbinitGWWork(self):
        """
        Testing the concrete SingelAbinitGWWork class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        #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_nompi.yml'),
            os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(
            os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'),
            os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_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], unicode)
        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, 180, 30, 30, 60, 60, 120, 120, 180, 180, 30, 30,
            60, 60, 120, 120, 180, 180, 30, 30, 60, 60, 120, 120, 180, 180, 30,
            30, 60, 60, 120, 120, 180, 180, 30, 30, 60, 60, 120, 120, 180, 180
        ])

        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, 8, 8, 8, 8,
            8, 8, 8, 8, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16,
            16, 16, 20, 20, 20, 20, 20, 20, 20, 20
        ])

        inplens = [len(task.input.as_dict()['abi_args']) for task in flow[0]]
        print(inplens)
        self.assertEqual(inplens, [
            17, 17, 17, 17, 18, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30,
            27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27,
            30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30
        ])

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

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

        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
Exemple #3
0
    def test_SingleAbinitGWWork(self):
        """
        Testing the concrete SingelAbinitGWWork class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        #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_nompi.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_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], unicode)
        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.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