From 54df1d46413286fae4b3570740eca0985a7caaf5 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 23 Apr 2024 20:38:07 -0500 Subject: [PATCH 1/3] Test use assertAlmostEqual() --- tests/test_elastic_ase_emt.py | 6 +++--- tests/test_elastic_lammps.py | 30 +++++++++++++++--------------- tests/test_evcurve_ase_emt.py | 6 +++--- tests/test_evcurve_ase_lammps.py | 6 +++--- tests/test_evcurve_eos.py | 30 +++++++++++++++--------------- tests/test_evcurve_lammps.py | 6 +++--- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/test_elastic_ase_emt.py b/tests/test_elastic_ase_emt.py index 91b03901..95b27154 100644 --- a/tests/test_elastic_ase_emt.py +++ b/tests/test_elastic_ase_emt.py @@ -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) diff --git a/tests/test_elastic_lammps.py b/tests/test_elastic_lammps.py index 21618edb..5037341f 100644 --- a/tests/test_elastic_lammps.py +++ b/tests/test_elastic_lammps.py @@ -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( [ [ @@ -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.], @@ -100,15 +100,15 @@ 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) # self.assertTrue(np.isclose(elastic_dict['C_eigval'].eigenvalues, np.array( # [235.12517572, 53.59208765, 53.59208765, 51.23853765, 51.23853765, 51.23853765] # )).all()) diff --git a/tests/test_evcurve_ase_emt.py b/tests/test_evcurve_ase_emt.py index 015cb630..725a3b3c 100644 --- a/tests/test_evcurve_ase_emt.py +++ b/tests/test_evcurve_ase_emt.py @@ -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]) diff --git a/tests/test_evcurve_ase_lammps.py b/tests/test_evcurve_ase_lammps.py index 2caaef5a..74f9c639 100644 --- a/tests/test_evcurve_ase_lammps.py +++ b/tests/test_evcurve_ase_lammps.py @@ -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]) diff --git a/tests/test_evcurve_eos.py b/tests/test_evcurve_eos.py index 57f6caa8..157cc3e9 100644 --- a/tests/test_evcurve_eos.py +++ b/tests/test_evcurve_eos.py @@ -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.43019853103964) + 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.43019853103964) + 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.43019853103964) + 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.43019853103964) + 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.43019853103964) + self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.61265363975706) + self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2734991618131122) diff --git a/tests/test_evcurve_lammps.py b/tests/test_evcurve_lammps.py index a57da44d..704638d5 100644 --- a/tests/test_evcurve_lammps.py +++ b/tests/test_evcurve_lammps.py @@ -52,9 +52,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.43019853103964) + self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.7250135953191) + 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]) From cf4dc4d08f9649a76b4574e9ab89168aa745b6b5 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 23 Apr 2024 20:43:24 -0500 Subject: [PATCH 2/3] fix equilibrium volume --- tests/test_evcurve_eos.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_evcurve_eos.py b/tests/test_evcurve_eos.py index 157cc3e9..32aff681 100644 --- a/tests/test_evcurve_eos.py +++ b/tests/test_evcurve_eos.py @@ -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.assertAlmostEqual(fit_dict['volume_eq'], 66.43019853103964) + 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.assertAlmostEqual(fit_dict['volume_eq'], 66.43019853103964) + 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.assertAlmostEqual(fit_dict['volume_eq'], 66.43019853103964) + 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.assertAlmostEqual(fit_dict['volume_eq'], 66.43019853103964) + 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.assertAlmostEqual(fit_dict['volume_eq'], 66.43019853103964) + 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) From 5b23e14a4cb78839bf25ef11be6169d5c335749a Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 23 Apr 2024 20:49:17 -0500 Subject: [PATCH 3/3] fix evcurve --- tests/test_evcurve_lammps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_evcurve_lammps.py b/tests/test_evcurve_lammps.py index 704638d5..eafe0b05 100644 --- a/tests/test_evcurve_lammps.py +++ b/tests/test_evcurve_lammps.py @@ -52,8 +52,8 @@ def test_calc_evcurve(self): output_keys=["temperatures", "volumes"] ) temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] - self.assertAlmostEqual(fit_dict['volume_eq'], 66.43019853103964) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.7250135953191) + 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)