File: phonopy_to_python.py

package info (click to toggle)
python-symfc 1.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,980 kB
  • sloc: python: 10,485; makefile: 12
file content (39 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""A script to convert the phonopy.yaml to raw data in python."""

import numpy as np
import phono3py
import phonopy

ph3 = phono3py.load("phono3py_params_Si-111-222-rd.yaml.xz", produce_fc=False)
ph = phonopy.load("phonopy_GaN_222_rd.yaml.xz", produce_fc=False)

print("    lattice = [")
for v in ph.supercell.cell:
    print("[", ", ".join([f"{x:.15f}" for x in v]), "],")
print("    ]")

print("    points = [")
for v in ph.supercell.scaled_positions:
    print("[", ", ".join([f"{x:.15f}" for x in v]), "],")
print("    ]")

print("    numbers = [")
for v in ph.supercell.numbers:
    print(f"{v},")
print("    ]")

print("    cell = SymfcAtoms(cell=lattice, scaled_positions=points, numbers=numbers)")


print(f"    N = {ph.displacements.shape[0]}")
print('    dfset = np.loadtxt(cwd / "dfset_Si_111_fc3_rd.xz")')
print("    d = dfset[:, :3].reshape(N, -1, 3)")
print("    f = dfset[:, 3:].reshape(N, -1, 3)")
print("    return cell, d, f")

d = ph.displacements.reshape(-1, 3)
f = ph.forces.reshape(-1, 3)

with open("dfset_Si_111_fc3_rd", "w") as w:
    for v in np.c_[(d, f)]:
        print(" ".join([f"{x:18.15f}" for x in v]), file=w)