<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wikis.ch.cam.ac.uk/ro-walesdocs/wiki/index.php?action=history&amp;feed=atom&amp;title=Python_interface_for_GMIN%2FOPTIM</id>
	<title>Python interface for GMIN/OPTIM - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wikis.ch.cam.ac.uk/ro-walesdocs/wiki/index.php?action=history&amp;feed=atom&amp;title=Python_interface_for_GMIN%2FOPTIM"/>
	<link rel="alternate" type="text/html" href="https://wikis.ch.cam.ac.uk/ro-walesdocs/wiki/index.php?title=Python_interface_for_GMIN/OPTIM&amp;action=history"/>
	<updated>2026-04-12T04:35:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.7</generator>
	<entry>
		<id>https://wikis.ch.cam.ac.uk/ro-walesdocs/wiki/index.php?title=Python_interface_for_GMIN/OPTIM&amp;diff=1176&amp;oldid=prev</id>
		<title>Adk44: Created page with &quot;= Introduction &amp; Motivation = GMIN can be compiled as a python interface. Use the cmake option -DWITH_PYTHON. The goal of this interface is to allow for quick testing of new i...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wikis.ch.cam.ac.uk/ro-walesdocs/wiki/index.php?title=Python_interface_for_GMIN/OPTIM&amp;diff=1176&amp;oldid=prev"/>
		<updated>2019-05-10T17:18:52Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Introduction &amp;amp; Motivation = GMIN can be compiled as a python interface. Use the cmake option -DWITH_PYTHON. The goal of this interface is to allow for quick testing of new i...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Introduction &amp;amp; Motivation =&lt;br /&gt;
GMIN can be compiled as a python interface. Use the cmake option -DWITH_PYTHON. The goal of this interface is to allow for quick testing of new ideas before implementing them in Fortran. There is no need to recompile the code during testing and python offers a huge selection of 3rd party libraries. &lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
The strategy for the python hook is similar to that of the testing framework: call the main rountine, let it read the data file and initialize all the structures, then stop and go back to the python interpreter. The main file for the interface is automatically generated from main.F using a set of sed command. This part is then called from python by pygmin.init()&lt;br /&gt;
&lt;br /&gt;
Hopefully this interface will help modularizing the GMIN/OPTIM codebase a bit more.&lt;br /&gt;
&lt;br /&gt;
= Example =&lt;br /&gt;
Once compiled, set the python path to the directory which contains the newly generated pygmin.so. Then it can be used, as in the following example script&lt;br /&gt;
&lt;br /&gt;
 import pygmin&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 &lt;br /&gt;
 # parse the data file and setup all gmin structures&lt;br /&gt;
 pygmin.init()&lt;br /&gt;
 &lt;br /&gt;
 # get the number of atoms&lt;br /&gt;
 natoms = pygmin.getNAtoms()&lt;br /&gt;
 &lt;br /&gt;
 # initialize array with random coordinates&lt;br /&gt;
 x = np.random.random(3*natoms)&lt;br /&gt;
 &lt;br /&gt;
 # calculate the energy&lt;br /&gt;
 print pygmin.getEnergy(x)&lt;br /&gt;
 &lt;br /&gt;
 # initialize gradient array&lt;br /&gt;
 g = np.zeros(x.shape)&lt;br /&gt;
 &lt;br /&gt;
 # calculate energy and gradient&lt;br /&gt;
 print pygmin.getEnergyGradient(x, g)&lt;br /&gt;
 print g&lt;br /&gt;
&lt;br /&gt;
= Known problems =&lt;br /&gt;
* Compilation only tested using gfortran&lt;br /&gt;
* If you get an error during linking, stating something with -fPIC, add -fPIC to CMAKE_CXX_FLAGS, CMAKE_FORTRAN_FLAGS, CMAKE_C_FLAGS&lt;/div&gt;</summary>
		<author><name>Adk44</name></author>
	</entry>
</feed>