Skip to content

Commit

Permalink
Minor changes and refactoring.
Browse files Browse the repository at this point in the history
- Added helper function for initializing the logger in Qpyl.common
- Added torsion calculations and fixed rmsd in Qpyl.core.qcalc
- Added some newly implemented parameter keywords to Qpyl.core.qdyninp
- Fatal errors due to 'bad' inputs/keywords in Qpyl.core.qdyninp /
  Qpyl.qgeninp / q_genrelax.py / q_genfeps.py can now be bypassed with
  ignore_errors / --ignore_errors
  • Loading branch information
Miha Purg committed Jun 24, 2017
1 parent f10a6f0 commit 76475e9
Show file tree
Hide file tree
Showing 18 changed files with 373 additions and 258 deletions.
36 changes: 35 additions & 1 deletion packages/Qpyl/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# Some common classes and functions

import math
import sys
import os
import shutil
import logging
Expand All @@ -50,7 +51,40 @@ def format(self, record):
return logging.Formatter.format(self, record)


def raise_or_log(message, exception_class, logger, ignore_errors=False):
def init_logger(name,
level=None,
handler=None,
formatter=None):
"""Helper function for initializing the logger.
Args:
name (string): module name, usually root: 'Qpyl'
level (int, optional): logging level (DEBUG, INFO, WARNING...),
default is INFO
handler: (logging.Handler, optional): default is
StreamHandler(sys.stdout)
formatter: (logging.Formatter, optional): default is
SpecialFormatter
Returns:
lg (logging.Logger)
"""
lg = logging.getLogger(name)
if level == None:
level = logging.INFO
lg.setLevel(level)

if handler == None:
handler = logging.StreamHandler(sys.stdout)
if formatter == None:
handler.setFormatter(SpecialFormatter())

lg.addHandler(handler)
return lg


def raise_or_log(message, exception_class, logger, ignore_errors):
"""Method used for raising exceptions or writting them to logger instead
This way one can bypass certain exceptions like non-integer charge groups,
Expand Down
31 changes: 25 additions & 6 deletions packages/Qpyl/core/qcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ def run(self, qcalc_input_str, workdir=None):
# "\n" is added to fix the blocking qcalc5 issue
stdout, stderr = self.process.communicate(qcalc_input_str + "\n")

# not sure if this ever happens, but will keep it anyway
if stderr:
raise QCalcError("QCalc wrote to STDERR: {}".format(stderr))

# stderr is useless in qcalc5
return stdout


Expand Down Expand Up @@ -128,7 +125,22 @@ def add_angle(self, atom1, atom2, atom3):
"""
self.actions.append((self.CALC_ANGLE, ["{} {} {}".format(atom1,
atom2)]))
atom2,
atom3)]))
def add_torsion(self, atom1, atom2, atom3, atom4):
"""Add a torsion/torsion_energy calculation.
Args:
atom1 (int): index of atom in topology
atom2 (int): index of atom in topology
atom3 (int): index of atom in topology
atom4 (int): index of atom in topology
"""
self.actions.append((self.CALC_TORSION,
["{} {} {} {}".format(atom1, atom2,
atom3, atom4)]))


def add_rmsd(self, masks):
"""Add a RMSD calculation.
Expand All @@ -139,7 +151,8 @@ def add_rmsd(self, masks):
"""
if isinstance(masks, basestring):
masks = [masks,]
self.actions.append((self.CALC_RMSD, "rmsd.out", masks + ["."]))
# rmsd.out is due to the unfortunate feature added in Q c79ef672400
self.actions.append((self.CALC_RMSD, masks + [".",] + ["rmsd.out",]))

def add_residue_nb_mon(self, resid_first, resid_last, masks):
"""Add a residue nonbond monitor calculation.
Expand Down Expand Up @@ -254,6 +267,12 @@ def _parse(self):
self.results[calc_i] = DataContainer(["Frame", "angle"])
elif "angle, qangle energy between" in line:
self.results[calc_i] = DataContainer(["Frame", "angle"])
elif "torsion between" in line:
self.results[calc_i] = DataContainer(["Frame", "torsion"])
elif "torsion, torsion energy between" in line:
self.results[calc_i] = DataContainer(["Frame", "torsion"])
elif "torsion, qtorsion energy between" in line:
self.results[calc_i] = DataContainer(["Frame", "torsion"])
elif "nonbond monitor for residues" in line:
pass
else:
Expand Down
Loading

0 comments on commit 76475e9

Please sign in to comment.