Skip to content

Commit

Permalink
Merge pull request #251 from pyiron/almostequal
Browse files Browse the repository at this point in the history
Test use assertAlmostEqual()
  • Loading branch information
jan-janssen authored Apr 24, 2024
2 parents 924acec + 9406dbe commit 1abf169
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions tests/test_elastic_ase_emt.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ def test_calc_elastic(self):
task_dict = workflow.generate_structures()
result_dict = evaluate_with_ase(task_dict=task_dict, ase_calculator=EMT())
elastic_dict = workflow.analyse_structures(output_dict=result_dict)
self.assertTrue(np.isclose(elastic_dict["elastic_matrix"][0, 0], 53.33436324))
self.assertTrue(np.isclose(elastic_dict["elastic_matrix"][0, 1], 32.85853415))
self.assertTrue(np.isclose(elastic_dict["elastic_matrix"][3, 3], 36.19530571))
self.assertAlmostEqual(elastic_dict["elastic_matrix"][0, 0], 53.33436324)
self.assertAlmostEqual(elastic_dict["elastic_matrix"][0, 1], 32.85853415)
self.assertAlmostEqual(elastic_dict["elastic_matrix"][3, 3], 36.19530571)
30 changes: 15 additions & 15 deletions tests/test_elastic_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def test_calc_elastic(self):
self.assertEqual(workflow._data['LC'], 'CI')
self.assertEqual(workflow._data['Lag_strain_list'], ['01', '08', '23'])
self.assertTrue(np.isclose(workflow._data['epss'], np.array([-0.005, -0.0025, 0., 0.0025, 0.005])).all())
self.assertTrue(np.isclose(workflow._data["v0"], 66.43035441556098))
self.assertTrue(np.isclose(workflow._data["e0"], -13.439999952735112))
self.assertAlmostEqual(workflow._data["v0"], 66.43035441556098)
self.assertAlmostEqual(workflow._data["e0"], -13.439999952735112)
self.assertTrue(np.isclose(workflow._data['strain_energy'], np.array(
[
[
Expand All @@ -86,10 +86,10 @@ def test_calc_elastic(self):
])).all()
)
self.assertTrue(np.isclose(workflow._data['A2'], np.array([2.20130388, 1.08985578, 1.91883479])).all())
self.assertTrue(np.isclose(elastic_dict['bulkmodul_voigt'], 78.37505857279467))
self.assertTrue(np.isclose(elastic_dict['shearmodul_voigt'], 41.46154012284969))
self.assertTrue(np.isclose(elastic_dict['youngsmodul_voigt'], 105.73882997912072))
self.assertTrue(np.isclose(elastic_dict['poissonsratio_voigt'], 0.2751435386362729))
self.assertAlmostEqual(elastic_dict['bulkmodul_voigt'], 78.37505857279467)
self.assertAlmostEqual(elastic_dict['shearmodul_voigt'], 41.46154012284969)
self.assertAlmostEqual(elastic_dict['youngsmodul_voigt'], 105.73882997912072)
self.assertAlmostEqual(elastic_dict['poissonsratio_voigt'], 0.2751435386362729)
self.assertTrue(np.isclose(elastic_dict['elastic_matrix_inverse'], np.array(
[
[0.01385733, -0.00480214, -0.00480214, 0., 0., 0.],
Expand All @@ -100,12 +100,12 @@ def test_calc_elastic(self):
[0., 0., 0., 0., 0., 0.01951656]
]
)).all())
self.assertTrue(np.isclose(elastic_dict['bulkmodul_reuss'], 78.37505857279469))
self.assertTrue(np.isclose(elastic_dict['shearmodul_reuss'], 37.54104251720356))
self.assertTrue(np.isclose(elastic_dict['youngsmodul_reuss'], 97.11702764970639))
self.assertTrue(np.isclose(elastic_dict['poissonsratio_reuss'], 0.29347803281170937))
self.assertTrue(np.isclose(elastic_dict['bulkmodul_hill'], 78.37505857279467))
self.assertTrue(np.isclose(elastic_dict['shearmodul_hill'], 39.501291320026624))
self.assertTrue(np.isclose(elastic_dict['youngsmodul_hill'], 101.45869947879392))
self.assertTrue(np.isclose(elastic_dict['poissonsratio_hill'], 0.2842453510798992))
self.assertTrue(np.isclose(elastic_dict['AVR'], 4.962492964955925))
self.assertAlmostEqual(elastic_dict['bulkmodul_reuss'], 78.37505857279469)
self.assertAlmostEqual(elastic_dict['shearmodul_reuss'], 37.54104251720356)
self.assertAlmostEqual(elastic_dict['youngsmodul_reuss'], 97.11702764970639)
self.assertAlmostEqual(elastic_dict['poissonsratio_reuss'], 0.29347803281170937)
self.assertAlmostEqual(elastic_dict['bulkmodul_hill'], 78.37505857279467)
self.assertAlmostEqual(elastic_dict['shearmodul_hill'], 39.501291320026624)
self.assertAlmostEqual(elastic_dict['youngsmodul_hill'], 101.45869947879392)
self.assertAlmostEqual(elastic_dict['poissonsratio_hill'], 0.2842453510798992)
self.assertAlmostEqual(elastic_dict['AVR'], 4.962492964955925)
6 changes: 3 additions & 3 deletions tests/test_evcurve_ase_emt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def test_calc_evcurve(self):
output_keys=["temperatures", "volumes"]
)
temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"]
self.assertTrue(np.isclose(fit_dict['volume_eq'], 63.72747170239313))
self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 39.51954433668759))
self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 2.148388436768747))
self.assertAlmostEqual(fit_dict['volume_eq'], 63.72747170239313)
self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 39.51954433668759)
self.assertAlmostEqual(fit_dict['b_prime_eq'], 2.148388436768747)
self.assertEqual(len(temperatures_ev), 2)
self.assertEqual(len(volumes_ev), 2)
self.assertTrue(volumes_ev[0] < volumes_ev[-1])
6 changes: 3 additions & 3 deletions tests/test_evcurve_ase_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def test_calc_evcurve(self):
output_keys=["temperatures", "volumes"]
)
temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"]
self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.29753110818122))
self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 218.25686471974936))
self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 6.218603542219656))
self.assertAlmostEqual(fit_dict['volume_eq'], 66.29753110818122)
self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 218.25686471974936)
self.assertAlmostEqual(fit_dict['b_prime_eq'], 6.218603542219656)
self.assertEqual(len(temperatures_ev), 2)
self.assertEqual(len(volumes_ev), 2)
self.assertTrue(volumes_ev[0] < volumes_ev[-1])
30 changes: 15 additions & 15 deletions tests/test_evcurve_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ def setUp(self):

