Predictions of new oxide slabs

Hi all.

I’d like to make energy predictions of the oxide materials which are not in the OC22 dataset by one of the pretrained models as OCPCalculator.
I’m trying to create the oxide slab by specifying atoms one-by-one, or by using Materials Project (by material ID for example). But, I was unable to make progress for the relaxation step. I’m getting an error from LBFGS (I shared after the code). I couldn’t figure this error out. And, is this the most suitable way to create new oxide slabs, or are there any other ways?
Here is an example code snippet to create PtO2 with O adsorbate:

from ase import Atom
from ase.build import surface
from ase.visualize.plot import plot_atoms

PtO2 = Atoms([Atom('Pt', (-0., -0., -0.)),
                        Atom('Pt', (1.57841783, 2.27358129, 2.25503354)),
                        Atom('O', (0.        , 3.35854824, 2.89009325)),
                        Atom('O', (0.        , 1.18861434, 1.61997384)),
                        Atom('O', (1.57841783, 1.08496695, 3.87500738)),
                        Atom('O', (1.57841783, 3.46219563, 0.63505971))],
              cell=[3.15683565, 4.54716258, 4.51006709],
              pbc=True)

adslab = surface(PtO2, (1, 1, 1), 9)
adslab.center(vacuum=10, axis=2)

adsorbate = molecule("O")
add_adsorbate(adslab, adsorbate, 1, offset=(1, 1))
adslab.set_pbc(True)

adslab.set_calculator(ocp_calculator)

dyn = LBFGS(adslab, trajectory="data/gemnetOC_oc22_PtO2-O.traj")
dyn.run(fmax=0.03, steps=100)

adslab_traj = ase.io.read("data/gemnetOC_oc22_PtO2-O.traj", ":")

The error I get:

User provided device_type of 'cuda', but CUDA is not available. Disabling
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-138-43a2aaa38245> in <cell line: 1>()
----> 1 dyn = LBFGS(adslab, trajectory="data/gemnetOC_oc22_PtO2-O.traj")
      2 dyn.run(fmax=0.03, steps=100)
      3 
      4 adslab_traj = ase.io.read("data/gemnetOC_oc22_PtO2-O.traj", ":")

18 frames
/content/ocp/ocpmodels/models/gemnet_oc/layers/spherical_basis.py in <lambda>(cosφ, θ)
    118                 circular_basis(cosφ)[:, :, None]
    119                 * circular_basis(torch.cos(ϑ))[:, None, :]
--> 120             ).reshape(cosφ.shape[0], -1)
    121 
    122         elif sbf_name == "gaussian_outer":

RuntimeError: cannot reshape tensor of 0 elements into shape [0, -1] because the unspecified dimension size -1 can be any value and is ambiguous

Hello! Errors like this often come up when using GemNet-OC in a structure without tags. There is some more information in this issue: Error in OCPCalculator when using most checkpoints from OC22 · Issue #524 · Open-Catalyst-Project/ocp · GitHub.

One way to add tags is shown here: GemNet-OC pre-trained checkpoints failing with gas molecules · Issue #426 · Open-Catalyst-Project/ocp · GitHub.

1 Like

Thank you so much! It really worked!
Now I’m trying to revise how I create the slab. -it doesn’t seem to be a complete slab with enough number of atoms… If you or anyone has any opinion or comment on this, I’d appreciate!

Here is the modified code, if anyone needs:

from ase import Atom
from ase.build import surface
from ase.visualize.plot import plot_atoms

PtO2 = Atoms([Atom('Pt', (-0., -0., -0.)),
              Atom('Pt', (1.57841783, 2.27358129, 2.25503354)),
              Atom('O', (0.        , 3.35854824, 2.89009325)),
              Atom('O', (0.        , 1.18861434, 1.61997384)),
              Atom('O', (1.57841783, 1.08496695, 3.87500738)),
              Atom('O', (1.57841783, 3.46219563, 0.63505971))],
              cell=[3.15683565, 4.54716258, 4.51006709],
              pbc=True)

adslab = surface(PtO2, (1, 1, 1), 3)
adslab.center(vacuum=10, axis=2)

adsorbate = molecule("O")
add_adsorbate(adslab, adsorbate, 0.5)

# Tag all slab atoms below surface as 0, surface as 1, adsorbate as 2
tags = np.zeros(len(adslab))
tags[12:18] = 1
tags[18:] = 2
adslab.set_tags(tags)

# Fixed atoms are prevented from moving during a structure relaxation.
# We fix all slab atoms beneath the surface.
cons = FixAtoms(indices=[atom.index for atom in adslab if (atom.tag == 0)])
adslab.set_constraint(cons)
adslab.center(vacuum=13.0, axis=2)
adslab.set_pbc(True)

adslab.set_calculator(ocp_calculator)

os.makedirs("data", exist_ok=True)

dyn = LBFGS(adslab, trajectory="data/gemnetOC_oc22_PtO2-O.traj")
dyn.run(fmax=0.03, steps=100)

adslab_traj = ase.io.read("data/gemnetOC_oc22_PtO2-O.traj", ":")