-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexponential_average.py
executable file
·63 lines (45 loc) · 1.49 KB
/
exponential_average.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /Users/mikicanyelles/.pyenv/shims/python
from scipy import constants
import argparse
from math import exp, log
R = constants.R/4184
def sum(values):
sum = 0
for v in values:
sum += float(v)
return sum
def calculate_exponential_average(temp, barriers, R=R):
exp_factors = []
for barrier in barriers:
exp_factors.append(
exp(
(-float(barrier)/
(R*temp))
)
)
exp_avg = -R*temp*log((1/len(barriers))*sum(exp_factors))
return exp_avg
if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog='exponential_average',
description='Python script for calculating exponential averages of barriers'
)
parser.add_argument(
'-T', '--temperature',
default=298,
type=float,
help='Option to input the temperature (in K) for obtaining the exponential average energy barrier. By default the value is 298 K.'
)
parser.add_argument(
#'-b', '--barriers',
'barriers',
metavar='barriers',
action='store',
type=str,
nargs='+',
help='List of single energy barriers (in kcal/mol)',
#required=True
)
args = vars(parser.parse_args())
args['barriers'] = args['barriers'][0].split()
print('The exponential barrier at %s K is:' % args['temperature'], round(calculate_exponential_average(args['temperature'], args['barriers']), 2), 'kcal/mol')