示例#1
0
文件: run.py 项目: jchodera/yank
def dispatch(args):
    from yank.yank import Yank # TODO: Fix this awkward import syntax.

    store_directory = args['--store']

    # Set override options.
    options = dict()

    # Configure MPI, if requested.
    mpicomm = None
    if args['--mpi']:
        mpicomm = utils.initialize_mpi()
        logger.info("Initialized MPI on %d processes." % (mpicomm.size))

    # Configure logger
    utils.config_root_logger(args['--verbose'], mpicomm=mpicomm,
                             log_file_path=os.path.join(store_directory, 'run.log'))

    if args['--iterations']:
        options['number_of_iterations'] = int(args['--iterations'])
    if args['--online-analysis']:
        options['online_analysis'] = True
    if args['--platform'] not in [None, 'None']:
        options['platform'] = openmm.Platform.getPlatformByName(args['--platform'])
    if args['--precision']:
        # We need to modify the Platform object.
        if args['--platform'] is None:
            raise Exception("The --platform argument must be specified in order to specify platform precision.")

        # Set platform precision.
        precision = args['--precision']
        platform_name = args['--platform']
        logger.info("Setting %s platform to use precision model '%s'." % (platform_name, precision))
        if precision is not None:
            if platform_name == 'CUDA':
                options['platform'].setPropertyDefaultValue('CudaPrecision', precision)
            elif platform_name == 'OpenCL':
                options['platform'].setPropertyDefaultValue('OpenCLPrecision', precision)
            elif platform_name == 'CPU':
                if precision != 'mixed':
                    raise Exception("CPU platform does not support precision model '%s'; only 'mixed' is supported." % precision)
            elif platform_name == 'Reference':
                if precision != 'double':
                    raise Exception("Reference platform does not support precision model '%s'; only 'double' is supported." % precision)
            else:
                raise Exception("Platform selection logic is outdated and needs to be updated to add platform '%s'." % platform_name)

    # Create YANK object associated with data storage directory.
    yank = Yank(store_directory, mpicomm=mpicomm, **options)

    # Set YANK to resume from the store file.
    phases = None # By default, resume from all phases found in store_directory
    if args['--phase']: phases=[args['--phase']]
    yank.resume(phases=phases)

    # Run simulation.
    yank.run()

    return True
示例#2
0
def dispatch(args):
    from yank.yank import Yank # TODO: Fix this awkward import syntax.

    # Create YANK object associated with data storage directory.
    store_directory = args['--store']
    yank = Yank(store_directory)

    # Set override options.
    options = dict()
    if args['--iterations']:
        options['niterations'] = int(args['--iterations'])
    if args['--verbose']:
        options['verbose'] = True
    if args['--online-analysis']:
        options['online_analysis'] = True
    if args['--platform'] != 'None':
        options['platform'] = openmm.Platform.getPlatformByName(args['--platform'])

    # Set YANK to resume from the store file.
    phases = None # By default, resume from all phases found in store_directory
    if args['--phase']: phases=[args['--phase']]
    yank.resume(phases=phases)

    # Configure MPI, if requested.
    mpicomm = None
    if args['--mpi']:
        # Initialize MPI.
        from mpi4py import MPI
        hostname = os.uname()[1]
        if not MPI.COMM_WORLD.rank == 0:
            yank.verbose = False
        MPI.COMM_WORLD.barrier()
        if MPI.COMM_WORLD.rank == 0: print "Initialized MPI on %d processes." % (MPI.COMM_WORLD.size)
        mpicomm = MPI

    # Run simulation.
    yank.run(mpicomm, options=options)

    return True
