|
1 | | -#!/usr/bin/env python |
2 | | - |
3 | 1 | from tqdm import tqdm |
4 | 2 | from MDAnalysis.lib import distances |
5 | 3 | from multiprocessing import Pool, Lock |
@@ -54,6 +52,7 @@ def __init__(self, u, ag1, ag2, nproc=1, frames=None, |
54 | 52 | self.ag1, self.ag2 = ag1, ag2 |
55 | 53 | self.max_cutoff = max_cutoff |
56 | 54 | self.frames, self.nslices = frames, nslices |
| 55 | + self.contacts_filename = f"contacts_max{self.max_cutoff}.pkl" |
57 | 56 |
|
58 | 57 | def run(self): |
59 | 58 | """Run contact analysis and save to `contacts_max{max_cutoff}.pkl` |
@@ -92,11 +91,11 @@ def run(self): |
92 | 91 | delimiter=',') |
93 | 92 | contact_map.flush() |
94 | 93 |
|
95 | | - contact_map.dump(f'contacts_max{self.max_cutoff}.pkl', protocol=5) |
| 94 | + contact_map.dump(self.contacts_filename, protocol=5) |
96 | 95 | os.remove('.tmpmap') |
97 | 96 | cfiles = glob.glob('.contacts*') |
98 | 97 | [os.remove(f) for f in cfiles] |
99 | | - print(f'\nSaved contacts as "contacts_max{self.max_cutoff}.pkl') |
| 98 | + print(f'\nSaved contacts as "{self.contacts_filename}"') |
100 | 99 |
|
101 | 100 | def _run_contacts(self, i, sliced_traj): |
102 | 101 | from basicrta.util import get_dec |
@@ -386,8 +385,14 @@ def run(self): |
386 | 385 | cutoff, nproc, nslices = args.cutoff, args.nproc, args.nslices |
387 | 386 | ag1 = u.select_atoms(args.sel1) |
388 | 387 | 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}") |
389 | 396 |
|
390 | | - if not os.path.exists('contacts.pkl'): |
391 | | - MapContacts(u, ag1, ag2, nproc=nproc, nslices=nslices).run() |
| 397 | + ProcessContacts(cutoff, mapname, nproc=nproc).run() |
392 | 398 |
|
393 | | - ProcessContacts(cutoff, nproc, map_name='contacts_max10.0.pkl').run() |
|
0 commit comments