|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import os |
| 4 | +import unittest |
| 5 | + |
| 6 | +import numpy as np |
| 7 | + |
| 8 | +from qha.calculator import DifferentPhDOSCalculator |
| 9 | +from qha.multi_configurations.different_phonon_dos import PartitionFunction |
| 10 | +from qha.settings import from_yaml |
| 11 | + |
| 12 | + |
| 13 | +class TestPartitionFunction(unittest.TestCase): |
| 14 | + def setUp(self) -> None: |
| 15 | + os.chdir('../../examples/ice VII/') |
| 16 | + self.user_settings = {} |
| 17 | + settings = from_yaml("settings.yaml") |
| 18 | + |
| 19 | + for key in ('input', 'calculation', |
| 20 | + 'thermodynamic_properties', 'static_only', 'energy_unit', |
| 21 | + 'T_MIN', 'NT', 'DT', 'DT_SAMPLE', |
| 22 | + 'P_MIN', 'NTV', 'DELTA_P', 'DELTA_P_SAMPLE', |
| 23 | + 'volume_ratio', 'order', 'p_min_modifier', |
| 24 | + 'T4FV', 'output_directory', 'high_verbosity'): |
| 25 | + try: |
| 26 | + self.user_settings.update({key: settings[key]}) |
| 27 | + except KeyError: |
| 28 | + continue |
| 29 | + self.calculator = DifferentPhDOSCalculator(self.user_settings) |
| 30 | + self.calculator.read_input() |
| 31 | + self.partition_function = PartitionFunction(1000, self.calculator.degeneracies, self.calculator.q_weights, |
| 32 | + self.calculator.static_energies, self.calculator._volumes, |
| 33 | + self.calculator.frequencies) |
| 34 | + |
| 35 | + def test_parse_settings(self): |
| 36 | + self.assertDictEqual(self.user_settings, { |
| 37 | + 'input': {'input_01': 6, 'input_02': 96, 'input_03': 96, 'input_04': 24, 'input_05': 24, 'input_06': 192, |
| 38 | + 'input_07': 384, 'input_08': 24, 'input_09': 384, 'input_10': 96, 'input_11': 192, |
| 39 | + 'input_12': 384, 'input_13': 48, 'input_14': 96, 'input_15': 48, 'input_16': 96, 'input_17': 96, |
| 40 | + 'input_18': 384, 'input_19': 384, 'input_20': 48, 'input_21': 384, 'input_22': 96, |
| 41 | + 'input_23': 384, 'input_24': 96, 'input_25': 192, 'input_26': 192, 'input_27': 192, |
| 42 | + 'input_28': 384, 'input_29': 192, 'input_30': 192, |
| 43 | + 'input_31': 96, 'input_32': 192, 'input_33': 192, 'input_34': 384, 'input_35': 384, |
| 44 | + 'input_36': 192, 'input_37': 24, 'input_38': 48, 'input_39': 96, 'input_40': 48, 'input_41': 384, |
| 45 | + 'input_42': 12, 'input_43': 96, 'input_44': 48, 'input_45': 192, 'input_46': 12, 'input_47': 96, |
| 46 | + 'input_48': 48, 'input_49': 6, 'input_50': 96, 'input_51': 24, 'input_52': 24}, |
| 47 | + 'calculation': 'different phonon dos', |
| 48 | + 'thermodynamic_properties': ['F', 'G', 'U', 'H', 'V', 'alpha', 'gamma', 'Cp', 'Cv', 'Bt', 'Btp', 'Bs'], |
| 49 | + 'static_only': False, 'energy_unit': 'ry', 'T_MIN': 0, 'NT': 401, 'DT': 1, 'DT_SAMPLE': 1, 'P_MIN': 0, |
| 50 | + 'NTV': 701, 'DELTA_P': 0.1, 'DELTA_P_SAMPLE': 1, 'order': 3, 'p_min_modifier': 1.0, 'T4FV': ['0', '300'], |
| 51 | + 'output_directory': './results/', 'high_verbosity': True}) |
| 52 | + |
| 53 | + def test_parameters(self): |
| 54 | + self.assertEqual(self.calculator.degeneracies, ( |
| 55 | + 6, 96, 96, 24, 24, 192, 384, 24, 384, 96, 192, 384, 48, 96, 48, 96, 96, 384, 384, 48, 384, 96, 384, 96, 192, |
| 56 | + 192, 192, 384, 192, 192, 96, 192, 192, 384, 384, 192, 24, 48, 96, 48, 384, 12, 96, 48, 192, 12, 96, 48, 6, |
| 57 | + 96, 24, 24)) |
| 58 | + self.assertEqual(self.calculator.frequencies.shape, |
| 59 | + (52, 6, 1, 144)) # frequency on each (configuration, volume, q-point and mode) |
| 60 | + np.testing.assert_array_equal(self.calculator.q_weights, |
| 61 | + np.ones((52, 1))) # We only have Γ points, whose weight is 1. |
| 62 | + np.testing.assert_array_equal(self.calculator.volumes, |
| 63 | + [2290.7412, 2179.0756, 1666.2973, 1362.8346, 1215.6528, 1120.4173]) |
| 64 | + self.assertEqual(self.calculator._volumes.shape, (52, 6)) |
| 65 | + self.assertEqual(self.calculator.static_energies.shape, |
| 66 | + (52, 6)) # static energy on each (configuration, volume) |
| 67 | + |
| 68 | + def test_partition_function(self): |
| 69 | + self.assertEqual(self.partition_function.unaligned_free_energies_for_each_configuration.shape, |
| 70 | + (52, 6)) # (# of configurations, # of volumes) |
| 71 | + self.assertEqual(self.partition_function.aligned_free_energies_for_each_configuration.shape, |
| 72 | + (52, 6)) # (# of configurations, # of volumes) |
| 73 | + self.assertEqual(self.partition_function.partition_functions_for_each_configuration.shape, |
| 74 | + (52, 6)) # (# of configurations, # of volumes) |
| 75 | + self.assertEqual(self.partition_function.partition_functions_for_all_configurations.shape, |
| 76 | + (6,)) # (# of volumes,) |
| 77 | + np.testing.assert_array_almost_equal(self.partition_function.get_free_energies(), |
| 78 | + [-550.74580132, -550.70964062, -550.37436235, -549.87365787, -549.43586034, |
| 79 | + -549.03029969]) |
0 commit comments