Skip to content

Commit

Permalink
license; dot files; formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ctk3b committed Apr 22, 2015
1 parent f70558b commit 0cbef0a
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .coveragerc
@@ -0,0 +1,6 @@
[report]
exclude_lines =

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
42 changes: 42 additions & 0 deletions .gitignore
@@ -0,0 +1,42 @@
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml
htmlcov

# Translations
*.mo

# Complexity
output/*.html
output/*/index.html

# Sphinx
docs/_build

# PyCharm
.idea
.idea/*
38 changes: 38 additions & 0 deletions .travis.yml
@@ -0,0 +1,38 @@
language: python

python:
# We don't actually use the Travis Python, but this keeps it organized.
- "2.7"
- "3.3"
- "3.4"
install:
- sudo apt-get update
# You may want to periodically update this, although the conda update
# conda line below will keep everything up-to-date. We do this
# conditionally because it saves us some downloading if the version is
# the same.
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget http://repo.continuum.io/miniconda/Miniconda-3.4.2-Linux-x86_64.sh -O miniconda.sh;
else
wget http://repo.continuum.io/miniconda/Miniconda3-3.4.2-Linux-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a

# Replace dep1 dep2 ... with your dependencies
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION
- source activate test-environment
- conda install future coverage pytest
- pip install coveralls
- python setup.py install

script:
- coverage run --rcfile=.coveragerc --source=mbuild setup.py test

after_success:
- coveralls
21 changes: 3 additions & 18 deletions foyer/atomtyper.py
Expand Up @@ -6,12 +6,6 @@
import matplotlib.pyplot as plt
import networkx as nx







# Map rule ids to the functions that check for them (see `find_atomtypes()`).
RULE_NUMBER_TO_RULE = dict()
# Organizes the rules (see `builrule_map()`).
Expand Down Expand Up @@ -466,23 +460,15 @@ def sanitize():
if len(nx.descendants(graph, node)) == 0:
sinks.append(node)
if len(sinks) > 1:
# Cases with multiple sinks that we can safely ignore.
# TODO: Provide more robust way to add approved exceptions.
if '141' in sinks and '142' in sinks and '145' in graph.nodes():
# This case occurs because 145 requires AT LEAST 2 carbon
# neighbors (3 total) and thus can match multiple patterns.
continue
draw_rule_graph('multiple_sinks', graph, element_type, pattern,
sinks=sinks)
draw_rule_graph('multiple_sinks', graph, element_type, pattern, sinks)

# Check for multiple sources. This is not necessarily incorrect.
sources = []
for node in graph.nodes():
if len(nx.ancestors(graph, node)) == 0:
sources.append(node)
if len(sources) > 1:
draw_rule_graph('multiple_sources', graph, element_type, pattern,
sources=sources)
draw_rule_graph('multiple_sources', graph, element_type, pattern, sources)


def find_all_supported_elements():
Expand Down Expand Up @@ -706,5 +692,4 @@ def draw_rule_graph(issue, graph, element, pattern, sinks=None, sources=None):
plt.savefig(fig_name)
plt.clf()

warn("{} connected to {} {}. See '{}'".format(
element, pattern, phrase, fig_name))
warn("{element} connected to {pattern} {phrase}. See '{fig_name}'".format(**locals()))
2 changes: 1 addition & 1 deletion foyer/forcefield.py
Expand Up @@ -2,7 +2,7 @@

import simtk.unit as units

from mbuild.orderedset import OrderedSet
from foyer.orderedset import OrderedSet
from foyer.atomtyper import find_atomtypes


Expand Down
54 changes: 54 additions & 0 deletions foyer/orderedset.py
@@ -0,0 +1,54 @@
import collections
from copy import deepcopy


class OrderedSet(collections.Set):
""" """
def __init__(self, iterable=()):
self.d = collections.OrderedDict.fromkeys(iterable)

def add(self, key):
self.d[key] = None

def discard(self, key):
del self.d[key]

def difference_update(self, *args, **kwargs):
intersection = set(self.d.keys()).intersection(args[0])
self.intersection_update(intersection)

def intersection_update(self, *args, **kwargs):
for part in args[0]:
del self.d[part]

def __len__(self):
return len(self.d)

def __contains__(self, element):
return element in self.d

def __iter__(self):
return self.d.__iter__()

def __le__(self, other):
if not isinstance(other, collections.Set):
return NotImplemented
if len(self) > len(other):
return False

for e1, e2 in zip(self, other):
if e1 != e2:
return False
return True

def __repr__(self):
class_name = self.__class__.__name__
if not self:
return '{0!s}()'.format(class_name)
return '{0!s}({1!r})'.format(class_name, list(self))

def __deepcopy__(self, memo):
result = OrderedSet()
for elt in self:
result.add(deepcopy(elt, memo))
return result
2 changes: 2 additions & 0 deletions foyer/utils/io.py
@@ -1,3 +1,5 @@
from __future__ import print_function

import os

import mdtraj as md
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
@@ -0,0 +1,3 @@
matplotlib
networkx
simtk.units

0 comments on commit 0cbef0a

Please sign in to comment.