def run_selectivity(): storage_filename = 'output-src-abl.nc' system = Selectivity(storage_filename=storage_filename) system.designer.run(niterations=10) from perses.analysis import Analysis analysis = Analysis(storage_filename=storage_filename) analysis.plot_ncmc_work('ncmc-work.pdf')
def test_analysis(): """Test analysis tools. """ testsystem_names = ['AlanineDipeptideTestSystem'] for testsystem_name in testsystem_names: # Create storage. tmpfile = tempfile.NamedTemporaryFile() storage_filename = tmpfile.name import perses.tests.testsystems testsystem_class = getattr(perses.tests.testsystems, testsystem_name) # Instantiate test system. testsystem = testsystem_class(storage_filename=storage_filename) # Alter settings for environment in testsystem.environments: testsystem.mcmc_samplers[environment].verbose = False testsystem.mcmc_samplers[ environment].nsteps = 5 # use fewer MD steps to speed things up testsystem.exen_samplers[environment].verbose = False testsystem.exen_samplers[ environment].ncmc_engine.nsteps = 5 # NCMC switching testsystem.sams_samplers[environment].verbose = False # Run test simulations. niterations = 5 # just a few iterations if testsystem.designer is not None: # Run the designer testsystem.designer.verbose = False testsystem.designer.run(niterations=niterations) else: # Run the SAMS samplers. for environment in testsystem.environments: testsystem.sams_samplers[environment].run( niterations=niterations) # Analyze file. # TODO: Use temporary filenames analysis = Analysis(storage_filename) analysis.plot_ncmc_work('ncmc.pdf')
def test_analysis(): """Test analysis tools. """ testsystem_names = ['AlanineDipeptideTestSystem'] for testsystem_name in testsystem_names: # Create storage. tmpfile = tempfile.NamedTemporaryFile() storage_filename = tmpfile.name import perses.tests.testsystems testsystem_class = getattr(perses.tests.testsystems, testsystem_name) # Instantiate test system. testsystem = testsystem_class(storage_filename=storage_filename) # Alter settings for environment in testsystem.environments: testsystem.mcmc_samplers[environment].verbose = False testsystem.mcmc_samplers[environment].nsteps = 5 # use fewer MD steps to speed things up testsystem.exen_samplers[environment].verbose = False testsystem.exen_samplers[environment].ncmc_engine.nsteps = 5 # NCMC switching testsystem.sams_samplers[environment].verbose = False # Run test simulations. niterations = 5 # just a few iterations if testsystem.designer is not None: # Run the designer testsystem.designer.verbose = False testsystem.designer.run(niterations=niterations) else: # Run the SAMS samplers. for environment in testsystem.environments: testsystem.sams_samplers[environment].run(niterations=niterations) # Analyze file. # TODO: Use temporary filenames analysis = Analysis(storage_filename) analysis.plot_ncmc_work('ncmc.pdf')
def benchmark_ncmc_work_during_protocol(): """ Run 50 iterations of ExpandedEnsembleSampler for NullTestSystems over a range of total NCMC steps [0, 1, 10, 100, 1000, 10000]. Benchmark is repeated for Naphthalene, Butane, and Propane test systems, using two-stage and hybrid NCMC. For each combination of system and scheme, results are analyzed for the following: * For a given total number of steps: * For NCMC steps 100 and above, plot work done by ncmc integrator over the course of the protocol * Plot histograms of the contributions of each component to the overall log acceptance probability * Over the whole range of total steps: * Plot mean and standard deviation of NCMC logP as a function of total steps * Plot mean and standard deviation of EXEN logP as a function of total steps """ from perses.tests.testsystems import NaphthaleneTestSystem, ButaneTestSystem, PropaneTestSystem from perses.analysis import Analysis import netCDF4 as netcdf import pickle import codecs molecule_names = { #'propane' : PropaneTestSystem, 'butane': ButaneTestSystem, #'naphthalene' : NaphthaleneTestSystem, } methods = { 'hybrid': ['geometry-ncmc-geometry', functions_hybrid], 'two-stage': ['ncmc-geometry-ncmc', functions_twostage], } for molecule_name, NullProposal in molecule_names.items(): print('\nNow testing {0} null transformations'.format(molecule_name)) for name, [scheme, functions] in methods.items(): analyses = dict() #for ncmc_nsteps in [0, 1, 10, 100, 1000, 10000]: for ncmc_nsteps in [0, 1, 10, 100, 1000]: print( 'Running {0} {2} ExpandedEnsemble steps for {1} iterations' .format(ncmc_nsteps, niterations, name)) testsystem = NullProposal( storage_filename='{0}_{1}-{2}steps.nc'.format( molecule_name, name, ncmc_nsteps), scheme=scheme, options={ 'functions': functions, 'nsteps': ncmc_nsteps }) testsystem.exen_samplers[ ENV].geometry_engine.use_sterics = use_sterics testsystem.mcmc_samplers[ENV].verbose = True testsystem.exen_samplers[ENV].verbose = True testsystem.mcmc_samplers[ ENV].timestep = 1.0 * unit.femtoseconds # DEBUG #testsystem.exen_samplers[ENV].geometry_engine.write_proposal_pdb = True #testsystem.exen_samplers[ENV].geometry_engine.pdb_filename_prefix = '{0}_{1}-{2}steps'.format(molecule_name, name, ncmc_nsteps) # Equilibrate # WARNING: We can't equilibrate because it messes up the iteration counters and storage iterations for exen samplers #print('Equilibration...') #testsystem.mcmc_samplers[ENV].run(niterations=nequil) # Collect data on switching print('Production...') testsystem.exen_samplers[ENV].run(niterations=niterations) analysis = Analysis(testsystem.storage_filename) print(analysis.get_environments()) if ncmc_nsteps > 9: analysis.plot_ncmc_work( '{0}_{1}-ncmc_work_over_{2}_steps.pdf'.format( molecule_name, name, ncmc_nsteps)) analysis.plot_exen_logp_components() analyses[ncmc_nsteps] = analysis benchmark_exen_ncmc_protocol(analyses, molecule_name, name)
def benchmark_ncmc_work_during_protocol(): """ Run 50 iterations of ExpandedEnsembleSampler for NullTestSystems over a range of total NCMC steps [0, 1, 10, 100, 1000, 10000]. Benchmark is repeated for Naphthalene, Butane, and Propane test systems, using two-stage and hybrid NCMC. For each combination of system and scheme, results are analyzed for the following: * For a given total number of steps: * For NCMC steps 100 and above, plot work done by ncmc integrator over the course of the protocol * Plot histograms of the contributions of each component to the overall log acceptance probability * Over the whole range of total steps: * Plot mean and standard deviation of NCMC logP as a function of total steps * Plot mean and standard deviation of EXEN logP as a function of total steps """ from perses.tests.testsystems import NaphthaleneTestSystem, ButaneTestSystem, PropaneTestSystem from perses.analysis import Analysis import netCDF4 as netcdf import pickle import codecs molecule_names = { #'propane' : PropaneTestSystem, 'butane' : ButaneTestSystem, #'naphthalene' : NaphthaleneTestSystem, } methods = { 'hybrid' : ['geometry-ncmc-geometry', functions_hybrid], 'two-stage' : ['ncmc-geometry-ncmc', functions_twostage], } for molecule_name, NullProposal in molecule_names.items(): print('\nNow testing {0} null transformations'.format(molecule_name)) for name, [scheme, functions] in methods.items(): analyses = dict() #for ncmc_nsteps in [0, 1, 10, 100, 1000, 10000]: for ncmc_nsteps in [0, 1, 10, 100, 1000]: print('Running {0} {2} ExpandedEnsemble steps for {1} iterations'.format(ncmc_nsteps, niterations, name)) testsystem = NullProposal(storage_filename='{0}_{1}-{2}steps.nc'.format(molecule_name, name, ncmc_nsteps), scheme=scheme, options={'functions' : functions, 'nsteps' : ncmc_nsteps}) testsystem.exen_samplers[ENV].geometry_engine.use_sterics = use_sterics testsystem.mcmc_samplers[ENV].verbose = True testsystem.exen_samplers[ENV].verbose = True testsystem.mcmc_samplers[ENV].timestep = 1.0 * unit.femtoseconds # DEBUG #testsystem.exen_samplers[ENV].geometry_engine.write_proposal_pdb = True #testsystem.exen_samplers[ENV].geometry_engine.pdb_filename_prefix = '{0}_{1}-{2}steps'.format(molecule_name, name, ncmc_nsteps) # Equilibrate # WARNING: We can't equilibrate because it messes up the iteration counters and storage iterations for exen samplers #print('Equilibration...') #testsystem.mcmc_samplers[ENV].run(niterations=nequil) # Collect data on switching print('Production...') testsystem.exen_samplers[ENV].run(niterations=niterations) analysis = Analysis(testsystem.storage_filename) print(analysis.get_environments()) if ncmc_nsteps > 9: analysis.plot_ncmc_work('{0}_{1}-ncmc_work_over_{2}_steps.pdf'.format(molecule_name, name, ncmc_nsteps)) analysis.plot_exen_logp_components() analyses[ncmc_nsteps] = analysis benchmark_exen_ncmc_protocol(analyses, molecule_name, name)