@@ -52,6 +52,7 @@ def __init__(self, u, ag1, ag2, nproc=1, frames=None,
5252 self .ag1 , self .ag2 = ag1 , ag2
5353 self .max_cutoff = max_cutoff
5454 self .frames , self .nslices = frames , nslices
55+ self .contacts_filename = f"contacts_max{ self .max_cutoff } .pkl"
5556
5657 def run (self ):
5758 """Run contact analysis and save to `contacts_max{max_cutoff}.pkl`
@@ -90,11 +91,11 @@ def run(self):
9091 delimiter = ',' )
9192 contact_map .flush ()
9293
93- contact_map .dump (f'contacts_max { self .max_cutoff } .pkl' , protocol = 5 )
94+ contact_map .dump (self .contacts_filename , protocol = 5 )
9495 os .remove ('.tmpmap' )
9596 cfiles = glob .glob ('.contacts*' )
9697 [os .remove (f ) for f in cfiles ]
97- print (f'\n Saved contacts as "contacts_max { self .max_cutoff } .pkl ' )
98+ print (f'\n Saved contacts as "{ self .contacts_filename } " ' )
9899
99100 def _run_contacts (self , i , sliced_traj ):
100101 from basicrta .util import get_dec
@@ -384,8 +385,14 @@ def run(self):
384385 cutoff , nproc , nslices = args .cutoff , args .nproc , args .nslices
385386 ag1 = u .select_atoms (args .sel1 )
386387 ag2 = u .select_atoms (args .sel2 )
388+
389+ mc = MapContacts (u , ag1 , ag2 , nproc = nproc , nslices = nslices )
390+ mapname = mc .contacts_filename
391+ if not os .path .exists (mapname ):
392+ print (f"running MapContacts to generate { mapname } " )
393+ mc .run ()
394+ else :
395+ print (f"using existing { mapname } " )
387396
388- if not os .path .exists ('contacts.pkl' ):
389- MapContacts (u , ag1 , ag2 , nproc = nproc , nslices = nslices ).run ()
397+ ProcessContacts (cutoff , mapname , nproc = nproc ).run ()
390398
391- ProcessContacts (cutoff , nproc , map_name = 'contacts_max10.0.pkl' ).run ()
0 commit comments