Skip to content

Commit

Permalink
Merge branch '1192-add-solvent-model-cli' into mikemhenry-patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
ijpulidos committed Jun 9, 2023
2 parents 1a7f712 + 135dc60 commit cd0e440
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
3 changes: 3 additions & 0 deletions examples/new-cli/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ phases:
# Use geometry-derived mapping
use_given_geometries: true
given_geometries_tolerance: 0.4 # angstroms

# Solvent model
solvent_model: "tip3p"
21 changes: 15 additions & 6 deletions perses/app/relative_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(self,
use_given_geometries = False,
given_geometries_tolerance=0.2*unit.angstroms,
transform_waters_into_ions_for_charge_changes=True,
solvent_model="tip3p"
):
"""
Initialize a NonequilibriumFEPSetup object
Expand Down Expand Up @@ -160,6 +161,7 @@ def __init__(self,
self._use_given_geometries = use_given_geometries
self._given_geometries_tolerance = given_geometries_tolerance
self.small_molecule_forcefield = small_molecule_forcefield
self._solvent_model = solvent_model
if isinstance(ligand_input, str):
self._ligand_input = AnyPath(ligand_input)
else:
Expand Down Expand Up @@ -408,7 +410,9 @@ def __init__(self,
_logger.info(f"setting up complex phase...")
self._setup_complex_phase()
self._complex_topology_old_solvated, self._complex_positions_old_solvated, self._complex_system_old_solvated = self._solvate_system(
self._complex_topology_old, self._complex_positions_old,phase='complex',box_dimensions=self._complex_box_dimensions, ionic_strength=self._ionic_strength)
self._complex_topology_old, self._complex_positions_old, phase='complex',
box_dimensions=self._complex_box_dimensions, ionic_strength=self._ionic_strength,
model=self._solvent_model)
_logger.info(f"successfully generated complex topology, positions, system")

self._complex_md_topology_old_solvated = md.Topology.from_openmm(self._complex_topology_old_solvated)
Expand Down Expand Up @@ -466,7 +470,9 @@ def __init__(self,
_logger.info(f"no complex detected in phases...generating unique topology/geometry proposals...")
_logger.info(f"solvating ligand...")
self._ligand_topology_old_solvated, self._ligand_positions_old_solvated, self._ligand_system_old_solvated = self._solvate_system(
self._ligand_topology_old, self._ligand_positions_old,phase='solvent',box_dimensions=self._solvent_box_dimensions,ionic_strength=self._ionic_strength)
self._ligand_topology_old, self._ligand_positions_old, phase='solvent',
box_dimensions=self._solvent_box_dimensions, ionic_strength=self._ionic_strength,
model=self._solvent_model)
self._ligand_md_topology_old_solvated = md.Topology.from_openmm(self._ligand_topology_old_solvated)

_logger.info(f"creating TopologyProposal")
Expand Down Expand Up @@ -532,8 +538,10 @@ def __init__(self,

if self._proposal_phase is None:
_logger.info('No complex or solvent leg, so performing topology proposal for vacuum leg')
self._vacuum_topology_old, self._vacuum_positions_old, self._vacuum_system_old = self._solvate_system(self._ligand_topology_old,
self._ligand_positions_old,phase='vacuum')
# FIXME: We shouldn't use a "solvate" system method for the vacuum phase. Separate functionalities.
self._vacuum_topology_old, self._vacuum_positions_old, self._vacuum_system_old = self._solvate_system(
self._ligand_topology_old,
self._ligand_positions_old, phase='vacuum', model=self._solvent_model)
self._vacuum_topology_proposal = self._proposal_engine.propose(self._vacuum_system_old,
self._vacuum_topology_old,
current_mol_id=0, proposed_mol_id=1)
Expand Down Expand Up @@ -666,7 +674,8 @@ def _generate_solvent_topologies(self, topology_proposal, old_positions):

# solvate the old ligand topology:
old_solvated_topology, old_solvated_positions, old_solvated_system = self._solvate_system(
old_ligand_topology.to_openmm(), old_ligand_positions,phase='solvent', box_dimensions=self._solvent_box_dimensions)
old_ligand_topology.to_openmm(), old_ligand_positions, phase='solvent',
box_dimensions=self._solvent_box_dimensions, model=self._solvent_model)

old_solvated_md_topology = md.Topology.from_openmm(old_solvated_topology)

Expand Down Expand Up @@ -826,7 +835,7 @@ def _solvate_system(self, topology, positions, model='tip3p',phase='complex', bo
forcefield : SystemGenerator.forcefield
forcefield file of solvent to add
model : str, default 'tip3p'
solvent model to use for solvation
solvent model to use for solvation. Supported values are 'tip3p', 'spce', 'tip4pew', 'tip5p', and 'swm4ndp' (polarizable)
box_dimensions : tuple of Vec3, default None
if not None, padding distance will be omitted in favor of a pre-specified set of box dimensions
Expand Down
37 changes: 25 additions & 12 deletions perses/app/setup_relative_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,24 +506,37 @@ def run_setup(setup_options, serialize_systems=True, build_samplers=True):

if 'topology_proposal' not in list(setup_options.keys()) or setup_options['topology_proposal'] is None:
_logger.info(f"\tno topology_proposal specified; proceeding to RelativeFEPSetup...\n\n\n")
# TODO: This if-else is not doing anything as far as I can tell. Remove?
if 'set_solvent_box_dims_to_complex' in list(setup_options.keys()) and setup_options['set_solvent_box_dims_to_complex']:
set_solvent_box_dims_to_complex=True
else:
set_solvent_box_dims_to_complex=False

_logger.info(f'Box dimensions: {setup_options["complex_box_dimensions"]} and {setup_options["solvent_box_dimensions"]}')
fe_setup = RelativeFEPSetup(ligand_file, old_ligand_index, new_ligand_index, forcefield_files,phases=phases,
protein_pdb_filename=protein_pdb_filename,
receptor_mol2_filename=receptor_mol2, pressure=pressure,
temperature=temperature, solvent_padding=solvent_padding_angstroms, spectator_filenames=setup_options['spectators'],
map_strength=setup_options['map_strength'],
atom_expr=setup_options['atom_expr'], bond_expr=setup_options['bond_expr'],
neglect_angles = setup_options['neglect_angles'], anneal_14s = setup_options['anneal_1,4s'],
small_molecule_forcefield=setup_options['small_molecule_forcefield'], small_molecule_parameters_cache=setup_options['small_molecule_parameters_cache'],
trajectory_directory=trajectory_directory, trajectory_prefix=setup_options['trajectory_prefix'], nonbonded_method=setup_options['nonbonded_method'],
complex_box_dimensions=setup_options['complex_box_dimensions'],solvent_box_dimensions=setup_options['solvent_box_dimensions'], ionic_strength=ionic_strength, remove_constraints=setup_options['remove_constraints'],
use_given_geometries=use_given_geometries, given_geometries_tolerance=given_geometries_tolerance,
transform_waters_into_ions_for_charge_changes = setup_options['transform_waters_into_ions_for_charge_changes'])
fe_setup = RelativeFEPSetup(ligand_file, old_ligand_index, new_ligand_index, forcefield_files, phases=phases,
protein_pdb_filename=protein_pdb_filename,
receptor_mol2_filename=receptor_mol2, pressure=pressure,
temperature=temperature, solvent_padding=solvent_padding_angstroms,
spectator_filenames=setup_options['spectators'],
map_strength=setup_options['map_strength'],
atom_expr=setup_options['atom_expr'], bond_expr=setup_options['bond_expr'],
neglect_angles=setup_options['neglect_angles'],
anneal_14s=setup_options['anneal_1,4s'],
small_molecule_forcefield=setup_options['small_molecule_forcefield'],
small_molecule_parameters_cache=setup_options['small_molecule_parameters_cache'],
trajectory_directory=trajectory_directory,
trajectory_prefix=setup_options['trajectory_prefix'],
nonbonded_method=setup_options['nonbonded_method'],
complex_box_dimensions=setup_options['complex_box_dimensions'],
solvent_box_dimensions=setup_options['solvent_box_dimensions'],
ionic_strength=ionic_strength,
remove_constraints=setup_options['remove_constraints'],
use_given_geometries=use_given_geometries,
given_geometries_tolerance=given_geometries_tolerance,
transform_waters_into_ions_for_charge_changes=setup_options[
'transform_waters_into_ions_for_charge_changes'],
solvent_model=setup_options.get("solvent_model", "tip3p"),
)


_logger.info(f"\twriting pickle output...")
Expand Down

0 comments on commit cd0e440

Please sign in to comment.