You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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!
You could set the tags yourself (0=bulk/subsurface, 1=surface, 2=adsorbate) on the atoms object
You could use the OCP tools to help make the surface and tag at the same time (example in the tutorial)
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.
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")
The text was updated successfully, but these errors were encountered: