コード例 #1
0
ファイル: timing.py プロジェクト: cctbx/cctbx-playground
def run():
  target_structure = random_structure.xray_structure(
    space_group_info=sgtbx.space_group_info("I432"),
    elements=['C']*6+['O'],
    use_u_iso=False,
    use_u_aniso=True,
  )
  shift = tuple(flex.random_double(3))
  print "shift to be found: (%.3f, %.3f, %.3f)" % shift
  target_structure_in_p1 = target_structure.expand_to_p1().apply_shift(shift)
  miller_indices = miller.build_set(
    crystal_symmetry=target_structure,
    anomalous_flag=True,
    d_min=0.8)
  f_obs = miller_indices.structure_factors_from_scatterers(
    xray_structure=target_structure,
    algorithm="direct").f_calc().amplitudes()
  miller_indices_in_p1 = miller.build_set(
    crystal_symmetry=target_structure_in_p1,
    anomalous_flag=True,
    d_min=0.8)
  f_calc = miller_indices_in_p1.structure_factors_from_scatterers(
      xray_structure=target_structure_in_p1,
      algorithm="direct").f_calc()
  crystal_gridding = f_calc.crystal_gridding(
    symmetry_flags=translation_search.symmetry_flags(
      is_isotropic_search_model=False,
      have_f_part=False),
    resolution_factor=1/2
  )
  omptbx.env.num_threads = 1
  t_fast_tf = show_times()
  fast_tf_map = translation_search.fast_nv1995(
    gridding=crystal_gridding.n_real(),
    space_group=f_obs.space_group(),
    anomalous_flag=f_obs.anomalous_flag(),
    miller_indices_f_obs=f_obs.indices(),
    f_obs=f_obs.data(),
    f_part=flex.complex_double(), ## no sub-structure is already fixed
    miller_indices_p1_f_calc=f_calc.indices(),
    p1_f_calc=f_calc.data()).target_map()
  print
  print "Fast translation function"
  t_fast_tf()
  t_cross_corr = show_times()
  for op in target_structure.space_group():
    f, op_times_f = f_calc.original_and_transformed(op)
    cross_corr_map = miller.fft_map(crystal_gridding,
                                    f * op_times_f.conjugate().data())
  print
  print "Traditional cross-correlation"
  t_cross_corr()
コード例 #2
0
ファイル: timing.py プロジェクト: zhuligs/cctbx_project
def run():
    target_structure = random_structure.xray_structure(
        space_group_info=sgtbx.space_group_info("I432"),
        elements=['C'] * 6 + ['O'],
        use_u_iso=False,
        use_u_aniso=True,
    )
    shift = tuple(flex.random_double(3))
    print "shift to be found: (%.3f, %.3f, %.3f)" % shift
    target_structure_in_p1 = target_structure.expand_to_p1().apply_shift(shift)
    miller_indices = miller.build_set(crystal_symmetry=target_structure,
                                      anomalous_flag=True,
                                      d_min=0.8)
    f_obs = miller_indices.structure_factors_from_scatterers(
        xray_structure=target_structure,
        algorithm="direct").f_calc().amplitudes()
    miller_indices_in_p1 = miller.build_set(
        crystal_symmetry=target_structure_in_p1,
        anomalous_flag=True,
        d_min=0.8)
    f_calc = miller_indices_in_p1.structure_factors_from_scatterers(
        xray_structure=target_structure_in_p1, algorithm="direct").f_calc()
    crystal_gridding = f_calc.crystal_gridding(
        symmetry_flags=translation_search.symmetry_flags(
            is_isotropic_search_model=False, have_f_part=False),
        resolution_factor=1 / 2)
    omptbx.env.num_threads = 1
    t_fast_tf = show_times()
    fast_tf_map = translation_search.fast_nv1995(
        gridding=crystal_gridding.n_real(),
        space_group=f_obs.space_group(),
        anomalous_flag=f_obs.anomalous_flag(),
        miller_indices_f_obs=f_obs.indices(),
        f_obs=f_obs.data(),
        f_part=flex.complex_double(),  ## no sub-structure is already fixed
        miller_indices_p1_f_calc=f_calc.indices(),
        p1_f_calc=f_calc.data()).target_map()
    print
    print "Fast translation function"
    t_fast_tf()
    t_cross_corr = show_times()
    for op in target_structure.space_group():
        f, op_times_f = f_calc.original_and_transformed(op)
        cross_corr_map = miller.fft_map(crystal_gridding,
                                        f * op_times_f.conjugate().data())
    print
    print "Traditional cross-correlation"
    t_cross_corr()
