Skip to content

Commit cd6779d

Browse files
committed
Merge branch 'master' of https://github.com/SSCHAcode/python-sscha into new/flare-interface
2 parents 4aa3954 + ae48d6e commit cd6779d

8 files changed

Lines changed: 364 additions & 10 deletions

File tree

Modules/Ensemble.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4334,7 +4334,57 @@ def set_otf(
43344334
self.train_hyps = train_hyps
43354335

43364336

4337+
4338+
4339+
4340+
# ------------------------------------------------------------------------------
4341+
def load_ensemble_bin(directory, population, temperature, nqirr=-1):
4342+
"""
4343+
Load the ensemble from the given directory. This subroutine automatically initializes the ensemble
4344+
and avoids the hursle of having to define and initialize a dynamical matrix before loading the ensemble.
4345+
4346+
4347+
Parameters
4348+
----------
4349+
- directory : string
4350+
Path to the directory where the ensemble is located
4351+
- population : Int
4352+
The index of the ensemble
4353+
- temperature : Float
4354+
The temperature for the ensemble
4355+
- nqirr : Int
4356+
The number of irreducible points of the dynamical matrix.
4357+
If not provided (or negative), it is inferred from the files.
4358+
4359+
Returns
4360+
-------
4361+
- ensemble : Ensemble()
4362+
The Ensemble object.
4363+
"""
4364+
4365+
# Get the generated dyn
4366+
generated_name = os.path.join(directory, "dyn_gen_pop%d_" % population)
4367+
4368+
# Infer the nqirr if not provided
4369+
if nqirr < 0:
4370+
nqirr = len([x for x in os.listdir(directory) if x.startswith("dyn_gen_pop%d_" % population)])
4371+
if os.path.exists(generated_name + "0"):
4372+
nqirr -= 1
4373+
4374+
# Load the dynamical matrix
4375+
dyn = CC.Phonons.Phonons(generated_name, nqirr)
4376+
4377+
# Check if nqirr was correct
4378+
assert np.prod(dyn.GetSupercell()) == len(dyn.dynmats), "Error, the value of nqirr = {} is wrong. Check wether you specified the correct value.".format(nqirr)
4379+
4380+
ensemble = Ensemble(dyn, temperature)
4381+
ensemble.load_bin(directory, population)
4382+
4383+
return ensemble
4384+
4385+
43374386
#-------------------------------------------------------------------------------
4387+
43384388
def _wrapper_julia_get_upsilon_q(*args, **kwargs):
43394389
"""Worker function, just for testing"""
43404390
return julia.Main.get_upsilon_fourier(*args, **kwargs)

Modules/Minimizer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ def run_step(self, gradient, kl_new):
224224
# Enlarge the step
225225
if not self.fixed_step:
226226
self.step *= self.increment_step
227+
228+
# Perform the minimization step for new direction
229+
self.current_x = self.old_x - self.step * self.direction
227230
else:
228231
# Proceed with the line minimization
229232

@@ -243,14 +246,16 @@ def run_step(self, gradient, kl_new):
243246
print("Step too large (scalar = {} | kl_ratio = {}), reducing to {}".format(scalar, kl_ratio, self.step))
244247
#print("Direction: ", self.direction)
245248
#print("Gradient: ", gradient)
249+
250+
# Try again with reduced step
251+
self.current_x = self.old_x - self.step * self.direction
246252
else:
247253
# The step is good, therefore next step perform a new direction
248254
self.new_direction = True
249255
if self.verbose:
250256
print("Good step found with {}, try increment".format(self.step))
251-
252-
# Perform the minimiziation step
253-
self.current_x = self.old_x - self.step * self.direction
257+
# DO NOT update current_x - we accept the current position
258+
# (current_x was already updated in the previous step)
254259

255260

256261
def update_dyn(self, new_kl_ratio, dyn_gradient, structure_gradient = None):

Modules/SchaMinimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,11 @@ def print_info(self):
964964
print (" supercell size = ", " ".join([str(x) for x in self.ensemble.supercell]))
965965

966966
# Get the current frequencies
967-
w, pols = self.dyn.GenerateSupercellDyn(self.ensemble.supercell).DyagDinQ(0)
967+
w, pols = self.dyn.DiagonalizeSupercell()#self.dyn.GenerateSupercellDyn(self.ensemble.supercell).DyagDinQ(0)
968968
w *= __RyToCm__
969969

970970
# Get the starting frequencies
971-
w0, p0 = self.ensemble.dyn_0.GenerateSupercellDyn(self.ensemble.supercell).DyagDinQ(0)
971+
w0, p0 = self.ensemble.dyn_0.DiagonalizeSupercell()
972972
w0 *= __RyToCm__
973973

974974
print ()

Modules/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"""
66

77

8-
__all__ = ["Ensemble", "SchaMinimizer"]
8+
__all__ = ["Ensemble", "SchaMinimizer", "cli"]

0 commit comments

Comments
 (0)