|
6 | 6 | import os
|
7 | 7 | import numpy as np
|
8 | 8 | from lightdock.mathutil.cython.quaternion import Quaternion
|
9 |
| -from lightdock.util.analysis import read_lightdock_output |
| 9 | +from lightdock.util.analysis import read_ranking_file |
10 | 10 | from lightdock.util.logger import LoggingManager
|
11 | 11 | from lightdock.constants import DEFAULT_NMODES_REC, DEFAULT_NMODES_LIG, DEFAULT_REC_NM_FILE, DEFAULT_LIG_NM_FILE
|
12 | 12 | from lightdock.pdbutil.PDBIO import parse_complex_from_file, write_pdb_to_file
|
13 | 13 | from lightdock.structure.complex import Complex
|
14 | 14 | from lightdock.structure.nm import read_nmodes
|
15 | 15 | from lightdock.util.parser import CommandLineParser, get_lightdock_structures
|
| 16 | +from lightdock.prep.simulation import get_setup_from_file |
16 | 17 |
|
17 | 18 |
|
18 | 19 | log = LoggingManager.get_logger('lightdock_top')
|
|
33 | 34 | # Number of structures to generate
|
34 | 35 | parser.add_argument("top", help="number of structures to generate", type=CommandLineParser.valid_integer_number,
|
35 | 36 | metavar="top")
|
| 37 | + # Optional, setup file |
| 38 | + parser.add_argument("--setup", "-setup", "-s", help="Simulation setup file", |
| 39 | + dest="setup_file", metavar="setup_file", type=CommandLineParser.valid_file, |
| 40 | + default=None) |
36 | 41 |
|
37 | 42 | args = parser.parse_args()
|
38 | 43 |
|
| 44 | + # Load setup configuration if provided |
| 45 | + setup = get_setup_from_file(args.setup_file) if args.setup_file else None |
| 46 | + |
| 47 | + num_anm_rec = DEFAULT_NMODES_REC |
| 48 | + num_anm_lig = DEFAULT_NMODES_LIG |
| 49 | + if setup and setup['use_anm']: |
| 50 | + num_anm_rec = setup['anm_rec'] |
| 51 | + num_anm_lig = setup['anm_lig'] |
| 52 | + |
39 | 53 | # Receptor
|
40 | 54 | structures = []
|
41 | 55 | for structure in get_lightdock_structures(args.receptor_structures):
|
|
55 | 69 | ligand = Complex.from_structures(structures)
|
56 | 70 |
|
57 | 71 | # Read ranking file
|
58 |
| - glowworms = read_lightdock_output(args.lightdock_ranking_file, initial=1, final=args.top) |
| 72 | + predictions = read_ranking_file(args.lightdock_ranking_file) |
59 | 73 |
|
60 | 74 | # Destination path is the same as the lightdock output
|
61 | 75 | destination_path = os.path.dirname(args.lightdock_ranking_file)
|
|
72 | 86 | if os.path.exists(nm_lig_file):
|
73 | 87 | nmodes_lig = read_nmodes(nm_lig_file)
|
74 | 88 |
|
75 |
| - for i, glowworm in enumerate(glowworms): |
76 |
| - receptor_pose = receptor.atom_coordinates[glowworm.receptor_id].clone() |
77 |
| - ligand_pose = ligand.atom_coordinates[glowworm.ligand_id].clone() |
78 |
| - # Use normal modes if provided: |
79 |
| - if nmodes_rec.any(): |
80 |
| - for nm in range(DEFAULT_NMODES_REC): |
81 |
| - rec_extent = np.array([float(x) for x in glowworm.pose[7:7 + DEFAULT_NMODES_REC]]) |
82 |
| - receptor_pose.coordinates += nmodes_rec[nm] * rec_extent[nm] |
83 |
| - if nmodes_lig.any(): |
84 |
| - for nm in range(DEFAULT_NMODES_LIG): |
85 |
| - lig_extent = np.array([float(x) for x in glowworm.pose[-DEFAULT_NMODES_LIG:]]) |
86 |
| - ligand_pose.coordinates += nmodes_lig[nm] * lig_extent[nm] |
87 |
| - |
88 |
| - # We rotate first, ligand it's at initial position |
89 |
| - rotation = Quaternion(glowworm.pose[3], glowworm.pose[4], glowworm.pose[5], glowworm.pose[6]) |
90 |
| - ligand_pose.rotate(rotation) |
91 |
| - ligand_pose.translate([glowworm.pose[0], glowworm.pose[1], glowworm.pose[2]]) |
92 |
| - |
93 |
| - write_pdb_to_file(receptor, os.path.join(destination_path, 'top_%s.pdb' % str(i+1)), receptor_pose) |
94 |
| - write_pdb_to_file(ligand, os.path.join(destination_path, 'top_%s.pdb' % str(i+1)), ligand_pose) |
| 89 | + for i, glowworm in enumerate(predictions): |
| 90 | + if i < args.top: |
| 91 | + receptor_pose = receptor.atom_coordinates[glowworm.receptor_id].clone() |
| 92 | + ligand_pose = ligand.atom_coordinates[glowworm.ligand_id].clone() |
| 93 | + # Use normal modes if provided: |
| 94 | + if nmodes_rec.any(): |
| 95 | + for nm in range(num_anm_rec): |
| 96 | + rec_extent = np.array([float(x) for x in glowworm.pose[7:7 + num_anm_rec]]) |
| 97 | + receptor_pose.coordinates += nmodes_rec[nm] * rec_extent[nm] |
| 98 | + if nmodes_lig.any(): |
| 99 | + for nm in range(num_anm_lig): |
| 100 | + lig_extent = np.array([float(x) for x in glowworm.pose[-num_anm_lig:]]) |
| 101 | + ligand_pose.coordinates += nmodes_lig[nm] * lig_extent[nm] |
| 102 | + |
| 103 | + # We rotate first, ligand it's at initial position |
| 104 | + rotation = Quaternion(glowworm.pose[3], glowworm.pose[4], glowworm.pose[5], glowworm.pose[6]) |
| 105 | + ligand_pose.rotate(rotation) |
| 106 | + ligand_pose.translate([glowworm.pose[0], glowworm.pose[1], glowworm.pose[2]]) |
| 107 | + |
| 108 | + write_pdb_to_file(receptor, os.path.join(destination_path, 'top_%s.pdb' % str(i+1)), receptor_pose) |
| 109 | + write_pdb_to_file(ligand, os.path.join(destination_path, 'top_%s.pdb' % str(i+1)), ligand_pose) |
95 | 110 | log.info("Generated %d conformations" % args.top)
|
0 commit comments