diff --git a/packages/Qpyl/common.py b/packages/Qpyl/common.py index e0038dd..21365ca 100644 --- a/packages/Qpyl/common.py +++ b/packages/Qpyl/common.py @@ -36,7 +36,7 @@ logger = logging.getLogger(__name__) -__version__ = "0.5.7" +__version__ = "0.5.8" class SpecialFormatter(logging.Formatter): diff --git a/packages/Qpyl/core/qparameter.py b/packages/Qpyl/core/qparameter.py index 91e831b..1f6bc42 100644 --- a/packages/Qpyl/core/qparameter.py +++ b/packages/Qpyl/core/qparameter.py @@ -134,9 +134,8 @@ def read_prm(self, parm_fn): key, value = line.split() except ValueError: raise QPrmError("Malformed key/value pair in " - "[options] section of parm file: " - "{line}" - .format(line)) + "[options] section of parm file: {}" + "".format(line)) self.options[key] = value diff --git a/packages/Qpyl/qgroupcontrib.py b/packages/Qpyl/qgroupcontrib.py index a9435fb..6e18ebb 100644 --- a/packages/Qpyl/qgroupcontrib.py +++ b/packages/Qpyl/qgroupcontrib.py @@ -242,7 +242,8 @@ def calcall(self): # iterate through each residue and calculate # means and stdevs - for res_key in sorted(gcs.keys()): + # (sort by residue index) + for res_key in sorted(gcs.keys(), key=lambda x: int(x.split(".")[0])): rc = gcs[res_key] resid, resname = res_key.split(".") # get mean and stdev @@ -522,5 +523,29 @@ def plotdata(self): return plots + def get_pdbgc(self): + """Return the pdb structure (string) with added GC values. - + Fill the 'Temperature factor' fields with the calculated GC values, + and return the whole pdb structure in string format. + """ + resids, _, _, _, _, els, _ = self.gcs_stats.get_columns() + gcs = dict(zip(resids, els)) + pdb = [] + for mol in self._pdb_qstruct.molecules: + for res in mol.residues: + for atom in res.atoms: + x, y, z = atom.coordinates + try: + gc = gcs[atom.residue.index] + except KeyError: + gc = 0 + finally: + pdb.append("ATOM {:>5d} {:<4s} {:3s} {:>4d} "\ + "{:>8.3f}{:>8.3f}{:>8.3f}{:>6}{:>6.2f}"\ + "".format(atom.index, atom.name, + atom.residue.name, + atom.residue.index, + x, y, z, "", gc)) + pdb.append("GAP") + return "\n".join(pdb) diff --git a/qscripts-cli/q_automapper.py b/qscripts-cli/q_automapper.py index 0772228..56c682e 100755 --- a/qscripts-cli/q_automapper.py +++ b/qscripts-cli/q_automapper.py @@ -55,9 +55,6 @@ from Qpyl.qmapping import QMapper, QMapperError from Qpyl.common import backup_file, init_logger -logger = init_logger('Qpyl') - - def main(): logger = init_logger('Qpyl') diff --git a/qscripts-cli/q_calc.py b/qscripts-cli/q_calc.py index 41ab9ec..752a07e 100755 --- a/qscripts-cli/q_calc.py +++ b/qscripts-cli/q_calc.py @@ -36,8 +36,6 @@ from Qpyl import plotdata from Qpyl.common import backup_file, init_logger -logger = init_logger('Qpyl') - def gc(args): if not os.path.lexists(args.pdb): @@ -158,6 +156,14 @@ def gc(args): print "Wrote '{}'... (q_plot.py is your "\ "friend)".format(fn_out) + # writeout the pdbgc if requested + if args.pdbgc_out: + backup = backup_file(args.pdbgc_out) + if backup: + print "# Backed up '{}' to '{}'".format(args.pdbgc_out, backup) + open(args.pdbgc_out, 'w').write(qgc.get_pdbgc()) + print "Wrote '{}'... (use Pymol/Chimera/VMD and color by B-factor)"\ + "".format(args.pdbgc_out) def main(): @@ -233,6 +239,12 @@ def main(): "".format(QScfg.get("files", "calcs_log")), default=QScfg.get("files", "calcs_log")) + gc_optarg.add_argument("--pdbgc", dest="pdbgc_out", + help="Output filename of PDB structure file " + "with group contributions in place of the " + "B-factor. Default=Don't output.", + default=None) + gc_optarg.add_argument("--writeout", action="store_true", default=False, help="Write out QCalc inputs and outputs." "Default=Don't")