Skip to content

Commit

Permalink
Code cleaning and minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
brennanaba committed Nov 10, 2022
1 parent 07f4bf5 commit 08143a5
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ImmuneBuilder/ABodyBuilder2.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def save_all(self, dirname=None, filename=None):
np.save(os.path.join(dirname,"error_estimates"), self.error_estimates.mean(0).cpu().numpy())
final_filename = os.path.join(dirname, filename)
refine(os.path.join(dirname,"rank0_unrefined.pdb"), final_filename)
add_errors_as_bfactors(final_filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), new_txt=[header])
add_errors_as_bfactors(final_filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), header=[header])


def save(self, filename=None):
Expand All @@ -82,7 +82,7 @@ def save(self, filename=None):

if not success:
print(f"FAILED TO REFINE {filename}.\nSaving anyways.", flush=True)
add_errors_as_bfactors(filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), new_txt=[header])
add_errors_as_bfactors(filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), header=[header])


class ABodyBuilder2:
Expand Down
4 changes: 2 additions & 2 deletions ImmuneBuilder/NanoBodyBuilder2.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def save_all(self, dirname=None, filename=None):
np.save(os.path.join(dirname,"error_estimates"), self.error_estimates.mean(0).cpu().numpy())
final_filename = os.path.join(dirname, filename)
refine(os.path.join(dirname,"rank0_unrefined.pdb"), final_filename)
add_errors_as_bfactors(final_filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), new_txt=[header])
add_errors_as_bfactors(final_filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), header=[header])


def save(self, filename=None):
Expand All @@ -82,7 +82,7 @@ def save(self, filename=None):

if not success:
print(f"FAILED TO REFINE {filename}.\nSaving anyways.", flush=True)
add_errors_as_bfactors(filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), new_txt=[header])
add_errors_as_bfactors(filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), header=[header])


class NanoBodyBuilder2:
Expand Down
6 changes: 3 additions & 3 deletions ImmuneBuilder/TCRBuilder2.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def save_all(self, dirname=None, filename=None):
np.save(os.path.join(dirname,"error_estimates"), self.error_estimates.mean(0).cpu().numpy())
final_filename = os.path.join(dirname, filename)
refine(os.path.join(dirname,"rank0_unrefined.pdb"), final_filename)
add_errors_as_bfactors(final_filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), new_txt=[header])
add_errors_as_bfactors(final_filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), header=[header])


def save(self, filename=None):
Expand All @@ -82,7 +82,7 @@ def save(self, filename=None):

if not success:
print(f"FAILED TO REFINE {filename}.\nSaving anyways.", flush=True)
add_errors_as_bfactors(filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), new_txt=[header])
add_errors_as_bfactors(filename, self.error_estimates.mean(0).sqrt().cpu().numpy(), header=[header])


class TCRBuilder2:
Expand Down Expand Up @@ -164,7 +164,7 @@ def command_line_interface():
print("Running sequences through deep learning model...", flush=True)

try:
antibody = tcr = TCRBuilder2().predict(seqs)
tcr = TCRBuilder2().predict(seqs)
except AssertionError as e:
print(e, flush=True)
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion ImmuneBuilder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def forward(self, node_features, sequence):

# Remove atoms of side chains with outrageous clashes
ds = torch.linalg.norm(all_atoms[None,:,None] - all_atoms[:,None,:,None], axis = -1)
ds[(ds!=ds) | (ds==0.0)] = 10
ds[torch.isnan(ds!=ds) | (ds==0.0)] = 10
min_ds = ds.min(dim=-1)[0].min(dim=-1)[0].min(dim=-1)[0]
all_atoms[min_ds < 0.2, 5:, :] = float("Nan")

Expand Down
4 changes: 3 additions & 1 deletion ImmuneBuilder/rigids.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ def __init__(self, origin, rot):
def __matmul__(self, other):
if isinstance(other, Vector):
return self.rot @ other + self.origin
if isinstance(other, Rigid):
elif isinstance(other, Rigid):
return Rigid(self.rot @ other.origin + self.origin, self.rot @ other.rot)
else:
raise TypeError(f"can't multiply rigid by object of type {type(other)}")

def inv(self):
inv_rot = self.rot.inv()
Expand Down
3 changes: 2 additions & 1 deletion ImmuneBuilder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ def sequence_dict_from_fasta(fasta_file):
return out


def add_errors_as_bfactors(filename, errors, new_txt=[]):
def add_errors_as_bfactors(filename, errors, header=[]):

with open(filename) as file:
txt = file.readlines()

new_txt = header.copy()
residue_index = -1
position = " "

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='ImmuneBuilder',
version='0.0.3',
version='0.0.4',
description='Set of functions to predict the structure of immune receptor proteins',
license='BSD 3-clause license',
maintainer='Brennan Abanades',
Expand Down

0 comments on commit 08143a5

Please sign in to comment.