def test_birch(self):
fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='birch')
self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.43019853103964))
self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 77.7433780646763))
self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 1.2836228593874182))
self.assertAlmostEqual(fit_dict['volume_eq'], 66.43027009811671)
self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.7433780646763)
self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2836228593874182)

def test_birchmurnaghan(self):
fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='birchmurnaghan')
self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.43019853103964))
self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 77.74337806467966))
self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 1.2836228593684815))
self.assertAlmostEqual(fit_dict['volume_eq'], 66.43027009811708)
self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.74337806467966)
self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2836228593684815)

def test_murnaghan(self):
fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='murnaghan')
self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.43019853103964))
self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 77.60443933015738))
self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 1.2716548170090776))
self.assertAlmostEqual(fit_dict['volume_eq'], 66.43035753542675)
self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.60443933015738)
self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2716548170090776)

def test_pouriertarantola(self):
fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='pouriertarantola')
self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.43019853103964))
self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 77.61743376692809))
self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 1.272111993713677))
self.assertAlmostEqual(fit_dict['volume_eq'], 66.43035598678892)
self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.61743376692809)
self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.272111993713677)

def test_vinet(self):
fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='vinet')
self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.43019853103964))
self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 77.61265363975706))
self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 1.2734991618131122))
self.assertAlmostEqual(fit_dict['volume_eq'], 66.43032532814925)
self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.61265363975706)
self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2734991618131122)
6 changes: 3 additions & 3 deletions tests/test_evcurve_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def test_calc_evcurve(self):
output_keys=["temperatures", "volumes"]
)
temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"]
self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.43019853103964))
self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 77.7250135953191))
self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 1.2795467367276832))
self.assertAlmostEqual(fit_dict['volume_eq'], 66.43019790724603)
self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.72501703646152)
self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2795467367276832)
self.assertEqual(len(temperatures_ev), 2)
self.assertEqual(len(volumes_ev), 2)
self.assertTrue(volumes_ev[0] < volumes_ev[-1])

0 comments on commit 1abf169

Please sign in to comment.