Skip to content

Commit

Permalink
Merge pull request #75 from fhh2626/dev
Browse files Browse the repository at this point in the history
merge dev branch
  • Loading branch information
fhh2626 authored Dec 10, 2021
2 parents 3c46e36 + 55c6f97 commit 17787b2
Show file tree
Hide file tree
Showing 10 changed files with 885 additions and 247 deletions.
24 changes: 20 additions & 4 deletions BFEE2/commonTools/ploter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def readPMF(pmfFile):
pmfFile (str): path to the pmf File
Returns:
np.array (N * 2): 1D PMF
np.array (N*2): 1D PMF
"""

return np.loadtxt(pmfFile)
Expand All @@ -24,7 +24,7 @@ def mergePMF(pmfFiles):
pmfFiles (list of np.arrays): list of 1D pmfs
Returns:
np.array (N * 2): merged PMF if the PMFs overlap, pmfFiles[0] otherwise
np.array (N*2): merged PMF if the PMFs overlap, pmfFiles[0] otherwise
"""

numPmfs = len(pmfFiles)
Expand Down Expand Up @@ -57,7 +57,7 @@ def writePMF(pmfFile, pmf):
Args:
pmfFile (str): path to the pmf File
pmf np.array (N * 2): pmf to be written
pmf (np.array, N*2): pmf to be written
"""

np.savetxt(pmfFile, pmf, fmt='%g')
Expand All @@ -66,14 +66,30 @@ def plotPMF(pmf):
"""plot a pmf
Args:
pmf np.array (N * 2): pmf to be plotted
pmf (np.array, N*2): pmf to be plotted
"""

plt.plot(pmf[:,0], pmf[:,1])
plt.xlabel('Transition coordinate')
plt.ylabel('ΔG (kcal/mol)')
plt.show()

def plotHysteresis(forwardProfile, backwardProfile):
"""plot the profile describing the hysteresis between forward and backward
simulations
Args:
forwardProfile (np.array, N*2): forward free-energy profile to be plotted
backwardProfile (np.array, N*2): backward free-energy profile to be plotted
"""

plt.plot(forwardProfile[:,0], forwardProfile[:,1], label='Forward')
plt.plot(backwardProfile[:,0], backwardProfile[:,1], label='Backward')
plt.xlabel('Lambda')
plt.ylabel('ΔG (kcal/mol)')
plt.legend()
plt.show()

def calcRMSD(inputArray):
"""calculate RMSD of a np.array with respect to (0,0,0,...0)
Expand Down
73 changes: 73 additions & 0 deletions BFEE2/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import webbrowser

import numpy as np
# use appdirs to manage persistent configuration
from appdirs import user_config_dir
from PySide2 import QtCore
Expand Down Expand Up @@ -1151,9 +1152,38 @@ def _initQuickPlotTab(self):
self.mergePmfLayout.addLayout(self.mergePmfChildLayout)
self.mergePmf.setLayout(self.mergePmfLayout)

# plot hysteresis between forward and backward simulations
self.plotHysteresis = QGroupBox('Plot hysteresis between bidirectional simulations:')
self.plotHysteresisLayout = QVBoxLayout()

self.plotHysteresisForwardLayout = QHBoxLayout()
self.plotHysteresisForwardLabel = QLabel('Forward (fepout/log): ')
self.plotHysteresisForwardLineEdit = QLineEdit()
self.plotHysteresisForwardButton = QPushButton('Browse')
self.plotHysteresisForwardLayout.addWidget(self.plotHysteresisForwardLabel)
self.plotHysteresisForwardLayout.addWidget(self.plotHysteresisForwardLineEdit)
self.plotHysteresisForwardLayout.addWidget(self.plotHysteresisForwardButton)