示例#3
0
def dispatch(args):
    from yank.yank import Yank  # TODO: Fix this awkward import syntax.

    # Create YANK object associated with data storage directory.
    store_directory = args["--store"]
    yank = Yank(store_directory)

    # Set override options.
    options = dict()
    if args["--iterations"]:
        options["niterations"] = int(args["--iterations"])
    if args["--verbose"]:
        options["verbose"] = True
    if args["--online-analysis"]:
        options["online_analysis"] = True
    if args["--platform"] != "None":
        options["platform"] = openmm.Platform.getPlatformByName(args["--platform"])

    # Set YANK to resume from the store file.
    phases = None  # By default, resume from all phases found in store_directory
    if args["--phase"]:
        phases = [args["--phase"]]
    yank.resume(phases=phases)

    # Configure MPI, if requested.
    mpicomm = None
    if args["--mpi"]:
        # Initialize MPI.
        from mpi4py import MPI

        hostname = os.uname()[1]
        if not MPI.COMM_WORLD.rank == 0:
            yank.verbose = False
        MPI.COMM_WORLD.barrier()
        if MPI.COMM_WORLD.rank == 0:
            print "Initialized MPI on %d processes." % (MPI.COMM_WORLD.size)
        mpicomm = MPI

    # Run simulation.
    yank.run(mpicomm, options=options)

    return True
示例#4
0
def dispatch(args):
    from yank.yank import Yank # TODO: Fix this awkward import syntax.

    store_directory = args['--store']

    # Set override options.
    options = dict()

    # Configure MPI, if requested.
    mpicomm = None
    if args['--mpi']:
        # Initialize MPI.
        from mpi4py import MPI
        hostname = os.uname()[1]
        MPI.COMM_WORLD.barrier()
        logger.info("Initialized MPI on %d processes." % (MPI.COMM_WORLD.size))
        mpicomm = MPI.COMM_WORLD

    # Configure logger
    utils.config_root_logger(args['--verbose'], mpicomm=mpicomm,
                             log_file_path=os.path.join(store_directory, 'run.log'))

    if args['--iterations']:
        options['number_of_iterations'] = int(args['--iterations'])
    if args['--online-analysis']:
        options['online_analysis'] = True
    if args['--platform'] not in [None, 'None']:
        options['platform'] = openmm.Platform.getPlatformByName(args['--platform'])
    if args['--precision']:
        # We need to modify the Platform object.
        if args['--platform'] is None:
            raise Exception("The --platform argument must be specified in order to specify platform precision.")

        # Set platform precision.
        precision = args['--precision']
        platform_name = args['--platform']
        logger.info("Setting %s platform to use precision model '%s'." % (platform_name, precision))
        if precision is not None:
            if platform_name == 'CUDA':
                options['platform'].setPropertyDefaultValue('CudaPrecision', precision)
            elif platform_name == 'OpenCL':
                options['platform'].setPropertyDefaultValue('OpenCLPrecision', precision)
            elif platform_name == 'CPU':
                if precision != 'mixed':
                    raise Exception("CPU platform does not support precision model '%s'; only 'mixed' is supported." % precision)
            elif platform_name == 'Reference':
                if precision != 'double':
                    raise Exception("Reference platform does not support precision model '%s'; only 'double' is supported." % precision)
            else:
                raise Exception("Platform selection logic is outdated and needs to be updated to add platform '%s'." % platform_name)

    # Create YANK object associated with data storage directory.
    yank = Yank(store_directory, mpicomm=mpicomm, **options)

    # Set YANK to resume from the store file.
    phases = None # By default, resume from all phases found in store_directory
    if args['--phase']: phases=[args['--phase']]
    yank.resume(phases=phases)

    # Run simulation.
    yank.run()

    return True
示例#5
0
        app.PDBFile.writeFile(simulation.topology, modeller.positions, open(filename, 'w'))

        # Clean up
        del simulation

    # Return the modeller instance.
    return [modeller.topology, system, modeller.positions]

# ==============================================================================
# PREPARE YANK CALCULATION
# ==============================================================================

from yank.yank import Yank

# Initialize YANK object.
yank = Yank(store_dir)

# Set options.
options = dict()
options['number_of_iterations'] = niterations
options['number_of_equilibration_iterations'] = nequiliterations
options['nsteps_per_iteration'] = nsteps_per_iteration
options['online_analysis'] = False
yank.restraint_type = None
options['randomize_ligand'] = False
options['minimize'] = True
options['timestep'] = timestep
options['collision_rate'] = collision_rate
options['platform'] = platform

