def test_script_yaml(): """Check that yank script --yamlscript command works.""" setup_dir = utils.get_data_filename(os.path.join("..", "examples", "p-xylene-implicit", "setup")) pxylene_path = os.path.join(setup_dir, "ligand.tripos.mol2") lysozyme_path = os.path.join(setup_dir, "receptor.pdbfixer.pdb") with utils.temporary_directory() as tmp_dir: yaml_content = """ --- options: number_of_iterations: 1 output_dir: '.' molecules: T4lysozyme: filepath: {} parameters: oldff/leaprc.ff99SBildn p-xylene: filepath: {} parameters: antechamber solvents: vacuum: nonbonded_method: NoCutoff experiments: components: receptor: T4lysozyme ligand: p-xylene solvent: vacuum """.format( lysozyme_path, pxylene_path ) yaml_file_path = os.path.join(tmp_dir, "yank.yaml") with open(yaml_file_path, "w") as f: f.write(textwrap.dedent(yaml_content)) run_cli("script --yaml={}".format(yaml_file_path))
def notest_prepare_binding(): dirname = utils.get_data_filename( "../examples/benzene-toluene-implicit/setup/" ) # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ with omt.utils.temporary_directory() as store_dir: run_cli( 'prepare binding amber --setupdir=%(dirname)s --ligand="resname TOL" --store %(store_dir)s --gbsa OBC1' % vars())
def test_prepare_amber_explicit(verbose=False): store_directory = tempfile.mkdtemp() examples_path = utils.get_data_filename("../examples/benzene-toluene-explicit/setup/") # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ command = 'yank prepare binding amber --setupdir=%(examples_path)s --ligname=BEN --store=%(store_directory)s --iterations=1 --nbmethod=CutoffPeriodic --temperature=300*kelvin --pressure=1*atmospheres' % vars() if verbose: command += ' --verbose' argv = command.split() args = docopt(usage, version=version.version, argv=argv[1:]) from yank.commands import prepare prepare.dispatch(args)
def test_script_yaml(): """Check that yank script --yaml command works.""" setup_dir = utils.get_data_filename( os.path.join('tests', 'data', 'p-xylene-implicit')) pxylene_path = os.path.join(setup_dir, 'p-xylene.mol2') lysozyme_path = os.path.join(setup_dir, '181L-pdbfixer.pdb') yaml_content = """ --- options: number_of_iterations: 0 output_dir: '.' resume_setup: yes resume_simulation: no minimize: no molecules: T4lysozyme: filepath: {} p-xylene: filepath: {} antechamber: charge_method: bcc solvents: vacuum: nonbonded_method: NoCutoff protocols: absolute-binding: complex: alchemical_path: lambda_electrostatics: [1.0, 0.5, 0.0] lambda_sterics: [1.0, 0.5, 0.0] solvent: alchemical_path: lambda_electrostatics: [1.0, 0.5, 0.0] lambda_sterics: [1.0, 0.5, 0.0] systems: system: receptor: T4lysozyme ligand: p-xylene solvent: vacuum leap: parameters: [leaprc.gaff, oldff/leaprc.ff14SB] experiments: system: system protocol: absolute-binding restraint: type: FlatBottom """.format(lysozyme_path, pxylene_path) with omt.utils.temporary_directory() as tmp_dir: yaml_file_path = os.path.join(tmp_dir, 'yank.yaml') with open(yaml_file_path, 'w') as f: f.write(textwrap.dedent(yaml_content)) run_cli('script --yaml={}'.format(yaml_file_path)) # Test option overriding. run_cli('script --yaml={} -o options:resume_simulation:yes'.format( yaml_file_path))
def test_prepare_binding(): # NOTE: switched to yank p-xylene from openmmtools T4-lysozyme because of yank bugs. dirname = utils.get_data_filename( "../examples/p-xylene-implicit/setup/" ) # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ with utils.temporary_directory() as store_dir: run_cli( 'prepare binding amber --setupdir=%(dirname)s --ligand="resname MOL" --store %(store_dir)s --gbsa OBC1' % vars())
def test_prepare_binding(): dirname = utils.get_data_filename( "../examples/benzene-toluene-implicit/setup/" ) # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ with omt.utils.temporary_directory() as store_dir: run_cli( 'prepare binding amber --setupdir=%(dirname)s --ligand="resname TOL" --store %(store_dir)s --gbsa OBC1' % vars() )
def test_prepare_amber_implicit(verbose=False): store_directory = tempfile.mkdtemp() examples_path = utils.get_data_filename("../examples/benzene-toluene-implicit/setup/") # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ command = 'yank prepare binding amber --setupdir=%(examples_path)s --store=%(store_directory)s --iterations=1 --restraints=harmonic --gbsa=OBC2 --temperature=300*kelvin' % vars() if verbose: command += ' --verbose' argv = command.split() argv.append('--ligand=resname BEN') # if included in the command string it is split in two args = docopt(usage, version=version.version, argv=argv[1:]) from yank.commands import prepare prepare.dispatch(args)
def test_prepare_binding(): # NOTE: switched to yank p-xylene from openmmtools T4-lysozyme because of yank bugs. dirname = utils.get_data_filename( "../examples/p-xylene-implicit/setup/" ) # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ with utils.temporary_directory() as store_dir: run_cli( 'prepare binding amber --setupdir=%(dirname)s --ligand="resname MOL" --store %(store_dir)s --gbsa OBC1' % vars() )
def test_setup_binding(): # NOTE: switched to yank p-xylene from openmmtools T4-lysozyme because of yank bugs. #dirname = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit") dirname = utils.get_data_filename( "../examples/p-xylene-implicit/setup/" ) # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ storedir = tempfile.mkdtemp() run_cli( 'setup binding amber --setupdir=%(dirname)s --ligname MOL --store %(storedir)s' % vars())
def test_prepare_gromacs_explicit(verbose=False): store_directory = tempfile.mkdtemp() examples_path = utils.get_data_filename("../examples/p-xylene-gromacs-example/setup/") command = 'yank prepare binding gromacs --setupdir=%(examples_path)s --store=%(store_directory)s --iterations=1 --nbmethod=CutoffPeriodic --temperature=300*kelvin --pressure=1*atmospheres --cutoff=1*nanometer' % vars() if verbose: command += ' --verbose' argv = command.split() argv.append('--ligand=resname MOL') # if included in the command string it is split in two args = docopt(usage, version=version.version, argv=argv[1:]) from yank.commands import prepare prepare.dispatch(args)
def test_prepare_gromacs_explicit(verbose=False): store_directory = tempfile.mkdtemp() examples_path = utils.get_data_filename("../examples/p-xylene-gromacs-example/setup/") command = 'yank prepare binding gromacs --setupdir=%(examples_path)s --store=%(store_directory)s --iterations=1 --nbmethod=CutoffPeriodic --temperature=300*kelvin --pressure=1*atmospheres --cutoff=1*nanometer' % vars() if verbose: command += ' --verbose' argv = command.split() argv.append("--ligand=resname 'p-xylene'") # if included in the command string it is split in two args = docopt(usage, version=version.version, argv=argv[1:]) from yank.commands import prepare prepare.dispatch(args)
def test_prepare_amber_explicit(verbose=False): store_directory = tempfile.mkdtemp() examples_path = utils.get_data_filename("../examples/benzene-toluene-explicit/setup/") # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ command = 'yank prepare binding amber --setupdir=%(examples_path)s --store=%(store_directory)s --iterations=1 --nbmethod=CutoffPeriodic --temperature=300*kelvin --pressure=1*atmospheres' % vars() if verbose: command += ' --verbose' argv = command.split() argv.append('--ligand=resname TOL') # if included in the command string it is split in two args = docopt(usage, version=version.version, argv=argv[1:]) from yank.commands import prepare prepare.dispatch(args)
def test_script_yaml(): """Check that yank script --yaml command works.""" setup_dir = utils.get_data_filename(os.path.join('tests', 'data', 'p-xylene-implicit')) pxylene_path = os.path.join(setup_dir, 'p-xylene.mol2') lysozyme_path = os.path.join(setup_dir, '181L-pdbfixer.pdb') yaml_content = """ --- options: default_number_of_iterations: 0 output_dir: '.' resume_setup: yes resume_simulation: no minimize: no molecules: T4lysozyme: filepath: {} p-xylene: filepath: {} antechamber: charge_method: bcc solvents: vacuum: nonbonded_method: NoCutoff protocols: absolute-binding: complex: alchemical_path: lambda_electrostatics: [1.0, 0.5, 0.0] lambda_sterics: [1.0, 0.5, 0.0] solvent: alchemical_path: lambda_electrostatics: [1.0, 0.5, 0.0] lambda_sterics: [1.0, 0.5, 0.0] systems: system: receptor: T4lysozyme ligand: p-xylene solvent: vacuum leap: parameters: [leaprc.gaff, oldff/leaprc.ff14SB] experiments: system: system protocol: absolute-binding restraint: type: FlatBottom """.format(lysozyme_path, pxylene_path) with mmtools.utils.temporary_directory() as tmp_dir: yaml_file_path = os.path.join(tmp_dir, 'yank.yaml') with open(yaml_file_path, 'w') as f: f.write(textwrap.dedent(yaml_content)) run_cli('script --yaml={}'.format(yaml_file_path)) # Test option overriding. run_cli('script --yaml={} -o options:resume_simulation:yes'.format(yaml_file_path))
def test_setup_amber_implicit(verbose=False): """ Test 'yank setup binding amber' for implicit solvent system. """ store_directory = tempfile.mkdtemp() examples_path = utils.get_data_filename("../examples/benzene-toluene-implicit/setup/") # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ command = 'yank setup binding amber --setupdir=%(examples_path)s --ligname=BEN --store=%(store_directory)s --iterations=1 --restraints=harmonic --gbsa=OBC2 --temperature=300*kelvin' % vars() if verbose: command += ' --verbose' argv = command.split() args = docopt(usage, version=version.version, argv=argv[1:]) from yank.commands import setup setup.dispatch(args)
def test_script_yaml(): """Check that yank script --yaml command works.""" setup_dir = utils.get_data_filename(os.path.join("..", "examples", "p-xylene-implicit", "input")) pxylene_path = os.path.join(setup_dir, "p-xylene.mol2") lysozyme_path = os.path.join(setup_dir, "181L-pdbfixer.pdb") with omt.utils.temporary_directory() as tmp_dir: yaml_content = """ --- options: number_of_iterations: 1 output_dir: '.' molecules: T4lysozyme: filepath: {} p-xylene: filepath: {} antechamber: charge_method: bcc solvents: vacuum: nonbonded_method: NoCutoff protocols: absolute-binding: complex: alchemical_path: lambda_electrostatics: [1.0, 0.9, 0.8, 0.6, 0.4, 0.2, 0.0] lambda_sterics: [1.0, 0.9, 0.8, 0.6, 0.4, 0.2, 0.0] solvent: alchemical_path: lambda_electrostatics: [1.0, 0.8, 0.6, 0.3, 0.0] lambda_sterics: [1.0, 0.8, 0.6, 0.3, 0.0] systems: system: receptor: T4lysozyme ligand: p-xylene solvent: vacuum leap: parameters: [leaprc.gaff, leaprc.ff14SB] experiments: system: system protocol: absolute-binding """.format( lysozyme_path, pxylene_path ) yaml_file_path = os.path.join(tmp_dir, "yank.yaml") with open(yaml_file_path, "w") as f: f.write(textwrap.dedent(yaml_content)) run_cli("script --yaml={}".format(yaml_file_path))
def test_setup_amber_explicit(verbose=False): """ Test 'yank setup binding amber' for explicit solvent system. """ store_directory = tempfile.mkdtemp() examples_path = utils.get_data_filename( "../examples/benzene-toluene-explicit/setup/" ) # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ command = 'yank setup binding amber --setupdir=%(examples_path)s --ligname=BEN --store=%(store_directory)s --iterations=1 --nbmethod=CutoffPeriodic --temperature=300*kelvin --pressure=1*atmospheres' % vars( ) if verbose: command += ' --verbose' argv = command.split() args = docopt(usage, version=version.version, argv=argv[1:]) from yank.commands import setup setup.dispatch(args)
def test_script_yaml(): """Check that yank script --yaml command works.""" setup_dir = utils.get_data_filename(os.path.join('..', 'examples', 'p-xylene-implicit', 'input')) pxylene_path = os.path.join(setup_dir, 'p-xylene.mol2') lysozyme_path = os.path.join(setup_dir, '181L-pdbfixer.pdb') with omt.utils.temporary_directory() as tmp_dir: yaml_content = """ --- options: number_of_iterations: 1 output_dir: '.' molecules: T4lysozyme: filepath: {} p-xylene: filepath: {} antechamber: charge_method: bcc solvents: vacuum: nonbonded_method: NoCutoff protocols: absolute-binding: complex: alchemical_path: lambda_electrostatics: [1.0, 0.9, 0.8, 0.6, 0.4, 0.2, 0.0] lambda_sterics: [1.0, 0.9, 0.8, 0.6, 0.4, 0.2, 0.0] solvent: alchemical_path: lambda_electrostatics: [1.0, 0.8, 0.6, 0.3, 0.0] lambda_sterics: [1.0, 0.8, 0.6, 0.3, 0.0] systems: system: receptor: T4lysozyme ligand: p-xylene solvent: vacuum leap: parameters: [leaprc.gaff, leaprc.ff14SB] experiments: system: system protocol: absolute-binding """.format(lysozyme_path, pxylene_path) yaml_file_path = os.path.join(tmp_dir, 'yank.yaml') with open(yaml_file_path, 'w') as f: f.write(textwrap.dedent(yaml_content)) run_cli('script --yaml={}'.format(yaml_file_path))
def general_restraint_run(options): """ Generalized restraint simulation run to test free energy = standard state correction. options : Dict. A dictionary of substitutions for restraint_test_yaml """ with mmtools.utils.temporary_directory() as output_directory: # TODO refactor this to use AlchemicalPhase API rather than a YAML script. options['input_directory'] = get_data_filename( os.path.join('tests', 'data')) options['output_directory'] = output_directory # run both setup and experiment yaml_builder = experiment.ExperimentBuilder(restraint_test_yaml % options) yaml_builder.run_experiments() # Estimate Free Energies ncfile_path = os.path.join(output_directory, 'experiments', 'complex.nc') reporter = multistate.MultiStateReporter(ncfile_path, open_mode='r') #analyzer = multistate.MultiStateSamplerAnalyzer(reporter) analyzer = YankMultiStateSamplerAnalyzer(reporter) Deltaf_ij, dDeltaf_ij = analyzer.get_free_energy() # Correct the sign for the fact that we are adding vs removing the restraints DeltaF_simulated = Deltaf_ij[-1, 0] dDeltaF_simulated = dDeltaf_ij[-1, 0] print('Standard state correction:') #ncfile = netcdf.Dataset(ncfile_path, 'r') #print(ncfile.groups['metadata'].variables['standard_state_correction'][:]) #print(float(ncfile.groups['metadata'].variables['standard_state_correction'][:])) #ncfile.close() DeltaF_restraints = analyzer.get_standard_state_correction() # Check if they are close msg = '' msg += 'Computed: %8.3f kT\n' % (DeltaF_restraints) msg += 'Actual: %8.3f +- %8.3f kT\n' % (DeltaF_simulated, dDeltaF_simulated) msg += 'ERROR: %8.3f +- %8.3f kT\n' % ( DeltaF_restraints - DeltaF_simulated, dDeltaF_simulated) # DEBUG print(msg) assert np.allclose( DeltaF_restraints, DeltaF_simulated, rtol=2 * dDeltaF_simulated), 'Standard state correction is inaccurate.\n' + msg
def test_script_yaml(): """Check that yank script --yamlscript command works.""" setup_dir = utils.get_data_filename(os.path.join('..', 'examples', 'p-xylene-implicit', 'setup')) pxylene_path = os.path.join(setup_dir, 'ligand.tripos.mol2') lysozyme_path = os.path.join(setup_dir, 'receptor.pdbfixer.pdb') with utils.temporary_directory() as tmp_dir: yaml_content = """ --- options: number_of_iterations: 1 output_dir: '.' molecules: T4lysozyme: filepath: {} parameters: oldff/leaprc.ff99SBildn p-xylene: filepath: {} parameters: antechamber solvents: vacuum: nonbonded_method: NoCutoff protocols: absolute-binding: phases: complex: alchemical_path: lambda_electrostatics: [1.0, 0.9, 0.8, 0.6, 0.4, 0.2, 0.0] lambda_sterics: [1.0, 0.9, 0.8, 0.6, 0.4, 0.2, 0.0] solvent: alchemical_path: lambda_electrostatics: [1.0, 0.8, 0.6, 0.3, 0.0] lambda_sterics: [1.0, 0.8, 0.6, 0.3, 0.0] experiments: components: receptor: T4lysozyme ligand: p-xylene solvent: vacuum protocol: absolute-binding """.format(lysozyme_path, pxylene_path) yaml_file_path = os.path.join(tmp_dir, 'yank.yaml') with open(yaml_file_path, 'w') as f: f.write(textwrap.dedent(yaml_content)) run_cli('script --yaml={}'.format(yaml_file_path))
def general_restraint_run(options): """ Generalized restraint simulation run to test free energy = standard state correction. options : Dict. A dictionary of substitutions for restraint_test_yaml """ with mmtools.utils.temporary_directory() as output_directory: # TODO refactor this to use AlchemicalPhase API rather than a YAML script. options['input_directory'] = get_data_filename(os.path.join('tests', 'data')) options['output_directory'] = output_directory # run both setup and experiment yaml_builder = experiment.ExperimentBuilder(restraint_test_yaml % options) yaml_builder.run_experiments() # Estimate Free Energies ncfile_path = os.path.join(output_directory, 'experiments', 'complex.nc') reporter = multistate.MultiStateReporter(ncfile_path, open_mode='r') #analyzer = multistate.MultiStateSamplerAnalyzer(reporter) analyzer = YankMultiStateSamplerAnalyzer(reporter) Deltaf_ij, dDeltaf_ij = analyzer.get_free_energy() # Correct the sign for the fact that we are adding vs removing the restraints DeltaF_simulated = Deltaf_ij[-1, 0] dDeltaF_simulated = dDeltaf_ij[-1, 0] print('Standard state correction:') #ncfile = netcdf.Dataset(ncfile_path, 'r') #print(ncfile.groups['metadata'].variables['standard_state_correction'][:]) #print(float(ncfile.groups['metadata'].variables['standard_state_correction'][:])) #ncfile.close() DeltaF_restraints = analyzer.get_standard_state_correction() # Check if they are close msg = '' msg += 'Computed: %8.3f kT\n' % (DeltaF_restraints) msg += 'Actual: %8.3f +- %8.3f kT\n' % (DeltaF_simulated, dDeltaF_simulated) msg += 'ERROR: %8.3f +- %8.3f kT\n' % (DeltaF_restraints - DeltaF_simulated, dDeltaF_simulated) # DEBUG print(msg) assert np.allclose(DeltaF_restraints, DeltaF_simulated, rtol=2*dDeltaF_simulated), 'Standard state correction is inaccurate.\n' + msg
def test_setup_binding(): # NOTE: switched to yank p-xylene from openmmtools T4-lysozyme because of yank bugs. #dirname = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit") dirname = utils.get_data_filename("../examples/p-xylene-implicit/setup/") # Could only figure out how to install things like yank.egg/examples/, rather than yank.egg/yank/examples/ storedir = tempfile.mkdtemp() run_cli('setup binding amber --setupdir=%(dirname)s --ligname MOL --store %(storedir)s' % vars())
def test_protein_ligand_restraints(): """Test the restraints in a protein:ligand system. """ from yank.yamlbuild import YamlBuilder from yank.utils import get_data_filename yaml_script = """ --- options: minimize: no verbose: no output_dir: %(output_directory)s number_of_iterations: 2 nsteps_per_iteration: 10 temperature: 300*kelvin molecules: T4lysozyme: filepath: %(receptor_filepath)s p-xylene: filepath: %(ligand_filepath)s antechamber: charge_method: bcc solvents: vacuum: nonbonded_method: NoCutoff systems: lys-pxyl: receptor: T4lysozyme ligand: p-xylene solvent: vacuum leap: parameters: [oldff/leaprc.ff14SB, leaprc.gaff] protocols: absolute-binding: complex: alchemical_path: lambda_restraints: [0.0, 0.5, 1.0] lambda_electrostatics: [1.0, 1.0, 1.0] lambda_sterics: [1.0, 1.0, 1.0] solvent: alchemical_path: lambda_electrostatics: [1.0, 1.0, 1.0] lambda_sterics: [1.0, 1.0, 1.0] experiments: system: lys-pxyl protocol: absolute-binding restraint: type: %(restraint_type)s """ # Test all possible restraint types. available_restraint_types = yank.restraints.available_restraint_types() for restraint_type in available_restraint_types: print('***********************************') print('Testing %s restraints...' % restraint_type) print('***********************************') output_directory = tempfile.mkdtemp() data = { 'output_directory': output_directory, 'restraint_type': restraint_type, 'receptor_filepath': get_data_filename( 'tests/data/p-xylene-implicit/181L-pdbfixer.pdb'), 'ligand_filepath': get_data_filename('tests/data/p-xylene-implicit/p-xylene.mol2'), } # run both setup and experiment yaml_builder = YamlBuilder(yaml_script % data) yaml_builder.build_experiments() # Clean up shutil.rmtree(output_directory)