self.plotHysteresisBackwardLayout = QHBoxLayout()
self.plotHysteresisBackwardLabel = QLabel('Backward (fepout/log):')
self.plotHysteresisBackwardLineEdit = QLineEdit()
self.plotHysteresisBackwardButton = QPushButton('Browse')
self.plotHysteresisBackwardLayout.addWidget(self.plotHysteresisBackwardLabel)
self.plotHysteresisBackwardLayout.addWidget(self.plotHysteresisBackwardLineEdit)
self.plotHysteresisBackwardLayout.addWidget(self.plotHysteresisBackwardButton)

self.plotHysteresisPlotButton = QPushButton('Plot')

self.plotHysteresisLayout.addLayout(self.plotHysteresisForwardLayout)
self.plotHysteresisLayout.addLayout(self.plotHysteresisBackwardLayout)
self.plotHysteresisLayout.addWidget(self.plotHysteresisPlotButton)

self.plotHysteresis.setLayout(self.plotHysteresisLayout)

self.quickPlotLayout.addWidget(self.plotPmf)
self.quickPlotLayout.addWidget(self.mergePmf)
self.quickPlotLayout.addWidget(self.plotPmfConvergence)
self.quickPlotLayout.addWidget(self.plotHysteresis)
self.quickPlot.setLayout(self.quickPlotLayout)

# slots are defined below
Expand Down Expand Up @@ -1760,6 +1790,46 @@ def f():
rmsds = ploter.parseHistFile(path)
ploter.plotConvergence(rmsds)
return f

def _plotHysteresis(self):
"""plot hysteresis between forward and backward alchemical transformations
Returns:
function obj: a slot function that plot hysteresis between forward and backward alchemical transformations
"""

def f():
forwardFilePath = self.plotHysteresisForwardLineEdit.text()
backwardFilePath = self.plotHysteresisBackwardLineEdit.text()
if not os.path.exists(forwardFilePath):
QMessageBox.warning(self, 'Error', f'file {forwardFilePath} does not exist!')
return
if not os.path.exists(backwardFilePath):
QMessageBox.warning(self, 'Error', f'file {backwardFilePath} does not exist!')
return

forwardPostfix = os.path.splitext(forwardFilePath)[-1]
backwardPostfix = os.path.splitext(backwardFilePath)[-1]

if forwardPostfix != '.fepout' and forwardPostfix != '.log' \
and backwardPostfix != '.fepout' and forwardPostfix != '.log':
QMessageBox.warning(self, 'Error', f'File type not correct!')
return

if forwardPostfix != backwardPostfix:
QMessageBox.warning(self, 'Error', f'File types of forward and backward simulations are not the same!')
return

pTreat = postTreatment.postTreatment(float(self.alchemicalPostTemperatureLineEdit.text()), 'namd', 'alchemical')
if forwardPostfix == '.fepout':
forwardProfile = np.transpose(pTreat._fepoutFile(forwardFilePath))
backwardProfile = np.transpose(pTreat._fepoutFile(backwardFilePath))
backwardProfile[:,1] *= -1
elif forwardPostfix == '.log':
forwardProfile = np.transpose(pTreat._tiLogFile(forwardFilePath))
backwardProfile = np.transpose(pTreat._tiLogFile(backwardFilePath))
ploter.plotHysteresis(forwardProfile, backwardProfile)
return f


def _initSingalsSlots(self):
Expand Down Expand Up @@ -1819,3 +1889,6 @@ def _initSingalsSlots(self):
self.mergePmfmergeButton.clicked.connect(self._mergePMFs())
self.plotPmfConvergenceBrowseButton.clicked.connect(commonSlots.openFileDialog('pmf', self.plotPmfConvergenceBox))
self.plotPmfConvergencePlotButton.clicked.connect(self._plotRMSDConvergence())
self.plotHysteresisForwardButton.clicked.connect(commonSlots.openFileDialog('fepout/log', self.plotHysteresisForwardLineEdit))
self.plotHysteresisBackwardButton.clicked.connect(commonSlots.openFileDialog('fepout/log', self.plotHysteresisBackwardLineEdit))
self.plotHysteresisPlotButton.clicked.connect(self._plotHysteresis())
Loading

0 comments on commit 17787b2

Please sign in to comment.