if not is_periodic:
示例#6
0
def dispatch_binding(args):
    """
    Set up a binding free energy calculation.

    Parameters
    ----------
    args : dict
       Command-line arguments from docopt.

    """

    verbose = args['--verbose']

    #
    # Determine simulation options.
    #

    # Specify thermodynamic parameters.
    temperature = process_unit_bearing_argument(args, '--temperature', unit.kelvin)
    pressure = process_unit_bearing_argument(args, '--pressure', unit.atmospheres)
    thermodynamic_state = ThermodynamicState(temperature=temperature, pressure=pressure)

    # Create systems according to specified setup/import method.
    if args['amber']:
        [phases, systems, positions, atom_indices] = setup_binding_amber(args)
    elif args['systembuilder']:
        [phases, systems, positions, atom_indices] = setup_binding_systembuilder(args)
    else:
        print "No valid binding free energy calculation setup command specified: Must be one of ['amber', 'systembuilder']."
        # Trigger help argument to be returned.
        return False

    # Report some useful properties.
    if verbose:
        if 'complex-explicit' in atom_indices:
            phase = 'complex-explicit'
        else:
            phase = 'complex-implicit'
        print "  TOTAL ATOMS      : %9d" % len(atom_indices[phase]['complex'])
        print "  receptor         : %9d" % len(atom_indices[phase]['receptor'])
        print "  ligand           : %9d" % len(atom_indices[phase]['ligand'])
        if phase == 'complex-explicit':
            print "  solvent and ions : %9d" % len(atom_indices[phase]['solvent'])

    # Initialize YANK object.
    yank = Yank(args['--store'], verbose=verbose)

    # Set options.
    options = dict()
    if args['--iterations']:
        options['number_of_iterations'] = int(args['--iterations'])
    if args['--online-analysis']:
        options['online_analysis'] = True
    if args['--restraints']:
        yank.restraint_type = args['--restraints']
    if args['--randomize-ligand']:
        options['randomize_ligand'] = True
    if args['--minimize']:
        options['minimize'] = True

    # Create new simulation.
    yank.create(phases, systems, positions, atom_indices, thermodynamic_state, options=options)

    # Report success.
    return True
示例#7
0
文件: prepare.py 项目: akapoor85/yank
def dispatch_binding(args):
    """
    Set up a binding free energy calculation.

    Parameters
    ----------
    args : dict
       Command-line arguments from docopt.

    """

    verbose = args['--verbose']
    store_dir = args['--store']
    utils.config_root_logger(verbose,
                             log_file_path=os.path.join(
                                 store_dir, 'prepare.log'))

    #
    # Determine simulation options.
    #

    # Specify thermodynamic parameters.
    temperature = process_unit_bearing_argument(args, '--temperature',
                                                unit.kelvin)
    pressure = process_unit_bearing_argument(args, '--pressure',
                                             unit.atmospheres)
    thermodynamic_state = ThermodynamicState(temperature=temperature,
                                             pressure=pressure)

    # Create systems according to specified setup/import method.
    if args['amber']:
        [phases, systems, positions, atom_indices] = setup_binding_amber(args)
    elif args['gromacs']:
        [phases, systems, positions,
         atom_indices] = setup_binding_gromacs(args)
    else:
        logger.error(
            "No valid binding free energy calculation setup command specified: Must be one of ['amber', 'systembuilder']."
        )
        # Trigger help argument to be returned.
        return False

    # Report some useful properties.
    if verbose:
        if 'complex-explicit' in atom_indices:
            phase = 'complex-explicit'
        else:
            phase = 'complex-implicit'
        logger.info("TOTAL ATOMS      : %9d" %
                    len(atom_indices[phase]['complex']))
        logger.info("receptor         : %9d" %
                    len(atom_indices[phase]['receptor']))
        logger.info("ligand           : %9d" %
                    len(atom_indices[phase]['ligand']))
        if phase == 'complex-explicit':
            logger.info("solvent and ions : %9d" %
                        len(atom_indices[phase]['solvent']))

    # Initialize YANK object.
    yank = Yank(store_dir)

    # Set options.
    options = dict()
    if args['--nsteps']:
        options['nsteps_per_iteration'] = int(args['--nsteps'])
    if args['--iterations']:
        options['number_of_iterations'] = int(args['--iterations'])
    if args['--equilibrate']:
        options['number_of_equilibration_iterations'] = int(
            args['--equilibrate'])
    if args['--online-analysis']:
        options['online_analysis'] = True
    if args['--restraints']:
        yank.restraint_type = args['--restraints']
    if args['--randomize-ligand']:
        options['randomize_ligand'] = True
    if args['--minimize']:
        options['minimize'] = True

    # Allow platform to be optionally specified in order for alchemical tests to be carried out.
    if args['--platform'] not in [None, 'None']:
        options['platform'] = openmm.Platform.getPlatformByName(
            args['--platform'])
    if args['--precision']:
        # We need to modify the Platform object.
        if args['--platform'] is None:
            raise Exception(
                "The --platform argument must be specified in order to specify platform precision."
            )

        # Set platform precision.
        precision = args['--precision']
        platform_name = args['--platform']
        logger.info(
            "Setting %s platform to use precision model '%s'." % platform_name,
            precision)
        if precision is not None:
            if platform_name == 'CUDA':
                options['platform'].setPropertyDefaultValue(
                    'CudaPrecision', precision)
            elif platform_name == 'OpenCL':
                options['platform'].setPropertyDefaultValue(
                    'OpenCLPrecision', precision)
            elif platform_name == 'CPU':
                if precision != 'mixed':
                    raise Exception(
                        "CPU platform does not support precision model '%s'; only 'mixed' is supported."
                        % precision)
            elif platform_name == 'Reference':
                if precision != 'double':
                    raise Exception(
                        "Reference platform does not support precision model '%s'; only 'double' is supported."
                        % precision)
            else:
                raise Exception(
                    "Platform selection logic is outdated and needs to be updated to add platform '%s'."
                    % platform_name)

    # Create new simulation.
    yank.create(phases,
                systems,
                positions,
                atom_indices,
                thermodynamic_state,
                options=options)

    # Report success.
    return True
