Skip to content

Commit 0e10f43

Browse files
committed
feature: Add (broken) functions to extract progress
feature: Add (broken) functions to extract current progress of each job, e.g. "Job pos_004 is on restart 4 and is relaxing ions only"
1 parent 9823530 commit 0e10f43

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

src/pylada/vasp/extract/base.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,103 @@ def fftFrac(self):
19541954
absolute path of the executable.
19551955
"""
19561956
return round(self.fftTime / self.compTime, 4)
1957+
1958+
def _count_dirs(self, path):
1959+
import os
1960+
folders = 0
1961+
for _, dirnames, _ in os.walk(path):
1962+
# ^ this idiom means "we won't be using this value"
1963+
# files += len(filenames)
1964+
folders += len(dirnames)
1965+
return folders
1966+
1967+
@property
1968+
def _count_steps(self, outcar_path):
1969+
import re
1970+
with open(outcar_path, 'r') as file:
1971+
ionic_steps = 0
1972+
elec_steps = 0
1973+
lines = file.readlines()
1974+
lines.reverse()
1975+
for line in lines:
1976+
if 'Iteration' in line:
1977+
line = re.split('\s+|\(|\)', line)
1978+
ionic_steps = line[1]
1979+
elec_steps = line[2]
1980+
return ionic_steps, elec_steps
1981+
1982+
@property
1983+
def _count_dirs_steps(self, path=None):
1984+
import os
1985+
dirs = os.listdir(path).sort()
1986+
starts = len(dirs)
1987+
current_outcar_path = os.path.join(path, dirs[-1], 'OUTCAR')
1988+
ionic_steps, elec_steps = self._count_steps(current_outcar_path)
1989+
return starts, ionic_steps, elec_steps
1990+
1991+
@property
1992+
def progress(self):
1993+
import os
1994+
progress_dict = {}
1995+
if self.success:
1996+
progress_dict['success'] = True
1997+
else:
1998+
print('Run not completed.')
1999+
sc_outcar_path = os.path.join(self.directory, 'OUTCAR')
2000+
if os.path.exists(sc_outcar_path):
2001+
print('Self-consistent OUTCAR found.')
2002+
ion_steps, elec_steps = self._count_steps(sc_outcar_path)
2003+
progress_dict['running self-consistent'] = True
2004+
progress_dict['on ionic step'] = ion_steps
2005+
progress_dict['on electronic step'] = elec_steps
2006+
else:
2007+
print('No self-consistent OUTCAR.')
2008+
ion_path = os.path.join(self.directory, 'relax_ions')
2009+
if os.path.exists(ion_path):
2010+
print('Ions being relaxed.')
2011+
starts, ion_steps, elec_steps = self._count_dirs_steps(ion_path)
2012+
progress_dict['relax_ions starts'] = starts
2013+
progress_dict['on ionic step'] = ion_steps
2014+
progress_dict['on electronic step'] = elec_steps
2015+
else:
2016+
print('Not yet to ion-only relaxation.')
2017+
cellshape_path = os.path.join(self.directory, 'relax_cellshape')
2018+
print(f'cellshape_path is {cellshape_path} of type {type(cellshape_path)}')
2019+
if os.path.exists(cellshape_path):
2020+
print('Cellshape dir exists.')
2021+
starts, ion_steps, elec_steps = self._count_dirs_steps(self, path=cellshape_path)
2022+
progress_dict['relax_cellshape starts'] = starts
2023+
progress_dict['on ionic step'] = ion_steps
2024+
progress_dict['on electronic step'] = elec_steps
2025+
else:
2026+
print('Nothing started yet.')
2027+
progress_dict['started'] = False
2028+
return progress_dict
2029+
2030+
@property
2031+
@make_cached
2032+
def total_energies_restarts(self):
2033+
from . import Extract
2034+
energy_list = []
2035+
files = self._find_outcars()
2036+
files = sorted(files)
2037+
scf_outcar = files[0]
2038+
files.remove(scf_outcar)
2039+
files.append(scf_outcar)
2040+
for file in files:
2041+
extr = Extract(file)
2042+
energy_list.append(extr.total_energies.magnitude)
2043+
return energy_list
2044+
2045+
# @property
2046+
# @make_cached
2047+
# def total_energy_differences(self):
2048+
""" Sum of times listed at end of OUTCARs for all steps,
2049+
converted to hours.
2050+
"""
2051+
# import os
2052+
# colton_mod_end
2053+
19572054
def __dir__(self):
19582055
""" Attributes and members of this class.
19592056

0 commit comments

Comments
 (0)