Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ctk3b committed Apr 29, 2015
1 parent 8191e63 commit bea3625
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
25 changes: 12 additions & 13 deletions mbuild/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def atom_list_by_name(self, name='*', exclude_ports=True):
"""
atom_list = []
for atom in self.yield_atoms():
if not (exclude_ports and atom.name == "G"):
if not (exclude_ports and atom.name == 'G'):
if name == '*':
atom_list.append(atom)
elif atom.name == name:
Expand Down Expand Up @@ -300,7 +300,7 @@ def add(self, new_part, label=None, containment=True, replace=False,
elem.parent = self
return

assert new_part.parent is None, "Part {} already has a parent: {}".format(
assert new_part.parent is None, 'Part {} already has a parent: {}'.format(
new_part, new_part.parent)
self.parts.add(new_part)
new_part.parent = self
Expand All @@ -312,19 +312,18 @@ def add(self, new_part, label=None, containment=True, replace=False,
label = '_{0}[$]'.format(new_part.__class__.__name__)

if label is not None:
if label.endswith("[$]"):
if label.endswith('[$]'):
label = label[:-3]
if label not in self.labels:
self.labels[label] = []
label_pattern = label + "[{}]"
label_pattern = label + '[{}]'

count = len(self.labels[label])
self.labels[label].append(new_part)
label = label_pattern.format(count)

if not replace and label in self.labels:
raise Exception(
"Label {0} already exists in {1}".format(label, self))
raise Exception('Label {0} already exists in {1}'.format(label, self))
else:
self.labels[label] = new_part
new_part.referrers.add(self)
Expand Down Expand Up @@ -487,13 +486,13 @@ def from_trajectory(self, traj, frame=-1, coords_only=False):
for chain in traj.topology.chains:
if traj.topology.n_chains > 1:
chain_compound = Compound()
self.add(chain_compound, "chain[$]")
self.add(chain_compound, 'chain[$]')
else:
chain_compound = self
for res in chain.residues:
for atom in res.atoms:
new_atom = Atom(str(atom.name), traj.xyz[frame, atom.index])
chain_compound.add(new_atom, label="{0}[$]".format(atom.name))
chain_compound.add(new_atom, label='{0}[$]'.format(atom.name))
atom_mapping[atom] = new_atom

for a1, a2 in traj.topology.bonds:
Expand Down Expand Up @@ -568,7 +567,7 @@ def _to_topology(self, atom_list, chain_types=None, residue_types=None):
atom_mapping = {}

default_chain = top.add_chain()
default_residue = top.add_residue("RES", default_chain)
default_residue = top.add_residue('RES', default_chain)

last_residue_compound = None
last_chain_compound = None
Expand All @@ -582,7 +581,7 @@ def _to_topology(self, atom_list, chain_types=None, residue_types=None):
if parent != last_chain_compound:
last_chain_compound = parent
last_chain = top.add_chain()
last_chain_default_residue = top.add_residue("RES", last_chain)
last_chain_default_residue = top.add_residue('RES', last_chain)
last_chain.compound = last_chain_compound
break
else:
Expand Down Expand Up @@ -683,9 +682,9 @@ def _add_intermol_molecule_type(intermol_system, parent):
# Magic
# -----
def __getattr__(self, attr):
assert "labels" != attr, ("Compound __init__ never called. Make "
"sure to call super().__init__() in the "
"__init__ method of your class.")
assert 'labels' != attr, ('Compound __init__ never called. Make '
'sure to call super().__init__() in the '
'__init__ method of your class.')
if attr in self.labels:
return self.labels[attr]
else:
Expand Down
4 changes: 2 additions & 2 deletions mbuild/periodic_kdtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer. Redistributions in binary
# form must reproduce the above copyright notice, this list of conditions and
# the # following disclaimer in the documentation and/or other materials
# provided with # the distribution. Neither the name of Enthought nor the
# the following disclaimer in the documentation and/or other materials
# provided with the distribution. Neither the name of Enthought nor the
# names of the SciPy Developers may be used to endorse or promote products
# derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Expand Down
1 change: 0 additions & 1 deletion mbuild/tiled_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __init__(self, tile, n_tiles, kind=None):
self.kind = kind
self.periodicity = np.array(tile.periodicity * n_tiles)


# For every tile, assign temporary ID's to atoms which are internal to
# that tile. E.g., when replicating a tile with 1800 atoms, every tile
# will contain atoms with ID's from 0-1799. These ID's are used below
Expand Down
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
'http://mdtraj.org/latest/installation.html for help!', file=sys.stderr)
sys.exit(1)

try:
import scipy
except ImportError:
print('Building and running mbuild requires scipy. We '
'recommend using conda to install this: '
'https://store.continuum.io/cshop/anaconda/', file=sys.stderr)
sys.exit(1)

requirements = [line.strip() for line in open('requirements.txt').readlines()]

if sys.argv[-1] == 'publish':
Expand Down Expand Up @@ -68,7 +76,9 @@ def run_tests(self):
'License :: OSI Approved :: MIT License,'
'Natural Language :: English',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Scientific/Engineering :: Chemistry',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
Expand Down

0 comments on commit bea3625

Please sign in to comment.