def analyze(self): """ Programmatic interface to retrieve the results of a YANK free energy calculation. Returns ------- results : dict results[phase][component] is the estimate of 'component' of thermodynamic leg 'phase' 'component' can be one of ['DeltaF', 'dDeltaF', 'DeltaH', 'dDeltaH'] DeltaF is the estimated free energy difference dDeltaF is the statistical uncertainty in DeltaF (one standard error) DeltaH is the estimated enthalpy difference dDeltaH is the statistical uncertainty in DeltaH (one standard error) all quantites are reported in units are kT If simulation has not been initialized by a call to resume() or create(), None is returned. """ if not self._initialized: return None # TODO: Can we simplify this code by pushing more into analyze.py or repex.py? import analyze from pymbar import MBAR, timeseries import netCDF4 as netcdf # Storage for results. results = dict() logger.debug("Analyzing simulation data...") # Process each netcdf file in output directory. for phase in self._phases: fullpath = self._store_filenames[phase] # Skip if the file doesn't exist. if (not os.path.exists(fullpath)): continue # Read this phase. simulation = ModifiedHamiltonianExchange(fullpath) simulation.resume() # Analyze this phase. analysis = simulation.analyze() # Retrieve standard state correction. analysis['standard_state_correction'] = simulation.metadata[ 'standard_state_correction'] # Store results. results[phase] = analysis # Clean up. del simulation # TODO: Analyze binding or hydration, depending on what phases are present. # TODO: Include effects of analytical contributions. phases_available = results.keys() if set(['solvent', 'vacuum']).issubset(phases_available): # SOLVATION FREE ENERGY results['solvation'] = dict() results['solvation']['Delta_f'] = results['solvent'][ 'Delta_f'] + results['vacuum']['Delta_f'] # TODO: Correct in different ways depending on what reference conditions are desired. results['solvation']['Delta_f'] += results['solvent'][ 'standard_state_correction'] + results['vacuum'][ 'standard_state_correction'] results['solvation']['dDelta_f'] = np.sqrt( results['solvent']['dDelta_f']**2 + results['vacuum']['Delta_f']**2) if set(['ligand', 'complex']).issubset(phases_available): # BINDING FREE ENERGY results['binding'] = dict() # Compute binding free energy. results['binding']['Delta_f'] = ( results['solvent']['Delta_f'] + results['solvent']['standard_state_correction']) - ( results['complex']['Delta_f'] + results['complex']['standard_state_correction']) results['binding']['dDelta_f'] = np.sqrt( results['solvent']['dDelta_f']**2 + results['complex']['dDelta_f']**2) return results
def analyze(self): """ Programmatic interface to retrieve the results of a YANK free energy calculation. Returns ------- results : dict results[phase][component] is the estimate of 'component' of thermodynamic leg 'phase' 'component' can be one of ['DeltaF', 'dDeltaF', 'DeltaH', 'dDeltaH'] DeltaF is the estimated free energy difference dDeltaF is the statistical uncertainty in DeltaF (one standard error) DeltaH is the estimated enthalpy difference dDeltaH is the statistical uncertainty in DeltaH (one standard error) all quantites are reported in units are kT If simulation has not been initialized by a call to resume() or create(), None is returned. """ if not self._initialized: return None # TODO: Can we simplify this code by pushing more into analyze.py or repex.py? import analyze from pymbar import MBAR, timeseries import netCDF4 as netcdf # Storage for results. results = dict() logger.debug("Analyzing simulation data...") # Process each netcdf file in output directory. for phase in self._phases: fullpath = self._store_filenames[phase] # Skip if the file doesn't exist. if (not os.path.exists(fullpath)): continue # Analyze this leg. simulation = ModifiedHamiltonianExchange(store_filename=store_filename, mpicomm=mpicomm, options=options) analysis = simulation.analyze() del simulation # Store results. results[phase] = analysis # TODO: Analyze binding or hydration, depending on what phases are present. # TODO: Include effects of analytical contributions. phases_available = results.keys() if set(['solvent', 'vacuum']).issubset(phases_available): # SOLVATION FREE ENERGY results['solvation'] = dict() results['solvation']['Delta_f'] = results['solvent']['Delta_f'] + results['vacuum']['Delta_f'] results['solvation']['dDelta_f'] = np.sqrt(results['solvent']['dDelta_f']**2 + results['vacuum']['Delta_f']**2) if set(['ligand', 'complex']).issubset(phases_available): # BINDING FREE ENERGY results['binding'] = dict() # Read standard state correction free energy. Delta_f_restraints = 0.0 phase = 'complex' fullpath = os.path.join(source_directory, phase + '.nc') ncfile = netcdf.Dataset(fullpath, 'r') Delta_f_restraints = ncfile.groups['metadata'].variables['standard_state_correction'][0] ncfile.close() results['binding']['standard_state_correction'] = Delta_f_restraints # Compute binding free energy. results['binding']['Delta_f'] = results['solvent']['Delta_f'] - Delta_f_restraints - results['complex']['Delta_f'] results['binding']['dDelta_f'] = np.sqrt(results['solvent']['dDelta_f']**2 + results['complex']['dDelta_f']**2) return results
def analyze(self): """ Programmatic interface to retrieve the results of a YANK free energy calculation. Returns ------- results : dict results[phase][component] is the estimate of 'component' of thermodynamic leg 'phase' 'component' can be one of ['DeltaF', 'dDeltaF', 'DeltaH', 'dDeltaH'] DeltaF is the estimated free energy difference dDeltaF is the statistical uncertainty in DeltaF (one standard error) DeltaH is the estimated enthalpy difference dDeltaH is the statistical uncertainty in DeltaH (one standard error) all quantites are reported in units are kT If simulation has not been initialized by a call to resume() or create(), None is returned. """ if not self._initialized: return None # TODO: Can we simplify this code by pushing more into analyze.py or repex.py? import analyze from pymbar import MBAR, timeseries import netCDF4 as netcdf # Storage for results. results = dict() if self.verbose: print "Analyzing simulation data..." # Process each netcdf file in output directory. for phase in self._phases: fullpath = self._store_filenames[phase] # Skip if the file doesn't exist. if (not os.path.exists(fullpath)): continue # Analyze this leg. simulation = ModifiedHamiltonianExchange( store_filename=store_filename, mpicomm=mpicomm, options=options) analysis = simulation.analyze() del simulation # Store results. results[phase] = analysis # TODO: Analyze binding or hydration, depending on what phases are present. # TODO: Include effects of analytical contributions. phases_available = results.keys() if set(['solvent', 'vacuum']).issubset(phases_available): # SOLVATION FREE ENERGY results['solvation'] = dict() results['solvation']['Delta_f'] = results['solvent'][ 'Delta_f'] + results['vacuum']['Delta_f'] results['solvation']['dDelta_f'] = np.sqrt( results['solvent']['dDelta_f']**2 + results['vacuum']['Delta_f']**2) if set(['ligand', 'complex']).issubset(phases_available): # BINDING FREE ENERGY results['binding'] = dict() # Read standard state correction free energy. Delta_f_restraints = 0.0 phase = 'complex' fullpath = os.path.join(source_directory, phase + '.nc') ncfile = netcdf.Dataset(fullpath, 'r') Delta_f_restraints = ncfile.groups['metadata'].variables[ 'standard_state_correction'][0] ncfile.close() results['binding'][ 'standard_state_correction'] = Delta_f_restraints # Compute binding free energy. results['binding']['Delta_f'] = results['solvent'][ 'Delta_f'] - Delta_f_restraints - results['complex']['Delta_f'] results['binding']['dDelta_f'] = np.sqrt( results['solvent']['dDelta_f']**2 + results['complex']['dDelta_f']**2) return results