Esempio n. 1
0
def run(args):
    if (len(args) != 1):
        raise RuntimeError("Please specify one pdb file name.")
    model_filename = args[0]
    pdb_inp = iotbx.pdb.input(file_name=model_filename)
    model = mmtbx.model.manager(model_input=pdb_inp)
    model.composition().show(log=sys.stdout)

    pdb_hierarchy = model.get_hierarchy()

    print('\nLoop over hierarchy:')
    for model in pdb_hierarchy.models():
        for chain in model.chains():
            print('Chain: ', chain.id)
            for rg in chain.residue_groups():
                print('  Resnumber: ', rg.resid())
                for ag in rg.atom_groups():
                    if (ag.resname in aa_resnames):
                        print('    Resname: %s, Altloc: %s' %
                              (ag.resname, ag.altloc))
                        for atom in ag.atoms():
                            if (atom.name not in ala_atom_names):
                                print('      %s' % atom.name)
                                ag.remove_atom(atom=atom)

    #print(help(pdb_hierarchy.write_pdb_file))
    pdb_hierarchy.write_pdb_file(file_name='polyala.pdb')
def run(args):
    if (len(args) != 1):
        raise RuntimeError("Please specify one model file name.")
    model_filename = args[0]
    pdb_inp = iotbx.pdb.input(file_name=model_filename)
    model = mmtbx.model.manager(model_input=pdb_inp)

    composition_obj = model.composition()
    #print(help(composition_obj))

    model.composition().show(log=sys.stdout)
def run(args):
    if (len(args) != 1):
        raise RuntimeError("Please specify one pdb file name.")
    model_filename = args[0]
    pdb_inp = iotbx.pdb.input(file_name=model_filename)
    model = mmtbx.model.manager(model_input=pdb_inp)
    model.composition().show(log=sys.stdout)

    pdb_hierarchy = model.get_hierarchy()

    print('\nLoop over hierarchy:')
    for model in pdb_hierarchy.models():
        for chain in model.chains():
            print('Chain: ', chain.id)
            for rg in chain.residue_groups():
                pass  # Add your code here
Esempio n. 4
0
def run(args):
    if (len(args) != 1):
        raise RuntimeError("Please specify one pdb file name.")
    model_filename = args[0]
    pdb_inp = iotbx.pdb.input(file_name=model_filename)
    model = mmtbx.model.manager(model_input=pdb_inp)
    model.composition().show(log=sys.stdout)

    pdb_hierarchy = model.get_hierarchy()

    n_amino_acid_residues = 0
    n_other_residues = 0
    n_atoms_removed = 0

    for model in pdb_hierarchy.models():
        for chain in model.chains():
            for rg in chain.residue_groups():
                if rg_has_amino_acid(rg):
                    n_amino_acid_residues += 1
                    for ag in rg.atom_groups():
                        for atom in ag.atoms():
                            if (atom.name not in ala_atom_names):
                                ag.remove_atom(atom=atom)
                                n_atoms_removed += 1
                else:
                    n_other_residues += 1

    print("\nNumber of amino acid residues:", n_amino_acid_residues)
    print("Number of other residues:", n_other_residues)
    print("Number of atoms removed:", n_atoms_removed)

    if (n_atoms_removed != 0):
        output_pdb = os.path.splitext(
            model_filename)[0] + "_truncated_to_ala.pdb"
        print("Writing file: ", output_pdb)
        pdb_hierarchy.write_pdb_file(
            file_name=output_pdb, crystal_symmetry=pdb_inp.crystal_symmetry())
Esempio n. 5
0
  def get_composition(self, run_map_box=True):
    make_sub_header('Get composition', out=self.logger)
    self.save_json()
    success = True

    for p, fn in zip(('', 'r_'),
      [self.json_data['pdb_file_updated'], self.json_data['pdb_file_refined']]):

      if not fn: continue

      pdb_inp = iotbx.pdb.input(file_name = fn)
      try:
        model = mmtbx.model.manager(
          model_input      = pdb_inp,
          log              = null_out())
      except Exception as e:
        msg = traceback.format_exc()
        step = 'Model class without restraints from initial pdb '
        print(msg, file=self.logger)
        self.write_log(step=step, msg=msg)
        self.json_data['success_composition'] = False
        self.save_json()
        return

      ph = model.get_hierarchy()
      # Overall composition
      if (p == ''):
        model_comp = model.composition()
        model_comp.show(log=self.logger)
        composition = model_comp.result()
        self.json_data['n_atoms']         = composition.n_atoms
        self.json_data['n_residues']      = composition.n_protein
        self.json_data['n_chains']        = composition.n_chains
        self.json_data['n_water']         = composition.n_water
        self.json_data['n_nucleotide']    = composition.n_nucleotide
        self.json_data['n_other']         = composition.n_other
        self.json_data['n_hd']            = composition.n_hd
        self.json_data['fraction_hd']     = composition.n_hd/composition.n_atoms
        self.json_data['composition_keys'] = composition.other_cnts.keys()
        self.json_data['n_alt_conf']      = ph.overall_counts().n_alt_conf
      #
      # ADPs
      try:
        adp_result = model.adp_statistics().result()
      except Exception as e:
        msg = traceback.format_exc()
        step = 'ADP statistics.'
        print(msg, file=self.logger)
        self.write_log(step=step, msg=msg)
        self.json_data['success_composition'] = False
        self.save_json()
        return

      adp_overall = adp_result.overall
      adp_protein = adp_result.protein
      adp_other = adp_result.other

      if adp_protein is not None:
        self.json_data[p+'b_min_protein']  = adp_protein.min
        self.json_data[p+'b_max_protein']  = adp_protein.max
        self.json_data[p+'b_mean_protein'] = adp_protein.mean
      if adp_other is not None:
        self.json_data[p+'b_min_other']  = adp_other.min
        self.json_data[p+'b_max_other']  = adp_other.max
        self.json_data[p+'b_mean_other'] = adp_other.mean

      self.json_data[p+'n_iso'] = adp_overall.n_iso
      self.json_data[p+'n_aniso'] = adp_overall.n_aniso

      #occupancy
      occ_stats = model.occupancy_statistics().result()
      self.json_data[p+'occ_zero'] = occ_stats.zero_count
      self.json_data[p+'occ_equal_to_1'] = occ_stats.equal_to_1_count
      self.json_data[p+'occ_between_0_and_1'] = occ_stats.between_0_and_1_count
      self.json_data[p+'occ_negative'] = occ_stats.negative

      if (p == ''):
        self.pickle_data.adp_hist = adp_result.histogram
      elif (p == 'r_'):
        self.pickle_data.r_adp_hist = adp_result.histogram

      # get boxed map
      if (p == '' and run_map_box):
        print('\nRunning phenix.map_box...', file=self.logger)
        pdb_file = self.json_data['pdb_file_updated']
        map_file = self.json_data['map_file']

        cmds = [
            "phenix.map_box",
            pdb_file,
            map_file,
            'resolution=%s' % self.resolution,
            'mask_atoms=True',
            ">& map_box.log"
            ]
        cmd = " ".join(cmds)
        print(cmd, file=self.logger)
        msg = ''
        try:
          easy_run.call(cmd)
        except Exception as e:
          success = False
          msg = traceback.format_exc()

        map_boxed_fn = os.path.join(self.dest_dir, self.prefix + '_box.ccp4')
        if os.path.isfile(map_boxed_fn):
          self.json_data['map_boxed'] = map_boxed_fn
        else:
          success = False
          msg = 'No output file from map_box'

    self.json_data['success_composition'] = success