Skip to content

Commit

Permalink
MPI should be ready
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Sep 7, 2024
1 parent 2167d89 commit d6ea184
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyxtal/interface/charmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def read(self):
self.structure.energy = self.errorE
self.error = True
if self.debug:
print("Unable to retrieve Structure after optimization")
print("Cannot retrieve Structure after optimization")
print("lattice", self.structure.lattice)
self.structure.to_file("1.cif")
print("Check 1.cif in ", os.getcwd())
Expand Down
10 changes: 8 additions & 2 deletions pyxtal/optimize/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ def handler(signum, frame):
return None # or some other placeholder for timeout results

def process_task(args):
result = run_optimizer_with_timeout(args)
#logger = args[-1]
#logger.info(f"Rank start processing task")
result = run_optimizer_with_timeout(args)#[:-1])
#logger.info(f"Rank finished processing task")
return result


class GlobalOptimize:
"""
Base-class for all global optimization methods
Expand Down Expand Up @@ -1063,13 +1067,15 @@ def local_optimization_mproc(self, xtals, ncpu, ids=None, qrs=False, pool=None):
+ "-p" + str(id) for id in _ids]
_xtals = [xtals[id][0] for id in range(id1, id2)]
mutates = [False if qrs else xtal is not None for xtal in _xtals]
my_args = [_xtals, _ids, mutates, job_tags, *args, self.timeout]
my_args = [_xtals, _ids, mutates, job_tags, *args, self.timeout]#, self.logging]
args_lists.append(tuple(my_args))

self.logging.info(f"Rank {self.rank} assign args in local_opt_mproc")
gen_results = []

for result in pool.imap_unordered(process_task, args_lists):
if result is not None:
#self.logging.info(f"Rank {self.rank} grab {len(result)} strucs")
for _res in result:
gen_results.append(_res)

Expand Down
52 changes: 41 additions & 11 deletions pyxtal/optimize/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,36 +218,53 @@ def optimizer(
"""
if calculators is None:
calculators = ["CHARMM"]

cwd = os.getcwd()
t0 = time()
os.chdir(workdir)
stress_tol = 10.0 if len(struc.mol_sites[0].molecule.mol) < 10 else 5.0

results = None

for i, calculator in enumerate(calculators):
if calculator == "CHARMM":
if i == 0:
calc = CHARMM(struc, tag, steps=[1000], atom_info=atom_info)
calc.run()#clean=False); import sys; sys.exit()
# in case CHARMM over-relax the structure
# print("CCCCCC", calc.optimized); import sys; sys.exit()
if not calc.optimized: #
calc = CHARMM(struc, tag, steps=[500], atom_info=atom_info)
calc.run()
if calc.error:
os.chdir(cwd)
return None
else:
if not calc.optimized: #
calc = CHARMM(struc, tag, steps=[500], atom_info=atom_info)
calc.run()
if calc.error:
os.chdir(cwd)
return None

# print(calc.structure)
steps = [1000, 1000] if opt_lat else [2000]
calc = CHARMM(calc.structure, tag, steps=steps, atom_info=atom_info)
calc.run() # print("Debug", calc.optimized); import sys; sys.exit()

# only count good struc
if not calc.error:
if calc.error:
os.chdir(cwd)
return None
else:
calc = CHARMM(calc.structure, tag, steps=steps, atom_info=atom_info)
calc.run()#clean=False)

if calc.optlat: # lattice with bad inclination angles
calc = CHARMM(calc.structure, tag, steps=steps, atom_info=atom_info)
calc.run()#clean=False)
if calc.error:
os.chdir(cwd)
return None
else:
if calc.optlat: # with bad inclination angles
calc = CHARMM(calc.structure, tag, steps=steps, atom_info=atom_info)
calc.run()#clean=False)
if calc.error:
os.chdir(cwd)
return None

# Check if there exists a 2nd FF model for better energy ranking
if os.path.exists("pyxtal1.prm"):
Expand All @@ -259,12 +276,22 @@ def optimizer(
atom_info=atom_info,
)
calc.run()
if calc.error:
os.chdir(cwd)
return None

if calc.error:
os.chdir(cwd)
return None
else:
struc = calc.structure
struc.resort()

struc = calc.structure
struc.resort()
os.chdir(cwd)

# density should not be too small
if not skip_ani:
stress_tol = 10.0 if len(struc.mol_sites[0].molecule.mol) < 10 else 5.0
if (
struc.energy < 9999
and struc.lattice.is_valid_matrix()
Expand All @@ -284,16 +311,19 @@ def optimizer(
struc.optimize_lattice()
except:
print("Trouble in optLat")
return None
elif stress < stress_tol:
results = {}
results["xtal"] = struc
if eng is not None:
results["energy"] = eng # /sum(struc.numMols)
else:
results["energy"] = 10000
return None
results["time"] = time() - t0
else:
print(f"stress is wrong {stress:6.2f}")
return None
# print(struc)
# print(struc.to_file())
# import sys; sys.exit()
Expand Down

0 comments on commit d6ea184

Please sign in to comment.