def exercise_02(inputs, verbose=0):
  #
  # run at n_step = 0
  #
  if (inputs.xray_structure is None):
    print("Skipping exercise_02(): input file not available")
    return
  structure_ = inputs.xray_structure.deep_copy_scatterers()
  if (verbose): log = sys.stdout
  else:         log = StringIO()
  gradients_calculator=cartesian_dynamics.gradients_calculator_reciprocal_space(
    restraints_manager = inputs.restraints_manager,
    sites_cart         = structure_.sites_cart(),
    wc                 = 1)
  cartesian_dynamics.run(
    xray_structure = structure_,
    gradients_calculator = gradients_calculator,
    temperature = 300,
    n_steps = 0,
    time_step = 0.0005,
    log = log,
    verbose = 1)
  assert inputs.xray_structure.rms_difference(structure_) \
      == structure_.rms_difference(inputs.xray_structure)
  assert approx_equal(
    structure_.rms_difference(inputs.xray_structure), 0.0, 1e-6)
Пример #2
0
def run_cartesian_dynamics(xray_structure, states_collector,
                           restraints_manager, params, stop_at_diff, log):
    from mmtbx.dynamics import cartesian_dynamics
    make_header("Simple cartesian dynamics", out=log)
    sites_cart_start = xray_structure.sites_cart().deep_copy()
    gradients_calculator = \
      cartesian_dynamics.gradients_calculator_reciprocal_space(
        restraints_manager = restraints_manager,
        sites_cart         = xray_structure.sites_cart(),
        wc                 = 1)
    cartesian_dynamics.run(xray_structure=xray_structure,
                           gradients_calculator=gradients_calculator,
                           temperature=params.temperature,
                           states_collector=states_collector,
                           n_steps=params.number_of_steps,
                           time_step=params.time_step,
                           initial_velocities_zero_fraction=params.
                           initial_velocities_zero_fraction,
                           n_print=params.n_print,
                           stop_cm_motion=params.stop_cm_motion,
                           stop_at_diff=stop_at_diff,
                           log=log,
                           verbose=1)
    sites_cart_end = xray_structure.sites_cart()
    rmsd = sites_cart_end.rms_difference(sites_cart_start)
    print("", file=log)
    print("RMSD from starting structure: %.3f" % rmsd, file=log)
Пример #3
0
def run_cartesian_dynamics (
    xray_structure,
    states_collector,
    restraints_manager,
    params,
    stop_at_diff,
    log) :
  from mmtbx.dynamics import cartesian_dynamics
  make_header("Simple cartesian dynamics", out=log)
  sites_cart_start = xray_structure.sites_cart().deep_copy()
  gradients_calculator = \
    cartesian_dynamics.gradients_calculator_reciprocal_space(
      restraints_manager = restraints_manager,
      sites_cart         = xray_structure.sites_cart(),
      wc                 = 1)
  cartesian_dynamics.run(
    xray_structure=xray_structure,
    gradients_calculator=gradients_calculator,
    temperature=params.temperature,
    states_collector=states_collector,
    n_steps=params.number_of_steps,
    time_step=params.time_step,
    initial_velocities_zero_fraction=params.initial_velocities_zero_fraction,
    n_print=params.n_print,
    stop_cm_motion=params.stop_cm_motion,
    stop_at_diff=stop_at_diff,
    log=log,
    verbose=1)
  sites_cart_end = xray_structure.sites_cart()
  rmsd = sites_cart_end.rms_difference(sites_cart_start)
  print >> log, ""
  print >> log, "RMSD from starting structure: %.3f" % rmsd
