Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find adsorption energy correctly #940

Open
amru104 opened this issue Dec 11, 2024 · 1 comment
Open

Unable to find adsorption energy correctly #940

amru104 opened this issue Dec 11, 2024 · 1 comment

Comments

@amru104
Copy link

amru104 commented Dec 11, 2024

What would you like to report?

I am trying to find the adsorption energy of OH adsorbate with Pt(111) surface but the code is give me an incorrect value. This is the eroor i am getting: RuntimeError: cannot reshape tensor of 0 elements into shape [0, -1] because the unspecified dimension size -1 can be any value and is ambiguous.
This is my code:
import json
from ase import Atoms
from ase.optimize import BFGS
from fairchem.core.common.relaxation.ase_utils import OCPCalculator
from ase.build import fcc111, add_adsorbate

with open('./ocp/docs/tutorials/energies.json') as f:
edata = json.load(f)

re1 = -3.03 # H2 + 1/2 O2 -> H2O (Energy from the reaction)
re3 = -2.58 # OH -> 1/2 O2 + H2 (Energy from the reaction)

slab = fcc111('Pt', size=(2, 2, 5), vacuum=10.0)

OH = Atoms(['O', 'H'], positions=[(0, 0, 0), (0, 0, 1)]) # Positions of O and H atoms for OH

add_adsorbate(slab, OH, height=1.5, position='fcc')

checkpoint_path = '/tmp/fairchem_checkpoints/gnoc_oc22_oc20_all_s2ef.pt'
calc = OCPCalculator(checkpoint_path=checkpoint_path, cpu=False)
slab.set_calculator(calc)
OH.set_calculator(calc) # Attach the calculator to the OH adsorbate

opt = BFGS(slab)
opt.run(fmax=0.05, steps=100)

from ase.constraints import FixAtoms

constraint = FixAtoms(indices=[atom.index for atom in slab if atom.symbol == 'Pt'])
slab.set_constraint(constraint)

opt = BFGS(slab)
opt.run(fmax=0.05, steps=100)

E_slab_OH = slab.get_potential_energy()

E_slab = slab.copy() # Create a copy of the clean slab
E_slab.set_calculator(calc)
E_slab = E_slab.get_potential_energy()

E_OH = OH.get_potential_energy()

re2_OH = E_slab_OH - E_slab - E_OH + 0.167
print(f"Calculated re2_OH energy: {re2_OH} eV")

adsorption_energy_OH = re1 + re2_OH + re3
print(f"Calculated adsorption energy for OH + * -> OH* on Pt(111): {adsorption_energy_OH} eV")

@zulissimeta
Copy link
Collaborator

Hi - the GemNet-OC models require the atoms tags to be set (which indicate the subsurface, surface, and adsorbate atoms, which can be helpful for reducing the number of atoms that are considered for the adsorption energy). The error you're seeing usually happens when either an atom has no neighbors, or the tags are not set correctly.

You have a few options, all of which should work fine!

  1. You could set the tags yourself (0=bulk/subsurface, 1=surface, 2=adsorbate) on the atoms object
  2. You could use the OCP tools to help make the surface and tag at the same time (example in the tutorial)
  3. You could use another model like eSCN or equiformerV2, which do no need/use the tag information. I would probable recommend this option, as the latest EquiformerV2 models are also significantly more accurate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants