Skip to content

Commit 943b27f

Browse files
committed
Added a function that allows to load the ensemble with one line
1 parent e2a96a4 commit 943b27f

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

Modules/Ensemble.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4230,7 +4230,57 @@ def w_to_a(self,w, T):
42304230
a[:] = np.sqrt((1.0 / np.tanh(0.5 * w * 315774.65221921849 / T)) / (2.0 * w))
42314231
return a
42324232

4233+
4234+
4235+
4236+
# ------------------------------------------------------------------------------
4237+
def load_ensemble_bin(directory, population, temperature, nqirr=-1):
4238+
"""
4239+
Load the ensemble from the given directory. This subroutine automatically initializes the ensemble
4240+
and avoids the hursle of having to define and initialize a dynamical matrix before loading the ensemble.
4241+
4242+
4243+
Parameters
4244+
----------
4245+
- directory : string
4246+
Path to the directory where the ensemble is located
4247+
- population : Int
4248+
The index of the ensemble
4249+
- temperature : Float
4250+
The temperature for the ensemble
4251+
- nqirr : Int
4252+
The number of irreducible points of the dynamical matrix.
4253+
If not provided (or negative), it is inferred from the files.
4254+
4255+
Returns
4256+
-------
4257+
- ensemble : Ensemble()
4258+
The Ensemble object.
4259+
"""
4260+
4261+
# Get the generated dyn
4262+
generated_name = os.path.join(directory, "dyn_gen_pop%d_" % population)
4263+
4264+
# Infer the nqirr if not provided
4265+
if nqirr < 0:
4266+
nqirr = len([x for x in os.listdir(directory) if x.startswith("dyn_gen_pop%d_" % population)])
4267+
if os.path.exists(generated_name + "0"):
4268+
nqirr -= 1
4269+
4270+
# Load the dynamical matrix
4271+
dyn = CC.Phonons.Phonons(generated_name, nqirr)
4272+
4273+
# Check if nqirr was correct
4274+
assert np.prod(dyn.GetSupercell()) == len(dyn.dynmats), "Error, the value of nqirr = {} is wrong. Check wether you specified the correct value.".format(nqirr)
4275+
4276+
ensemble = Ensemble(dyn, temperature)
4277+
ensemble.load_bin(directory, population)
4278+
4279+
return ensemble
4280+
4281+
42334282
#-------------------------------------------------------------------------------
4283+
42344284
def _wrapper_julia_get_upsilon_q(*args, **kwargs):
42354285
"""Worker function, just for testing"""
42364286
return julia.Main.get_upsilon_fourier(*args, **kwargs)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "mesonpy"
44

55
[project]
66
name = "python-sscha"
7-
version = "1.5.0"
7+
version = "1.5.1"
88
description = "Python implementation of the sscha code"
99
authors = [{name = "Lorenzo Monacelli"}] # Put here email
1010
readme = "README.md"

0 commit comments

Comments
 (0)