Skip to content

Commit

Permalink
Fix bug with listing of initial adsorption configs
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiagoMorandi committed Sep 10, 2024
1 parent a6c7a6a commit 565881f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
14 changes: 6 additions & 8 deletions src/care/evaluators/gamenet_uq/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

class GameNetUQInter(IntermediateEnergyEstimator):
def __init__(
self,
surface: Surface,
self,
surface: Surface,
dft_db_path: Optional[str] = None,
num_configs: int = 3,
**kwargs
Expand Down Expand Up @@ -178,16 +178,14 @@ def eval(
if self.db and self.retrieve_from_db(intermediate):
return
else:
adsorptions = place_adsorbate(intermediate, self.surface)
adsorptions = place_adsorbate(intermediate, self.surface)[:self.num_configs]
ads_config_dict = {}
for i in range(len(adsorptions)):
if i == self.num_configs:
break
for i, adsorption in enumerate(adsorptions):
with no_grad():
ads_config_dict[f"{i}"] = {}
ads_config_dict[f"{i}"]["ase"] = adsorptions[i]
ads_config_dict[f"{i}"]["ase"] = adsorption
ads_config_dict[f"{i}"]["pyg"] = atoms_to_data(
adsorptions[i], self.model.graph_params
adsorption, self.model.graph_params
)
y = self.model(ads_config_dict[f"{i}"]["pyg"])
ads_config_dict[f"{i}"]["mu"] = (
Expand Down
24 changes: 12 additions & 12 deletions src/care/evaluators/oc20models/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(
cpu (bool): Whether to use the CPU for the calculation. Default is False.
fmax (float): The maximum force allowed on the atoms. Default is 0.05 eV/Angstrom.
max_steps (int): The maximum number of steps for the relaxation. Default is 100.
Note:
- The intermediate energy is stored as E_tot - E_slab in eV.
"""

self.model_name = model_name
Expand Down Expand Up @@ -60,11 +64,7 @@ def eval(
"""
gas_energy = intermediate['C']*self.eref['C'] + intermediate['H']*self.eref['H'] + intermediate['O']*self.eref['O']

if intermediate.phase == "surf": # active site
intermediate.ads_configs = {
"surf": {"ase": intermediate.molecule, "mu": 0.0, "s": 0.0}
}
elif intermediate.phase == "gas": # gas phase
if intermediate.phase == "gas": # gas phase
intermediate.ads_configs = {
"gas": {
"ase": intermediate.molecule,
Expand All @@ -74,14 +74,14 @@ def eval(
}
elif intermediate.phase == "ads": # adsorbed
ads_config_dict = {}
adsorptions = place_adsorbate(intermediate, self.surface)
for i in range(self.num_configs):
ads_config_dict[str(i)] = {}
adsorptions[i].set_calculator(self.calc)
opt = BFGS(adsorptions[i])
adsorptions = place_adsorbate(intermediate, self.surface)[:self.num_configs]
for i, adsorption in enumerate(adsorptions):
adsorption.set_calculator(self.calc)
opt = BFGS(adsorption)
opt.run(fmax=self.fmax, steps=self.max_steps)
ads_config_dict[str(i)]['ase'] = adsorptions[i]
ads_config_dict[str(i)]['mu'] = adsorptions[i].get_potential_energy() + gas_energy
ads_config_dict[str(i)] = {}
ads_config_dict[str(i)]['ase'] = adsorption
ads_config_dict[str(i)]['mu'] = adsorption.get_potential_energy() + gas_energy
ads_config_dict[str(i)]['s'] = 0.0
intermediate.ads_configs = ads_config_dict
print(intermediate.ads_configs)
Expand Down

0 comments on commit 565881f

Please sign in to comment.