Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/whitead/plumed_grids
A Python script to aid creating and manipulating the grids which are used by plumed and plumed2
https://github.com/whitead/plumed_grids
Last synced: about 1 month ago
JSON representation
A Python script to aid creating and manipulating the grids which are used by plumed and plumed2
- Host: GitHub
- URL: https://github.com/whitead/plumed_grids
- Owner: whitead
- License: gpl-2.0
- Created: 2015-07-06T20:01:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-08T18:29:47.000Z (almost 8 years ago)
- Last Synced: 2024-10-16T02:59:08.599Z (3 months ago)
- Language: Python
- Size: 762 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Plumed Grids
====A Python script to aid creating and manipulating the grids which are
used by plumed and plumed2. Just add the location of the folder to
your PYTHONPATH withexport PYTHONPATH=$PYTHONPATH:/path/to/this/repo
It does some nice things, but doesn't work with derivatives and does
not do spline interpolation.Quickstart
----```python
from plumed_grids import *#create empty grid
g = Grid()#read in a PLUMED grid. In this example, it's assumed to be 2D
g.read_plumed_grid('BIAS')#Add a pretty sunset to the bias
g.add_png_to_grid('sunset.png')#normalize it so it integrates to 1
g.normalize()
print g.integrate_all()#plot it to make sure it looks good
g.plot_2d('my_bias.png')#write it to be ready for plumed2
g.write_plumed2_grid('plumed_2.dat', names=['phi', 'psi', 'pot.target'])
```The Grid Object
---```python
g = Grid()
#Create grid by adding CVs. The name doesn't matter so much, but was tracked in PLUMED1 (not PLUMED2)
#After name comes min, max, nbins, and periodicity
g.add_cv('Absolute position', -155, 155, 1024, False)
g.add_cv('Absolute position', -155, 155, 1024, False)#add some values to bias using an image
g.add_png_to_grid('test.png')#see a summary
print g#see individual attributes
print g.nbins
print g.dims
print g.dx
print g.ncv#Write/Read
g.write_plumed1_grid('test_1.dat')
g2 = Grid()
g2.read_plumed1_grid('test_1.dat')#uses fuzzy floating point to test equality
#useful for testing (perhaps one day for unit tests of PLUMED/PLUMED2)
print g == g2```
Plumed 1 vs Plumed 2
----When writing files, you must specify with either `write_plumed1_grid`
or `write_plumed2_grid`. When reading, the generic `read_plumed_grid`
will infer the file type.When writing Plumed 2 grids, you can optionally specify names by
passing a list to the `write_plumed2_grid` methodIntegrals and Units
---It is always assumed that what is stored in the grid is -ln P(s) or F(s) / kT, where P(s) and F(s) are probability and free energy, respectively. To integrate we take e^(-V) of the values (V) stored and then return -log
of that integral. So, if units are in energy in kT, we integrate the
probability. This is the format used for experiment directed
metadynamics (EDM) as implemented in Plumed 2, Plumed 1, and the
electronic dance music lammps plugin.Regions
----```python
#Continuing the example from above:
#Create a function which returns True when in region or False
def ellipse_region(x, center, radii):
sum = 0
for xi, ci, ri in zip(x, center, radii):
sum += (xi - ci) ** 2 / ri ** 2
if(sum > 1):
return False
return True
#create a few particular ellipses
region1 = lambda x: ellipse_region(x, [0,0], [2.5, 5])
region2 = lambda x: ellipse_region(x, [-2,4], [2.5, 5])#plot them to make sure they're correct
g.plot_2d_region('region1.png', region1)
g.plot_2d_region('region2.png', region2)#get free energy difference between them
-np.log(g.integrate_region(region1)) + np.log(g.integrate_region(region2))
```Convert Plumed 1 to Plumed 2
----Note that the derivatives will not be transferred!
```python
g = Grid()
g.read_plumed1_grid('some_grid.dat')
g.write_plumed2_grid('some_grid2.dat', names = ['foo', 'bar', 'metad.target'])
```Manipulate Grids
----```python
g = Grid()#read in grid previosuly created to get its min/max/bins
g.read_plumed1_grid('bias.dat')#zero out its potential
g.pot[:,:] = 0#add a picture to it
g.add_png_to_grid('logo.png')
g.normalize()#Make it so that the maximum difference is 3 kT
diff = np.max(g.pot) - np.min(g.pot)
g.pot *= 3. / diff
g.pot -= np.max(g.pot)
g.plot_2d('logo-bias.png', axis=(0,1))
g.write_plumed1_grid(open('logo.dat', 'w'))
g.pot *= -kt
g.pot -= np.max(g.pot)
g.plot_2d('logo-fes.png',axis=(0,1))######################
g = Grid()
g.read_plumed2_grid('bias.dat')#Change the bin number with interpolation
g.set_bin_number( (1024, 1024) )#Stretch by 20%
g.stretch( (1.2, 1.2) )#Smooth the bias by adding a blur with a radius of 3 in x and 2 in y
g.gaussian_blur( (3,2) )#Extend the edge value outwards 20% so that there is a margin. Make it a whole number (pretty = True)
g.add_margin( (1.2, 1.2), pretty=True)```
Requirements
---Numpy, Scipy, Matplotlib (if plotting is used)
Disclaimer
----Grid orientation can be a funny thing. Please make sure by examining
the min/max and number of bins that your grid is correctly oriented in
PLUMED/PLUMED2 and when read into the python code. Plotting a lot
helps too.Cite
----This was created for helping in the experiment directed targeted
metadynamics work. Please cite:**Designing Free Energy Surfaces that Match Experimental Data with Metadynamics**. AD White, JF Dama, GA Voth. *J. Chem. Theory Comput.* **2015**, *11 (6)*, pp 2451-2460