def test_force_constants_self_consistency(self): trajectory = io.generate_test_trajectory(self.structure, supercell=[2, 2, 2], total_time=10, silent=False) calculation = dynaphopy.Quasiparticle(trajectory) calculation.select_power_spectra_algorithm(2) renormalized_force_constants = calculation.get_renormalized_force_constants().get_array() harmonic_force_constants = calculation.dynamic.structure.get_force_constants().get_array() self.assertEqual(np.allclose(renormalized_force_constants, harmonic_force_constants, rtol=1, atol=1.e-2), True)
def setUp(self): structure = io.read_from_file_structure_poscar('MgO_data/POSCAR') structure.set_primitive_matrix([[0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]]) structure.set_force_constants(get_force_constants_from_file(file_name='MgO_data/FORCE_CONSTANTS', fc_supercell=[[2, 0, 0], [0, 2, 0], [0, 0, 2]])) trajectory = io.generate_test_trajectory(structure, supercell=[2, 2, 2], total_time=5, silent=False) self.calculation = dynaphopy.Quasiparticle(trajectory)
def test_q_points_data(self): import yaml trajectory = io.generate_test_trajectory(self.structure, supercell=[2, 2, 2], total_time=5, silent=False) calculation = dynaphopy.Quasiparticle(trajectory) calculation.select_power_spectra_algorithm(2) calculation.write_atomic_displacements([0, 0, 1], 'atomic_displacements.dat') calculation.write_quasiparticles_data( filename='quasiparticles_data.yaml') calculation.write_renormalized_phonon_dispersion_bands( filename='bands_data.yaml') reference = np.loadtxt('Si_data/atomic_displacements.dat') data = np.loadtxt('atomic_displacements.dat') test_range = np.arange(-5, 5, 0.1) for i in range(1, data.shape[1]): diff_square = np.square( np.interp(test_range, data[:, 0], data[:, i], right=0, left=0) - np.interp(test_range, reference[:, 0], reference[:, i], right=0, left=0)) rms = np.sqrt(np.average(diff_square)) self.assertLess(rms, 0.05) def assertDictAlmostEqual(dict, reference, decimal=6): for key, value in dict.items(): np.testing.assert_array_almost_equal(np.array(value), np.array(reference[key]), decimal=decimal) files = ['quasiparticles_data.yaml'] for file in files: print('file: {}'.format(file)) with open(file) as stream: data = yaml.safe_load(stream) with open('Si_data/' + file) as stream: reference = yaml.safe_load(stream) for dict_data, dict_reference in zip(data, reference): assertDictAlmostEqual(dict_data, dict_reference, decimal=1)
def test_force_constants_self_consistency(self): trajectory = io.generate_test_trajectory(self.structure, supercell=[2, 2, 2], total_time=3, time_step=0.001, temperature=300, silent=False) self.calculation = dynaphopy.Quasiparticle(trajectory) self.calculation.select_power_spectra_algorithm(2) renormalized_force_constants = self.calculation.get_renormalized_force_constants().get_array() harmonic_force_constants = self.calculation.dynamic.structure.get_force_constants().get_array() self.assertEqual(np.allclose(renormalized_force_constants, harmonic_force_constants, rtol=1, atol=5.e-2), True)
def setUp(self): self.structure = io.read_from_file_structure_poscar('GaN_data/POSCAR') self.structure.set_primitive_matrix([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) self.structure.set_force_constants(get_force_constants_from_file(file_name='GaN_data/FORCE_CONSTANTS', fc_supercell=[[3, 0, 0], [0, 3, 0], [0, 0, 3]])) if not os.path.exists('test_gan.h5'): trajectory = io.generate_test_trajectory(self.structure, supercell=[3, 3, 3], total_time=8, silent=False) self.calculation = dynaphopy.Quasiparticle(trajectory) self.calculation.save_velocity_hdf5('test_gan.h5', save_trajectory=True)
def setUp(self): import phonopy print ('Using phonopy {}'.format(phonopy.__version__)) # structure = io.read_from_file_structure_poscar('Si_data/POSCAR') structure = io.read_from_file_structure_outcar('Si_data/OUTCAR') structure.set_primitive_matrix([[0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]]) structure.set_force_constants(get_force_constants_from_file(file_name='Si_data/FORCE_CONSTANTS', fc_supercell=[[2, 0, 0], [0, 2, 0], [0, 0, 2]])) trajectory = io.generate_test_trajectory(structure, supercell=[2, 2, 2], total_time=5, silent=False) self.calculation = dynaphopy.Quasiparticle(trajectory)
def setUp(self): self.structure = io.read_from_file_structure_poscar('GaN_data/POSCAR') self.structure.set_force_constants( parse_FORCE_CONSTANTS(filename='GaN_data/FORCE_CONSTANTS')) self.structure.set_primitive_matrix([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) self.structure.set_supercell_phonon([[3, 0, 0], [0, 3, 0], [0, 0, 3]]) if not os.path.exists('test_gan.h5'): trajectory = io.generate_test_trajectory(self.structure, supercell=[3, 3, 3], total_time=8, silent=False) self.calculation = dynaphopy.Quasiparticle(trajectory) self.calculation.save_velocity_hdf5('test_gan.h5', save_trajectory=True)
def setUp(self): import phonopy print('Using phonopy {}'.format(phonopy.__version__)) # structure = io.read_from_file_structure_poscar('Si_data/POSCAR') structure = io.read_from_file_structure_outcar('Si_data/OUTCAR') structure.set_primitive_matrix([[0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]]) structure.set_force_constants( get_force_constants_from_file(file_name='Si_data/FORCE_CONSTANTS', fc_supercell=[[2, 0, 0], [0, 2, 0], [0, 0, 2]])) trajectory = io.generate_test_trajectory(structure, supercell=[2, 2, 2], total_time=5, silent=False) self.calculation = dynaphopy.Quasiparticle(trajectory)
def _test_average(self): trajectory = io.generate_test_trajectory(self.structure, supercell=[1, 2, 3], total_time=5, silent=False, temperature=10) self.calculation = dynaphopy.Quasiparticle(trajectory) positions_average = self.calculation.dynamic.average_positions(to_unit_cell=True).real print(positions_average) reference = [[-1.94173041e+00, 2.81396066e+00, 5.39755913e+00], [ 1.08905801e+00, 1.40691916e+00, 5.39306914e+00], [ 5.09064600e+00, 1.40718064e+00, 2.68983555e+00], [ 2.05985758e+00, 1.39139630e-04, 2.69432553e+00], [ 1.56812170e+00, 1.40719153e+00, 1.56230533e+00], [ 2.55169805e+00, 1.40716376e+00, 3.82629282e+00], [ 4.59891013e+00, 1.50025412e-04, 1.55781535e+00], [-4.79090372e-01, 1.22256709e-04, 3.83078280e+00]] np.testing.assert_array_almost_equal(positions_average, reference, decimal=1)