Ejemplo n.º 1
0
Archivo: run.py Proyecto: 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
Ejemplo n.º 2
0
    assert repex.nsteps_per_iteration == 1000000
    assert repex.collision_rate == repex.default_parameters['collision_rate']

@tools.raises(TypeError)
def test_unknown_parameters():
    """Test ReplicaExchange raises exception on wrong initialization."""
    ReplicaExchange(store_filename='test', wrong_parameter=False)

#=============================================================================================
# MAIN AND TESTS
#=============================================================================================

if __name__ == "__main__":
    # Configure logger.
    utils.config_root_logger(False)

    # Try MPI, if possible.
    try:
        mpicomm = utils.initialize_mpi()
        if mpicomm.rank == 0:
            print("MPI initialized successfully.")
    except Exception as e:
        print(e)
        print("Could not start MPI. Using serial code instead.")
        mpicomm = None

    # Test simple system of harmonic oscillators.
    # Disabled until we fix the test
    # test_hamiltonian_exchange(mpicomm)
    test_replica_exchange(mpicomm)
Ejemplo n.º 3
0
Archivo: run.py Proyecto: jlerche/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