Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.7 #96

Merged
merged 67 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
35bb491
initial code try
sroet Jul 8, 2020
3a0c0fe
initial version of new atom slicing
dwhswenson Aug 14, 2020
638b2dd
Add atom_indexer!
dwhswenson Aug 14, 2020
6d73a9a
Use map in convert_contacts; cleanup
dwhswenson Aug 15, 2020
db35210
(start to) add slice_trajectory to Indexers
dwhswenson Aug 16, 2020
bcc027f
fix up tests
dwhswenson Aug 28, 2020
daac39f
bump 0.6.1.dev0
dwhswenson Sep 1, 2020
6e5f0b0
Merge pull request #86 from dwhswenson/bump-0.6.1.dev0
dwhswenson Sep 1, 2020
07637b4
Merge branch 'master' into new_atom_slice
dwhswenson Sep 1, 2020
590b6a9
fix ContactTraj for new atom slice; better perf
dwhswenson Sep 1, 2020
27ce581
More performance improvements
dwhswenson Sep 1, 2020
0f5201b
finish atom_indexer stuff
dwhswenson Sep 3, 2020
4aebb51
Remove ContactMap
dwhswenson Sep 3, 2020
703c541
Apply suggestions from code review
dwhswenson Sep 4, 2020
0753f08
Merge pull request #87 from dwhswenson/new_atom_slice
dwhswenson Sep 4, 2020
813dc52
Merge branch 'master' into remove_map
dwhswenson Sep 4, 2020
f06e3ea
bump version 0.7.0.dev0
dwhswenson Sep 4, 2020
9bb0e1c
Add PendingDeprecationWarning for ContactFreq
dwhswenson Sep 4, 2020
667a6f3
Merge branch 'master' into topol_difference
sroet Sep 7, 2020
5c37bd6
should be feature complete now, just tests and examples left
sroet Sep 7, 2020
af8194e
split out topology stuff to topology.py
sroet Sep 16, 2020
f85f7d8
see if codeclimate thinks this is better or worse
sroet Sep 16, 2020
24aa411
do some more refactoring
sroet Sep 16, 2020
fd0c2fa
even more refactoring
sroet Sep 16, 2020
0cd6b9b
don't loop twice
sroet Sep 16, 2020
46b537a
make out topology optional
sroet Sep 16, 2020
a9fd84a
Apply suggestions from code review
dwhswenson Sep 23, 2020
a22e862
Merge pull request #88 from dwhswenson/remove_map
dwhswenson Sep 23, 2020
d7bfec0
Remove ContactFrequency frames argument
dwhswenson Sep 23, 2020
a05fe7a
Finish removing frame; private _contact_map()
dwhswenson Sep 23, 2020
f388b80
Merge branch 'master' into topol_difference
sroet Oct 7, 2020
f3bd515
restructure the disabling
sroet Oct 7, 2020
90ce5df
overriding properties is hard
sroet Oct 7, 2020
6d5f478
This seems to work, enough for today
sroet Oct 8, 2020
b7de3b1
Feature complete and 100% coverage
sroet Oct 9, 2020
99f9673
removed some copied docstrings
sroet Oct 9, 2020
0684ca2
refactor some more for codeclimate
sroet Oct 9, 2020
e3ac6cf
Added example and classes to main import
sroet Oct 11, 2020
2bc9cde
move parameter fixing to another file
sroet Oct 12, 2020
4f1c983
Apply suggestions from code review
sroet Oct 13, 2020
41c07c3
Make differences of intersects only
sroet Oct 13, 2020
46aa736
only care about overlaps in the maps
sroet Oct 16, 2020
1bdb9e2
remove unused function
sroet Oct 16, 2020
355da66
fixes after code review
sroet Oct 20, 2020
8eb2091
more possible refactoring
sroet Oct 20, 2020
efe33ff
alter check_compat behavior
sroet Oct 20, 2020
350a28e
Merge pull request #77 from sroet/topol_difference
dwhswenson Oct 21, 2020
929fda7
Merge branch 'master' of github.com:dwhswenson/contact_map into api_c…
dwhswenson Oct 21, 2020
5a3b4e3
Merge pull request #91 from dwhswenson/api_cleanup
dwhswenson Oct 21, 2020
d804684
see if this helps
sroet Oct 23, 2020
15810cc
add tables for h5 reading
sroet Oct 23, 2020
51c1e41
does this work to install this repo?
sroet Oct 23, 2020
dfbb55e
update with extra dependencies
sroet Oct 23, 2020
53ace5b
try grabbing files with postBuild
sroet Oct 23, 2020
1058a40
also remove zip
sroet Oct 23, 2020
9c68659
Merge pull request #92 from sroet/try_binder
dwhswenson Oct 23, 2020
b3f65a3
add binder links to the readme
sroet Oct 23, 2020
70260fa
update online docs to include binder links
sroet Oct 23, 2020
bf64d7e
fix examples/index.rst to render correctly
sroet Oct 23, 2020
b3fad2f
add binder links
sroet Oct 24, 2020
ae75539
add jinja convert to other rst as well
sroet Oct 24, 2020
ddeef36
Update docs/examples/index.rst
sroet Oct 26, 2020
878aa1f
Merge pull request #93 from sroet/add_binder_links
dwhswenson Oct 26, 2020
731ee11
allow for other mixings of queries and haystacks
sroet Oct 27, 2020
2788dab
make set_mixing private
sroet Oct 27, 2020
86635d4
Merge pull request #95 from sroet/future_proof_fix_parameter
dwhswenson Oct 27, 2020
5b94518
Release 0.7
dwhswenson Oct 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f7f3cf53698e4655ac8895f13fa5dea6)](https://www.codacy.com/app/dwhswenson/contact_map?utm_source=github.com&utm_medium=referral&utm_content=dwhswenson/contact_map&utm_campaign=Badge_Grade)
[![Maintainability](https://api.codeclimate.com/v1/badges/84768756d594176d8da6/maintainability)](https://codeclimate.com/github/dwhswenson/contact_map/maintainability)

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dwhswenson/contact_map/master)
# Contact Map Explorer

This package provides tools for analyzing and exploring contacts
Expand Down Expand Up @@ -38,6 +38,8 @@ representing the fraction of trajectory time that the contact was present.

Full documentation is at http://contact-map.readthedocs.io/.

Try it out online: [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dwhswenson/contact_map/master?filepath=%2Fexamples) (Note: the performance of the online servers can vary widely.)

## Installation

The easiest way to install is with `conda`. Conda is a powerful package and
Expand Down
2 changes: 1 addition & 1 deletion ci/conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package:
name: contact_map
# add ".dev0" for unreleased versions
version: "0.6.0"
version: "0.7.0"

source:
path: ../../
Expand Down
4 changes: 3 additions & 1 deletion contact_map/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
__version__ = version.version

from .contact_map import (
ContactMap, ContactFrequency, ContactDifference
ContactMap, ContactFrequency, ContactDifference,
AtomMismatchedContactDifference, ResidueMismatchedContactDifference,
OverrideTopologyContactDifference
)

from .contact_count import ContactCount
Expand Down
106 changes: 106 additions & 0 deletions contact_map/atom_indexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import collections
import numpy as np
import mdtraj as md

def _atom_slice(traj, indices):
"""Mock MDTraj.atom_slice without rebuilding topology"""
xyz = np.array(traj.xyz[:, indices], order='C')
topology = traj.topology.copy()
if traj._have_unitcell:
unitcell_lengths = traj._unitcell_lengths.copy()
unitcell_angles = traj._unitcell_angles.copy()
else:
unitcell_lengths = None
unitcell_angles = None
time = traj._time.copy()

# Hackish to make the smart slicing work
topology._atoms = indices
topology._numAtoms = len(indices)
return md.Trajectory(xyz=xyz, topology=topology, time=time,
unitcell_lengths=unitcell_lengths,
unitcell_angles=unitcell_angles)

def residue_query_atom_idxs(sliced_query, atom_idx_to_residue_idx):
residue_query_atom_idxs = collections.defaultdict(list)
for sliced_idx in sliced_query:
residue_idx = atom_idx_to_residue_idx[sliced_idx]
residue_query_atom_idxs[residue_idx].append(sliced_idx)
return residue_query_atom_idxs


class AtomSlicedIndexer(object):
"""Indexer when using atom slicing.
"""
def __init__(self, topology, real_query, real_haystack, all_atoms):
self.all_atoms = all_atoms
self.sliced_idx = {
real_idx : sliced_idx
for sliced_idx, real_idx in enumerate(all_atoms)
}
self.real_idx = {
sliced_idx: real_idx
for real_idx, sliced_idx in self.sliced_idx.items()
}
self.query = set([self.sliced_idx[q] for q in real_query])
self.haystack = set([self.sliced_idx[h] for h in real_haystack])

# atom_idx_to_residue_idx
self.real_atom_idx_to_residue_idx = {atom.index: atom.residue.index
for atom in topology.atoms}
self.atom_idx_to_residue_idx = {
sliced_idx: self.real_atom_idx_to_residue_idx[real_idx]
for sliced_idx, real_idx in enumerate(all_atoms)
}
self.residue_query_atom_idxs = residue_query_atom_idxs(
self.query, self.atom_idx_to_residue_idx
)

def ignore_atom_idx(self, atoms, all_atoms_set):
result = set(atom.index for atom in atoms)
result &= all_atoms_set
result = set(self.sliced_idx[a] for a in result)
return result

def convert_atom_contacts(self, atom_contacts):
result = {frozenset(map(self.real_idx.__getitem__, pair)): value
for pair, value in atom_contacts.items()}
return collections.Counter(result)

def slice_trajectory(self, trajectory):
# Prevent (memory) expensive atom slicing if not needed.
# This check is also needed here because ContactFrequency slices the
# whole trajectory before calling this function.
if len(self.all_atoms) < trajectory.topology.n_atoms:
sliced = _atom_slice(trajectory, self.all_atoms)
else:
sliced = trajectory
return sliced


class IdentityIndexer(object):
"""Indexer when not using atom slicing.
"""
def __init__(self, topology, real_query, real_haystack, all_atoms):
self.all_atoms = all_atoms
self.topology = topology
identity_mapping = {a: a for a in range(topology.n_atoms)}
self.sliced_idx = identity_mapping
self.real_idx = identity_mapping
self.query = set(real_query)
self.haystack = set(real_haystack)
self.real_atom_idx_to_residue_idx = {atom.index: atom.residue.index
for atom in topology.atoms}
self.atom_idx_to_residue_idx = self.real_atom_idx_to_residue_idx
self.residue_query_atom_idxs = residue_query_atom_idxs(
self.query, self.atom_idx_to_residue_idx
)

def ignore_atom_idx(self, atoms, all_atoms_set):
return set(atom.index for atom in atoms)

def convert_atom_contacts(self, atom_contacts):
return atom_contacts

def slice_trajectory(self, trajectory):
return trajectory
13 changes: 13 additions & 0 deletions contact_map/contact_count.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import collections
import scipy
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -310,3 +311,15 @@ def most_common_idx(self):
most_common : same thing, using objects as key
"""
return self._counter.most_common()

def filter(self, idx):
"""New ContactCount filtered to idx.

Returns a new ContactCount with the only the counter keys/values
where both the keys are in idx
"""
dct = {k: v for k, v in self._counter.items()
if all([i in idx for i in k])}
new_count = collections.Counter()
new_count.update(dct)
return ContactCount(new_count, self._object_f, self.n_x, self.n_y)