Skip to content

Commit 5022a1e

Browse files
author
Steven Ayoub
committed
Created Boresch restraint integrator
1 parent 5850f07 commit 5022a1e

2 files changed

Lines changed: 47 additions & 29 deletions

File tree

blues/moves.py

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -195,24 +195,51 @@ class RandomLigandRotationMove(Move):
195195
'LIG'
196196
"""
197197

198-
def __init__(self, structure, resname='LIG', ligand_indices=None, random_state=None):
198+
def __init__(self,
199+
structure,
200+
resname='LIG',
201+
ligand_indices=None,
202+
random_state=None, ligand_pdb_file=None,
203+
restraints=None, K_r=None, K_angle=None,
204+
restrained_receptor_atoms=None, restrained_ligand_atoms=None,
205+
lambda_restraints = "max(0, 1-(1/0.10)*abs(lambda-0.5))",
206+
no_move=False,
207+
):
199208
self.structure = structure
200209
self.resname = resname
201210
self.random_state = random_state
202211
self.atom_indices = self.getAtomIndices(structure, self.resname)
203212
self.ligand_indices = ligand_indices
204213
self.topology = structure[self.atom_indices].topology
205214
self.totalmass = 0
215+
self.restraints = restraints
206216
self.masses = []
207217
self.center_of_mass = None
218+
self.K_r = K_r
219+
self.K_angle = K_angle
220+
self.lambda_restraints = lambda_restraints
221+
self.restrained_receptor_atoms = restrained_receptor_atoms
222+
self.restrained_ligand_atoms = restrained_ligand_atoms
208223
self.positions = structure[self.atom_indices].positions
224+
self.no_move = no_move
209225
if self.ligand_indices:
210226
self.topology = structure[self.ligand_indices].topology
211227
self.positions = structure[self.ligand_indices].positions
212-
228+
229+
if ligand_pdb_file is not None:
230+
self._loadBindingModeTraj(ligand_pdb_file)
213231
self._calculateProperties()
214232

215233

234+
def _loadBindingModeTraj(self, ligand_pdb_file):
235+
"""
236+
Load the binding mode trajectory from the file.
237+
"""
238+
import mdtraj as md
239+
binding_mode_traj = []
240+
binding_mode_traj.append(md.load(ligand_pdb_file))
241+
self.binding_mode_traj = binding_mode_traj
242+
216243
def initializeSystem(self, system, integrator, config):
217244
"""
218245
Changes the system by adding forces corresponding to restraints (if specified)
@@ -299,30 +326,17 @@ def initializeRestraints(self, system: openmm.System, integrator: openmm.Integra
299326
integrator_kwargs = config or {}
300327

301328
# Get integrator kwargs if available, otherwise use defaults
302-
# Create new integrator with restraints
303-
304-
if self.old_restraint:
305-
new_int = AlchemicalExternalRestrainedLangevinIntegrator(
306-
restraint_group=set(self.restraint_groups.values()),
307-
lambda_restraints=self.lambda_restraints,
308-
alchemical_functions = old_int._alchemical_functions,
309-
nsteps_neq=integrator_kwargs['nstepsNC'],
310-
nprop=integrator_kwargs['nprop'],
311-
prop_lambda=integrator_kwargs['propLambda'],
312-
splitting=integrator_kwargs['splitting'],)
313-
314-
else:
315-
new_int = AlchemicalExternalLangevinIntegrator(
316-
restraint_group=set(self.restraint_groups.values()),
317-
lambda_restraints=self.lambda_restraints,
318-
alchemical_functions = old_int._alchemical_functions,
319-
nsteps_neq=integrator_kwargs['nstepsNC'],
320-
nprop=integrator_kwargs['nprop'],
321-
prop_lambda=integrator_kwargs['propLambda'],
322-
splitting=integrator_kwargs['splitting'])
323-
#**old_int.int_kwargs)
324-
325-
new_int.reset()
329+
new_int = AlchemicalExternalLangevinIntegrator(
330+
restraint_group=set(self.restraint_groups.values()),
331+
lambda_restraints=self.lambda_restraints,
332+
alchemical_functions = old_int._alchemical_functions,
333+
nsteps_neq=integrator_kwargs['nstepsNC'],
334+
nprop=integrator_kwargs['nprop'],
335+
prop_lambda=integrator_kwargs['propLambda'],
336+
splitting=integrator_kwargs['splitting'])
337+
#**old_int.int_kwargs)
338+
339+
#new_int.reset()
326340

327341
# Verify we have the required trajectory data
328342
if not hasattr(self, 'binding_mode_traj') or len(self.binding_mode_traj) == 0:
@@ -350,8 +364,7 @@ def initializeRestraints(self, system: openmm.System, integrator: openmm.Integra
350364
new_sys = add_boresch_restraints(sys=new_sys, struct=self.structure, pos=pose_allpos, ligand_atoms=self.atom_indices,
351365
pose_num=index, force_group=self.restraint_groups['boresch'],
352366
restrained_receptor_atoms=self.restrained_receptor_atoms, restrained_ligand_atoms=self.restrained_ligand_atoms,
353-
K_r=self.K_r, K_angle=self.K_angle, K_RMSD=self.K_RMSD, RMSD0=self.RMSD0,
354-
K_com=self.K_com)
367+
K_r=self.K_r, K_angle=self.K_angle)
355368

356369
if 'boresch' not in self.restraints and 'rmsd' not in self.restraints:
357370
raise ValueError(f'Invalid restraint type: {self.restraints}')
@@ -469,6 +482,8 @@ def move(self, context):
469482
context: openmm.openmm.Context object
470483
The same input context, but whose positions were changed by this function.
471484
"""
485+
if self.no_move:
486+
return context
472487
positions = context.getState(getPositions=True).getPositions(asNumpy=True)
473488

474489
self.positions = positions[self.atom_indices]

blues/simulation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,10 @@ def generateSimulationSet(self, config=None):
805805

806806
#Initialize the Move Engine with the Alchemical System and NCMC Integrator
807807
for move in self._move_engine.moves:
808-
self._alch_system, self.ncmc_integrator = move.initializeSystem(self._alch_system, self.ncmc_integrator)
808+
try:
809+
self._alch_system, self.ncmc_integrator = move.initializeSystem(self._alch_system, self.ncmc_integrator)
810+
except TypeError:
811+
self._alch_system, self.ncmc_integrator = move.initializeSystem(self._alch_system, self.ncmc_integrator, config=config)
809812
self.ncmc = self.generateSimFromStruct(self._structure, self._alch_system, self.ncmc_integrator, **config)
810813
utils.print_host_info(self.ncmc)
811814

0 commit comments

Comments
 (0)