コード例 #1
0
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
ファイル: dynamics.py プロジェクト: cctbx/cctbx-playground
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
コード例 #3
0
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)
コード例 #4
0
ファイル: dynamics.py プロジェクト: yayahjb/cctbx_project
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)
コード例 #5
0
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.")
コード例 #6
0
ファイル: tst_sa.py プロジェクト: mphancock/cctbx_project
def shake_sites(xrs, random, shift, grm=None):
    if (random):
        xrs.shake_sites_in_place(mean_distance=shift)
    else:
        grad_calc = cartesian_dynamics.gradients_calculator_geometry_restraints(
            restraints_manager=grm)
        cartesian_dynamics.run(xray_structure=xrs,
                               gradients_calculator=grad_calc,
                               temperature=1000,
                               n_steps=100000,
                               time_step=0.0005,
                               stop_cm_motion=True,
                               stop_at_diff=shift)
    return xrs
コード例 #7
0
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.")
コード例 #8
0
ファイル: tst_sa.py プロジェクト: cctbx/cctbx-playground
def shake_sites(xrs, random, shift, grm=None):
  if(random):
    xrs.shake_sites_in_place(mean_distance = shift)
  else:
    grad_calc = cartesian_dynamics.gradients_calculator_geometry_restraints(
      restraints_manager = grm)
    cartesian_dynamics.run(
      xray_structure       = xrs,
      gradients_calculator = grad_calc,
      temperature          = 1000,
      n_steps              = 100000,
      time_step            = 0.0005,
      stop_cm_motion       = True,
      stop_at_diff         = shift)
  return xrs
コード例 #9
0
ファイル: fake_f_obs.py プロジェクト: yayahjb/cctbx_project
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)
コード例 #10
0
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
ファイル: fake_f_obs.py プロジェクト: cctbx/cctbx-playground
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)
コード例 #12
0
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
コード例 #13
0
 def __init__(self,
              params,
              restraints_manager,
              xray_structure = None,
              wx = None,
              wc = None,
              fmodel = None,
              target_map = None,
              real_space = False,
              log = None,
              states_collector = None,
              callback = None,
              verbose=True):
   adopt_init_args(self, locals())
   assert (callback is None) or hasattr(callback, "__call__")
   if(self.params is None): self.params = master_params().extract()
   if(log is None): self.log = sys.stdout
   if(self.fmodel is not None):
     self.xray_structure = self.fmodel.xray_structure
   self.sites_cart_start = self.xray_structure.sites_cart()
   self.curr_temp = params.start_temperature
   verbose = params.verbose
   reset_velocities = True
   vxyz = None
   den_manager = restraints_manager.geometry.den_manager
   cartesian_den_restraints = False
   if(den_manager is not None):
     if("cartesian" in den_manager.params.annealing_type):
       # restraints_manager.geometry.generic_restraints_manager.flags.den = True
       cartesian_den_restraints = True
       verbose = False
   while params.final_temperature <= self.curr_temp:
     #if(self.curr_temp == params.start_temperature):
     #  cmremove=True
     #else: cmremove=False
     cmremove=True
     cd_manager = cartesian_dynamics.run(
       xray_structure           = self.xray_structure,
       gradients_calculator     = self.gradients_calculator(),
       temperature              = self.curr_temp,
       interleaved_minimization = self.params.interleave_minimization,
       vxyz                 = vxyz,
       n_steps              = self.params.number_of_steps,
       time_step            = self.params.time_step,
       n_print              = self.params.n_print,
       random_seed          = self.params.random_seed,
       stop_cm_motion       = cmremove,
       reset_velocities     = reset_velocities,
       log                  = self.log,
       verbose              = verbose)
     reset_velocities = False
     vxyz = cd_manager.vxyz
     self.xray_structure = cd_manager.xray_structure
     if(self.fmodel is not None):
       self.fmodel.update_xray_structure(
         xray_structure = self.xray_structure,
         update_f_calc  = True,
         update_f_mask  = True)
     if(states_collector is not None):
       self.states_collector.add(sites_cart = cd_manager.xray_structure.sites_cart())
     if (callback is not None) :
       callback(fmodel=self.fmodel)
     self.show(curr_temp = self.curr_temp)
     self.curr_temp -= params.cool_rate
     if(cartesian_den_restraints):
       print >> self.log, "update DEN eq distances at temp=%.1f" % self.curr_temp
       den_manager.update_eq_distances(
         sites_cart=fmodel.xray_structure.sites_cart())
コード例 #14
0
 def __init__(self,
              params,
              restraints_manager,
              xray_structure=None,
              wx=None,
              wc=None,
              fmodel=None,
              target_map=None,
              real_space=False,
              log=None,
              states_collector=None,
              callback=None,
              verbose=True):
     adopt_init_args(self, locals())
     assert (callback is None) or hasattr(callback, "__call__")
     if (self.params is None): self.params = master_params().extract()
     if (log is None): self.log = sys.stdout
     if (self.fmodel is not None):
         self.xray_structure = self.fmodel.xray_structure
     self.sites_cart_start = self.xray_structure.sites_cart()
     self.curr_temp = params.start_temperature
     verbose = params.verbose
     reset_velocities = True
     vxyz = None
     den_manager = restraints_manager.geometry.den_manager
     cartesian_den_restraints = False
     if (den_manager is not None):
         if ("cartesian" in den_manager.params.annealing_type):
             # restraints_manager.geometry.generic_restraints_manager.flags.den = True
             cartesian_den_restraints = True
             verbose = False
     while params.final_temperature <= self.curr_temp:
         #if(self.curr_temp == params.start_temperature):
         #  cmremove=True
         #else: cmremove=False
         cmremove = True
         cd_manager = cartesian_dynamics.run(
             xray_structure=self.xray_structure,
             gradients_calculator=self.gradients_calculator(),
             temperature=self.curr_temp,
             interleaved_minimization=self.params.interleave_minimization,
             vxyz=vxyz,
             n_steps=self.params.number_of_steps,
             time_step=self.params.time_step,
             n_print=self.params.n_print,
             random_seed=self.params.random_seed,
             stop_cm_motion=cmremove,
             reset_velocities=reset_velocities,
             log=self.log,
             verbose=verbose)
         reset_velocities = False
         vxyz = cd_manager.vxyz
         self.xray_structure = cd_manager.xray_structure
         if (self.fmodel is not None):
             self.fmodel.update_xray_structure(
                 xray_structure=self.xray_structure,
                 update_f_calc=True,
                 update_f_mask=True)
         if (states_collector is not None):
             self.states_collector.add(
                 sites_cart=cd_manager.xray_structure.sites_cart())
         if (callback is not None):
             callback(fmodel=self.fmodel)
         self.show(curr_temp=self.curr_temp)
         self.curr_temp -= params.cool_rate
         if (cartesian_den_restraints):
             print >> self.log, "update DEN eq distances at temp=%.1f" % self.curr_temp
             den_manager.update_eq_distances(
                 sites_cart=fmodel.xray_structure.sites_cart())