Skip to content

Commit 54b9c8a

Browse files
authored
Merge pull request #36 from Becksteinlab/fixcontacts-script
Fix contacts script
2 parents 75695d6 + 4abecb4 commit 54b9c8a

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ The rules for this file:
1515
* YYYY-MM-DD date format (following ISO 8601)
1616
* accompany each entry with github issue/PR number (Issue #xyz)
1717
-->
18+
## [1.1.2] - 2025-07-??
19+
20+
### Authors
21+
* @rjoshi44
22+
23+
## Fixed
24+
* fixed contact script (issue #34)
25+
26+
1827
## [1.1.1] - 2025-07-18
1928

2029
### Authors

basicrta/contacts.py

100755100644
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
from tqdm import tqdm
42
from MDAnalysis.lib import distances
53
from multiprocessing import Pool, Lock
@@ -54,6 +52,7 @@ def __init__(self, u, ag1, ag2, nproc=1, frames=None,
5452
self.ag1, self.ag2 = ag1, ag2
5553
self.max_cutoff = max_cutoff
5654
self.frames, self.nslices = frames, nslices
55+
self.contacts_filename = f"contacts_max{self.max_cutoff}.pkl"
5756

5857
def run(self):
5958
"""Run contact analysis and save to `contacts_max{max_cutoff}.pkl`
@@ -92,11 +91,11 @@ def run(self):
9291
delimiter=',')
9392
contact_map.flush()
9493

95-
contact_map.dump(f'contacts_max{self.max_cutoff}.pkl', protocol=5)
94+
contact_map.dump(self.contacts_filename, protocol=5)
9695
os.remove('.tmpmap')
9796
cfiles = glob.glob('.contacts*')
9897
[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}"')
10099

101100
def _run_contacts(self, i, sliced_traj):
102101
from basicrta.util import get_dec
@@ -386,8 +385,14 @@ def run(self):
386385
cutoff, nproc, nslices = args.cutoff, args.nproc, args.nslices
387386
ag1 = u.select_atoms(args.sel1)
388387
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}")
389396

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()
392398

393-
ProcessContacts(cutoff, nproc, map_name='contacts_max10.0.pkl').run()

0 commit comments

Comments
 (0)