DynaPhoPy

repository·master·Indexed 40 days ago

https://github.com/abelcarreras/dynaphopy

A tool for calculating crystal microscopic anharmonic properties, such as phonon frequency shifts and linewidths, from molecular dynamics data. It utilizes normal-mode-decomposition and quasiparticle theory, providing interfaces for MD outputs from VASP and LAMMPS and integrating with PHONOPY for harmonic phonon modes. It includes capabilities for calculating renormalized force constants, thermal properties (free energy, entropy, heat capacity), and power spectra.

Tokens
9.5K
Snippets
51
Records
60
Agent score
50%

What's inside DynaPhoPy

  1. What is DynaPhoPy?

    master

    DynaPhoPy is software designed to calculate crystal microscopic anharmonic properties from molecular dynamics (MD) using the normal-mode-decomposition technique.

    Key Capabilities:

    • Calculates phonon frequency shifts and linewidths.
    • Calculates renormalized force constants and thermal properties using quasiparticle theory.
    • Provides interfaces for MD outputs from VASP and LAMMPS.
    • Utilizes PHONOPY to obtain harmonic phonon modes.
  2. Install DynaPhoPy from source

    master

    To install from source, you must have a C compiler available. First, install the necessary dependencies from requirements.txt, then run the setup.py script.

    Requirements:

    • Python 3.5 or higher
    • Phonopy 2.0 or higher
    • Matplotlib
    • Scipy
    • h5py
    • pyYAML
    • (optional) pyFFTW
    • (optional) cuda_functions
    pip install -r requirements.txt --user
    python setup.py install --user
  3. Calculate anharmonic properties using the LAMMPS interface

    master

    To calculate anharmonic properties of a material (like GaN) using the LAMMPS interface, you must have the LAMMPS Python interface installed on your system. The workflow involves three main steps:

    1. Prepare a LAMMPS input script: This script must define the crystal unit cell and atom positions (matching your POSCAR file).
    2. Calculate harmonic force constants: Use a tool like phonoLAMMPS to obtain these constants.
    3. Run DynaPhoPy with the --run_lammps flag: Execute the calculation by providing the input script and MD parameters.

    Important Notes:

    • The LAMMPS interface performs calculations directly via MD without writing intermediate data to files.
    • A full MD simulation is performed every time dynaphopy is executed. To avoid redundant calculations, use option flags or interactive mode to calculate multiple properties in a single run.
    • To save the trajectory for later analysis, use the --save_data option to store it in HDF5 format.
    dynaphopy input_dynaphopy --run_lammps in.lammps 50 0.001 20 --dim 6 6 6 -i
  4. Analyze power spectrum and phonon properties with Quasiparticle

    master

    The Quasiparticle class provides a high-level interface for analyzing molecular dynamics (MD) trajectories to extract phonon-related properties, including power spectra, renormalized force constants, and thermal properties.

    Key analysis workflows include:

    • Power Spectrum Calculation: Use get_power_spectrum_full() to get the full power spectrum, or get_power_spectrum_phonon() for projections onto specific phonon modes.
    • Renormalized Force Constants: Calculate renormalized force constants using get_renormalized_force_constants(), which relies on get_commensurate_points_data() to identify relevant Q-points.
    • Thermal Properties: Compute thermodynamic quantities like free energy, entropy, and heat capacity ($C_v$) using get_thermal_properties() or display_thermal_properties().
    • Visualization: Plot trajectories, velocities, energy, and power spectra using various plot_* methods.
  5. Manage global configuration with the Parameters class

    master

    The Parameters class is a Singleton used to manage all default parameters for DynaPhoPy. Because it implements the Singleton pattern, any instance of Parameters created will return the same object, ensuring a single source of truth for configuration across your application.

    You can initialize it with custom values or update existing values using its properties or by passing a dictionary via get_data_from_dict.

    from dynaphopy.parameters import Parameters
    
    # Initialize with specific settings
    params = Parameters(silent=True, power_spectra_algorithm=2)
    
    # Since it is a Singleton, subsequent calls return the same instance
    params_again = Parameters()
    print(params is params_again)  # True
    
    # Update via properties
    params.spectrum_resolution = 0.01
    
    # Update multiple values from a dictionary
    config_dict = {
        "spectrum_resolution": 0.02,
        "use_NAC": True
    }
    params.get_data_from_dict(config_dict)
  6. Optimization: Using atomic velocities for long MD simulations

    master

    When performing long MD simulations, you can configure LAMMPS to store atomic velocities instead of positions (e.g., using an input file like in.md_vel).

    Benefits:

    • Memory Efficiency: Reading velocities can save RAM during the DynaPhoPy calculation.
    • Accuracy: May increase the accuracy of the calculation.

    This is the preferred approach for large-scale or long-duration MD trajectories.

  7. Generate MD initial crystal structure for VASP

    master

    To prepare a VASP MD simulation, use the dynaphopy input_si command with the -c_poscar flag to specify your unit cell POSCAR file and the --dim flag to define the supercell dimensions. This generates the necessary initial structure for the MD run.

    dynaphopy input_si -c_poscar POSCAR --dim 2 2 2
  8. Compute phonon anharmonic properties via CLI

    master

    Once you have completed an MD simulation (e.g., using LAMMPS), you can compute anharmonic properties such as phonon frequency shifts, linewidths, renormalized force constants, and thermal properties using the dynaphopy input_gan command.

    Key flags:

    • -ts <value>: Time step.
    • -sdata: Output data.
    • -thm: Compute thermal properties.
    • --normalize_dos: Normalize the Density of States (DOS).
    • -sfc <name>: Specify the output filename for renormalized force constants.

    Example command:

    dynaphopy input_gan gan_2000_test.lammpstrj -ts 0.001 -sdata -thm --normalize_dos -sfc renormalized_fc
  9. Initialize the Dynamics class

    master

    The Dynamics class is the central object for managing molecular dynamics data. It can be initialized with a structure, trajectory, velocities, energy, time, and supercell information.

    If memmap=True is passed, the class will use memory-mapped files for large datasets, utilizing the directory specified by the DYNAPHOPY_TEMPDIR environment variable. If this environment variable is not set, it defaults to an empty directory.

    Note: If you initialize without a structure, a warning will be issued.

    from dynaphopy.dynamics import Dynamics
    
    dynamics = Dynamics(
        structure=my_structure,
        trajectory=my_trajectory,
        velocity=my_velocity,
        time=my_time,
        supercell=my_supercell,
        memmap=False
    )
  10. Generate LAMMPS initial crystal structure from POSCAR

    master

    To prepare a LAMMPS simulation, you can generate the initial crystal structure from a POSCAR type file using the dynaphopy input_gan command. Use the -c_lammps flag to specify the output data file and --dim to define the supercell dimensions.

    Example for a 3x3x3 supercell:

    dynaphopy input_gan -c_lammps data.gan --dim 3 3 3