Esempio n. 1
0
def exercise_convert_to_isotropic():
    pdb_str = """
ATOM    104  N   SER A   8      14.526  19.060  18.223  1.00  5.10           N
ANISOU  104  N   SER A   8      500    632    808   -107     58    104       N
ATOM    105  CA  SER A   8      14.099  17.792  18.758  1.00  5.95           C
"""
    cs = crystal.symmetry((5.01, 5.01, 5.47, 90, 90, 120), "P 62 2 2")
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str)
    model = mmtbx.model.manager(model_input=pdb_inp, crystal_symmetry=cs)
    #
    m = model.deep_copy()
    m.convert_to_isotropic()
    assert approx_equal(m.get_hierarchy().atoms().extract_b(),
                        [5.105875, 5.95])
    assert approx_equal(m.get_hierarchy().atoms().extract_uij(),
                        [(-1.0, -1.0, -1.0, -1.0, -1.0, -1.0),
                         (-1.0, -1.0, -1.0, -1.0, -1.0, -1.0)])
    #
    m = model.deep_copy()
    m.convert_to_isotropic(selection=flex.bool([False, True]))
    assert approx_equal(m.get_hierarchy().atoms().extract_b(),
                        model.get_hierarchy().atoms().extract_b())
    assert approx_equal(m.get_hierarchy().atoms().extract_uij(),
                        model.get_hierarchy().atoms().extract_uij())
    #
    m1 = model.deep_copy()
    m2 = model.deep_copy()
    m1.convert_to_isotropic(selection=flex.bool([True, False]))
    m2.convert_to_isotropic()
    assert approx_equal(m1.get_hierarchy().atoms().extract_b(),
                        m2.get_hierarchy().atoms().extract_b())
    assert approx_equal(m1.get_hierarchy().atoms().extract_uij(),
                        m2.get_hierarchy().atoms().extract_uij())
Esempio n. 2
0
def exercise_set_b_iso():
    pdb_str = """
ATOM    104  N   SER A   8      14.526  19.060  18.223  1.00  5.10           N
ANISOU  104  N   SER A   8      500    632    808   -107     58    104       N
ATOM    105  CA  SER A   8      14.099  17.792  18.758  1.00  5.95           C
"""
    cs = crystal.symmetry((5.01, 5.01, 5.47, 90, 90, 120), "P 62 2 2")
    uc = cs.unit_cell()
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str)
    model = mmtbx.model.manager(model_input=pdb_inp, crystal_symmetry=cs)
    #
    m = model.deep_copy()
    bs = flex.double([10, 20])
    m.set_b_iso(values=bs)
    assert approx_equal(m.get_hierarchy().atoms().extract_b(), [-1.0, 20.0])
    us = m.get_hierarchy().atoms().extract_uij()
    assert approx_equal(us[0], model.get_hierarchy().atoms().extract_uij()[0])
    assert approx_equal(us[1], (-1.0, -1.0, -1.0, -1.0, -1.0, -1.0))
    u_iso_1 = m.get_xray_structure().scatterers().extract_u_iso()
    b_iso_2 = m.get_hierarchy().atoms().extract_b()
    assert approx_equal(u_iso_1[0], -1)
    assert approx_equal(b_iso_2[0], -1)
    assert approx_equal(adptbx.u_as_b(u_iso_1[1]), 20)
    assert approx_equal(b_iso_2[1], 20)
    #
    m = model.deep_copy()
    m.convert_to_isotropic()
    bs = flex.double([10, 20])
    sel = flex.bool([True, False])
    m.set_b_iso(values=bs, selection=sel)
    assert approx_equal(m.get_b_iso(), [10, 5.95])
Esempio n. 3
0
def exercise_3():
    """
  Make sure model can do deep_copy() straight away.
  """
    inp = iotbx.pdb.input(lines=pdb_str_1, source_info=None)
    model = mmtbx.model.manager(model_input=inp)
    new_model = model.deep_copy()
