Dear Ase Users,
I’m trying to relax some periodic structures using a combination of machine learning potential (m3gnet) with DFTd3 dispersion due to the fact that the dataset of m3gnet is without dispersion effects.
This is the following script that I’m using:
import os
#import ase
#import m3gnet
from m3gnet.models import *
from ase.optimize.fire import FIRE
from ase.optimize.bfgs import BFGS
from ase.io.trajectory import Trajectory
from ase.constraints import UnitCellFilter, StrainFilter, ExpCellFilter
from ase.calculators.mixing import SumCalculator
from dftd3.ase import DFTD3
from ase.io import read,write
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
warnings.filterwarnings("ignore")
import tensorflow as tf
tf.get_logger().setLevel('ERROR')
atoms = read('poscar_banco_forsterite.POSCAR')
#atoms=ase.io.read('forsterite_opt_banco_crystal.f34', format='crystal')
#ase.io.crystal.read_crystal('forsterite_opt_banco_crystal.f34')
#atoms.set_calculator(M3GNetCalculator(potential=Potential(M3GNet.load())))
#with Grimme dispersion
atoms.calc = SumCalculator([DFTD3(method="PBE", damping="d3bj"), M3GNetCalculator(potential=Potential(M3GNet.load()),compute_stress = True, stress_weight = 1.0)])
energy = atoms.get_potential_energy()
a,b,c,bc,ac,ab = atoms.get_cell_lengths_and_angles()
#forces = atoms.get_forces()
print("Single point energy --> %.8f eV" % (energy))
print("Cell parameter --> a: %.5f , b: %.5f, c: %.5f " % (a,b,c))
print(" BC: %.4f , AC: %.4f , AB: %.4f" % (bc,ac,ab))
atoms = ExpCellFilter(atoms)
opt=BFGS(atoms)
opt.run(fmax=0.001)
energy_opt = atoms.get_potential_energy()
a,b,c,bc,ac,ab = atoms.get_cell_lengths_and_angles()
print("Optimized energy --> %.8f eV" % (energy_opt))
print("Optimized cell parameter --> a: %.5f , b: %.5f, c: %.5f " % (a,b,c))
print(" BC: %.4f , AC: %.4f , AB: %.4f" % (bc,ac,ab))
when I run this code it exits with this error message:
ValueError Traceback (most recent call last)
Cell In[1], line 47
43 atoms = ExpCellFilter(atoms)
46 opt=BFGS(atoms)
—> 47 opt.run(fmax=0.1)
51 # >>> atoms = Atoms(…)
52 # ecf = StrainFilter(atoms)
53 # qn = BFGS(ecf)
(…)
57 # qn.attach(traj)
58 # qn.run(fmax=0.05)
62 energy_opt = atoms.get_potential_energy()
…
…
…
57 self.results[k] = w * calc.results[k]
58 else:
—> 59 self.results[k] += w * calc.results[k]
ValueError: operands could not be broadcast together with shapes (6,) (3,3) (6,)
However, when I remove the SumCalcuator function, thus I’m removing the dispersion effects from my calculator, the calculation run smoothly.
Do you have any clue about this?
Thank you