original_docstring: Constructs a set of protocols which, when combined in a workflow schema,
      may be executed to reweight a set of existing data to estimate a particular
      property. The reweighted observable of interest will be calculated by
      following the passed in `analysis_protocol`.
  
      Parameters
      ----------
      analysis_protocol: AveragePropertyProtocol
          The protocol which will take input from the stored data,
          and generate a set of observables to reweight.
      mbar_protocol: BaseReweightingProtocol
          A template mbar reweighting protocol, which has it's reference
          observables already set. This method will automatically set the
          reduced potentials on this object.
      workflow_options: WorkflowOptions
          The options being used to generate a workflow.
      replicator_id: str
          The id to use for the data replicator.
      id_suffix: str
          A string suffix to append to each of the protocol ids.
  
      Returns
      -------
      BaseReweightingProtocols:
          A named tuple of the protocol which should form the bulk of
          a property estimation workflow.
      ProtocolReplicator:
          A replicator which will clone the workflow for each piece of
          stored data.
      
docstring: Constructs a set of protocols which, when combined in a workflow schema,
  may be executed to reweight a set of existing data to estimate a particular
  property. The reweighted observable of interest will be calculated by
  following the passed in `analysis_protocol`.
  
  Parameters
  
  AveragePropertyProtocol
  The protocol which will take input from the stored data,
  and generate a set of observables to reweight.
  mbar_protocol: BaseReweightingProtocol
  A template mbar reweighting protocol, which has it's reference
  observables already set. This method will automatically set the
  reduced potentials on this object.
  workflow_options: WorkflowOptions
  The options being used to generate a workflow.
  replicator_id: str
  The id to use for the data replicator.
  id_suffix: str
  A string suffix to append to each of the protocol ids.
  
  Returns
  
  A named tuple of the protocol which should form the bulk of
  a property estimation workflow.
  ProtocolReplicator:
  A replicator which will clone the workflow for each piece of
  stored data.
