Skip to content

Commit

Permalink
Changes for PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorPigg committed Jun 12, 2019
1 parent 7280b46 commit e8efe5f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python

python:
- "3.4"
- "3.7"
- "3.6"

env: PYTHONPATH=$PYTHONPATH:$TRAVIS_BUILD_DIR/tests
Expand Down
31 changes: 26 additions & 5 deletions idpflex/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, properties=None):
self._properties.update({p.name: p for p in properties})

def __iter__(self):
return iter(self._properties.values())
return iter(self._properties.keys())

def __getitem__(self, name):
r"""
Expand Down Expand Up @@ -116,9 +116,11 @@ def feature_vector(self, names=None):
Feature vector for the specified sequence of names.
The feature vector is a concatenation of the feature vectors for
each of the properties.
each of the properties and the concatenation follows the order of
names.
If names is None, return all features in the property dict.
If names is None, return all features in the property dict in the
order of insertion.
Parameters
----------
Expand All @@ -131,14 +133,33 @@ def feature_vector(self, names=None):
"""
if names is None:
return np.concatenate([prop.feature_vector
for prop in self])
for prop in self.values()])
return np.concatenate([self._properties[n].feature_vector
for n in names])

def feature_weights(self, names=None):
r"""
Feature vector weights for the specified sequence of names.
The feature vector weights is a concatenation of the feature vectors
weights for each of the properties and the concatenation follows the
order of names.
If names is None, return all features in the property dict in the
order of insertion.
Parameters
----------
names: list
List of property names
Returns
-------
numpy.ndarray
"""
if names is None:
return np.concatenate([prop.feature_weights
for prop in self])
for prop in self.values()])
return np.concatenate([self._properties[n].feature_weights
for n in names])

Expand Down
15 changes: 6 additions & 9 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np
import pytest
import tempfile
import os
import shutil

from idpflex import properties as ps
Expand Down Expand Up @@ -286,10 +285,9 @@ def test_to_and_from_ascii(self, sans_benchmark):
sans_prop_ref = ps.SansProperty()
sans_prop_ref.from_cryson_int(sans_benchmark['cryson_int'])
sans_prop = ps.SansProperty()
f = tempfile.NamedTemporaryFile(delete=False)
sans_prop_ref.to_ascii(f.name)
sans_prop.from_ascii(f.name)
os.remove(f.name)
with tempfile.NamedTemporaryFile() as f:
sans_prop_ref.to_ascii(f.name)
sans_prop.from_ascii(f.name)
np.testing.assert_array_almost_equal(
sans_prop.qvalues, sans_prop_ref.qvalues)

Expand Down Expand Up @@ -328,10 +326,9 @@ def test_to_and_from_ascii(self, saxs_benchmark):
saxs_prop_ref = ps.SaxsProperty()
saxs_prop_ref.from_crysol_int(saxs_benchmark['crysol_int'])
saxs_prop = ps.SaxsProperty()
f = tempfile.NamedTemporaryFile(delete=False)
saxs_prop_ref.to_ascii(f.name)
saxs_prop.from_ascii(f.name)
os.remove(f.name)
with tempfile.NamedTemporaryFile() as f:
saxs_prop_ref.to_ascii(f.name)
saxs_prop.from_ascii(f.name)
np.testing.assert_array_almost_equal(
saxs_prop.qvalues, saxs_prop_ref.qvalues)

Expand Down

0 comments on commit e8efe5f

Please sign in to comment.