Skip to content

Commit 6a26ead

Browse files
committed
Added the possibility to avoid the dynamical matrix minimization
1 parent 95149ea commit 6a26ead

1 file changed

Lines changed: 45 additions & 39 deletions

File tree

Modules/SchaMinimizer.py

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def __init__(self, ensemble = None, root_representation = "normal",
177177
self.precond_dyn = True
178178

179179
self.minim_struct = True
180+
self.minim_dyn = True
180181

181182
# This is a debugging flag
182183
# If true the preconditioning of the original ensemble
@@ -318,10 +319,14 @@ def minimization_step(self, custom_function_gradient = None):
318319
#dyn_grad, err = self.ensemble.get_free_energy_gradient_respect_to_dyn()
319320
#dyn_grad, err = self.ensemble.get_fc_from_self_consistency(True, True)
320321
#dyn_grad, err = self.ensemble.get_fc_from_self_consistency(True, True)
321-
if self.precond_dyn:
322-
dyn_grad, err = self.ensemble.get_preconditioned_gradient(True, True, preconditioned=1)
322+
if self.minim_dyn:
323+
if self.precond_dyn:
324+
dyn_grad, err = self.ensemble.get_preconditioned_gradient(True, True, preconditioned=1)
325+
else:
326+
dyn_grad, err = self.ensemble.get_preconditioned_gradient(True, True, preconditioned=0)
323327
else:
324-
dyn_grad, err = self.ensemble.get_preconditioned_gradient(True, True, preconditioned=0)
328+
dyn_grad = np.zeros( (len(self.dyn.q_tot), 3 * self.dyn.structure.N_atoms, 3 * self.dyn.structure.N_atoms), dtype = np.complex128)
329+
err = np.zeros_like(dyn_grad)
325330

326331

327332
# Perform the symmetrization
@@ -330,45 +335,46 @@ def minimization_step(self, custom_function_gradient = None):
330335
# qe_sym.ImposeSumRule(err)
331336
# qe_sym.SymmetrizeDynQ(err, np.array([0,0,0]))
332337
t1 = time.time()
333-
if not self.neglect_symmetries:
334-
# Check if the symmetries must be applied in the supercell
335-
if self.use_spglib:
336-
# Check if we have a supercell
337-
supercell = self.dyn.GetSupercell()
338-
n_cell = np.prod(supercell)
339-
if n_cell == 1:
340-
# Only gamma, apply the symmetries
341-
qe_sym.ApplySymmetriesToV2(dyn_grad[0, :, :])
342-
343-
#qe_sym.ApplySymmetriesToV2(err)
344-
#CC.symmetries.CustomASR(err)
338+
if self.minim_dyn:
339+
if not self.neglect_symmetries:
340+
# Check if the symmetries must be applied in the supercell
341+
if self.use_spglib:
342+
# Check if we have a supercell
343+
supercell = self.dyn.GetSupercell()
344+
n_cell = np.prod(supercell)
345+
if n_cell == 1:
346+
# Only gamma, apply the symmetries
347+
qe_sym.ApplySymmetriesToV2(dyn_grad[0, :, :])
348+
349+
#qe_sym.ApplySymmetriesToV2(err)
350+
#CC.symmetries.CustomASR(err)
351+
else:
352+
# We have a supercell, we must generate the dynamical matrix in the supercell
353+
super_structure = self.dyn.structure.generate_supercell(supercell)
354+
fc_supercell = CC.Phonons.GetSupercellFCFromDyn(dyn_grad, np.array(self.dyn.q_tot), \
355+
self.dyn.structure, super_structure)
356+
357+
# Lets generate a new symmetries for the supercell
358+
qe_sym_supcell = CC.symmetries.QE_Symmetry(super_structure)
359+
qe_sym_supcell.SetupFromSPGLIB()
360+
361+
# Apply the symmetries to the fc_supercell matrix
362+
qe_sym_supcell.ApplySymmetriesToV2(fc_supercell)
363+
364+
# Convert back to Q space
365+
dyn_grad = CC.Phonons.GetDynQFromFCSupercell(fc_supercell, np.array(self.dyn.q_tot), \
366+
self.dyn.structure, super_structure)
367+
368+
# Apply the sum rule at gamma
369+
CC.symmetries.CustomASR(dyn_grad[0,:,:])
345370
else:
346-
# We have a supercell, we must generate the dynamical matrix in the supercell
347-
super_structure = self.dyn.structure.generate_supercell(supercell)
348-
fc_supercell = CC.Phonons.GetSupercellFCFromDyn(dyn_grad, np.array(self.dyn.q_tot), \
349-
self.dyn.structure, super_structure)
350-
351-
# Lets generate a new symmetries for the supercell
352-
qe_sym_supcell = CC.symmetries.QE_Symmetry(super_structure)
353-
qe_sym_supcell.SetupFromSPGLIB()
354-
355-
# Apply the symmetries to the fc_supercell matrix
356-
qe_sym_supcell.ApplySymmetriesToV2(fc_supercell)
357-
358-
# Convert back to Q space
359-
dyn_grad = CC.Phonons.GetDynQFromFCSupercell(fc_supercell, np.array(self.dyn.q_tot), \
360-
self.dyn.structure, super_structure)
371+
qe_sym.SymmetrizeFCQ(dyn_grad, np.array(self.dyn.q_stars), asr = "custom")
372+
#qe_sym.SymmetrizeFCQ(err, np.array(self.dyn.q_stars), asr = "custom")
361373

362-
# Apply the sum rule at gamma
363-
CC.symmetries.CustomASR(dyn_grad[0,:,:])
374+
# Just divide the error by the square root the number of symmetries
375+
err /= np.sqrt(qe_sym.QE_nsym * np.prod(self.ensemble.supercell))
364376
else:
365-
qe_sym.SymmetrizeFCQ(dyn_grad, np.array(self.dyn.q_stars), asr = "custom")
366-
#qe_sym.SymmetrizeFCQ(err, np.array(self.dyn.q_stars), asr = "custom")
367-
368-
# Just divide the error by the square root the number of symmetries
369-
err /= np.sqrt(qe_sym.QE_nsym * np.prod(self.ensemble.supercell))
370-
else:
371-
CC.symmetries.CustomASR(dyn_grad[0, :,:])
377+
CC.symmetries.CustomASR(dyn_grad[0, :,:])
372378
t2 = time.time()
373379
print ("Time elapsed to symmetrize the gradient:", t2 - t1, "s")
374380

0 commit comments

Comments
 (0)