Esempio n. 1
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_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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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