choderalab / yank

An open, extensible Python framework for GPU-accelerated alchemical free energy calculations.
http://getyank.org
MIT License
177 stars 70 forks source link

Can !Combinatorial be used in mcmc_moves and samplers sections? #1002

Open jchodera opened 6 years ago

jchodera commented 6 years ago

The documentation states that protocols and solvents cannot contain !Combinatorial, but it looks like neither mcmc_moves nor samplers can contain !Combinatorial options either.

In trying to combinatorially try multiple timesteps in mcmc_moves, I see

2018-05-27 10:39:16,940: ERROR - yank.experiment - MCMC moves validation failed with:
mcmc_moves:
- langevin: ['Validation of constructor failed with: The expression Combinatorial([''2.0*femtosecond'',
      ''2.5*femtosecond'', ''3.0*femtosecond'', ''3.5*femtosecond'', ''4.0*femtosecond'',
      ''4.5*femtosecond'', ''5.0*femtosecond'']) must be a string defining units,
      not a <class ''yank.utils.CombinatorialLeaf''> instance']

Traceback (most recent call last):
  File "/home/chodera/miniconda/bin/yank", line 11, in <module>
    load_entry_point('yank==0.22.1', 'console_scripts', 'yank')()
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/cli.py", line 73, in main
    dispatched = getattr(commands, command).dispatch(command_args)
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/commands/script.py", line 133, in dispatch
    yaml_builder = ExperimentBuilder(script=yaml_path, job_id=job_id, n_jobs=n_jobs)
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/experiment.py", line 636, in __init__
    self.parse(script)
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/experiment.py", line 752, in parse
    self._mcmc_moves = self._validate_mcmc_moves(yaml_content)
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/experiment.py", line 1927, in _validate_mcmc_moves
    raise YamlParseError(error.format(yaml.dump(mcmc_move_validator.errors)))
yank.experiment.YamlParseError: MCMC moves validation failed with:
mcmc_moves:
- langevin: ['Validation of constructor failed with: The expression Combinatorial([''2.0*femtosecond'',
      ''2.5*femtosecond'', ''3.0*femtosecond'', ''3.5*femtosecond'', ''4.0*femtosecond'',
      ''4.5*femtosecond'', ''5.0*femtosecond'']) must be a string defining units,
      not a <class ''yank.utils.CombinatorialLeaf''> instance']

If I explicitly create different mcmc_move types with different timesteps and use !Combinatorial in samplers, I see

2018-05-27 10:42:20,763: ERROR - yank.experiment - Samplers validation failed with:
samplers:
- sams:
  - mcmc_moves: [must be of string type]

Traceback (most recent call last):
  File "/home/chodera/miniconda/bin/yank", line 11, in <module>
    load_entry_point('yank==0.22.1', 'console_scripts', 'yank')()
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/cli.py", line 73, in main
    dispatched = getattr(commands, command).dispatch(command_args)
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/commands/script.py", line 133, in dispatch
    yaml_builder = ExperimentBuilder(script=yaml_path, job_id=job_id, n_jobs=n_jobs)
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/experiment.py", line 636, in __init__
    self.parse(script)
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/experiment.py", line 753, in parse
    self._samplers = self._validate_samplers(yaml_content)
  File "/home/chodera/miniconda/lib/python3.6/site-packages/yank/experiment.py", line 1966, in _validate_samplers
    raise YamlParseError(error.format(yaml.dump(sampler_validator.errors)))
yank.experiment.YamlParseError: Samplers validation failed with:
samplers:
- sams:
  - mcmc_moves: [must be of string type]

We should address this in the documentation if needed, or see if we could allow !Combinatorial to work in these sections if possible.

andrrizzi commented 6 years ago

Ah! Sorry, I forgot to add. It may be faster to implement this than add this to the docs actually. It should be a one-liner (plus tests) with the functions I have already implemented for this task.

jchodera commented 6 years ago

Awesome, thanks!