docstring_tokens: Constructs a set of protocols which when combined in a workflow schema may be executed to reweight a set of existing data to estimate a particular property . The reweighted observable of interest will be calculated by following the passed in ` analysis_protocol ` . Parameters AveragePropertyProtocol The protocol which will take input from the stored data and generate a set of observables to reweight . mbar_protocol : BaseReweightingProtocol A template mbar reweighting protocol which has it ' s reference observables already set . This method will automatically set the reduced potentials on this object . workflow_options : WorkflowOptions The options being used to generate a workflow . replicator_id : str The id to use for the data replicator . id_suffix : str A string suffix to append to each of the protocol ids . Returns A named tuple of the protocol which should form the bulk of a property estimation workflow . ProtocolReplicator : A replicator which will clone the workflow for each piece of stored data .
code: def generate_base_reweighting_protocols(analysis_protocol, mbar_protocol, workflow_options,
                                          replicator_id='data_repl', id_suffix=''):
      """Constructs a set of protocols which, when combined in a workflow schema,
      may be executed to reweight a set of existing data to estimate a particular
      property. The reweighted observable of interest will be calculated by
      following the passed in `analysis_protocol`.
  
      Parameters
      ----------
      analysis_protocol: AveragePropertyProtocol
          The protocol which will take input from the stored data,
          and generate a set of observables to reweight.
      mbar_protocol: BaseReweightingProtocol
          A template mbar reweighting protocol, which has it's reference
          observables already set. This method will automatically set the
          reduced potentials on this object.
      workflow_options: WorkflowOptions
          The options being used to generate a workflow.
      replicator_id: str
          The id to use for the data replicator.
      id_suffix: str
          A string suffix to append to each of the protocol ids.
  
      Returns
      -------
      BaseReweightingProtocols:
          A named tuple of the protocol which should form the bulk of
          a property estimation workflow.
      ProtocolReplicator:
          A replicator which will clone the workflow for each piece of
          stored data.
      """
  
      assert isinstance(analysis_protocol, analysis.AveragePropertyProtocol)
  
      assert f'$({replicator_id})' in analysis_protocol.id
      assert f'$({replicator_id})' not in mbar_protocol.id
  
      replicator_suffix = '_$({}){}'.format(replicator_id, id_suffix)
  
      # Unpack all the of the stored data.
      unpack_stored_data = storage.UnpackStoredSimulationData('unpack_data{}'.format(replicator_suffix))
      unpack_stored_data.simulation_data_path = ReplicatorValue(replicator_id)
  
      # The autocorrelation time of each of the stored files will be calculated for this property
      # using the passed in analysis protocol.
      if isinstance(analysis_protocol, analysis.ExtractAverageStatistic):
  
          analysis_protocol.statistics_path = ProtocolPath('statistics_file_path', unpack_stored_data.id)
  
      elif isinstance(analysis_protocol, analysis.AverageTrajectoryProperty):
  
          analysis_protocol.input_coordinate_file = ProtocolPath('coordinate_file_path', unpack_stored_data.id)
          analysis_protocol.trajectory_path = ProtocolPath('trajectory_file_path', unpack_stored_data.id)
  
      # Decorrelate the frames of the stored trajectory and statistics arrays.
      decorrelate_statistics = analysis.ExtractUncorrelatedStatisticsData('decorrelate_stats{}'.format(replicator_suffix))
      decorrelate_statistics.statistical_inefficiency = ProtocolPath('statistical_inefficiency', analysis_protocol.id)
      decorrelate_statistics.equilibration_index = ProtocolPath('equilibration_index', analysis_protocol.id)
      decorrelate_statistics.input_statistics_path = ProtocolPath('statistics_file_path', unpack_stored_data.id)
  
      decorrelate_trajectory = analysis.ExtractUncorrelatedTrajectoryData('decorrelate_traj{}'.format(replicator_suffix))
      decorrelate_trajectory.statistical_inefficiency = ProtocolPath('statistical_inefficiency', analysis_protocol.id)
      decorrelate_trajectory.equilibration_index = ProtocolPath('equilibration_index', analysis_protocol.id)
      decorrelate_trajectory.input_coordinate_file = ProtocolPath('coordinate_file_path', unpack_stored_data.id)
      decorrelate_trajectory.input_trajectory_path = ProtocolPath('trajectory_file_path', unpack_stored_data.id)
  
      # Stitch together all of the trajectories
      join_trajectories = reweighting.ConcatenateTrajectories('concat_traj' + id_suffix)
      join_trajectories.input_coordinate_paths = ProtocolPath('coordinate_file_path', unpack_stored_data.id)
      join_trajectories.input_trajectory_paths = ProtocolPath('output_trajectory_path', decorrelate_trajectory.id)
  
      join_statistics = reweighting.ConcatenateStatistics('concat_stats' + id_suffix)
      join_statistics.input_statistics_paths = ProtocolPath('output_statistics_path', decorrelate_statistics.id)
  
      # Calculate the reduced potentials for each of the reference states.
      build_reference_system = forcefield.BuildSmirnoffSystem('build_system{}'.format(replicator_suffix))
      build_reference_system.force_field_path = ProtocolPath('force_field_path', unpack_stored_data.id)
      build_reference_system.substance = ProtocolPath('substance', unpack_stored_data.id)
      build_reference_system.coordinate_file_path = ProtocolPath('coordinate_file_path', unpack_stored_data.id)
  
      reduced_reference_potential = reweighting.CalculateReducedPotentialOpenMM('reduced_potential{}'.format(
                                                                                replicator_suffix))
      reduced_reference_potential.system_path = ProtocolPath('system_path', build_reference_system.id)
      reduced_reference_potential.thermodynamic_state = ProtocolPath('thermodynamic_state', unpack_stored_data.id)
      reduced_reference_potential.coordinate_file_path = ProtocolPath('coordinate_file_path', unpack_stored_data.id)
      reduced_reference_potential.trajectory_file_path = ProtocolPath('output_trajectory_path', join_trajectories.id)
      reduced_reference_potential.kinetic_energies_path = ProtocolPath('output_statistics_path', join_statistics.id)
  
      # Calculate the reduced potential of the target state.
      build_target_system = forcefield.BuildSmirnoffSystem('build_system_target' + id_suffix)
      build_target_system.force_field_path = ProtocolPath('force_field_path', 'global')
      build_target_system.substance = ProtocolPath('substance', 'global')
      build_target_system.coordinate_file_path = ProtocolPath('output_coordinate_path', join_trajectories.id)
  
      reduced_target_potential = reweighting.CalculateReducedPotentialOpenMM('reduced_potential_target' + id_suffix)
      reduced_target_potential.thermodynamic_state = ProtocolPath('thermodynamic_state', 'global')
      reduced_target_potential.system_path = ProtocolPath('system_path', build_target_system.id)
      reduced_target_potential.coordinate_file_path = ProtocolPath('output_coordinate_path', join_trajectories.id)
      reduced_target_potential.trajectory_file_path = ProtocolPath('output_trajectory_path', join_trajectories.id)
      reduced_target_potential.kinetic_energies_path = ProtocolPath('output_statistics_path', join_statistics.id)
  
      # Finally, apply MBAR to get the reweighted value.
      mbar_protocol.reference_reduced_potentials = ProtocolPath('statistics_file_path', reduced_reference_potential.id)
      mbar_protocol.target_reduced_potentials = [ProtocolPath('statistics_file_path', reduced_target_potential.id)]
  
      if (isinstance(mbar_protocol, reweighting.ReweightStatistics) and
          mbar_protocol.statistics_type != ObservableType.PotentialEnergy and
          mbar_protocol.statistics_type != ObservableType.TotalEnergy and
          mbar_protocol.statistics_type != ObservableType.Enthalpy and
          mbar_protocol.statistics_type != ObservableType.ReducedPotential):
  
          mbar_protocol.statistics_paths = ProtocolPath('output_statistics_path', decorrelate_statistics.id)
  
      elif isinstance(mbar_protocol, reweighting.ReweightStatistics):
  
          mbar_protocol.statistics_paths = [ProtocolPath('statistics_file_path', reduced_target_potential.id)]
          mbar_protocol.frame_counts = ProtocolPath('number_of_uncorrelated_samples', decorrelate_statistics.id)
  
      # TODO: Implement a cleaner way to handle this.
      if workflow_options.convergence_mode == WorkflowOptions.ConvergenceMode.NoChecks:
          mbar_protocol.required_effective_samples = -1
  
      base_protocols = BaseReweightingProtocols(unpack_stored_data,
                                                analysis_protocol,
                                                decorrelate_statistics,
                                                decorrelate_trajectory,
                                                join_trajectories,
                                                join_statistics,
                                                build_reference_system,
                                                reduced_reference_potential,
                                                build_target_system,
                                                reduced_target_potential,
                                                mbar_protocol)
  
      # Create the replicator object.
      component_replicator = ProtocolReplicator(replicator_id=replicator_id)
      component_replicator.template_values = ProtocolPath('full_system_data', 'global')
  
      return base_protocols, component_replicator