示例#8
0
def dispatch_binding(args):
    """
    Set up a binding free energy calculation.

    Parameters
    ----------
    args : dict
       Command-line arguments from docopt.

    """

    verbose = args["--verbose"]
    store_dir = args["--store"]
    utils.config_root_logger(verbose, log_file_path=os.path.join(store_dir, "prepare.log"))

    #
    # Determine simulation options.
    #

    # Specify thermodynamic parameters.
    temperature = process_unit_bearing_arg(args, "--temperature", unit.kelvin)
    pressure = process_unit_bearing_arg(args, "--pressure", unit.atmospheres)
    thermodynamic_state = ThermodynamicState(temperature=temperature, pressure=pressure)

    # Create systems according to specified setup/import method.
    if args["amber"]:
        [phases, systems, positions, atom_indices] = setup_binding_amber(args)
    elif args["gromacs"]:
        [phases, systems, positions, atom_indices] = setup_binding_gromacs(args)
    else:
        logger.error(
            "No valid binding free energy calculation setup command specified: Must be one of ['amber', 'systembuilder']."
        )
        # Trigger help argument to be returned.
        return False

    # Report some useful properties.
    if verbose:
        if "complex-explicit" in atom_indices:
            phase = "complex-explicit"
        else:
            phase = "complex-implicit"
        logger.info("TOTAL ATOMS      : %9d" % len(atom_indices[phase]["complex"]))
        logger.info("receptor         : %9d" % len(atom_indices[phase]["receptor"]))
        logger.info("ligand           : %9d" % len(atom_indices[phase]["ligand"]))
        if phase == "complex-explicit":
            logger.info("solvent and ions : %9d" % len(atom_indices[phase]["solvent"]))

    # Initialize YANK object.
    yank = Yank(store_dir)

    # Set options.
    options = dict()
    if args["--nsteps"]:
        options["nsteps_per_iteration"] = int(args["--nsteps"])
    if args["--iterations"]:
        options["number_of_iterations"] = int(args["--iterations"])
    if args["--equilibrate"]:
        options["number_of_equilibration_iterations"] = int(args["--equilibrate"])
    if args["--online-analysis"]:
        options["online_analysis"] = True
    if args["--restraints"]:
        options["restraint_type"] = args["--restraints"]
    if args["--randomize-ligand"]:
        options["randomize_ligand"] = True
    if args["--minimize"]:
        options["minimize"] = True

    # Allow platform to be optionally specified in order for alchemical tests to be carried out.
    if args["--platform"] not in [None, "None"]:
        options["platform"] = openmm.Platform.getPlatformByName(args["--platform"])
    if args["--precision"]:
        # We need to modify the Platform object.
        if args["--platform"] is None:
            raise Exception("The --platform argument must be specified in order to specify platform precision.")

        # Set platform precision.
        precision = args["--precision"]
        platform_name = args["--platform"]
        logger.info("Setting %s platform to use precision model '%s'." % platform_name, precision)
        if precision is not None:
            if platform_name == "CUDA":
                options["platform"].setPropertyDefaultValue("CudaPrecision", precision)
            elif platform_name == "OpenCL":
                options["platform"].setPropertyDefaultValue("OpenCLPrecision", precision)
            elif platform_name == "CPU":
                if precision != "mixed":
                    raise Exception(
                        "CPU platform does not support precision model '%s'; only 'mixed' is supported." % precision
                    )
            elif platform_name == "Reference":
                if precision != "double":
                    raise Exception(
                        "Reference platform does not support precision model '%s'; only 'double' is supported."
                        % precision
                    )
            else:
                raise Exception(
                    "Platform selection logic is outdated and needs to be updated to add platform '%s'." % platform_name
                )

    yank.options.cli = options

    # Parse YAML configuration file and create YankOptions object
    if args["--yaml"]:
        yank.options.yaml = YamlBuilder(args["--yaml"]).options

    # Create new simulation.
    yank.create(phases, systems, positions, atom_indices, thermodynamic_state)

    # Report success.
    return True
