示例#1
0
    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)
示例#2
0
    def test_q_points_data(self):

        import yaml

        trajectory = io.initialize_from_hdf5_file('test_gan.h5',
                                                  self.structure,
                                                  read_trajectory=True,
                                                  initial_cut=1,
                                                  final_cut=3000,
                                                  memmap=True)
        self.calculation = dynaphopy.Quasiparticle(trajectory)

        self.calculation.select_power_spectra_algorithm(2)
        self.calculation.write_atomic_displacements([0, 0, 1],
                                                    'atomic_displacements.dat')
        self.calculation.write_quasiparticles_data(
            filename='quasiparticles_data.yaml')
        self.calculation.write_renormalized_phonon_dispersion_bands(
            filename='bands_data.yaml')

        reference = np.loadtxt('GaN_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.load(stream)

            with open('GaN_data/' + file) as stream:
                reference = yaml.load(stream)

            for dict_data, dict_reference in zip(data, reference):
                assertDictAlmostEqual(dict_data, dict_reference, decimal=1)
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    def test_force_constants_self_consistency(self):
        trajectory = io.initialize_from_hdf5_file('test_gan.h5',
                                                  self.structure,
                                                  read_trajectory=False,
                                                  initial_cut=1,
                                                  final_cut=3000,
                                                  memmap=True)
        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=1.e-2), True)
示例#6
0
    def test_thermal_properties(self):
        trajectory = io.initialize_from_hdf5_file('test_gan.h5',
                                                  self.structure,
                                                  read_trajectory=False,
                                                  initial_cut=1000,
                                                  final_cut=4000,
                                                  memmap=False)
        self.calculation = dynaphopy.Quasiparticle(trajectory)
        self.calculation.select_power_spectra_algorithm(2)
        harmonic = np.array(self.calculation.get_thermal_properties())
        anharmonic = np.array(
            self.calculation.get_thermal_properties(
                force_constants=self.calculation.
                get_renormalized_force_constants()))

        print(harmonic)
        print(anharmonic)
        maximum = np.max((harmonic - anharmonic)**2 / harmonic)
        print('maximum: {}'.format(maximum))
        self.assertLess(maximum, 0.4)
示例#7
0
    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)
示例#8
0
    def test_adp(self):
        trajectory = io.initialize_from_hdf5_file('test_gan.h5',
                                                  self.structure,
                                                  read_trajectory=True,
                                                  initial_cut=1,
                                                  final_cut=4000,
                                                  memmap=False)

        self.calculation = dynaphopy.Quasiparticle(trajectory)
        self.calculation.get_anisotropic_displacement_parameters()

        positions_average = self.calculation.dynamic.average_positions(
            to_unit_cell=True).real
        positions = self.structure.get_positions()
        difference = positions - positions_average

        norm = np.linalg.norm(self.structure.get_cell(), axis=1)
        difference = np.mod(difference, norm)
        multiples = np.divide(difference, norm)

        self.assertLess(np.max(np.abs(multiples - np.round(multiples))), 1e-4)
示例#9
0
    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)
示例#10
0
############################### READING TRAJECTORY FILES #####################################
# 4. Set the location of OUTCAR/LAMMPS file containing the Molecular Dynamics trajectory

# trajectory = parsers.read_vasp_trajectory('/home/abel/VASP/Si/Si-FINAL3/Si_0.5_600/No1/OUTCAR', structure, initial_cut=10000, end_cut=60000)
# or
trajectory = parsers.read_VASP_XDATCAR(
    '/home/abel/VASP/Si/Si-FINAL3/Si_0.5_800/No1/XDATCAR',
    structure,
    initial_cut=10000,
    end_cut=40000,
    time_step=0.0005)
# or
#trajectory = parsers.read_lammps_trajectory('/home/abel/LAMMPS/Si/Si_400.lammpstrj', structure, initial_cut=10000, end_cut=12000, time_step=0.001)

quasiparticle = dynaphopy.Quasiparticle(trajectory)

############################# DEFINE CALCULATION PARAMETERS ##################################
# 5. All this options are totally optional and independent, just comment or uncomment the desired ones
# Other option not yet shown in this example script may be available (take a look at dynaphopt/__init__.py)

# 5a. Set the power spectrum algorithm
# 0: Direct Fourier transform (Not recommended)
# 1: Maximum entropy method (MEM)
# 2; numpy FFT
# 3: FFTW (Needs FFTW installed in the system)
# 4: CUDA (Needs cuda_functions installed in the system)
quasiparticle.select_power_spectra_algorithm(1)  # MEM
quasiparticle.set_number_of_mem_coefficients(
    1000)  # Only is used if MEM is selected
示例#11
0
                    curses.endwin()

                # SUB OPT 8 : # Frequency range
                if x2 == ord('8'):
                    frequency_limits = np.array([float(Fraction(s)) for s in
                                                 get_param(screen, "Insert frequency range (min, max)").split(',')])
                    print(frequency_limits)
                    calculation.set_frequency_limits(frequency_limits)
                    curses.endwin()

    curses.endwin()

# Testing
if __name__ == 'test_gui.py':
    import dynaphopy as controller
    import dynaphopy.functions.iofunctions as reading

    # Get data from input file
    input_parameters = reading.read_parameters_from_input_file(sys.argv[1])

    structure = reading.read_from_file_structure_outcar(input_parameters['structure_file_name'])
    structure.set_force_set( file_IO.parse_FORCE_SETS(filename=input_parameters['force_constants_file_name']))
    structure.set_primitive_matrix(input_parameters['primitive_matrix'])
    structure.set_supercell_phonon(input_parameters['supercell_matrix'])

    trajectory_file_name = sys.argv[2]

    trajectory = reading.read_from_file_trajectory(trajectory_file_name,structure,last_steps=5000)

    calculation = controller.Quasiparticle(trajectory)
    calculation.set_band_ranges(input_parameters['bands'])