rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
space_group, assume_incomming_is_in_reference_setting=False):
space_group):
def __init__(self, unit_cell, space_group, assume_incomming_is_in_reference_setting=False): from cctbx import crystal
if not assume_incomming_is_in_reference_setting: tmp = self.sg_info.change_of_basis_op_to_reference_setting() self.xs = self.xs.change_basis( tmp ) self.unit_cell = self.xs.unit_cell() self.sg_info.change_basis( tmp ) self.hall_symbol = self.sg_info.type().hall_symbol() self.best_cb_op = self.best_cb_op*tmp
tmp = self.sg_info.change_of_basis_op_to_reference_setting() self.xs = self.xs.change_basis( tmp ) self.unit_cell = self.xs.unit_cell() self.sg_info=self.sg_info.change_basis( tmp ) self.best_cb_op = self.best_cb_op*tmp
def __init__(self, unit_cell, space_group, assume_incomming_is_in_reference_setting=False): from cctbx import crystal
return r"""\ @echo off
return r"""@echo off
def create_script(bundle, top_modules): py_major, py_minor = sys.version_info[:2] return r"""\
if (not gradients_should_be_zero):
if (gradients_should_be_zero):
def compare_analytical_and_finite( f_obs, xray_structure, gradients_should_be_zero, eps, out): grads_fin = d_target_d_params_finite( d_order=1, f_obs=f_obs, xray_structure=xray_structure) print >> out, "grads_fin:", list(grads_fin) sf = structure_factors( xray_structure=xray_structure, miller_set=f_obs) grads_ana = sf....
def run_lbfgs(target_evaluator, max_calls=100, traditional_convergence_test=0):
def run_lbfgs(target_evaluator, min_iterations=10, max_calls=100, traditional_convergence_test=0):
def run_lbfgs(target_evaluator, max_calls=100, traditional_convergence_test=0): minimizer = lbfgs.minimizer(target_evaluator.n) if (traditional_convergence_test): is_converged = lbfgs.traditional_convergence_test(target_evaluator.n) else: is_converged = lbfgs.drop_convergence_test() try: while 1: x, f, g = target_evalu...
is_converged = lbfgs.drop_convergence_test()
is_converged = lbfgs.drop_convergence_test(min_iterations)
def run_lbfgs(target_evaluator, max_calls=100, traditional_convergence_test=0): minimizer = lbfgs.minimizer(target_evaluator.n) if (traditional_convergence_test): is_converged = lbfgs.traditional_convergence_test(target_evaluator.n) else: is_converged = lbfgs.drop_convergence_test() try: while 1: x, f, g = target_evalu...
if (is_converged(x, g)): break
if (minimizer.iter() >= min_iterations and is_converged(x, g)): break
def run_lbfgs(target_evaluator, max_calls=100, traditional_convergence_test=0): minimizer = lbfgs.minimizer(target_evaluator.n) if (traditional_convergence_test): is_converged = lbfgs.traditional_convergence_test(target_evaluator.n) else: is_converged = lbfgs.drop_convergence_test() try: while 1: x, f, g = target_evalu...
def __init__(self, miller_indices, multiplicities,
def __init__(self, unit_cell, miller_indices, multiplicities,
def __init__(self, miller_indices, multiplicities, data_reference, data_scaled, k_initial, u_initial): python_utils.adopt_init_args(self, locals()) if (hasattr(self.u_initial, "__len__")): self.anisotropic = 1 self.n = 7 else: self.n = 2 self.x = self.pack(self.k_initial, self.u_initial) self.minimizer = run_lbfgs(self...
k_initial, u_initial):
k_initial, u_initial, refine_k, refine_u, min_iterations=50, max_calls=1000):
def __init__(self, miller_indices, multiplicities, data_reference, data_scaled, k_initial, u_initial): python_utils.adopt_init_args(self, locals()) if (hasattr(self.u_initial, "__len__")): self.anisotropic = 1 self.n = 7 else: self.n = 2 self.x = self.pack(self.k_initial, self.u_initial) self.minimizer = run_lbfgs(self...
if (hasattr(self.u_initial, "__len__")): self.anisotropic = 1 self.n = 7
self.anisotropic = hasattr(self.u_initial, "__len__") self.k_min = 1 self.u_scale = unit_cell.getLongestVector2() if (self.anisotropic): self.u_min = [u * self.u_scale for u in self.u_initial]
def __init__(self, miller_indices, multiplicities, data_reference, data_scaled, k_initial, u_initial): python_utils.adopt_init_args(self, locals()) if (hasattr(self.u_initial, "__len__")): self.anisotropic = 1 self.n = 7 else: self.n = 2 self.x = self.pack(self.k_initial, self.u_initial) self.minimizer = run_lbfgs(self...
self.n = 2 self.x = self.pack(self.k_initial, self.u_initial) self.minimizer = run_lbfgs(self)
self.u_min = self.u_initial * self.u_scale self.x = self.pack(self.k_min, self.u_min) self.n = self.x.size() self.minimizer = run_lbfgs(self, min_iterations, max_calls)
def __init__(self, miller_indices, multiplicities, data_reference, data_scaled, k_initial, u_initial): python_utils.adopt_init_args(self, locals()) if (hasattr(self.u_initial, "__len__")): self.anisotropic = 1 self.n = 7 else: self.n = 2 self.x = self.pack(self.k_initial, self.u_initial) self.minimizer = run_lbfgs(self...
if (self.anisotropic): return shared.double((k,) + tuple(u)) else: return shared.double((k, u))
v = [] if (self.refine_k): v.append(k) if (self.refine_u): if (self.anisotropic): v += list(u) else: v.append(u) return shared.double(tuple(v))
def pack(self, k, u): if (self.anisotropic): return shared.double((k,) + tuple(u)) else: return shared.double((k, u))
self.k_min = self.x[0] if (self.anisotropic): self.u_min = self.x.as_tuple()[1:] else: self.u_min = self.x[1]
i = 0 if (self.refine_k): self.k_min = self.x[i] i += 1 if (self.refine_u): if (self.anisotropic): self.u_min = self.x.as_tuple()[i:] else: self.u_min = self.x[i]
def unpack_x(self): self.k_min = self.x[0] if (self.anisotropic): self.u_min = self.x.as_tuple()[1:] else: self.u_min = self.x[1]
self.k_min, self.u_min, 1)
self.k_initial * self.k_min, self.u_min, self.u_scale, self.refine_k, self.refine_u)
def __call__(self): self.unpack_x() tg = mintbx.k_b_scaling_target_and_gradients( self.miller_indices, self.multiplicities, self.data_reference, self.data_scaled, self.k_min, self.u_min, 1) self.f = tg.target() if (self.anisotropic): self.g = self.pack(tg.gradient_k(), tg.gradients_u_star()) else: raise AssertionError,...
k_sim = 1 u_star = [0,0,0,0,0,0]
k_sim = 1000 u_star = [0.001,0.002,0.003,0.004,0.005,0.006]
def exercise(SgInfo, d_min=2., verbose=0): elements = ("N", "C", "C", "O", "N", "C", "C", "O") friedel_flag = 0 xtal = debug_utils.random_structure( SgInfo, elements, volume_per_atom=50., min_distance=1.5, general_positions_only=0) print "Unit cell:", xtal.UnitCell print "Space group:", xtal.SgInfo.BuildLookupSymbol() ...
minimized = k_b_scaling_minimizer( miller_set.H, multiplicity_set.F, f_ref.F, f_sca.F, k_initial=1+1.e-4, u_initial=[0,0,0,0,0,0])
k_min = 1 u_min = [0,0,0,0,0,0] for p in xrange(20): for refine_k, refine_u in ((1,0), (0,1), (1,0), (0,1), (1,0), (1,1)): minimized = k_b_scaling_minimizer( xtal.UnitCell, miller_set.H, multiplicity_set.F, f_ref.F, f_sca.F, k_min, u_min, refine_k, refine_u) k_min = minimized.k_min u_min = minimized.u_min
def exercise(SgInfo, d_min=2., verbose=0): elements = ("N", "C", "C", "O", "N", "C", "C", "O") friedel_flag = 0 xtal = debug_utils.random_structure( SgInfo, elements, volume_per_atom=50., min_distance=1.5, general_positions_only=0) print "Unit cell:", xtal.UnitCell print "Space group:", xtal.SgInfo.BuildLookupSymbol() ...
print "after %d iterations" % (minimized.minimizer.iter(),)
print "after %d iteration(s)" % (minimized.minimizer.iter(),) print
def exercise(SgInfo, d_min=2., verbose=0): elements = ("N", "C", "C", "O", "N", "C", "C", "O") friedel_flag = 0 xtal = debug_utils.random_structure( SgInfo, elements, volume_per_atom=50., min_distance=1.5, general_positions_only=0) print "Unit cell:", xtal.UnitCell print "Space group:", xtal.SgInfo.BuildLookupSymbol() ...
self.effective_root = norm(open(self.dist_path).readlines()[0][:-1])
self.effective_root = norm( abspath(open(self.dist_path).readlines()[0][:-1]))
def __init__(self, dist_root, name, must_exist=1): self.dist_root = dist_root self.effective_root = dist_root self.name = name self.dist_path = norm(join(self.effective_root, name)) if (isfile(self.dist_path)): try: self.effective_root = norm(open(self.dist_path).readlines()[0][:-1]) assert len(self.effective_root) > 0...
self.effective_root = norm(join(self.dist_root, self.effective_root))
self.effective_root = norm( abspath(join(self.dist_root, self.effective_root)))
def __init__(self, dist_root, name, must_exist=1): self.dist_root = dist_root self.effective_root = dist_root self.name = name self.dist_path = norm(join(self.effective_root, name)) if (isfile(self.dist_path)): try: self.effective_root = norm(open(self.dist_path).readlines()[0][:-1]) assert len(self.effective_root) > 0...
assert rt.make_boost_int_2() == (7, 2)
def exercise_to_tuple(verbose=0): if (verbose): print 'Checking to_tuple conversions' if (not hasattr(rt, "make_boost_int_2")): # XXX if (verbose): print 'SKIPPED' return assert rt.make_boost_int_2(3, 5) == (3, 5) assert rt.make_boost_int_2(3) == (3, 2) #assert rt.make_boost_int_2() == (7, 2) XXX currently not supporte...
print >> f, 'if [ ! -n "$%s" ]; then' % v print >> f, ' %s="$LIBTBX0%s"' % (v, v) print >> f, ' export %s' % v print >> f, 'elif [ "$%s" != "$LIBTBX0%s" ]; then' % (v, v) print >> f, ' x=`echo "$%s" | grep libtbx`' % v print >> f, ' if [ ! -n "$x" ]; then' print >> f, ' %s="$LIBTBX0%s:$%s"' % (v, v, v)
print >> f, 'if [ -n "$LIBTBX0%s" ]; then' % v print >> f, ' if [ ! -n "$%s" ]; then' % v print >> f, ' %s="$LIBTBX0%s"' % (v, v)
def __call__(self, source_file, target_file): f = open(target_file, "w") print >> f, '#! /bin/sh' print >> f, '# LIBTBX_DISPATCHER DO NOT EDIT' print >> f, 'unset PYTHONHOME' essentials = ["PYTHONPATH"] if (sys.platform.startswith("darwin")): essentials.append("DYLD_LIBRARY_PATH") else: essentials.append("LD_LIBRARY_PA...
print >> "Cannot find SCons (Software Construction Tool)"
print >> sys.stderr, "Cannot find SCons (Software Construction Tool)"
def emit_SConstruct(env, libtbx_info): if (env.libtbx_scons == None): if (not os.path.isdir("libtbx")): print >> sys.stderr, "Warning:", print >> "Cannot find SCons (Software Construction Tool)" print >> sys.stderr, " For more information please refer to:" print >> sys.stderr, " XXX" return SConstruct_p...
if self.twin_results.patterson_p_value >= self.patterson_p_cut:
if self.twin_results.patterson_p_value <= self.patterson_p_cut:
def analyse_intensity_stats(self): if self.twin_results.maha_l >= self.maha_l_cut: if self.twin_results.l_mean < 0.5 : print >> self.twinning_verdict, \ "The results of the L-test indicate that the intensity statistics" print >> self.twinning_verdict, \ "are significantly different then is expected from good to reasona...
print "Error: At least one package must be specified." return
raise UserError("At least one package must be specified.")
def run(libtbx_dist, args): env = libtbx_env(os.getcwd(), libtbx_dist) packages = registry() build_mode = "release" remaining_args = [] for arg in args: if (arg.startswith("--build=")): build_mode = arg.split("=", 1)[1] assert build_mode in ("quick", "release", "debug") elif (arg.startswith("--")): raise UserError("Unk...
assert not g.has_origin()
assert g.is_0_based()
def exercise_flex_grid(): g = flex.grid() assert g.nd() == 0 assert g.size_1d() == 0 assert not g.has_origin() assert g.origin() == () assert g.all() == () assert g.last() == () assert g.last(1) == () assert g.last(0) == () assert g.is_0_based() assert not g.is_padded() assert not g.is_trivial_1d() g = flex.grid((2,3,5...
assert g.is_0_based()
def exercise_flex_grid(): g = flex.grid() assert g.nd() == 0 assert g.size_1d() == 0 assert not g.has_origin() assert g.origin() == () assert g.all() == () assert g.last() == () assert g.last(1) == () assert g.last(0) == () assert g.is_0_based() assert not g.is_padded() assert not g.is_trivial_1d() g = flex.grid((2,3,5...
assert flex.grid().set_focus(1).focus() == (1,) assert flex.grid().set_focus(1,2).focus() == (1,2,) assert flex.grid().set_focus(1,2,3).focus() == (1,2,3) assert flex.grid().set_focus(1,2,3,4).focus() == (1,2,3,4) assert flex.grid().set_focus(1,2,3,4,5).focus() == (1,2,3,4,5) assert flex.grid().set_focus(1,2,3,4,5,6).f...
assert flex.grid(1).set_focus(1).focus() == (1,) assert flex.grid(1,2).set_focus(1,2).focus() == (1,2,) assert flex.grid(1,2,3).set_focus(1,2,3).focus() == (1,2,3) assert flex.grid(1,2,3,4).set_focus(1,2,3,4).focus() == (1,2,3,4) assert flex.grid(1,2,3,4,5).set_focus(1,2,3,4,5).focus() == (1,2,3,4,5) assert flex.grid(1...
def exercise_flex_grid(): g = flex.grid() assert g.nd() == 0 assert g.size_1d() == 0 assert not g.has_origin() assert g.origin() == () assert g.all() == () assert g.last() == () assert g.last(1) == () assert g.last(0) == () assert g.is_0_based() assert not g.is_padded() assert not g.is_trivial_1d() g = flex.grid((2,3,5...
assert g.has_origin()
assert not g.is_0_based()
def exercise_flex_grid(): g = flex.grid() assert g.nd() == 0 assert g.size_1d() == 0 assert not g.has_origin() assert g.origin() == () assert g.all() == () assert g.last() == () assert g.last(1) == () assert g.last(0) == () assert g.is_0_based() assert not g.is_padded() assert not g.is_trivial_1d() g = flex.grid((2,3,5...
assert not g.is_0_based()
def exercise_flex_grid(): g = flex.grid() assert g.nd() == 0 assert g.size_1d() == 0 assert not g.has_origin() assert g.origin() == () assert g.all() == () assert g.last() == () assert g.last(1) == () assert g.last(0) == () assert g.is_0_based() assert not g.is_padded() assert not g.is_trivial_1d() g = flex.grid((2,3,5...
assert not g.has_focus()
def exercise_flex_grid(): g = flex.grid() assert g.nd() == 0 assert g.size_1d() == 0 assert not g.has_origin() assert g.origin() == () assert g.all() == () assert g.last() == () assert g.last(1) == () assert g.last(0) == () assert g.is_0_based() assert not g.is_padded() assert not g.is_trivial_1d() g = flex.grid((2,3,5...
assert g.has_focus()
assert g.is_padded()
def exercise_flex_grid(): g = flex.grid() assert g.nd() == 0 assert g.size_1d() == 0 assert not g.has_origin() assert g.origin() == () assert g.all() == () assert g.last() == () assert g.last(1) == () assert g.last(0) == () assert g.is_0_based() assert not g.is_padded() assert not g.is_trivial_1d() g = flex.grid((2,3,5...
assert not f.has_origin()
assert f.is_0_based()
def exercise_flex_constructors(): f = flex.double() assert f.size() == 0 assert f.capacity() == 0 assert f.accessor().nd() == 1 assert tuple(f.accessor().origin()) == (0,) assert tuple(f.accessor().all()) == (0,) assert tuple(f.accessor().last()) == (0,) assert tuple(f.accessor().last(1)) == (0,) assert tuple(f.accesso...
assert not f.has_focus()
assert not f.is_padded()
def exercise_flex_constructors(): f = flex.double() assert f.size() == 0 assert f.capacity() == 0 assert f.accessor().nd() == 1 assert tuple(f.accessor().origin()) == (0,) assert tuple(f.accessor().all()) == (0,) assert tuple(f.accessor().last()) == (0,) assert tuple(f.accessor().last(1)) == (0,) assert tuple(f.accesso...
assert f.is_0_based() assert not f.is_padded()
def exercise_flex_constructors(): f = flex.double() assert f.size() == 0 assert f.capacity() == 0 assert f.accessor().nd() == 1 assert tuple(f.accessor().origin()) == (0,) assert tuple(f.accessor().all()) == (0,) assert tuple(f.accessor().last()) == (0,) assert tuple(f.accessor().last(1)) == (0,) assert tuple(f.accesso...
a = flex.double(flex.grid((-1,2,-3), (7,5,3)).set_focus((3,-5,7)), 13)
a = flex.double(flex.grid((-1,2,-3), (7,5,3)).set_focus((1,3,2)), 13)
def exercise_pickle_single_buffered(): a = flex.bool((1,0,1)) p = pickle.dumps(a) b = pickle.loads(p) assert b.size() == 3 assert tuple(b) == (1,0,1) a = flex.double(()) p = pickle.dumps(a) b = pickle.loads(p) assert b.size() == 0 a = flex.double((1,2,3)) p = pickle.dumps(a) b = pickle.loads(p) assert b.size() == 3 ass...
""")) assert list(pdb_inp.model_indices()) == [5,10,15]
MODEL 4 ATOM C ATOM D ATOM C ATOM E X ATOM ...
HETATM12345qN123AR123C1234Ixyz1234.6781234.6781234.678123.56213.56abcdef E1C1
== [[2,3,5],[7,9,10],[11,13,15]]
== [[2,3,5],[7,9,10],[11,13,15], [18,20]]
HETATM12345qN123AR123C1234Ixyz1234.6781234.6781234.678123.56213.56abcdef E1C1
chain_ids={"C": 2, "D": 2, "E": 3, " ": 2}, conformer_ids={" ": 9}, residue_names={" ": 9}, residue_name_classes={"other": 9}))
chain_ids={"C": 2, "D": 2, "E": 4, " ": 3}, conformer_ids={" ": 11}, residue_names={" ": 11}, residue_name_classes={"other": 11}))
HETATM12345qN123AR123C1234Ixyz1234.6781234.6781234.678123.56213.56abcdef E1C1
t = dmtbx.triplet_invariants(
tprs = dmtbx.triplet_invariants(
def exercise(SgInfo, number_of_point_atoms = 10, d_min=1., e_min=1.2, loop_k_equiv=0, use_weights=0, verbose=0): elements = ["const"] * number_of_point_atoms xtal = debug_utils.random_structure( SgInfo, elements, volume_per_atom=50., min_distance=1.5, general_positions_only=0, no_random_u=1) print xtal.UnitCell debug_u...
t.total_number_of_triplets()
tprs.total_number_of_triplets()
def exercise(SgInfo, number_of_point_atoms = 10, d_min=1., e_min=1.2, loop_k_equiv=0, use_weights=0, verbose=0): elements = ["const"] * number_of_point_atoms xtal = debug_utils.random_structure( SgInfo, elements, volume_per_atom=50., min_distance=1.5, general_positions_only=0, no_random_u=1) print xtal.UnitCell debug_u...
t.average_number_of_triplets_per_reflection() new_phases = t.refine_phases(MillerIndices.H, e_values, phases)
tprs.average_number_of_triplets_per_reflection() new_phases = tprs.refine_phases(MillerIndices.H, e_values, phases)
def exercise(SgInfo, number_of_point_atoms = 10, d_min=1., e_min=1.2, loop_k_equiv=0, use_weights=0, verbose=0): elements = ["const"] * number_of_point_atoms xtal = debug_utils.random_structure( SgInfo, elements, volume_per_atom=50., min_distance=1.5, general_positions_only=0, no_random_u=1) print xtal.UnitCell debug_u...
dispatcher_name=os.path.basename(target_file)))
dispatcher_name=os.path.splitext(os.path.basename(target_file))[0]))
def write_win32_dispatcher(self, source_file, target_file): open(target_file, "wb").write( self.windows_dispatcher( command_path=source_file, dispatcher_name=os.path.basename(target_file)))
gradients[i] += term gradients[j] -= term
gradients[i] += term * 2 gradients[j] -= term * 2
def harmonic_restraints(self, variables, type_indices, type_weights): assert self.shell_sym_tables is not None assert len(self.shell_sym_tables) > 0 assert variables.size() == self.shell_sym_tables[0].size() residual_sum = 0 gradients = flex.double(variables.size(), 0) for pair in self.shell_sym_tables[0].iterator(): i...
def example_and_test_fit():
def test_fit():
def example_and_test_fit(): x1_obs=[] x2_obs=[] x1m=1.0 x2m=3.0 a=1 b=2 c=-0.5 y_obs=[] for ii in range(10): for jj in range(10): x1_obs.append(ii-5) x2_obs.append(jj-5) y_obs.append( a*(( (ii-5.0)-x1m )**2.0) + b*(( (jj-5.0)-x2m )**2.0) + 2.0*c*( (ii-5.0)-x1m )*( (jj-5.0)-x2m ) ) fit =fqf.fit_quadratic_function_2d_d...
exercise()
test_fit()
def example_and_test_fit(): x1_obs=[] x2_obs=[] x1m=1.0 x2m=3.0 a=1 b=2 c=-0.5 y_obs=[] for ii in range(10): for jj in range(10): x1_obs.append(ii-5) x2_obs.append(jj-5) y_obs.append( a*(( (ii-5.0)-x1m )**2.0) + b*(( (jj-5.0)-x2m )**2.0) + 2.0*c*( (ii-5.0)-x1m )*( (jj-5.0)-x2m ) ) fit =fqf.fit_quadratic_function_2d_d...
set python=%(bundle)s_build\python\python
cd %(bundle)s_build set python=python\python
def create_script(bundle, top_modules): py_major, py_minor = sys.version_info[:2] return r"""@echo off
cd %(bundle)s_build
def create_script(bundle, top_modules): py_major, py_minor = sys.version_info[:2] return r"""@echo off
self.effective_root = norm( abspath(open(self.dist_path).readlines()[0][:-1])) assert len(self.effective_root) > 0
redirection = open(self.dist_path).readlines()[0][:-1] assert len(redirection) > 0
def __init__(self, dist_root, name, must_exist=1): self.dist_root = dist_root self.effective_root = dist_root self.name = name self.dist_path = norm(join(self.effective_root, name)) if (isfile(self.dist_path)): try: self.effective_root = norm( abspath(open(self.dist_path).readlines()[0][:-1])) assert len(self.effective...
self.effective_root = norm( abspath(join(self.dist_root, self.effective_root)))
self.effective_root = norm(abspath(join(self.dist_root, redirection)))
def __init__(self, dist_root, name, must_exist=1): self.dist_root = dist_root self.effective_root = dist_root self.name = name self.dist_path = norm(join(self.effective_root, name)) if (isfile(self.dist_path)): try: self.effective_root = norm( abspath(open(self.dist_path).readlines()[0][:-1])) assert len(self.effective...
r.title = "Wilson Plot: " + self.info r.xList = list(self.x) r.yList = list(self.y)
r.title = "Wilson Plot" if (self.info != 0): r.title += ": " + str(self.info) r.x = self.x r.y = self.y
def get_xy_plot_info(self): r = empty() r.title = "Wilson Plot: " + self.info r.xList = list(self.x) r.yList = list(self.y) r.xLegend = "(sin(theta)/lambda)^2" r.Legend = "ln(<Fobs^2>/<Fcalc^2>)" r.b = self.fit.b() r.m = self.fit.m() r.cc = self.fit.cc() r.overlayLegend = ("k=%f, b=%f, corr=%f" % ( self.wilson_k, self....
r.Legend = "ln(<Fobs^2>/<Fcalc^2>)"
r.yLegend = "ln(<Fobs^2>/<Fcalc^2>)"
def get_xy_plot_info(self): r = empty() r.title = "Wilson Plot: " + self.info r.xList = list(self.x) r.yList = list(self.y) r.xLegend = "(sin(theta)/lambda)^2" r.Legend = "ln(<Fobs^2>/<Fcalc^2>)" r.b = self.fit.b() r.m = self.fit.m() r.cc = self.fit.cc() r.overlayLegend = ("k=%f, b=%f, corr=%f" % ( self.wilson_k, self....
if (min_fraction_bijvoet_pairs is not None):
if (self.indices().size() == 0): anomalous_flag = False elif (min_fraction_bijvoet_pairs is not None):
def auto_anomalous(self, min_n_bijvoet_pairs=None, min_fraction_bijvoet_pairs=None): assert [min_n_bijvoet_pairs, min_fraction_bijvoet_pairs].count(None) > 0 if (min_fraction_bijvoet_pairs is not None): anomalous_flag = (2*self.n_bijvoet_pairs()/self.indices().size() >= min_fraction_bijvoet_pairs) elif (min_n_bijvoet_p...
self.analyse() self.select_and_transform()
if len(self.nice_cb_ops)>0: self.analyse() self.select_and_transform() else: print >> self.out, "No simple reindexing relation found between unit cells"
def __init__(self, set_a, set_b, out=None, relative_length_tolerance=0.05, absolute_angle_tolerance=3.0, lattice_symmetry_max_delta=3.0, file_name=None):
fa_estimation.combined_scaling(
scaler = fa_estimation.combined_scaling(
def run(args): if len(args)==0: print "no help available" elif ( "--help" in args ): print "no help available" elif ( "--h" in args ): print "no help available" else: log = multi_out() if (not "--quiet" in args): log.register(label="stdout", file_object=sys.stdout) string_buffer = StringIO() string_buffer_plots = Stri...
p = Popen(
p = subprocess.Popen(
def __init__(self, command, stdin_lines=None, join_stdout_stderr=False, bufsize=-1): self.command = command self.join_stdout_stderr = join_stdout_stderr if (not isinstance(command, str)): command = subprocess.list2cmdline(command) if (stdin_lines is not None): if (not isinstance(stdin_lines, str)): stdin_lines = os.lin...
if (subprocess is None): fully_buffered = fully_buffered_simple else: fully_buffered = fully_buffered_subprocess class Popen(subprocess.Popen): if (not subprocess.mswindows): def _communicate(self, input): """Copy of Python 2.5 subprocess.py with patch to fix O(N**2) problem: +++ subprocess.py 2006-11-16 11:57:3...
fully_buffered = fully_buffered_subprocess
def __init__(self, command, stdin_lines=None, join_stdout_stderr=False, bufsize=-1): self.command = command self.join_stdout_stderr = join_stdout_stderr if (not isinstance(command, str)): command = subprocess.list2cmdline(command) if (stdin_lines is not None): if (not isinstance(stdin_lines, str)): stdin_lines = os.lin...
self._weights = self._f_obs.sigmas().data()
sigmas_squared = flex.pow2(self._f_obs.sigmas().data()) assert sigmas_squared.all_gt(0) self._weights = 1 / sigmas_squared
def __init__(self, f_obs, weights=None, use_sigmas_as_weights=00000, scale_factor=0): adopt_init_args(self, locals(), hide=0001) assert self._weights is None or self._use_sigmas_as_weights == 00000 if (self._use_sigmas_as_weights): self._weights = self._f_obs.sigmas().data()
if (label == ""): label = "Site" + str(len(positions)+1)
if (label == ""): label = "Site" + str(len(self.positions)+1)
def __init__(self, ucparams, sgsymbol, convention, format, coor_type, skip_columns, coordinates): self.ucparams = ucparams self.sgsymbol = sgsymbol self.convention = convention if (format == "generic"): skip_columns = int(skip_columns) self.positions = [] for line in coordinates: label, coor = interpret_generic_coordin...
print >> file, iotbx.pdb.format_atom_record(
print >> file, pdb.format_atom_record(
def write_ensemble(self, pdb_inp, out): for index in xrange( len(self.matches) ): name = out+"_%s.pdb"%(index) file = open(name, "w") for ser, lbl, atom in zip( pdb_inp.atom_serial_number_strings(), pdb_inp.input_atom_labels_list(), pdb_inp.atoms() ): r = self.matches[index][1] t = self.matches[index][2] print >> file,...
def exersize_enforce_positive_amplitudes():
def exercise_enforce_positive_amplitudes():
def exersize_enforce_positive_amplitudes(): from cctbx.xray import observation_types xs = crystal.symmetry((3,4,5), "P 2 2 2") mi = flex.miller_index(((1,-2,3), (0,0,-4))) data = flex.double((-1,-2)) sigmas = flex.double((1,2)) ms = miller.set(xs, mi) ma = miller.array(ms) ma = miller.array(ms, data=data, sigmas=sigmas...
exersize_enforce_positive_amplitudes()
exercise_enforce_positive_amplitudes()
def run(args): exercise_set() exercise_generate_r_free_flags(use_lattice_symmetry=False, verbose="--verbose" in args) exercise_generate_r_free_flags(use_lattice_symmetry=True, verbose="--verbose" in args) exersize_enforce_positive_amplitudes() exercise_binner() exercise_array() exercise_crystal_gridding() exercise_fft_...
a, p = xutils.f_as_ampl_phase(f) a = round_scaled(a, 10**precision_ampl) p = round_scaled(p, 10**precision_phase) % 360 if (p <= round_scaled(-180., 10**precision_phase)): p += 360 return ("%%.%dg %%.%df" % (precision_ampl, precision_phase)) % (a, p)
if (type(f) == type(0j)): a, p = xutils.f_as_ampl_phase(f) a = round_scaled(a, 10**precision_ampl) p = round_scaled(p, 10**precision_phase) % 360 if (p <= round_scaled(-180., 10**precision_phase)): p += 360 return ("%%.%dg %%.%df" % (precision_ampl, precision_phase)) % (a, p) else: a = round_scaled(f, 10**precision_amp...
def format_structure_factor(f, precision_ampl=3, precision_phase=0): a, p = xutils.f_as_ampl_phase(f) a = round_scaled(a, 10**precision_ampl) p = round_scaled(p, 10**precision_phase) % 360 if (p <= round_scaled(-180., 10**precision_phase)): p += 360 return ("%%.%dg %%.%df" % (precision_ampl, precision_phase)) % (a, p)
if (type(F) == type(0j)): for i in xrange(len(F.H)): print F.H[i], format_structure_factor( F.F[i], precision_ampl, precision_phase) else: for i in xrange(len(F.H)): print F.H[i], round_scaled(F.F[i], 10**precision_ampl)
for i in xrange(len(F.H)): print F.H[i], format_structure_factor( F.F[i], precision_ampl, precision_phase)
def print_structure_factors(F, precision_ampl=3, precision_phase=0): if (type(F) == type(0j)): for i in xrange(len(F.H)): print F.H[i], format_structure_factor( F.F[i], precision_ampl, precision_phase) else: for i in xrange(len(F.H)): print F.H[i], round_scaled(F.F[i], 10**precision_ampl)
try: f(n=2**32-1,m=2**5)
assert eps_eq(f(n=2**32-1,m=2**5), 6.83193552992e+272) try: f(n=2**32-1,m=2**6)
def exercise_slatec_dbinom(): f = scitbx.math.slatec_dlnrel try: f(-1) except RuntimeError, e: assert str(e) == \ "slatec: dlnrel: x is le -1 (nerr=2, level=2)" else: raise RuntimeError("Exception expected.") assert approx_equal(f(-1+1.e-10), -23.0258508472) assert approx_equal(f(0.374), 0.3177261938) assert approx_equ...
assert str(e) == "slatec: d9lgmc: x must be ge 10 (nerr=1, level=2)"
assert str(e) == \ "slatec: dbinom: result overflows" \ " because n and/or m too big (nerr=3, level=2)"
def exercise_slatec_dbinom(): f = scitbx.math.slatec_dlnrel try: f(-1) except RuntimeError, e: assert str(e) == \ "slatec: dlnrel: x is le -1 (nerr=2, level=2)" else: raise RuntimeError("Exception expected.") assert approx_equal(f(-1+1.e-10), -23.0258508472) assert approx_equal(f(0.374), 0.3177261938) assert approx_equ...
x_after_step = None
x_after_step = x.deep_copy()
def run_c_plus_plus(target_evaluator, termination_params=None, core_params=None, exception_handling_params=None): if (termination_params is None): termination_params = termination_parameters() if (core_params is None): core_params = core_parameters() if (exception_handling_params is None): exception_handling_params = e...
if (x is not None and x_after_step is not None):
if (x is not None):
def run_c_plus_plus(target_evaluator, termination_params=None, core_params=None, exception_handling_params=None): if (termination_params is None): termination_params = termination_parameters() if (core_params is None): core_params = core_parameters() if (exception_handling_params is None): exception_handling_params = e...
return self._peak_list()
return self._peak_list
def peak_list(self): return self._peak_list()
(scale, error, fraction, fmodel.r_work()), k_sol, b_sol
def exercise(d_min = 3.5, k_sol = 0.3, b_sol = 60.0, b_cart = [0,0,0,0,0,0], sf_algorithm = "fft", sf_cos_sin_table = False, anomalous_flag = False, scattering_table = "it1992", space_group_info = None): space_groups = [ str(space_group_info) ] for sg in space_groups: ##...
usage="iotbx.emma [options] reference_coordinates"
usage="iotbx.emma [options]"
def run(args): command_line = (iotbx_option_parser( usage="iotbx.emma [options] reference_coordinates" +" reference_coordinates other_coordinates", description="Example: iotbx.emma model1.pdb model2.sdb") .enable_symmetry_comprehensive() .option(None, "--tolerance", action="store", type="float", dest="tolerance", defau...
d_obs = miller.array(miller_set = self.f_calc,
d_obs = miller.array(miller_set = f_model,
def map_coefficients(self, map_type = "k*Fobs-n*Fmodel", k = 1, n = 1, w1 = None, w2 = None): assert map_type in ("k*Fobs-n*Fmodel", "2m*Fobs-D*Fmodel", "m*Fobs-D*Fmodel", "k*w1*Fobs-n*w2*Fmodel") if(map_type == "k*Fobs-n*Fmodel"): d_obs = miller.ar...
).phase_transfer(phase_source = self.f_calc)
).phase_transfer(phase_source = f_model)
def map_coefficients(self, map_type = "k*Fobs-n*Fmodel", k = 1, n = 1, w1 = None, w2 = None): assert map_type in ("k*Fobs-n*Fmodel", "2m*Fobs-D*Fmodel", "m*Fobs-D*Fmodel", "k*w1*Fobs-n*w2*Fmodel") if(map_type == "k*Fobs-n*Fmodel"): d_obs = miller.ar...
return miller.array(miller_set = self.f_calc,
return miller.array(miller_set = f_model,
def map_coefficients(self, map_type = "k*Fobs-n*Fmodel", k = 1, n = 1, w1 = None, w2 = None): assert map_type in ("k*Fobs-n*Fmodel", "2m*Fobs-D*Fmodel", "m*Fobs-D*Fmodel", "k*w1*Fobs-n*w2*Fmodel") if(map_type == "k*Fobs-n*Fmodel"): d_obs = miller.ar...
).phase_transfer(phase_source = self.f_calc) d_model = self.f_model().data()*alpha.data() return miller.array(miller_set = self.f_calc,
).phase_transfer(phase_source = f_model) d_model = f_model.data()*alpha.data() return miller.array(miller_set = self.f_model(),
def map_coefficients(self, map_type = "k*Fobs-n*Fmodel", k = 1, n = 1, w1 = None, w2 = None): assert map_type in ("k*Fobs-n*Fmodel", "2m*Fobs-D*Fmodel", "m*Fobs-D*Fmodel", "k*w1*Fobs-n*w2*Fmodel") if(map_type == "k*Fobs-n*Fmodel"): d_obs = miller.ar...
).phase_transfer(phase_source = self.f_calc) d_model = self.f_model().data()*alpha.data()
).phase_transfer(phase_source = f_model) d_model = f_model.data()*alpha.data()
def map_coefficients(self, map_type = "k*Fobs-n*Fmodel", k = 1, n = 1, w1 = None, w2 = None): assert map_type in ("k*Fobs-n*Fmodel", "2m*Fobs-D*Fmodel", "m*Fobs-D*Fmodel", "k*w1*Fobs-n*w2*Fmodel") if(map_type == "k*Fobs-n*Fmodel"): d_obs = miller.ar...
tmp = -math.log(self.twin_cap/start_alpha-1.0) self.x = flex.double([tmp])
start_alpha = 0.40 if start_alpha <=0 : start_alpha = 0.05 tmp = -math.log(self.twin_cap/start_alpha-1.0) self.x = flex.double([tmp])
def __init__(self, miller_array, twin_law, out, n_bins=10, calc_data=None, start_alpha=None): if out == None: out = sys.stdout
try: f = open(file_name, mode)
try: return open(file_name, mode)
def _open(file_name, mode): try: f = open(file_name, mode) except IOError, e: raise IOError("Cannot open pickle file %s (%s)" % ( show_string(file_name), str(e)))
minimize_multi_histogram = {None: 0}
minimize_multi_histogram = {"None": 0}
def show_minimize_multi_histogram(f=None, reset=True): global minimize_multi_histogram minimizer_types = minimize_multi_histogram.keys() counts = flex.double(minimize_multi_histogram.values()) perm = flex.sort_permutation(data=counts, reverse=True) minimizer_types = flex.select(minimizer_types, perm) counts = counts.se...
for st in open("ref1_001.pdb","r").read().splitlines():
for st in open("occ_ref1_001.pdb","r").read().splitlines():
def check_result(): for st in open("ref1_001.pdb","r").read().splitlines(): if(st.count("REMARK Final: r_work =")==1): st = st.split() r1 = float(st[4]) for st in open("ref2_001.pdb","r").read().splitlines(): if(st.count("REMARK Final: r_work =")==1): st = st.split() r2 = float(st[4]) os.system("rm -rf occ_ref1* occ_re...
for st in open("ref2_001.pdb","r").read().splitlines():
for st in open("occ_ref2_001.pdb","r").read().splitlines():
def check_result(): for st in open("ref1_001.pdb","r").read().splitlines(): if(st.count("REMARK Final: r_work =")==1): st = st.split() r1 = float(st[4]) for st in open("ref2_001.pdb","r").read().splitlines(): if(st.count("REMARK Final: r_work =")==1): st = st.split() r2 = float(st[4]) os.system("rm -rf occ_ref1* occ_re...
% tuple([i] + list(r) + [r_total] + list(t) + [t_total])
% tuple([i] + r + [r_total] + list(t) + [t_total])
def show_rigid_body_rotations_and_translations( out, prefix, frame, euler_angle_convention, rotations, translations): assert euler_angle_convention in ["xyz", "zyz"] euler_angles_as_matrix = getattr( scitbx.math.euler_angles, euler_angle_convention+"_matrix") print >> out, prefix_each_line_suffix( prefix=prefix+frame, ...
minimize_multi_histogram = {}
minimize_multi_histogram = {None: 0}
def show_minimize_multi_histogram(f=None, reset=True): global minimize_multi_histogram minimizer_types = minimize_multi_histogram.keys() counts = flex.double(minimize_multi_histogram.values()) perm = flex.sort_permutation(data=counts, reverse=True) minimizer_types = flex.select(minimizer_types, perm) counts = counts.se...
where Itrue>=0 (positivity constraint on error free amplitudes) for amplitudes, this results in
where Itrue>=0 (positivity constraint on error free amplitudes). For amplitudes, this results in
def enforce_positive_amplitudes(self,i_sig_level=-4.0): """ Takes in an intensity array (including negatives) and spits out amplitudes. The basic assumption is that P(Itrue) \propto exp(-(Itrue-Iobs)**2/(2*s)) where Itrue>=0 (positivity constraint on error free amplitudes) for amplitudes, this results in P(Ftrue) \prop...
a Gaussian approximation is fitted to the Mode of this distribution. An analitical solution exists and is implemented below.
A Gaussian approximation is fitted to the Mode of this distribution. An analytical solution exists and is implemented below.
def enforce_positive_amplitudes(self,i_sig_level=-4.0): """ Takes in an intensity array (including negatives) and spits out amplitudes. The basic assumption is that P(Itrue) \propto exp(-(Itrue-Iobs)**2/(2*s)) where Itrue>=0 (positivity constraint on error free amplitudes) for amplitudes, this results in P(Ftrue) \prop...
s_saddle = (1.0/(f_saddle*f_saddle)) + (self.data() + 3.0*det)/(self.sigmas()*self.sigmas() )
s_saddle = (1.0/(f_saddle*f_saddle)) + (self.data() + 3.0*det) \ / (self.sigmas()*self.sigmas() )
def enforce_positive_amplitudes(self,i_sig_level=-4.0): """ Takes in an intensity array (including negatives) and spits out amplitudes. The basic assumption is that P(Itrue) \propto exp(-(Itrue-Iobs)**2/(2*s)) where Itrue>=0 (positivity constraint on error free amplitudes) for amplitudes, this results in P(Ftrue) \prop...
have_write_back=not is_const, prefix=" "))
return_directly=is_const and signature.disable_handle_error, prefix=" "))
def bytes_converters(signature): assert signature.return_type == "void" function_name = signature.function_name arg_type = signature.args[-1].type arg_name = signature.args[-1].name arg_type_name = arg_type+" "+arg_name is_const = arg_type.startswith("const ") call = "\n".join(signature.format_call( have_write_back=not...
def format_call(self, have_write_back, prefix):
def format_call(self, return_directly, prefix):
def format_call(self, have_write_back, prefix): s = "" if (self.return_type != "void"): if (not have_write_back): s += "return " else: s += self.return_type + " result = " s += self.function_name+"(" s += ", ".join([arg.name for arg in self.args]) s += ");" result = [] indent = "" for line in line_breaker(s, 70): resul...
if (not have_write_back):
if (return_directly):
def format_call(self, have_write_back, prefix): s = "" if (self.return_type != "void"): if (not have_write_back): s += "return " else: s += self.return_type + " result = " s += self.function_name+"(" s += ", ".join([arg.name for arg in self.args]) s += ");" result = [] indent = "" for line in line_breaker(s, 70): resul...
lines.append(" throw std::runtime_error(") lines.append(' "Conversion not implemented:"') lines.append(' " %s(): %s %s");' % (
lines.append(ss+" throw std::runtime_error(") lines.append(ss+' "Conversion not implemented:"') lines.append(ss+' " %s(): %s %s");' % (
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
lines.append(" %s %s = 0;" % (arg.type, arg.name))
ss = "//" lines.append(ss+" %s %s = 0;" % (arg.type, arg.name))
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
lines.append(' %s<%s> %s_proxy(' % (
lines.append(ss+' %s<%s> %s_proxy(' % (
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
lines.append(' "%s", py_%s, %s, %s);' % (
lines.append(ss+' "%s", py_%s, %s, %s);' % (
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
lines.append(" %s %s = %s_proxy.get();" % (
lines.append(ss+" %s %s = %s_proxy.get();" % (
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
lines.append(' boost::python::extract<%s> %s_proxy(py_%s);' % (
lines.append(ss+' boost::python::extract<%s> %s_proxy(py_%s);' % (
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
lines.append(" %s %s = %s_proxy();" % (
lines.append(ss+" %s %s = %s_proxy();" % (
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
have_write_back = len(to_write_back) != 0 lines.extend( self.format_call(have_write_back=have_write_back, prefix=" "))
return_directly = len(to_write_back) == 0 and self.disable_handle_error lines.extend([ss+line for line in self.format_call(return_directly=return_directly, prefix=" ")])
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
lines.append(" handle_error();")
lines.append(ss+" handle_error();")
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
lines.append(" %s_proxy.write_back();" % arg.name) if (self.return_type != "void" and have_write_back): lines.append(" return result;")
lines.append(ss+" %s_proxy.write_back();" % arg.name) if (self.return_type != "void" and not return_directly): lines.append(ss+" return result;")
def write_wrapper(self, f): special = special_wrappers.get(self.function_name, None) if (special is not None and special[0] is not None): print >> f, special[0] return lines = [ self.return_type, self.wrapper_function_name()+"(" ] for arg in self.args: lines.append(" %s %s," % ( "boost::python::object const&", "py_"+a...
self.partially_customized_windows_dispatcher = open(join( self.dist_path("libtbx"), dispatcher_exe_file_name), "rb").read()
try: self.partially_customized_windows_dispatcher = open(join( self.dist_path("libtbx"), dispatcher_exe_file_name), "rb").read() except IOError, e: raise RuntimeError(str(e))
def windows_dispatcher(self, command_path, unique_pattern="0W6I0N6D0O2W8S5_0D0I8S1P4A3T6C4H9E4R7", libtbx_build="3L0I2B2T9B4X2_8B5U5I5L2D4", python_executable="5P2Y5T7H2O5N8_0E7X9E7C8U6T4A9B9L5E3", pythonpath="2P0Y1T7H3O2N7P7A2T5H8", main_path="1M5A1I0N4_8P7A0T9H9", target_command="5T4A3R7G8E3T7_6C5O0M0M3A8N8D2", dispa...
while (refined_matches[0].pairs[0] != (0,0)): del refined_matches[0]
while ( len(refined_matches) > 1 and refined_matches[0].pairs[0] != (0,0)): del refined_matches[0]
def weed_refined_matches(space_group_number, refined_matches, rms_penalty_per_site): n_matches = len(refined_matches) if (n_matches == 0): return best_rms = refined_matches[0].rms best_n_pairs = len(refined_matches[0].pairs) is_redundant = [0] * n_matches for i in xrange(n_matches-1): match_i = refined_matches[i] if (i...