示例#9
0
    # Identify various components.
    solvated_topology_mdtraj = mdtraj.Topology.from_openmm(solvated_topology_openmm)
    atom_indices = dict()
    for component in components:
        atom_indices[component] = solvated_topology_mdtraj.select(component_dsl[component])

    # DEBUG
    print "Atom indices of ligand:"
    print atom_indices[phase]['ligand']

    alchemical_phases.append(AlchemicalPhase(phase, solvated_system,
                                             solvated_topology_openmm,
                                             solvated_positions, atom_indices,
                                             protocols[phase_prefix]))

# Create reference thermodynamic state.
from yank.repex import ThermodynamicState # TODO: Fix this weird import path to something more sane, like 'from yank.repex import ThermodynamicState'
if is_periodic:
    thermodynamic_state = ThermodynamicState(temperature=temperature, pressure=pressure)
else:
    thermodynamic_state = ThermodynamicState(temperature=temperature)

# TODO: Select protocols.

# Create new simulation.
yank = Yank(store_dir, **options)
yank.create(thermodynamic_state, *alchemical_phases)

# TODO: Write PDB files
示例#10
0
def dispatch_binding(args):
    """
    Set up a binding free energy calculation.

    Parameters
    ----------
    args : dict
       Command-line arguments from docopt.

    """

    verbose = args['--verbose']
    store_dir = args['--store']
    utils.config_root_logger(verbose, log_file_path=os.path.join(store_dir, 'prepare.log'))

    #
    # Determine simulation options.
    #

    # Specify thermodynamic parameters.
    temperature = process_unit_bearing_arg(args, '--temperature', unit.kelvin)
    pressure = process_unit_bearing_arg(args, '--pressure', unit.atmospheres)
    thermodynamic_state = ThermodynamicState(temperature=temperature, pressure=pressure)

    # Create systems according to specified setup/import method.
    if args['amber']:
        [phases, systems, positions, atom_indices] = setup_binding_amber(args)
    elif args['gromacs']:
        [phases, systems, positions, atom_indices] = setup_binding_gromacs(args)
    else:
        logger.error("No valid binding free energy calculation setup command specified: Must be one of ['amber', 'systembuilder'].")
        # Trigger help argument to be returned.
        return False

    # Report some useful properties.
    if verbose:
        if 'complex-explicit' in atom_indices:
            phase = 'complex-explicit'
        else:
            phase = 'complex-implicit'
        logger.info("TOTAL ATOMS      : %9d" % len(atom_indices[phase]['complex']))
        logger.info("receptor         : %9d" % len(atom_indices[phase]['receptor']))
        logger.info("ligand           : %9d" % len(atom_indices[phase]['ligand']))
        if phase == 'complex-explicit':
            logger.info("solvent and ions : %9d" % len(atom_indices[phase]['solvent']))

    # Set options.
    options = dict()
    if args['--nsteps']:
        options['nsteps_per_iteration'] = int(args['--nsteps'])
    if args['--iterations']:
        options['number_of_iterations'] = int(args['--iterations'])
    if args['--equilibrate']:
        options['number_of_equilibration_iterations'] = int(args['--equilibrate'])
    if args['--online-analysis']:
        options['online_analysis'] = True
    if args['--restraints']:
        options['restraint_type'] = args['--restraints']
    if args['--randomize-ligand']:
        options['randomize_ligand'] = True
    if args['--minimize']:
        options['minimize'] = True

    # Allow platform to be optionally specified in order for alchemical tests to be carried out.
    if args['--platform'] not in [None, 'None']:
        options['platform'] = openmm.Platform.getPlatformByName(args['--platform'])
    if args['--precision']:
        # We need to modify the Platform object.
        if args['--platform'] is None:
            raise Exception("The --platform argument must be specified in order to specify platform precision.")

        # Set platform precision.
        precision = args['--precision']
        platform_name = args['--platform']
        logger.info("Setting %s platform to use precision model '%s'." % platform_name, precision)
        if precision is not None:
            if platform_name == 'CUDA':
                options['platform'].setPropertyDefaultValue('CudaPrecision', precision)
            elif platform_name == 'OpenCL':
                options['platform'].setPropertyDefaultValue('OpenCLPrecision', precision)
            elif platform_name == 'CPU':
                if precision != 'mixed':
                    raise Exception("CPU platform does not support precision model '%s'; only 'mixed' is supported." % precision)
            elif platform_name == 'Reference':
                if precision != 'double':
                    raise Exception("Reference platform does not support precision model '%s'; only 'double' is supported." % precision)
            else:
                raise Exception("Platform selection logic is outdated and needs to be updated to add platform '%s'." % platform_name)

    # Parse YAML options, CLI options have priority
    if args['--yaml']:
        options.update(YamlBuilder(args['--yaml']).yank_options)

    # Create new simulation.
    yank = Yank(store_dir, **options)
    yank.create(phases, systems, positions, atom_indices, thermodynamic_state)

    # Report success.
    return True