def exercise_02(inputs, verbose=0):
    #
    # run at n_step = 0
    #
    if inputs.xray_structure is None:
        print "Skipping exercise_02(): input file not available"
        return
    structure_ = inputs.xray_structure.deep_copy_scatterers()
    if verbose:
        log = sys.stdout
    else:
        log = StringIO()
    gradients_calculator = cartesian_dynamics.gradients_calculator_reciprocal_space(
        restraints_manager=inputs.restraints_manager, sites_cart=structure_.sites_cart(), wc=1
    )
    cartesian_dynamics.run(
        xray_structure=structure_,
        gradients_calculator=gradients_calculator,
        temperature=300,
        n_steps=0,
        time_step=0.0005,
        log=log,
        verbose=1,
    )
    assert inputs.xray_structure.rms_difference(structure_) == structure_.rms_difference(inputs.xray_structure)
    assert approx_equal(structure_.rms_difference(inputs.xray_structure), 0.0, 1e-6)
def exercise_03(mon_lib_srv, ener_lib, verbose=0):
  #
  # normal run with real model
  #
  pdb_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/2ERL_noH.pdb", test=os.path.isfile)
  if (pdb_file is None):
    print("Skipping exercise_03: input file not available")
    return
  if (verbose): log = sys.stdout
  else:         log = StringIO()
  params = mmtbx.monomer_library.pdb_interpretation.master_params.extract()
  params.nonbonded_weight = 16
  processed_pdb = mmtbx.monomer_library.pdb_interpretation.process(
    mon_lib_srv = mon_lib_srv,
    params=params,
    ener_lib = ener_lib,
    file_name = pdb_file,
    log = log)
  xray_structure = processed_pdb.xray_structure()
  restraints_manager = mmtbx.restraints.manager(
    geometry=processed_pdb.geometry_restraints_manager())
  structure_ = xray_structure.deep_copy_scatterers()
  gradients_calculator=cartesian_dynamics.gradients_calculator_reciprocal_space(
    restraints_manager = restraints_manager,
    sites_cart         = xray_structure.sites_cart(),
    wc                 = 1)
  cartesian_dynamics.run(
    xray_structure = xray_structure,
    gradients_calculator = gradients_calculator,
    temperature = 300,
    n_steps = 200,
    time_step = 0.0005,
    log = log,
    verbose = 1)
  rms1 = xray_structure.rms_difference(structure_)
  rms2 = structure_.rms_difference(xray_structure)
  assert rms1 == rms2
  rms = rms1
  if(verbose):
    print("rms between structures before and after dynamics = ", rms)
  array_of_distances_between_each_atom = \
       flex.sqrt(structure_.difference_vectors_cart(xray_structure).dot())
  if(verbose):
    flex.histogram(
      data=array_of_distances_between_each_atom,
      n_slots=12).show(
        format_cutoffs="%6.4f")
  n_rms = 5.3
  selected_by_rms = (array_of_distances_between_each_atom > n_rms * rms)
  outlier_sc = xray_structure.scatterers().select(selected_by_rms)
  if (outlier_sc.size() != 0):
    print("number of rms outliers:", outlier_sc.size())
    outlier_d = array_of_distances_between_each_atom.select(selected_by_rms)
    for sc,d in zip(outlier_sc, outlier_d):
      print(sc.label, d)
    raise RuntimeError("rms outliers.")