code_tokens: def generate_base_reweighting_protocols ( analysis_protocol , mbar_protocol , workflow_options , replicator_id = 'data_repl' , id_suffix = '' ) : assert isinstance ( analysis_protocol , analysis . AveragePropertyProtocol ) assert f'$({replicator_id})' in analysis_protocol . id assert f'$({replicator_id})' not in mbar_protocol . id replicator_suffix = '_$({}){}' . format ( replicator_id , id_suffix ) unpack_stored_data = storage . UnpackStoredSimulationData ( 'unpack_data{}' . format ( replicator_suffix ) ) unpack_stored_data . simulation_data_path = ReplicatorValue ( replicator_id ) if isinstance ( analysis_protocol , analysis . ExtractAverageStatistic ) : analysis_protocol . statistics_path = ProtocolPath ( 'statistics_file_path' , unpack_stored_data . id ) elif isinstance ( analysis_protocol , analysis . AverageTrajectoryProperty ) : analysis_protocol . input_coordinate_file = ProtocolPath ( 'coordinate_file_path' , unpack_stored_data . id ) analysis_protocol . trajectory_path = ProtocolPath ( 'trajectory_file_path' , unpack_stored_data . id ) decorrelate_statistics = analysis . ExtractUncorrelatedStatisticsData ( 'decorrelate_stats{}' . format ( replicator_suffix ) ) decorrelate_statistics . statistical_inefficiency = ProtocolPath ( 'statistical_inefficiency' , analysis_protocol . id ) decorrelate_statistics . equilibration_index = ProtocolPath ( 'equilibration_index' , analysis_protocol . id ) decorrelate_statistics . input_statistics_path = ProtocolPath ( 'statistics_file_path' , unpack_stored_data . id ) decorrelate_trajectory = analysis . ExtractUncorrelatedTrajectoryData ( 'decorrelate_traj{}' . format ( replicator_suffix ) ) decorrelate_trajectory . statistical_inefficiency = ProtocolPath ( 'statistical_inefficiency' , analysis_protocol . id ) decorrelate_trajectory . equilibration_index = ProtocolPath ( 'equilibration_index' , analysis_protocol . id ) decorrelate_trajectory . input_coordinate_file = ProtocolPath ( 'coordinate_file_path' , unpack_stored_data . id ) decorrelate_trajectory . input_trajectory_path = ProtocolPath ( 'trajectory_file_path' , unpack_stored_data . id ) join_trajectories = reweighting . ConcatenateTrajectories ( 'concat_traj' + id_suffix ) join_trajectories . input_coordinate_paths = ProtocolPath ( 'coordinate_file_path' , unpack_stored_data . id ) join_trajectories . input_trajectory_paths = ProtocolPath ( 'output_trajectory_path' , decorrelate_trajectory . id ) join_statistics = reweighting . ConcatenateStatistics ( 'concat_stats' + id_suffix ) join_statistics . input_statistics_paths = ProtocolPath ( 'output_statistics_path' , decorrelate_statistics . id ) build_reference_system = forcefield . BuildSmirnoffSystem ( 'build_system{}' . format ( replicator_suffix ) ) build_reference_system . force_field_path = ProtocolPath ( 'force_field_path' , unpack_stored_data . id ) build_reference_system . substance = ProtocolPath ( 'substance' , unpack_stored_data . id ) build_reference_system . coordinate_file_path = ProtocolPath ( 'coordinate_file_path' , unpack_stored_data . id ) reduced_reference_potential = reweighting . CalculateReducedPotentialOpenMM ( 'reduced_potential{}' . format ( replicator_suffix ) ) reduced_reference_potential . system_path = ProtocolPath ( 'system_path' , build_reference_system . id ) reduced_reference_potential . thermodynamic_state = ProtocolPath ( 'thermodynamic_state' , unpack_stored_data . id ) reduced_reference_potential . coordinate_file_path = ProtocolPath ( 'coordinate_file_path' , unpack_stored_data . id ) reduced_reference_potential . trajectory_file_path = ProtocolPath ( 'output_trajectory_path' , join_trajectories . id ) reduced_reference_potential . kinetic_energies_path = ProtocolPath ( 'output_statistics_path' , join_statistics . id ) build_target_system = forcefield . BuildSmirnoffSystem ( 'build_system_target' + id_suffix ) build_target_system . force_field_path = ProtocolPath ( 'force_field_path' , 'global' ) build_target_system . substance = ProtocolPath ( 'substance' , 'global' ) build_target_system . coordinate_file_path = ProtocolPath ( 'output_coordinate_path' , join_trajectories . id ) reduced_target_potential = reweighting . CalculateReducedPotentialOpenMM ( 'reduced_potential_target' + id_suffix ) reduced_target_potential . thermodynamic_state = ProtocolPath ( 'thermodynamic_state' , 'global' ) reduced_target_potential . system_path = ProtocolPath ( 'system_path' , build_target_system . id ) reduced_target_potential . coordinate_file_path = ProtocolPath ( 'output_coordinate_path' , join_trajectories . id ) reduced_target_potential . trajectory_file_path = ProtocolPath ( 'output_trajectory_path' , join_trajectories . id ) reduced_target_potential . kinetic_energies_path = ProtocolPath ( 'output_statistics_path' , join_statistics . id ) mbar_protocol . reference_reduced_potentials = ProtocolPath ( 'statistics_file_path' , reduced_reference_potential . id ) mbar_protocol . target_reduced_potentials = [ ProtocolPath ( 'statistics_file_path' , reduced_target_potential . id ) ] if ( isinstance ( mbar_protocol , reweighting . ReweightStatistics ) and mbar_protocol . statistics_type != ObservableType . PotentialEnergy and mbar_protocol . statistics_type != ObservableType . TotalEnergy and mbar_protocol . statistics_type != ObservableType . Enthalpy and mbar_protocol . statistics_type != ObservableType . ReducedPotential ) : mbar_protocol . statistics_paths = ProtocolPath ( 'output_statistics_path' , decorrelate_statistics . id ) elif isinstance ( mbar_protocol , reweighting . ReweightStatistics ) : mbar_protocol . statistics_paths = [ ProtocolPath ( 'statistics_file_path' , reduced_target_potential . id ) ] mbar_protocol . frame_counts = ProtocolPath ( 'number_of_uncorrelated_samples' , decorrelate_statistics . id ) if workflow_options . convergence_mode == WorkflowOptions . ConvergenceMode . NoChecks : mbar_protocol . required_effective_samples = - 1 base_protocols = BaseReweightingProtocols ( unpack_stored_data , analysis_protocol , decorrelate_statistics , decorrelate_trajectory , join_trajectories , join_statistics , build_reference_system , reduced_reference_potential , build_target_system , reduced_target_potential , mbar_protocol ) component_replicator = ProtocolReplicator ( replicator_id = replicator_id ) component_replicator . template_values = ProtocolPath ( 'full_system_data' , 'global' ) return base_protocols , component_replicator
short_docstring: Constructs a set of protocols which, when combined in a workflow schema,
  may be executed to reweight a set of existing data to estimate a particular
  property.
