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

change path of GNN_ESM_MODEL #3

Merged
merged 1 commit into from
Jun 28, 2023
Merged
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
27 changes: 15 additions & 12 deletions src/deeprank_gnn/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@
# Constants
# TODO: Make these configurable
ESM_MODEL = "esm2_t33_650M_UR50D"
GNN_ESM_MODEL = "paper_pretrained_models/scoring_of_docking_models/gnn_esm/treg_yfnat_b64_e20_lr0.001_foldall_esm.pth.tar"
GNN_ESM_MODEL = (
Path(__file__).parent
/ "paper_pretrained_models/scoring_of_docking_models/gnn_esm/treg_yfnat_b64_e20_lr0.001_foldall_esm.pth.tar"
)
TOKS_PER_BATCH = 4096
REPR_LAYERS = [0, 32, 33]
TRUNCATION_SEQ_LENGTH = 1022
INCLUDE = ["mean", "per_tok"]
NPROC = mp.cpu_count() - 1 if mp.cpu_count() > 1 else 1
BATCH_SIZE = 64
DEVICE_NAME = "cuda" if torch.cuda.is_available() else "cpu" #configurable
DEVICE_NAME = "cuda" if torch.cuda.is_available() else "cpu" # configurable

'''
added two parameters in NeuralNet: num_workers and batch_size
default batch_size is 32, default num_workers is 1
"""
added two parameters in NeuralNet: num_workers and batch_size
default batch_size is 32, default num_workers is 1
for both, the higher the faster but depend on gpu capacity, should be configurable too
'''
"""
###########################################################


Expand All @@ -67,6 +70,7 @@ def setup_workspace(identificator: str) -> Path:
# log.info(f"WARNING: {workspace} already exists!")
return workspace


def renumber_pdb(pdb_file_path: Path) -> None:
"""Renumber PDB file starting from 1 with no gaps."""
log.info(f"Renumbering PDB file.")
Expand All @@ -80,7 +84,7 @@ def renumber_pdb(pdb_file_path: Path) -> None:
for chain in model:
if chain.id not in chain_residue_map:
chain_residue_map[chain.id] = {}

residue_number_map = {}
used_residue_numbers = set()

Expand All @@ -89,11 +93,10 @@ def renumber_pdb(pdb_file_path: Path) -> None:
new_residue_number += 1
residue_number_map[residue.id[1]] = new_residue_number
used_residue_numbers.add(new_residue_number)
residue.id = (' ', new_residue_number, ' ')

residue.id = (" ", new_residue_number, " ")

# Save the modified structure to the same file path
with open(str(pdb_file_path), 'w') as new_pdb_file:
with open(str(pdb_file_path), "w") as new_pdb_file:
io = PDB.PDBIO()
io.set_structure(structure)
io.save(new_pdb_file)
Expand Down Expand Up @@ -175,7 +178,7 @@ def get_embedding(fasta_file: Path, output_dir: Path) -> None:
result = {"label": label}
truncate_len = min(TRUNCATION_SEQ_LENGTH, len(strs[i]))
# Call clone on tensors to ensure tensors are not views into a larger representation
#See https://github.com/pytorch/pytorch/issues/1995
# See https://github.com/pytorch/pytorch/issues/1995
if "per_tok" in INCLUDE:
result["representations"] = {
layer: t[i, 1 : truncate_len + 1].clone()
Expand Down Expand Up @@ -310,7 +313,7 @@ def main():

## renumber PDB
renumber_pdb(pdb_file_path=pdb_file)

## PDB to FASTA
fasta_f = Path(workspace_path) / "all.fasta"
with open(fasta_f, "w") as f:
Expand Down