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
Get the Hessian matrix for the given atomic structure.
63
+
Args:
64
+
atoms (Atoms): The atomic structure to calculate the Hessian for.
65
+
vmap (bool): Whether to use vectorized mapping for Hessian calculation. This can speed up the calculation but for medium-sized systems (TMCs) it uses way too much RAM. Calculating the Hessian without vmap for a TMC with the small UMA model took around 6 minutes on Mac (with possible background parallelization).
Run UMA relaxation. The output is a dictionary with all relevant results. It is intention that this function does not return a uma calc object, since it is not pickable and might not be returnable on hpc parallel runs with ray or joblib. For local, non-parallel runs, one could totally modify this function to return the calc object as well.
125
+
:return: dict
126
+
"""
127
+
start_time=datetime.now()
128
+
ifdevice=='cuda'andnottorch.cuda.is_available():
129
+
print('CUDA device requested but not available. Falling back to CPU.')
atoms.info= {'charge': charge, 'spin': n_unpaired+1} # UMA wants the multiplicity, not the number of unpaired electrons
137
+
traj_path=Path(tempdir, 'uma_relaxation.xyz')
138
+
opt=LBFGS(atoms, trajectory=str(traj_path), logfile=logfile) # Traj must be str, not Path()
139
+
opt.run(fmax=fmax, steps=steps)
140
+
141
+
iffrequencies:
142
+
raiseNotImplementedError('The frequency calculation is not yet implemented. You can implement it here easily using the uma_get_hessian function in the code above and then calculating frequencies from the Hessian matrix and the Gibbs energies from the frequencies using the ase thermochemistry module.')
143
+
144
+
# Avoid serialization issues with Ray/joblib by removing the calc from the atoms object
145
+
relaxed_atoms=opt.atoms.copy()
146
+
relaxed_atoms.calc=None
147
+
148
+
# Return all relevant results. Can't return the calc and opt objects directly since they are not pickable by Ray/joblib.
warnings.warn(f'Atoms did not move during the optimization. This might be due to a too high fmax ({fmax}) or too few steps ({steps}). Consider increasing these values.')
229
+
230
+
returnresults
231
+
232
+
233
+
234
+
235
+
236
+
if__name__=='__main__':
237
+
238
+
# Todo once only: login to huggingface to download and cache the used model
239
+
# from huggingface_hub import login; login(token='...') # provide here your huggingface token after registering. Do this just once for every model. Never share your token publicly, e.g. never commit the code to git with the token in it.
240
+
241
+
########## Example: Relax a water molecule with the small UMA model ##########
242
+
atoms=molecule('H2O') # ase.Atoms object or path to an xyz file. Here we create a water molecule using ASE.
243
+
method='umas'# 'umas' (small) or 'umam' (medium). The small model is faster but less accurate.
244
+
charge=0# Total charge of the molecule.
245
+
n_unpaired=0# Number of unpaired electrons of the molecule.
246
+
fmax=0.05# Max. converge force in eV/A. fmax=0.05 will give a convergence dE of around 1E-3 eV for a typical TMC.
247
+
steps=300# Maximum number of steps for the relaxation. 0 means single-point calculation.
248
+
# Other options:
249
+
logfile=None# Logfile to save the optimization output. None to suppress output, '-' to print to stdout.
250
+
timing=True# Whether to print timing information or not.
251
+
# NOT YET IMPLEMENTED:
252
+
frequencies=False# Whether to calculate frequencies and Gibbs energy or not.
253
+
device='cpu'# Currently only 'cpu' is supported. For using uma on a gpu with 'cuda', best ask Timo.
254
+
255
+
results=uma_relax_atoms(
256
+
atoms=atoms,
257
+
charge=charge,
258
+
method=method,
259
+
n_unpaired=n_unpaired,
260
+
fmax=fmax,
261
+
steps=steps,
262
+
frequencies=frequencies,
263
+
device=device,
264
+
logfile=logfile,
265
+
timing=timing
266
+
)
267
+
268
+
# Optional: uncomment to view optimization trajectory in ase gui.
269
+
# from ase.visualize import view
270
+
# view(results['opt']['traj']) # List of Atoms objects representing the trajectory
0 commit comments