Skip to content

Commit c22070a

Browse files
authored
Merge pull request #420 from anyangml2nd/chrore/efficiency-fix
Fix: define calc out of for loop
2 parents 2141912 + 58071eb commit c22070a

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

lambench/metrics/vishelper/metrics_calculations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ def calculate_generalizability_downstream_score(self) -> tuple[dict, dict]:
159159
) # drop models with missing domain results
160160

161161
# # Now aggregate all domains to get the final generalizability metrics for each model
162-
return domain_results.to_dict(orient="index"), domain_results.mean(axis=1).to_dict()
162+
return domain_results.to_dict(orient="index"), domain_results.mean(
163+
axis=1
164+
).to_dict()
163165

164166
def calculate_stability_results(self) -> dict[str, float]:
165167
"""This calculates the stability score for a given LAM."""

lambench/tasks/calculator/elastic/elastic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ def get_elastic_for_one(
102102
"""
103103
atoms = read(StringIO(atom_info["poscar"]), format="vasp")
104104

105+
calc = model.calc
105106
relaxed_atoms = model.run_ase_relaxation(
106107
atoms=atoms,
107-
calc=model.calc,
108+
calc=calc,
108109
fmax=fmax,
109110
steps=max_steps,
110111
fix_symmetry=False,
@@ -119,7 +120,7 @@ def get_elastic_for_one(
119120
stresses = []
120121
for deformed_structure in deformed_structure_set:
121122
atoms = deformed_structure.to_ase_atoms()
122-
atoms.calc = model.calc
123+
atoms.calc = calc
123124
stresses.append(atoms.get_stress(voigt=False))
124125

125126
strains = [

lambench/tasks/calculator/torsionnet/torsionnet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def run_torsionnet(
3030
result = {} # predicted energy
3131
label = {} # label energy
3232

33+
calc = model.calc
34+
3335
# 500 fragments from Torsionnet500 dataset
3436
for fragment in tqdm(test_data.iterdir()):
3537
if not fragment.is_dir():
@@ -40,7 +42,7 @@ def run_torsionnet(
4042
for frame in dpdata.LabeledSystem(file_name=fragment, fmt="deepmd/raw"):
4143
assert len(frame) == 1
4244
atoms: Atoms = frame.to_ase_structure()[0] # type: ignore
43-
atoms.calc = model.calc
45+
atoms.calc = calc
4446
pred_energy = atoms.get_potential_energy() * 23.0609 # eV to kcal/mol
4547
result[fragment.name].append(pred_energy)
4648
label_energy = frame.data["energies"][0]

0 commit comments

Comments
 (0)