# Basics of numerical energy minimization techniques used in molecular dynamics?

The question below describes my plan to make a basic molecular dynamics calculation using a Python script rather than a canned, self-contained program.

There seems to be three parts:

1. a model of the honeycomb net and substrate atoms
2. an expression for energy based on atomic positions
3. an energy minimization procedure (the topic of this question)

The two procedures I can imagine implementing are

1. Monte-carlo method jiggle the positions randomly using some pseudo-temperature parameter, keep the new positions if energy goes down and flip a coin about keeping the new positions if higher based on *how much higher) it is.
2. Kinematically using a damped differential equation and a standard ODE solver for all atomic positions.

These are general tools that I'm aware of and know how to implement in general and I can start with these no problem. But are these the numerical techniques that proper classical molecular dynamical simulations use, or are there different and/or better ways?

References:

My nascent DIY model, from here (click for larger)

• Just FYI, "molecular dynamics" refers to the method that simulates the time evolution of a system by numerically integrating its equations of motion. Energy minimization (aka "geometry optimization") is something different. The umbrella term you might be looking for is "molecular mechanics". Commented Mar 3, 2022 at 22:13
• @TooTea yes I see what you mean, dynamics means what it means. However in practice it looks like at least some "MD people" use MD to reference either sometimes whether they should or shouldn't cf. this answer. Personally I'll pursue the FIRE (inertial relaxation (with damping)) method I think. It will make for better-looking movies :-) e.g. youtu.be/WFCvkkDSfIU?t=218
– uhoh
Commented Mar 3, 2022 at 22:22

AFAIK most MD codes do something like conjugate gradients or BFGS for energy minimization. Your option 1 is Metropolis Monte Carlo, while option 2 sounds like the FIRE algorithm.

However, why implement something yourself, when there is a multitude of solvers already available in e.g. scipy? See https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html, for example. You could just interface to these routines and get a lot of functionality "for free"?

• I for one, like making things myself. If you understand how to do something, it shouldn't take long. If it does, you were always just kidding yourself that you understood it and had no right to be using a black box on the pretext of simply using a more efficient code because you understood the fundamentals. Commented Mar 3, 2022 at 14:10
• Oh! somehow I totally misread your very clear suggestion. Yes in this question I already call scipy.optimize.minimize and it certainly makes complete sense not to reinvent the wheel when it comes to numerical algorithms necessarily implemented in complied code. What I want to implement myself is the model setup and energy evaluation function, and to do that well I'll need to understand the optimizer. Yes for option 2 FIRE (inertial relaxation) is just the kind of thing I was thinking of. Your answer is exactly what I needed; thank you!
– uhoh
Commented Mar 3, 2022 at 22:10
• Writing personal optimizers can be very helpful! For harder problems where off-the-shelf optimizers failed, I had success writing my own that was kind of a managed-wrapper around others: my optimizer would wrap the black-box function being optimized, allowing the off-the-shelf optimizers to do their thing when they were working well enough. When they'd start having problems, I'd trace the iteration-history to make some new guesses (e.g., to get out of a weird pot-hole), then put in some transforms to condition the model. Kinda like being a driver of a mostly-self-driving car.
– Nat
Commented Mar 3, 2022 at 22:33
• – uhoh
Commented Mar 3, 2022 at 22:39
• FIRE looks surprisingly easy to implement, I think I will give it a try. Thanks again!
– uhoh
Commented Mar 5, 2022 at 9:52