Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli protocol settings via yaml input #770

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
21 changes: 20 additions & 1 deletion docs/guide/cli/cli_yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ as an example, the settings file which re-specifies the default behaviour would
threed: True
max3d: 0.95
element_change: True
protocol:
method: RelativeHybridTopologyProtocol

The name of the algorithm is given behind the ``method:`` key and the arguments to the
algorithm are then optionally given behind the ``settings:`` key.
Both the `network:` and `mapper:` sections are optional.
The ``network:``, ``mapper:``, and ``protocol:`` sections are all optional.

This is then provided to the ``openfe plan-rbfe-network`` command as ::

Expand Down Expand Up @@ -76,3 +78,20 @@ settings file ::
method: generate_radial_network
settings:
central_ligand: '0'

Customising the Protocol
-------------------------

The Settings of a Protocol can be customised. The settings variable names map directly between the Python API and
yaml settings files. For example, to customise the production length of
the RFE Protocol, from Python would require a line of code such as::

settings.simulation_settings.production_length = '5.4 ns'

This would be achieved via the yaml file as::

protocol:
method: RelativeHybridTopologyProtocol
settings:
simulation_settings:
production_length: 5.4 ns
8 changes: 7 additions & 1 deletion openfe/setup/ligand_network_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,18 @@ def generate_radial_network(
# handle central_ligand arg possibilities
# after this, central_ligand is resolved to a SmallMoleculeComponent
if isinstance(central_ligand, int):
central_ligand_index = central_ligand
ligands = list(ligands)
try:
central_ligand = ligands[central_ligand]
central_ligand = ligands[central_ligand_index]
except IndexError:
raise ValueError(f"index '{central_ligand}' out of bounds, there are "
f"{len(ligands)} ligands")
# you could do a list comprehension like:
# ligands = [l for l in ligands if l != central]
# but this wouldn't properly catch when multiple identical central ligands have been passed
# so instead slice out the central ligand
ligands = ligands[:central_ligand_index] + ligands[central_ligand_index + 1:]
elif isinstance(central_ligand, str):
ligands = list(ligands)
possibles = [l for l in ligands if l.name == central_ligand]
Expand Down
6 changes: 6 additions & 0 deletions openfecli/commands/plan_rbfe_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def plan_rbfe_network_main(
solvent,
protein,
cofactors,
protocol=None,
):
"""Utility method to plan a relative binding free energy network.

Expand All @@ -37,6 +38,8 @@ def plan_rbfe_network_main(
protein component for complex simulations, to which the ligands are bound
cofactors : Iterable[SmallMoleculeComponent]
any cofactors alongisde the protein, can be empty list
protocol: Optional[Protocol]
fully set up Protocol to use

Returns
-------
Expand All @@ -53,6 +56,7 @@ def plan_rbfe_network_main(
mappers=mapper,
mapping_scorer=mapping_scorer,
ligand_network_planner=ligand_network_planner,
protocol=protocol,
)
alchemical_network = network_planner(
ligands=small_molecules, solvent=solvent, protein=protein,
Expand Down Expand Up @@ -145,6 +149,7 @@ def plan_rbfe_network(
mapping_scorer = yaml_options.scorer
ligand_network_planner = yaml_options.ligand_network_planner
solvent = yaml_options.solvent
protocol = yaml_options.protocol

write("\t\tSolvent: " + str(solvent))
write("")
Expand All @@ -169,6 +174,7 @@ def plan_rbfe_network(
solvent=solvent,
protein=protein,
cofactors=cofactors,
protocol=protocol,
)
write("\tDone")
write("")
Expand Down
5 changes: 4 additions & 1 deletion openfecli/commands/plan_rhfe_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def plan_rhfe_network_main(
mapper, mapping_scorer, ligand_network_planner, small_molecules,
solvent,
solvent, protocol=None
):
"""Utility method to plan a relative hydration free energy network.

Expand All @@ -31,6 +31,7 @@ def plan_rhfe_network_main(
molecules of the system
solvent : SolventComponent
Solvent component used for solvation
protocol : Optional[Protocol]

Returns
-------
Expand All @@ -46,6 +47,7 @@ def plan_rhfe_network_main(
mappers=mapper,
mapping_scorer=mapping_scorer,
ligand_network_planner=ligand_network_planner,
protocol=protocol,
)
alchemical_network = network_planner(
ligands=small_molecules, solvent=solvent
Expand Down Expand Up @@ -142,6 +144,7 @@ def plan_rhfe_network(molecules: List[str], yaml_settings: str, output_dir: str)
ligand_network_planner=ligand_network_planner,
small_molecules=small_molecules,
solvent=solvent,
protocol=yaml_options.protocol,
)
write("\tDone")
write("")
Expand Down
Loading
Loading