Skip to content

Commit

Permalink
fixed deferred file writing and corrected associated cli
Browse files Browse the repository at this point in the history
  • Loading branch information
csbrasnett committed Dec 20, 2024
1 parent 2d1da84 commit 6c6f935
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bin/martinize2
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ def entry():
go_group.add_argument(
"-go-write-file",
dest="go_write_file",
action="store_false",
default=True,
action="store_true",
default=False,
help=("Write out contact map to file if calculating as part of Martinize2.")
)

Expand Down
37 changes: 20 additions & 17 deletions vermouth/rcsu/contact_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from scipy.spatial import cKDTree as KDTree
from ..graph_utils import make_residue_graph
from itertools import product
from vermouth.file_writer import DeferredFileWriter
from vermouth.file_writer import deferred_open
from pathlib import Path

# BOND TYPE
Expand Down Expand Up @@ -646,20 +646,23 @@ def _write_contacts(all_contacts, ca_pos, G):
residue graph of the input molecule
'''
# this to write out the file if needed
with DeferredFileWriter.open(Path('contact_map_vermouth.out'), 'w') as f:
count = 0
for contact in all_contacts:
count += 1
msg = (f"R {int(count): 6d} "
f"{int(contact[0]): 5d} {G.nodes[contact[2]]['resname']: 3s}"
f"{G.nodes[contact[2]]['chain']:1s} {int(G.nodes[contact[2]]['resid']): 4d} "
f"{int(contact[1]): 5d} {G.nodes[contact[3]]['resname']: 3s}"
f"{G.nodes[contact[3]]['chain']: 1s} {int(G.nodes[contact[3]]['resid']): 4d} "
f"{euclidean(ca_pos[contact[2]], ca_pos[contact[3]])*10: 9.4f} "
f"{int(contact[4]): 1d} {1 if contact[5] != 0 else 0} "
f"{1 if contact[6] != 0 else 0} {1 if contact[7] else 0}"
f"{int(contact[7]): 6d} {int(contact[5]): 6d}\n")
f.writelines(msg)
msgs = []
count = 0
for contact in all_contacts:
count += 1
msg = (f"R {int(count):6d} "
f"{int(contact[0]):5d} {G.nodes[contact[2]]['resname']:3s} "
f"{G.nodes[contact[2]]['chain']:1s} {int(G.nodes[contact[2]]['resid']):4d} "
f"{int(contact[1]):5d} {G.nodes[contact[3]]['resname']:3s} "
f"{G.nodes[contact[3]]['chain']:1s} {int(G.nodes[contact[3]]['resid']):4d} "
f"{euclidean(ca_pos[contact[2]], ca_pos[contact[3]])*10:9.4f} "
f"{int(contact[4]):1d} {1 if contact[5] != 0 else 0} "
f"{1 if contact[6] != 0 else 0} {1 if contact[7] else 0}"
f"{int(contact[7]): 6d} {int(contact[5]): 6d}\n")
msgs.append(msg)
message_out = ''.join(msgs)
with deferred_open('contact_map_vermouth.out', "w") as f:
f.write(message_out)


"""
Expand Down Expand Up @@ -741,8 +744,8 @@ class GenerateContactMap(Processor):
"""
Processor to generate the contact rCSU contact map for a protein from an atomistic structure
"""
def __init__(self, go_write_file):
self.write_file = go_write_file
def __init__(self, write_file):
self.write_file = write_file

def run_molecule(self, molecule):
"""
Expand Down

0 comments on commit 6c6f935

Please sign in to comment.