Skip to content

Commit 4abecb4

Browse files
committed
Fix contacts script
* Fix #34 * Define contacts filename in MapContacts.__init__ * Update CHANGELOG
1 parent 4981819 commit 4abecb4

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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'\nSaved contacts as "contacts_max{self.max_cutoff}.pkl')
98+
print(f'\nSaved 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

Comments
 (0)