forked from arneschneuing/DiffSBDD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_ligands.py
50 lines (40 loc) · 1.8 KB
/
generate_ligands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
from pathlib import Path
import torch
import utils
from lightning_modules import LigandPocketDDPM
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('checkpoint', type=Path)
parser.add_argument('--pdbfile', type=str)
parser.add_argument('--resi_list', type=str, nargs='+', default=None)
parser.add_argument('--ref_ligand', type=str, default=None)
parser.add_argument('--outdir', type=Path)
parser.add_argument('--n_samples', type=int, default=20)
parser.add_argument('--num_nodes_lig', type=int, default=None)
parser.add_argument('--all_frags', action='store_true')
parser.add_argument('--sanitize', action='store_true')
parser.add_argument('--relax', action='store_true')
parser.add_argument('--resamplings', type=int, default=10)
parser.add_argument('--jump_length', type=int, default=1)
parser.add_argument('--timesteps', type=int, default=None)
args = parser.parse_args()
pdb_id = Path(args.pdbfile).stem
device = 'cuda' if torch.cuda.is_available() else 'cpu'
# Load model
model = LigandPocketDDPM.load_from_checkpoint(
args.checkpoint, map_location=device)
model = model.to(device)
if args.num_nodes_lig is not None:
num_nodes_lig = torch.ones(args.n_samples, dtype=int) * \
args.num_nodes_lig
else:
num_nodes_lig = None
molecules = model.generate_ligands(
args.pdbfile, args.n_samples, args.resi_list, args.ref_ligand,
num_nodes_lig, args.sanitize, largest_frag=not args.all_frags,
relax_iter=(200 if args.relax else 0),
resamplings=args.resamplings, jump_length=args.jump_length,
timesteps=args.timesteps)
# Make SDF files
utils.write_sdf_file(Path(args.outdir, f'{pdb_id}_mol.sdf'), molecules)