Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Eigenvector normalization problem in Raman workflow #777

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions atomate/vasp/firetasks/parse_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,11 @@ class RamanTensorToDb(FiretaskBase):
def run_task(self, fw_spec):
nm_eigenvecs = np.array(fw_spec["normalmodes"]["eigenvecs"])
nm_eigenvals = np.array(fw_spec["normalmodes"]["eigenvals"])
nm_norms = np.linalg.norm(nm_eigenvecs, axis=2)

structure = fw_spec["normalmodes"]["structure"]
masses = np.array([site.specie.data["Atomic mass"] for site in structure])
nm_norms = nm_norms / np.sqrt(
masses
) # eigenvectors in vasprun.xml are not divided by sqrt(M_i)

# eigenvectors in vasprun.xml are not divided by sqrt(M_i)
# To get the actual eigenvals, the values read from vasprun.xml must be multiplied by -1.
# frequency_i = sqrt(-e_i)
# To convert the frequency to THZ: multiply sqrt(-e_i) by 15.633
Expand Down Expand Up @@ -507,14 +506,16 @@ def run_task(self, fw_spec):

# raman tensor = finite difference derivative of epsilon wrt displacement.
raman_tensor_dict = {}
scale = np.sqrt(structure.volume / 2.0) / 4.0 / np.pi
scale = structure.volume / 4.0 / np.pi
for k, v in modes_eps_dict.items():
nm_eigenvec_sqm = nm_eigenvecs[k, :, :] / np.sqrt(masses[:, np.newaxis])
nm_norms = np.linalg.norm(nm_eigenvec_sqm)
raman_tensor = (np.array(v[0][1]) - np.array(v[1][1])) / (v[0][0] - v[1][0])
# frequency in cm^-1
omega = nm_frequencies[k]
if nm_eigenvals[k] > 0:
logger.warning(f"Mode: {k} is UNSTABLE. Freq(cm^-1) = {-omega}")
raman_tensor = scale * raman_tensor * np.sum(nm_norms[k]) / np.sqrt(omega)
raman_tensor = scale * raman_tensor * nm_norms
raman_tensor_dict[str(k)] = raman_tensor.tolist()

d["raman_tensor"] = raman_tensor_dict
Expand Down
10 changes: 4 additions & 6 deletions atomate/vasp/firetasks/write_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,12 @@ def run_task(self, fw_spec):
mode = self["mode"]
disp = self["displacement"]
structure = Structure.from_file("POSCAR")
masses = np.array([site.specie.data['Atomic mass'] for site in structure])
nm_eigenvecs = np.array(fw_spec["normalmodes"]["eigenvecs"])
nm_norms = np.linalg.norm(nm_eigenvecs, axis=2)
nm_eigenvec_sqm = nm_eigenvecs[mode, :, :] / np.sqrt(masses[:, np.newaxis])
nm_norms = np.linalg.norm(nm_eigenvec_sqm)
nm_displacement = (nm_eigenvec_sqm * disp / nm_norms)

# displace the sites along the given normal mode: displacement vector
# for each site = normalized eigen vector * amount of displacement
nm_displacement = (
nm_eigenvecs[mode, :, :] * disp / nm_norms[mode, :, np.newaxis]
)
for i, vec in enumerate(nm_displacement):
structure.translate_sites(i, vec, frac_coords=False)

Expand Down