Skip to content

Commit

Permalink
update db function with gulp calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed May 30, 2024
1 parent 839ab66 commit 8bf30c0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pyxtal/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,8 @@ def select_xtals(self, ids, overwrite=False, attribute=None, use_relaxed=None):
def update_row_ff_energy(self, ff='reaxff', ids=(None, None), ncpu=1,
calc_folder='gulp_calc',
criteria=None,
overwrite=False):
overwrite=False,
write_freq=10):
"""
Update row ff_energy with GULP calculator
Expand All @@ -858,6 +859,7 @@ def update_row_ff_energy(self, ff='reaxff', ids=(None, None), ncpu=1,
ncpu (int): number of parallel processes
calc_folder (str): temporary folder for GULP calculations
overwrite (bool): remove the existing attributes
write_freq (int): frequency to write results to db for ncpu=1
"""

os.makedirs(calc_folder, exist_ok=True)
Expand All @@ -870,7 +872,11 @@ def update_row_ff_energy(self, ff='reaxff', ids=(None, None), ncpu=1,
for id, xtal in zip(ids, xtals):
res = gulp_opt_single(id, xtal, ff, calc_folder, criteria)
(xtal, eng, status) = res
if status: gulp_results.append((id, xtal, eng))
if status:
gulp_results.append((id, xtal, eng))
if len(gulp_results) >= write_freq:
self._update_db_gulp(gulp_results)
gulp_results = []
else:
if len(ids) < ncpu: ncpu = len(ids)
N_cycle = int(np.ceil(len(ids)/ncpu))
Expand All @@ -886,7 +892,12 @@ def update_row_ff_energy(self, ff='reaxff', ids=(None, None), ncpu=1,
results = [executor.submit(gulp_opt_par, *p) for p in args_list]
for result in results:
gulp_results.extend(result.result())
self._update_db_gulp(gulp_results)

def _update_db_gulp(self, gulp_results):
"""
Update db with the gulp_results
"""
print("Wrap up the final results and update db", len(gulp_results))
for gulp_result in gulp_results:
(id, xtal, eng) = gulp_result
Expand Down

0 comments on commit 8bf30c0

Please sign in to comment.