Skip to content

Commit d93feb5

Browse files
committed
Tests for top N ranking post script, implements #21
1 parent 320caf7 commit d93feb5

20 files changed

+43744
-22
lines changed

bin/post/lgd_top.py

+37-22
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import os
77
import numpy as np
88
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
1010
from lightdock.util.logger import LoggingManager
1111
from lightdock.constants import DEFAULT_NMODES_REC, DEFAULT_NMODES_LIG, DEFAULT_REC_NM_FILE, DEFAULT_LIG_NM_FILE
1212
from lightdock.pdbutil.PDBIO import parse_complex_from_file, write_pdb_to_file
1313
from lightdock.structure.complex import Complex
1414
from lightdock.structure.nm import read_nmodes
1515
from lightdock.util.parser import CommandLineParser, get_lightdock_structures
16+
from lightdock.prep.simulation import get_setup_from_file
1617

1718

1819
log = LoggingManager.get_logger('lightdock_top')
@@ -33,9 +34,22 @@
3334
# Number of structures to generate
3435
parser.add_argument("top", help="number of structures to generate", type=CommandLineParser.valid_integer_number,
3536
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)
3641

3742
args = parser.parse_args()
3843

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+
3953
# Receptor
4054
structures = []
4155
for structure in get_lightdock_structures(args.receptor_structures):
@@ -55,7 +69,7 @@
5569
ligand = Complex.from_structures(structures)
5670

5771
# 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)
5973

6074
# Destination path is the same as the lightdock output
6175
destination_path = os.path.dirname(args.lightdock_ranking_file)
@@ -72,24 +86,25 @@
7286
if os.path.exists(nm_lig_file):
7387
nmodes_lig = read_nmodes(nm_lig_file)
7488

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)
95110
log.info("Generated %d conformations" % args.top)

0 commit comments

Comments
 (0)