def check_refinement_stability(self):
        if not self.shall_refine_thermal_displacements:
            for sc in self.xray_structure.scatterers():
                sc.flags.set_grad_site(True)
                if sc.flags.use_u_aniso(): sc.flags.set_grad_u_aniso(False)
                if sc.flags.use_u_iso(): sc.flags.set_grad_u_iso(False)

        xs = self.xray_structure
        xs0 = self.reference_xray_structure = xs.deep_copy_scatterers()
        mi = xs0.build_miller_set(anomalous_flag=False, d_min=0.5)
        fo_sq = mi.structure_factors_from_scatterers(
            xs0, algorithm="direct").f_calc().norm()
        fo_sq = fo_sq.customized_copy(sigmas=flex.double(fo_sq.size(), 1))

        xs.shake_sites_in_place(rms_difference=0.1)
        if self.shall_refine_thermal_displacements:
            # a spread of 10 for u_iso's would be enormous for our low temperature
            # test structures if those u_iso's were not constrained
            xs.shake_adp(
                spread=10,  # absolute
                aniso_spread=0.2)  # relative

        self.reparametrisation = constraints.reparametrisation(
            xs,
            self.constraints,
            self.connectivity_table,
            temperature=self.t_celsius)
        obs = fo_sq.as_xray_observations()
        ls = least_squares.crystallographic_ls(
            obs,
            self.reparametrisation,
            weighting_scheme=least_squares.mainstream_shelx_weighting())
        self.cycles = self.normal_eqns_solving_method(ls)
        print("%i %s iterations to recover from shaking" %
              (self.cycles.n_iterations, self.cycles))
        if 0:
            from crys3d.qttbx.xray_structure_viewer import display
            display(xray_structure=xs)

        diff = xray.meaningful_site_cart_differences(xs0, xs)
        assert diff.max_absolute() < self.site_refinement_tolerance,\
               self.__class__.__name__

        if self.shall_refine_thermal_displacements:
            delta_u = []
            for sc, sc0 in itertools.izip(xs.scatterers(), xs0.scatterers()):
                if not sc.flags.use_u_aniso() or not sc0.flags.use_u_aniso():
                    continue
                delta_u.extend(matrix.col(sc.u_star) - matrix.col(sc0.u_star))
            delta_u = flex.double(delta_u)

            assert flex.max_absolute(delta_u) < self.u_star_refinement_tolerance,\
                   self.__class__.__name__
  def check_refinement_stability(self):
    if not self.shall_refine_thermal_displacements:
      for sc in self.xray_structure.scatterers():
        sc.flags.set_grad_site(True)
        if sc.flags.use_u_aniso(): sc.flags.set_grad_u_aniso(False)
        if sc.flags.use_u_iso(): sc.flags.set_grad_u_iso(False)

    xs = self.xray_structure
    xs0 = self.reference_xray_structure = xs.deep_copy_scatterers()
    mi = xs0.build_miller_set(anomalous_flag=False, d_min=0.5)
    fo_sq = mi.structure_factors_from_scatterers(
      xs0, algorithm="direct").f_calc().norm()
    fo_sq = fo_sq.customized_copy(sigmas=flex.double(fo_sq.size(), 1))

    xs.shake_sites_in_place(rms_difference=0.1)
    if self.shall_refine_thermal_displacements:
      # a spread of 10 for u_iso's would be enormous for our low temperature
      # test structures if those u_iso's were not constrained
      xs.shake_adp(spread=10, # absolute
                   aniso_spread=0.2) # relative

    self.reparametrisation = constraints.reparametrisation(
      xs, self.constraints, self.connectivity_table,
      temperature=self.t_celsius)
    obs = fo_sq.as_xray_observations()
    ls = least_squares.crystallographic_ls(
      obs,
      self.reparametrisation,
      weighting_scheme=least_squares.mainstream_shelx_weighting())
    self.cycles = self.normal_eqns_solving_method(ls)
    print ("%i %s iterations to recover from shaking"
           % (self.cycles.n_iterations,
              self.cycles))
    if 0:
      from crys3d.qttbx.xray_structure_viewer import display
      display(xray_structure=xs)

    diff = xray.meaningful_site_cart_differences(xs0, xs)
    assert diff.max_absolute() < self.site_refinement_tolerance,\
           self.__class__.__name__

    if self.shall_refine_thermal_displacements:
      delta_u = []
      for sc, sc0 in itertools.izip(xs.scatterers(), xs0.scatterers()):
        if not sc.flags.use_u_aniso() or not sc0.flags.use_u_aniso(): continue
        delta_u.extend(matrix.col(sc.u_star) - matrix.col(sc0.u_star))
      delta_u = flex.double(delta_u)

      assert flex.max_absolute(delta_u) < self.u_star_refinement_tolerance,\
             self.__class__.__name__
 def display_structure(self):
     from crys3d.qttbx.xray_structure_viewer import display
     display(xray_structure=self.xray_structure)
 def display_structure(self):
   from crys3d.qttbx.xray_structure_viewer import display
   display(xray_structure=self.xray_structure)
from __future__ import absolute_import, division, print_function
from cctbx import xray
from crys3d.qttbx import xray_structure_viewer
try:
    import durham_structures
except ImportError:
    durham_structures = None
import sys, os

name = sys.argv[1]
filename = os.path.expanduser(name)
if os.path.exists(filename):
    xs = xray.structure.from_shelx(filename=filename, strictly_shelxl=False)
elif durham_structures:
    xs = durham_structures.some([name]).next().xray_structure
else:
    print("%s not found" % name)
    sys.exit(1)
xray_structure_viewer.display(xray_structure=xs, name=name)
from __future__ import division
from cctbx import xray
from crys3d.qttbx import xray_structure_viewer
try:
  import durham_structures
except ImportError:
  durham_structures = None
import sys, os

name = sys.argv[1]
filename = os.path.expanduser(name)
if os.path.exists(filename):
  xs = xray.structure.from_shelx(filename=filename, strictly_shelxl=False)
elif durham_structures:
  xs = durham_structures.some([name]).next().xray_structure
else:
  print "%s not found" % name
  sys.exit(1)
xray_structure_viewer.display(xray_structure=xs, name=name)