Skip to content
Snippets Groups Projects
Commit 54a81b41 authored by James Graham's avatar James Graham
Browse files

PEP8 and cleaning

parent 2f773339
Branches
No related tags found
No related merge requests found
...@@ -13,7 +13,6 @@ class Bond: ...@@ -13,7 +13,6 @@ class Bond:
self.values = [] self.values = []
def boltzmann_invert(self, temp=310): def boltzmann_invert(self, temp=310):
# TODO needs tests
mean, var = stat_moments(self.values) mean, var = stat_moments(self.values)
rt = 8.314 * temp / 1000. rt = 8.314 * temp / 1000.
...@@ -60,9 +59,9 @@ class BondSet: ...@@ -60,9 +59,9 @@ class BondSet:
def _populate_atom_numbers(self, mapping): def _populate_atom_numbers(self, mapping):
for mol in self._molecules: for mol in self._molecules:
molmap = mapping[mol] molmap = mapping[mol]
index = [bead.name for bead in molmap]
for bond in self._molecules[mol]: for bond in self._molecules[mol]:
ind = lambda name: [bead.name for bead in molmap].index(name) bond.atom_numbers = [index.index(atom) for atom in bond.atoms]
bond.atom_numbers = [ind(atom) for atom in bond.atoms]
def write_itp(self, filename, mapping): def write_itp(self, filename, mapping):
self._populate_atom_numbers(mapping) self._populate_atom_numbers(mapping)
...@@ -173,4 +172,3 @@ class BondSet: ...@@ -173,4 +172,3 @@ class BondSet:
def __iter__(self): def __iter__(self):
return iter(self._molecules) return iter(self._molecules)
import os import os
# Python 3.2 doesn't have FileExistsError
try: try:
raise FileExistsError raise FileExistsError
except NameError: except NameError:
...@@ -22,4 +23,3 @@ class ForceField: ...@@ -22,4 +23,3 @@ class ForceField:
def write_rtp(self, mapping, bonds): def write_rtp(self, mapping, bonds):
pass pass
...@@ -90,4 +90,3 @@ class Mapping: ...@@ -90,4 +90,3 @@ class Mapping:
cgframe.residues.append(res) cgframe.residues.append(res)
return cgframe return cgframe
import os import os
class Section: class Section:
__slots__ = ["name", "_lines"] __slots__ = ["name", "_lines"]
...@@ -33,18 +34,18 @@ class CFG: ...@@ -33,18 +34,18 @@ class CFG:
with open(self.filename) as f: with open(self.filename) as f:
curr_section = None curr_section = None
for line in f: for line in f:
line = line.strip("\n") line = line.strip(" \t\n")
if line == "": if not line or line.startswith(";"):
continue
elif line[0] == ";":
continue continue
elif line.startswith("#include"): elif line.startswith("#include"):
cfg2 = CFG(os.path.join(os.path.dirname(self.filename), cfg2 = CFG(os.path.join(os.path.dirname(self.filename),
line.split()[1])) line.split()[1]))
self._sections.update(cfg2._sections) self._sections.update(cfg2._sections)
self._section_names += cfg2._section_names self._section_names += cfg2._section_names
continue continue
elif line[0] == "[":
elif line.startswith("["):
curr_section = line.strip("[ ]") curr_section = line.strip("[ ]")
if curr_section in self._sections: if curr_section in self._sections:
raise DuplicateSectionError(curr_section, self.filename) raise DuplicateSectionError(curr_section, self.filename)
...@@ -84,4 +85,3 @@ class CFG: ...@@ -84,4 +85,3 @@ class CFG:
def __getitem__(self, item): def __getitem__(self, item):
return self._sections[item] return self._sections[item]
...@@ -25,6 +25,12 @@ def stat_moments(vals): ...@@ -25,6 +25,12 @@ def stat_moments(vals):
def sliding(vals): def sliding(vals):
"""
Yield three values in a sliding window along an iterable.
:param vals: Iterable to iterate over
:return: Iterable of tuples
"""
it = iter(vals) it = iter(vals)
prev = None prev = None
current = next(it) current = next(it)
...@@ -33,5 +39,3 @@ def sliding(vals): ...@@ -33,5 +39,3 @@ def sliding(vals):
prev = current prev = current
current = nxt current = nxt
yield (prev, current, None) yield (prev, current, None)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment