Skip to content

Commit 1c8e2c2

Browse files
committed
modification in qha_aproximation.py.
1 parent dc3d83f commit 1c8e2c2

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

abipy/dfpt/qha_aproximation.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,3 +1918,54 @@ def get_thermodynamic_properties(self, tstart=0, tstop=1000, num=101):
19181918
zpe[i] = d.zero_point_energy
19191919

19201920
return dict2namedtuple(tmesh=tmesh, cv=cv, free_energy=free_energy, entropy=entropy, zpe=zpe)
1921+
#=======================================================================================================
1922+
@classmethod
1923+
def from_files_app_ddb(cls, ddb_paths, phdos_paths):
1924+
"""
1925+
Creates an instance of QHA from a list of GSR files and a list of PHDOS.nc files.
1926+
The list should have the same size and the volumes should match.
1927+
1928+
Args:
1929+
ddb_paths: list of paths to DDB files.
1930+
phdos_paths: list of paths to PHDOS.nc files.
1931+
1932+
Returns: A new instance of QHA
1933+
"""
1934+
energies = []
1935+
structures = []
1936+
pressures = []
1937+
for gp in ddb_paths:
1938+
with DdbFile.from_file(gp) as g:
1939+
energies.append(g.total_energy)
1940+
structures.append(g.structure)
1941+
#pressures.append(g.pressure)
1942+
1943+
#doses = [PhononDos.as_phdos(dp) for dp in phdos_paths]
1944+
1945+
doses = []
1946+
structures_from_phdos = []
1947+
for path in phdos_paths:
1948+
with PhdosFile(path) as p:
1949+
doses.append(p.phdos)
1950+
structures_from_phdos.append(p.structure)
1951+
1952+
# cls._check_volumes_id(structures, structures_from_phdos)
1953+
vols1 = [s.volume for s in structures]
1954+
vols2 = [s.volume for s in structures_from_phdos]
1955+
dv=np.zeros((len(vols2)-1))
1956+
for j in range(len(vols2)-1):
1957+
dv[j]=vols2[j+1]-vols2[j]
1958+
tolerance = 1e-3
1959+
if (len(vols2)!=2):
1960+
max_difference = np.max(np.abs(dv - dv[0]))
1961+
if max_difference > tolerance:
1962+
raise RuntimeError("Expecting an equal volume change for structures from PDOS." )
1963+
1964+
index_list = [i for v2 in vols2 for i, v1 in enumerate(vols1) if abs(v2 - v1) < 1e-3]
1965+
if len(index_list) != len(vols2):
1966+
raise RuntimeError("Expecting the ground state files for all PDOS files!")
1967+
if len(index_list) not in (2, 3, 5):
1968+
raise RuntimeError("Expecting just 2, 3, or 5 PDOS files in the approximation method.")
1969+
1970+
return cls(structures,structures_from_phdos,index_list, doses, energies , pressures)
1971+

0 commit comments

Comments
 (0)