Esempio n. 4
0
  def get_statistics(self):
    if self.json_data['success_composition'] is False:
      return
    make_sub_header('Get statistics', out=self.logger)
    self.save_json()
    success = True
    self.json_data['success_statistics'] = None

    sc, r_sc = None, None
    self.pickle_data.min_reso = None
    self.pickle_data.d_inv = None
    self.pickle_data.r_d_inv = None
    self.pickle_data.d_inv_half = None
    self.pickle_data.fsc_model = None
    self.pickle_data.r_fsc_model = None
    self.pickle_data.fsc_half = None

    if self.json_data['restraints_file']:
      cif_file = self.json_data['restraints_file']
      cif_objects = monomer_library.server.read_cif(file_name=to_str(cif_file))
      cif_objects = [(cif_file, cif_objects)]
    else: cif_objects = None

    for p, fn in zip(('', 'r_'),
      [self.json_data['pdb_file_updated'], self.json_data['pdb_file_refined']]):
    # TODO which file to use for initial!!
      if (not fn or not os.path.isfile(fn)): continue

      if p=='': print('Initial model', file=self.logger)
      if p=='r_': print('\nRefined model', file=self.logger)

      dm = DataManager()

      dm.process_real_map_file(self.json_data['map_file'])
      map_inp = dm.get_real_map(self.json_data['map_file'])
      #map_inp   = iotbx.ccp4_map.map_reader(file_name = self.json_data['map_file'])
      map_inp_1, map_inp_2 = None, None
      if self.json_data['map_file_1'] is not None:
        #map_inp_1 = iotbx.ccp4_map.map_reader(file_name = self.json_data['map_file_1'])
        dm.process_real_map_file(self.json_data['map_file_1'])
        map_inp_1 = dm.get_real_map(self.json_data['map_file_1'])
        #map_data_1 = map_inp_1.map_data()
      if self.json_data['map_file_2'] is not None:
        dm.process_real_map_file(self.json_data['map_file_2'])
        map_inp_2 = dm.get_real_map(self.json_data['map_file_2'])
        #map_inp_2 = iotbx.ccp4_map.map_reader(file_name = self.json_data['map_file_2'])
        #map_data_2 = map_inp_2.map_data()

      print('\tGet model class with restraints...', file=self.logger)
      pdb_inp = iotbx.pdb.input(file_name = fn)
      try:
        model = mmtbx.model.manager(
          model_input       = pdb_inp,
          restraint_objects = cif_objects,
          build_grm         = True,
          stop_for_unknowns = False,
          crystal_symmetry  = map_inp.crystal_symmetry(),
          log               = null_out())
      except Exception as e:
        #success = False
        self.json_data['success_statistics'] = False
        msg = traceback.format_exc()
        print(msg, file=self.logger)
        self.write_log(
          step = 'Statistics: Model class (with restraints) from pdb ',
          msg  = msg)
        self.save_json()
        continue

      if not success: continue

      # Emringer
      if self.resolution < 4.0:
        print('\tCalculate Emringer score', file=self.logger)
        try:
          emringer_score = self.get_emringer_score(
            model   = model.deep_copy(),
            map_inp = map_inp.deep_copy())
          self.json_data[p+'emringer'] = emringer_score
        except Exception as e:
          msg = traceback.format_exc()
          print(msg, file=self.logger)
          self.write_log(step = 'EMRinger failed ', msg = msg)
          # TODO: save as success_statistics False?

      # Rama-z score
      try:
        rama_z_score = rama_z.rama_z(
        models = [model],
        log = self.logger)
        z_scores = rama_z_score.get_z_scores()
        self.json_data[p+'z_score'] = z_scores['W'][0]
      except Exception as e:
        msg = traceback.format_exc()
        print(msg, file=self.logger)
        self.write_log(step = 'Rama z-score failed ', msg = msg)

