class WannierCalcTest(AiidaTestCase): """Test creation and preparation of WannierCalculation""" def setUp(self): """Set up test environment""" self.calc_cls = CalculationFactory('vasp.wannier') self.code = Code() self.code.set_computer(self.computer) self.code.set_remote_computer_exec((self.computer, '/bin/foo')) Common.import_paw() self.tmpd, self.tmpf = tempfile.mkstemp() self.wdat = Common.wdat() self.wdat.add_file(self.tmpf, 'test1') self.wdat.add_file(self.tmpf, 'test2') self.wdat._make_archive() def tearDown(self): os.remove(self.tmpf) def _get_calc(self): """Create a calculation for testing""" calc = self.calc_cls() calc.use_code(self.code) calc.set_computer(self.computer) calc.use_parameters(Common.win()) calc.inp.parameters.update_dict({'hr_plot': True}) calc.use_data(self.wdat) return calc, calc.get_inputs_dict() def test_verify(self): calc, inp = self._get_calc() calc.verify_inputs(inp) def test_prepare(self): """Check that preparing creates all necessary files""" calc, inp = self._get_calc() with SandboxFolder() as sandbox_f: calc_info = calc._prepare_for_submission(sandbox_f, inp) inputs = sandbox_f.get_content_list() self.assertEquals(set(inputs), {'wannier90.win', 'test1', 'test2'}) self.assertIn(['wannier90*', '.', 0], calc_info.retrieve_list) def test_write_win(self): """Check that the .win file is written correctly""" calc, inp = self._get_calc() calc.write_win(inp, self.tmpf) with open(self.tmpf, 'r') as win: res = win.read() win_res = Common.win_res() + '\nhr_plot = T' self.assertEquals(res, win_res) def test_parse_with_retrieved(self): """Check that parsing is successful and that output links are created correctly""" calc, _ = self._get_calc() pars = calc.get_parserclass()(calc) success, _ = pars.parse_with_retrieved( {'retrieved': Common.retrieved_nscf()}) self.assertTrue(success)
class WannierCalcTest(AiidaTestCase): def setUp(self): self.calc_cls = CalculationFactory('vasp.wannier') self.code = Code() self.code.set_computer(self.computer) self.code.set_remote_computer_exec((self.computer, '/bin/foo')) Common.import_paw() self.tmpd, self.tmpf = tempfile.mkstemp() self.wdat = Common.wdat() self.wdat.add_file(self.tmpf, 'test1') self.wdat.add_file(self.tmpf, 'test2') self.wdat._make_archive() def tearDown(self): os.remove(self.tmpf) def _get_calc(self): calc = self.calc_cls() calc.use_code(self.code) calc.set_computer(self.computer) calc.use_settings(Common.win()) calc.inp.settings.update_dict({'hr_plot': True}) calc.use_data(self.wdat) return calc, calc.get_inputs_dict() def test_verify(self): calc, inp = self._get_calc() calc.verify_inputs(inp) def test_prepare(self): calc, inp = self._get_calc() with SandboxFolder() as sf: ci = calc._prepare_for_submission(sf, inp) il = sf.get_content_list() self.assertEquals(set(il), {'wannier90.win', 'test1', 'test2'}) self.assertIn(['wannier90*', '.', 0], ci.retrieve_list) def test_write_win(self): calc, inp = self._get_calc() calc.write_win(inp, self.tmpf) with open(self.tmpf, 'r') as win: res = win.read() win_res = Common.win_res() + '\nhr_plot = T' self.assertEquals(res, win_res) def test_parse_with_retrieved(self): calc, inpt = self._get_calc() pars = calc.get_parserclass()(calc) ok, outs = pars.parse_with_retrieved( {'retrieved': Common.retrieved_nscf()}) outs = dict(outs)
class ScfCalcTest(AiidaTestCase): """Test creation and preparation of ScfCalculation""" def setUp(self): """Set up test environment""" self.calc_cls = CalculationFactory('vasp.scf') self.code = Code() self.code.set_computer(self.computer) self.code.set_remote_computer_exec((self.computer, '/bin/foo')) Common.import_paw() def tearDown(self): pass def _get_calc(self, kpoints=None): """Create a calculation to test""" if not kpoints: kpoints = Common.kpoints_mesh() calc = self.calc_cls() calc.use_code(self.code) calc.set_computer(self.computer) calc.use_parameters(Common.parameters()) calc.use_structure(Common.cif()) calc.use_kpoints(kpoints) calc.use_paw(Common.paw_in(), kind='In') calc.use_paw(Common.paw_as(), kind='As') return calc, calc.get_inputs_dict() def test_verify(self): """Check that correct inputs are successfully verified""" calc, inp = self._get_calc(kpoints=Common.kpoints_list()) self.assertRaises(AttributeError, calc.verify_inputs, inp) calc.use_kpoints(Common.kpoints_mesh()) inp = calc.get_inputs_dict() calc.verify_inputs(inp) # pylint: disable=protected-access def test_prepare(self): """Check that preparing writes all necessary files""" calc, inp = self._get_calc() with SandboxFolder() as sandbox_f: calc_info = calc._prepare_for_submission(sandbox_f, inp) self.assertIn('CHGCAR', calc_info.retrieve_list) self.assertIn('WAVECAR', calc_info.retrieve_list) self.assertIn('IBZKPT', calc_info.retrieve_list)
class ScfCalcTest(AiidaTestCase): def setUp(self): self.calc_cls = CalculationFactory('vasp.scf') self.code = Code() self.code.set_computer(self.computer) self.code.set_remote_computer_exec((self.computer, '/bin/foo')) Common.import_paw() def tearDown(self): pass def _get_calc(self, kp=None): if not kp: kp = Common.kpoints_mesh() calc = self.calc_cls() calc.use_code(self.code) calc.set_computer(self.computer) calc.use_settings(Common.settings()) calc.use_structure(Common.cif()) calc.use_kpoints(kp) calc.use_paw(Common.paw_in(), kind='In') calc.use_paw(Common.paw_as(), kind='As') return calc, calc.get_inputs_dict() def test_verify(self): calc, inp = self._get_calc(kp=Common.kpoints_list()) self.assertRaises(AttributeError, calc.verify_inputs, inp) calc.use_kpoints(Common.kpoints_mesh()) inp = calc.get_inputs_dict() calc.verify_inputs(inp) def test_prepare(self): calc, inp = self._get_calc() with SandboxFolder() as sf: ci = calc._prepare_for_submission(sf, inp) self.assertIn('CHGCAR', ci.retrieve_list) self.assertIn('WAVECAR', ci.retrieve_list) self.assertIn('IBZKPT', ci.retrieve_list)
class BasicCalcTest(AiidaTestCase): """Test Creation and preparation of BasicCalculation""" def setUp(self): """Set up test environment""" self.calc_cls = CalculationFactory('vasp.base.BasicCalculation') Common.import_paw() paw_cls = DataFactory('vasp.paw') self.code = Code() self.code.set_computer(self.computer) self.code.set_remote_computer_exec((self.computer, '/bin/foo')) self.paw_in = paw_cls.load_paw(element='In')[0] self.paw_as = paw_cls.load_paw(element='As')[0] self.tmp, self.tmpf = tempfile.mkstemp() def tearDown(self): os.remove(self.tmpf) def _get_calc(self, stype, ktype): """Create a calculation""" calc = self.calc_cls() calc.use_code(self.code) calc.set_computer(self.computer) calc.set_resources({'num_machines': 1, 'num_mpiprocs_per_machine': 1}) calc.use_parameters(Common.parameters()) if stype == 's': calc.use_structure(Common.structure()) else: calc.use_structure(Common.cif()) if ktype == 'm': calc.use_kpoints(Common.kpoints_mesh()) else: calc.use_kpoints(Common.kpoints_list()) calc.use_paw(self.paw_in, kind='In') calc.use_paw(self.paw_as, kind='As') return calc def test_store(self): """Test that the calculation node is stored""" c_sm = self._get_calc('s', 'm') c_sm.store_all() self.assertIsNotNone(c_sm.pk) c_sl = self._get_calc('s', 'l') c_sl.store_all() self.assertIsNotNone(c_sl.pk) c_cm = self._get_calc('c', 'm') c_cm.store_all() self.assertIsNotNone(c_cm.pk) c_cl = self._get_calc('c', 'l') c_cl.store_all() self.assertIsNotNone(c_cm.pk) def test_write_incar(self): """Check that INCAR is written correctly""" calc = self._get_calc('s', 'm') inp = calc.get_inputs_dict() calc.write_incar(inp, self.tmpf) icp = IncarIo(self.tmpf) for key, value in calc.inp.parameters.get_dict().iteritems(): self.assertIn(str(value), icp.incar_dict[key]) def test_write_poscar_structure(self): """Check that POSCAR is written when the input is a structure node""" calc = self._get_calc('s', 'm') inp = calc.get_inputs_dict() from ase.io.vasp import read_vasp calc.write_poscar(inp, self.tmpf) working_dir = os.getcwd() os.chdir(os.path.dirname(self.tmpf)) poscar = None poscar = read_vasp(self.tmpf) os.chdir(os.path.dirname(working_dir)) self.assertIsNotNone(poscar) def test_write_poscar_cif(self): """Check that POSCAR is written when the input is a .cif file""" calc = self._get_calc('c', 'm') inp = calc.get_inputs_dict() from ase.io.vasp import read_vasp calc.write_poscar(inp, self.tmpf) working_dir = os.getcwd() os.chdir(os.path.dirname(self.tmpf)) poscar = None poscar = read_vasp(self.tmpf) os.chdir(os.path.dirname(working_dir)) self.assertIsNotNone(poscar) def test_write_kpoints_mesh(self): """Check that KPOINTS in mesh format is written correctly""" from aiida_vasp.io.kpoints import KpParser calc = self._get_calc('c', 'm') inp = calc.get_inputs_dict() calc.write_kpoints(inp, self.tmpf) kpp = KpParser(self.tmpf) self.assertTrue((kpp.kpoints == Common.kpoints_mesh_res()).all()) def test_write_kpoints_list(self): """Check that KPOINTS in list format is written correctly""" from aiida_vasp.io.kpoints import KpParser calc = self._get_calc('c', 'l') inp = calc.get_inputs_dict() calc.write_kpoints(inp, self.tmpf) kpp = KpParser(self.tmpf) kres, wres = Common.kpoints_list_res() self.assertTrue((kpp.kpoints == kres).all()) self.assertTrue((kpp.weights == wres).all()) def test_write_potcar(self): """Check that POTCAR is written correctly""" calc = self._get_calc('c', 'm') inp = calc.get_inputs_dict() calc.write_potcar(inp, self.tmpf) with open(self.tmpf, 'r') as pcf: pcs = pcf.read() with open(os.path.expanduser('~/tmp/potcar'), 'w') as tpc: tpc.write(pcs) self.assertIn('In_d', pcs) self.assertIn('As', pcs) self.assertEquals(pcs.count('End of Dataset'), 2) # pylint: disable=protected-access def test_elements(self): calc = self._get_calc('c', 'm') self.assertRaises(AttributeError, calc.get_attr, 'elements') calc._prestore() self.assertEquals(['In', 'As'], calc.elements) def test_new_parameters(self): calc = self.calc_cls() calc.use_parameters(calc.new_parameters(dict={'bla': 3})) self.assertEquals(calc.inp.parameters.get_dict().get('bla'), 3) def test_new_structure(self): calc = self.calc_cls() calc.use_structure(calc.new_structure()) def test_new_kpoints(self): calc = self.calc_cls() calc.use_kpoints(calc.new_kpoints()) def test_load_paw(self): calc = self.calc_cls() calc.use_paw(calc.load_paw(symbol=self.paw_in.symbol, family='TEST'), kind='test')
class BasicCalcTest(AiidaTestCase): def setUp(self): self.calc_cls = CalculationFactory('vasp.base.BasicCalculation') Common.import_paw() Paw = DataFactory('vasp.paw') self.code = Code() self.code.set_computer(self.computer) self.code.set_remote_computer_exec((self.computer, '/bin/foo')) self.paw_in = Paw.load_paw(element='In')[0] self.paw_as = Paw.load_paw(element='As')[0] self.tmp, self.tmpf = tempfile.mkstemp() def tearDown(self): import os os.remove(self.tmpf) def _get_calc(self, stype, ktype): calc = self.calc_cls() calc.use_code(self.code) calc.set_computer(self.computer) calc.set_resources({'num_machines': 1, 'num_mpiprocs_per_machine': 1}) calc.use_settings(Common.settings()) if stype == 's': calc.use_structure(Common.structure()) else: calc.use_structure(Common.cif()) if ktype == 'm': calc.use_kpoints(Common.kpoints_mesh()) else: calc.use_kpoints(Common.kpoints_list()) calc.use_paw(self.paw_in, kind='In') calc.use_paw(self.paw_as, kind='As') return calc def test_store(self): c_sm = self._get_calc('s', 'm') c_sm.store_all() self.assertIsNotNone(c_sm.pk) c_sl = self._get_calc('s', 'l') c_sl.store_all() self.assertIsNotNone(c_sl.pk) c_cm = self._get_calc('c', 'm') c_cm.store_all() self.assertIsNotNone(c_cm.pk) c_cl = self._get_calc('c', 'l') c_cl.store_all() self.assertIsNotNone(c_cm.pk) def test_write_incar(self): calc = self._get_calc('s', 'm') inp = calc.get_inputs_dict() calc.write_incar(inp, self.tmpf) icp = IncarParser(self.tmpf) for k, v in calc.inp.settings.get_dict().iteritems(): self.assertIn(str(v), icp.result[k]) def test_write_poscar_structure(self): calc = self._get_calc('s', 'm') inp = calc.get_inputs_dict() from ase.io.vasp import read_vasp calc.write_poscar(inp, self.tmpf) wd = os.getcwd() os.chdir(os.path.dirname(self.tmpf)) poscar = None poscar = read_vasp(self.tmpf) os.chdir(os.path.dirname(wd)) self.assertIsNotNone(poscar) def test_write_poscar_cif(self): calc = self._get_calc('c', 'm') inp = calc.get_inputs_dict() from ase.io.vasp import read_vasp calc.write_poscar(inp, self.tmpf) wd = os.getcwd() os.chdir(os.path.dirname(self.tmpf)) poscar = None poscar = read_vasp(self.tmpf) os.chdir(os.path.dirname(wd)) self.assertIsNotNone(poscar) def test_write_kpoints_mesh(self): from aiida.tools.codespecific.vasp.io.kpoints import KpParser calc = self._get_calc('c', 'm') inp = calc.get_inputs_dict() calc.write_kpoints(inp, self.tmpf) kpp = KpParser(self.tmpf) self.assertTrue((kpp.kpoints == Common.kpoints_mesh_res()).all()) def test_write_kpoints_list(self): from aiida.tools.codespecific.vasp.io.kpoints import KpParser calc = self._get_calc('c', 'l') inp = calc.get_inputs_dict() calc.write_kpoints(inp, self.tmpf) kpp = KpParser(self.tmpf) kres, wres = Common.kpoints_list_res() self.assertTrue((kpp.kpoints == kres).all()) self.assertTrue((kpp.weights == wres).all()) def test_write_potcar(self): calc = self._get_calc('c', 'm') inp = calc.get_inputs_dict() calc.write_potcar(inp, self.tmpf) with open(self.tmpf, 'r') as pcf: pcs = pcf.read() with open(os.path.expanduser('~/tmp/potcar'), 'w') as tpc: tpc.write(pcs) self.assertIn('In_d', pcs) self.assertIn('As', pcs) self.assertEquals(pcs.count('End of Dataset'), 2) def test_elements(self): calc = self._get_calc('c', 'm') self.assertRaises(AttributeError, calc.get_attr, 'elements') calc._prestore() self.assertEquals(['In', 'As'], calc.elements) def test_new_settings(self): calc = self.calc_cls() calc.use_settings(calc.new_settings(dict={'bla': 3})) self.assertEquals(calc.inp.settings.get_dict().get('bla'), 3) def test_new_structure(self): calc = self.calc_cls() calc.use_structure(calc.new_structure()) def test_new_kpoints(self): calc = self.calc_cls() calc.use_kpoints(calc.new_kpoints()) def test_load_paw(self): calc = self.calc_cls() calc.use_paw(calc.load_paw( symbol=self.paw_in.symbol, family='TEST'), kind='test')
class NscfCalcTest(AiidaTestCase): """Test creating and preparing NscfCalculation""" def setUp(self): """Set up test environment""" self.calc_cls = CalculationFactory('vasp.nscf') self.code = Code() self.code.set_computer(self.computer) self.code.set_remote_computer_exec((self.computer, '/bin/foo')) Common.import_paw() self.tmpd, self.tmpf = tempfile.mkstemp() def tearDown(self): os.remove(self.tmpf) def _get_calc(self, kpoints=None): """Create a calculation for testing""" if not kpoints: kpoints = Common.kpoints_mesh() calc = self.calc_cls() calc.use_code(self.code) calc.set_computer(self.computer) calc.use_parameters(Common.parameters()) calc.inp.parameters.update_dict({'icharg': 11}) calc.use_structure(Common.cif()) calc.use_kpoints(kpoints) calc.use_paw(Common.paw_in(), kind='In') calc.use_paw(Common.paw_as(), kind='As') calc.use_charge_density(Common.charge_density()) calc.use_wavefunctions(Common.wavefunctions()) return calc, calc.get_inputs_dict() def test_verify(self): """Check correct inputs get verified successfully""" calc, inp = self._get_calc(kpoints=Common.kpoints_list()) calc.verify_inputs(inp) calc.use_kpoints(Common.kpoints_mesh()) inp = calc.get_inputs_dict() calc.verify_inputs(inp) calc.use_parameters(Common.parameters()) inp = calc.get_inputs_dict() calc.verify_inputs(inp) # pylint: disable=protected-access def test_prepare(self): """Check that preparing creates all necessary files""" calc, inp = self._get_calc() with SandboxFolder() as sandbox_f: calc_info = calc._prepare_for_submission(sandbox_f, inp) inputs = sandbox_f.get_content_list() self.assertEquals( set(inputs), {'INCAR', 'KPOINTS', 'POSCAR', 'POTCAR', 'CHGCAR', 'WAVECAR'}) self.assertIn('EIGENVAL', calc_info.retrieve_list) self.assertIn('DOSCAR', calc_info.retrieve_list) self.assertIn(['wannier90*', '.', 0], calc_info.retrieve_list) calc.use_parameters(Common.parameters()) inp = calc.get_inputs_dict() calc.verify_inputs(inp) with SandboxFolder() as sandbox_f: calc._prepare_for_submission(sandbox_f, inp) inputs = sandbox_f.get_content_list() self.assertEquals(set(inputs), {'INCAR', 'KPOINTS', 'POSCAR', 'POTCAR', 'WAVECAR'}) def test_write_chgcar(self): """Test that CHGAR file is written correctly""" calc, inp = self._get_calc() calc.write_chgcar(inp, self.tmpf) with open(self.tmpf, 'r') as chg: res = chg.read() self.assertEquals(res, Common.charge_density_res()) def test_write_wavecar(self): """Test that WAVECAR file is written correctly""" calc, inp = self._get_calc() calc.write_wavecar(inp, self.tmpf) with open(self.tmpf, 'r') as wav: res = wav.read() self.assertEquals(res, Common.wavefunctions_res()) def test_parse_with_retrieved(self): """Check that parsing is successful and creates the right output links""" calc, _ = self._get_calc() pars = calc.get_parserclass()(calc) success, outs = pars.parse_with_retrieved( {'retrieved': Common.retrieved_nscf()}) outs = dict(outs) self.assertTrue(success) self.assertIn('bands', outs) self.assertIn('dos', outs) self.assertIn('wannier_parameters', outs) self.assertIn('wannier_data', outs) self.assertIn('results', outs)
class AmnCalcTest(AiidaTestCase): def setUp(self): self.calc_cls = CalculationFactory('vasp.amn') self.code = Code() self.code.set_computer(self.computer) self.code.set_remote_computer_exec((self.computer, '/bin/foo')) Common.import_paw() self.tmpd, self.tmpf = tempfile.mkstemp() self.wdat = Common.wdat() self.wdat.add_file(self.tmpf, 'test1') self.wdat.add_file(self.tmpf, 'test2') self.wdat._make_archive() def tearDown(self): os.remove(self.tmpf) def _get_calc(self, kp=None, no_wdat=False): if not kp: kp = Common.kpoints_mesh() calc = self.calc_cls() calc.use_code(self.code) calc.set_computer(self.computer) calc.use_settings(Common.settings()) calc.inp.settings.update_dict({'icharg': 11}) calc.use_structure(Common.cif()) calc.use_kpoints(kp) calc.use_paw(Common.paw_in(), kind='In') calc.use_paw(Common.paw_as(), kind='As') calc.use_charge_density(Common.charge_density()) calc.use_wavefunctions(Common.wavefunctions()) calc.use_wannier_settings(Common.win()) if not no_wdat: calc.use_wannier_data(self.wdat) return calc, calc.get_inputs_dict() def test_verify(self): calc, inp = self._get_calc(kp=Common.kpoints_list()) calc.verify_inputs(inp) calc.use_kpoints(Common.kpoints_mesh()) inp = calc.get_inputs_dict() calc.verify_inputs(inp) calc.use_settings(Common.settings()) inp = calc.get_inputs_dict() calc.verify_inputs(inp) def test_prepare(self): calc, inp = self._get_calc() with SandboxFolder() as sf: ci = calc._prepare_for_submission(sf, inp) il = sf.get_content_list() self.assertEquals( set(il), { 'INCAR', 'KPOINTS', 'POSCAR', 'POTCAR', 'CHGCAR', 'WAVECAR', 'wannier90.win', 'test1', 'test2' }) self.assertIn(['wannier90*', '.', 0], ci.retrieve_list) calc.use_settings(Common.settings()) inp = calc.get_inputs_dict() calc.verify_inputs(inp) with SandboxFolder() as sf: calc._prepare_for_submission(sf, inp) il = sf.get_content_list() self.assertEquals( set(il), { 'INCAR', 'KPOINTS', 'POSCAR', 'POTCAR', 'WAVECAR', 'wannier90.win', 'test1', 'test2' }) calc, inp = self._get_calc(no_wdat=True) with SandboxFolder() as sf: ci = calc._prepare_for_submission(sf, inp) il = sf.get_content_list() self.assertEquals( set(il), { 'INCAR', 'KPOINTS', 'POSCAR', 'POTCAR', 'CHGCAR', 'WAVECAR', 'wannier90.win' }) def test_write_chgcar(self): calc, inp = self._get_calc() calc.write_chgcar(inp, self.tmpf) with open(self.tmpf, 'r') as chg: res = chg.read() self.assertEquals(res, Common.charge_density_res()) def test_write_wavecar(self): calc, inp = self._get_calc() calc.write_wavecar(inp, self.tmpf) with open(self.tmpf, 'r') as wav: res = wav.read() self.assertEquals(res, Common.wavefunctions_res()) def test_parse_with_retrieved(self): calc, inpt = self._get_calc() pars = calc.get_parserclass()(calc) ok, outs = pars.parse_with_retrieved( {'retrieved': Common.retrieved_nscf()}) outs = dict(outs) self.assertIn('wannier_data', outs)