コード例 #3
0
def run(args):
  timer = show_times(time_start="now")
  if (len(args) == 5):
    exercise(
      lbfgs_impl=eval(args[0]),
      n=int(args[1]),
      m=int(args[2]),
      iprint=[int(args[3]), int(args[4])])
    return
  assert args in [[], ["--once"], ["--endless"]]
  if (not have_lbfgs_fem):
    print "Skipping some tests: lbfgs_fem.cpp not linked into scitbx_lbfgs_ext."
  once = "--once" in args
  endless = "--endless" in args
  if (once or endless):
    while 1:
      if (have_lbfgs_fem):
        exercise(lbfgs_impl=fortran)
      exercise(lbfgs_impl=raw_reference)
      exercise(lbfgs_impl=raw)
      if (not endless): break
  else:
    compare_implementations()
  timer()
  print "OK"
コード例 #4
0
ファイル: tst_lbfgs_fem.py プロジェクト: dials/cctbx
def run(args):
    timer = show_times(time_start="now")
    if len(args) == 5:
        exercise(lbfgs_impl=eval(args[0]),
                 n=int(args[1]),
                 m=int(args[2]),
                 iprint=[int(args[3]), int(args[4])])
        return
    assert args in [[], ["--once"], ["--endless"]]
    if not have_lbfgs_fem:
        print(
            "Skipping some tests: lbfgs_fem.cpp not linked into scitbx_lbfgs_ext."
        )
    once = "--once" in args
    endless = "--endless" in args
    while once or endless:
        if have_lbfgs_fem:
            exercise(lbfgs_impl=fortran)
        exercise(lbfgs_impl=raw_reference)
        exercise(lbfgs_impl=raw)
        once = False
    else:
        compare_implementations()
    timer()
    print("OK")
コード例 #5
0
def run_program(program_class=None,
                custom_process_arguments=None,
                args=None,
                logger=None):
    '''
  Function for running programs using CCTBXParser and the program template

  :param program_class:  ProgramTemplate type (required)
  :param custom_process_arguments:
                         Custom function to parse unknown arguments (optional)
  :param args:           list of command-line arguments (optional)
  :param logger:         logger (e.g. multi_out) for output (optional)
  :rtype:                whatever is returned from program_class.get_results()
  '''

    assert program_class is not None

    if args is None:
        args = sys.argv[1:]

    # create logger
    if logger is None:
        logger = multi_out()
        logger.register('stdout', sys.stdout)
        logger.register('parser_log', StringIO())

    # start timer
    t = show_times(out=logger)

    # create parser
    parser = CCTBXParser(program_class=program_class,
                         custom_process_arguments=custom_process_arguments,
                         logger=logger)
    namespace = parser.parse_args(args)

    # start program
    print('Starting job', file=logger)
    print('=' * 79, file=logger)
    task = program_class(parser.data_manager,
                         parser.working_phil.extract(),
                         master_phil=parser.master_phil,
                         logger=logger)

    # validate inputs
    task.validate()

    # run program
    task.run()

    # clean up (optional)
    task.clean_up()

    # stop timer
    print('', file=logger)
    print('=' * 79, file=logger)
    print('Job complete', file=logger)
    t()

    return task.get_results()