short_docstring_tokens: Constructs a set of protocols which when combined in a workflow schema may be executed to reweight a set of existing data to estimate a particular property .
comment: """Constructs a set of protocols which, when combined in a workflow schema,
      may be executed to reweight a set of existing data to estimate a particular
      property. The reweighted observable of interest will be calculated by
      following the passed in `analysis_protocol`.
  
      Parameters
      ----------
      analysis_protocol: AveragePropertyProtocol
          The protocol which will take input from the stored data,
          and generate a set of observables to reweight.
      mbar_protocol: BaseReweightingProtocol
          A template mbar reweighting protocol, which has it's reference
          observables already set. This method will automatically set the
          reduced potentials on this object.
      workflow_options: WorkflowOptions
          The options being used to generate a workflow.
      replicator_id: str
          The id to use for the data replicator.
      id_suffix: str
          A string suffix to append to each of the protocol ids.
  
      Returns
      -------
      BaseReweightingProtocols:
          A named tuple of the protocol which should form the bulk of
          a property estimation workflow.
      ProtocolReplicator:
          A replicator which will clone the workflow for each piece of
          stored data.
      """$SEP$# Unpack all the of the stored data.$SEP$# The autocorrelation time of each of the stored files will be calculated for this property$SEP$# using the passed in analysis protocol.$SEP$# Decorrelate the frames of the stored trajectory and statistics arrays.$SEP$# Stitch together all of the trajectories$SEP$# Calculate the reduced potentials for each of the reference states.$SEP$# Calculate the reduced potential of the target state.$SEP$# Finally, apply MBAR to get the reweighted value.$SEP$# TODO: Implement a cleaner way to handle this.$SEP$# Create the replicator object.