Skip to content

Commit

Permalink
Merge pull request #82 from fhh2626/dev
Browse files Browse the repository at this point in the history
merge Dev branch
  • Loading branch information
fhh2626 authored Mar 26, 2022
2 parents e94cf2b + 7097c76 commit 92352ae
Show file tree
Hide file tree
Showing 16 changed files with 1,365 additions and 184 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@

*.pyc
# for ease of testing
/BFEE2Gui.py
/unitTest/exampleInputs
/unitTest/exampleOutputs
/unitTest/test_output
59 changes: 56 additions & 3 deletions BFEE2/commonTools/fileParser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# file parser used in bfee

import math
import os
import shutil
import sys

import MDAnalysis
from MDAnalysis import transformations
import numpy as np
import os, sys, math, shutil
import parmed
from MDAnalysis import transformations


# an runtime error
# selection corresponding to nothing
Expand Down Expand Up @@ -271,4 +277,51 @@ def centerSystem(self):
"""

vec = self.measurePBC()[1] * -1.0
self.moveSystem(vec)
self.moveSystem(vec)

def charmmToGromacs(psfFile, pdbFile, prmFiles, PBC, outputPrefix):
"""convert a set of CHARMM files (psf + pdb + prm + pbc) into the Gromacs format
Args:
psfFile (str): path of the psf file
pdbFile (str): path of the pdb file
prmFiles (list of str): pathes of the prm files
PBC (list of flost): pbc information
outputPrefix (str): path + prefix of the output file
"""
struct = parmed.load_file(psfFile)
struct.load_parameters(
parmed.charmm.CharmmParameterSet(*prmFiles)
)
struct.coordinates = parmed.load_file(pdbFile).coordinates
struct.box = [PBC[0], PBC[1], PBC[2], 90, 90, 90]
struct.save(f'{outputPrefix}.top', format='gromacs')
struct.save(f'{outputPrefix}.gro')

def amberToGromacs(parmFile, rstFile, PBC, outputPrefix):
"""convert a set of Amber files (parm7 + rst7) into the Gromacs format
Args:
parmFile (str): path of the parm7 file
rstFile (str): path of the rst7 file
PBC (list of flost): pbc information
outputPrefix (str): path + prefix of the output file
"""
struct = parmed.load_file(parmFile, xyz=rstFile)
struct.box = [PBC[0], PBC[1], PBC[2], 90, 90, 90]
struct.save(f'{outputPrefix}.top', format='gromacs')
struct.save(f'{outputPrefix}.gro')

def gromacsToAmber(topFile, groFile, PBC, outputPrefix):
"""convert a set of Gromacs files (top + gro/pdb) into the Amber format
Args:
topFile (str): path of the top file
groFile (str): path of the gro file
PBC (list of flost): pbc information
outputPrefix (str): path + prefix of the output file
"""
struct = parmed.load_file(topFile, xyz=groFile)
struct.box = [PBC[0], PBC[1], PBC[2], 90, 90, 90]
struct.save(f'{outputPrefix}.parm7', format='amber')
struct.save(f'{outputPrefix}.rst7', format='rst7')
84 changes: 73 additions & 11 deletions BFEE2/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,20 @@ def _initUI(self):

# compatibility
self.compatibility = QGroupBox('Compatibility')
self.compatibilityLayout = QHBoxLayout()
self.compatibilityLayout = QGridLayout()

self.pinDownProCheckbox = QCheckBox('Pinning down the protein')
self.pinDownProCheckbox.setChecked(True)

self.useOldCvCheckbox = QCheckBox('Use quaternion-based CVs')
self.useOldCvCheckbox.setChecked(True)

self.compatibilityLayout.addWidget(self.pinDownProCheckbox)
self.compatibilityLayout.addWidget(self.useOldCvCheckbox)

self.reflectingBoundaryCheckbox = QCheckBox('Use reflecting boundary')
self.reflectingBoundaryCheckbox.setChecked(False)

self.compatibilityLayout.addWidget(self.pinDownProCheckbox, 0, 0)
self.compatibilityLayout.addWidget(self.useOldCvCheckbox, 0, 1)
self.compatibilityLayout.addWidget(self.reflectingBoundaryCheckbox, 1, 0)
self.compatibility.setLayout(self.compatibilityLayout)

# membrane protein
Expand Down Expand Up @@ -386,7 +390,7 @@ def _initUI(self):

self.useOldCvCheckbox = QCheckBox('Use quaternion-based CVs')
self.useOldCvCheckbox.setChecked(True)

self.compatibilityLayout.addWidget(self.pinDownProCheckbox)
self.compatibilityLayout.addWidget(self.useOldCvCheckbox)
self.compatibility.setLayout(self.compatibilityLayout)
Expand Down Expand Up @@ -557,8 +561,8 @@ def _initPreTreatmentTab(self):
# NAMD and gromacs
self.preTreatmentMainTabs = QTabWidget()

self.preTreatmentMainTabs.addTab(self.NAMDTab, 'NAMD')
self.preTreatmentMainTabs.addTab(self.GromacsTab, 'Gromacs')
self.preTreatmentMainTabs.addTab(self.NAMDTab, 'NAMD/Gromacs(CHARMM/Amber files)')
self.preTreatmentMainTabs.addTab(self.GromacsTab, 'Gromacs(Gromacs files)')

self.preTreatmentMainLayout = QVBoxLayout()
self.preTreatmentMainLayout.addWidget(self.preTreatmentMainTabs)
Expand Down Expand Up @@ -590,13 +594,19 @@ def _initPreTreatmentTab(self):

# select strategy
self.selectStrategyLayout = QHBoxLayout()
self.selectStrategyLabel = QLabel('Select strategy: ')

self.selectStrategyLabel = QLabel('Select MD engine and strategy: ')
self.selectStrategyCombobox = QComboBox()
self.selectStrategyCombobox.addItem('Geometric')
self.selectStrategyCombobox.addItem('Alchemical')
self.selectStrategyAdvancedButton = QPushButton('Advanced settings')


self.selectMDEngineCombobox = QComboBox()
self.selectMDEngineCombobox.addItem('NAMD')
self.selectMDEngineCombobox.addItem('Gromacs')

self.selectStrategyChildLayout = QHBoxLayout()
self.selectStrategyChildLayout.addWidget(self.selectMDEngineCombobox)
self.selectStrategyChildLayout.addWidget(self.selectStrategyCombobox)
self.selectStrategyChildLayout.addWidget(self.selectStrategyAdvancedButton)

Expand Down Expand Up @@ -1220,6 +1230,41 @@ def _changeFFButtonState(self):
self.forceFieldAddButton.setEnabled(False)
self.forceFieldClearButton.setEnabled(False)
self.forceFieldFilesBox.setEnabled(False)

def _changeStrategySettingState(self):
"""enable/disable the alchemical route and some advanced settings based on the MD engine
"""

if self.selectMDEngineCombobox.currentText() == 'NAMD':
self.selectStrategyCombobox.setEnabled(True)
self.geometricAdvancedSettings.useOldCvCheckbox.setEnabled(True)

elif self.selectMDEngineCombobox.currentText() == 'Gromacs':
index = self.selectStrategyCombobox.findText('Geometric', QtCore.Qt.MatchFixedString)
if index >= 0:
self.selectStrategyCombobox.setCurrentIndex(index)
self.selectStrategyCombobox.setEnabled(False)

def _changeStrategySettingStateForOldGromacs(self):
"""enable/disable a lot of options for the old Gromacs tab
"""

if self.preTreatmentMainTabs.currentWidget() == self.NAMDTab:
self.selectStrategyAdvancedButton.setEnabled(True)
self.selectMDEngineCombobox.setEnabled(True)

elif self.preTreatmentMainTabs.currentWidget() == self.GromacsTab:
index = self.selectMDEngineCombobox.findText('Gromacs', QtCore.Qt.MatchFixedString)
if index >= 0:
self.selectMDEngineCombobox.setCurrentIndex(index)

index = self.selectStrategyCombobox.findText('Geometric', QtCore.Qt.MatchFixedString)
if index >= 0:
self.selectStrategyCombobox.setCurrentIndex(index)

self.selectMDEngineCombobox.setEnabled(False)
self.selectStrategyCombobox.setEnabled(False)
self.selectStrategyAdvancedButton.setEnabled(False)

def _openDocFile(self):
"""open Documentation file
Expand Down Expand Up @@ -1514,6 +1559,14 @@ def f():
return

