Skip to content

Commit

Permalink
cli: docs: move docs on customising protocols
Browse files Browse the repository at this point in the history
didn't render nicely via command line --help, so instead put the example code into the userguide docs
  • Loading branch information
richardjgowers committed Mar 11, 2024
1 parent 422970b commit 8df0b05
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 21 deletions.
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
51 changes: 31 additions & 20 deletions openfecli/parameters/plan_network_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,42 @@ def apply_onto(settings: SettingsBaseModel, options: dict) -> None:


def resolve_protocol_choices(options: Optional[ProtocolSelection]):
"""Turn Protocol section into a fully formed Protocol"""
from openfe.protocols import openmm_rfe
"""Turn Protocol section into a fully formed Protocol
allowed = {'openmm_rfe'}
Returns
-------
Optional[Protocol]
if options and options.method and options.method.lower() not in allowed:
Raises
------
ValueError
if an unsupported method name is input
"""
if not options:
return None

Check warning on line 151 in openfecli/parameters/plan_network_options.py

View check run for this annotation

Codecov / codecov/patch

openfecli/parameters/plan_network_options.py#L151

Added line #L151 was not covered by tests

# issue #644, make this selection not static
allowed = {'RelativeHybridTopologyProtocol',
# 'AbsoluteSolvationProtocol',
# 'PlainMDProtocol',
}
if options.method.lower() == 'relativehybridtopologyprotocol':
from openfe.protocols import openmm_rfe
protocol = openmm_rfe.RelativeHybridTopologyProtocol
# This wouldn't be reachable from any plan command, so leave out
#elif options.method.lower() == 'absolutesolvationprotocol':
# from openfe.protocols import openmm_afe
# protocol = openmm_afe.AbsoluteSolvationProtocol
#elif options.method.lower() == 'plainmdprotocol':
# from openfe.protocols import openmm_md
# protocol = openmm_md.PlainMDProtocol
else:
raise ValueError(f"Unsupported protocol method '{options.method}'. "
f"Supported methods are {','.join(allowed)}")
# todo: we only allow one option, so this is hardcoded for now
protocol = openmm_rfe.RelativeHybridTopologyProtocol

settings = protocol.default_settings()
# work through the fields in yaml input and apply these onto settings
if options and options.settings:
if options.settings:
apply_onto(settings, options.settings)

return protocol(settings)
Expand Down Expand Up @@ -289,19 +312,7 @@ def load_yaml_planner_options(path: Optional[str], context) -> PlanNetworkOption
The Settings of a Protocol can also be customised in this settings yaml file.
To do this, the nested variable names from the Python API are directly converted
to the nested yaml format. 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
to the nested yaml format.
"""


Expand Down

0 comments on commit 8df0b05

Please sign in to comment.