Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dHisCu rotlibs to match those used in submitted manuscript. Enhance update_rotlib.py script. #118

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions scripts/update_rotlib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /usr/bin/env python
from pathlib import Path
from zipfile import ZipFile
from io import BytesIO
import numpy as np
Expand All @@ -16,21 +17,36 @@
'(compatible) versions.',
)
parser.add_argument('files_names', nargs='+', help='Names of the old rotlib files you wish to update')
parser.add_argument('-d', '--description', default=None, help='Description text you would like to add to the rotamer '
'library. Can be a string or a file')
parser.add_argument('-c', '--comment', default=None, help='Description text you would like to add to the rotamer '
'library. can be a string or a file')
parser.add_argument('-r', '--reference', default=None, help='Reference text you would like to add to the rotamer '
'library can be a string or a file.')

args = parser.parse_args()


def main():

adding_metadata = ((args.description is not None) or
(args.comment is not None) or
(args.reference is not None))

if adding_metadata and len(args.files_names) > 1:
raise RuntimeError("You can only add descriptions, comments, or references when updating one library at a time")

description = check_textfile(args.description)
comment = check_textfile(args.comment)
reference = check_textfile(args.reference)

for filename in args.files_names:

if filename.endswith('_rotlib.npz'):
shutil.copy(filename, filename + '.bku')
data = get_data(filename)
data = get_data(filename, description, comment, reference)
np.savez(filename, **data)


elif filename.endswith('_drotlib.zip'):
shutil.copy(filename, filename + '.bku')
libname = filename[:-12]
Expand All @@ -43,11 +59,11 @@ def main():
np.save(f'{libname}_csts.npy', csts)
elif f[-12] == 'A':
with archive.open(f) as of:
libA = get_data(of)
libA = get_data(of, description, comment, reference)
np.savez(f'{libname}A_rotlib.npz', **libA)
elif f[-12] == 'B':
with archive.open(f) as of:
libB = get_data(of)
libB = get_data(of, description, comment, reference)
np.savez(f'{libname}B_rotlib.npz', **libB)

with zipfile.ZipFile(f'{libname}_drotlib.zip', mode='w') as archive:
Expand Down Expand Up @@ -146,4 +162,17 @@ def get_data_1_2(filename):

return data

def check_textfile(file):

if Path(str(file)).exists():

with open(file, 'r') as f:
lines = f.readlines()

lines = "\n".join(lines)
else:
lines = file

return lines

main()
54 changes: 34 additions & 20 deletions src/chilife/chilife.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,40 +1185,54 @@ def safe_save(file: Union[str, Path], data: dict, backup: dict):


def _print_monofunc(files):
print(f"{'monofunctional' + ':':^60}")
print("-" * 60)
maxw = max([len(file.stem) for file in files]) - 6
wrapper = textwrap.TextWrapper(width=80, subsequent_indent=" "*(maxw + 3),
replace_whitespace=False, drop_whitespace=False)

print(f"{'monofunctional' + ':':^80}")
print("-" * 80)

for file in files:
with np.load(file, allow_pickle=True) as f:
for key in f.keys():
resname = f['resname']
resname = file.stem
if resname.endswith('_rotlib'):
resname = resname[:-len('_rotlib')]
if 'description' in f:
descr = f['description']
else:
descr = "No description"

print(f'{resname:<8} : {descr}')
print("-" * 60)
print("\n".join(wrapper.wrap(f'{resname:<{maxw}} : {descr}')))
print("-" * 80)


def _print_bifunc(files):
print(f"{'bifunctional' + ':':^60}")
print("-" * 60)

maxw = max([len(file.stem) for file in files]) - 7
wrapper = textwrap.TextWrapper(width=80, subsequent_indent=" "*(maxw + 3),
replace_whitespace=False, drop_whitespace=False)


print(f"{'bifunctional' + ':':^80}")
print("-" * 80)

for file in files:
with zipfile.ZipFile(file, 'r') as archive:
name = archive.namelist()[0]
resname = name[:3]
resname = file.stem
context = name[3:6]
if resname.endswith('_drotlib'):
resname = resname[:-len('_drotlib')]
with archive.open(name) as of:
with np.load(of, allow_pickle=True) as f:
if 'description' in f:
descr = f['description']
else:
descr = "No description"

print(f'{resname:<4}{context:<4} : {descr}')
print("-" * 60)
print("\n".join(wrapper.wrap(f'{resname:<{maxw}} : {descr} in the {context} context')))
print("-" * 80)


def list_available_rotlibs():
Expand All @@ -1238,22 +1252,22 @@ def list_available_rotlibs():
bifunctional = tuple(dpath.glob('*_drotlib.zip'))
if len(monofunctional) + len(bifunctional) > 0:

print("*" * 60)
print(f"*{f'Rotlibs in {dname}':^58}*")
print("*" * 80)
print(f"*{f'Rotlibs in {dname}':^78}*")
if 'user' in dname:
print(f'*{dname.name:^58}*')
print("*" * 60)
print(f'*{dname.name:^78}*')
print("*" * 80)

if len(monofunctional) > 0 : _print_monofunc(monofunctional)
if len(bifunctional) > 0 : _print_bifunc(bifunctional)

print()
print("*" * 60)
print(f"*{'DUNBRACK ROTLIBS':^58}*")
print(f"*{'ARG, ASN, ASP, CSY, GLN, GLU, HIS, ILE, LEU, LYS, MET,':^58}*")
print(f"*{'PHE, PRO, SER, THR, TRP, TYR, VAL':^58}*")
print(f"*{'(no ALA, GLY}':^58}*")
print("*" * 60)
print("*" * 80)
print(f"*{'DUNBRACK ROTLIBS':^78}*")
print(f"*{'ARG, ASN, ASP, CSY, GLN, GLU, HIS, ILE, LEU, LYS, MET, PHE, PRO, SER,':^78}*")
print(f"*{'THR, TRP, TYR, VAL':^78}*")
print(f"*{'(no ALA, GLY}':^78}*")
print("*" * 80)


def add_rotlib_dir(directory: Union[Path, str]) -> None:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.