abelcarreras / DynaPhoPy

Phonon anharmonicity analysis from molecular dynamics
http://abelcarreras.github.io/DynaPhoPy/
MIT License
113 stars 51 forks source link

How to use DynaPhoPy as a python module? #5

Closed gooaah closed 6 years ago

gooaah commented 6 years ago

I have run MD by ASE. How to analyse it by DynaPhoPy?

abelcarreras commented 6 years ago

Check API example script: https://github.com/abelcarreras/DynaPhoPy/blob/master/examples/api_scripts/script_silicon.py

The important point is that you have to create dynaphopy structure and trajectory objects from your ASE MD data. For structure object you can check read_from_file_structure_poscar function:

https://github.com/abelcarreras/DynaPhoPy/blob/51e99422228e6be84830d659b88a0ca904d9136f/dynaphopy/interface/iofile/__init__.py#L277

For trajectory object you can check for instance read_VASP_XDATCAR function: https://github.com/abelcarreras/DynaPhoPy/blob/51e99422228e6be84830d659b88a0ca904d9136f/dynaphopy/interface/iofile/trajectory_parsers.py#L342

Basically:

1)

import dynaphopy.atoms as atoms
structure = atoms.Structure(cell=latticevectors,  
                            scaled_positions=scaled_positions,
                            atomic_elements=atomic_types)

where latticevectors is a 3x3 numpy array with the unit cell lattice vectors in rows, scaled_positions is a Nax3 numpy array with the coordinates of the atoms in fractional coordinates, and atomic_types is a list with the atomic symbols of atoms

2)

import dynaphopy.dynamics as dyn
trajectory =  dyn.Dynamics(structure=structure,
                           scaled_trajectory=trajectory_coordinates,
                           time=time,
                           supercell=super_cell)

where structure is the previously generated structure object, trajectory_coordinates is a NsxNax3 numpy array containing the coordinates of all the atoms at each time step in fractional coordinates, time is a Nsx1 list with the time corresponding at each step (in picoseconds) and super_cell is a 3x3 numpy array that defines the MD supercell respect to the unitcell (in general it is diagonal) :

MDCell = super_cell * UnitCell