コード例 #6
0
ファイル: __init__.py プロジェクト: TheApacheCats/cctbx
def run_molprobity_program(program_class=None,
                           custom_process_arguments=None,
                           args=None,
                           logger=None):
    '''
  Function for running programs using CCTBXParser and the program template

  :param program_class:  ProgramTemplate type (required)
  :param custom_process_arguments:
                         Custom function to parse unknown arguments (optional)
  :param args:           list of command-line arguments (optional)
  :param logger:         logger (e.g. multi_out) for output (optional)
  :rtype:                whatever is returned from program_class.get_results()
  '''

    assert (program_class is not None)

    if (args is None):
        args = sys.argv[1:]

    # create logger
    if (logger is None):
        logger = multi_out()
        logger.register('stdout', sys.stdout)

    # start timer
    t = show_times(out=logger)

    # create parser
    parser = MolProbityParser(
        program_class=program_class,
        custom_process_arguments=custom_process_arguments,
        logger=logger)
    namespace = parser.parse_args(args)

    # start program
    print('Starting job', file=logger)
    print('=' * 79, file=logger)
    task = program_class(parser.data_manager,
                         parser.working_phil.extract(),
                         master_phil=parser.master_phil,
                         logger=logger)

    # custom constructor (optional)
    task.custom_init()

    # validate inputs
    task.validate()

    # run program
    task.run()

    # clean up (optional)
    task.clean_up()

    # output JSON file for PDB
    if (namespace.write_pdb_json):
        filename, ext = os.path.splitext(
            os.path.basename(parser.data_manager.get_default_model_name()))
        filename += '_pdb.json'
        json_text = task.get_results_as_PDB_JSON()
        print('\nJSON output')
        print('-' * 79, file=logger)
        print('  Writing results in JSON format to %s.' % filename,
              file=logger)
        parser.data_manager._write_text(None,
                                        filename,
                                        json_text,
                                        overwrite=namespace.overwrite)

    # stop timer
    print('', file=logger)
    print('=' * 79, file=logger)
    print('Job complete', file=logger)
    t()

    return task.get_results()
コード例 #7
0
def run_program(program_class=None,
                parser_class=CCTBXParser,
                custom_process_arguments=None,
                unused_phil_raises_sorry=True,
                args=None,
                json=False,
                logger=None):
    '''
  Function for running programs using CCTBXParser and the program template

  Parameters
  ----------
  program_class: ProgramTemplate
    The class defining the program. It must be a subclass of ProgramTemplate
  parser_class: CCTBXParser
    The parser class to use for parsing. It must be the CCTBXParser or a subclass
  custom_process_arguments: function(parser)
    Custom function to parse unknown arguments (optional)
  unused_phil_raises_sorry: bool
    If False, any unused PHIL parameters are kept for parsing later
  args: list
    List of command-line arguments (optional)
  json: bool
    If True, get_results_as_JSON is called for the return value instead of get_results
  logger: multi_out
    For logging output (optional)

  Returns
  -------
    Whatever is returned from program_class.get_results() or program_class.get_results_as_JSON()
  '''

    assert program_class is not None

    if args is None:
        args = sys.argv[1:]

    # start profiling
    pr = None
    if '--profile' in args:
        import cProfile
        pr = cProfile.Profile()
        pr.enable()

    # keep output in quiet mode
    if '--quiet' in args:
        logger = multi_out()
        logger.register('parser_log', StringIO())

    # create logger
    if logger is None:
        logger = multi_out()
        logger.register('stdout', sys.stdout)
        logger.register('parser_log', StringIO())

    # start timer
    t = show_times(out=logger)

    # create parser
    parser = parser_class(program_class=program_class,
                          custom_process_arguments=custom_process_arguments,
                          unused_phil_raises_sorry=unused_phil_raises_sorry,
                          logger=logger)
    namespace = parser.parse_args(args)

    # start program
    if namespace.dry_run:
        print('Starting dry run', file=logger)
    else:
        print('Starting job', file=logger)
    print('=' * 79, file=logger)
    task = program_class(parser.data_manager,
                         parser.working_phil.extract(),
                         master_phil=parser.master_phil,
                         logger=logger)

    # validate inputs
    task.validate()

    # stop if dry_run is set
    if namespace.dry_run:
        print('\nArguments have been validated by the program.\n', file=logger)
        print('=' * 79, file=logger)
        return

    # run program
    task.run()

    # clean up (optional)
    task.clean_up()

    # dump profiling stats
    if pr is not None:
        pr.disable()
        pr.dump_stats('profile.out')

    # output JSON
    if namespace.json:
        result = task.get_results_as_JSON()
        if result is not None:
            with open(parser.json_filename, 'w') as f:
                f.write(result)
        else:
            print('', file=logger)
            print('!' * 79, file=logger)
            print(
                'WARNING: The get_results_as_JSON function has not been defined for this program'
            )
            print('!' * 79, file=logger)

    # stop timer
    print('', file=logger)
    print('=' * 79, file=logger)
    print('Job complete', file=logger)
    t()

    # clean up file for quiet mode
    if namespace.quiet:
        logger.close()

    if json:
        result = task.get_results_as_JSON()
    else:
        result = task.get_results()

    return result