def exercise_03(mon_lib_srv, ener_lib, verbose=0):
    #
    # normal run with real model
    #
    pdb_file = libtbx.env.find_in_repositories(relative_path="phenix_regression/pdb/2ERL_noH.pdb", test=os.path.isfile)
    if pdb_file is None:
        print "Skipping exercise_03: input file not available"
        return
    if verbose:
        log = sys.stdout
    else:
        log = StringIO()
    params = mmtbx.monomer_library.pdb_interpretation.master_params.extract()
    params.nonbonded_weight = 16
    processed_pdb = mmtbx.monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv, params=params, ener_lib=ener_lib, file_name=pdb_file, log=log
    )
    xray_structure = processed_pdb.xray_structure()
    restraints_manager = mmtbx.restraints.manager(geometry=processed_pdb.geometry_restraints_manager())
    structure_ = xray_structure.deep_copy_scatterers()
    gradients_calculator = cartesian_dynamics.gradients_calculator_reciprocal_space(
        restraints_manager=restraints_manager, sites_cart=xray_structure.sites_cart(), wc=1
    )
    cartesian_dynamics.run(
        xray_structure=xray_structure,
        gradients_calculator=gradients_calculator,
        temperature=300,
        n_steps=200,
        time_step=0.0005,
        log=log,
        verbose=1,
    )
    rms1 = xray_structure.rms_difference(structure_)
    rms2 = structure_.rms_difference(xray_structure)
    assert rms1 == rms2
    rms = rms1
    if verbose:
        print "rms between structures before and after dynamics = ", rms
    array_of_distances_between_each_atom = flex.sqrt(structure_.difference_vectors_cart(xray_structure).dot())
    if verbose:
        flex.histogram(data=array_of_distances_between_each_atom, n_slots=12).show(format_cutoffs="%6.4f")
    n_rms = 5.3
    selected_by_rms = array_of_distances_between_each_atom > n_rms * rms
    outlier_sc = xray_structure.scatterers().select(selected_by_rms)
    if outlier_sc.size() != 0:
        print "number of rms outliers:", outlier_sc.size()
        outlier_d = array_of_distances_between_each_atom.select(selected_by_rms)
        for sc, d in zip(outlier_sc, outlier_d):
            print sc.label, d
        raise RuntimeError("rms outliers.")
Пример #7
0
def cd(xray_structure, restraints_manager, params):
    gradients_calculator = cartesian_dynamics.gradients_calculator_reciprocal_space(
        restraints_manager=restraints_manager,
        sites_cart=xray_structure.sites_cart(),
        wc=1)
    cartesian_dynamics.run(gradients_calculator=gradients_calculator,
                           xray_structure=xray_structure,
                           temperature=3000,
                           n_steps=500000,
                           time_step=0.0005,
                           initial_velocities_zero_fraction=0,
                           n_print=100,
                           stop_cm_motion=True,
                           log=None,
                           stop_at_diff=params.stop_cartesian_dynamics_at_diff,
                           verbose=-1)
def exercise_00(inputs, verbose=0):
  #
  # normal run
  #
  if (inputs.xray_structure is None):
    print("Skipping exercise_00(): input file not available")
    return
  structure_ = inputs.xray_structure.deep_copy_scatterers()
  if (verbose): log = sys.stdout
  else:         log = StringIO()
  gradients_calculator=cartesian_dynamics.gradients_calculator_reciprocal_space(
    restraints_manager = inputs.restraints_manager,
    sites_cart         = structure_.sites_cart(),
    wc                 = 1)
  cartesian_dynamics.run(
    gradients_calculator=gradients_calculator,
    xray_structure = structure_,
    temperature = 300,
    n_steps = 200,
    time_step = 0.0005,
    log = log,
    verbose = 1)
  rms1 = inputs.xray_structure.rms_difference(structure_)
  rms2 = structure_.rms_difference(inputs.xray_structure)
  assert rms1 == rms2
  rms = rms1
  if(verbose):
    print("rms between structures before and after dynamics = ", rms)
  array_of_distances_between_each_atom = \
       flex.sqrt(structure_.difference_vectors_cart(
         inputs.xray_structure).dot())
  if(verbose):
    print()
    for d in array_of_distances_between_each_atom:
      print(d)
  n_rms = 4.0
  selected_by_rms = (array_of_distances_between_each_atom > n_rms * rms)
  if(n_rms > 1.0):
    assert selected_by_rms.count(True) == 0
  if(verbose):
    print("number of outliers = ", selected_by_rms.count(True))
  selected = array_of_distances_between_each_atom.select(selected_by_rms)
  if(verbose):
    print("list of outliers : ")
    for s in selected:
      print(s)
Пример #9
0
def cd(xray_structure, restraints_manager, params):
  gradients_calculator=cartesian_dynamics.gradients_calculator_reciprocal_space(
    restraints_manager = restraints_manager,
    sites_cart         = xray_structure.sites_cart(),
    wc                 = 1)
  cartesian_dynamics.run(
    gradients_calculator             = gradients_calculator,
    xray_structure                   = xray_structure,
    temperature                      = 3000,
    n_steps                          = 500000,
    time_step                        = 0.0005,
    initial_velocities_zero_fraction = 0,
    n_print                          = 100,
    stop_cm_motion                   = True,
    log                              = None,
    stop_at_diff                     = params.stop_cartesian_dynamics_at_diff,
    verbose                          = -1)
