Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8 #13

Merged
merged 1 commit into from
Nov 6, 2022
Merged

PEP8 #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions safep/TI.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import numpy as np


def processTI(dataTI, restraint, Lsched):
def process_TI(dataTI, restraint, Lsched):
'''
Arguments: the TI data, restraint, and lambda schedule
Function: Calculate the free energy for each lambda value, aggregate the result, and estimate the error
Returns: The free energies and associated errors as functions of lambda. Both per window and cumulative.
'''
dUs = {}
for key, group in dataTI.groupby('L'):
dUs[key] = [HW_dUdL(restraint, coord, key) for coord in group.DBC]
dUs[key] = [harmonicWall_dUdL(restraint, coord, key) for coord in group.DBC]

Lsched = np.sort(list(dUs.keys()))
dL = Lsched[1] - Lsched[0]
Expand All @@ -27,7 +27,7 @@ def processTI(dataTI, restraint, Lsched):
return TIperWindow, TIcumulative


def plotTI(cumulative, perWindow, width=8, height=4, PDFtype='KDE', hystLim=(-1,1), color='#0072B2'):
def plot_TI(cumulative, perWindow, width=8, height=4, PDFtype='KDE', hystLim=(-1,1), color='#0072B2'):
fig, (cumAx,eachAx) = plt.subplots(2,1, sharex='col')

