12. Universal and updatable AIQM models
This tutorial will use the MLatom program.
12.1. Slides
12.2. Geometry optimization
We will get started by showcasing the power of ML to supercharge the computational chemistry simulations. We will use the most recent and advanced concept of performing simulations with the universal and updatable AI-enhanced quantum mechanical (UAIQM) models:
Let’s say you want to optimize the molecular geometry. Now you do not need to worry which method (DFT or ab initio, etc.) to choose: MLatom will choose the best model automatically for you.
Example 1.
The input is simple:
UAIQM
geomopt
xyzfile='5
C 0.0000000000 0.0000000000 0.0000000000
H 1.0870000000 0.0000000000 0.0000000000
H -0.3623333220 -1.0248334322 -0.0000000000
H -0.3623333220 0.5124167161 -0.8875317869
H -0.3623333220 0.5124167161 0.8875317869
'
In the output file, you will get the information which UAIQM model was selected:
Selected UAIQM method: uaiqm_gfn2xtbstar@cc
Selected version: 20240106
It is much nicer to use MLaton as a Python package, and Jupyter notebooks make it also easy to use if you do not know Python.
The connoisseurs of Python can get much more flexibility when using MLatom.
Here is the same example as above, but in Python (uaiqm_geomopt.ipynb), which you can use after you launch the Jupyter Lab on the Aitomistic Lab@XMU.
import mlatom as ml
# Get the initial guess for the molecules to optimize
initmol = ml.data.molecule.from_xyz_string('''5
C 0.0000000000 0.0000000000 0.0000000000
H 1.0870000000 0.0000000000 0.0000000000
H -0.3623333220 -1.0248334322 -0.0000000000
H -0.3623333220 0.5124167161 -0.8875317869
H -0.3623333220 0.5124167161 0.8875317869
''')
# define UAIQM method
uaiqm_optimal = ml.models.uaiqm(method='uaiqm_optimal', verbose=False)
# verbose = True in the above line requests to print the information about the model
uaiqm_optimal.select_optimal(
molecule=initmol,
nCPUs=1,
time_budget='1s'
)
print(f'Optimal model {uaiqm_optimal.method}, version {uaiqm_optimal.version}')
#uaiqm = ml.models.methods(method=uaiqm_optimal.method, version=uaiqm_optimal.version)
# Optimize the geometry with the choosen optimizer:
geomopt = ml.optimize_geometry(model=uaiqm_optimal, initial_molecule=initmol, program='geometric')
# Get the final geometry
final_mol = geomopt.optimized_molecule
# and its XYZ coordinates
print('\nOptimized coordinates\n')
print(final_mol.get_xyz_string())
# save the final geometry
final_mol.write_file_with_xyz_coordinates(filename='final.xyz')
# View the molecule
final_mol.view()
Optimal model uaiqm_gfn2xtbstar@cc, version 20240106 Optimized coordinates 5 C 0.0000000061260 -0.0000000030574 -0.0000000001556 H 1.0871538643808 0.0000000030857 -0.0000000000055 H -0.3623846150166 -1.0249784870625 0.0000000005359 H -0.3623846108738 0.5124892411848 -0.8876574045314 H -0.3623846114315 0.5124892429459 0.8876574028322
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
You can check the model’s composition online.
If your molecule happened to be neutral and closed shell and only contain the CHNO elements, UAIQM will give you the CCSD(T)/CBS-level result but at a very fast speed (usually even faster than DFT).
The MLatom output .log file will contain information about the optimization iterations and print out the final optimized geometry, which you can also find in the optgeoms.xyz.
Note that same kind of input works for other, QM and ML, methods, e.g. for DFT:
Example 2.
# example for DFT:
B3LYP/6-31G*
# example for ab initio:
# CCSD(T)/cc-pVDZ
# example for very fast universal ML model (also approaching CCSD(T)/CBS):
# ANI-1ccx
geomopt
xyzfile='5
C 0.0000000000 0.0000000000 0.0000000000
H 1.0870000000 0.0000000000 0.0000000000
H -0.3623333220 -1.0248334322 -0.0000000000
H -0.3623333220 0.5124167161 -0.8875317869
H -0.3623333220 0.5124167161 0.8875317869
'
or in Python:
import mlatom as ml
# Get the initial guess for the molecules to optimize
initmol = ml.data.molecule.from_xyz_string('''5
C 0.0000000000 0.0000000000 0.0000000000
H 1.0870000000 0.0000000000 0.0000000000
H -0.3623333220 -1.0248334322 -0.0000000000
H -0.3623333220 0.5124167161 -0.8875317869
H -0.3623333220 0.5124167161 0.8875317869
''')
# define DFT method
b3lyp = ml.models.methods(method='B3LYP/6-31G*')
# Optimize the geometry with the choosen optimizer:
geomopt = ml.optimize_geometry(model=b3lyp, initial_molecule=initmol, program='geometric')
# Get the final geometry
final_mol = geomopt.optimized_molecule
# and its XYZ coordinates
print('\nOptimized coordinates\n')
print(final_mol.get_xyz_string())
# save the final geometry
final_mol.write_file_with_xyz_coordinates(filename='final.xyz')
# View the molecule
final_mol.view()
You can play with these different options.
Since MLatom is a data-drive package, the optimization trajectory is also saved in the json format, i.e., you will find files like opttraj.json (it is also available in XYZ format for convenience: opttraj.xyz).
For more options on how to use MLatom for geometry optimizations, you can check out the dedicated tutorial. For example, you can use MLatom for the optimization with constraints too.
The power of MLatom is that you can use different ML models to do many types of simulations, including geometry optimization as we will see in the basics of ML.