示例#11
0
def dispatch_binding(args):
    """
    Set up a binding free energy calculation.

    Parameters
    ----------
    args : dict
       Command-line arguments from docopt.

    """

    verbose = args['--verbose']
    store_dir = args['--store']
    utils.config_root_logger(verbose,
                             log_file_path=os.path.join(
                                 store_dir, 'prepare.log'))

    #
    # Determine simulation options.
    #

    # Specify thermodynamic parameters.
    temperature = process_unit_bearing_arg(args, '--temperature', unit.kelvin)
    pressure = process_unit_bearing_arg(args, '--pressure', unit.atmospheres)
    thermodynamic_state = ThermodynamicState(temperature=temperature,
                                             pressure=pressure)

    # Create systems according to specified setup/import method.
    if args['amber']:
        alchemical_phases = setup_binding_amber(args)
    elif args['gromacs']:
        alchemical_phases = setup_binding_gromacs(args)
    else:
        logger.error(
            "No valid binding free energy calculation setup command specified: Must be one of ['amber', 'systembuilder']."
        )
        # Trigger help argument to be returned.
        return False

    # Set options.
    options = dict()
    if args['--nsteps']:
        options['nsteps_per_iteration'] = int(args['--nsteps'])
    if args['--iterations']:
        options['number_of_iterations'] = int(args['--iterations'])
    if args['--equilibrate']:
        options['number_of_equilibration_iterations'] = int(
            args['--equilibrate'])
    if args['--online-analysis']:
        options['online_analysis'] = True
    if args['--restraints']:
        options['restraint_type'] = args['--restraints']
    if args['--randomize-ligand']:
        options['randomize_ligand'] = True
    if args['--minimize']:
        options['minimize'] = True

    # Allow platform to be optionally specified in order for alchemical tests to be carried out.
    if args['--platform'] not in [None, 'None']:
        options['platform'] = openmm.Platform.getPlatformByName(
            args['--platform'])
    if args['--precision']:
        # We need to modify the Platform object.
        if args['--platform'] is None:
            raise Exception(
                "The --platform argument must be specified in order to specify platform precision."
            )

        # Set platform precision.
        precision = args['--precision']
        platform_name = args['--platform']
        logger.info(
            "Setting %s platform to use precision model '%s'." % platform_name,
            precision)
        if precision is not None:
            if platform_name == 'CUDA':
                options['platform'].setPropertyDefaultValue(
                    'CudaPrecision', precision)
            elif platform_name == 'OpenCL':
                options['platform'].setPropertyDefaultValue(
                    'OpenCLPrecision', precision)
            elif platform_name == 'CPU':
                if precision != 'mixed':
                    raise Exception(
                        "CPU platform does not support precision model '%s'; only 'mixed' is supported."
                        % precision)
            elif platform_name == 'Reference':
                if precision != 'double':
                    raise Exception(
                        "Reference platform does not support precision model '%s'; only 'double' is supported."
                        % precision)
            else:
                raise Exception(
                    "Platform selection logic is outdated and needs to be updated to add platform '%s'."
                    % platform_name)

    # Parse YAML options, CLI options have priority
    if args['--yaml']:
        options.update(YamlBuilder(args['--yaml']).yank_options)

    # Create new simulation.
    yank = Yank(store_dir, **options)
    yank.create(thermodynamic_state, *alchemical_phases)

    # Dump analysis object
    analysis = [[alchemical_phases[0].name, 1],
                [alchemical_phases[1].name, -1]]
    analysis_script_path = os.path.join(store_dir, 'analysis.yaml')
    with open(analysis_script_path, 'w') as f:
        yaml.dump(analysis, f)

    # Report success.
    return True
