Skip to content

Commit

Permalink
Added PDBGC functionality, minor bugfixes.
Browse files Browse the repository at this point in the history
Added the funcionality of writing out a PDB structure with group
contributions added in the B-factor field (q_calc.py gc ... --pdbgc asd.pdb)
Changed the output of GCs - sorted by numeric index (not string index).

Minor bug in read_prm fixed (error in raising an error).
Double init of logger in q_calc and q_automapper removed.
  • Loading branch information
Miha Purg committed Jul 6, 2017
1 parent 6aa3d3e commit e988ab9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/Qpyl/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
logger = logging.getLogger(__name__)


__version__ = "0.5.7"
__version__ = "0.5.8"


class SpecialFormatter(logging.Formatter):
Expand Down
5 changes: 2 additions & 3 deletions packages/Qpyl/core/qparameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
29 changes: 27 additions & 2 deletions packages/Qpyl/qgroupcontrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
3 changes: 0 additions & 3 deletions qscripts-cli/q_automapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
16 changes: 14 additions & 2 deletions qscripts-cli/q_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e988ab9

Please sign in to comment.