# Cumulative change in kcal/mol
Expand All @@ -47,11 +47,11 @@ def plotTI(cumulative, perWindow, width=8, height=4, PDFtype='KDE', hystLim=(-1,

return fig, [cumAx,eachAx]

def makeHarmonicWall(FC=10, targetFC=0, targetFE=1, upperWalls=1, schedule=None, numSteps=1000, targetEQ=500, name='HW', lowerWalls=None):
def make_harmonicWall(FC=10, targetFC=0, targetFE=1, upperWalls=1, schedule=None, numSteps=1000, targetEQ=500, name='HW', lowerWalls=None):
HW = {'name':name, 'targetFC':targetFC, 'targetFE':targetFE, 'FC':FC, 'upperWalls':upperWalls, 'schedule':schedule, 'numSteps':numSteps, 'targetEQ':targetEQ, 'lowerWalls':lowerWalls}
return HW

def HW_U(HW, coord, L):
def harmonicWall_U(HW, coord, L):
d=0
if HW['upperWalls'] and coord>HW['upperWalls']:
d = coord-HW['upperWalls']
Expand All @@ -67,7 +67,7 @@ def HW_U(HW, coord, L):
U=0
return U

def HW_dUdL(HW, coord, L):
def harmonicWall_dUdL(HW, coord, L):
d=0
if HW['upperWalls'] and coord>HW['upperWalls']:
d = coord-HW['upperWalls']
Expand Down
6 changes: 3 additions & 3 deletions safep/estimators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .helpers import *


def get_EXP(u_nk):
def get_exponential(u_nk):
'''
Get exponential estimation of the change in free energy.
Arguments: u_nk in alchemlyb format
Expand Down Expand Up @@ -96,7 +96,7 @@ def do_estimation(u_nk, method='both'):
perWindow.index = l_mids

if method=='both' or method=='EXP':
expl, expmid, dG_fs, dG_bs = get_EXP(u_nk)
expl, expmid, dG_fs, dG_bs = get_exponential(u_nk)

cumulative[('EXP', 'ff')] = np.insert(np.cumsum(dG_fs),0,0)
cumulative[('EXP', 'fb')] = np.insert(-np.cumsum(dG_bs),0,0)
Expand All @@ -117,7 +117,7 @@ def do_estimation(u_nk, method='both'):


#Light-weight exponential estimator. Requires alternative parser.
def get_dG_fromData(data, temperature):
def get_dG_from_data(data, temperature):
from scipy.constants import R, calorie
beta = 1/(R/(1000*calorie) * temperature) #So that the final result is in kcal/mol

Expand Down
14 changes: 7 additions & 7 deletions safep/fileIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .helpers import *


def guessLambda(fname):
def guess_lambda(fname):
'''
Guess lambda based on file name (last number in the filename divided by 100). Not very good.
Arguments: file name
Expand All @@ -36,14 +36,14 @@ def guessLambda(fname):
L = int(re.findall(r'\d+', fname)[-1])/100
return L

def saveUNK(u_nk, filepath):
def save_UNK(u_nk, filepath):
'''
Write u_nk to a file
Arguments: u_nk in the format of alchemlyb, filepath
'''
u_nk.to_csv(filepath)

def readUNK(filepath):
def read_UNK(filepath):
'''
Read a u_nk that was written by saveUNK.
Arguments: filepath
Expand All @@ -56,7 +56,7 @@ def readUNK(filepath):
return u_nk.copy()


def readFEPOUT(fileName, step=1):
def read_FEPOUT(fileName, step=1):
'''
Reads all data from a NAMD fepout file unlike alchemlyb's parser.
readFEPOUT reads each file in a single pass: keeping track of lambda values and appending each line to an array.
Expand Down Expand Up @@ -93,7 +93,7 @@ def readFEPOUT(fileName, step=1):
elif frame % step <= 1:
if np.isnan(L):
print("WARNING: lambda is not defined!")
L = guessLambda(fileName)
L = guess_lambda(fileName)
print("Guessing lambda to be {L} based on file name.")


Expand Down Expand Up @@ -126,15 +126,15 @@ def readFEPOUT(fileName, step=1):
df = df.sort_index()
return df

def readFiles(files, step=1):
def read_Files(files, step=1):
'''
Batch readFEPOUT
Arguments: file (paths), step (stride)
Returns: a list of dataframes, one dataframe per file
'''
fileList = []
for file in files:
df = readFEPOUT(file, step)
df = read_FEPOUT(file, step)
fileList.append(df)
data = pd.concat(fileList)

Expand Down
6 changes: 3 additions & 3 deletions safep/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from glob import glob #file regexes

# Calculate the coefficient of determination:
def GetRsq(X, Y, Yexpected):
def get_Rsq(X, Y, Yexpected):
'''
Calculate the coefficient of determination for arbitrary fits.
Arguments: X (inputs), Y (experimental data), Yexpected (fitted or predicted data)
Expand All @@ -37,14 +37,14 @@ def GetRsq(X, Y, Yexpected):
return R

#Wrappers
def cumFn(x, m, s):
def cum_Fn(x, m, s):
'''
Wrapper for the normal cumulative density function
'''
r = norm.cdf(x, m, s)
return r

def pdfFn(x,m,s):
def pdf_Fn(x,m,s):
'''
Wrapper for the normal probability density function
'''
Expand Down
30 changes: 5 additions & 25 deletions safep/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from scipy.special import erfc
from scipy.optimize import curve_fit as scipyFit
from scipy.stats import skew
import scipy as sp

import pandas as pd

Expand All @@ -27,7 +28,7 @@
from .helpers import *


def convergencePlot(theax, fs, ferr, bs, berr, fwdColor='#0072B2', bwdColor='#D55E00', lgndF=None, lgndB=None):
def convergence_plot(theax, fs, ferr, bs, berr, fwdColor='#0072B2', bwdColor='#D55E00', lgndF=None, lgndB=None):
'''
A revised convergence plot. Plays nicely with other plotting functions and is more customizable.
Arguments: theax[is] on which to plot, fs (forward estimates), ferr (forward errors), bs (backward-sampled estimates), berr (backward-sampled errors), fwdColor, bwdColor, lgndF legend forward color, lgndB legend backward color
Expand All @@ -49,7 +50,7 @@ def convergencePlot(theax, fs, ferr, bs, berr, fwdColor='#0072B2', bwdColor='#D5

return theax

def doConvPlot(ax, X, fs, ferr, fwdColor, label=None):
def do_conv_plot(ax, X, fs, ferr, fwdColor, label=None):
'''
A minimalist convergence plot
Arguments: ax[is], X (the X values), fs (forward estimates), ferr (forward errors), fwdColor (the forward color), label text
Expand All @@ -58,29 +59,8 @@ def doConvPlot(ax, X, fs, ferr, fwdColor, label=None):
ax.errorbar(X, fs, yerr=ferr, marker=None, linewidth=1, color=fwdColor, markerfacecolor='white', markeredgewidth=1, markeredgecolor=fwdColor, ms=5, label=label)
return ax

#Cannonical convergence plot
def convergence_plot(u_nk, tau=1, units='kT', RT=0.59):
'''
Older convergence plot. Does the convergence calculation and plotting. Deprecated.
Arguments: u_nk, tau (an error tuning factor), units (kT or kcal/mol), RT
Returns: a pyplot
'''
forward, forward_error, backward, backward_error = doConvergence(u_nk, num_points=10)

if units=='kcal/mol':
forward = forward*RT
forward_error = forward_error*RT
backward = backward*RT
backward_error = backward_error*RT

ax = plot_convergence(forward, forward_error, backward, backward_error)

if units=='kcal/mol':
ax.set(ylabel=r'$\rm\Delta G$'+'\n(kcal/mol)')

return plt.gca()

def convergencePlot(theax, fs, ferr, bs, berr, fwdColor='#0072B2', bwdColor='#D55E00', lgndF=None, lgndB=None):
def convergence_plot(theax, fs, ferr, bs, berr, fwdColor='#0072B2', bwdColor='#D55E00', lgndF=None, lgndB=None):
'''
Convergence plot. Does the convergence calculation and plotting.
Arguments: u_nk, tau (an error tuning factor), units (kT or kcal/mol), RT
Expand Down Expand Up @@ -138,7 +118,7 @@ def fb_discrepancy_hist(dG_f, dG_b):
return plt.gca()


def plotGeneral(cumulative, cumulativeYlim, perWindow, perWindowYlim, RT, width=8, height=4, PDFtype='KDE'):
def plot_general(cumulative, cumulativeYlim, perWindow, perWindowYlim, RT, width=8, height=4, PDFtype='KDE'):
fig, ((cumAx, del1),( eachAx, del2), (ddGAx, del3), (hystAx, pdfAx)) = plt.subplots(4,2, sharex='col', sharey='row', gridspec_kw={'width_ratios': [2, 1]})

fig.delaxes(del1)
Expand Down
Loading