本文整理汇总了Python中dials.util.options.OptionParser类的典型用法代码示例。如果您正苦于以下问题:Python OptionParser类的具体用法?Python OptionParser怎么用?Python OptionParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OptionParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(args):
from dials.util.options import OptionParser
import libtbx.load_env
usage = "%s [options] find_spots.json" %(
libtbx.env.dispatcher_name)
parser = OptionParser(
usage=usage,
phil=phil_scope,
epilog=help_message)
filenames = [arg for arg in args if os.path.isfile(arg)]
args = [arg for arg in args if not arg in filenames]
params, options, args = parser.parse_args(
show_diff_phil=True, return_unhandled=True)
if params.nproc is libtbx.Auto:
from libtbx.introspection import number_of_processors
params.nproc = number_of_processors(return_value_if_unknown=-1)
print 'nproc: %i' %params.nproc
results = work_all(filenames, args, nproc=params.nproc)
print results
if params.json is not None:
import json
with open(params.json, 'wb') as f:
json.dump(results, f)
示例2: test_function2
def test_function2():
from dials.util.options import OptionParser
from time import time
from omptbx import omp_get_max_threads
args = [
"/media/upc86896/Betelgeuse/Data/xia2_test_data/i19_sucrose/processed/dataset1/experiments.json",
"/media/upc86896/Betelgeuse/Data/xia2_test_data/i19_sucrose/processed/dataset1/shoeboxes_0.pickle",
]
parser = OptionParser(read_experiments=True, read_reflections=True)
params, options = parser.parse_args(args=args)
experiment = params.input.experiments[0].data[0]
reflections = params.input.reflections[0].data
print "N Threads: ", omp_get_max_threads()
print "N Refl: ", len(reflections)
from dials.algorithms.integration.fitrs import test_function
st = time()
test_function(
experiment.beam, experiment.detector, experiment.goniometer, experiment.scan, 0.071016, 0.390601, 5, reflections
)
print "Time: ", time() - st
示例3: run
def run(args):
from dials.util.options import OptionParser
from dials.util.options import flatten_datablocks
import libtbx.load_env
usage = "%s [options] image_*.cbf" % (
libtbx.env.dispatcher_name)
parser = OptionParser(
usage=usage,
phil=phil_scope,
read_datablocks=True,
read_datablocks_from_images=True,
epilog=help_message)
params, options = parser.parse_args(show_diff_phil=True)
datablocks = flatten_datablocks(params.input.datablock)
if len(datablocks) == 0 and len(experiments) == 0 and len(reflections) == 0:
parser.print_help()
exit()
assert(len(datablocks) == 1)
datablock = datablocks[0]
imagesets = datablock.extract_imagesets()
assert(len(imagesets) == 1)
imageset = imagesets[0]
images = imageset.indices()
if params.frames:
images = params.frames
d_spacings = []
intensities = []
sigmas = []
for indx in images:
print 'For frame %d:' % indx
d, I, sig = background(imageset, indx, n_bins=params.n_bins)
print '%8s %8s %8s' % ('d', 'I', 'sig')
for j in range(len(I)):
print '%8.3f %8.3f %8.3f' % (d[j], I[j], sig[j])
d_spacings.append(d)
intensities.append(I)
sigmas.append(sig)
if params.plot:
from matplotlib import pyplot
fig = pyplot.figure()
for d, I, sig in zip(d_spacings, intensities, sigmas):
ds2 = 1/flex.pow2(d)
pyplot.plot(ds2, I)
pyplot.show()
示例4: run
def run(args):
from dials.util.options import OptionParser
from dials.util.options import flatten_experiments
from dials.util.options import flatten_reflections
import libtbx.load_env
usage = "%s [options] integrated.pickle experiments.json" % (
libtbx.env.dispatcher_name)
parser = OptionParser(
usage=usage,
phil=phil_scope,
read_experiments=True,
read_reflections=True,
check_format=False,
epilog=help_message)
params, options = parser.parse_args(show_diff_phil=False)
experiments = flatten_experiments(params.input.experiments)
reflections = flatten_reflections(params.input.reflections)
if len(experiments) != 1 or len(reflections) != 1:
parser.print_help()
exit()
if not 'shoebox' in reflections[0]:
print 'Please add shoeboxes to reflection pickle'
exit()
results = main(reflections[0], experiments[0], params)
if results:
print 'mean result: %.3f' % (sum(results) / len(results))
示例5: Script
class Script(object):
''' The debugging visualization program. '''
def __init__(self):
'''Initialise the script.'''
from dials.util.options import OptionParser
import libtbx.load_env
# The script usage
usage = "usage: %s [options] experiment.json" \
% libtbx.env.dispatcher_name
# Create the parser
self.parser = OptionParser(
usage=usage,
epilog=help_message,
read_reflections=True)
def run(self):
from dials.util.options import flatten_reflections
from dials.viewer.viewer_interface import extract_n_show
# Parse the command line
params, options = self.parser.parse_args(show_diff_phil=True)
table = flatten_reflections(params.input.reflections)
if len(table) == 0:
self.parser.print_help()
return
extract_n_show(table[0])
示例6: run
def run(args):
import libtbx.load_env
usage = "%s [options]" %libtbx.env.dispatcher_name
parser = OptionParser(
usage=usage,
phil=phil_scope,
check_format=False,
epilog=help_message)
params, options, args = parser.parse_args(
show_diff_phil=True, return_unhandled=True)
results = []
for mtz in args:
print mtz
assert os.path.isfile(mtz), mtz
results.append(get_merging_stats(
mtz, anomalous=params.anomalous,
n_bins=params.n_bins,
use_internal_variance=params.use_internal_variance,
eliminate_sys_absent=params.eliminate_sys_absent))
plot_merging_stats(results, labels=params.labels,
size_inches=params.size_inches,
image_dir=params.image_dir)
示例7: main
def main():
from dials.util.options import OptionParser
from dials.util.options import flatten_datablocks
import libtbx.load_env
usage = "%s [options] image_*.cbf" % (
libtbx.env.dispatcher_name)
parser = OptionParser(
usage=usage,
phil=phil_scope,
read_datablocks=True,
read_datablocks_from_images=True,
epilog=help_message)
params, options = parser.parse_args(show_diff_phil=True)
datablocks = flatten_datablocks(params.input.datablock)
if len(datablocks) == 0:
parser.print_help()
exit()
datablock = datablocks[0]
imageset = datablock.extract_imagesets()[0]
stability_fft(imageset, params)
示例8: run
def run(args):
import libtbx.load_env
usage = "%s [options] experiment.json indexed.pickle" % libtbx.env.dispatcher_name
parser = OptionParser(
usage=usage,
phil=phil_scope,
read_reflections=True,
read_experiments=True,
check_format=False,
epilog=help_message,
)
params, options = parser.parse_args(show_diff_phil=True)
reflections = flatten_reflections(params.input.reflections)
experiments = flatten_experiments(params.input.experiments)
if len(reflections) == 0 or len(experiments) == 0:
parser.print_help()
return
assert len(reflections) == 1
assert len(experiments) == 1
experiment = experiments[0]
reflections = reflections[0]
test_P1_crystal_indexing(reflections, experiment, params)
test_crystal_pointgroup_symmetry(reflections, experiment, params)
示例9: read_experiment_file
def read_experiment_file(self, experiment_file):
### open DIALS json file
phil_scope_str='''
experiments = 'example_refined_experiments.json'
'''
phil_scope = parse(phil_scope_str, process_includes=True)
parser = OptionParser(
phil=phil_scope,
check_format=False,
read_experiments=True)
params, options = parser.parse_args(args=[experiment_file], show_diff_phil=True)
experiments = flatten_experiments(params.input.experiments)
exp_xtal = experiments.crystals()[0]
### define useful attributes
self.crystal = exp_xtal
uc = self.crystal.get_unit_cell()
uc_nospace = str(uc).replace(" ", "")
uc_nospace_noparen = uc_nospace[1:-1]
self.unit_cell = uc_nospace_noparen
self.space_group = self.crystal.get_space_group()
self.laue_group = self.space_group.laue_group_type()
# self.a_matrix = crystal.get_A()
self.experiments = experiments
示例10: run
def run(args):
from dials.util.options import OptionParser
from dials.util.options import flatten_datablocks
parser = OptionParser(
read_datablocks=True,
read_datablocks_from_images=True,
phil=phil_scope,
check_format=True)
params, options = parser.parse_args(show_diff_phil=True)
datablocks = flatten_datablocks(params.input.datablock)
assert len(datablocks) == 1
imagesets = datablocks[0].extract_imagesets()
img_count = 0
import time
t0 = time.time()
for imgset in imagesets:
for i in range(len(imgset)):
if params.data == 'raw':
imgset.get_raw_data(i)
else:
imgset.get_corrected_data(i)
img_count += 1
print "Read %i images" %img_count
t1 = time.time()
t = t1 - t0
print "Read %i images in %.2fs (%.1f images/s)" %(
img_count, t, img_count/t)
return
示例11: run
def run(args):
import libtbx.load_env
from dials.util.options import OptionParser
from dials.util.options import flatten_reflections
from libtbx.utils import Sorry
from libtbx.phil import parse
phil_scope = parse(
"""
hklout = hklout.pickle
.type = str
.help = "The output pickle file"
"""
)
usage = "%s integrated.pickle [hklout=hklout.pickle]" % (libtbx.env.dispatcher_name)
parser = OptionParser(usage=usage, read_reflections=True, check_format=False, phil=phil_scope)
params, options = parser.parse_args(show_diff_phil=True)
reflections = flatten_reflections(params.input.reflections)
if len(reflections) != 1:
raise Sorry("exactly 1 reflection table must be specified")
integrated_data = reflections[0]
filter_good_reflections(integrated_data).as_pickle(params.hklout)
示例12: run
def run(args):
from dials.util.options import OptionParser
from dials.util.options import flatten_experiments
from libtbx.utils import Sorry
import libtbx.load_env
usage = "%s [options] experiments.json" %libtbx.env.dispatcher_name
parser = OptionParser(
usage=usage,
phil=phil_scope,
read_experiments=True,
check_format=False,
epilog=help_message)
params, options = parser.parse_args(show_diff_phil=True)
experiments = flatten_experiments(params.input.experiments)
if len(experiments) <= 1:
parser.print_help()
return
hkl = flex.miller_index(params.hkl)
from dials.algorithms.indexing.compare_orientation_matrices import \
show_rotation_matrix_differences
show_rotation_matrix_differences(experiments.crystals(),
miller_indices=hkl)
示例13: Script
class Script(object):
''' The integration program. '''
def __init__(self):
'''Initialise the script.'''
from dials.util.options import OptionParser
import libtbx.load_env
# The script usage
usage = "usage: %s [options] experiment.json" % libtbx.env.dispatcher_name
# Create the parser
self.parser = OptionParser(
usage=usage,
phil=phil_scope,
epilog=help_message,
read_experiments=True)
def run(self):
''' Analyse the background '''
from dials.util.command_line import heading
from dials.util.options import flatten_experiments
from dials.util import log
from logging import info, debug
from time import time
from libtbx.utils import Sorry
# Parse the command line
params, options = self.parser.parse_args(show_diff_phil=False)
experiments = flatten_experiments(params.input.experiments)
if len(experiments) == 0:
self.parser.print_help()
return
assert len(experiments) == 1
# Get the imageset
imageset = experiments[0].imageset
total_image = None
total_mask = None
for i in range(len(imageset)):
print i
image = imageset.get_raw_data(i)
mask = imageset.get_mask(i)
if total_image is None:
total_image = image[0]
total_mask = mask[0]
else:
total_image += image[0]
total_image /= len(imageset)
print min(total_image)
print max(total_image)
print sum(total_image) / len(total_image)
from matplotlib import pylab
pylab.imshow(total_image.as_numpy_array(), vmin=0,vmax=2)
pylab.show()
示例14: run
def run(args):
import libtbx.load_env
from libtbx.utils import Sorry
from dials.util import log
usage = "%s [options] datablock.json strong.pickle" %libtbx.env.dispatcher_name
parser = OptionParser(
usage=usage,
phil=phil_scope,
read_datablocks=True,
read_reflections=True,
check_format=False,
epilog=help_message)
params, options = parser.parse_args(show_diff_phil=False)
datablocks = flatten_datablocks(params.input.datablock)
reflections = flatten_reflections(params.input.reflections)
if len(datablocks) == 0 or len(reflections) == 0:
parser.print_help()
exit(0)
# Configure the logging
log.config(
info=params.output.log,
debug=params.output.debug_log)
# Log the diff phil
diff_phil = parser.diff_phil.as_str()
if diff_phil is not '':
info('The following parameters have been modified:\n')
info(diff_phil)
imagesets = []
for datablock in datablocks:
imagesets.extend(datablock.extract_imagesets())
assert len(imagesets) > 0
assert len(reflections) == len(imagesets)
if params.scan_range is not None and len(params.scan_range) > 0:
reflections = [
filter_reflections_by_scan_range(refl, params.scan_range)
for refl in reflections]
dps_params = dps_phil_scope.extract()
# for development, we want an exhaustive plot of beam probability map:
dps_params.indexing.plot_search_scope = params.plot_search_scope
dps_params.indexing.mm_search_scope = params.mm_search_scope
new_detector, new_beam = discover_better_experimental_model(
imagesets, reflections, params, dps_params, nproc=params.nproc,
wide_search_binning=params.wide_search_binning)
for imageset in imagesets:
imageset.set_detector(new_detector)
imageset.set_beam(new_beam)
from dxtbx.serialize import dump
dump.datablock(datablock, params.output.datablock)
示例15: run
def run(args):
from dials.util import log
import libtbx.load_env
usage = "%s experiments.json indexed.pickle [options]" %libtbx.env.dispatcher_name
from dials.util.options import OptionParser
from dials.util.options import flatten_reflections
from dials.util.options import flatten_experiments
from dials.array_family import flex
parser = OptionParser(
usage=usage,
phil=phil_scope,
read_experiments=True,
read_reflections=True,
check_format=False,
epilog=help_message)
params, options = parser.parse_args(show_diff_phil=False)
# Configure the logging
#log.config(info=params.output.log, debug=params.output.debug_log)
from dials.util.version import dials_version
logger.info(dials_version())
# Log the diff phil
diff_phil = parser.diff_phil.as_str()
if diff_phil is not '':
logger.info('The following parameters have been modified:\n')
logger.info(diff_phil)
experiments = flatten_experiments(params.input.experiments)
reflections = flatten_reflections(params.input.reflections)
assert(len(reflections) == 1)
reflections = reflections[0]
if len(experiments) == 0:
parser.print_help()
return
#from dials.command_line import refine
#params = refine.phil_scope.extract()
indexed_reflections = reflections.select(reflections['id'] > -1)
from dials.algorithms.refinement import RefinerFactory
refiner = RefinerFactory.from_parameters_data_experiments(
params, indexed_reflections, experiments)
#refiner.run()
rmsds = refiner.rmsds()
import math
xy_rmsds = math.sqrt(rmsds[0]**2 + rmsds[1]**2)
print rmsds
return