77import itertools
88import pickle
99import json
10+
11+ import warnings
12+
1013import numpy as np
1114import pandas as pd
1215import mdtraj as md
@@ -171,6 +174,24 @@ def __init__(self, topology, query, haystack, cutoff, n_neighbors_ignored):
171174 }
172175 self ._atom_idx_to_residue_idx = self ._set_atom_idx_to_residue_idx ()
173176
177+ @classmethod
178+ def from_contacts (cls , atom_contacts , residue_contacts , topology ,
179+ query = None , haystack = None , cutoff = 0.45 ,
180+ n_neighbors_ignored = 2 ):
181+ obj = cls .__new__ (cls )
182+ super (cls , obj ).__init__ (topology , query , haystack , cutoff ,
183+ n_neighbors_ignored )
184+
185+ def get_contact_counter (contact ):
186+ if isinstance (contact , ContactCount ):
187+ return contact .counter
188+ else :
189+ return contact
190+
191+ obj ._atom_contacts = get_contact_counter (atom_contacts )
192+ obj ._residue_contacts = get_contact_counter (residue_contacts )
193+ return obj
194+
174195 def _set_atom_slice (self ):
175196 """ Set atom slice logic """
176197 if (self ._class_use_atom_slice is None and
@@ -675,13 +696,25 @@ def residue_contacts(self):
675696class ContactMap (ContactObject ):
676697 """
677698 Contact map (atomic and residue) for a single frame.
699+
700+ .. deprecated:: 0.6.0
701+ ``ContactMap`` will be removed in Contact Map Explorer 0.7.0 because
702+ it is redundant with ``ContactFrequency``. For more, see
703+ https://github.com/dwhswenson/contact_map/issues/82.
704+
678705 """
679706 # Default for use_atom_slice, None tries to be smart
680707 _class_use_atom_slice = None
681708
709+ _deprecation_message = (
710+ "The ContactMap class will be removed in Contact Map Explorer 0.7. "
711+ + "Use ContactFrequency instead. For more, see: "
712+ + "https://github.com/dwhswenson/contact_map/issues/82."
713+ )
714+
682715 def __init__ (self , frame , query = None , haystack = None , cutoff = 0.45 ,
683716 n_neighbors_ignored = 2 ):
684-
717+ warnings . warn ( self . _deprecation_message , FutureWarning )
685718 self ._frame = frame # TODO: remove this?
686719 super (ContactMap , self ).__init__ (frame .topology , query , haystack ,
687720 cutoff , n_neighbors_ignored )
@@ -692,6 +725,19 @@ def __init__(self, frame, query=None, haystack=None, cutoff=0.45,
692725 (atom_contacts , self ._residue_contacts ) = contact_maps
693726 self ._atom_contacts = self .convert_atom_contacts (atom_contacts )
694727
728+ @classmethod
729+ def from_dict (cls , dct ):
730+ warnings .warn (cls ._deprecation_message , FutureWarning )
731+ return super (ContactMap , cls ).from_dict (dct )
732+
733+ # don't need to add deprecation in from_json because it uses from_dict
734+
735+ @classmethod
736+ def from_file (cls , filename ):
737+ warnings .warn (cls ._deprecation_message , FutureWarning )
738+ return super (ContactMap , cls ).from_file (filename )
739+
740+
695741 def __hash__ (self ):
696742 return hash ((super (ContactMap , self ).__hash__ (),
697743 tuple (self ._atom_contacts .items ()),
@@ -746,6 +792,17 @@ def __init__(self, trajectory, query=None, haystack=None, cutoff=0.45,
746792 contacts = self ._build_contact_map (trajectory )
747793 (self ._atom_contacts , self ._residue_contacts ) = contacts
748794
795+ @classmethod
796+ def from_contacts (cls , atom_contacts , residue_contacts , n_frames ,
797+ topology , query = None , haystack = None , cutoff = 0.45 ,
798+ n_neighbors_ignored = 2 ):
799+ obj = super (ContactFrequency , cls ).from_contacts (
800+ atom_contacts , residue_contacts , topology , query , haystack ,
801+ cutoff , n_neighbors_ignored
802+ )
803+ obj ._n_frames = n_frames
804+ return obj
805+
749806 def __hash__ (self ):
750807 return hash ((super (ContactFrequency , self ).__hash__ (),
751808 tuple (self ._atom_contacts .items ()),
@@ -923,6 +980,10 @@ def __sub__(self, other):
923980 def contact_map (self , * args , ** kwargs ): #pylint: disable=W0221
924981 raise NotImplementedError
925982
983+ @classmethod
984+ def from_contacts (self , * args , ** kwargs ): #pylint: disable=W0221
985+ raise NotImplementedError
986+
926987 @property
927988 def atom_contacts (self ):
928989 n_x = self .topology .n_atoms
0 commit comments