epc_ml_data / 2_training /forces /_phonopy_launcher.py
Koulb's picture
Add files using upload-large-folder tool
e9e349d verified
import json, numpy as np
import phonopy
from phonopy.structure.atoms import PhonopyAtoms
from nequip.ase import NequIPCalculator
from ase import Atoms
from ase.io import read as ase_read
uc = ase_read('/home/apolyukhin/Development/epc_ml/example/diamond/1_data_prepare/scf.in', format='espresso-in')
calc = NequIPCalculator.from_compiled_model(
'/home/apolyukhin/Development/epc_ml/example/diamond/2_training/forces/diamond_ase_ref.nequip.pt2', device='cuda', chemical_species_to_atom_type_map=True)
sc_matrix = [[4, 0, 0], [0, 4, 0], [0, 0, 4]]
ph = phonopy.Phonopy(
unitcell=PhonopyAtoms(
symbols=uc.get_chemical_symbols(),
cell=uc.get_cell(),
scaled_positions=uc.get_scaled_positions(),
),
supercell_matrix=sc_matrix,
primitive_matrix='auto',
)
ph.generate_displacements(distance=0.01)
supercells = ph.supercells_with_displacements
print(f' Phonopy: {len(supercells)} displacements ({len(supercells[0])} atoms each)')
forces_list = []
for i, sc in enumerate(supercells):
a = Atoms(symbols=sc.get_chemical_symbols(),
positions=sc.get_positions(),
cell=sc.get_cell(), pbc=True)
a.calc = calc
f = a.get_forces()
forces_list.append(f)
if (i + 1) % 5 == 0 or i == 0:
print(f' [{i+1}/{len(supercells)}] |F|max={np.abs(f).max():.4f} eV/A')
ph.forces = forces_list
ph.produce_force_constants()
ph.run_qpoints([[0, 0, 0]], with_eigenvectors=False)
freqs_thz = ph.get_qpoints_dict()['frequencies'][0].tolist()
with open('/home/apolyukhin/Development/epc_ml/example/diamond/2_training/forces/_phonopy_freqs_ref.json', 'w') as fp:
json.dump({'freqs_thz': freqs_thz}, fp)
print(f' Gamma freqs written to /home/apolyukhin/Development/epc_ml/example/diamond/2_training/forces/_phonopy_freqs_ref.json')