Skip to content

Commit

Permalink
Merge pull request #39 from fhh2626/dev
Browse files Browse the repository at this point in the history
merge Dev branch
  • Loading branch information
fhh2626 authored Apr 5, 2021
2 parents e6c93f6 + 9e3136e commit 67880d1
Show file tree
Hide file tree
Showing 9 changed files with 983 additions and 687 deletions.
379 changes: 167 additions & 212 deletions BFEE2/BFEEGromacs.py

Large diffs are not rendered by default.

32 changes: 22 additions & 10 deletions BFEE2/commonTools/commonSlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
from PySide2.QtWidgets import QLineEdit, QFileDialog, QMessageBox

def openFileDialog(fileType, lineEdit):
''' return a openFile function that opens special type of files
the openFile dialog is connected with a lineEdit widget
inputs:
fileType (string): the file type for opening
lineEdit (QLineEdit): the QLineEdit that connects to the QFileDialog '''
"""return a openFile function that opens special type of files
the openFile dialog is connected with a lineEdit widget
Args:
fileType (str): the file type for opening
lineEdit (QLineEdit): the QLineEdit that connects to the QFileDialog
Returns:
function obj: slot function opening special type of files
"""

def openFile():
fileName, _ = QFileDialog.getOpenFileName(
None,
Expand All @@ -20,11 +26,17 @@ def openFile():
return openFile

def openFilesDialog(fileType, listWidget):
''' return a openFile function that opens a series of files
the openFile dialog is connected with a QListWidget
inputs:
fileType (string): the file type for opening
listWidget (QListWidget): the QListWidget that connects to the QFileDialog '''
"""return a openFile function that opens a series of files
the openFile dialog is connected with a QListWidget
Args:
fileType (str): the file type for opening
listWidget (QListWidget): the QListWidget that connects to the QFileDialog
Returns:
function obj: slot function opening a series of files
"""

def openFiles():

fileNames, _ = QFileDialog.getOpenFileNames(
Expand Down
186 changes: 118 additions & 68 deletions BFEE2/commonTools/fileParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ def __init__(self, arg):
self.args = arg

class fileParser:
''' topology and coordinate parser,
this class implements basic method for the topology and
coordinate file, used by BFEE '''
"""topology and coordinate parser,
this class implements basic method for the topology and
coordinate file, used by BFEE
"""

def __init__(self, topFile, coorFile=''):
''' initialize fileParser, on coorFile is not provided, then
topFile is considered as a top-coor file, such as mol2
inputs:
topFile (string): path of the topology (psf, parm) file
coorFile (string): path of the coordinate (pdb, rst) file '''
"""initialize fileParser, on coorFile is not provided, then
topFile is considered as a top-coor file, such as mol2
Args:
topFile (str): path of the topology (psf, parm) file
coorFile (str): path of the coordinate (pdb, rst) file. Defaults to ''.
"""

coorPostfix = os.path.splitext(coorFile)[-1]
if coorPostfix == '.rst7' or coorPostfix == '.rst' or coorPostfix == '.inpcrd':
Expand All @@ -41,15 +44,20 @@ def __init__(self, topFile, coorFile=''):
self.topPath = topFile

def saveFile(self, selection, targetPath, targetType, saveTop=False, topPath=''):
''' save the coordinate file to the target type
this function cannot really 'save' the topology file,
it can only copy the original topology to the target path
inputs:
selection (string): selection of atoms to save
targetPath (string): path for the coor file to be saved
targetType (string): type of the coor file (pdb, xyz)
saveTop (bool): whether the topology file will be saved
topPath (string): path for the topology file to be saved '''
"""save the coordinate file to the target type
this function cannot really 'save' the topology file,
it can only copy the original topology to the target path
Args:
selection (str): selection of atoms to save
targetPath (str): path for the coor file to be saved
targetType (str): type of the coor file (pdb, xyz)
saveTop (bool): whether the topology file will be saved. Defaults to False.
topPath (str, optional): path for the topology file to be saved. Defaults to ''.
Raises:
SelectionError: if the selection corresponds to nothing
"""

atoms = self.uObject.select_atoms(selection)

Expand All @@ -62,11 +70,17 @@ def saveFile(self, selection, targetPath, targetType, saveTop=False, topPath='')
shutil.copyfile(self.topPath, topPath)

def saveNDX(self, selections, names, targetPath, nonHydrogen=True):
''' save an ndx file, including the selections
inputs:
selections (list of strings): the selections for the ndx file
names (list of strings): the name in ndx of each selection
targetPath (string): path for the file to be saved'''
"""save an ndx file, including the selections
Args:
selections (list of str): the selections for the ndx file
names (list of str): the name in ndx of each selection
targetPath (str): path for the file to be saved
nonHydrogen (bool, optional): whether only non-H atoms are considered. Defaults to True.
Raises:
SelectionError: if the selection corresponds to nothing
"""

assert(len(selections) == len(names))

Expand All @@ -84,12 +98,19 @@ def saveNDX(self, selections, names, targetPath, nonHydrogen=True):
atoms.write(targetPath, 'ndx', name=name, mode='a')

def getResid(self, selection):
''' return a string listing the resid of the selection
may be used to generate amber masks
Inputs:
selection (string): MDAnalysis selection
Return:
string: a list of resid, e.g. (4,5,6,7,8,9,10) '''
"""return a string listing the resid of the selection
may be used to generate amber masks
Args:
selection (str): MDAnalysis selection
Raises:
SelectionError: if the selection corresponds to nothing
Returns:
str: a list of resid, e.g. (4,5,6,7,8,9,10)
"""

atoms = self.uObject.select_atoms(selection)

if len(atoms) == 0:
Expand All @@ -98,11 +119,17 @@ def getResid(self, selection):
return ','.join([str(num+1) for num in atoms.residues.ix])

def measureMinmax(self, selection):
''' mimic VMD measure minmax
inputs:
selection (string): selection of atoms
return:
np.array (2*3, float): ((minX, minY, minZ), (maxX, maxY, maxZ)) '''
"""mimic VMD measure minmax
Args:
selection (str): selection of atoms
Raises:
SelectionError: if the selection corresponds to nothing
Returns:
np.array (2*3, float): ((minX, minY, minZ), (maxX, maxY, maxZ))
"""

atoms = self.uObject.select_atoms(selection)

Expand All @@ -121,11 +148,17 @@ def measureMinmax(self, selection):
return np.array([[min_x, min_y, min_z],[max_x, max_y, max_z]])

def measureCenter(self, selection):
''' mimic vmd measure center
inputs:
selection (string): selection of atoms
return:
np.array (3, float): (x, y, z) '''
"""mimic vmd measure center
Args:
selection (str): selection of atoms
Raises:
SelectionError: if the selection corresponds to nothing
Returns:
np.array (3, float): (x, y, z)
"""

atoms = self.uObject.select_atoms(selection)

Expand All @@ -141,23 +174,27 @@ def measureCenter(self, selection):
return np.array([center_x, center_y, center_z])

def measureDistance(self, selection1, selection2):
''' measure the distance between the center of mass
of two atom groups
Inputs:
selection1 (string): selection of atom group 1
selection2 (string): selection of atom group 2
Return:
float: distance between the center of mass of the
two atom groups '''
"""measure the distance between the center of mass
of two atom groups
Args:
selection1 (str): selection of atom group 1
selection2 (str): selection of atom group 2
Returns:
float: distance between the center of mass of the two atom groups
"""

center1 = self.measureCenter(selection1)
center2 = self.measureCenter(selection2)
return round(np.linalg.norm(center2 - center1), 1)

def measurePBC(self):
''' measure periodic boundary condition of the file
return:
np.array (2*3, float): ((lengthX, lengthY, lengthZ), (centerX, centerY, centerZ)) '''
"""measure periodic boundary condition of the file
Returns:
np.array (2*3, float): ((lengthX, lengthY, lengthZ), (centerX, centerY, centerZ))
"""

minmaxArray = self.measureMinmax('all')
vec = minmaxArray[1] - minmaxArray[0]
Expand All @@ -166,23 +203,31 @@ def measurePBC(self):
return np.array((vec, center))

def measurePolarAngles(self, selectionPro, selectionLig):
''' calculation the polar angles based on selectionPro and selectionLig
inputs:
selectionPro (string): selection of the host molecule
selectionLig (string): selection of the ligand molecule
return:
np.array (2, float): (theta, phi) in degrees'''
"""calculation the polar angles based on selectionPro and selectionLig
Args:
selectionPro (str): selection of the host molecule
selectionLig (str): selection of the ligand molecule
Returns:
np.array (2, float): (theta, phi) in degrees
"""

vector = self.measureCenter(selectionLig) - self.measureCenter(selectionPro)
vector /= np.linalg.norm(vector)

return (float(int(math.degrees(np.arccos(-vector[1])))), float(int(math.degrees(np.arctan2(vector[2], vector[0])))))

def setBeta(self, selection, beta):
''' set beta for the selected atoms
Inputs:
selection (string): selection of atoms to change beta
beta (int): beta value '''
"""set beta for the selected atoms
Args:
selection (str): selection of atoms to change beta
beta (int): beta value
Raises:
SelectionError: if the selection corresponds to nothing
"""

atoms = self.uObject.select_atoms(selection)

Expand All @@ -192,18 +237,22 @@ def setBeta(self, selection, beta):
atoms.tempfactors = beta

def moveSystem(self, moveVector):
''' move all the atoms in the loaded file
inputs:
moveVector (np.array, 3, float): the vector of moving '''
"""move all the atoms in the loaded file
Args:
moveVector (np.array, 3, float): the vector of moving
"""

allAtoms = self.uObject.select_atoms('all')
transformations.translate(moveVector)(allAtoms)

def rotateSystem(self, axis, degrees):
''' rotate all the atoms in the loaded file
inputs:
axis (string): 'x' or 'y' or 'z'
degrees (float): degrees to move by '''
"""rotate all the atoms in the loaded file
Args:
axis (str): 'x' or 'y' or 'z'
degrees (float): degrees to move by
"""

assert(axis == 'x' or axis == 'y' or axis == 'z')

Expand All @@ -217,8 +266,9 @@ def rotateSystem(self, axis, degrees):
transformations.rotate.rotateby(degrees, axisVector, ag=allAtoms)(allAtoms)

def centerSystem(self):
''' move all the atoms in the loaded file,
such that the center of system be (0,0,0) '''
"""move all the atoms in the loaded file,
such that the center of system be (0,0,0)
"""

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

0 comments on commit 67880d1

Please sign in to comment.