#      base = map_and_model.input(
#        map_manager   = map_inp,
#        map_manager_1 = map_inp_1,
#        map_manager_2 = map_inp_2,
#        model         = model,
#        box           = True)

      checked = map_model_manager(
        map_manager         = map_inp,
        map_manager_1       = map_inp_1,
        map_manager_2       = map_inp_2,
        model      = model,
        wrapping   = None)
      checked.box_all_maps_around_model_and_shift_origin()

      params = validation_cryoem.master_params().extract()
      params.resolution = self.resolution
      params.slim = False

      if (p == ''):
        print('\tGet map parameters...', file=self.logger)
        self.get_map_parameters(base = checked)

      print('\tRun Mtriage...', file=self.logger)
      try:
        o = validation_cryoem.validation(
          model      = checked.model(),
          map_data   = checked.map_data(),
          map_data_1 = checked.map_data_1(),
          map_data_2 = checked.map_data_2(),
          params     = params)
      except Exception as e:
        # success = False
        self.json_data['success_statistics'] = False
        msg = traceback.format_exc()
        print(msg, file=self.logger)
        self.write_log(step = 'Statistics ', msg = msg)
        self.save_json()
        continue

      print('\tStore info in pkl...', file=self.logger)
      o_dict = self.fill_dictionary(o)
      if (p == ''):
        self.json_data['o'] = o_dict
        sc = o.model.get_sites_cart()
      elif (p == 'r_'):
        self.json_data['o_refined'] = o_dict
        r_sc = o.model.get_sites_cart()
      if o is not None:
        if o.model_vs_data is not None:
          if o.model_vs_data.cc is not None:
            if o.model_vs_data.cc.cc_per_chain is not None:
              if (p == ''):
                self.pickle_data.cc_per_chain = o.model_vs_data.cc.cc_per_chain
              if (p == 'r_'):
                self.pickle_data.r_cc_per_chain = o.model_vs_data.cc.cc_per_chain
            if o.model_vs_data.cc.cc_per_residue is not None:
              if (p == ''):
                self.pickle_data.cc_per_residue = o.model_vs_data.cc.cc_per_residue
              if (p == 'r_'):
                self.pickle_data.r_cc_per_residue = o.model_vs_data.cc.cc_per_residue
        if o.model_stats.geometry.ramachandran.ramalyze is not None:
          rl = o.model_stats.geometry.ramachandran.ramalyze
          if (p == ''): self.pickle_data.ramalyze = rl
          if (p == 'r_'): self.pickle_data.r_ramalyze = rl
      # values for the curve go up to very high reso, get highest reso limit
#      if o is not None:
#        reso_list = [self.json_data['d_pdb'],self.json_data['d_cif'],
#          self.json_data['d_map'], self.json_data['o']['d99'],
#          self.json_data['o']['d_model'], self.json_data['o']['d_fsc']]
#      else:
#        reso_list = [self.json_data['d_pdb'],self.json_data['d_cif'],
#          self.json_data['d_map']]
#      min_reso = min([elem for elem in reso_list if elem is not None])
#      self.pickle_data.min_reso = min_reso
      min_reso = self.resolution
      self.pickle_data.min_reso = self.resolution
      # apply some arbitrary buffer
      min_reso = min_reso - 0.5
      if o is not None:
        masked = o.data_stats.masked
        if (masked.fsc_curve_model is not None):
          if ((masked.fsc_curve_model.d_inv is not None) and
              (masked.fsc_curve_model.fsc is not None)):
            if (p == ''):
              self.pickle_data.d_inv = masked.fsc_curve_model.d_inv
              self.pickle_data.fsc_model   = masked.fsc_curve_model.fsc
            if (p == 'r_'):
              self.pickle_data.r_d_inv = masked.fsc_curve_model.d_inv
              self.pickle_data.r_fsc_model   = masked.fsc_curve_model.fsc
        if (p == ''):
          if (masked.fsc_curve is not None):
            if (masked.fsc_curve.fsc is not None):
              if ((masked.fsc_curve.fsc.d_inv is not None) and
                  (masked.fsc_curve.fsc.fsc is not None)):
                self.pickle_data.d_inv_half = masked.fsc_curve.fsc.d_inv
                self.pickle_data.fsc_half   = masked.fsc_curve.fsc.fsc

      if o is not None:
        print("\nd99                  :", o.data_stats.masked.d99)
        print("d_model              :", o.data_stats.masked.d_model)
        print("d_fsc                :", o.data_stats.masked.d_fsc)
        print("ramachandran.outliers:", o.model_stats.geometry.ramachandran.outliers)
        print("cc_mask              :", o.model_vs_data.cc.cc_mask)
        print("cc_box               :", o.model_vs_data.cc.cc_box)

    if sc is not None and r_sc is not None:
      self.json_data['rmsd'] = sc.rms_difference(r_sc)

    if self.json_data['success_statistics'] is not False:
      self.json_data['success_statistics'] = success