示例#12
0
        # Clean up
        del simulation

    # Return the modeller instance.
    return [modeller.topology, system, modeller.positions]


# ==============================================================================
# PREPARE YANK CALCULATION
# ==============================================================================

from yank.yank import Yank

# Initialize YANK object.
yank = Yank(store_dir)

# Set options.
options = dict()
options['number_of_iterations'] = niterations
options['number_of_equilibration_iterations'] = nequiliterations
options['nsteps_per_iteration'] = nsteps_per_iteration
options['online_analysis'] = False
yank.restraint_type = None
options['randomize_ligand'] = False
options['minimize'] = True
options['timestep'] = timestep
options['collision_rate'] = collision_rate
options['platform'] = platform

if not is_periodic:
示例#13
0
def dispatch_binding(args):
    """
    Set up a binding free energy calculation.

    Parameters
    ----------
    args : dict
       Command-line arguments from docopt.

    """

    verbose = args['--verbose']

    # Specify simulation parameters.
    nonbondedMethod = getattr(app, args['--nbmethod'])
    implicitSolvent = getattr(app, args['--gbsa'])
    if args['--constraints'] == None:
        args[
            '--constraints'] = None  # Necessary because there is no 'None' in simtk.openmm.app
    constraints = getattr(app, args['--constraints'])
    removeCMMotion = False

    # Specify thermodynamic parameters.
    temperature = process_unit_bearing_argument(args, '--temperature',
                                                unit.kelvin)
    pressure = process_unit_bearing_argument(args, '--pressure',
                                             unit.atmospheres)
    thermodynamic_state = ThermodynamicState(temperature=temperature,
                                             pressure=pressure)

    # Create systems according to specified setup/import method.
    if args['amber']:
        [phases, systems, positions, atom_indices] = setup_binding_amber(args)
    elif args['systembuilder']:
        [phases, systems, positions,
         atom_indices] = setup_binding_systembuilder(args)
    else:
        print "No valid binding free energy calculation setup command specified: Must be one of ['amber', 'systembuilder']."
        # Trigger help argument to be returned.
        return False

    # Report some useful properties.
    if verbose:
        if 'complex-explicit' in atom_indices:
            phase = 'complex-explicit'
        else:
            phase = 'complex-implicit'
        print "  TOTAL ATOMS      : %9d" % len(atom_indices[phase]['complex'])
        print "  receptor         : %9d" % len(atom_indices[phase]['receptor'])
        print "  ligand           : %9d" % len(atom_indices[phase]['ligand'])
        if phase == 'complex-explicit':
            print "  solvent and ions : %9d" % len(
                atom_indices[phase]['solvent'])

    # Initialize YANK object.
    yank = Yank(args['--store'], verbose=verbose)

    # Set options.
    options = dict()
    if args['--iterations']:
        options['number_of_iterations'] = int(args['--iterations'])
    if args['--online-analysis']:
        options['online_analysis'] = True
    if args['--restraints']:
        yank.restraint_type = args['--restraints']
    if args['--randomize-ligand']:
        options['randomize_ligand'] = True
    if args['--platform'] != 'None':
        options['platform'] = openmm.Platform.getPlatformByName(
            args['--platform'])
    if args['--minimize']:
        options['minimize'] = True

    # Create new simulation.
    yank.create(phases,
                systems,
                positions,
                atom_indices,
                thermodynamic_state,
                options=options)

    # Report success.
    return True
