# Shortest Path from contour plot?

**URL:** <https://discourse.julialang.org/t/shortest-path-from-contour-plot/121719>\
**Category:** General Usage\
**Tags:** question, optimization, physics, chemistry\
**Created:** [October 24, 2024, 8:02pm UTC](https://discourse.julialang.org/t/shortest-path-from-contour-plot/121719 "2024-10-24T20:02:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sophibug](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sophibug/32/210241_2.png) [@sophibug](https://discourse.julialang.org/u/sophibug)\
**Post date:** [October 24, 2024, 8:02pm UTC](https://discourse.julialang.org/t/shortest-path-from-contour-plot/121719/1 "2024-10-24T20:02:20Z")

</div>

Putting this in general usage, because I’m applying it to chemistry, but shortest path is a frequent problem.

I have a 2D potential energy surface of a molecule as two of its axes rotate, formatted for a contour plot. I am looking to find the least-energetic path between two points.

Here’s a segment of the array:

```julia
 0.494 0.938 2.252
 0.605 1.465 3.177
 0.937 2.15 4.163
 1.41 2.88 5.072
 1.931 3.541 5.777
 2.396 4.02 6.168
 2.714 4.233 6.19
 2.834 4.162 5.865
 2.756 3.845 5.261
 2.522 3.344 4.465
 2.18 2.73 3.568
 1.787 2.079 2.659
 1.404 1.465 1.823
 1.083 0.947 1.119
 0.862 0.561 0.579
 0.754 0.323 0.216
 0.755 0.228 0.027
 0.853 0.265 0.0

```

Each of these is an energy. I’m looking for the barrier to conversion between the 0.0 position and the 0.494 position.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [October 24, 2024, 8:16pm UTC](https://discourse.julialang.org/t/shortest-path-from-contour-plot/121719/2 "2024-10-24T20:16:38Z")

</div>

Hi welcome to the forum!

Your problem is not clear to me. What do you mean by “least energetic path”? Do I need to add up the values along the path? What “moves” are allowed?  
Perhaps you could provide a small example with solution?

---

<div class="post-metadata">

**Author:** ![sophibug](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sophibug/32/210241_2.png) [@sophibug](https://discourse.julialang.org/u/sophibug)\
**Post date:** [October 24, 2024, 9:09pm UTC](https://discourse.julialang.org/t/shortest-path-from-contour-plot/121719/3 "2024-10-24T21:09:59Z")

</div>

You can essentially think of it as a topographic map, where each number is an elevation. To get from one node to the next, you need to spend energy that’s the difference between the two nodes (climb uphill). Moving down releases energy and is always preferred (climb downhill). Moving in any direction is allowed (including diagonal), and I have empirical evidence the molecules do go from the 0.494 position to the 0.0 position.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 24, 2024, 9:33pm UTC](https://discourse.julialang.org/t/shortest-path-from-contour-plot/121719/4 "2024-10-24T21:33:21Z")

</div>

Check the package StringMethod.jl, and [the example](https://gideonsimpson.github.io/StringMethod.jl/dev/string1/) provided at the bottom of its doc’s page.