def exercise_00(inputs, verbose=0):
    #
    # normal run
    #
    if inputs.xray_structure is None:
        print "Skipping exercise_00(): input file not available"
        return
    structure_ = inputs.xray_structure.deep_copy_scatterers()
    if verbose:
        log = sys.stdout
    else:
        log = StringIO()
    gradients_calculator = cartesian_dynamics.gradients_calculator_reciprocal_space(
        restraints_manager=inputs.restraints_manager, sites_cart=structure_.sites_cart(), wc=1
    )
    cartesian_dynamics.run(
        gradients_calculator=gradients_calculator,
        xray_structure=structure_,
        temperature=300,
        n_steps=200,
        time_step=0.0005,
        log=log,
        verbose=1,
    )
    rms1 = inputs.xray_structure.rms_difference(structure_)
    rms2 = structure_.rms_difference(inputs.xray_structure)
    assert rms1 == rms2
    rms = rms1
    if verbose:
        print "rms between structures before and after dynamics = ", rms
    array_of_distances_between_each_atom = flex.sqrt(structure_.difference_vectors_cart(inputs.xray_structure).dot())
    if verbose:
        print
        for d in array_of_distances_between_each_atom:
            print d
    n_rms = 4.0
    selected_by_rms = array_of_distances_between_each_atom > n_rms * rms
    if n_rms > 1.0:
        assert selected_by_rms.count(True) == 0
    if verbose:
        print "number of outliers = ", selected_by_rms.count(True)
    selected = array_of_distances_between_each_atom.select(selected_by_rms)
    if verbose:
        print "list of outliers : "
        for s in selected:
            print s
Пример #11
0
 def gradients_calculator(self):
   if(not self.real_space):
     if(self.fmodel is not None):
       grad_calc = cartesian_dynamics.gradients_calculator_reciprocal_space(
         restraints_manager        = self.restraints_manager, # XXX WHY?
         fmodel                    = self.fmodel,
         sites_cart                = self.fmodel.xray_structure.sites_cart(),
         wx                        = self.wx,
         wc                        = self.wc,
         update_gradient_threshold = self.params.update_grads_shift)
     else:
       grad_calc = cartesian_dynamics.gradients_calculator_geometry_restraints(
         restraints_manager = self.restraints_manager)
   else:
     grad_calc = cartesian_dynamics.gradients_calculator_real_space_simple(
       restraints_manager        = self.restraints_manager.geometry, # XXX WHY?
       target_map                = self.target_map,
       unit_cell                 = self.xray_structure.unit_cell(),
       sites_cart                = self.xray_structure.sites_cart(),
       wx                        = self.wx,
       wc                        = self.wc,
       update_gradient_threshold = 0)
   return grad_calc
Пример #12
0
 def gradients_calculator(self):
     if (not self.real_space):
         if (self.fmodel is not None):
             grad_calc = cartesian_dynamics.gradients_calculator_reciprocal_space(
                 restraints_manager=self.restraints_manager,  # XXX WHY?
                 fmodel=self.fmodel,
                 sites_cart=self.fmodel.xray_structure.sites_cart(),
                 wx=self.wx,
                 wc=self.wc,
                 update_gradient_threshold=self.params.update_grads_shift)
         else:
             grad_calc = cartesian_dynamics.gradients_calculator_geometry_restraints(
                 restraints_manager=self.restraints_manager)
     else:
         grad_calc = cartesian_dynamics.gradients_calculator_real_space_simple(
             restraints_manager=self.restraints_manager.
             geometry,  # XXX WHY?
             target_map=self.target_map,
             unit_cell=self.xray_structure.unit_cell(),
             sites_cart=self.xray_structure.sites_cart(),
             wx=self.wx,
             wc=self.wc,
             update_gradient_threshold=0)
     return grad_calc