Skip to content

Commit

Permalink
rewrite GA/PSO/QRS
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Jul 29, 2024
1 parent 641f5eb commit 6b81c86
Show file tree
Hide file tree
Showing 7 changed files with 470 additions and 125 deletions.
37 changes: 18 additions & 19 deletions pyxtal/optimize/PSO.py → pyxtal/optimize/DFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from pyxtal.molecule import pyxtal_molecule


class PSO(GlobalOptimize):
class DFS(GlobalOptimize):
"""
Standard Genetic algorithm
Standard Population algorithm
Args:
smiles (str): smiles string
Expand Down Expand Up @@ -138,7 +138,7 @@ def __init__(

def full_str(self):
s = str(self)
s += "\nMethod : Depth First Population Algorithm"
s += "\nMethod : Stochastic Depth First Sampling"
s += f"\nGeneration: {self.N_gen:4d}"
s += f"\nPopulation: {self.N_pop:4d}"
# The rest base information from now on
Expand Down Expand Up @@ -353,9 +353,9 @@ def run(self, ref_pmg=None, ref_eng=None, ref_pxrd=None):
if xtal.has_special_site():
xtal = xtal.to_subgroup()

# GA run
# GO run
t0 = time()
ga = GA(
go = DFS(
smile,
wdir,
xtal.group.number,
Expand All @@ -369,19 +369,18 @@ def run(self, ref_pmg=None, ref_eng=None, ref_pxrd=None):
cif="pyxtal.cif",
)

match = ga.run(pmg0)
if match is not None:
eng = match["energy"]
tmp = "{:}/{:}".format(match["rank"], ga.N_struc)
mytag = "True[{:}] {:10s}".format(match["tag"], tmp)
mytag += "{:5.2f}{:5.2f}".format(match["l_rms"], match["a_rms"])
suc_rate = go.run(pmg0)
print(strs + " in Gen {:d}\n".format(go.generation))

if len(go.matches) > 0:
best_rank = go.print_matches()
mytag = f"True {best_rank:d}/{go.N_struc:d} Succ_rate: {suc_rate:7.4f}%"
else:
eng = ga.min_energy
tmp = f"0/{ga.N_struc}"
mytag = f"False {tmp:10s}"

t1 = int((time() - t0) / 60)
strs = f"Final {name:8s} {spg:8s} {t1:3d}m"
strs += f" {ga.generation:3d}[{ga.N_torsion:2d}] {wt:6.1f}"
strs += f"{eng:12.3f} {mytag:30s} {smile:s}"
mytag = f"False 0/{go.N_struc:d}"

eng = go.min_energy
t1 = int((time() - t0)/60)
strs = "Final {:8s} [{:2d}]{:10s} ".format(code, sum(xtal.numMols), spg)
strs += "{:3d}m {:2d} {:6.1f}".format(t1, N_torsion, wt)
strs += "{:12.3f} {:20s} {:s}".format(eng, mytag, smile)
print(strs)
Loading

0 comments on commit 6b81c86

Please sign in to comment.