Skip to content

Commit 82ec019

Browse files
committed
fix the label in ex09
1 parent af9b31d commit 82ec019

2 files changed

Lines changed: 25 additions & 251 deletions

File tree

examples/example_09_QRS.py

Lines changed: 0 additions & 242 deletions
This file was deleted.

examples/example_09_QRS_conf.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ def get_match_points(qrs):
7676
return match_ids, match_energies
7777

7878

79+
def get_visited_energies(qrs):
80+
"""Return visited energies in the same (gen, pop) order used for match IDs."""
81+
if not hasattr(qrs, "stats"):
82+
return []
83+
84+
energies = []
85+
for gen in range(qrs.N_gen):
86+
for pop in range(qrs.N_pop):
87+
energy = float(qrs.stats[gen, pop, 0])
88+
if energy < qrs.E_max:
89+
energies.append(energy)
90+
return energies
91+
92+
7993
def plot_id_vs_energy(code, energies, match_ids=None, match_energies=None, out_dir="qrs_plots", time_cost_s=None):
8094
"""Save a plot of visited-structure ID vs energy for one QRS run."""
8195
if not energies:
@@ -115,7 +129,7 @@ def plot_id_vs_energy(code, energies, match_ids=None, match_energies=None, out_d
115129
margin = max(abs(ymin) * 0.05, 1.0)
116130
ax.set_ylim(ymin - margin, ymax + margin)
117131
else:
118-
y_max = min(ymin + 50, ymax)
132+
y_max = min(ymin + 30, ymax)
119133
ax.set_ylim(ymin - 1, y_max)
120134
fig.tight_layout()
121135

@@ -127,8 +141,9 @@ def plot_id_vs_energy(code, energies, match_ids=None, match_energies=None, out_d
127141

128142
if __name__ == "__main__":
129143
db = database("pyxtal/database/test.db")
130-
os.makedirs("Tests", exist_ok=True)
131-
csv_path = "Tests/qrs_results_pregen_mols.csv"
144+
out_dir = "Tests_0"
145+
os.makedirs(out_dir, exist_ok=True)
146+
csv_path = os.path.join(out_dir, "qrs_results_pregen_mols.csv")
132147

133148
with open(csv_path, "w", newline="") as fcsv:
134149
writer = csv.writer(fcsv)
@@ -158,7 +173,7 @@ def plot_id_vs_energy(code, energies, match_ids=None, match_energies=None, out_d
158173
print(f"\n=== {code} ===")
159174
print(ref_xtal)
160175

161-
workdir = os.path.join("Tests", row.csd_code)
176+
workdir = os.path.join(out_dir, row.csd_code)
162177
os.makedirs(workdir, exist_ok=True)
163178
sites = build_sites_from_reference(ref_xtal)
164179

@@ -219,9 +234,9 @@ def plot_id_vs_energy(code, energies, match_ids=None, match_energies=None, out_d
219234
composition = [int(a) for a in ref_xtal.get_zprime()],
220235
molecules=molecules,
221236
sites=sites,
222-
N_gen=20,
223-
N_pop=50,
224-
N_cpu=2,
237+
N_gen=100,
238+
N_pop=24,
239+
N_cpu=24,
225240
cif="all.cif",
226241
skip_mlp=True,
227242
verbose=False,
@@ -238,13 +253,14 @@ def plot_id_vs_energy(code, energies, match_ids=None, match_energies=None, out_d
238253
else:
239254
print("No match found within the given generations/population.")
240255
print(f"Time cost: {time_cost_s:.2f} s")
256+
visited_energies = get_visited_energies(qrs)
241257
match_ids, match_energies = get_match_points(qrs)
242258
plot_id_vs_energy(
243259
code,
244-
qrs.engs,
260+
visited_energies,
245261
match_ids=match_ids,
246262
match_energies=match_energies,
247-
out_dir="Tests/qrs_plots",
263+
out_dir=os.path.join(out_dir, "qrs_plots"),
248264
time_cost_s=time_cost_s,
249265
)
250266

0 commit comments

Comments
 (0)