if self.selectStrategyCombobox.currentText() == 'Geometric':

if self.selectMDEngineCombobox.currentText().lower() == 'gromacs':
QMessageBox.warning(
self, 'Warning', f'Please pay attention if you use the new Gromacs interface: \n\
1. Occationally, the atom number in complex.ndx do not correct. If so, just modify it manually; \n\
2. Make sure in complex.gro, the center of box is approximately at (x/2, y/2, z/2) rather than (0, 0, 0); \n\
3. Gromacs patched by the latest (master branch) version of Colvars is needed.'
)

# for the amber force field, files of large box must be provided
if forceFieldType == 'amber':
Expand Down Expand Up @@ -1549,7 +1602,9 @@ def f():
self.geometricAdvancedSettings.pinDownProCheckbox.isChecked(),
self.geometricAdvancedSettings.useOldCvCheckbox.isChecked(),
int(self.geometricAdvancedSettings.parallelRunsLineEdit.text()),
self.mainSettings.vmdLineEdit.text()
self.mainSettings.vmdLineEdit.text(),
self.geometricAdvancedSettings.reflectingBoundaryCheckbox.isChecked(),
self.selectMDEngineCombobox.currentText().lower()
)
except fileParser.SelectionError:
QMessageBox.warning(
Expand Down Expand Up @@ -1671,7 +1726,10 @@ def f():
# gromacs
if self.preTreatmentMainTabs.currentIndex() == 1:

QMessageBox.warning(self, 'Warning', f'Any setting in "Advanced settings" is not supported by Gromacs!')
QMessageBox.warning(
self, 'Warning', f'Any setting in "Advanced settings" is not supported \n\
when using Gromacs-formatted files as inputs!'
)

for item in [
self.topLineEdit.text(),
Expand Down Expand Up @@ -1838,6 +1896,7 @@ def _initSingalsSlots(self):

# pre-treatment tab
self.selectStrategyAdvancedButton.clicked.connect(self._advancedSettings(self.selectStrategyCombobox))
self.preTreatmentMainTabs.currentChanged.connect(self._changeStrategySettingStateForOldGromacs)

# NAMD tab
self.psfButton.clicked.connect(commonSlots.openFileDialog('psf/parm', self.psfLineEdit))
Expand All @@ -1847,6 +1906,9 @@ def _initSingalsSlots(self):
self.forceFieldCombobox.currentTextChanged.connect(self._changeFFButtonState)
self.forceFieldAddButton.clicked.connect(commonSlots.openFilesDialog('prm', self.forceFieldFilesBox))
self.forceFieldClearButton.clicked.connect(self.forceFieldFilesBox.clear)

# MD engine
self.selectMDEngineCombobox.currentTextChanged.connect(self._changeStrategySettingState)

# gromacs tab
self.gromacsPdbButton.clicked.connect(commonSlots.openFileDialog('pdb', self.gromacsPdbLineEdit))
Expand Down
Loading

0 comments on commit 92352ae

Please sign in to comment.