示例#14
0
文件: prepare.py 项目: jchodera/yank
def dispatch_binding(args):
    """
    Set up a binding free energy calculation.

    Parameters
    ----------
    args : dict
       Command-line arguments from docopt.

    """

    verbose = args["--verbose"]
    store_dir = args["--store"]
    utils.config_root_logger(verbose, log_file_path=os.path.join(store_dir, "prepare.log"))

    #
    # Determine simulation options.
    #

    # Specify thermodynamic parameters.
    temperature = process_unit_bearing_arg(args, "--temperature", unit.kelvin)
    pressure = process_unit_bearing_arg(args, "--pressure", unit.atmospheres)
    thermodynamic_state = ThermodynamicState(temperature=temperature, pressure=pressure)

    # Create systems according to specified setup/import method.
    if args["amber"]:
        alchemical_phases = setup_binding_amber(args)
    elif args["gromacs"]:
        alchemical_phases = setup_binding_gromacs(args)
    else:
        logger.error(
            "No valid binding free energy calculation setup command specified: Must be one of ['amber', 'systembuilder']."
        )
        # Trigger help argument to be returned.
        return False

    # Set options.
    options = dict()
    if args["--nsteps"]:
        options["nsteps_per_iteration"] = int(args["--nsteps"])
    if args["--iterations"]:
        options["number_of_iterations"] = int(args["--iterations"])
    if args["--equilibrate"]:
        options["number_of_equilibration_iterations"] = int(args["--equilibrate"])
    if args["--online-analysis"]:
        options["online_analysis"] = True
    if args["--restraints"]:
        options["restraint_type"] = args["--restraints"]
    if args["--randomize-ligand"]:
        options["randomize_ligand"] = True
    if args["--minimize"]:
        options["minimize"] = True

    # Allow platform to be optionally specified in order for alchemical tests to be carried out.
    if args["--platform"] not in [None, "None"]:
        options["platform"] = openmm.Platform.getPlatformByName(args["--platform"])
    if args["--precision"]:
        # We need to modify the Platform object.
        if args["--platform"] is None:
            raise Exception("The --platform argument must be specified in order to specify platform precision.")

        # Set platform precision.
        precision = args["--precision"]
        platform_name = args["--platform"]
        logger.info("Setting %s platform to use precision model '%s'." % platform_name, precision)
        if precision is not None:
            if platform_name == "CUDA":
                options["platform"].setPropertyDefaultValue("CudaPrecision", precision)
            elif platform_name == "OpenCL":
                options["platform"].setPropertyDefaultValue("OpenCLPrecision", precision)
            elif platform_name == "CPU":
                if precision != "mixed":
                    raise Exception(
                        "CPU platform does not support precision model '%s'; only 'mixed' is supported." % precision
                    )
            elif platform_name == "Reference":
                if precision != "double":
                    raise Exception(
                        "Reference platform does not support precision model '%s'; only 'double' is supported."
                        % precision
                    )
            else:
                raise Exception(
                    "Platform selection logic is outdated and needs to be updated to add platform '%s'." % platform_name
                )

    # Parse YAML options, CLI options have priority
    if args["--yaml"]:
        options.update(YamlBuilder(args["--yaml"]).yank_options)

    # Create new simulation.
    yank = Yank(store_dir, **options)
    yank.create(thermodynamic_state, *alchemical_phases)

    # Dump analysis object
    analysis = [[alchemical_phases[0].name, 1], [alchemical_phases[1].name, -1]]
    analysis_script_path = os.path.join(store_dir, "analysis.yaml")
    with open(analysis_script_path, "w") as f:
        yaml.dump(analysis, f)

    # Report success.
    return True