def test_Chemical_Element_to_and_from_hdf_with_None_Parent(self): pr = Project(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_periodic_table')) basis = pr.create_structure(element='Ni', bravais_basis='fcc', lattice_constant=3.7) ham = pr.create_job(pr.job_type.Lammps, 'lammps_test_2') test_ham = pr.create_job(pr.job_type.Lammps, 'lammps_test_2') ham.structure = basis ham.to_hdf() test_ham.from_hdf() self.assertEqual(test_ham['input/structure/species'][0], ham['input/structure/species'][0]) ham.remove()
def test_Chemical_Element_to_and_from_hdf(self): ni_up = self.pse.add_element("Ni", "Ni_up", spin="up") pr = Project(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_periodic_table')) basis = pr.create_structure(element=ni_up, bravais_basis='fcc', lattice_constant=3.7) ham = pr.create_job(pr.job_type.Lammps, 'lammps_test_1') test_ham = pr.create_job(pr.job_type.Lammps, 'lammps_test_1') ham.structure = basis ham.to_hdf() test_ham.from_hdf() self.assertEqual(test_ham['input/structure/species'][0], ham['input/structure/species'][0]) ham.remove()
class TestStructureContainer(unittest.TestCase): def setUp(self): self.lattice_constant = 3.5 self.project = Project('structure_testing') self.basis = self.project.create_structure( element="Fe", bravais_basis='fcc', lattice_constant=self.lattice_constant) self.structure_container = self.project.create_job( "StructureContainer", "structure_container") self.structure_container.structure = self.basis @classmethod def tearDownClass(cls): project = Project('structure_testing') ham = project.load(1) ham.remove() project.remove(enable=True) s.close_connection() os.remove('container.db') def test_container(self): structure_container = self.project.load(1) self.assertEqual(structure_container.job_id, 1) self.assertEqual(structure_container.job_name, 'structure_container') self.assertEqual(structure_container.project_hdf5.project_path, 'structure_testing/') self.assertTrue(structure_container.status.finished) self.assertEqual(structure_container.structure, self.basis)
class TestStructureContainer(unittest.TestCase): def setUp(self): self.lattice_constant = 3.5 self.file_location = os.path.dirname(os.path.abspath(__file__)) self.project = Project( os.path.join(self.file_location, 'structure_testing')) self.basis = self.project.create_structure( element="Fe", bravais_basis='fcc', lattice_constant=self.lattice_constant) self.structure_container = self.project.create_job( self.project.job_type.StructureContainer, "structure_container") self.structure_container.structure = self.basis @classmethod def tearDownClass(cls): file_location = os.path.dirname(os.path.abspath(__file__)) project = Project(os.path.join(file_location, 'structure_testing')) ham = project.load(project.get_job_ids()[0]) ham.remove() project.remove(enable=True) def test_container(self): structure_container = self.project.load(self.project.get_job_ids()[0]) self.assertEqual(structure_container.job_id, self.project.get_job_ids()[0]) self.assertEqual(structure_container.job_name, 'structure_container') self.assertTrue('atomistics/job/structure_testing/' in structure_container.project_hdf5.project_path) self.assertTrue(structure_container.status.finished) self.assertEqual(structure_container.structure, self.basis)
class TestExampleJob(unittest.TestCase): def setUp(self): self.count_run_one = 12 self.count_run_two = 12 self.file_location = os.path.dirname(os.path.abspath(__file__)) self.project = Project(os.path.join(self.file_location, 'random_testing_lib')) self.ham = self.project.create_job("ExampleJob", "job_test_run") self.ham.input['count'] = self.count_run_one self.ham.server.run_mode.interactive = True self.ham.run() self.ham.input['count'] = self.count_run_two self.ham.run() self.ham.interactive_close() @classmethod def tearDownClass(cls): file_location = os.path.dirname(os.path.abspath(__file__)) project = Project(os.path.join(file_location, 'random_testing_lib')) ham = project.load(project.get_job_ids()[0]) ham.remove() project.remove(enable=True) def test_output(self): count = self.ham.get("output/generic/count") energy = self.ham.get("output/generic/energy") self.assertEqual(self.count_run_one, count[0]) self.assertEqual(self.count_run_two, count[1]) self.assertEqual(count[0], len(energy[0])) self.assertEqual(count[0], len(energy[1]))
class TestExampleJob(unittest.TestCase): def setUp(self): self.count = 12 self.file_location = os.path.dirname(os.path.abspath(__file__)) self.project = Project(os.path.join(self.file_location, 'random_testing_non_modal')) self.project.remove_jobs(recursive=True) self.project.set_logging_level('INFO') @classmethod def tearDownClass(cls): # print('tear down') file_location = os.path.dirname(os.path.abspath(__file__)) project = Project(os.path.join(file_location, 'random_testing_non_modal')) project.remove_jobs() project.remove(enable=True) def test_non_modal_run(self): ham_non_modal = self.project.create_job(self.project.job_type.ExampleJob, "job_non_modal") ham_non_modal.input['count'] = self.count ham_non_modal.server.run_mode.non_modal = True ham_non_modal.run() self.assertFalse(ham_non_modal.status.finished) self.project.wait_for_job(ham_non_modal, interval_in_s=5, max_iterations=50) self.assertTrue(ham_non_modal.status.finished) lines = self.project['job_non_modal/input.inp'] input_lst = ["alat 3.2 #lattice constant (would be in a more realistic example in the structure file)\n", "alpha 0.1 #noise amplitude\n", "a_0 3 #equilibrium lattice constant\n", "a_1 0\n", "a_2 1. #2nd order in energy (corresponds to bulk modulus)\n", "a_3 0. #3rd order\n", "a_4 0. #4th order\n", "count " + str(self.count) + " #number of calls (dummy)\n", "write_restart True\n", "read_restart False\n"] self.assertEqual(input_lst, lines) lines = self.project['job_non_modal/restart.out'] restart_lst = ["count " + str(self.count) + " \n"] self.assertEqual(restart_lst, lines) energy_lst = ham_non_modal.get("output/generic/energy_tot") self.assertEqual(len(energy_lst), self.count) lines = self.project['job_non_modal/output.log'] output_lst = ["exampleExecutable logFile \n", "alat 3.2 \n", "count " + str(self.count) + " \n"] self.assertEqual(output_lst, lines[0:3]) energy_output_lst = np.array([float(line.split(' ')[1]) for line in lines[3:]]) for e_1, e_2 in zip(energy_lst, energy_output_lst): self.assertTrue(1 > e_1 > 0) self.assertEqual(e_1, e_2) ham_non_modal.remove()
class TestVasp(unittest.TestCase): """ Tests the pyiron.objects.hamilton.dft.vasp.Vasp class """ def setUp(self): self.file_location = os.path.dirname(os.path.abspath(__file__)) self.project = Project(os.path.join(self.file_location, 'test_vasp')) self.job = self.project.create_job("Vasp", "trial") @classmethod def tearDownClass(cls): pass def test_init(self): self.assertEqual(self.job.__name__, "Vasp") self.assertEqual(self.job._sorted_indices, None) self.assertIsInstance(self.job.input, Input) self.assertIsInstance(self.job._output_parser, Output) def test_calc_static(self): self.job.calc_static(electronic_steps=90, retain_charge_density=True, retain_electrostatic_potential=True) self.assertEqual(self.job.input.incar["IBRION"], -1) self.assertEqual(self.job.input.incar["NELM"], 90) self.assertEqual(self.job.input.incar["LVTOT"], True) self.assertEqual(self.job.input.incar["LCHARG"], True) def test_set_structure(self): self.assertEqual(self.job.structure, None) atoms = CrystalStructure("Pt", BravaisBasis="fcc", a=3.98) self.job.structure = atoms self.assertEqual(self.job.structure, atoms) self.job.structure = None self.assertEqual(self.job.structure, None) self.job.structure = atoms self.assertEqual(self.job.structure, atoms) def test_list_potenitals(self): self.assertRaises(ValueError, self.job.list_potentials) def tearDown(self): pass