Skip to content

Commit 4b9fb8e

Browse files
committed
Added the possibility to constrain a single frequency
1 parent e761797 commit 4b9fb8e

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

Modules/Ensemble.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def __init__(self, dyn0, T0, supercell = None):
128128

129129
self.sscha_energies = []
130130
self.sscha_forces = []
131+
132+
# If True the frequency smaller than CC.Phonons.__EPSILON_W__ are ignored
133+
self.ignore_small_w = False
131134

132135
# The original dynamical matrix used to generate the ensemble
133136
self.dyn_0 = dyn0.Copy()
@@ -924,7 +927,7 @@ class is created.
924927

925928
structures = []
926929
if evenodd:
927-
structs = self.dyn_0.ExtractRandomStructures(N // 2, self.T0, project_on_vectors = project_on_modes)
930+
structs = self.dyn_0.ExtractRandomStructures(N // 2, self.T0, project_on_vectors = project_on_modes, lock_low_w = self.ignore_small_w)
928931

929932

930933

@@ -935,7 +938,7 @@ class is created.
935938
new_s.coords = super_struct.coords - new_s.get_displacement(super_struct)
936939
structures.append(new_s)
937940
else:
938-
structures = self.dyn_0.ExtractRandomStructures(N, self.T0, project_on_vectors = project_on_modes)
941+
structures = self.dyn_0.ExtractRandomStructures(N, self.T0, project_on_vectors = project_on_modes, lock_low_w = self.ignore_small_w)
939942

940943

941944
# Enforce all the processors to share the same structures
@@ -1178,7 +1181,11 @@ def update_weights(self, new_dynamical_matrix, newT, update_q = False):
11781181
w, pols = self.dyn_0.DiagonalizeSupercell()#super_dyn.DyagDinQ(0)
11791182

11801183
# Exclude translations
1181-
trans_original = CC.Methods.get_translations(pols, super_struct0.get_masses_array())
1184+
if not self.ignore_small_w:
1185+
trans_original = CC.Methods.get_translations(pols, super_struct0.get_masses_array())
1186+
else:
1187+
trans_original = np.abs(w) < CC.Phonons.__EPSILON_W__
1188+
11821189
w = w[~trans_original]
11831190

11841191
# Convert from Ry to Ha and in fortran double precision
@@ -1193,10 +1200,19 @@ def update_weights(self, new_dynamical_matrix, newT, update_q = False):
11931200

11941201
w, pols = new_dynamical_matrix.DiagonalizeSupercell()#new_super_dyn.DyagDinQ(0)
11951202

1196-
trans_mask = CC.Methods.get_translations(pols, super_structure.get_masses_array())
1203+
if not self.ignore_small_w:
1204+
trans_mask = CC.Methods.get_translations(pols, super_structure.get_masses_array())
1205+
else:
1206+
trans_mask = np.abs(w) < CC.Phonons.__EPSILON_W__
1207+
11971208

11981209
# Check if the new dynamical matrix satisfies the sum rule
1199-
if (np.sum(trans_mask.astype(int)) != 3) or (np.sum(trans_original.astype(int)) != 3):
1210+
violating_sum_rule = (np.sum(trans_mask.astype(int)) != 3) or (np.sum(trans_original.astype(int)) != 3)
1211+
if self.ignore_small_w:
1212+
violating_sum_rule = np.sum(trans_mask.astype(int)) != np.sum(trans_original.astype(int))
1213+
1214+
1215+
if violating_sum_rule:
12001216
ERR_MSG = """
12011217
ERROR WHILE UPDATING THE WEIGHTS
12021218
@@ -2821,6 +2837,7 @@ def split(self, split_mask):
28212837
ens.energies[:] = self.energies[split_mask]
28222838
ens.forces[:, :, :] = self.forces[split_mask, :, :]
28232839
ens.has_stress = self.has_stress
2840+
ens.ignore_small_w = self.ignore_small_w
28242841
if self.has_stress:
28252842
ens.stresses[:, :, :] = self.stresses[split_mask, :, :]
28262843

Modules/SchaMinimizer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,10 @@ def check_imaginary_frequencies(self):
12791279
ss = self.dyn.structure.generate_supercell(self.dyn.GetSupercell())
12801280

12811281
# Get translations
1282-
trans_mask = ~CC.Methods.get_translations(pols, ss.get_masses_array())
1282+
if not self.ensemble.ignore_small_w:
1283+
trans_mask = ~CC.Methods.get_translations(pols, ss.get_masses_array())
1284+
else:
1285+
trans_mask = np.abs(w) > CC.Phonons.__EPSILON_W__
12831286

12841287
current_n_trans = np.sum((~trans_mask).astype(int))
12851288

0 commit comments

Comments
 (0)