Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[run]
branch = True
source = MDAnalysis

exclude_lines =
pragma: no cover

[report]
exclude_lines =
pragma: no cover

def __repr__
raise NotImplementedError
if __name__ == .__main__.:
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: python
python:
- "2.6"
- "2.7"
# command to install dependencies
before_install:
- sudo apt-get update -qq
- sudo apt-get install -q -y gfortran libhdf5-serial-dev libnetcdf-dev liblapack-dev libatlas-dev
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b
- export PATH=/home/travis/miniconda/bin:$PATH
- conda update --yes conda
install:
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then conda create --yes -q -n pyenv mkl python=2.6 numpy=1.6.2 scipy=0.11 nose=1.1; fi
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then conda create --yes -q -n pyenv mkl python=2.7 numpy=1.9.1 scipy=0.14.0 nose=1.3.4; fi
- source activate pyenv
- conda install --yes python=$TRAVIS_PYTHON_VERSION cython biopython matplotlib networkx netcdf4
- pip install package/
- pip install testsuite/
- pip install coveralls
# command to run tests
script:
- nosetests --with-coverage --cover-package MDAnalysis
after_success:
coveralls
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
MDAnalysis Repository README
================================

|build| |cov|

MDAnalysis_ is a Python toolkit to analyze molecular dynamics
trajectories generated by CHARMM, Amber, NAMD, LAMMPS, or Gromacs.

Expand Down Expand Up @@ -34,3 +36,10 @@ MDAnalysis issue tracker.)
.. _Issue 87: https://github.com/MDAnalysis/mdanalysis/issues/87
.. _MDAnalysis: http://www.MDAnalysis.org
.. _LICENSE: https://github.com/MDAnalysis/mdanalysis/blob/master/LICENSE

