def excecute_flow(self, structure, spec_data): """ excecute 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 print(option) work_flow = SingleAbinitGWWork(structure, spec_data, option) flow = work_flow.create() if flow is not None: flow.build_and_pickle_dump() work_flow.create_job_file()
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()
def test_expand(self): self.maxDiff = None spec = get_spec('GW') tests = SingleAbinitGWWork(structure, spec).convs tests_out = { 'nscf_nbands': { 'test_range': (40, ), '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, 8, 12, 16, 20), 'control': 'gap', 'method': 'direct', 'level': 'sigma' } } self.assertEqual(expand(tests, 1), tests_out) spec.data['code'] = 'VASP' spec.update_code_interface() tests = GWG0W0VaspInputSet(structure, spec).convs tests_out = { 'ENCUTGW': { 'test_range': (200, 400, 600, 800), 'control': 'gap', 'method': 'incar_settings' } } self.assertEqual(expand(tests, 1), tests_out)
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
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
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', '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 tests = SingleAbinitGWWork(struc, spec).convs tests_out = { 'nscf_nbands': { 'test_range': (40, ), '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, 8, 12, 16, 20), 'control': 'gap', 'method': 'direct', 'level': 'sigma' } } self.assertEqual(expand(tests, 1), tests_out) spec.data['code'] = 'VASP' if "VASP_PSP_DIR" in os.environ: spec.update_code_interface() tests = GWG0W0VaspInputSet(struc, spec).convs tests_out = { 'ENCUTGW': { 'test_range': (200, 400, 600, 800), 'control': 'gap', 'method': 'incar_settings' } } self.assertEqual(expand(tests, 1), tests_out) if temp_ABINIT_PS is not None: os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT os.environ['ABINIT_PS'] = temp_ABINIT_PS
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