Skip to content

Commit

Permalink
Merge pull request #11 from anotherjoshsmith/parse_input
Browse files Browse the repository at this point in the history
Add input bias parser to core functions.
  • Loading branch information
anotherjoshsmith committed Apr 2, 2018
2 parents 6944772 + d7b28f1 commit d06ae9d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
47 changes: 47 additions & 0 deletions plumitas/core.py
@@ -1,4 +1,5 @@
import os
import re

import pandas as pd

Expand Down Expand Up @@ -68,3 +69,49 @@ def read_hills(filename='HILLS'):
CVs and bias as columns, time as index.
"""
return read_colvar(filename)


def parse_bias(filename='plumed.dat', method=None):
"""
Function that takes experimental data and gives us the
dependent/independent variables for analysis.
Parameters
----------
filename : string
Name of the plumed input file used for enhanced sampling run.
method : string
Name of bias method used during
Returns
-------
bias_args : dict
Dictionary of key: value pairs from the plumed.dat file. Will
facilitate automatic reading of parameter reading once
core.SamplingProject class is implemented.
"""
if not method:
print('Parser requires method to identify biased CVs. '
'Please retry with valid method arg.')
return

# read input file into string
full_path = os.path.abspath(filename)
input_string = ''
with open(full_path) as input_file:
for line in input_file:
input_string += line

# isolate bias section
method = method.upper()
bias_string = input_string.split(method)[1].lower()

# use regex to create dictionary of arguments
arguments = (re.findall(r'\w+=".+?"', bias_string)
+ re.findall(r'\w+=[\S.]+', bias_string))

# partition each match at '='
arguments = [(m.split('=')[0], m.split('=')[1].split(','))
for m in arguments]
bias_args = dict(arguments)

return bias_args
37 changes: 37 additions & 0 deletions plumitas/data/plumed.dat
@@ -0,0 +1,37 @@
RESTART
MOLINFO MOLTYPE=protein STRUCTURE=reference.pdb
WHOLEMOLECULES ENTITY0=1-55

CENTER ATOMS=20-28 LABEL=pos0
CENTER ATOMS=45-47 LABEL=neg0
dp0n0: DISTANCE ATOMS=pos0,neg0

#### DIHEDRALS ####
#phiA0: TORSION ATOMS=@phi-A2
psiA0: TORSION ATOMS=@psi-2
phiA1: TORSION ATOMS=@phi-3
psiA1: TORSION ATOMS=@psi-3
phiA2: TORSION ATOMS=@phi-4
#psiA2: TORSION ATOMS=@psi-A4

#### Water COORDINATION ####
GROUP ATOMS=21,24,25,27,28 LABEL=pos_H
GROUP ATOMS=46,47 LABEL=neg_O
GROUP ATOMS=56-4118:3 LABEL=sol_O

coord_H: COORDINATION GROUPA=pos_H GROUPB=sol_O D_0=0.19 R_0=0.03
coord_O: COORDINATION GROUPA=neg_O GROUPB=sol_O D_0=0.27 R_0=0.03

PBMETAD ...
ARG=dp0n0,psiA0,phiA1,psiA1,phiA2,coord_H,coord_O
PACE=500 BIASFACTOR=10.0 HEIGHT=2.0 TEMP=300.0
SIGMA=0.02,0.25,0.25,0.25,0.25,0.25,0.25
FILE=HILLS_MTD0,HILLS_psiA0,HILLS_phiA1,HILLS_psiA1,HILLS_phiA2,HILLS_coord_H,HILLS_coord_O
GRID_MIN=0,-pi,-pi,-pi,-pi,-2,-2
GRID_MAX=3.0,pi,pi,pi,pi,20,20
LABEL=pb
WALKERS_MPI
... PBMETAD

#make STRIDE = to your exchange attempt frequency!!!
PRINT FILE=COLVAR ARG=* STRIDE=500

0 comments on commit d06ae9d

Please sign in to comment.