.. |build| image:: https://travis-ci.org/richardjgowers/mdanalysis.svg?branch=develop
:alt: Build Status
:target: https://travis-ci.org/richardjgowers/mdanalysis
.. |cov| image:: https://coveralls.io/repos/richardjgowers/mdanalysis/badge.svg?branch=develop
:alt: Coverage Status
:target: https://coveralls.io/r/richardjgowers/mdanalysis?branch=develop
2 changes: 1 addition & 1 deletion package/MDAnalysis/coordinates/DCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def __init__(self, filename, numatoms, start=0, step=1,
self.step = 1
self.delta = MDAnalysis.core.units.convert(dt, 'ps', 'AKMA')
else:
raise ValueError("DCDWriter: dt must be > 0, not {}".format(dt))
raise ValueError("DCDWriter: dt must be > 0, not {0}".format(dt))
else:
self.step = step
self.delta = delta
Expand Down
21 changes: 12 additions & 9 deletions package/MDAnalysis/coordinates/MOL2.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ def parse_block(self, block):

atom_lines, bond_lines = sections["atom"], sections["bond"]
if not len(atom_lines):
raise Exception("The mol2 (starting at line {}) block has no atoms".format(block["start_line"]))
raise Exception("The mol2 (starting at line {0}) block has no atoms"
"".format(block["start_line"]))
if not len(bond_lines):
raise Exception("The mol2 (starting at line {}) block has no bonds".format(block["start_line"]))
raise Exception("The mol2 (starting at line {0}) block has no bonds"
"".format(block["start_line"]))

coords = []
for a in atom_lines:
Expand Down Expand Up @@ -284,8 +286,8 @@ def encode_block(self, obj):
bonds = sorted([(bond[0].id, bond[1].id, bond.order) for bond in bonds])
mapping = dict([(a.id, i) for i, a in enumerate(obj.atoms)])

atom_lines = ["{:>4} {:>4} {:>13.4f} {:>9.4f} {:>9.4f} {:>4} {} {} "
"{:>7.4f}".format(mapping[a.id] + 1, a.name,
atom_lines = ["{0:>4} {1:>4} {2:>13.4f} {3:>9.4f} {4:>9.4f} {5:>4} {6} {7} "
"{8:>7.4f}".format(mapping[a.id] + 1, a.name,
float(a.pos[0]),
float(a.pos[1]),
float(a.pos[2]), a.type,
Expand All @@ -295,10 +297,11 @@ def encode_block(self, obj):
atom_lines = "\n".join(atom_lines)

bonds = [(atom1, atom2, order) for atom1, atom2, order in bonds if atom1 in mapping and atom2 in mapping]
bond_lines = ["{:>5} {:>5} {:>5} {:>2}".format(bid + 1,
mapping[atom1] + 1,
mapping[atom2] + 1,
order) for bid, (atom1, atom2, order) in enumerate(bonds)]
bond_lines = ["{0:>5} {1:>5} {2:>5} {3:>2}"
"".format(bid + 1,
mapping[atom1] + 1,
mapping[atom2] + 1,
order) for bid, (atom1, atom2, order) in enumerate(bonds)]
bond_lines = ["@<TRIPOS>BOND"] + bond_lines + ["\n"]
bond_lines = "\n".join(bond_lines)

Expand All @@ -312,7 +315,7 @@ def encode_block(self, obj):
molecule = traj.molecule[traj.frame]
check_sums = molecule[1].split()
check_sums[0], check_sums[1] = str(len(obj.atoms)), str(len(bonds))
molecule[1] = "{}\n".format(" ".join(check_sums))
molecule[1] = "{0}\n".format(" ".join(check_sums))
molecule = ["@<TRIPOS>MOLECULE\n"] + molecule

return "".join(molecule) + atom_lines + bond_lines + "".join(substructure)
Expand Down
6 changes: 3 additions & 3 deletions package/MDAnalysis/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def __getitem__(self, frame):

def _read_frame(self, frame):
"""Move to *frame* and fill timestep with data."""
raise TypeError("{} does not support direct frame indexing."
raise TypeError("{0} does not support direct frame indexing."
"".format(self.__class__.__name__))
# Example implementation in the DCDReader:
#self._jump_to_frame(frame)
Expand All @@ -589,7 +589,7 @@ def _iter(start=start, stop=stop, step=step):
for i in xrange(start, stop, step):
yield self[i]
except TypeError: # if _read_frame not implemented
raise TypeError("{} does not support slicing."
raise TypeError("{0} does not support slicing."
"".format(self.__class__.__name__))
return _iter()

Expand Down Expand Up @@ -996,7 +996,7 @@ class SingleFrameReader(Reader):

.. versionadded:: 0.10.0
"""
_err = "{} only contains a single frame"
_err = "{0} only contains a single frame"

def __init__(self, filename, convert_units=None, **kwargs):
self.filename = filename
Expand Down
10 changes: 5 additions & 5 deletions package/MDAnalysis/coordinates/xdrfile/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ def __init__(self, filename, convert_units=None, sub=None, **kwargs):
if not isinstance(sub, numpy.ndarray) or len(sub.shape) != 1 or sub.dtype.kind != 'i':
raise TypeError("sub MUST be a single dimensional numpy array of integers")
if len(sub) > self._trr_numatoms:
raise ValueError("sub MUST be less than or equal to the number of actual trr atoms, {} in this case".
format(self._trr_numatoms))
raise ValueError("sub MUST be less than or equal to the number of actual trr atoms,"
" {0} in this case".format(self._trr_numatoms))
if numpy.max(sub) >= self._trr_numatoms or numpy.min(sub) < 0:
raise IndexError("sub contains out-of-range elements for the given trajectory")
# sub appears to be valid
Expand Down Expand Up @@ -524,7 +524,7 @@ def delta(self):

def _offset_filename(self):
head, tail = os.path.split(self.filename)
return os.path.join(head, '.{}_offsets.pkl'.format(tail))
return os.path.join(head, '.{0}_offsets.pkl'.format(tail))

def _store_offsets(self):
"""Stores offsets for trajectory as a hidden file in the same directory
Expand Down Expand Up @@ -638,7 +638,7 @@ def load_offsets(self, filename, check=False):
key = 'size'
conditions = (os.path.getsize(self.filename) == offsets[key]) and conditions
except KeyError:
warnings.warn("Offsets in file '{}' not suitable; missing {}.".format(filename, key))
warnings.warn("Offsets in file '{0}' not suitable; missing {1}.".format(filename, key))
return

# if conditions not met, abort immediately
Expand All @@ -650,7 +650,7 @@ def load_offsets(self, filename, check=False):
try:
self._offsets = offsets['offsets']
except KeyError:
warnings.warn("Missing key 'offsets' in file '{}'; aborting load of offsets.".format(filename))
warnings.warn("Missing key 'offsets' in file '{0}'; aborting load of offsets.".format(filename))
return
self._numframes = len(self._offsets)

Expand Down
50 changes: 26 additions & 24 deletions package/MDAnalysis/core/AtomGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def __repr__(self):
idx=self.number + 1, name=self.name, t=self.type,
rname=self.resname, rid=self.resid, sid=self.segid,
altloc="" if not self.altLoc
else " and altloc {}".format(self.altLoc)))
else " and altloc {0}".format(self.altLoc)))

def __cmp__(self, other):
return cmp(self.number, other.number)
Expand All @@ -483,7 +483,7 @@ def __hash__(self):

def __add__(self, other):
if not (isinstance(other, Atom) or isinstance(other, AtomGroup)):
raise TypeError('Can only concatenate Atoms (not "{}")'
raise TypeError('Can only concatenate Atoms (not "{0}")'
' to AtomGroup'.format(other.__class__.__name__))
if isinstance(other, Atom):
return AtomGroup([self, other])
Expand Down Expand Up @@ -592,7 +592,7 @@ def universe(self):
return self.__universe
else:
raise AttributeError(
"Atom {} is not assigned to a Universe".format(self.number))
"Atom {0} is not assigned to a Universe".format(self.number))

@universe.setter
def universe(self, universe):
Expand Down Expand Up @@ -957,7 +957,7 @@ def __contains__(self, other):

def __add__(self, other):
if not (isinstance(other, Atom) or isinstance(other, AtomGroup)):
raise TypeError('Can only concatenate AtomGroup (not "{}") to'
raise TypeError('Can only concatenate AtomGroup (not "{0}") to'
' AtomGroup'.format(other.__class__.__name__))
if isinstance(other, AtomGroup):
return AtomGroup(self._atoms + other._atoms)
Expand Down Expand Up @@ -2441,7 +2441,7 @@ def wrap(self, compound="atoms", center="com", box=None):
elif compound.lower() == 'fragments':
objects = self.fragments
else:
raise ValueError("Unrecognised compound definition: {}"
raise ValueError("Unrecognised compound definition: {0}"
"Please use one of 'group' 'residues' 'segments'"
"or 'fragments'".format(compound))

Expand All @@ -2450,7 +2450,7 @@ def wrap(self, compound="atoms", center="com", box=None):
elif center.lower() in ('cog', 'centroid', 'centerofgeometry'):
centers = numpy.vstack([o.centerOfGeometry() for o in objects])
else:
raise ValueError("Unrecognised center definition: {}"
raise ValueError("Unrecognised center definition: {0}"
"Please use one of 'com' or 'cog'".format(center))
centers = centers.astype(numpy.float32)

Expand Down Expand Up @@ -2589,7 +2589,7 @@ def write(self, filename=None, format="PDB",
selection = True

if not (coords or selection):
raise ValueError("No writer found for format: {}".format(filename))
raise ValueError("No writer found for format: {0}".format(filename))
else:
writer.write(self.atoms)
if coords: # only these writers have a close method
Expand Down Expand Up @@ -3130,7 +3130,8 @@ def __getattr__(self, attr):
if len(seglist) == 0:
return super(SegmentGroup, self).__getattr__(attr)
if len(seglist) > 1:
warnings.warn("SegmentGroup: Multiple segments with the same name {}; a combined, NON-CONSECUTIVE "
warnings.warn("SegmentGroup: Multiple segments with the same name {0};"
" a combined, NON-CONSECUTIVE "
"Segment is returned.".format(attr), category=SelectionWarning)
#return Segment(sum([s.residues for s in seglist])) ### FIXME: not working yet, need __add__
return seglist[0]
Expand Down Expand Up @@ -3341,13 +3342,13 @@ def __init__(self, *args, **kwargs):
with parser(self.filename, universe=self) as p:
self._topology = p.parse()
except IOError as err:
raise IOError("Failed to load from the topology file {}"
" with parser {}.\n"
"Error: {}".format(self.filename, parser, err))
raise IOError("Failed to load from the topology file {0}"
" with parser {1}.\n"
"Error: {2}".format(self.filename, parser, err))
except ValueError as err:
raise ValueError("Failed to construct topology from file {}"
" with parser {} \n"
"Error: {}".format(self.filename, parser, err))
raise ValueError("Failed to construct topology from file {0}"
" with parser {1} \n"
"Error: {2}".format(self.filename, parser, err))

# Generate atoms, residues and segments
self._init_topology()
Expand Down Expand Up @@ -3549,7 +3550,7 @@ def add(self, other):
def update(self, other):
self.ats.update(other.ats)

f = {a: None for a in self.atoms} # each atom starts with its own list
f = dict.fromkeys(self.atoms, None) # each atom starts with its own list

for a1, a2 in bonds: # Iterate through all bonds
if not (f[a1] or f[a2]): # New set made here
Expand All @@ -3565,10 +3566,10 @@ def update(self, other):
continue
else: # If they are both in different fragments, combine fragments
f[a1].update(f[a2])
f.update({a: f[a1] for a in f[a2]})
f.update(dict((a, f[a1]) for a in f[a2]))

# Lone atoms get their own fragment
f.update({a: _fragset((a,)) for a, val in f.items() if not val})
f.update(dict((a, _fragset((a,))) for a, val in f.items() if not val))

# All the unique values in f are the fragments
frags = tuple([AtomGroup(list(a.ats)) for a in set(f.values())])
Expand Down Expand Up @@ -3871,13 +3872,14 @@ def load_new(self, filename, **kwargs):
kwargs['numatoms'] = self.atoms.numberOfAtoms()
self.trajectory = reader(filename, **kwargs) # unified trajectory API
if self.trajectory.numatoms != self.atoms.numberOfAtoms():
raise ValueError("The topology and {} trajectory files don't"
raise ValueError("The topology and {form} trajectory files don't"
" have the same number of atoms!\n"
"Topology number of atoms {}\n"
"Trajectory: {} Number of atoms {}".format(
self.trajectory.format,
len(self.atoms),
filename, self.trajectory.numatoms))
"Topology number of atoms {top_natoms}\n"
"Trajectory: {fname} Number of atoms {trj_natoms}".format(
form=self.trajectory.format,
top_natoms=len(self.atoms),
fname=filename,
trj_natoms=self.trajectory.numatoms))

return filename, self.trajectory.format

Expand Down Expand Up @@ -4032,7 +4034,7 @@ def selectAtoms(self, sel, *othersel, **selgroups):
def __repr__(self):
return "<Universe with {natoms} atoms{bonds}>".format(
natoms=len(self.atoms),
bonds=" and {} bonds".format(len(self.bonds)) if self.bonds else "")
bonds=" and {0} bonds".format(len(self.bonds)) if self.bonds else "")

def __getstate__(self):
raise NotImplementedError
Expand Down
8 changes: 4 additions & 4 deletions package/MDAnalysis/core/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def _check_array(coords, desc):
float32 data
"""
if (coords.ndim != 2 or coords.shape[1] != 3):
raise ValueError("{} must be a sequence of 3 dimensional coordinates"
raise ValueError("{0} must be a sequence of 3 dimensional coordinates"
"".format(desc))
if coords.dtype != numpy.float32:
raise TypeError("{} must be of type float32".format(desc))
raise TypeError("{0} must be of type float32".format(desc))


def _check_results_array(results, size):
Expand All @@ -123,7 +123,7 @@ def _check_results_array(results, size):
"""
if results.shape != size:
raise ValueError("Result array has incorrect size,"
"should be {}, got {}".format(size, results.shape))
"should be {0}, got {1}".format(size, results.shape))
if results.dtype != numpy.float64:
raise TypeError("Results array must be of type float64")

Expand All @@ -134,7 +134,7 @@ def _check_lengths_match(*arrays):

if not all([a.shape == ref for a in arrays]):
raise ValueError("Input arrays must all be same shape"
"Got {}".format([a.shape for a in arrays]))
"Got {0}".format([a.shape for a in arrays]))

def distance_array(reference, configuration, box=None, result=None):
"""Calculate all distances between a reference set and another configuration.
Expand Down
6 changes: 4 additions & 2 deletions package/MDAnalysis/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def anyopen(datasource, mode='r', reset=True):
try:
stream.seek(0L)
except (AttributeError, IOError):
warnings.warn("Stream {}: not guaranteed to be at the beginning.".format(filename),
warnings.warn("Stream {0}: not guaranteed to be at the beginning."
"".format(filename),
category=StreamWarning)
else:
stream = None
Expand Down Expand Up @@ -543,7 +544,8 @@ def reset(self):
try:
self.stream.seek(0L) # typical file objects
except (AttributeError, IOError):
warnings.warn("NamedStream {}: not guaranteed to be at the beginning.".format(self.name),
warnings.warn("NamedStream {0}: not guaranteed to be at the beginning."
"".format(self.name),
category=StreamWarning)

# access the stream
Expand Down
4 changes: 2 additions & 2 deletions package/MDAnalysis/topology/CRDParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def parse(self):
try:
serial, TotRes, resName, name, x, y, z, chainID, resSeq, tempFactor = r.read(line)
except:
raise ValueError("Check CRD format at line {}: {}".format(
linenum, line.rstrip()))
raise ValueError("Check CRD format at line {0}: {1}"
"".format(linenum, line.rstrip()))

atomtype = guess_atom_type(name)
mass = guess_atom_mass(name)
Expand Down
Loading